Repository navigation
Expand file tree
/
Copy pathsimple_gui.py
More file actions
796 lines (665 loc) · 25 KB
/
Copy pathsimple_gui.py
File metadata and controls
796 lines (665 loc) · 25 KB
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
#!/usr/bin/python3
"""
Micro positioning tool for printing dropplets using the EPSON xp235 positioning platform
BEP PME 06 Hacking a commercial inkjet printer
Author: R. Slingerland
Date: XX-06-2017
Version: 0.1
"""
# ---- Import modules ----
from tkinter import *
from tkinter import Tk, Label, StringVar, IntVar, DoubleVar, Entry, Canvas, Scrollbar, Button, Menu, Toplevel, Text
from PIL import Image, ImageTk
from tkinter import filedialog, messagebox
from os import *
import os
import serial
import sys
from numpy import arctan, pi, sin, cos, tan, arcsin, arccos
#from main import *
#create the window
root = Tk()
#Operating system
#Linux = 1
#Windows = 2
#Enables zoom function and arduino settings
if str(sys.platform) == "win32":
operatingSystem = 2
print("OS Windows")
elif str(sys.platform) == "linux":
operatingSystem = 1
print("OS Linux")
else:
operatingSystem = input('Select operating system number: Linux (1), Windows (2): ')
# ---- variables ----
#imagePath = "substrate.png"
imagePath = StringVar()
imagePath.set("/home/localadmin/Desktop/GUI/EPNCS-tweak/initial_image.JPG")
#imagePath = filedialog.askopenfilename(title='open')
imageMagnification = DoubleVar()
imageMagnification.set(0.25) #default 1/5, change when using a different camera
calibrationLength_x = IntVar()
calibrationLength_y = IntVar()
calibrationLength_x.set(5000) #length of the calibration line in horizontal direction, unit = microns
calibrationLength_y.set(5000) #length of the calibration line in vertical direction, unit = microns
canvasxPosition = 0
canvasyPosition = 0
canvasHeight = 780
canvasWidth = 1040
canvas_abs_x = canvasxPosition+canvasWidth
canvas_abs_y = canvasyPosition+canvasHeight
x0 = IntVar()
y0 = IntVar()
x0.set(0)
y0.set(0)
x1 = IntVar()
y1 = IntVar()
x1.set(0)
y1.set(0)
dx = IntVar()
dy = IntVar()
dx.set(0)
dy.set(0)
line_x1 = DoubleVar()
line_y1 = DoubleVar()
line_x2 = DoubleVar()
line_y2 = DoubleVar()
line_x1.set(0)
line_y1.set(0)
line_x2.set(0)
line_y2.set(0)
x_calix1 = IntVar()
x_calix2 = IntVar()
x_caliy1 = IntVar()
x_caliy2 = IntVar()
x_calix1.set(0)
x_calix2.set(0)
x_caliy1.set(0)
x_caliy2.set(0)
y_calix1 = IntVar()
y_calix2 = IntVar()
y_caliy1 = IntVar()
y_caliy2 = IntVar()
y_calix1.set(0)
y_calix2.set(0)
y_caliy1.set(0)
y_caliy2.set(0)
dx_calix = IntVar()
dy_calix = IntVar()
dx_caliy = IntVar()
dy_caliy = IntVar()
dx_calix.set(0)
dy_calix.set(0)
dx_caliy.set(0)
dy_caliy.set(0)
dx_calix_corr = DoubleVar()
dy_caliy_corr = DoubleVar()
dx_microns_corr = DoubleVar()
dy_microns_corr = DoubleVar()
dx_calix_corr.set(0)
dy_caliy_corr.set(0)
dx_microns_corr.set(0)
dy_microns_corr.set(0)
dy_corr = DoubleVar()
dx_corr= DoubleVar()
dy_corr.set(0)
dx_corr.set(0)
dx_microns = DoubleVar()
dy_microns = DoubleVar()
dx_microns.set(0)
dy_microns.set(0)
dx_microns_round = DoubleVar()
dy_microns_round = DoubleVar()
dx_microns_round.set(0)
dy_microns_round.set(0)
dx_microns_round0 = DoubleVar()
dx_microns_round0.set(0)
moveMicrons = DoubleVar()
moveMicrons.set(100)
theta = DoubleVar()
theta.set(0)
theta_deg = DoubleVar()
theta_deg.set(0)
inputESCP2client = DoubleVar()
inputESCP2client.set(0)
xstartOrigin = 166000 # absolute x position of the origin (standard value in ESCP2 client = 166000 microns which is in the middle of the platform)
t = 7 #printcoord variable
#buttonPressed = 1
#modify root window
root.title("Microdroplet positioning tool")
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
#Labels lay-out
headerfont = ('times', 15, 'bold')
def openFilename():
filename = filedialog.askopenfilename(title='open')
return filename
#Does not work as wanted, check later
def openImage():
global imagePath
global image
global im
global im_width
global im_height
global im_size
global photo
global canvas
global xscrollbar
global yscrollbar
imagePath.set(openFilename())
print(imagePath.get())
canvas.destroy()
canvas = Canvas(root,height=canvasHeight,width=canvasWidth,xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set)
canvas.place(x=canvasxPosition,y=canvasyPosition)
im = Image.open(imagePath.get())
im_width, im_height = im.size
im = im.resize((int(im_width*imageMagnification.get()), int(im_height*imageMagnification.get())),Image.ANTIALIAS)
photo = ImageTk.PhotoImage(im)
image = canvas.create_image(0,0, anchor=NW, image=photo)
canvas.grid(row=0, column=0, sticky=N+S+E+W)
canvas.config(scrollregion=canvas.bbox(ALL))
xscrollbar.config(command=canvas.xview)
yscrollbar.config(command=canvas.yview)
print("openImage")
canvas.bind("<Motion>",crop)
canvas.bind("<ButtonPress-1>", printcoord)
canvas.bind('<B1-Motion>', onGrow)
reset()
def reloadImage():
global imagePath
global image
global im
global im_width
global im_height
global im_size
global photo
global canvas
global xscrollbar
global yscrollbar
canvas = Canvas(root,height=canvasHeight,width=canvasWidth,xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set)
canvas.place(x=canvasxPosition,y=canvasyPosition)
im = Image.open(imagePath.get())
im_width, im_height = im.size
im = im.resize((int(im_width*imageMagnification.get()), int(im_height*imageMagnification.get())),Image.ANTIALIAS)
photo = ImageTk.PhotoImage(im)
image = canvas.create_image(0,0, anchor=NW, image=photo)
canvas.grid(row=0, column=0, sticky=N+S+E+W)
canvas.config(scrollregion=canvas.bbox(ALL))
xscrollbar.config(command=canvas.xview)
yscrollbar.config(command=canvas.yview)
print("openImage")
canvas.bind("<Motion>",crop)
canvas.bind("<ButtonPress-1>", printcoord)
canvas.bind('<B1-Motion>', onGrow)
reset()
def rotateImage():
global imagePath
global image
global im
global im_width
global im_height
global im_size
global photo
global canvas
global xscrollbar
global yscrollbar
global t
canvas.destroy()
canvas = Canvas(root,height=canvasHeight,width=canvasWidth,xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set)
canvas.place(x=canvasxPosition,y=canvasyPosition)
im = Image.open(imagePath.get())
im_width, im_height = im.size
im = im.resize((int(im_width*imageMagnification.get()), int(im_height*imageMagnification.get())),Image.ANTIALIAS)
im = im.rotate(-theta.get()*180/pi)
photo = ImageTk.PhotoImage(im)
image = canvas.create_image(0,0, anchor=NW, image=photo)
canvas.grid(row=0, column=0, sticky=N+S+E+W)
canvas.config(scrollregion=canvas.bbox(ALL))
xscrollbar.config(command=canvas.xview)
yscrollbar.config(command=canvas.yview)
print("openImage")
canvas.bind("<Motion>",crop)
canvas.bind("<ButtonPress-1>", printcoord)
canvas.bind('<B1-Motion>', onGrow)
t=1
# ---- canvas ----
#creating scrollbars
xscrollbar = Scrollbar(root, orient=HORIZONTAL)
xscrollbar.grid(row=1, column=0, sticky=E+W)
yscrollbar = Scrollbar(root)
yscrollbar.grid(row=0, column=1, sticky=N+S)
#creating canvas
canvas = Canvas(root,height=canvasHeight,width=canvasWidth,xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set)
canvas.place(x=canvasxPosition,y=canvasyPosition)
im = Image.open(imagePath.get())
im_width, im_height = im.size
im = im.resize((int(im_width*imageMagnification.get()), int(im_height*imageMagnification.get())),Image.ANTIALIAS)
photo = ImageTk.PhotoImage(im)
image = canvas.create_image(0,0, anchor=NW, image=photo)
canvas.grid(row=0, column=0, sticky=N+S+E+W)
canvas.config(scrollregion=canvas.bbox(ALL))
xscrollbar.config(command=canvas.xview)
yscrollbar.config(command=canvas.yview)
print(xscrollbar.get())
# ---- zoom function ----
zoomcycle = 0
zimg_id = None
if operatingSystem ==2:
def zoomer(event):
global zoomcycle
if (event.delta > 0):
if zoomcycle != 4: zoomcycle += 1
elif (event.delta < 0):
if zoomcycle != 0: zoomcycle -= 1
crop(event)
print("zoooom")
root.bind("<MouseWheel>",zoomer)
else:
None
if operatingSystem ==1:
def zoom_in(event):
global zoomcycle
if zoomcycle != 0: zoomcycle -= 1
crop(event)
print(zoomcycle)
print(event.num)
def zoom_out(event):
global zoomcycle
if zoomcycle != 4: zoomcycle += 1
crop(event)
print(zoomcycle)
print(event.num)
root.bind("<Button-4>",zoom_out)
root.bind("<Button-5>",zoom_in)
else:
None
def crop(event):
global im
global zimg_id
global zoomcycle
global canvas
global zimg
if zimg_id: canvas.delete(zimg_id)
if (zoomcycle) != 0:
x,y = canvas.canvasx(event.x), canvas.canvasy(event.y)
if zoomcycle == 1:
tmp = im.crop((x-45,y-30,x+45,y+30))
elif zoomcycle == 2:
tmp = im.crop((x-30,y-20,x+30,y+20))
elif zoomcycle == 3:
tmp = im.crop((x-15,y-10,x+15,y+10))
elif zoomcycle == 4:
tmp = im.crop((x-6,y-4,x+6,y+4))
size = 300,200
zimg = ImageTk.PhotoImage(tmp.resize(size))
zimg_id = canvas.create_image(canvas.canvasx(event.x), canvas.canvasy(event.y), image=zimg)
print(zoomcycle)
canvas.bind("<Motion>",crop)
#root.bind("<MouseWheel>",zoomer) #use MouseWheel and function zoomer for Windows
#root.bind("<Button-4>",zoom_out)
#root.bind("<Button-5>",zoom_in)
#canvas.bind("<Motion>",crop)
# ---- /zoom function ----
def printcoord(event):
global t
global checkBox1
global checkBox2
global checkBox3
global checkBox4
global checkBox5
global checkBox6
global canvasWidth
global canvasHeight
global rectangle
global line
global start
global drawn
global theta
print("printcoord")
if (event.x <= canvasWidth) and (event.y<=canvasHeight):
#only do action clicking on canvas
#possibly try root.winfo_x() later
if t==7:
line_purple = "#e800e8"
line_x1.set(int(canvas.canvasx(event.x)))
line_y1.set(int(canvas.canvasy(event.y)))
px1, py1 = (line_x1.get() - 3), (line_y1.get() - 3)
px2, py2 = (line_x1.get() + 3), (line_y1.get() + 3)
canvas.create_oval(px1, py1, px2, py2, fill=line_purple, tag="dot7")
# checkBox2 = Label(root, text=u"\u2714")
# checkBox2.place(x=1390,y=50)
t=8
return None
if t==8:
line_purple = "#e800e8"
line_x2.set(int(canvas.canvasx(event.x)))
line_y2.set(int(canvas.canvasy(event.y)))
px1, py1 = (line_x2.get() - 3), (line_y2.get() - 3)
px2, py2 = (line_x2.get() + 3), (line_y2.get() + 3)
canvas.create_oval(px1, py1, px2, py2, fill=line_purple, tag="dot8")
# line = canvas.create_line
# start = event
# drawn = None
canvas.create_line(line_x1.get(),line_y1.get(),line_x2.get(),line_y2.get(), tag="line")
# checkBox2 = Label(root, text=u"\u2714")
# checkBox2.place(x=1390,y=50)
theta.set(arctan((line_y1.get()-line_y2.get())/(line_x2.get()-line_x1.get())))
theta_deg.set(theta.get()*180/pi)
t=10
return None
if t==1:
calibratex_blue = "#00008B"
x_calix1.set(int(canvas.canvasx(event.x)))
x_caliy1.set(int(canvas.canvasy(event.y)))
px1, py1 = (x_calix1.get() - 3), (x_caliy1.get() - 3)
px2, py2 = (x_calix1.get() + 3), (x_caliy1.get() + 3)
canvas.create_oval(px1, py1, px2, py2, fill=calibratex_blue, tag="dot1")
rectangle = canvas.create_rectangle
start = event
drawn = None
checkBox1 = Label(root, text=u"\u2714")
checkBox1.place(x=1370,y=50)
t=2
return None
if t==2:
calibratex_blue = "#00008B"
x_calix2.set(int(canvas.canvasx(event.x)))
x_caliy2.set(int(canvas.canvasy(event.y)))
px1, py1 = (x_calix2.get() - 3), (x_caliy2.get() - 3)
px2, py2 = (x_calix2.get() + 3), (x_caliy2.get() + 3)
canvas.create_oval(px1, py1, px2, py2, fill=calibratex_blue, tag="dot2")
checkBox2 = Label(root, text=u"\u2714")
checkBox2.place(x=1390,y=50)
t=3
return None
if t==3:
calibratey_blue = "#1E90FF"
y_calix1.set(int(canvas.canvasx(event.x)))
y_caliy1.set(int(canvas.canvasy(event.y)))
px1, py1 = (y_calix1.get() - 3), (y_caliy1.get() - 3)
px2, py2 = (y_calix1.get() + 3), (y_caliy1.get() + 3)
canvas.create_oval(px1, py1, px2, py2, fill=calibratey_blue, tag="dot3")
# explanation2.config(font = (None, None, 'bold'))
checkBox3 = Label(root, text=u"\u2714")
checkBox3.place(x=1370,y=70)
t=4
return None
if t==4:
calibratey_blue = "#1E90FF"
y_calix2.set(int(canvas.canvasx(event.x)))
y_caliy2.set(int(canvas.canvasy(event.y)))
px1, py1 = (y_calix2.get() - 3), (y_caliy2.get() - 3)
px2, py2 = (y_calix2.get() + 3), (y_caliy2.get() + 3)
canvas.create_oval(px1, py1, px2, py2, fill=calibratey_blue, tag="dot4")
checkBox4 = Label(root, text=u"\u2714")
checkBox4.place(x=1390,y=70)
t=5
return None
if t==5:
origin_green = "#5ba552"
x0.set(int(canvas.canvasx(event.x))) #when using global mouse position coordinates use x0.set(root.winfo_pointerx())
y0.set(int(canvas.canvasy(event.y)))
px1, py1 = (x0.get() - 3), (y0.get() - 3)
px2, py2 = (x0.get() + 3), (y0.get() + 3)
canvas.create_oval(px1, py1, px2, py2, fill=origin_green, tag="dot5")
# explanation3.config(font = (None, None, 'bold'))
checkBox5 = Label(root, text=u"\u2714")
checkBox5.place(x=1370,y=90)
t=6
return None
if t==6:
point1_yellow = "#ede625"
x1.set(int(canvas.canvasx(event.x)))
y1.set(int(canvas.canvasy(event.y)))
px1, py1 = (x1.get() - 3), (y1.get() - 3)
px2, py2 = (x1.get() + 3), (y1.get() + 3)
canvas.create_oval(px1, py1, px2, py2, fill=point1_yellow, tag="dot6")
# explanation4.config(font = (None, None, 'bold'))
checkBox6 = Label(root, text=u"\u2714")
checkBox6.place(x=1370,y=110)
t=10
return None
else:
return None
def onGrow(event):
global rectangle
global start
global drawn
global canvas
global line
global t
if t==2:
canvas = event.widget
if drawn: canvas.delete(drawn)
objectId = rectangle(canvas.canvasx(start.x), canvas.canvasy(start.y), canvas.canvasx(event.x), canvas.canvasy(event.y), tag="rectangle")
drawn = objectId
print("start.x = %r start.y = %r event.x = %r event.y = %r" % (start.x, start.y, event.x, event.y))
if t==8:
canvas = event.widget
if drawn: canvas.delete(drawn)
objectId = line(canvas.canvasx(start.x), canvas.canvasy(start.y), canvas.canvasx(event.x), canvas.canvasy(event.y), tag="line")
drawn = objectId
print("start.x = %r start.y = %r event.x = %r event.y = %r" % (start.x, start.y, event.x, event.y))
else:
return None
canvas.bind("<ButtonPress-1>", printcoord)
canvas.bind('<B1-Motion>', onGrow)
def reset():
global t
print(xscrollbar.delta(10,10))
t = 7
x0.set(0)
y0.set(0)
x1.set(0)
y1.set(0)
dx.set(0)
dy.set(0)
x_calix1.set(0)
x_calix2.set(0)
x_caliy1.set(0)
x_caliy2.set(0)
y_calix1.set(0)
y_calix2.set(0)
y_caliy1.set(0)
y_caliy2.set(0)
dx_calix.set(0)
dy_calix.set(0)
dx_caliy.set(0)
dy_caliy.set(0)
dx_microns.set(0)
dy_microns.set(0)
theta.set(0)
theta_deg.set(0)
dx_microns_round.set(0)
dy_microns_round.set(0)
dx_microns_round0.set(0)
inputESCP2client.set(0)
canvas.delete("dot1")
canvas.delete("dot2")
canvas.delete("dot3")
canvas.delete("dot4")
canvas.delete("dot5")
canvas.delete("dot6")
canvas.delete("rectangle")
canvas.delete("line")
canvas.delete("dot7")
canvas.delete("dot8")
checkBox1.destroy()
checkBox2.destroy()
checkBox3.destroy()
checkBox4.destroy()
checkBox5.destroy()
checkBox6.destroy()
def buttonRelease(event):
global buttonPressed
buttonPressed = 0
canvas.bind("<ButtonRelease-1>",buttonRelease)
def calculate():
#Computing coordinates relative to photo frame
dx.set(x1.get()-x0.get())
dy.set(y1.get()-y0.get())
dy_corr.set(dy.get()/cos(theta.get())+(dx.get()-dy.get()*tan(theta.get()))*cos(theta.get()))
dx_corr.set((dx.get()-dy.get()*tan(theta.get()))*cos(theta.get()))
dx_calix.set(abs(x_calix2.get()-x_calix1.get()))
dy_calix.set(abs(x_caliy1.get()-x_caliy2.get()))
# dx_calix_corr.set((dy_calix.get()-dx_calix.get()*tan(theta.get()))*cos(theta.get())+(dx_calix.get()/cos(theta.get()))) #corrected with respect to the print line
dx_calix_corr.set(dx_calix.get()/cos(theta.get())) #corrected with respect to the print line
dx_caliy.set(abs(y_calix1.get()-y_calix2.get()))
dy_caliy.set(abs(y_caliy1.get()-y_caliy2.get()))
dy_caliy_corr.set(dy_caliy.get()/cos(theta.get())) #corrected with respect to the print line
dx_microns.set(calibrationLength_x.get()*dx.get()/dx_calix.get())
dy_microns.set(calibrationLength_y.get()*dy.get()/dy_caliy.get())
dx_microns_corr.set(dx_microns.get())
dy_microns_corr.set(dy_microns.get())
dx_microns_round.set("%.3f" % dx_microns.get())
dy_microns_round.set("%.3f" % dy_microns.get())
dx_microns_round0.set("%.f" % dx_microns.get())
inputESCP2client.set(xstartOrigin+dx_microns_round0.get())
def client_exit():
mExit=messagebox.askyesno(title="Quit", message="Are You Sure?")
if mExit>0:
root.destroy()
return
def sendtoArduino():
calculate()
global dy_microns
if operatingSystem == 1:
arduino = serial.Serial("/dev/ttyACM0")
if operatingSystem == 2:
arduino = serial.Serial('COM3')
else:
print("Select operationSystem")
print(arduino.name)
# arduino = serial.Serial('COM3') #COM3 is the usb port from the arduino, may vary
# timeout=0.1 #arduino connectie maken
if arduino.is_open == 1:
print("usb working") # no conflict on usb
start = arduino.readline().decode().strip()
print(start)
translationRate = 500 #one rotation is 500 microns rotation using the 28BYJ-48 stepper motor
stepsperRotation = 64*64 #one rotation is 64*64=4096 steps using the 28BYJ-48 stepper motor
steps = -dy_microns.get()/translationRate*stepsperRotation
# steps = 5/translationRate*stepsperRotation
distanceStr = str(steps)
print ("steps to travel")
print (steps)
arduino.write(distanceStr.encode()) #newpos is the variable distance to travel
arduino.close()
print ("usb closed, program finished")
def sendValuetoArduino():
global moveMicrons
if operatingSystem == 1:
arduino = serial.Serial("/dev/ttyACM0")
if operatingSystem == 2:
arduino = serial.Serial('COM3')
else:
print("Select operationSystem")
print(arduino.name)
# arduino = serial.Serial('COM3') #COM3 is the usb port from the arduino, may vary
# timeout=0.1 #arduino connectie maken
if arduino.is_open == 1:
print("usb working") # no conflict on usb
start = arduino.readline().decode().strip()
print(start)
translationRate = 500 #one rotation is 500 microns rotation using the 28BYJ-48 stepper motor
stepsperRotation = 64*64 #one rotation is 64*64=4096 steps using the 28BYJ-48 stepper motor
steps = moveMicrons.get()/translationRate*stepsperRotation
# steps = 5/translationRate*stepsperRotation
distanceStr = str(steps)
print ("steps to travel")
print (steps)
arduino.write(distanceStr.encode()) #newpos is the variable distance to travel
arduino.close()
print ("usb closed, program finished")
def callESCP2client():
print("callESCP2client")
def calibratePlatform():
global moveMicrons
print(moveMicrons.get())
calibrate_window = Toplevel()
calibrate_window.title("Calibrate platform")
w, h = 300, 200
calibrate_window.geometry("%dx%d+0+0" % (w, h))
Label(calibrate_window, text="Move the platform (in microns)").place(x=10,y=10)
Entry(calibrate_window, textvariable=moveMicrons).place(x=10,y=40)
print(moveMicrons.get())
ArduinoValueButton = Button(calibrate_window, text="Send to Arduino", width=20, command=sendValuetoArduino)
ArduinoValueButton.place(x=10, y=60)
Label(calibrate_window, text="Negative value: move inside printer").place(x=10,y=100)
Label(calibrate_window, text="Positive value: move towards observer").place(x=10,y=120)
#Menu
menu = Menu(root)
root.config(menu=menu)
file = Menu(menu)
file.add_command(label="Open image", command=openImage)
file.add_command(label="Exit", command=client_exit)
menu.add_cascade(label="File", menu=file)
edit = Menu(menu)
edit.add_command(label="Execute ESCP2 client", command=callESCP2client)
edit.add_command(label="Calibrate platform", command=calibratePlatform)
menu.add_cascade(label="Edit", menu=edit)
#undoButton = Button(root, text="undo", command=undo)
#undoButton.place(x=1000,y=390)
# ---- sidebar -----
#SELECT
explanation_h = Label(root, text="Select")
explanation_h.config(font=headerfont)
explanation_h.place(x=1100,y=20)
#explanation_h.grid(row=0, column=3, sticky=N)
explanation1 = Label(root, text="borders of the horizontal calibration sample").place(x=1100,y=50)
explanation2 = Label(root, text="borders of the vertical calibration sample").place(x=1100,y=70)
explanation3 = Label(root, text="printed (0,0) point").place(x=1100,y=90)
explanation4 = Label(root, text="desired print location").place(x=1100,y=110)
#explanation1 = Label(root, text="borders of the horizontal calibration sample").grid(row=0, column =3, sticky=NW)
#explanation2 = Label(root, text="borders of the vertical calibration sample").grid(row=0, column =3, sticky=NW)
#explanation3 = Label(root, text="printed (0,0) point").grid(row=0, column =3, sticky=NW)
#explanation4 = Label(root, text="desired print location").grid(row=0, column =3, sticky=NW)
Button(root, text="Rotate image", width=20, command=rotateImage).place(x=1400,y=70)
#SETTINGS
settings_h = Label(root, text="Settings")
settings_h.config(font=headerfont)
settings_h.place(x=1100,y=150)
#Change Image Magnification factor
Label(root, text="Image Magnification Factor = ").place(x=1100,y=175)
Entry(root, textvariable=imageMagnification).place(x=1300, y=175)
Button(root, text="Select", width=10, command=reloadImage).place(x=1300,y=200)
cali_comment = Label(root, text="Size of the calibration sample").place(x=1100,y=225)
cali_hor = Label(root, text="Horizontal").place(x=1100,y=255)
cali_ver = Label(root, text="Vertical").place(x=1100,y=275)
Label(root, text="microns").place(x=1350,y=255)
Label(root, text="microns").place(x=1350,y=275)
calibrateLengthx = Entry(root, textvariable=calibrationLength_x).place(x=1180,y=255)
calibrateLengthy = Entry(root, textvariable=calibrationLength_y).place(x=1180,y=275)
#CONTROL
control_h = Label(root, text="Control")
control_h.config(font=headerfont)
control_h.place(x=1100,y=305)
resetButton = Button(root, text="Reset", width=20, command=reset)
resetButton.place(x=1100, y=340)
calcButton = Button(root, text="Calculate", width=20, command=calculate)
calcButton.place(x=1100, y=370)
arduinoButton = Button(root, text="Send to Arduino", width=20, command=sendtoArduino)
arduinoButton.place(x=1100, y=400)
#OUTPUT
outputl_h = Label(root, text="Output")
outputl_h.config(font=headerfont)
outputl_h.place(x=1100,y=430)
Label(root, text=u"\u0394"+"x = ").place(x=1100,y=460)
Label(root, text=u"\u0394"+"y = ").place(x=1100,y=480)
output_dx = Label(root, textvariable=dx_microns_round)
output_dy = Label(root, textvariable=dy_microns_round)
output_dx.place(x=1130,y=460)
output_dy.place(x=1130,y=480)
Label(root, text="microns").place(x=1200,y=460)
Label(root, text="microns").place(x=1200,y=480)
output_comment = Label(root, text="Fill in in ESCP2-client (microns):")
output_comment.config(font=headerfont)
output_comment.place(x=1100,y=530)
output = Entry(root, textvariable=inputESCP2client)
output.place(x=1100,y=580)
output.configure(state="readonly")
theta_label = Label(root, textvariable=theta_deg).place(x=1300,y=480)
root.mainloop()
# ---- TO DO ----
#using scrolling to zoom whole picture
#keep click position