-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPNP_Curio.py
2456 lines (2143 loc) · 84.2 KB
/
PNP_Curio.py
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
#!/usr/bin/python
About_Text="""
Copyright (C) 2020-2021 Jesus Calvino-Fraga
jesuscf (at) gmail.com
This program is free software; you can redistribute
it and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General
Public License along with this program; if not, write
to the Free Software Foundation, 59 Temple Place -
Suite 330, Boston, MA 02111-1307, USA.
"""
import globalvars as g
from globalvars import *
import sys
from threading import *
import math
import subprocess
sys.path.insert(0, './Symbols')
if sys.version_info[0] < 3:
import Tkinter
from Tkinter import *
import tkMessageBox
import tkFileDialog
else:
import tkinter as Tkinter
from tkinter import *
from tkinter import messagebox as tkMessageBox
from tkinter import filedialog as tkFileDialog
from tkinter import simpledialog
import vectortext
import label
import wire
import os
import string
import colordialog
import ToolTip # Taken from IDLE source code
import Curio
from Curio import *
import time
import datetime
def initlocals():
global selected_symbol_list, click_x, click_y
global selected, selected_item, selected_label_list, selected_wire_list
global scounter, resize_canvas, ctrlkey, wiremode
global undu_list, undu_ctr
global Curio_in_Use, abort_PnP, pause_PnP, wires_hidden
global PnP_X_Offset, PnP_Y_Offset
global prev_file_modified, file_modified
selected_symbol_list=[]
selected_label_list=[]
selected_wire_list=[]
click_x=0
click_y=0
selected=0
selected_item=0
scounter=0
resize_canvas = 1
ctrlkey=0
Curio_in_Use=0
abort_PnP=0
pause_PnP=0
wires_hidden=0
PnP_X_Offset=0.0
PnP_Y_Offset=0.0
file_modified=False
prev_file_modified=True # Used to know when to update the title bar
def addundo(toremove, toadd):
global undo_list_toadd, undo_list_toremove, undo_ctr
global filename
global file_modified
if toadd==toremove:
return
del undo_list_toremove[undo_ctr:]
del undo_list_toadd[undo_ctr:]
undo_list_toremove.append(toremove)
undo_list_toadd.append(toadd)
undo_ctr+=1
file_modified=True
def do_undo(event=None):
global undo_list_toadd, undo_list_toremove, undo_ctr, selected_item
global selected_symbol_list, selected_label_list, selected_wire_list
global filename
global file_modified
# print ("Undo level is %d" % (undo_ctr)) # for testing
if(undo_ctr>0):
file_modified=True
undo_ctr-=1
else:
return # nothing to undo
# Deselect everything
selected_item=0
for item in selected_symbol_list:
item.select(False)
for item in selected_wire_list:
item.select(False)
selected_symbol_list=[]
selected_label_list=[]
selected_wire_list=[]
s1=''.join(undo_list_toadd[undo_ctr])
addlist=s1.split('\n')
# Remove all the symbols that were added
for elem in addlist:
for item in g.symbol_list:
s2=''.join(item.sym_ascii())
itemstr=s2.split('\n')
if itemstr[0]==elem:
g.symbol_list.remove(item)
item.clean()
del item
break # We found the added one. No need to keep looking
# Remove all the wires that were added
for elem in addlist:
for item in g.wire_list:
s2=''.join(item.sym_ascii())
itemstr=s2.split('\n')
if itemstr[0]==elem:
g.wire_list.remove(item)
item.clean()
del item
break # We found the added one. No need to keep looking
# add everything that was removed
loadfromstring(undo_list_toremove[undo_ctr], 0, False)
def do_redo(event=None):
global undo_list_toadd, undo_list_toremove, undo_ctr, selected_item
global selected_symbol_list, selected_label_list, selected_wire_list
global filename
global file_modified
l=len(undo_list_toadd)
if undo_ctr==l:
return # Nothing to redo
selected_item=0
for item in selected_symbol_list:
item.select(False)
for item in selected_wire_list:
item.select(False)
selected_symbol_list=[]
selected_label_list=[]
selected_wire_list=[]
s1=''.join(undo_list_toremove[undo_ctr])
addlist=s1.split('\n')
# re-remove what was removed
for elem in addlist:
for item in g.symbol_list:
s2=''.join(item.sym_ascii())
itemstr=s2.split('\n')
if itemstr[0]==elem:
g.symbol_list.remove(item)
item.clean()
del item
break # We found the one to remove. No need to keep looking
for elem in addlist:
for item in g.wire_list:
s2=''.join(item.sym_ascii())
itemstr=s2.split('\n')
if itemstr[0]==elem:
g.wire_list.remove(item)
item.clean()
del item
break # We found the one to remove. No need to keep looking
# re-add what was added
loadfromstring(undo_list_toadd[undo_ctr], 0, False)
undo_ctr+=1
file_modified=True
def B1Motion(event):
global click_x, click_y, selected_item, selected_symbol_list, selected_wire_list, ctrlkey
if ctrlkey:
return
if wiremode==True:
posx=canvas.canvasx(event.x)
posy=canvas.canvasy(event.y)
canvas.coords('ConstructionWire', (click_x, click_y, posx, posy))
return
if selected_symbol_list or selected_label_list or selected_wire_list:
posx=canvas.canvasx(event.x)
posy=canvas.canvasy(event.y)
# move the selected symbols and their pins. Don't move their labels.
for item in selected_symbol_list:
item.move_nl(posx-click_x, posy-click_y)
# now move the selected labels
for item in selected_label_list:
item.move(posx-click_x, posy-click_y)
for item in selected_wire_list:
item.move(posx-click_x, posy-click_y)
click_x=posx
click_y=posy
elif selected_item!=0:
posx=canvas.canvasx(event.x)
posy=canvas.canvasy(event.y)
selected_item.move(posx-click_x, posy-click_y)
click_x=posx
click_y=posy
else: # Creating a selection box
posx=canvas.canvasx(event.x)
posy=canvas.canvasy(event.y)
canvas.itemconfig('selection', outline=g.select_color)
canvas.coords('selection', (click_x, click_y, posx, posy))
def B1Release(event):
global click_x, click_y, selected_item, selected_symbol_list, selected_label_list, selected_wire_list, ctrlkey
global buff_toremove
# If we are adding wires:
if wiremode==True:
x0,y0,x1,y1=canvas.coords('ConstructionWire')
if x0!=x1 or y0!=y1: # If the wire has zero length, ignore it
# Search for a pin nearby. If found one nearby, change the corresponding end of the wire
for item in g.pin_list:
z=get_zoom()
a,b,c,d=canvas.coords(item.line)
if abs(a-x0)<5 and abs(a-y0)<5:
x0=a
y0=a
if abs(a-x1)<5 and abs(a-y1)<5:
x1=a
y1=a
newwire=wire.wire(canvas, x0/get_zoom(), y0/get_zoom(), x1/get_zoom(), y1/get_zoom(), '')
g.wire_list.append(newwire)
addundo('',newwire.sym_ascii())
canvas.delete('ConstructionWire')
return
if ctrlkey==1:
ctrlkey=0
elif selected_symbol_list or selected_label_list or selected_wire_list:
old_buff_toremove=buff_toremove[:]
for item in selected_symbol_list:
item.movetogrid()
for item in selected_wire_list:
item.movetogrid()
rebuild_buff_toremove()
addundo(old_buff_toremove, buff_toremove)
elif selected_item!=0: # Dealing just with one item
selected_item.movetogrid()
try:
addundo(buff_toremove, selected_item.parentsymbol.sym_ascii()) # for labels, we need to add the parent symbol
except:
addundo(buff_toremove, selected_item.sym_ascii()) # for everything else
else: # Just created a selection box...
xs1,ys1,xs2,ys2=canvas.coords('selection') # read the selection box rectangle
# Reset the list of selected items
selected_symbol_list=[]
selected_label_list=[]
selected_wire_list=[]
for item in g.label_list: # For all the labels in the list...
if item.visible!=0: # Important: only visible labels when its parent part is not moving!
# Check if the label rectangle is completely inside the selection box rectangle
x1,y1,x2,y2=canvas.coords(item.rect)
if ( (x1>=xs1 and x1<=xs2) and (y1>=ys1 and y1<=ys2) ) and ( (x2>=xs1 and x2<=xs2) and (y2>=ys1 and y2<=ys2) ):
selected_label_list.append(item)
else:
item.select(False)
else:
item.select(False)
for item in g.symbol_list: # For all the symbols in the list...
# Check if the symbol rectangle is completely inside the selection box rectangle. If so, select it
# and its labels!
x1,y1,x2,y2=canvas.coords(item.rect) # NEED TO CHANGE THIS BECAUSE IT DOESNT WORK WITH ROTATED SYMBOLS
if ( (x1>=xs1 and x1<=xs2) and (y1>=ys1 and y1<=ys2) ) and ( (x2>=xs1 and x2<=xs2) and (y2>=ys1 and y2<=ys2) ):
item.select(True)
selected_symbol_list.append(item)
for itemlabel in item.label_list:
# EXPERIMENT:
try:
canvas.itemconfigure(item.tag_fill, fill = get_select_color())
canvas.itemconfigure(item.tag_outline, outline = get_select_color())
except:
pass
if itemlabel not in selected_label_list:
selected_label_list.append(itemlabel)
if itemlabel.visible==0: # Important: Move invisible label with its parent part!
selected_label_list.append(itemlabel)
else:
item.select(False)
# EXPERIMENT:
try:
canvas.itemconfigure(item.tag_fill, fill = get_symbol_color())
canvas.itemconfigure(item.tag_outline, outline = get_symbol_color())
except:
pass
for item in selected_label_list:
item.select(True)
for item in g.wire_list: # For all the wires in the list...
# Check if the wire is completely inside the selection box rectangle or if one of the ends is inside the
# the selection rectangle.
x1,y1,x2,y2=canvas.coords(item.line)
if ( (x1>=xs1 and x1<=xs2) and (y1>=ys1 and y1<=ys2) ) and ( (x2>=xs1 and x2<=xs2) and (y2>=ys1 and y2<=ys2) ):
item.select(True)
for itemlabel in item.label_list:
if itemlabel not in selected_label_list:
selected_label_list.append(itemlabel)
if itemlabel.visible==0: # Important: Move invisible label with its parent part!
selected_label_list.append(itemlabel)
selected_wire_list.append(item)
item.setmove(True, True)
elif ( (x1>=xs1 and x1<=xs2) and (y1>=ys1 and y1<=ys2) ):
selected_wire_list.append(item)
item.setmove(True, False)
item.select(True)
elif ( (x2>=xs1 and x2<=xs2) and (y2>=ys1 and y2<=ys2) ):
selected_wire_list.append(item)
item.setmove(False, True)
item.select(True)
else:
item.setmove(False, False)
item.select(False)
rebuild_buff_toremove()
canvas.itemconfig('selection', outline='')
canvas.coords('selection', (0,0,0,0))
def B1Press(event):
global click_x, click_y, selected_item, selected_symbol_list, selected_label_list, selected_wire_list, ctrlkey
global buff_toremove
if ctrlkey==1:
return
posx=canvas.canvasx(event.x)
posy=canvas.canvasy(event.y)
if wiremode==True:
click_x=posx
click_y=posy
canvas.create_line(click_x, click_y, click_x+1, click_y+1, fill = get_select_color(), width=3*get_zoom(), tags="ConstructionWire")
return
# Check if the button has been pressed on any selected item. If not, deselect all selected items
# and check if the click is in any other item.
count=0
for item in selected_symbol_list:
if item.pointisin(posx, posy)==1:
count+=1
break
if count==0:
for item in selected_label_list:
if item.pointisin(posx, posy)==1:
count+=1
break
if count==0:
for item in selected_wire_list:
if item.pointisin(posx, posy)==1:
count+=1
break
if count==0: # not in a selected item
for item in selected_symbol_list:
item.select(False)
try:
canvas.itemconfigure(item.tag_fill, fill = get_symbol_color())
canvas.itemconfigure(item.tag_outline, outline = get_symbol_color())
except:
pass
selected_symbol_list=[]
for item in selected_label_list:
item.select(False)
selected_label_list=[]
canvas.itemconfigure('text', fill = get_label_color())
for item in selected_wire_list:
item.select(False)
selected_wire_list=[]
for item in g.label_list: # For all the labels in the list that are visible...
if item.pointisin(posx, posy)==1 and item.visible!=0:
canvas.itemconfigure("wirebuble", outline = get_wire_color())
canvas.itemconfigure("wires", fill = '')
if wires_hidden==0:
canvas.itemconfigure("wireline", fill = get_wire_color())
else:
canvas.itemconfigure("wireline", fill = '')
selected_item=item
click_x=posx
click_y=posy
# Change the color of the label
canvas.itemconfigure(item.tagtext, fill = get_select_color())
buff_toremove=item.parentsymbol.sym_ascii() # Must add the parent symbol!
return
# Give preference to the wire ends
for item in g.wire_list: # For all the wires in the list...
if item.nearP1(posx, posy)==True:
canvas.itemconfigure("wirebuble", outline = get_wire_color())
canvas.itemconfigure("wires", fill = '')
if wires_hidden==0:
canvas.itemconfigure("wireline", fill = get_wire_color())
else:
canvas.itemconfigure("wireline", fill = '')
canvas.itemconfigure("wireline", fill = '')
selected_item=item
item.setmove(True, False)
canvas.itemconfigure(item.tag, fill = get_select_color())
canvas.itemconfigure("wirebox", fill = '')
click_x=posx
click_y=posy
buff_toremove=item.sym_ascii()
return
# Give preference to the wire ends
for item in g.wire_list: # For all the wires in the list...
if item.nearP2(posx, posy)==True:
canvas.itemconfigure("wirebuble", outline = get_wire_color())
canvas.itemconfigure("wires", fill = '')
if wires_hidden==0:
canvas.itemconfigure("wireline", fill = get_wire_color())
else:
canvas.itemconfigure("wireline", fill = '')
selected_item=item
item.setmove(False, True)
canvas.itemconfigure(item.tag, fill = get_select_color())
canvas.itemconfigure("wirebox", fill = '')
click_x=posx
click_y=posy
buff_toremove=item.sym_ascii()
return
if wires_hidden==0: # Hidden wires are not selectable.
for item in g.wire_list: # For all the wires in the list...
if item.pointisin(posx, posy)==1:
canvas.itemconfigure("wirebuble", outline = get_wire_color())
canvas.itemconfigure("wires", fill = '')
canvas.itemconfigure("wireline", fill = get_wire_color())
selected_item=item
item.setmove(True, True)
canvas.itemconfigure(item.tag, fill = get_select_color())
canvas.itemconfigure("wirebox", fill = '')
click_x=posx
click_y=posy
buff_toremove=item.sym_ascii()
return
for item in g.wire_list: # For all the wires in the list...
canvas.itemconfigure("wirebuble", outline = get_wire_color())
canvas.itemconfigure("wires", fill = '')
if wires_hidden==0:
canvas.itemconfigure("wireline", fill = get_wire_color())
else:
canvas.itemconfigure("wireline", fill = '')
selected_item=0
for item in g.symbol_list: # For all the symbols in the list...
if item.pointisin(posx, posy)==1:
try:
canvas.itemconfigure(item.tag_fill, fill = get_select_color())
canvas.itemconfigure(item.tag_outline, outline = get_select_color())
except:
pass
selected_item=item
click_x=posx
click_y=posy
buff_toremove=item.sym_ascii()
else:
try:
canvas.itemconfigure(item.tag_fill, fill = get_symbol_color())
canvas.itemconfigure(item.tag_outline, outline = get_symbol_color())
except:
pass
if selected_item!=0:
return
canvas.itemconfigure("wirebuble", outline = get_wire_color())
canvas.itemconfigure("wires", fill = '')
if wires_hidden==0:
canvas.itemconfigure("wireline", fill = get_wire_color())
else:
canvas.itemconfigure("wireline", fill = '')
selected_item=0
click_x=posx
click_y=posy
def rebuild_buff_toremove():
global selected_label_list, selected_symbol_list, selected_wire_list
global buff_toremove
touched_symbol=[]
buff_toremove=[]
for item in selected_label_list:
if item.parentsymbol not in touched_symbol:
touched_symbol.append(item.parentsymbol)
buff_toremove+=item.parentsymbol.sym_ascii()
for item in selected_symbol_list:
if item not in touched_symbol:
touched_symbol.append(item)
buff_toremove+=item.sym_ascii()
for item in selected_wire_list:
buff_toremove+=item.sym_ascii()
def B1CtrlPress(event):
global click_x, click_y, selected_label_list, selected_symbol_list, selected_wire_list, ctrlkey
posx=canvas.canvasx(event.x)
posy=canvas.canvasy(event.y)
ctrlkey=1
for item in g.label_list: # For all the labels in the list...
if item.pointisin(posx, posy)==1 and item.visible==1:
if item in selected_label_list:
selected_label_list.remove(item)
canvas.itemconfigure(item.rect, outline = "")
item.select(False)
else:
selected_label_list.append(item)
canvas.itemconfigure(item.rect, outline = get_select_color())
item.select(True)
click_x=posx
click_y=posy
rebuild_buff_toremove()
return
for item in g.symbol_list: # For all the symbols in the list...
if item.pointisin(posx, posy)==1:
if item in selected_symbol_list:
selected_symbol_list.remove(item)
try:
canvas.itemconfigure(item.tag_fill, fill = get_symbol_color())
canvas.itemconfigure(item.tag_outline, outline = get_symbol_color())
except:
pass
for itemlabel in item.label_list:
if itemlabel in selected_label_list:
selected_label_list.remove(itemlabel)
if itemlabel.visible==1:
canvas.itemconfigure(item.rect, outline = "")
itemlabel.select(True)
item.select(False)
else:
try:
canvas.itemconfigure(item.tag_fill, fill = get_select_color())
canvas.itemconfigure(item.tag_outline, outline = get_select_color())
except:
pass
selected_symbol_list.append(item)
for itemlabel in item.label_list:
if itemlabel not in selected_label_list:
selected_label_list.append(itemlabel)
if itemlabel.visible==1:
canvas.itemconfigure(item.rect, outline = get_select_color())
itemlabel.select(True)
item.select(True)
click_x=posx
click_y=posy
rebuild_buff_toremove()
return
for item in g.wire_list: # For all the wires in the list...
if item.pointisin(posx, posy)==1:
item.setmove(True, True)
#item.printmove() # For debug, prints the states of item.move0 and item.move1
if item in selected_wire_list:
canvas.itemconfigure(item.tag, fill = get_wire_color())
selected_wire_list.remove(item)
for itemlabel in item.label_list:
if itemlabel in selected_label_list:
selected_label_list.remove(itemlabel)
if itemlabel.visible==1:
canvas.itemconfigure(item.rect, outline = "")
itemlabel.select(True)
item.select(False)
else:
canvas.itemconfigure(item.tag, fill = get_select_color())
selected_wire_list.append(item)
for itemlabel in item.label_list:
if itemlabel not in selected_label_list:
selected_label_list.append(itemlabel)
if itemlabel.visible==1:
canvas.itemconfigure(item.rect, outline = get_select_color())
itemlabel.select(True)
item.select(True)
click_x=posx
click_y=posy
rebuild_buff_toremove()
return
rebuild_buff_toremove()
click_x=posx
click_y=posy
def DoubleB1Press(event):
posx=canvas.canvasx(event.x)
posy=canvas.canvasy(event.y)
# This one may take a very long time to run
for item in g.wire_list: # For all the wires in the list...
if item.pointisin(posx, posy)==1:
buff_toremove=item.sym_ascii()
item.valueset(root, event.x, event.y)
buff_toadd=item.sym_ascii()
addundo(buff_toremove, buff_toadd)
return
for item in g.label_list: # For all the labels in the list...
if (item.pointisin(posx, posy)==1) and (item.visible>0):
buff_toremove=item.parentsymbol.sym_ascii() # undo goes to its parent symbol instead
item.valueset(root, event.x, event.y)
buff_toadd=item.parentsymbol.sym_ascii() # undo goes to its parent symbol instead
addundo(buff_toremove, buff_toadd)
return
for item in g.symbol_list: # For all the symbols in the list...
if item.pointisin(posx, posy)==1:
buff_toremove=item.sym_ascii()
item.valueset(root, event.x, event.y)
buff_toadd=item.sym_ascii()
addundo(buff_toremove, buff_toadd)
return
def do_cut(event=None):
do_copy()
do_delete()
def do_delete(event=None):
global click_x, click_y, selected_symbol_list, selected_label_list, selected_wire_list
global buff_toremove
# Check selected items first
if selected_symbol_list or selected_wire_list:
buff_toremove=[]
for item in selected_symbol_list:
buff_toremove+=item.sym_ascii()
item.clean()
g.symbol_list.remove(item)
del item
for item in selected_wire_list:
buff_toremove+=item.sym_ascii()
item.clean()
g.wire_list.remove(item)
del item
addundo(buff_toremove,'');
selected_symbol_list=[]
selected_label_list=[]
selected_wire_list=[]
return # skip the rest...
for item in g.symbol_list: # For all the symbols in the list...
if item.pointisin(click_x, click_y)==1:
buff_toremove=item.sym_ascii()
item.clean()
g.symbol_list.remove(item)
del item
addundo(buff_toremove,'');
return
for item in g.wire_list: # For all the wires in the list...
if item.pointisin(click_x, click_y)==1:
buff_toremove=item.sym_ascii()
item.clean()
g.wire_list.remove(item)
del item
addundo(buff_toremove,'');
return
def do_rotate_ccw(event=None):
global click_x, click_y, selected_symbol_list, selected_label_list, selected_wire_list
global buff_toremove
if selected_symbol_list or selected_label_list or selected_wire_list:
for item in selected_symbol_list:
item.rotate_ccw()
for item in selected_label_list:
item.rotate_ccw()
for item in selected_wire_list:
item.rotate_ccw()
toremove=buff_toremove[:] # Copy the string
rebuild_buff_toremove()
toadd=buff_toremove[:] # Copy the string
addundo(toremove, toadd)
else:
for item in g.symbol_list: # For all the symbols in the list...
if item.pointisin(click_x, click_y)==1:
buff_toremove=item.sym_ascii()
item.rotate_ccw()
buff_add=item.sym_ascii()
addundo(buff_toremove,buff_add)
return
for item in g.label_list: # For all the labels in the list...
if item.pointisin(click_x, click_y)==1:
buff_toremove=item.parentsymbol.sym_ascii() # WARNING: undo the label parent symbol instead
item.rotate_ccw()
buff_add=item.parentsymbol.sym_ascii()
addundo(buff_toremove,buff_add)
return
for item in g.wire_list: # For all the wires in the list...
if item.pointisin(click_x, click_y)==1:
buff_toremove=item.sym_ascii()
item.rotate_ccw()
buff_add=item.sym_ascii()
addundo(buff_toremove,buff_add)
return
def AddSymbol(event=None):
global click_x, click_y
input_filename=tkFileDialog.askopenfilename(title='Select new symbol', initialdir='./Symbols',
filetypes=[("All files", "*.*"),('Symbol files', 'sim_*.py')] )
if input_filename:
head, tail = os.path.split(input_filename)
fname, extension = os.path.splitext(tail)
mod = __import__(fname)
try:
newsymbol=mod.sym(canvas, click_x/get_zoom(), click_y/get_zoom())
newsymbol.movetogrid()
buff_add=newsymbol.sym_ascii()
addundo('',buff_add)
g.symbol_list.append(newsymbol)
except:
tkMessageBox.showerror("PNP_Curio ERROR", "Not a valid symbol file.")
def do_zoomto(val):
h0,h1=hbar.get()
v0,v1=vbar.get()
zold=float(get_zoom())
z=val
if z>10.0:
z=10.0
if z<0.5:
z=0.5
set_zoom(z)
canvas.config(scrollregion=(0,0,g.canvas_xsize*get_zoom(),g.canvas_ysize*get_zoom()))
canvas.scale("all", 0, 0, z/zold, z/zold)
hbar.set(h0,h1)
vbar.set(v0,v1)
try:
canvas.itemconfigure("all", width=get_zoom())
except:
pass
canvas.itemconfigure("wires", width=get_zoom()*3)
canvas.itemconfigure("text", width=get_zoom()*3)
canvas.itemconfigure("grid", width=1)
canvas.itemconfigure("selection", width=1)
def do_zoomin(event=None):
h0,h1=hbar.get()
v0,v1=vbar.get()
zold=float(get_zoom())
z=zold+0.5
if z>10.0:
z=10.0
set_zoom(z)
canvas.config(scrollregion=(0,0,g.canvas_xsize*get_zoom(),g.canvas_ysize*get_zoom()))
canvas.scale("all", 0, 0, z/zold, z/zold)
hbar.set(h0,h1)
vbar.set(v0,v1)
try:
canvas.itemconfigure("all", width=get_zoom())
except:
pass
canvas.itemconfigure("wires", width=get_zoom()*3)
canvas.itemconfigure("text", width=get_zoom()*3)
canvas.itemconfigure("grid", width=1)
canvas.itemconfigure("selection", width=1)
def do_zoomout(event=None):
h0,h1=hbar.get()
v0,v1=vbar.get()
zold=float(get_zoom())
z=zold-0.5
if z<0.5:
z=0.5
set_zoom(z)
canvas.scale("all", 0, 0, z/zold, z/zold)
canvas.config(scrollregion=(0,0,g.canvas_xsize*get_zoom(),g.canvas_ysize*get_zoom()))
hbar.set(h0,h1)
vbar.set(v0,v1)
try:
canvas.itemconfigure("all", width=get_zoom())
except:
pass
canvas.itemconfigure("text", width=get_zoom()*3)
canvas.itemconfigure("wires", width=get_zoom()*3)
canvas.itemconfigure("grid", width=1)
canvas.itemconfigure("selection", width=1)
def do_valueset():
global click_x, click_y
# The functionality is built in wires, but not used so skip them
for item in g.wire_list: # For all the wires in the list...
if item.pointisin(click_x, click_y)==1:
remove_buffer=item.sym_ascii()
item.valueset(root, screen_x, screen_y)
add_buffer=item.sym_ascii()
addundo(remove_buffer, add_buffer)
return
for item in g.label_list: # For all the labels in the list...
if (item.pointisin(click_x, click_y)==1) and (item.visible>0):
remove_buffer=item.parentsymbol.sym_ascii() # Undo goes to the label parent symbol
item.valueset(root, screen_x, screen_y)
add_buffer=item.parentsymbol.sym_ascii()
addundo(remove_buffer, add_buffer)
return
for item in g.symbol_list: # For all the symbols in the list...
if item.pointisin(click_x, click_y)==1:
remove_buffer=item.sym_ascii()
item.valueset(root, screen_x, screen_y)
add_buffer=item.sym_ascii()
addundo(remove_buffer, add_buffer)
return
def do_copy(event=None):
global selected_symbol_list, selected_wire_list
copy_buffer=[]
if selected_symbol_list or selected_wire_list:
for item in selected_symbol_list:
copy_buffer+=item.sym_ascii()
for item in selected_wire_list:
copy_buffer+=item.sym_ascii()
elif selected_item!=0:
copy_buffer=selected_item.sym_ascii()
root.clipboard_clear()
root.clipboard_append(''.join(copy_buffer))
def do_paste(event=None):
result = root.selection_get(selection = "CLIPBOARD")
loadfromstring(result, 50, True)
add_buffer=[]
for item in selected_symbol_list:
add_buffer+=item.sym_ascii()
for item in selected_wire_list:
add_buffer+=item.sym_ascii()
addundo('',add_buffer)
def do_popup(event=None):
global click_x, click_y, screen_x, screen_y
global event_x_root, event_y_root
# Read the scroll bars and convert to screen coordinates
screen_x=event.x
screen_y=event.y
click_x=canvas.canvasx(event.x)
click_y=canvas.canvasy(event.y)
try:
event_x_root=event.x_root
event_y_root=event.y_root
popup.tk_popup(event_x_root, event_y_root, 0)
finally:
popup.grab_release() # make sure to release the grab (Tk 8.0a1 only)
def do_popup2(event=None):
global event_x_root, event_y_root
try:
popup2.tk_popup(event_x_root, event_y_root, 0)
finally:
popup.grab_release()
def do_wireonoff(event=None):
global wiremode
if wiremode==True:
wiremode=False
canvas.config( cursor="top_left_arrow")
else:
wiremode=True
canvas.config( cursor="pencil")
def do_editmode(event=None):
global wiremode
wiremode=False
canvas.config( cursor="top_left_arrow")
def do_quit():
global file_modified
if file_modified:
mymessage='File %s has changes. Do you want to discard them?' % (filename)
if not tkMessageBox.askyesno("Open File", mymessage):
return
Save_Configuration()
root.destroy()
def do_savefile(event=None):
global filename
global file_modified
if filename:
text_file = open(filename, "w")
for item in g.symbol_list: # For all the symbols in the list...
text_file.write("%s"%item.sym_ascii())
for item in g.wire_list: # For all the wires in the list...
text_file.write("%s"%item.sym_ascii())
text_file.close()
file_modified=False
else:
savefileas()
def savefileas():
global filename
global prev_file_modified, file_modified
output_filename=tkFileDialog.asksaveasfilename(title='Save file...', initialdir='./Cases', filetypes=[("All files", "*.*"),('Symbol files', '*.txt')] )
if output_filename:
filename=output_filename[:]
Add_Recent_File(filename, filemenu, Recent_File_Callback)
text_file = open(output_filename, "w")
for item in g.symbol_list: # For all the symbols in the list...
text_file.write("%s"%item.sym_ascii())
for item in g.wire_list: # For all the wires in the list...
text_file.write("%s"%item.sym_ascii())
text_file.close()
file_modified=False
prev_file_modified=True # To refresh title bar
def loadfromstring(str, offset, select):
global selected_symbol_list, selected_label_list, selected_wire_list
s=''.join(str)
mylines=s.split('\n')
if select==True:
for item in selected_symbol_list:
item.select(False)
for item in selected_wire_list:
item.select(False)
selected_symbol_list=[]
selected_label_list=[]
selected_wire_list=[]
for item in mylines:
row=item.split(',')
z=get_zoom()
if row:
if row[0]=='symbol':
newsym = __import__(row[1])
x=float(row[2])
y=float(row[3])
direction=int(row[5])
currsym=newsym.sym(canvas, x, y)
if direction==1:
currsym.rotate_ccw()
elif direction==2:
currsym.rotate_ccw()
currsym.rotate_ccw()
elif direction==3:
currsym.rotate_ccw()
currsym.rotate_ccw()
currsym.rotate_ccw()
x1, y1, x2, y2 = canvas.coords(currsym.rect) # get the symbol bounding rectangle after rotation
currsym.move( ((x+offset)*z)-x1, ((y+offset)*z)-y1 ) # move the symbol to its final position
if select==True:
currsym.select(True)
selected_symbol_list.append(currsym)