-
Notifications
You must be signed in to change notification settings - Fork 11
/
k40_whisperer.py
5846 lines (4989 loc) · 258 KB
/
k40_whisperer.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
"""
K40 Whisperer
Copyright (C) <2017-2023> <Scorch>
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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
"""
version = '0.64'
title_text = "K40 Whisperer V"+version
import sys
from math import *
from egv import egv
from nano_library import K40_CLASS
from dxf import DXF_CLASS
from svg_reader import SVG_READER
from svg_reader import SVG_TEXT_EXCEPTION
from svg_reader import SVG_PXPI_EXCEPTION
from g_code_library import G_Code_Rip
from interpolate import interpolate
from ecoords import ECoord
from convex_hull import hull2D
from embedded_images import K40_Whisperer_Images
import inkex
import simplestyle
import simpletransform
import cubicsuperpath
import cspsubdiv
import traceback
import struct
DEBUG = False
if DEBUG:
import inspect
VERSION = sys.version_info[0]
LOAD_MSG = ""
if VERSION == 3:
from tkinter import *
from tkinter.filedialog import *
import tkinter.messagebox
MAXINT = sys.maxsize
else:
from Tkinter import *
from tkFileDialog import *
import tkMessageBox
MAXINT = sys.maxint
if VERSION < 3 and sys.version_info[1] < 6:
def next(item):
#return item.next()
return item.__next__()
try:
import psyco
psyco.full()
LOAD_MSG = LOAD_MSG+"\nPsyco Loaded\n"
except:
pass
import math
from time import time
import os
import re
import binascii
import getopt
import operator
import webbrowser
from PIL import Image
from PIL import ImageOps
from PIL import ImageFilter
try:
Image.warnings.simplefilter('ignore', Image.DecompressionBombWarning)
except:
pass
try:
from PIL import ImageTk
from PIL import _imaging
except:
pass #Don't worry everything will still work
PYCLIPPER=True
try:
import pyclipper
except:
print("Unable to load Pyclipper library (Offset trace outline will not work without it)")
PYCLIPPER = False
try:
os.chdir(os.path.dirname(__file__))
except:
pass
QUIET = False
################################################################################
class Application(Frame):
def __init__(self, master):
self.trace_window = toplevel_dummy()
Frame.__init__(self, master)
self.w = 780
self.h = 490
frame = Frame(master, width= self.w, height=self.h)
self.master = master
self.x = -1
self.y = -1
self.createWidgets()
self.micro = False
def resetPath(self):
self.RengData = ECoord()
self.VengData = ECoord()
self.VcutData = ECoord()
self.GcodeData = ECoord()
self.SCALE = 1
self.Design_bounds = (0,0,0,0)
self.UI_image = None
#if self.HomeUR.get():
self.move_head_window_temporary([0.0,0.0])
#else:
# self.move_head_window_temporary([0.0,0.0])
self.pos_offset=[0.0,0.0]
def createWidgets(self):
self.initComplete = 0
self.stop=[True]
self.k40 = None
self.run_time = 0
self.master.bind("<Configure>", self.Master_Configure)
self.master.bind('<Enter>', self.bindConfigure)
self.master.bind('<F1>', self.KEY_F1)
self.master.bind('<F2>', self.KEY_F2)
self.master.bind('<F3>', self.KEY_F3)
self.master.bind('<F4>', self.KEY_F4)
self.master.bind('<F5>', self.KEY_F5)
self.master.bind('<F6>', self.KEY_F6)
self.master.bind('<Home>', self.Home)
#self.master.bind('<Control-R>', self.Raster_Eng)
#self.master.bind('<Control-V>', self.Vector_Eng)
#self.master.bind('<Control-C>', self.Vector_Cut)
#self.master.bind('<Control-G>', self.Gcode_Cut)
self.master.bind('<Control-Left>' , self.Move_Left)
self.master.bind('<Control-Right>' , self.Move_Right)
self.master.bind('<Control-Up>' , self.Move_Up)
self.master.bind('<Control-Down>' , self.Move_Down)
self.master.bind('<Control-Home>' , self.Move_UL)
self.master.bind('<Control-Prior>' , self.Move_UR)
self.master.bind('<Control-Next>' , self.Move_LR)
self.master.bind('<Control-End>' , self.Move_LL)
self.master.bind('<Control-Clear>' , self.Move_CC)
self.master.bind('<Control-Key-4>' , self.Move_Left)
self.master.bind('<Control-6>' , self.Move_Right)
self.master.bind('<Control-8>' , self.Move_Up)
self.master.bind('<Control-Key-2>' , self.Move_Down)
self.master.bind('<Control-7>' , self.Move_UL)
self.master.bind('<Control-9>' , self.Move_UR)
self.master.bind('<Control-Key-3>' , self.Move_LR)
self.master.bind('<Control-Key-1>' , self.Move_LL)
self.master.bind('<Control-Key-5>' , self.Move_CC)
#####
self.master.bind('<Alt-Control-Left>' , self.Move_Arb_Left)
self.master.bind('<Alt-Control-Right>', self.Move_Arb_Right)
self.master.bind('<Alt-Control-Up>' , self.Move_Arb_Up)
self.master.bind('<Alt-Control-Down>' , self.Move_Arb_Down)
self.master.bind('<Alt-Control-Key-4>', self.Move_Arb_Left)
self.master.bind('<Alt-Control-6>' , self.Move_Arb_Right)
self.master.bind('<Alt-Control-8>' , self.Move_Arb_Up)
self.master.bind('<Alt-Control-Key-2>', self.Move_Arb_Down)
self.master.bind('<Alt-Left>' , self.Move_Arb_Left)
self.master.bind('<Alt-Right>', self.Move_Arb_Right)
self.master.bind('<Alt-Up>' , self.Move_Arb_Up)
self.master.bind('<Alt-Down>' , self.Move_Arb_Down)
self.master.bind('<Alt-Key-4>', self.Move_Arb_Left)
self.master.bind('<Alt-6>' , self.Move_Arb_Right)
self.master.bind('<Alt-8>' , self.Move_Arb_Up)
self.master.bind('<Alt-Key-2>', self.Move_Arb_Down)
#####
self.master.bind('<Control-i>' , self.Initialize_Laser)
self.master.bind('<Control-f>' , self.Unfreeze_Laser)
self.master.bind('<Control-o>' , self.menu_File_Open_Design)
self.master.bind('<Control-l>' , self.menu_Reload_Design)
self.master.bind('<Control-h>' , self.Home)
self.master.bind('<Control-u>' , self.Unlock)
self.master.bind('<Escape>' , self.Stop)
self.master.bind('<Control-t>' , self.TRACE_Settings_Window)
self.include_Reng = BooleanVar()
self.include_Rpth = BooleanVar()
self.include_Veng = BooleanVar()
self.include_Vcut = BooleanVar()
self.include_Gcde = BooleanVar()
self.include_Time = BooleanVar()
self.advanced = BooleanVar()
self.halftone = BooleanVar()
self.mirror = BooleanVar()
self.rotate = BooleanVar()
self.negate = BooleanVar()
self.inputCSYS = BooleanVar()
self.HomeUR = BooleanVar()
self.engraveUP = BooleanVar()
self.init_home = BooleanVar()
self.post_home = BooleanVar()
self.post_beep = BooleanVar()
self.post_disp = BooleanVar()
self.post_exec = BooleanVar()
self.pre_pr_crc = BooleanVar()
self.inside_first = BooleanVar()
self.rotary = BooleanVar()
self.reduced_mem = BooleanVar()
self.wait = BooleanVar()
self.ht_size = StringVar()
self.Reng_feed = StringVar()
self.Veng_feed = StringVar()
self.Vcut_feed = StringVar()
self.Reng_passes = StringVar()
self.Veng_passes = StringVar()
self.Vcut_passes = StringVar()
self.Gcde_passes = StringVar()
self.board_name = StringVar()
self.units = StringVar()
self.jog_step = StringVar()
self.rast_step = StringVar()
self.funits = StringVar()
self.bezier_M1 = StringVar()
self.bezier_M2 = StringVar()
self.bezier_weight = StringVar()
## self.unsharp_flag = BooleanVar()
## self.unsharp_r = StringVar()
## self.unsharp_p = StringVar()
## self.unsharp_t = StringVar()
## self.unsharp_flag.set(False)
## self.unsharp_r.set("40")
## self.unsharp_p.set("350")
## self.unsharp_t.set("3")
self.LaserXsize = StringVar()
self.LaserYsize = StringVar()
self.LaserXscale = StringVar()
self.LaserYscale = StringVar()
self.LaserRscale = StringVar()
self.rapid_feed = StringVar()
self.gotoX = StringVar()
self.gotoY = StringVar()
self.n_egv_passes = StringVar()
self.inkscape_path = StringVar()
self.batch_path = StringVar()
self.ink_timeout = StringVar()
self.t_timeout = StringVar()
self.n_timeouts = StringVar()
self.Reng_time = StringVar()
self.Veng_time = StringVar()
self.Vcut_time = StringVar()
self.Gcde_time = StringVar()
self.comb_engrave = BooleanVar()
self.comb_vector = BooleanVar()
self.zoom2image = BooleanVar()
self.trace_w_laser = BooleanVar()
self.trace_gap = StringVar()
self.trace_speed = StringVar()
###########################################################################
# INITILIZE VARIABLES #
# if you want to change a default setting this is the place to do it #
###########################################################################
self.include_Reng.set(1)
self.include_Rpth.set(0)
self.include_Veng.set(1)
self.include_Vcut.set(1)
self.include_Gcde.set(1)
self.include_Time.set(0)
self.advanced.set(0)
self.halftone.set(1)
self.mirror.set(0)
self.rotate.set(0)
self.negate.set(0)
self.inputCSYS.set(0)
self.HomeUR.set(0)
self.engraveUP.set(0)
self.init_home.set(1)
self.post_home.set(0)
self.post_beep.set(0)
self.post_disp.set(0)
self.post_exec.set(0)
self.pre_pr_crc.set(1)
self.inside_first.set(1)
self.rotary.set(0)
self.reduced_mem.set(0)
self.wait.set(1)
self.ht_size.set(500)
self.Reng_feed.set("100")
self.Veng_feed.set("20")
self.Vcut_feed.set("10")
self.Reng_passes.set("1")
self.Veng_passes.set("1")
self.Vcut_passes.set("1")
self.Gcde_passes.set("1")
self.jog_step.set("10.0")
self.rast_step.set("0.002")
self.bezier_weight.set("3.5")
self.bezier_M1.set("2.5")
self.bezier_M2.set("0.50")
self.bezier_weight_default = float(self.bezier_weight.get())
self.bezier_M1_default = float(self.bezier_M1.get())
self.bezier_M2_default = float(self.bezier_M2.get())
self.board_name.set("LASER-M2") # Options are
# "LASER-M2",
# "LASER-M1",
# "LASER-M",
# "LASER-B2",
# "LASER-B1",
# "LASER-B",
# "LASER-A"
self.units.set("mm") # Options are "in" and "mm"
self.ink_timeout.set("3")
self.t_timeout.set("200")
self.n_timeouts.set("30")
self.HOME_DIR = os.path.expanduser("~")
if not os.path.isdir(self.HOME_DIR):
self.HOME_DIR = ""
self.DESIGN_FILE = (self.HOME_DIR+"/None")
self.EGV_FILE = None
self.aspect_ratio = 0
self.segID = []
self.LaserXsize.set("325")
self.LaserYsize.set("220")
self.LaserXscale.set("1.000")
self.LaserYscale.set("1.000")
self.LaserRscale.set("1.000")
self.rapid_feed.set("0.0")
self.gotoX.set("0.0")
self.gotoY.set("0.0")
self.n_egv_passes.set("1")
self.comb_engrave.set(0)
self.comb_vector.set(0)
self.zoom2image.set(0)
self.trace_w_laser.set(0)
self.trace_gap.set(0)
self.trace_speed.set(50)
self.laserX = 0.0
self.laserY = 0.0
self.PlotScale = 1.0
self.GUI_Disabled = False
# PAN and ZOOM STUFF
self.panx = 0
self.panx = 0
self.lastx = 0
self.lasty = 0
self.move_start_x = 0
self.move_start_y = 0
self.RengData = ECoord()
self.VengData = ECoord()
self.VcutData = ECoord()
self.GcodeData = ECoord()
self.SCALE = 1
self.Design_bounds = (0,0,0,0)
self.UI_image = None
self.pos_offset=[0.0,0.0]
self.inkscape_warning = False
# Derived variables
if self.units.get() == 'in':
self.funits.set('in/min')
self.units_scale = 1.0
else:
self.units.set('mm')
self.funits.set('mm/s')
self.units_scale = 25.4
self.statusMessage = StringVar()
self.statusMessage.set("Welcome to K40 Whisperer")
self.Reng_time.set("0")
self.Veng_time.set("0")
self.Vcut_time.set("0")
self.Gcde_time.set("0")
self.min_vector_speed = 1.1 #in/min
self.min_raster_speed = 12 #in/min
##########################################################################
### END INITILIZING VARIABLES ###
##########################################################################
# make a Status Bar
self.statusbar = Label(self.master, textvariable=self.statusMessage, \
bd=1, relief=SUNKEN , height=1)
self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)
# Canvas
lbframe = Frame( self.master )
self.PreviewCanvas_frame = lbframe
self.PreviewCanvas = Canvas(lbframe, width=self.w-(220+20), height=self.h-200, background="grey75")
self.PreviewCanvas.pack(side=LEFT, fill=BOTH, expand=1)
self.PreviewCanvas_frame.place(x=230, y=10)
self.PreviewCanvas.tag_bind('LaserTag',"<1>" , self.mousePanStart)
self.PreviewCanvas.tag_bind('LaserTag',"<B1-Motion>" , self.mousePan)
self.PreviewCanvas.tag_bind('LaserTag',"<ButtonRelease-1>", self.mousePanStop)
self.PreviewCanvas.tag_bind('LaserDot',"<3>" , self.right_mousePanStart)
self.PreviewCanvas.tag_bind('LaserDot',"<B3-Motion>" , self.right_mousePan)
self.PreviewCanvas.tag_bind('LaserDot',"<ButtonRelease-3>", self.right_mousePanStop)
# Left Column #
self.separator1 = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.separator2 = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.separator3 = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.separator4 = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.Label_Reng_feed_u = Label(self.master,textvariable=self.funits, anchor=W)
self.Entry_Reng_feed = Entry(self.master,width="15")
self.Entry_Reng_feed.configure(textvariable=self.Reng_feed,justify='center',fg="black")
self.Reng_feed.trace_variable("w", self.Entry_Reng_feed_Callback)
self.NormalColor = self.Entry_Reng_feed.cget('bg')
self.Label_Veng_feed_u = Label(self.master,textvariable=self.funits, anchor=W)
self.Entry_Veng_feed = Entry(self.master,width="15")
self.Entry_Veng_feed.configure(textvariable=self.Veng_feed,justify='center',fg="blue")
self.Veng_feed.trace_variable("w", self.Entry_Veng_feed_Callback)
self.NormalColor = self.Entry_Veng_feed.cget('bg')
self.Label_Vcut_feed_u = Label(self.master,textvariable=self.funits, anchor=W)
self.Entry_Vcut_feed = Entry(self.master,width="15")
self.Entry_Vcut_feed.configure(textvariable=self.Vcut_feed,justify='center',fg="red")
self.Vcut_feed.trace_variable("w", self.Entry_Vcut_feed_Callback)
self.NormalColor = self.Entry_Vcut_feed.cget('bg')
# Buttons
self.Reng_Button = Button(self.master,text="Raster Engrave", command=self.Raster_Eng)
self.Veng_Button = Button(self.master,text="Vector Engrave", command=self.Vector_Eng)
self.Vcut_Button = Button(self.master,text="Vector Cut" , command=self.Vector_Cut)
self.Grun_Button = Button(self.master,text="Run G-Code" , command=self.Gcode_Cut)
self.Reng_Veng_Button = Button(self.master,text="Raster and\nVector Engrave", command=self.Raster_Vector_Eng)
self.Veng_Vcut_Button = Button(self.master,text="Vector Engrave\nand Cut", command=self.Vector_Eng_Cut)
self.Reng_Veng_Vcut_Button = Button(self.master,text="Raster Engrave\nVector Engrave\nand\nVector Cut", command=self.Raster_Vector_Cut)
self.Label_Position_Control = Label(self.master,text="Position Controls:", anchor=W)
self.Initialize_Button = Button(self.master,text="Initialize Laser Cutter", command=self.Initialize_Laser)
self.Open_Button = Button(self.master,text="Open\nDesign File", command=self.menu_File_Open_Design)
self.Reload_Button = Button(self.master,text="Reload\nDesign File", command=self.menu_Reload_Design)
self.Home_Button = Button(self.master,text="Home", command=self.Home)
self.UnLock_Button = Button(self.master,text="Unlock Rail", command=self.Unlock)
self.Stop_Button = Button(self.master,text="Pause/Stop", command=self.Stop)
try:
self.left_image = PhotoImage(data=K40_Whisperer_Images.left_B64, format='gif')
self.right_image = PhotoImage(data=K40_Whisperer_Images.right_B64, format='gif')
self.up_image = PhotoImage(data=K40_Whisperer_Images.up_B64, format='gif')
self.down_image = PhotoImage(data=K40_Whisperer_Images.down_B64, format='gif')
self.Right_Button = Button(self.master,image=self.right_image, command=self.Move_Right)
self.Left_Button = Button(self.master,image=self.left_image, command=self.Move_Left)
self.Up_Button = Button(self.master,image=self.up_image, command=self.Move_Up)
self.Down_Button = Button(self.master,image=self.down_image, command=self.Move_Down)
self.UL_image = PhotoImage(data=K40_Whisperer_Images.UL_B64, format='gif')
self.UR_image = PhotoImage(data=K40_Whisperer_Images.UR_B64, format='gif')
self.LR_image = PhotoImage(data=K40_Whisperer_Images.LR_B64, format='gif')
self.LL_image = PhotoImage(data=K40_Whisperer_Images.LL_B64, format='gif')
self.CC_image = PhotoImage(data=K40_Whisperer_Images.CC_B64, format='gif')
self.UL_Button = Button(self.master,image=self.UL_image, command=self.Move_UL)
self.UR_Button = Button(self.master,image=self.UR_image, command=self.Move_UR)
self.LR_Button = Button(self.master,image=self.LR_image, command=self.Move_LR)
self.LL_Button = Button(self.master,image=self.LL_image, command=self.Move_LL)
self.CC_Button = Button(self.master,image=self.CC_image, command=self.Move_CC)
except:
self.Right_Button = Button(self.master,text=">", command=self.Move_Right)
self.Left_Button = Button(self.master,text="<", command=self.Move_Left)
self.Up_Button = Button(self.master,text="^", command=self.Move_Up)
self.Down_Button = Button(self.master,text="v", command=self.Move_Down)
self.UL_Button = Button(self.master,text=" ", command=self.Move_UL)
self.UR_Button = Button(self.master,text=" ", command=self.Move_UR)
self.LR_Button = Button(self.master,text=" ", command=self.Move_LR)
self.LL_Button = Button(self.master,text=" ", command=self.Move_LL)
self.CC_Button = Button(self.master,text=" ", command=self.Move_CC)
self.Label_Step = Label(self.master,text="Jog Step", anchor=CENTER )
self.Label_Step_u = Label(self.master,textvariable=self.units, anchor=W)
self.Entry_Step = Entry(self.master,width="15")
self.Entry_Step.configure(textvariable=self.jog_step, justify='center')
self.jog_step.trace_variable("w", self.Entry_Step_Callback)
###########################################################################
self.GoTo_Button = Button(self.master,text="Move To", command=self.GoTo)
self.Entry_GoToX = Entry(self.master,width="15",justify='center')
self.Entry_GoToX.configure(textvariable=self.gotoX)
self.gotoX.trace_variable("w", self.Entry_GoToX_Callback)
self.Entry_GoToY = Entry(self.master,width="15",justify='center')
self.Entry_GoToY.configure(textvariable=self.gotoY)
self.gotoY.trace_variable("w", self.Entry_GoToY_Callback)
self.Label_GoToX = Label(self.master,text="X", anchor=CENTER )
self.Label_GoToY = Label(self.master,text="Y", anchor=CENTER )
###########################################################################
# End Left Column #
# Advanced Column #
self.separator_vert = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.Label_Advanced_column = Label(self.master,text="Advanced Settings",anchor=CENTER)
self.separator_adv = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.Label_Halftone_adv = Label(self.master,text="Halftone (Dither)")
self.Checkbutton_Halftone_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_Halftone_adv.configure(variable=self.halftone)
self.halftone.trace_variable("w", self.View_Refresh_and_Reset_RasterPath) #self.menu_View_Refresh_Callback
self.Label_Negate_adv = Label(self.master,text="Invert Raster Color")
self.Checkbutton_Negate_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_Negate_adv.configure(variable=self.negate)
self.negate.trace_variable("w", self.View_Refresh_and_Reset_RasterPath)
self.separator_adv2 = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.Label_Mirror_adv = Label(self.master,text="Mirror Design")
self.Checkbutton_Mirror_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_Mirror_adv.configure(variable=self.mirror)
self.mirror.trace_variable("w", self.View_Refresh_and_Reset_RasterPath)
self.Label_Rotate_adv = Label(self.master,text="Rotate Design")
self.Checkbutton_Rotate_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_Rotate_adv.configure(variable=self.rotate)
self.rotate.trace_variable("w", self.View_Refresh_and_Reset_RasterPath)
self.separator_adv3 = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.Label_inputCSYS_adv = Label(self.master,text="Use Input CSYS")
self.Checkbutton_inputCSYS_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_inputCSYS_adv.configure(variable=self.inputCSYS)
self.inputCSYS.trace_variable("w", self.menu_View_inputCSYS_Refresh_Callback)
self.Label_Inside_First_adv = Label(self.master,text="Cut Inside First")
self.Checkbutton_Inside_First_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_Inside_First_adv.configure(variable=self.inside_first)
self.inside_first.trace_variable("w", self.menu_Inside_First_Callback)
self.Label_Inside_First_adv = Label(self.master,text="Cut Inside First")
self.Checkbutton_Inside_First_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_Inside_First_adv.configure(variable=self.inside_first)
self.Label_Rotary_Enable_adv = Label(self.master,text="Use Rotary Settings")
self.Checkbutton_Rotary_Enable_adv = Checkbutton(self.master,text="")
self.Checkbutton_Rotary_Enable_adv.configure(variable=self.rotary)
self.rotary.trace_variable("w", self.Reset_RasterPath_and_Update_Time)
#####
self.separator_comb = Frame(self.master, height=2, bd=1, relief=SUNKEN)
self.Label_Comb_Engrave_adv = Label(self.master,text="Group Engrave Tasks")
self.Checkbutton_Comb_Engrave_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_Comb_Engrave_adv.configure(variable=self.comb_engrave)
self.comb_engrave.trace_variable("w", self.menu_View_Refresh_Callback)
self.Label_Comb_Vector_adv = Label(self.master,text="Group Vector Tasks")
self.Checkbutton_Comb_Vector_adv = Checkbutton(self.master,text=" ", anchor=W)
self.Checkbutton_Comb_Vector_adv.configure(variable=self.comb_vector)
self.comb_vector.trace_variable("w", self.menu_View_Refresh_Callback)
#####
self.Label_Reng_passes = Label(self.master,text="Raster Eng. Passes")
self.Entry_Reng_passes = Entry(self.master,width="15")
self.Entry_Reng_passes.configure(textvariable=self.Reng_passes,justify='center',fg="black")
self.Reng_passes.trace_variable("w", self.Entry_Reng_passes_Callback)
self.NormalColor = self.Entry_Reng_passes.cget('bg')
self.Label_Veng_passes = Label(self.master,text="Vector Eng. Passes")
self.Entry_Veng_passes = Entry(self.master,width="15")
self.Entry_Veng_passes.configure(textvariable=self.Veng_passes,justify='center',fg="blue")
self.Veng_passes.trace_variable("w", self.Entry_Veng_passes_Callback)
self.NormalColor = self.Entry_Veng_passes.cget('bg')
self.Label_Vcut_passes = Label(self.master,text="Vector Cut Passes")
self.Entry_Vcut_passes = Entry(self.master,width="15")
self.Entry_Vcut_passes.configure(textvariable=self.Vcut_passes,justify='center',fg="red")
self.Vcut_passes.trace_variable("w", self.Entry_Vcut_passes_Callback)
self.NormalColor = self.Entry_Vcut_passes.cget('bg')
self.Label_Gcde_passes = Label(self.master,text="G-Code Passes")
self.Entry_Gcde_passes = Entry(self.master,width="15")
self.Entry_Gcde_passes.configure(textvariable=self.Gcde_passes,justify='center',fg="black")
self.Gcde_passes.trace_variable("w", self.Entry_Gcde_passes_Callback)
self.NormalColor = self.Entry_Gcde_passes.cget('bg')
self.Hide_Adv_Button = Button(self.master,text="Hide Advanced", command=self.Hide_Advanced)
# End Right Column #
self.calc_button = Button(self.master,text="Calculate Raster Time", command=self.menu_Calc_Raster_Time)
#GEN Setting Window Entry initializations
self.Entry_Sspeed = Entry()
self.Entry_BoxGap = Entry()
self.Entry_ContAngle = Entry()
# Make Menu Bar
self.menuBar = Menu(self.master, relief = "raised", bd=2)
top_File = Menu(self.menuBar, tearoff=0)
top_File.add("command", label = "Save Settings File", command = self.menu_File_Save)
top_File.add("command", label = "Read Settings File", command = self.menu_File_Open_Settings_File)
top_File.add_separator()
top_File.add("command", label = "Open Design (SVG/DXF/G-Code)" , command = self.menu_File_Open_Design)
top_File.add("command", label = "Reload Design" , command = self.menu_Reload_Design)
top_File.add_separator()
top_File.add("command", label = "Send EGV File to Laser" , command = self.menu_File_Open_EGV)
SaveEGVmenu = Menu(self.master, relief = "raised", bd=2, tearoff=0)
top_File.add_cascade(label="Save EGV File", menu=SaveEGVmenu)
SaveEGVmenu.add("command", label = "Raster Engrave" , command = self.menu_File_Raster_Engrave)
SaveEGVmenu.add("command", label = "Vector Engrave" , command = self.menu_File_Vector_Engrave)
SaveEGVmenu.add("command", label = "Vector Cut" , command = self.menu_File_Vector_Cut)
SaveEGVmenu.add("command", label = "G-Code Operations" , command = self.menu_File_G_Code)
SaveEGVmenu.add_separator()
SaveEGVmenu.add("command", label = "Raster and Vector Engrave" , command = self.menu_File_Raster_Vector_Engrave)
SaveEGVmenu.add("command", label = "Vector Engrave and Cut" , command = self.menu_File_Vector_Engrave_Cut)
SaveEGVmenu.add("command", label = "Raster, Vector Engrave and Vector Cut" , command = self.menu_File_Raster_Vector_Cut)
top_File.add_separator()
top_File.add("command", label = "Exit" , command = self.menu_File_Quit)
self.menuBar.add("cascade", label="File", menu=top_File)
#top_Edit = Menu(self.menuBar, tearoff=0)
#self.menuBar.add("cascade", label="Edit", menu=top_Edit)
top_View = Menu(self.menuBar, tearoff=0)
top_View.add("command", label = "Refresh <F5>", command = self.menu_View_Refresh)
top_View.add_separator()
top_View.add_checkbutton(label = "Show Raster Image" , variable=self.include_Reng ,command= self.menu_View_Refresh)
if DEBUG:
top_View.add_checkbutton(label = "Show Raster Paths" ,variable=self.include_Rpth ,command= self.menu_View_Refresh)
top_View.add_checkbutton(label = "Show Vector Engrave", variable=self.include_Veng ,command= self.menu_View_Refresh)
top_View.add_checkbutton(label = "Show Vector Cut" , variable=self.include_Vcut ,command= self.menu_View_Refresh)
top_View.add_checkbutton(label = "Show G-Code Paths" , variable=self.include_Gcde ,command= self.menu_View_Refresh)
top_View.add_separator()
top_View.add_checkbutton(label = "Show Time Estimates", variable=self.include_Time ,command= self.menu_View_Refresh)
top_View.add_checkbutton(label = "Zoom to Design Size", variable=self.zoom2image ,command= self.menu_View_Refresh)
#top_View.add_separator()
#top_View.add("command", label = "computeAccurateReng",command= self.computeAccurateReng)
#top_View.add("command", label = "computeAccurateVeng",command= self.computeAccurateVeng)
#top_View.add("command", label = "computeAccurateVcut",command= self.computeAccurateVcut)
self.menuBar.add("cascade", label="View", menu=top_View)
top_Tools = Menu(self.menuBar, tearoff=0)
self.menuBar.add("cascade", label="Tools", menu=top_Tools)
USBmenu = Menu(self.master, relief = "raised", bd=2, tearoff=0)
top_Tools.add("command", label = "Calculate Raster Time", command = self.menu_Calc_Raster_Time)
top_Tools.add("command", label = "Trace Design Boundary <Ctrl-t>", command = self.TRACE_Settings_Window)
top_Tools.add_separator()
top_Tools.add("command", label = "Initialize Laser <Ctrl-i>", command = self.Initialize_Laser)
top_Tools.add("command", label = "Unfreeze Laser <Ctrl-f>" , command = self.Unfreeze_Laser)
top_Tools.add_cascade(label="USB", menu=USBmenu)
USBmenu.add("command", label = "Reset USB", command = self.Reset)
USBmenu.add("command", label = "Release USB", command = self.Release_USB)
#top_USB = Menu(self.menuBar, tearoff=0)
#top_USB.add("command", label = "Reset USB", command = self.Reset)
#top_USB.add("command", label = "Release USB", command = self.Release_USB)
#top_USB.add("command", label = "Initialize Laser", command = self.Initialize_Laser)
#self.menuBar.add("cascade", label="USB", menu=top_USB)
top_Settings = Menu(self.menuBar, tearoff=0)
top_Settings.add("command", label = "General Settings <F2>", command = self.GEN_Settings_Window)
top_Settings.add("command", label = "Raster Settings <F3>", command = self.RASTER_Settings_Window)
top_Settings.add("command", label = "Rotary Settings <F4>", command = self.ROTARY_Settings_Window)
top_Settings.add_separator()
top_Settings.add_checkbutton(label = "Advanced Settings <F6>", variable=self.advanced ,command= self.menu_View_Refresh)
self.menuBar.add("cascade", label="Settings", menu=top_Settings)
top_Help = Menu(self.menuBar, tearoff=0)
top_Help.add("command", label = "About (e-mail)", command = self.menu_Help_About)
top_Help.add("command", label = "K40 Whisperer Web Page", command = self.menu_Help_Web)
top_Help.add("command", label = "Manual (Web Page)", command = self.menu_Help_Manual)
self.menuBar.add("cascade", label="Help", menu=top_Help)
self.master.config(menu=self.menuBar)
##########################################################################
# Config File and command line options #
##########################################################################
config_file = "k40_whisperer.txt"
home_config1 = self.HOME_DIR + "/" + config_file
if ( os.path.isfile(config_file) ):
self.Open_Settings_File(config_file)
elif ( os.path.isfile(home_config1) ):
self.Open_Settings_File(home_config1)
# opts, args = None, None
# try:
# opts, args = getopt.getopt(sys.argv[1:], "ho:",["help", "other_option"])
# except:
# debug_message('Unable interpret command line options')
# sys.exit()
# for option, value in opts:
## if option in ('-h','--help'):
## fmessage(' ')
## fmessage('Usage: python .py [-g file]')
## fmessage('-o : unknown other option (also --other_option)')
## fmessage('-h : print this help (also --help)\n')
## sys.exit()
# if option in ('-m','--micro'):
# self.micro = True
##########################################################################
################################################################################
def entry_set(self, val2, calc_flag=0, new=0):
if calc_flag == 0 and new==0:
try:
self.statusbar.configure( bg = 'yellow' )
val2.configure( bg = 'yellow' )
self.statusMessage.set(" Recalculation required.")
except:
pass
elif calc_flag == 3:
try:
val2.configure( bg = 'red' )
self.statusbar.configure( bg = 'red' )
self.statusMessage.set(" Value should be a number. ")
except:
pass
elif calc_flag == 2:
try:
self.statusbar.configure( bg = 'red' )
val2.configure( bg = 'red' )
except:
pass
elif (calc_flag == 0 or calc_flag == 1) and new==1 :
try:
self.statusbar.configure( bg = 'white' )
self.statusMessage.set(" ")
val2.configure( bg = 'white' )
except:
pass
elif (calc_flag == 1) and new==0 :
try:
self.statusbar.configure( bg = 'white' )
self.statusMessage.set(" ")
val2.configure( bg = 'white' )
except:
pass
elif (calc_flag == 0 or calc_flag == 1) and new==2:
return 0
return 1
################################################################################
def Write_Config_File(self, event):
config_data = self.WriteConfig()
config_file = "k40_whisperer.txt"
configname_full = self.HOME_DIR + "/" + config_file
current_name = event.widget.winfo_parent()
win_id = event.widget.nametowidget(current_name)
if ( os.path.isfile(configname_full) ):
try:
win_id.withdraw()
except:
pass
if not message_ask_ok_cancel("Replace", "Replace Exiting Configuration File?\n"+configname_full):
try:
win_id.deiconify()
except:
pass
return
try:
fout = open(configname_full,'w')
except:
self.statusMessage.set("Unable to open file for writing: %s" %(configname_full))
self.statusbar.configure( bg = 'red' )
return
for line in config_data:
try:
fout.write(line+'\n')
except:
fout.write('(skipping line)\n')
fout.close
self.statusMessage.set("Configuration File Saved: %s" %(configname_full))
self.statusbar.configure( bg = 'white' )
try:
win_id.deiconify()
except:
pass
################################################################################
def WriteConfig(self):
global Zero
header = []
header.append('( K40 Whisperer Settings: '+version+' )')
header.append('( by Scorch - 2019 )')
header.append("(=========================================================)")
# BOOL
header.append('(k40_whisperer_set include_Reng %s )' %( int(self.include_Reng.get()) ))
header.append('(k40_whisperer_set include_Veng %s )' %( int(self.include_Veng.get()) ))
header.append('(k40_whisperer_set include_Vcut %s )' %( int(self.include_Vcut.get()) ))
header.append('(k40_whisperer_set include_Gcde %s )' %( int(self.include_Gcde.get()) ))
header.append('(k40_whisperer_set include_Time %s )' %( int(self.include_Time.get()) ))
header.append('(k40_whisperer_set halftone %s )' %( int(self.halftone.get()) ))
header.append('(k40_whisperer_set HomeUR %s )' %( int(self.HomeUR.get()) ))
header.append('(k40_whisperer_set inputCSYS %s )' %( int(self.inputCSYS.get()) ))
header.append('(k40_whisperer_set advanced %s )' %( int(self.advanced.get()) ))
header.append('(k40_whisperer_set mirror %s )' %( int(self.mirror.get()) ))
header.append('(k40_whisperer_set rotate %s )' %( int(self.rotate.get()) ))
header.append('(k40_whisperer_set negate %s )' %( int(self.negate.get()) ))
header.append('(k40_whisperer_set engraveUP %s )' %( int(self.engraveUP.get()) ))
header.append('(k40_whisperer_set init_home %s )' %( int(self.init_home.get()) ))
header.append('(k40_whisperer_set post_home %s )' %( int(self.post_home.get()) ))
header.append('(k40_whisperer_set post_beep %s )' %( int(self.post_beep.get()) ))
header.append('(k40_whisperer_set post_disp %s )' %( int(self.post_disp.get()) ))
header.append('(k40_whisperer_set post_exec %s )' %( int(self.post_exec.get()) ))
header.append('(k40_whisperer_set pre_pr_crc %s )' %( int(self.pre_pr_crc.get()) ))
header.append('(k40_whisperer_set inside_first %s )' %( int(self.inside_first.get()) ))
header.append('(k40_whisperer_set comb_engrave %s )' %( int(self.comb_engrave.get()) ))
header.append('(k40_whisperer_set comb_vector %s )' %( int(self.comb_vector.get()) ))
header.append('(k40_whisperer_set zoom2image %s )' %( int(self.zoom2image.get()) ))
header.append('(k40_whisperer_set rotary %s )' %( int(self.rotary.get()) ))
header.append('(k40_whisperer_set reduced_mem %s )' %( int(self.reduced_mem.get()) ))
header.append('(k40_whisperer_set wait %s )' %( int(self.wait.get()) ))
header.append('(k40_whisperer_set trace_w_laser %s )' %( int(self.trace_w_laser.get()) ))
# STRING.get()
header.append('(k40_whisperer_set board_name %s )' %( self.board_name.get() ))
header.append('(k40_whisperer_set units %s )' %( self.units.get() ))
header.append('(k40_whisperer_set Reng_feed %s )' %( self.Reng_feed.get() ))
header.append('(k40_whisperer_set Veng_feed %s )' %( self.Veng_feed.get() ))
header.append('(k40_whisperer_set Vcut_feed %s )' %( self.Vcut_feed.get() ))
header.append('(k40_whisperer_set jog_step %s )' %( self.jog_step.get() ))
header.append('(k40_whisperer_set Reng_passes %s )' %( self.Reng_passes.get() ))
header.append('(k40_whisperer_set Veng_passes %s )' %( self.Veng_passes.get() ))
header.append('(k40_whisperer_set Vcut_passes %s )' %( self.Vcut_passes.get() ))
header.append('(k40_whisperer_set Gcde_passes %s )' %( self.Gcde_passes.get() ))
header.append('(k40_whisperer_set rast_step %s )' %( self.rast_step.get() ))
header.append('(k40_whisperer_set ht_size %s )' %( self.ht_size.get() ))
header.append('(k40_whisperer_set LaserXsize %s )' %( self.LaserXsize.get() ))
header.append('(k40_whisperer_set LaserYsize %s )' %( self.LaserYsize.get() ))
header.append('(k40_whisperer_set LaserXscale %s )' %( self.LaserXscale.get() ))
header.append('(k40_whisperer_set LaserYscale %s )' %( self.LaserYscale.get() ))
header.append('(k40_whisperer_set LaserRscale %s )' %( self.LaserRscale.get() ))
header.append('(k40_whisperer_set rapid_feed %s )' %( self.rapid_feed.get() ))
header.append('(k40_whisperer_set gotoX %s )' %( self.gotoX.get() ))
header.append('(k40_whisperer_set gotoY %s )' %( self.gotoY.get() ))
header.append('(k40_whisperer_set bezier_M1 %s )' %( self.bezier_M1.get() ))
header.append('(k40_whisperer_set bezier_M2 %s )' %( self.bezier_M2.get() ))
header.append('(k40_whisperer_set bezier_weight %s )' %( self.bezier_weight.get() ))
header.append('(k40_whisperer_set trace_gap %s )' %( self.trace_gap.get() ))
header.append('(k40_whisperer_set trace_speed %s )' %( self.trace_speed.get() ))
## header.append('(k40_whisperer_set unsharp_flag %s )' %( int(self.unsharp_flag.get()) ))
## header.append('(k40_whisperer_set unsharp_r %s )' %( self.unsharp_r.get() ))
## header.append('(k40_whisperer_set unsharp_p %s )' %( self.unsharp_p.get() ))
## header.append('(k40_whisperer_set unsharp_t %s )' %( self.unsharp_t.get() ))
header.append('(k40_whisperer_set t_timeout %s )' %( self.t_timeout.get() ))
header.append('(k40_whisperer_set n_timeouts %s )' %( self.n_timeouts.get() ))
header.append('(k40_whisperer_set ink_timeout %s )' %( self.ink_timeout.get() ))
header.append('(k40_whisperer_set designfile \042%s\042 )' %( self.DESIGN_FILE ))
header.append('(k40_whisperer_set inkscape_path \042%s\042 )' %( self.inkscape_path.get() ))
header.append('(k40_whisperer_set batch_path \042%s\042 )' %( self.batch_path.get() ))
self.jog_step
header.append("(=========================================================)")
return header
######################################################
def Quit_Click(self, event):
self.statusMessage.set("Exiting!")
self.Release_USB
root.destroy()
def mousePanStart(self,event):
self.panx = event.x
self.pany = event.y
self.move_start_x = event.x