aboutsummaryrefslogtreecommitdiff
path: root/Python/library/Zinc.py
blob: d5a276db461506a66f17059bb213c9cfc8831481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
#
# Zinc.py -- Python interface to the tkzinc widget.
#
# Authors         : Frederic Lepied, Patrick Lecoanet
# Created Date    : Thu Jul 22 09:36:04 1999
#
# $Id: Zinc.py 1908 2008-09-15 09:38:54Z lecoanet $
#
#
# Copyright (c) 1999 CENA --
#
# See the file "Copyright" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#

__version__  = "$Revision: 1908 $"
__revision__ = "$Revision: 1908 $"

from Tkinter import *
import new
import os
import locale, types
import traceback

ZINC_CURRENT_POSITION = -2
ZINC_SPEED_VECTOR     = -3
ZINC_LEADER           = -4
ZINC_CONNECTION       = -5
_LIBLOADED            = 0
_VERSION              = ""
ZINC_NO_PART          = ""

# current part dictionnary
ZINC_DPART = { 'position'      : ZINC_CURRENT_POSITION, 
         'speedvector'   : ZINC_SPEED_VECTOR , 
         'leader'        : ZINC_LEADER, 
         'connection'    : ZINC_CONNECTION}
# notes : 'field' will be return when currentpart is a field 

def havetkzinc( window ):
  '''load Zinc dynamic sharable object library , test if everything is ok
if  ok :return zinc version
if nok : return 0 '''
  global _LIBLOADED
  global _VERSION
  if ( _LIBLOADED == 1 ) : 
    return _VERSION
  try:
    if os.environ.has_key( 'auto_path' ):
      ldir = os.environ['auto_path'].split( ':' )
      ldir.reverse()
      for adir in ldir :
        window.tk.call( 'eval', 
                  "set auto_path "
                  + "[linsert $auto_path 0 %s]" % ( adir ) )
    window.tk.call( 'eval', 'package require Tkzinc' )
    # Call a function from the package to autoload it
    # and verify that all is OK.
    sversion = window.tk.call( 'zinc' ) + " Zinc.py %s" % __version__
  except TclError:
    traceback.print_exc()
    return 0
  _LIBLOADED = 1
  _VERSION = sversion
  return sversion

class ZincException:
  def __call__( self ):
    raise self

  def __init__( self, message ):
    self.message = message
    
  def __str__( self ):
    return self.message

class Zinc( Widget ):
  def __str__( self ):
    return( "Zinc instance" )
  def __init__( self, master = None, cnf = None, **kw ):
    if kw.has_key( 'backward_compatibility' ):
      self.currentpart = self.__oldcurrentpart
      self.configure   = self.__oldconfigure
      self.scale       = self.__oldscale
      self.translate   = self.__oldtranslate
      del kw['backward_compatibility']
      #Pour éviter des effets de bord 
      #si on met comme valeur par défaut de cnf
      #à {} 
    if cnf is None :
      cnf = {}
    if master :
      self.version = havetkzinc( master )
    else:
      master = Frame()
      master.pack()
      self.version = havetkzinc( master )
    Widget.__init__( self, master, 'zinc', cnf, kw )
    self.items = {}
    #BootStrap Root
    classe = eval( 'Group' )
    obj = None
    kw['id'] = 1
    obj = new.instance( classe, kw )
    self.items[1] = obj

  def mainloop( self ):
    """
    Run the events mainloop 
    """
    self.tk.mainloop()
    
  def add( self, itemType, *args, **kw ):
    """
    listTypes = zinc.add()
    id        = zinc.add(type, group)
    id        = zinc.add(type, group, initargs, **options)
    type=[arc|curve|rectangle|triangles|tabular|track|waypoint|group|icon|map|reticle|text|window]
    """
    args = list( args )
    args = args+list( self._options( kw ) )
    try:
      return self.tk.getint( 
        self.tk.call( self._w, 'add', itemType, *args ) )
    except TclError, excpt :
      ZincException( "%s\nType %s\nArgs : %s"%( excpt, itemType, args ) )()
  
  def addtag( self, *args ):
    """
    zinc.addtag(tag, searchSpec)
    This command add the given tag to all items matching
    the search specification.
    If the tag is already present on some item,
    nothing is done for that item.
    The command has no effect if no item satisfy
    the given criteria. The command returns an empty string.
    """
    self.tk.call( self._w, 'addtag', *args )

  def addtag_above( self, newtag, tagOrId ):
    """
    zinc.addtag_above(tag, tagOrId)
    """
    self.addtag( newtag, 'above', tagOrId )

  def addtag_all( self, newtag ):
    """
    A ne plus utiliser
    Utiliser addtag_withtag
    """
    self.addtag( newtag, 'all' )

  def addtag_ancestors( self, newtag, tagOrId, *ltagOrId ):
    """
    zinc.addtag_ancestors(tag, tagOrId, *listTagOrId)
    """
    self.addtag( newtag, 'ancestors', tagOrId, *ltagOrId )

  def addtag_atpriority( self, newtag, pri, tagOrId = 1 ):
    """
    zinc.addtag_atpriority(tag, priority, tagOrId = 1)
    """
    
    self.addtag( newtag, 'atpriority', pri, tagOrId )

  def addtag_below( self, newtag, tagOrId ):
    """
    zinc.addtag_below(tag, tagOrId)
    """
    self.addtag( newtag, 'below', tagOrId )

  def addtag_closest( self, newtag, x, y, halo = None, startItem = 1, recursive = 0 ):
    """
    zinc.addtag_closest(tag, x, y, halo = None, startItem = 1, recursive = 0)
    """
    self.addtag( newtag, 'closest', x, y, halo, startItem, recursive )    

  def addtag_enclosed( self, newtag, x1, y1, x2, y2, inGroup = 1, recursive = 0 ):
    """
    zinc.addtag_enclosed(tag, x1, y1, x2, y2, inGroup = 1, recursive = 0)
    """
    self.addtag( newtag, 'enclosed', x1, y1, x2, y2, inGroup, recursive )   

  def addtag_overlapping( self, newtag, x1, y1, x2, y2, inGroup = 1, recursive = 0 ):
    """
    zinc.addtag_overlapping(tag, x1, y1, x2, y2, inGroup = 1, recursive = 0)
    """
    self.addtag( newtag, 'overlapping', x1, y1, x2, y2, inGroup, recursive )

  def addtag_withtag( self, newtag, tagOrId ):
    """
    zinc.addtag_withtag(tag, tagOrId)
    """
    self.addtag( newtag, 'withtag', tagOrId )

  def addtag_withtype( self, newtag, type, tagOrId = 1 ):
    """
    zinc.addtag_withtype(tag, type, tagOrId = 1)
    """
    self.addtag( newtag, 'withtype', type, tagOrId )

  def anchorxy( self, *args ):
    """
    (x, y) = zinc.anchorxy(tagOrId, anchor)
    """
    return self.tk.call( self._w, 'anchorxy', *args )

  def bbox( self, *args ):
    """
    (xo, yo, xc, yc) = zinc.bbox(tagOrId, ?fieldIndex?)
    """
    return self.tk.call( self._w, 'bbox', *args )

  def becomes( self ):
    """
    zinc.becomes()
    """
    self.tk.call( self._w, 'becomes' )

  def bind_tag( self, tagOrId, sequence = None, func = None, add = None ):
    '''
    return a funcid which can be usefull for unbinding
    listBindings = zinc.bind_tag(tagOrId)
    listbindings = zinc.bind_tag(tagOrId, sequence)
    zinc.bind_tag(tagOrId, sequence, '')
    zinc.bind_tag(tagOrId, sequence, command)
    '''
    return self._bind( ( self._w, 'bind', tagOrId ), 
          sequence, func, add )

  def cget( self, option ):
    """
    val = zinc.cget(option)
    """
    return self.tk.call( self._w, 'cget', '-' + option )

  def chggroup( self, *args ):
    """
    zinc.chggroup(tagOrId, group, ?adjustTransform?)
    """
    self.tk.call( self._w, 'chggroup', *args )

  def clone( self, *args, **kw):
    """
    id = zinc.clone(tagOrId, **attributs)
    """
    args = list( args ) + list( self._options( kw ) )
    return self.tk.call( self._w, 'clone', *args)

  def __oldconfigure( self, **kw ):
    return Widget.configure( self, **kw )
    
  def configure( self, **kw ):
    """
    listOptions = zinc.configurez()
    listOptions = zinc.configurez(option)
    zinc.configurez(**options)
    """
    res  = Widget.configure( self, **kw )
    dico = {}
    if res:
      for i, j in res.items():
        dico[i] = j[3:]
      return dico

  def contour( self, *args ):
    """
    contourNum = zinc.contour(tagOrId)
    contourNum = zinc.contour(tagOrId, operatorAndFlag, coordListOrTagOrId)
    """
    return self.tk.call( self._w, 'contour', *args )

  def coords( self, *args ):
    """
    zinc.coords(tagOrId, contourIndex)
    zinc.coords(tagOrId, contourIndex, coordList)
    zinc.coords(tagOrId, contourIndex, coordIndex)
    zinc.coords(tagOrId, contourIndex, coordIndex, coordList)
    zinc.coords(tagOrId, 'remove', contourIndex, coordIndex)
    zinc.coords(tagOrId, 'add', contourIndex, coordList)
    zinc.coords(tagOrId, 'add', contourIndex, coordIndex, coordList)
    zinc.coords(tagOrId)
    zinc.coords(tagOrId, coordList)
    zinc.coords(tagOrId, 'remove', coordIndex)
    zinc.coords(tagOrId, 'add', coordList)
    """   
    return self.tk.call( self._w, 'coords', *args )

  def __buggyoldcurrentpart( self ):
    '''
    return a string (result from zinc current part function) and an
    integer representing either the number of the field either
    the number of the item part either ZINC_NO_PART   
    '''
    scurrentp = self.tk.call( self._w, 'currentpart' )
    if scurrentp == "":
      rvalue = ZINC_NO_PART
    else:
      try:
        rvalue = locale.atoi( scurrentp )
      except:
        try:
          rvalue = ZINC_DPART[scurrentp]
        except:
          rvalue = ZINC_NO_PART
      else:
        # string to integer succeeded
        scurrentp = "field"
    return( scurrentp, rvalue )
  
  def __oldcurrentpart( self ):
    '''return a string and an integer ;
the string is among "field", "position", "speedvector", "leader", "connection", "",
the number is the number of the part , or the field number in case of "field";
ex: 
no part return '', ZINC_NO_PART
'''
    scurrentp = self.tk.call( self._w, 'currentpart' )
    print "Zinc::__oldcurrentpart scurrentp = [%s]" % scurrentp
    # warning : read this first :
    # return a string among 'position', 'speedvector', 'leader', 'connection' ,''
    #        or an int representing the number of a field label
    # 
    # print "Zinc::currentpart cp=%s  ,type(cp)=%s" % (scurrentp,type(scurrentp))
    if scurrentp == "":
      rvalue = ZINC_NO_PART
    elif type( scurrentp ) == type( 1 ):
      # meaning a field
      # the subtil thing is here ! warning !
      rvalue    = scurrentp
      scurrentp = "field"
    else:
      # scurrentp is a string different from ""
      try:
        rvalue = ZINC_DPART[scurrentp]
      except:
        print "Zinc::currentpart unknown item part" 
        rvalue = ZINC_NO_PART

    return scurrentp, rvalue

  def currentpart( self ):
    '''
    num = zinc.currentpart()
    '''
    return  str( self.tk.call( self._w, 'currentpart' ) )
    

  def cursor( self, *args ):
    """
    zinc.cursor(tagOrId, index)
    """
    self.tk.call( self._w, 'cursor', *args )
    
  def dchars( self, *args ):
    """
    zinc.dchars( tagOrId, first )
    zinc.dchars( tagOrId, first,last )
    """
    self.tk.call( self._w, 'dchars', *args )
    
  def dtag( self, *args ):
    """
    zinc.dtag(tagOrId)
    zinc.dtag(tagOrId, tagToDelete)
    """
    self.tk.call( self._w, 'dtag', *args )

  def find( self, *args ):
    return self._getints( 
      self.tk.call( self._w, 'find', *args ) ) or ()

  def find_above( self, tagOrId ):
    """
    listItems=zinc.find_above(tagOrId)}
    """
    return self.find( 'above', tagOrId )

  def find_all( self ):
    return self.find( 'all' )
  
  def find_ancestors( self, newtag, tagOrId, *tagOrId2 ):
    """
    listItems=zinc.find_ancestor(tag, tagOrId, ?tagOrId2?)
    """
    return self.find( newtag, 'ancestors', tagOrId, *tagOrId2 )

  def find_atpriority( self, pri, *tagOrId ):
    """
    listItems=zinc.find_atpriority(pri, ?tagOrId?)
    """
    return self.find( 'atpriority', pri, *tagOrId )

  def find_below( self, tagOrId ):
    """
    listItems=zinc.find_below(tagOrId)
    """
    return self.find( 'below', tagOrId )

  def find_closest( self, x, y, *options ):
    """
    listItems=zinc.find_closest(x, y, ?halo?, ?startItem?, ?recursive?)
    """
    return self.find( 'closest', x, y, *options )

  def find_enclosed( self, x1, y1, x2, y2 ):
    """
    listItems=zinc.find_enclosed(x1, y1, x2, y2, inGroup=1, recursive=0)
    """
    return self.find( 'enclosed', x1, y1, x2, y2 )

  def find_overlapping( self, x1, y1, x2, y2, *options ):
    """
    listItems=zinc.find_overlapping( x1, y1, x2, y2, ?inGroup?, ?recursive?)
    """
    return self.find( 'overlapping', x1, y1, x2, y2, *options )

  def find_withtag( self, tagOrId ):
    """
    listItems=zinc.find_withtag( tagOrId)
    """
    return self.find( 'withtag', tagOrId )

  def find_withtype( self, type, *tagOrId ):
    """
    listItems=zinc.find_withtype( type, ?tagOrId?)
    """
    return self.find( 'withtype', type, *tagOrId )


  def fit( self, *args ):
    """
    listControls=zinc.fit(coordList,error)
    """
    return self.tk.call( self._w, 'fit', *args )
    
  def focus( self, *args ):
    """
    zinc.focus(tagOrId, ?itemPart?)
    """
    self.tk.call( self._w, 'focus', *args )

  def gdelete( self, *args ):
    """
    zinc.gdelete(gradientName)
    """
    self.tk.call( self._w, 'gdelete', *args )

  def gettags( self, *args ):
    """
    listTags=zinc.gettags(tagorid)
    """
    return self.tk.splitlist( self.tk.call( self._w, 'gettags', *args ) )

  def gname( self, *args ):
    """
    zinc.gname(gradientDesc, gradientName)
    bExist=zinc.gname(gradientName)
    """
    return self.tk.call( self._w, 'gname', *args )
  
  def group( self, *args ):
    """
    group=zinc.group(tagOrId)
    """
    return self.tk.call( self._w, 'group', *args )

  def hasanchors( self, *args ):
    """
    bool=zinc.hasanchors(tagOrId)
    """
    return self.tk.call( self._w, 'hasanchors', *args )

  def hasfields( self, *args ):
    """
    bool=zinc.hasfields(tagOrId)
    """
    return self.tk.call( self._w, 'hasfield', *args )

  def hastag( self, *args ):
    """
    bool=zinc.hastag(tagOrId, tag)
    """
    return self.tk.call( self._w, 'hastag', *args )

  def index( self, *args ):
    """
    num = zinc.index(tagOrId, index)
    """
    return self.tk.call( self._w, 'tagOrId', *args )

  def insert( self, *args ):
    """
    zinc.insert(tagOrId, before, string)
    """
    self.tk.call( self._w, 'insert', *args )

  def itemcget( self, tagOrId, option ):
    """
    val=zinc.itemcget(tagOrId, attr)
    """
    return self.tk.call( self._w, 'itemcget', tagOrId, '-'+option )

  def itemfieldget( self, tagOrId, field, option ):
    """
    val=zinc.itemcget(tagOrId, field, attr)
    """
    return self.tk.call( self._w, 'itemcget', tagOrId, field, '-'+option )

  def itemconfigure( self, tagOrId, field=None, **kw ):
    '''
    either get the dictionnary of possible attributes (if kw is None)
    either allow to set Items attributes or Field attributes
    
    listAttribs=zinc.itemconfigure(tagOrId)
    listAttribs=zinc.itemconfigure(tagOrId, attrib)
    zinc.itemconfigure(tagOrId, **attributs)
    listAttribs=zinc.itemconfigure(tagOrId, fieldIs, attrib)
    zinc.itemconfigure(TagOrId,fieldId,**attributs)
    '''
    if not kw:
      cnf = {}
      for var_x in self.tk.split( 
        field != None and self.tk.call( self._w, 'itemconfigure', 
                          ( tagOrId, field ) ) or
        self.tk.call( self._w, 'itemconfigure', ( tagOrId, ) ) ):
        cnf[var_x[0][1:]] = ( var_x[0][1:], ) + var_x[1:]
      return cnf
    if field != None:
      args = ( tagOrId, str( field ), )+ self._options( {}, kw )
      self.tk.call( self._w, 'itemconfigure', *args )
    else:
      args = ( tagOrId, ) + self._options( {}, kw )
      self.tk.call( self._w, 'itemconfigure', *args )

  # _dp voir si cette instruction est a execute ici
  # permet de creer un synonyme de itemconfigure
  itemconfig = itemconfigure

  def loweritem( self, *args ):
    """
    zinc.loweritem(tagOrId)
    zinc.loweritem(tagOrId, belowThis)
    Reorder all the items given by tagOrId so that
    they will be under the item given by belowThis.
    If tagOrId name more than one item,
    their relative order will be preserved.
    If tagOrId doesn't name an item, an error is raised.
    If  belowThis name more than one item, the bottom most them is used.
    If belowThis  doesn't name an item, an error is raised.
    If belowThis is omitted the items are put
    at the bottom most position of their respective groups.
    The command ignore all items named by tagOrId
    that are not in the same group than belowThis or,
    if not specified, in the same group than the first item
    named by tagOrId. The command returns an empty string.
    As a side affect of this command, the -priority  attribute
    of all the reordered items is ajusted to match the priority
    of the  belowThis item (or the priority of the bottom most item)
    """
    self.tk.call( self._w, 'lower', *args )

  def monitor( self, *args ):
    """
    bool = zinc.monitor()
    zinc.monitor(bool)
    """
    return self.tk.call( self._w, 'monitor', *args )

  def numparts( self, *args ):
    """
    num = zinc.numparts(tagOrId)
    """
    return self.tk.call( self._w, 'numparts', *args )

  def postcript( self, *args ):
    """
    Not Yet Implemented
    zinc.postscript()
    """
    return self.tk.call( self._w, 'postscript', *args )

  def raiseitem( self, *args ):
    """
    Correspond à l'appel raise de la documentation
    le mot raise est reservé en python
    zinc.raiseitem(tagOrId)
    zinc.raiseitem(tagOrId, aboveThis)
    """
    self.tk.call( self._w, 'raise', *args )

  def remove( self, *args ):
    """
    zinc.remove(tagOrId, ?tagOrId,...?)
    """
    self.tk.call( self._w, 'remove', *args )
  
  def rotate( self, *args ):
    """
    zinc.rotate(tagOrId, angle)
    zinc.rotate(tagOrId, angle, centerX, centerY)
    """
    self.tk.call( self._w, 'rotate', *args )

  def __oldscale( self, xFactor=None, yFactor=None, tagOrId=None ):
    if yFactor == None:
      return self.tk.getdouble( self.tk.call( 'scale' ) )
    else:
      if tagOrId == None:
        self.tk.call( self._w, 'scale', xFactor, yFactor )
      else:
        self.tk.call( self._w, 'scale', tagOrId, xFactor, yFactor )

  def scale( self, *args ):
    """
    zinc.scale(tagOrIdOrTName, xFactor, yFactor)
    zinc.scale(tagOrIdOrTName, xFactor, yFactor, centerX, centerY)
    Add a scale factor to the items or the transform described
    by tagOrId.
    If  tagOrId describes a named transform then this transform
    is used to do the operation. If tagOrId describes more than
    one item then all the items are affected by the operation.
    If tagOrId describes neither a named transform nor an item,
    an error is raised.
    A separate factor is specified for X and Y.
    The optional parameters describe the center of scaling,
    which defaults to the origin.
    """
    if not len( args ):
      return self.tk.getdouble( self.tk.call( self._w, 'scale' ) )
    else:
      self.tk.call( self._w, 'scale', *args )
        
  def select( self, *args ):
    """
    zinc.select('adjust', tagOrId, index)
    Adjust the end of the selection in tagOrId
    that is nearest to the character given by index so
    that it is at index.
    The other end of the selection is made the anchor
    for future select to commands.
    If the selection is not currently in tagOrId,
    this command behaves as the select to command.
    The command returns an empty string.
    zinc.select('clear')
    Clear the selection if it is in the widget.
    If the selection is not in the widget,
    the command has no effect. Return an empty string.
    zinc.select('from', tagOrId, index)
    Set the selection anchor point for the widget
    to be just before the character given by index
    in the item described by tagOrId.
    The command has no effect on the selection,
    it sets one end of the selection so that future
    select to can actually set the selection.
    The command returns an empty string.
    (item,part) = zinc.select('item')
    Returns a list of two elements.
    The first is the id of the selected item
    if the selection is in an item on this widget;
    Otherwise the first element is an empty string.
    The second element is the part of the item
    (track, waypoint or tabular item only) or the empty string.
    zinc.select('to', tagOrId, index)
    Set the selection to be the characters that lies
    between the selection anchor and  index in the item described
    by tagOrId. The selection includes the character given
    by index and includes the character given by the anchor point
    if  index is greater or equal to the anchor point.
    The anchor point is set by the most recent select adjust
    or select from command issued for this widget.
    If the selection anchor point for the widget is not currently
    in tagOrId, it is set to the character given by index.
    The command returns an empty string.
    Manipulates the selection as requested by option.
    tagOrId describes the target item.
    This item must support text indexing and selection. I
    f more than one item is referred to by tagOrId,
    the first in display list order that support both text
    indexing and selection will be used.
    Some forms of the command include an index  parameter,
    this parameter describes a textual position within the
    item and should be a valid index as described in
    Text indices.
    """
    return self.tk.call( self._w, 'select', *args )

  def skew( self, *args ):
    """
    zinc.skew(tagOrIdOrTName,xSkewAngle, ySkewAngle)
    Add a skew (or shear) transform to the to the items
    or the transform described by tagOrIdOrTName.
    If tagOrId describes a named transform then this transform
    is used to do the operation.
    If tagOrId describes more than one item then all the
    items are affected by the operation.
    If tagOrId describes neither a named transform nor an item,
    an error is raised. The angles are given in radian.
    """
    return self.tk.call( self._w, 'skew', *args )

  def smooth( self, *args ):
    """
    zinc.smooth(coordList)
    This command computes a sequence of segments
    that will smooth the polygon described by the vertices
    in coordList and returns a list of lists describing points
    of the generated segments. These segments are approximating
    a Bezier curve. coordList should be either a flat list
    of an even number of coordinates in x, y order, or a list
    of lists of point coordinates X, Y.
    The returned list can be used to create or change the contour
    of a curve item.
    """
    return self.tk.call( self._w, 'smooth', *args )

  def tapply( self, *args ):
    """
    Not Yet Implemented
    zinc.tapply()
    """
    return self.tk.call( self._w, 'tapply', *args )

  def tcompose( self, *args ):
    """
    zinc.tcompose(tagOrIdOrTName, tName)
    zinc.tcompose(tagOrIdOrTName, tName, invert)
    """
    return self.tk.call( self._w, 'tapply', *args )

  def tdelete( self, *args ):
    """
    zinc.tdelete(tName)
    Destroy a named transform.
    If the given name is not found among the named transforms,
    an error is raised.
    """
    self.tk.call( self._w, 'tdelete', *args )
  
  def transform( self, *args ):
    """
    listCoords=zinc.transform(tagOrIdTo, coordList)
    listCoords=zinc.transform(tagOrIdFrom, tagOrIdTo, coordList)
    This command returns a list of coordinates obtained by transforming the coordinates given in coordList
    from the coordinate space of the transform or item described by tagOrIdFrom to the coordinate space
    of the transform or item described by  tagOrIdTo.
    If tagOrIdFrom is omitted it defaults to the window coordinate space.
    If either tagOrIdFrom or tagOrIdTo describes more than one item,
    the topmost in display list order is used. If either tagOrIdFrom or tagOrIdTo
    doesn't describe either a transform or an item, an error is raised.
    The coordList should either be a flat list containing an even number of coordinates
    each point having two coordinates, or a list of lists each sublist of the form [ X Y ?pointtype? ].
    The returned coordinates list will be isomorphic to the list given as argument. 

    It is possible to convert from window coordinate space to the coordinate space of any item.
    This is done by omitting ?tagOrIdFrom? and specifying in tagOrIdTo, the id of the item.
    It can also be done by using the predefined tag 'device' as first argument. 

    It is also possible to convert from the coordinate space of an item to the window coordinate
    space by using the predefined tag 'device' as second argument. 

    """
    return self._getdoubles( self.tk.call( self._w, 'transform', *args ) )

#ANCIENNE IMPLEMENTATION
  def __oldtranslate( self, dx=None, dy=None, tagOrId=None ):   
    if dx == None:
      return self._getints( self.tk.call( 'translate' ) )
    else:
      if tagOrId == None:
        self.tk.call( self._w, 'translate', dx, dy )
      else:
        self.tk.call( self._w, 'translate', tagOrId, dx, dy )

  def translate( self, *args ):
    """
    zinc.translate(tagOrIdOrTName, xAmount, yAmount)
    zinc.translate(tagOrIdOrTName, xAmount, yAmount, absolute)
    Add a translation to the items or the transform described by tagOrIdOrTName.
    If  tagOrIdOrTName describes a named transform then this transform is used
    to do the operation.
    If tagOrIdOrTName describes more than one item then all the items are affected
    by the opration.
    If tagOrIdOrTName describes neither a named transform nor an item,
    an error is raised. A separate value is specified for X and Y.
    If the optionnal ?absolute? parameter is true,
    it will set an absolute translation to the tagOrIdOrTName
    """
    if ( len( args ) == 1 ):
      return self._getints( self.tk.call( self._w, 'translate' ) )
    else:
      self.tk.call( self._w, 'translate', *args )

  def treset( self, *args ):
    """
    zinc.treset(tagOrIdOrTName)
    Set the named transform or the transform for the items described by tagOrIdOrTName
    to identity. If tagOrIdOrTName describes neither a named transform nor an item,
    an error is raised.
    """
    self.tk.call( self._w, 'treset', *args )
  
  def trestore( self, *args ):
    """
    zinc.trestore(tagOrId, tName)
    Set the transform for the items described by tagOrId to the transform named by tName.
    If tagOrId doesn't describe any item or if the transform named  tName doesn't exist,
    an error is raised.
    """
    self.tk.call( self._w, 'trestore', *args )
  
  def tsave( self, *args ):
    """
    zinc.tsave(tName)
    zinc.tsave(tagOrIdOrTName, tName)
    zinc.tsave(tagOrIdOrTName, tName, invert)
    Create (or reset) a transform associated with the name tName
    with initial value the transform associated with the item tagOrIdOrTName.
    If tagOrIdOrTName describes more than one item, the topmost in display list order is used.
    If tagOrIdOrTName doesn't describe any item or named transformation, an error is raised.
    If tName already exists, the transform is set to the new value.
    This command is the only way to create a named transform.
    If tagOrIdOrTName is not specified, the command returns a boolean telling
    if the name is already in use.
    The invert boolean, if specified, cause the transform to be inverted prior to be saved. 

    It is possible to create a new named transformation from the identity
    by using the predefined tag 'identity': $zinc->tsave('identity', 'myTransfo'); 
    """
    return self.tk.call( self._w, 'tsave', *args )

  def tget( self, *args ):
    """
    zinc.tget(tagOrId)
    zinc.tget(tagOrIdOrTName, selector)
    selector:={'all'|'translation'|'scale'|'rotation'|'skew'}
    With only one argument, get the six elements of the 3x4 matrix
    used in affine transformation for tagOrIdOrTName.
    The result is compatible with the tset method.
    With optional second parameter 'all' returns the transform
    decomposed in translation, scale, rotation, skew
    and return the list in this order,
    With 'translation', 'scale', 'rotation', 'skew' optional
    second parameter, returns the corresponding values.
    """
    return self.tk.call( self._w, 'tget', *args )
    
  def tset( self, *args ):
    """
    zinc.tset(tagOrIdOrName, m00, m01, m10, m11, m20, m21)
    Set the six elements of the 3x4 matrix used in affine transformation for tagOrIdOrTName.
    BEWARE that depending on mij values,
    it is possible to define a not inversible matrix which will end up in core dump.
    This method must BE USED CAUTIOUSLY.
    """
    return self.tk.call( self._w, 'tset', *args )

  def type( self, tagOrId ):
    """
    name=zinc.type(tagOrId)
    If more than one item is named by tagOrId,
    then the type of the topmost item in display list order is returned.
    If no items are named by tagOrId, an error is raised.
    """
    return self.tk.call( self._w, 'type', tagOrId )

  def vertexat( self, *args ):
    """
    (contour,vertex,edgevertex)=zinc.vertexat(tagOrId,x,y)
    """
    return self.tk.call( self._w, 'vertexat', *args )

  def xview(self, *args):
      """Query and change horizontal position of the view."""
      if not args:
          return self._getdoubles(self.tk.call(self._w, 'xview'))
      self.tk.call((self._w, 'xview') + args)
  def xview_moveto(self, fraction):
      """Adjusts the view in the window so that FRACTION of the
      total width of the canvas is off-screen to the left."""
      self.tk.call(self._w, 'xview', 'moveto', fraction)
  def xview_scroll(self, number, what):
      """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
      self.tk.call(self._w, 'xview', 'scroll', number, what)
  def yview(self, *args):
      """Query and change vertical position of the view."""
      if not args:
          return self._getdoubles(self.tk.call(self._w, 'yview'))
      self.tk.call((self._w, 'yview') + args)
  def yview_moveto(self, fraction):
      """Adjusts the view in the window so that FRACTION of the
      total height of the canvas is off-screen to the top."""
      self.tk.call(self._w, 'yview', 'moveto', fraction)
  def yview_scroll(self, number, what):
      """Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
      self.tk.call(self._w, 'yview', 'scroll', number, what)

class ZincItem:
  def __init__( self, zinc, itemType, group = 1, *args, **kw ):
    self.zinc  = zinc
    texture    = None
    fillpatern = None
    scale      = None
    translate  = None
    if kw.has_key( 'texture' ):
      texture = kw['texture']
      del kw['texture']

    if kw.has_key( 'fillpatern' ):
      fillpastern = kw['fillpatern']
      del kw['fillpatern']

    if kw.has_key( 'scale' ):
      scale = kw['scale']
      del kw['scale']

    if kw.has_key( 'rotate' ):
      rotate = kw['rotate']
      del kw['rotate']

    if kw.has_key( 'translate' ):
      translate = kw['translate']
      del kw['translate']
      
    if kw.has_key( 'cloneid' ):
      cloneid = kw['cloneid']
      del kw['cloneid']
    else:
      cloneid = 0 
    group = str( group )
    #        sys.stdout.flush()
    if cloneid == 0 :
      self.id = zinc.add( itemType, group, *args, **kw )
    else :
      self.id = self.zinc.clone(cloneid, *args, **kw)

    zinc.items[self.id] = self
    texture = None
    if fillpatern:
      self.itemconfigure( fillpatern )
    if scale:
      self.scale( scale )     
    if translate:
      self.translate( translate )
    
    
  def __str__( self ):
    return str( self.id )

  def __repr__( self ):
    return str( self.id )

  def bbox( self, *args ):
    return self.zinc.bbox( self.id, *args )
  
  def clone( self, *args, **kw):
    '''id = zincitem.clone(*args,**kw) '''
    # print "ZincItem::clone"
        # on cherche tagOrId
    # nidcloned = self.find_above(tagOrId)
    sclonedtype = self.type()
    sclonedgroupid = self.zinc.group(self.id)

    # ajout cle 'cloneid' (voir ZincItem::__init__) 
    kw['cloneid'] = self.id
        # on cree un nouveau ZincItem meme type,
    return(ZincItem(self.zinc, sclonedtype, sclonedgroupid, **kw ))
  
  def delete( self ):
    del self.zinc.items[self.id]
    try:
      self.zinc.remove( self.id )
    except:
      pass
  def __getitem__( self, key ):
    '''allow to get attribute by self["key"] '''
    if ( key == "coords" ):
      return self.zinc.coords( self.id )
    return self.zinc.itemcget( self.id, key )

  def __setitem__( self, key, value ):
    '''allow to set item attrbutes, eg. for a track position attributes
    just writing :
    a = ZincItem(myzinc, ...)
    a["position"]    = (x,y)
    Notes : when setting multiple attributes
    using itemconfigure is more efficient '''
    if ( key is "coords" ):
      self.zinc.coords( self.id, value )
    else:
      self.zinc.itemconfigure( self.id, **{key:value} )
      
  def getGroup( self ):
    groupid = self.zinc.group( self.id )
    return self.zinc.items[groupid]
    
  def keys( self ):
    if not hasattr( self, '_keys' ):
      self._keys = {}
      config = self.zinc.itemconfig( self.id )
      for x in config.keys():
        self._keys[x] = config[x][1]
    return self._keys

  def has_key( self, key ):
    return key in self.keys()

  def bind( self, sequence=None, command=None, add=None ):
    '''return a funcid which can be used to unbind
notes: unbinding can be done by bind("<seq>","") or using native tkinter
unbind method '''
    return( self.zinc.bind_tag( self.id, sequence, command, add ) )
    
  def cget( self, attr ):
    return self.zinc.itemcget( self.id, attr )
       
  def coords( self, *args, **kw ):
    return self.zinc.coords( self.id, *args, **kw )

  def fieldcget( self, field, attr ):
    return self.zinc.itemfieldcget( self.id, field, attr )

  def itemconfigure( self, field=None, **kw ):
    self.zinc.itemconfigure( self.id, field, **kw )

  def rotate( self, *args ):
    return self.zinc.rotate( self.id, *args )
  
  def scale( self, *args ):
    return self.zinc.scale( self.id, *args )

  def transforms( self, *args ):
    """
    zincitem.transform(tozincitem, coordList)
    This command returns a list of coordinates obtained by transforming the coordinates given in coordList
    from the coordinate space of item to the coordinate space
    of the tozincitem item.
    The coordList should either be a flat list containing an even number of coordinates
    each point having two coordinates, or a list of lists each sublist of the form [ X Y ?pointtype? ].
    The returned coordinates list will be isomorphic to the list given as argument. 
    """
    return self.zinc.transforms( self.id, *args )

  def translate( self, *args ):
    """
    zincitem.translate( xAmount, yAmount)
    zincitem.translate( xAmount, yAmount, absolute)
    Add a translation to the item.
    A separate value is specified for X and Y.
    If the optionnal ?absolute? parameter is true,
    it will set an absolute translation to the item   
    """
    self.zinc.translate( self.id, *args )

  def tset( self, *args ):
    """
    zincitemtset(m00, m01, m10, m11, m20, m21)
    Set the six elements of the 3x4 matrix used in affine transformation.
    BEWARE that depending on mij values,
    it is possible to define a not inversible matrix which will end up in core dump.
    This method must BE USED CAUTIOUSLY.     
    """
    self.zinc.tset( self.id, *args )

  def type( self ):
    """
    name=zincitemtype()
    This command returns the type of the item.
    """
    return self.zinc.type( self.id )

  def tsave( self, *args ):
    """
    zincitemtsave( tName)
    zincitemtsave( tName, invert)
    Create a transform associated with the name tName
    with initial value the transform associated with the item.
    If tName already exists, the transform is set to the new value.
    This command is the only way to create a named transform.
    The invert boolean, if specified, cause the transform to be inverted prior to be saved. 
    """
    return self.zinc.tsave( self.id, *args )

  def treset( self, *args ):
    """
    zincitemtreset()
    Set the named transform or the transform for the item
    to identity. If there are no named transform,
    an error is raised.
    """
    self.zinc.treset( self.id, *args )
    
  def trestore( self, *args ):
    """
    zincitemtrestore( tName)
    Set the transform for the item to the transform named by tName.
    If the transform named  tName doesn't exist, an error is raised.
    """
    self.zinc.trestore( self.id, *args )
    
  def tget( self, *args ):
    """
    zincitemtget()
    zincitemtget(selector)
    selector:={'all'|'translation'|'scale'|'rotation'|'skew'}
    With only one argument, get the six elements of the 3x4 matrix
    used in affine transformation.
    The result is compatible with the tset method.
    With optional second parameter 'all' returns the transform
    decomposed in translation, scale, rotation, skew
    and return the list in this order,
    With 'translation', 'scale', 'rotation', 'skew' optional
    second parameter, returns the corresponding values.
    """   
    return self.zinc.tget( self.id, *args )


class Arc( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        """
        The arc type expects a list of four floating point numbers xo yo xc yc,
        giving the coordinates of the origin and the corner of the enclosing rectangle.
        The origin should be the top left vertex of the enclosing rectangle and the corner
        the bottom right vertex of the rectangle.
        """
        ZincItem.__init__( self, zinc, 'arc', *args, **kw )    

class Group( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        """
        These type do not expect type specific arguments.
        """
        ZincItem.__init__( self, zinc, 'group', *args, **kw )    

    def getGroup( self ):
        """Retourne l'objet de type Group
        auquel est attache l'item"""
        ###Gestion du boostrap
        if self.id == 1:
            return self.zinc.items[1]
        else:
            return ZincItem.getGroup( self )

  #TODO: Extension. Renvoie les références aux ZincItems contenus dans le Groupe
    def getNode( self ):
        """
        """
        pass
            
class Icon( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        """
        These type do not expect type specific arguments.
        """
        ZincItem.__init__( self, zinc, 'icon', *args, **kw )    

class Map( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        """
        These type do not expect type specific arguments.
        """
        ZincItem.__init__( self, zinc, 'map', *args, **kw )
  
class Curve( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        """
        The curve type expects either a flat list or a list of lists.
        In the first case, the flat list must be a list of floating point numbers
        x0 y0 x1 y1 ... xn yn, giving the coordinates of the curve vertices.
        The number of values should be even (or the last value will be discarded)
        but the list can be empty to build an empty invisible curve.
        In the second case,thelist must contain lists of 2 or 3 elements:
        xi, yi and and an optionnal point type. Currently,
        the only available point type is 'c' for a cubic bezier control point.
        For example, the following list is an example of 2 beziers segments
        with a straight segment in-between:
        ( [x0, y0], [x1, y1, 'c'], [x2, y2, 'c'], [x3, y3], [x4, y4, 'c'], [x5, y5] )
        
        As there is only on control point, [x4, y4, 'c'] ,
        for the second cubic bezier,
        the omitted second control point will be defaulted to the same point.
        a named tuple contours can give to define new contours in curve.
        contours=(<contour1>,...)
        <contour>=(<point1>,...)
        A curve can be defined later with the contour or coords commands.
        As a side effect of the curve behavior,
        a one vertex curve is essentially the same as an empty curve,
        it only waste some more memory.
        
        """
        contours = []
        if kw.has_key( 'contours' ):
            contours = kw['contours']
            del kw['contours']
        ZincItem.__init__( self, zinc, 'curve', *args, **kw )
        for contour in contours:
            self.zinc.contour( self.id, *contour )
    

class Rectangle( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        """
        The rectangle type expects a list of four floating point numbers xo yo xc yc,
        giving the coordinates of the origin and the corner of the rectangle.
        """
        ZincItem.__init__( self, zinc, 'rectangle', *args, **kw )    

class Reticle( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        """
        These type do not expect type specific arguments.
        """
        ZincItem.__init__( self, zinc, 'reticle', *args, **kw )    

class Tabular( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        ZincItem.__init__( self, zinc, 'tabular', *args, **kw )    

class Text( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        """
        These type do not expect type specific arguments.
        """
        ZincItem.__init__( self, zinc, 'text', *args, **kw )    

class Track( ZincItem ):
    def __init__( self, zinc, *args, **kw ):
        ZincItem.__init__( self, zinc, 'track', *args, **kw )
  
class WayPoint( ZincItem ):
  def __init__( self, zinc, *args, **kw ):
    ZincItem.__init__( self, zinc, 'waypoint', *args, **kw )
  

# Class to hold mapinfos used by the Map Item class 
class Mapinfo:
    def __init__( self, interp, name = None ):
        """
        @type name: string
        @param name: Name of mapinfo. Must be used carrefully !
        Create a new empty map description.
        The new mapinfo object named name or internal id if name is omitted
        """
        if name :
            self.name = name
        else:
            self.name = `id( self )`
            self.interp = interp.tk
            apply( self.interp.call, ( 'mapinfo', self.name, 'create' ) )
    
    def __repr__( self ):
        return self.name

    def __del__( self ):
        self.delete()

    def delete( self ):
        """
        Delete the mapinfo object.
        All maps that refer to the deleted mapinfo are updated to reflect the change.
        """
        self.interp.call( 'mapinfo', self.name, 'delete' )


    def duplicate( self, *args ):
        """
        B{Optional}
        @type name: Name of the new mapinfo
        @param name: Must be use carrefully !!
        Create a new mapinfo that is a exact copy of this mapinfo Object.
        """
        classe = Mapinfo
        obj = new.instance( classe )
        if len( args ):
            new_name = args[0]
        else:
            new_name = str( obj )
        self.interp.call( 'mapinfo', self.name, 'duplicate', new_name )
        return obj
    
    def add_text( self, text_style, line_style, x, y, text ):
        """
        Add a new graphical element to the mapinfo object text. 
        This element describes a line of text.
        @type text_style: {normal|underlined}
        @param text_style: text style 
        @type line_style: string
        @param line_style: a line style (simple, dashed,  dotted, mixed, marked) to be used for the underline
        @type X: int
        @param X: Coord on X axe
        @type Y: int
        @param Y: Coord on Y axe
        @type text: string
        @param : a string describing the text.
    
        """
        self.interp.call( 'mapinfo', self.name, 'add', 'text', text_style, 
                         line_style, x, y, text )

    def add_line( self, line_style, width, x1, y1, x2, y2 ):
        """
        Add a new graphical element to the mapinfo object line.
        This element describes a line segment.
        @type line_style: {simple|dashed|dotted|mixed|marked}
        @param line_style: a line style
        @type width: int
        @param width: the line width in pixels
        @type x1: int
        @param x1: coords on X axe
        @type x2: int
        @param x2: coords on Y axe
        @type x3: int
        @param x3:  end vertices on X axe
        @type x4: int
        @param x4: end vertices on Y axe
        four integer values setting the X and Y coordinates of the two end vertices.
        """
        self.interp.call( 'mapinfo', self.name, 'add', 'line', line_style, 
                         width, x1, y1, x2, y2 )

    def add_arc( self, line_style, width, cx, cy, radius, start, extent ):
        """
        Add a new graphical element to the mapinfo object arc.
        
        @type line_style: {simple|dashed|dotted|mixed|marked}
        @param line_style: a line style
        @type width: int 
        @param width: the line width in pixels
        @type cx: int
        @param cx: X of arc center
        @type cy: int 
        @param cy: Y of arc center
        @type radius: int 
        @param radius: the arc radius
        @type start: int
        @param start: the start angle (in degree)
        @type extent: int
        @param extent: the angular extent of the arc (in degree).
        
        """
        self.interp.call( 'mapinfo', self.name, 'add', 'arc', line_style, 
                         width, cx, cy, radius, start, extent )
        
    def add_symbol( self, x, y, index ):
        """
        Add a new graphical element to the mapinfo object symbol.
        @type x: int
        @param x: position on X
        @type y: int
        @param y: position on Y
        
        @type index: int
        @param : an integer setting the symbol index in the -symbols list of the map item
        
        """
        self.interp.call( 'mapinfo', self.name, 'add', 'symbol', x, y, index )
    
    def count( self, type ):
        """
        @type type: {text|arc|line|symbol}
        @param type:
        Return an integer value that is the number of elements matching type in the mapinfo.
        type may be one the legal element types   
        """
        return self.interp.call( 'mapinfo', self.name, 'count', type )
    
    def get( self, type, index ):
        """
        Return the parameters of the element at index with type type in the mapinfo.
        The returned value is a list.
        The exact number of parameters in the list and their meaning depend on type and is accurately described in mapinfo add.
        type may be one the legal element types as described in the mapinfo add command.
        Indices are zero based and elements are listed by type.
        """
        return self.interp.call( 'mapinfo', self.name, 'remove', type, index )

    def replace( self, type, index, *args ):
        """
        Replace all parameters for the element at index with type type in the mapinfo.
        The exact number and content for args depend on  type and is accurately described in mapinfo add.
        type may be one the legal element types as described in the mapinfo add command.
        Indices are zero based and elements are listed by type.
        """
        return self.interp.call( 'mapinfo', self.name, 'replace', 
                 type, index, args )

    def remove( self, type, index ):
        """
        Remove the element at index with type type in the mapinfo.
        type may be one the legal element types as described in the mapinfo add command. Indices are zero based and elements are listed by type.
        """
        return self.interp.call( 'mapinfo', self.name, 'remove', type, index )
    
    def scale( self, factor ):
        """
        """
        self.interp.call( 'mapinfo', self.name, 'scale', factor )
        
    def translate( self, xAmount, yAmount ):
        """
        """
        self.interp.call( 'mapinfo', self.name, 'translate', xAmount, yAmount )
    
class Videomap ( Mapinfo ):
    """
    create a mapinfo from a proprietary
    file format for simple maps, in use in french Air Traffic Control Centres. The format is the
    binary cautra4 (with x and y in 1/8nm units) 
    """
    def __init__( self, tk, *args ):
        """
        @type  filename: 
        @param filename:
        @type  mapinfoname: 
        @param mapinfoname: 
        Load the videomap sub-map located at position index in the file named  fileName into a mapinfo object named mapInfoName. It is possible, if needed, to use the videomap ids command to help translate a sub-map id into a sub-map file index.
        """
        self.tk = tk.tk
        args    = args + ( self, )
        self.tk.call( 'videomap', 'load', *args )
        

    def ids( self, filename ):
        """
        @type  filename: string
        @param filename: filename where to search syb-map
        B{Class Method}
        Return all sub-map ids that are described in the videomap file described by  fileName.
        The ids are listed in file order. This command makes possible to iterate through a videomap file
        one sub-map at a time, to know how much sub-maps are there and to sort them according to their ids.
        """
        return self.tk.call( 'videomap', 'ids', filename )

class Colors:
  """
  Classe abstraite utilitaire permettant de gérer sous forme d'objet
  les couleurs aux formats Zinc
  """
  def __init__( self ):
    self.lColors = []
  
  #TODO:
  def getColorsIter( self ):
    """
    Renvoie un itérateur sur les couleurs
    """
    return self.lColors.__iter__()
    
    def addColor( self, color, alpha = 100, 
           colorposition = 0, mid_span_position = 50 ):
      self.lColors.append( ( color, alpha, colorposition, mid_span_position ) )

  def __repr__( self ):
    res = ""
    for i in self.lColors:
      res = "%s%s;%s %s %s|" % ( res, i[0], i[1], i[2], i[3] )
    return res[:-1]
    
class AxialGradientColor( Colors ):
    def __init__( self, *params ):
        """
        params : degre or  x1, y1, x2, y2 which define angle and extension of the axe
        =axial degre | gradient_step1 | ... | gradient_stepn or
        =axial x1 y1 x2 y2 | gradient_step1 | ... | gradient_stepn
        """
        Colors.__init__( self )
        count = 0
        self.params = ""
        for i in params:
            self.params = "%s %s" % ( self.params, str( i ) )
            count += 1
        if ( count != 1 ) and ( count != 4 ):
            raise Exception( "Bad Format of params %s" % count )
        
    def __repr__( self ):
        res = "=axial %s" % self.params
        if not ( len( self.lColors ) ):
            raise Exception( "Bad Format, must have  one color less" )
        res = "%s | %s" % ( res, Colors.__repr__( self ) )
        return res
                
class RadialGradientColor( Colors ):
    def __init__( self, *params ):
        """
        =radial x y | gradient_step1 | ... | gradient_stepn  or
        =radial x1 y1 x2 y2 | gradient_step1 | ... | gradient_stepn
        The x y parameters define the center of the radial.
        The x1 y1 x2 y2 parameters define both the center and the extension of the radial.
        """
        Colors.__init__( self )
        count = 0
        self.params = ""
        for i in params:
            self.params = "%s %s" % ( self.params, str( i ) )
            count += 1
        if ( ( count!= 2 ) and ( count != 4 ) ):
            raise Exception( "Bad Format of params %s"%count )
        
    def __repr__( self ):
        res = "=radial %s " % self.params
        if not ( len( self.lColors ) ):
            raise Exception( "Bad Format, must have  one color less" )
        res = "%s | %s" % ( res, Colors.__repr__( self ) )
        return res

class PathGradientColor( Colors ):
    def __init__( self, *params ):
        """
    =path x y | gradient_step1 | ... | gradient_stepn
    The x y parameters define the center of the gradient. 
        """
        Colors.__init__( self )
        count       = 0
        self.params = ""
        for i in params:
            self.params = "%s %s" % ( self.params, str( i ) )
            count += 1
        if ( count != 2 ):
            raise Exception( "Bad Format of params %s" % count )
        
    def __repr__( self ):
        res = "=path %s " % self.params
        if not ( len( self.lColors ) ):
            raise Exception( "Bad Format, must have  one color less" )
        res = "%s | %s" % ( res, Colors.__repr__( self ) )
        return res

class ConicalGradientColor( Colors ):
    def __init__( self, *params ):
        """
        =conical degre | gradient_step1 | ... | gradient_stepn or
        =conical degre x y | gradient_step1 | ... | gradient_stepn or
        =conical x1 y1 x2 y2 | gradient_step1 | ... | gradient_stepn
        
        The degre parameter defines the angle of the cone in the usual trigonometric sense.
        The optional x y parameters define the center of the cone.
        By default, it is the center of the bounding-box.
        The x1 y1 x2 y2 parameters define the center and the angle of the cone.

        All x and y coordinates are expressed in percentage of the bounding box,
        relatively to the center of the bounding box.
        So 0 0 means the center while -50 -50 means the lower left corner of the bounding box. 

        If none of the above gradient type specification is given,
        the gradient will be drawn as an axial gradient with a null angle. 
        """
        Colors.__init__( self )
        count = 0
        self.params = ""
        for i in params:
            self.params = "%s %s" % ( self.params, str( i ) )
            count += 1
        if ( count != 1 ) and ( count != 3 ) and ( count != 4 ):
            raise Exception( "Bad Format of params %s" % count )
        
    def __repr__( self ):
        res = "=conical %s " % self.params
        if not ( len( self.lColors ) ):
            raise Exception( "Bad Format, must have  one color less" )
        res = "%s | %s" % ( res, Colors.__repr__( self ) )
        return res
                
        
# ---- self-test ----------------------------------------------------------
if __name__ == '__main__':
  from Tkinter import *
  import Zinc
  def createItem( zinc, group, ev ):
    print >> sys.stdout, "CreateIHM"
    sys.stdout.flush()
    Zinc.Rectangle( zinc, group, 
             ( 100, 100, 150, 150 ), 
             linewidth = "10", linecolor = '#FFFF00', 
             relief = "roundgroove", filled = 1, 
             fillcolor = "red", tags = ( "hello", "test" ) )
    sys.stdout.write( "hello_clic" + str( ev ) )
    
  z  = Zinc.Zinc( master = None, render = 1, height = 200, width = 400 )
  g1 = Zinc.Group( z, 1 ) 
  r  = Zinc.Rectangle( z, g1, ( 0, 0, 400, 200 ), 
                 linewidth = "10", 
                 linecolor = '#FFFF00', 
                 relief    = "roundgroove", 
                 filled    = 1, 
                 fillcolor = "#FFFFFF", 
                 tags      = ( "hello", "test" ) )
  t = Zinc.Text( z, g1, position = ( 40, 100 ), text = z.version )
# z.bind_tag("hello","<1>",lambda ev,z=z,g=g1 : createItem(z,g,ev)) 
  z.configure( backcolor = 'black' )
  z.pack()
  z.mainloop()

# Zinc.py ends here