-
Notifications
You must be signed in to change notification settings - Fork 0
/
RBD21.py
2277 lines (1756 loc) · 70.9 KB
/
RBD21.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
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 07 11:33:05 2017
@author: DELL
"""
#========================= req module install & import =========================#
req_modules=["Tkinter",'datetime','time','tkMessageBox','pyserial','thread','ttk','platform',"PIL",'Image',"sys","os","opencv-python"]
plt_modules=["numpy","matplotlib","scipy"]
req_modules.extend(plt_modules)
def install_and_import(package):
import importlib
global manually,proxy
_import=True
try:
if package=='pyserial':
importlib.import_module("serial")
elif package=='opencv-python':
importlib.import_module("cv2")
else:
importlib.import_module(package)
# print 'import ',package
except ImportError:
print 'import ERROR: ',package
manually.append(package)
print " installing "+str(package)+"..."
import pip
#print pip.__version__
try:
try:
pip.main(['install', "--retries=1",package])
except:
pip.main(['install', "--retries=1",package])
# pip.main(['uninstall', 'leancloud'])
if package=='pyserial':
importlib.import_module("serial")
elif package=="opencv-python":
importlib.import_module("cv2")
else:
importlib.import_module(package)
except ImportError:
response=["y","n"]
if proxy==None:
is_proxy=str(raw_input("Are you running Internet behind a proxy (y/n)? : "))
while 1:
if not is_proxy in response:
print "Your response "+str((is_proxy))+" was not one of the expected responses: (y , n) "
is_proxy=str(raw_input("Are you running Internet behind a proxy (y/n)? : "))
else:
break
if is_proxy=="y" :
proxy=str(raw_input("Enter proxy_IP & proxy_Port ex: 10.10.78.21:3128 : "))
pip.main(['install','--proxy='+proxy, package])
#=====================================#
import sys,os,importlib
manually=[]
proxy=None
print " ----installing Packages... "
for package in req_modules:
# try:
if package=="Image":
try:
from PIL import Image,ImageTk
except ImportError:
install_and_import(package)
else:
install_and_import(package)
# except Exception as e:
# exc_type, exc_obj, exc_tb = sys.exc_info()
# fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
# print(exc_type, fname, exc_tb.tb_lineno)
try:
if package=="pyserial":
package=="serial"
globals()[package] = importlib.import_module(package)
print 'import ',package
except ImportError:
pass
# manually.append(package)
if not manually==[]:
if 'pyserial' in manually:
try:
import serial
manually.remove("pyserial")
except ImportError:
pass
if 'PIL' in manually:
try:
from PIL import Image,ImageTk
manually.remove("PIL")
manually.remove("Image")
except ImportError:
pass
if manually==[]:
print "_______________________________"
print "Packages not installed yet:"+str(manually)
print "Try to install them manually. "
else:
print "All Packages imported successfully. "
else:
print "All Packages imported successfully. "
#================================ installation finished =========================================#
#================================ GUI Part ==========================================#
DIR= os.getcwd()
import Tkinter as t
import Tkinter as tk
from Tkinter import *
import time
import datetime
import tkMessageBox
import serial
import serial.tools.list_ports
import Cell_Pin
#from Cell_Pin import Port,ser
import ttk
import thread
from time import gmtime, strftime
import os,csv,sys
from PIL import Image,ImageTk
import platform
import cv2
import subprocess
from subprocess import Popen,PIPE
#from operator import itemgetter3
#=============== plot ================#
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import matplotlib.patches as mpatches
import scipy.interpolate as interpolate
from tool_tip import CreateToolTip
#========================================
fil = ""
refPt = []
cropping = False
imageimage = np.zeros((480,640,3))
total_cell=10
no_pin=8
host_addr=0
cell_no=0
Data=0
packet=[]
cycle=None
test_flag=None
HOST_Version = 21
root=t.Tk()
root_color='slategray'
w = root.winfo_screenwidth()#int(round(h*.90)
h = root.winfo_screenheight()
root.geometry(("%dx%d+%d+%d" %( w ,int(round(h*.90)) ,0,0))) ## set location dyanamic
root.minsize(width=200,height=100)
root.configure(background = root_color)
root.title("RBD Debugging Tool - v" + str(HOST_Version-15))
root.state('zoomed')
#=============================== for scrollbars=======================================#
def onFrameConfigure(canvas):
'''Reset the scroll region to encompass the inner frame'''
canvas.configure(scrollregion=canvas.bbox("all"))
#============
f0=t.Frame(root, bg="lightskyblue4",relief=t.RIDGE,bd=1 ,highlightthickness=2,pady=2)
f0.pack(side=TOP, expand = 1,fill=BOTH)
f1=t.Frame(root, bg="grey92",relief=t.RIDGE ,padx=1,pady=8)
f1.pack(side=TOP, expand = 1,fill=X)
canvas1=f1
#canvas2= tk.Canvas(f1 , background="grey92" )
#canvas2.pack(side="top", fill="both", expand=True )
f4=t.Frame(root, bg="grey23",relief=t.RIDGE,bd=1, height=200 ,highlightthickness=1,pady=1, borderwidth=1)
f4.pack(side=BOTTOM, expand = 1,fill=X) #bg="grey23"
f4.propagate(1)
#====================main central frame=====================#
f2=t.Frame(root, bg="grey23",relief=t.RIDGE,bd=1, height=400 ,highlightthickness=0,pady=1, borderwidth=2)
f2.pack(side=BOTTOM, expand = 1,fill=BOTH)
f2.propagate(0)
#notebook = ttk.Notebook(f2)
#nf1 = ttk.Frame(notebook)
#nf2 = ttk.Frame(notebook)
#notebook.add(nf1, text='Mode One')
#notebook.add(nf2, text='Mode Two')
#notebook.pack(side=TOP,expand = 1,fill=BOTH)
canvas3= tk.Canvas(f2, borderwidth=1, background="grey90" ,bd=2)
canvas3.pack(side="top", fill="both", expand=True)
f3=t.Frame(canvas3, bg="#e0ebeb",relief=t.RIDGE,bd=1, height=400 ,highlightthickness=0,pady=1)
f3.pack(side=BOTTOM, expand = 1,fill=BOTH) #checkbutton winow
f3.propagate(0)
#============================ ttk_notebook ==================#
##================= background Image =====================##
background_image=ImageTk.PhotoImage(file= "b8.png") #a1,b8,b10,b12,b15,b16,b17
background_label = tk.Label(f3, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
f3.pack_propagate(0)
#======================== frame to hold function buttons =======================#
fn_btns_frame=tk.Frame(f3, bg="grey45",relief=t.RIDGE,bd=1 ,highlightthickness=1,padx=2,pady=1,borderwidth=1)
fn_btns_frame.pack(side=BOTTOM , anchor="s", expand = 1,fill=None,pady=40)
#ttk.Separator(f3,orient=HORIZONTAL).pack(side="top",fill=X,pady=25)
#-------------------------------------------------------------
var_output= IntVar()
output_chk= Checkbutton(fn_btns_frame,bd=2 ,text="Optical Testing", variable = var_output,\
onvalue =1, offvalue = 0, \
bg='grey52',fg='#300302',padx=5)
output_chk.pack(side="left",ipadx=2)
output_chk_ttp = CreateToolTip(output_chk, " Real Time optical testing ")
#-------------------------------------------------------------
##==================== func_button_image ========###
def button_image(b,img):
image = ImageTk.PhotoImage(file=img)
b.config(image=image)
b.image = image
##===================================Toolbar(Menubar)=================#
#def donothing():
# filewin = Toplevel(root)
# button = Button(filewin, text="Do nothing button")
# button.pack()
#
#def openfile():
# path=os.getcwd()
# os.startfile(str(path))
#menubar = Menu(root,fg='red')
#
#filemenu = Menu(menubar, tearoff=0)
#filemenu.add_command(label="New", command=donothing)
#filemenu.add_command(label="Open", command=openfile)
#filemenu.add_command(label="Save", command=donothing)
#filemenu.add_command(label="Save as...", command=donothing)
#filemenu.add_command(label="Close", command=donothing)
#
#filemenu.add_separator()
#
#filemenu.add_command(label="Exit", command=root.quit)
#menubar.add_cascade(label="File", menu=filemenu)
#
#csvmenu = Menu(menubar, tearoff=0)
#csvmenu.add_command(label="Slave_wise", command=donothing)
#
#csvmenu.add_separator()
#
#csvmenu.add_command(label="Row_wise", command=donothing)
#
#
#menubar.add_cascade(label="csv", menu=csvmenu)
#
#helpmenu = Menu(menubar, tearoff=0)
#helpmenu.add_command(label="Help Index", command=donothing)
#helpmenu.add_command(label="About...", command=donothing)
#menubar.add_cascade(label="Help", menu=helpmenu)
#
#root.config(menu=menubar)
#=============================================func to Get =====================================================#
def GetHostAdress(event=None):
try:
host_addr=Host.get()
except ValueError:
tkMessageBox.showwarning("WARNING", " Enter Proper Host Address ! ")
return
#tkMessageBox.font=('arial',28,'bold')
tkMessageBox.showinfo("OK", " Entered "+'Host Address is '+str(host_addr))
return
def GetData(event=None):
try:
Data=datac.get()
except ValueError:
tkMessageBox.showwarning("WARNING", " Enter Proper Data ! . Data must be in range (0,255) ")
return
#tkMessageBox.font=('arial',28,'bold')
if not Data in range(0,256):
tkMessageBox.showwarning("Err", " Data must be in range (0,255)")
return
#tkMessageBox.showinfo("OK", " Entered "+'Data is '+str(Data))
return Data
def GetCellNo(event=None):
try:
cell_no=cell.get()
except ValueError:
tkMessageBox.showwarning("WARNING", " Enter Proper Cell no !. must be integer in range (1,10) ")
return
if not cell_no in range(1,11):
tkMessageBox.showwarning("Err", " Cell_no must be in range (1,10)")
return
#tkMessageBox.font=('arial',28,'bold')
#tkMessageBox.showinfo("OK", " Entered "+'Cell no is '+str(cell_no))
Data=GetData()
main_func(Data,cell_no)
#for widget in f2.winfo_children():
# widget.destroy()
#=============================================func to Main=====================================================#
def main_func(Data,cell_no):
global ser,Port
try: ##change\remove
ser=serial.Serial(Port.get(), 115200)
#print('Seial_Port_was_already_closed')
#ser.close()
except serial.SerialException:
tkMessageBox.showwarning("WARNING", " Port "+Port.get()+" not Available! or Busy! ")
if ser.isOpen():
ser.close()
return
try:
host_addr=Host.get()
if abs(host_addr) not in range(0,256):
tkMessageBox.showinfo("WARNING", "Please Enter Proper Host address. Host address must be in range(0, 256) ")
ser.close()
return
else:
if ser.isOpen():
Cell_Pin.send_data (ser,host_addr,Cell_Pin.ACC_CMD,cell_no,Data)
ser.close()
except ValueError:
tkMessageBox.showwarning("WARNING", " Enter Host Address First ! ")
ser.close()
return
#=================================Label and Entry Widgets on f0============================================#
#==========Module_ID========##
M_id=t.StringVar()
lblM_id= t.Label(f0,font=('arial',10,'bold'),text="Module_ID",bd=2,anchor="w" ,relief=t.RIDGE,highlightthickness=1)
lblM_id.pack(side=LEFT, expand = 1,fill=None,ipadx=2)
txtM_id= t.Entry(f0,font=('arial',9,'bold'),textvariable=M_id,bd=4,insertwidth=3,bg="gray99",justify='left')
txtM_id.pack(side=LEFT, expand = 1,fill=None)
#==========version===========#
#ttk.Separator(f0,orient=HORIZONTAL).pack(side=LEFT, expand = 1,fill=Y,ipadx=11)
lbl_Vstatus= t.Label(f0,font=('arial',8,'bold'),text=" ",bd=3 ,width=7,anchor="w",pady=2,relief=t.SUNKEN,justify='center')
lbl_Vstatus.pack(side=RIGHT, expand = 1,fill=None,ipadx=1)
lbl_version= t.Label(f0,font=('arial',9,'bold'),text="Version",highlightthickness=1,bd=3,anchor="w" ,relief=t.RIDGE)
lbl_version.pack(side=RIGHT, expand = 1,fill=None,ipadx=1)
#==================================HOST_ADDR=================================##
Host=t.IntVar()
txtHost= t.Entry(f0,font=('arial',9,'bold'),textvariable=Host,bd=3,width=3,insertwidth=3,bg="gray99",justify='center')
txtHost.pack(side=RIGHT, expand = 1,fill=X,padx=1)
lblHost= t.Label(f0,font=('arial',9,'bold'),text="Host",bd=2,anchor="w" ,highlightthickness=1,relief=t.RIDGE)
lblHost.pack(side=RIGHT, expand = 1,fill=None)
lblHost_ttp = CreateToolTip(lblHost, " Host Addres ")
#txtHost.focus_set()
#btnHost=t.Button(f0,font=('arial',8,'bold'),text="ENTER",fg="Black",bd=8,width=8,command=GetHostAdress,pady=2).pack(side=LEFT, expand = 1,fill=X)
#txtHost.bind('<Return>', GetHostAdress)
##------------------------------------Test Status ----------------------------#
lbl_status= t.Label(f3,font=('arial',8,'bold'),text=" ",bd=3 ,width=7,anchor="nw",pady=3,relief=t.SUNKEN,justify='center')
lbl_status.pack(side="right")
lbl_Test= t.Label(f3,font=('arial',8,'bold'),text="Status", width=7,anchor="center",pady=4,
highlightthickness=1,relief=t.RIDGE,justify='center')
lbl_Test.pack(side="right")
lbl_Test_ttp = CreateToolTip(lbl_Test, "Test Result status")
ttk.Separator(f3,orient=HORIZONTAL).place(x=0,y=30, relwidth=1)
#=================================cycles_widgets============================================#
cycle_var=t.IntVar(value=1)
txtcycles= t.Entry(f3,font=('arial',8,'bold'),exportselection=0,textvariable=cycle_var,bd=4,width=15,insertwidth=3 ,bg="lightskyblue2",justify='center')
txtcycles.pack(side="right")
lbl_cycles= t.Label(f3,font=('arial',8,'bold'),text="Cycles", width=7,anchor="center",pady=3,
highlightthickness=1,relief=t.RIDGE,justify='center')
lbl_cycles.pack(side="right")
#=============================================combobox to save_as option =====================================================#
save_as_list=['Slaves matrix','Single Row']
save_var=StringVar()
cbo_save= ttk.Combobox( f3)
cbo_save.config(values=save_as_list,textvariable=save_var,font=('flat',9,),width=16)#,background="lightskyblue"
try:
cbo_save.set(save_as_list[0])
except:
pass
#cbo.place( x=100,y=1 )
cbo_save.pack(side="right")
#cbo.pack( expand=1,fill=X )
cbo_save.config(state='readonly')
lbl_save_as= t.Label(f3,font=('arial',8,'bold'),text="Save as..",bd=2,bg='grey96',
highlightthickness=1,anchor="nw",relief=t.RIDGE)
lbl_save_as.pack(side="right",ipady=1)
#=============================================combobox to pattern option =====================================================#
pat_list=['Pattern','Custom']
pat_var=StringVar()
cbo_pat= ttk.Combobox( f3)
cbo_pat.config(values=pat_list,textvariable=pat_var,font=('flat',9,),width=16, )
try:
cbo_pat.set(pat_list[1])
except:
pass
cbo_pat.pack(side="right")
cbo_pat.config(state='readonly')
#======================label_TEST=====================#
lbl_test_pat= t.Label(f3,font=('arial',8,'bold'),text=" Pattern ",bd=2,bg='grey96',
highlightthickness=1,anchor="nw",relief=t.RIDGE)
lbl_test_pat.pack(side="right",ipady=1)
lbl_test_pat_ttp = CreateToolTip(lbl_test_pat, " Test Patterns ")
#=============================================scanning combobox as a function to Get port and ser=====================================================#
ser=None
com_ports=list(serial.tools.list_ports.comports())
#print com_ports
cbo = ttk.Combobox( f0)
def scan_ports():
global ser,Port,cbo
port_list=[]
com_ports=list(serial.tools.list_ports.comports())
#____For windows8____#
# print com_ports
for e in com_ports:
# print e, " : " ,e.device
port_list.append(e[0])
##____new-method_____#
#
#
#try:
# #______NEW-METHOD_______#
# for item in com_ports:
# port_list.append(item.device)
#except:
##____old-method_____#
#
# port_list=list(serial.tools.list_ports.comports())
# for i in range(0,len(port_list)):
# for j in range(0,len(str(port_list[i]))):
# if (str(port_list[i]))[j]=='-':
# port_list[i]=str(port_list[i])[0:j-1]
# print port_list[i]
# break
Port =StringVar()
# cbo = ttk.Combobox( f0)
cbo.config(values=port_list,textvariable=Port,font=('flat',9,),width=20, )
try:
cbo.set(port_list[-1])
except:
# print "exception : no port detected"
pass
#cbo.place( x=100,y=1 )
cbo.pack(side='right',expand=True,fill=None)
#cbo.pack( expand=1,fill=X )
scan_ports()
##=============================================combobox to Get port and ser=====================================================#
#ser=None
#port_list=[]
#com_ports=list(serial.tools.list_ports.comports())
##____For windows8____#
##print com_ports
#for e in com_ports:
## print e,e.device
# port_list.append(e[0])
#
###____new-method_____#
##
##
##try:
## #______NEW-METHOD_______#
## for item in com_ports:
## port_list.append(item.device)
##except:
###____old-method_____#
##
## port_list=list(serial.tools.list_ports.comports())
## for i in range(0,len(port_list)):
## for j in range(0,len(str(port_list[i]))):
## if (str(port_list[i]))[j]=='-':
## port_list[i]=str(port_list[i])[0:j-1]
## print port_list[i]
## break
#
#
#
#Port =StringVar()
#cbo = ttk.Combobox( f0)
#
#cbo.config(values=port_list,textvariable=Port,font=('flat',9,),width=20, )
#try:
# cbo.set(port_list[-1])
#except:
# pass
##cbo.place( x=100,y=1 )
#cbo.pack(side='right',expand=True,fill=None)
##cbo.pack( expand=1,fill=X )
#################################
fill=' '
lbl_fill= t.Label(f0 ,text=fill*4, bg='lightskyblue4',anchor="nw",pady=6,relief=t.FLAT)
lbl_fill.pack(side='left',expand=True ,fill=None)
lbl_channel= t.Label(f0,font=('arial',10,'bold'),text="Channel",bd=2,bg='grey99',anchor="nw",
highlightthickness=1,relief=t.RIDGE)
lbl_channel.pack(side='right', expand=True )
##############################
#ser=None
#
#port_list=None
#
#
#Port =StringVar()
#
#def scan_port():
# global Port,port_list,cbo
# time.sleep(.4)
# port_list=list(serial.tools.list_ports.comports())
# for i in range(0,len(port_list)):
# for j in range(0,len(str(port_list[i]))):
# if (str(port_list[i]))[j]=='-':
# port_list[i]=str(port_list[i])[0:j-1]
## print port_list[i]
# break
# cbo.config(values=port_list,textvariable=Port,font=('flat',9,),width=25 )
#
# time.sleep(.4)
# scan_port()
#
#cbo = ttk.Combobox( f0)
#cbo.config(values=port_list,textvariable=Port,font=('flat',10,),width=25 )
#cbo.pack(side='right',expand=True,fill=None)
#
#thread.start_new_thread(scan_port, ())
#=========================================Time_Stamp========================================#
showDate = strftime("%Y-%m-%d %H:%M:%S", time.localtime() )
lblDate_show= t.Label(f0,font=('arial',10,'bold'),text='Date&time: '+showDate[0:10]+' '+showDate[10:16],fg="white" ,bg='lightskyblue4')#bg=root color
lblDate_show.pack(side="bottom",anchor='w',padx=2,fill=X)
def show_time():
global showDate
showDate = strftime("%Y-%m-%d %H:%M:%S", time.localtime() )
lblDate_show.config(text=' '+showDate[0:10]+' '+showDate[10:])
root.after(1000,show_time)
thread.start_new_thread(show_time, ())
##=============================fill_space================##
fill=' '
lbl_fill= t.Label(f0 ,text=fill*4, bg='lightskyblue4',anchor="nw",pady=6,relief=t.FLAT)
lbl_fill.pack(side='left',expand=True ,fill=X)
#lbl_ch= t.Label(f0,font=('arial',10,'bold'),text="Channel",bd=3,bg='grey99',anchor="nw",relief=t.FLAT)
#lbl_ch.pack(side='right',expand=True )
#=================================Label and Entry Widgets on f1============================================#
cell=t.IntVar(value=1)
lblCell= t.Label(canvas1,font=('arial',10,'bold'),text="Cell No:",relief=t.FLAT,justify='right')
lblCell.pack(side='left', expand = 1)
txtCell= t.Entry(canvas1,font=('arial',10,'bold'),textvariable=cell,insertwidth=1,bg="gray99",justify='center')
txtCell.pack(side='left', expand = 1,anchor='w')
#txtCell.bind('<Return>', GetCellNo)
#lbl= t.Label(canvas1,bg='grey50',width=22)
#lbl.pack(side='left', expand = 1,fill=X)
#lbl= t.Label(canvas1,bg='grey50',width=22)
#lbl.pack(side='left', expand = 1,fill=X)
#lbl= t.Label(canvas1,bg='grey50',width=22)
#lbl.pack(side='left', expand = 1,fill=X)
#txtHost.focus_set()
datac=t.IntVar(value=0)
#lbl= t.Label(canvas2,bg='grey50',width=22)
#lbl.pack(side='left', expand = 1,fill=X)
lblData= t.Label(canvas1,font=('arial',10,'bold'),text="Data:",anchor="w",relief=t.FLAT,justify='left')
lblData.pack(side='left', expand = 1 ,anchor=CENTER)
txtData= t.Entry(canvas1,font=('arial',10,'bold'),textvariable=datac,insertwidth=1,bg="gray99",justify='center')
txtData.pack(side='left', expand = 1 ,anchor='w')
#txtData.bind('<Return>', GetCellNo)
#txtHost.focus_set()
#lbl= t.Label(canvas2,bg='grey50',width=14)
#lbl.pack(side='left', expand = 1,fill=X)
#btnData=t.Button(canvas1,font=('arial',8,'bold'),text="SEND",bg='#e6f7ff',fg="Black",bd=2,width=8,command=GetCellNo ,relief=t.RAISED,activebackground='#b3e6ff')
btnData=t.Button(canvas1 ,command=GetCellNo,bd=1 ,highlightthickness=1)
button_image(btnData,"i1.ico")
btnData.pack(side=LEFT, expand = 1 ,anchor='w')
btnData_ttp = CreateToolTip(btnData, " SEND ")
#lbl= t.Label(canvas2,bg='grey50',width=22)
#lbl.pack(side='left', expand = 1,fill=X)
#lbl= t.Label(canvas2,bg='grey50',width=22)
#lbl.pack(side='left', expand = 1,fill=X)
#=================================Label and Widgets on f2============================================#
def go(x):
j=x[0]
i=x[1]
print Var[j][i].get()
Var=['VarC']*total_cell
Tag=['TagC']*total_cell
sp=100
#===========================80 pins====================#
for j in range(0,total_cell):
Var[j]=['VarP']*no_pin
Tag[j]=['TagP']*no_pin
for i in range (0,no_pin):
Var[j][i] = IntVar()
#print Var[j][i]
if i<4:
Tag[j][i]= Checkbutton(f3 , variable = Var[j][i],command=lambda x=(j,i): go(x), \
onvalue =pow(2,i), offvalue = 0, height=1, \
width = 2,bg='grey74')
Tag[j][i].place(x=sp+100+85*j,y=30*i+100)
if i>=4:
Tag[j][i]= Checkbutton(f3 , variable = Var[j][i],command=lambda x=(j,i): go(x), \
onvalue =pow(2,(i-1)), offvalue = 0, height=1, \
width = 2,bg='grey74')
Tag[j][i].place(x=sp+125+85*j,y=30*(i-4)+100)
for j in range(0,total_cell):
Tag[j][3].config(onvalue =pow(2,6))
Tag[j][7].config(onvalue =pow(2,7))
#================================cell no labels=========================#
lblcn=[0]*total_cell
for i in range(0,total_cell):
lblcn[i]= t.Label(f3,bg='white',text=str(i+1) ,bd=2,padx=3)
lblcn[i].place(x=sp+125+85*(i),y=0+73)
#================================ func for vertical and hrizontal extra checkbuttons=========================#
def go_all():
if Var_all.get()==1:
value=1
else:
value=0
for i in range(0,4):
Var_V[i].set(value)
go_V()
def go_V():
# for i in range(0,20):
# Var_H[i].set(0)
# go_H()
for i in range(0,3):
if not Var_V[i].get()==0: #(select)
for j in range(0,total_cell):
Var[j][i].set(pow(2,i))
Var[j][i+4].set(pow(2,i+3))
if Var_V[i].get()==0:#(deselect)
for j in range(0,total_cell):
Var[j][i].set(0)
Var[j][i+4].set(0)
i=3
if not Var_V[i].get()==0:
for j in range(0,total_cell):
Var[j][i].set(pow(2,i*2))
Var[j][i+4].set(pow(2,i+4))
if Var_V[i].get()==0:
for j in range(0,total_cell):
Var[j][i].set(0)
Var[j][i+4].set(0)
def go_H():
k=0
for j in range(0,20):
if j%2==0 : #(even)
if not Var_H[j].get()==0: #(select)
for i in range(0,3):
Var[k][i].set(pow(2,i))
Var[k][3].set(pow(2,6))
elif Var_H[j].get()==0: #(deselect)
for i in range(0,4):
Var[k][i].set(0)
if not j%2==0 :
if not Var_H[j].get()==0:
for i in range(4,7):
Var[k][i].set(pow(2,(i-1)))
Var[k][7].set(pow(2,7))
elif Var_H[j].get()==0: #(tic)
for i in range(4,8):
Var[k][i].set(0)
k+=1
#================================Vertical checkbuttons for row select=========================#
Var_V=['V1']*4
Tag_V=['Tag_V']*4
for i in range(0,len(Var_V)):
Var_V[i] = IntVar()
Tag_V[i] = Checkbutton(f3 , variable = Var_V[i],command=go_V, \
onvalue =1, offvalue = 0, height=1, \
width = 1,bg='lightskyblue4',fg='red')
Tag_V[i].place(x=sp+30,y=30*i+100)
#================================checkbutton for ALL_PIN select=========================#
vm=15 #vertical margin
Var_all=IntVar()
Tag_all =Checkbutton(f3 , variable = Var_all,command=go_all, \
onvalue =1, offvalue = 0, height=1, \
width = 1,bg='lightskyblue3',fg='red')
Tag_all.place(x=sp+30,y=225+vm)
Tag_all_ttp = CreateToolTip(Tag_all , "Select All Pins")
#================================Horizontal checkbuttons for column select=========================#
Var_H=['H']*20
Tag_H=['Tag_H']*20
X=[]
for i in range(0,len(Var_H)):
X.append(100+85*i)
X.append(107+25+85*i)
#print X
for i in range(0,len(Var_H)):
Var_H[i] = IntVar()
Tag_H[i] = Checkbutton(f3 , variable = Var_H[i],command=go_H, \
onvalue =1, offvalue = 0, height=1, \
width = 1,bg='lightskyblue4',fg='red')
Tag_H[i].place(x=sp+X[i],y=225+vm)
#
#def pat():
# a = 0
# print pat_chk.get()
#
#pat_chk =IntVar()
#chk_pat=Checkbutton(f3 , variable = pat_chk,command=pat, \
# onvalue =1, offvalue = 0, height=1, \
# width = 1,bg='lightskyblue4',fg='red')
#chk_pat.place(x=900,y=283)
#
#lblpat= t.Label(f3,font=('arial',10,'bold'),text="Pattern :",relief=t.FLAT,justify='right')
##lblpat.pack(side='left', expand = 1)
def GetDatap():
global Var
datap=[0]*10
for j in range(0,total_cell):
for i in range(0,no_pin):
datap[j]+=Var[j][i].get()
return datap
def GetDatap_cust(data):
data = data%64
if(data % 2 == 0):
datap=[(data/2)+192]*10
else:
datap=[(data/2)]*10
return datap
def GetDatap_cust1(data):
data = data%64
dat = 126
if(data % 2 == 0):
datap=[255]*10
datap[0] = 0
else:
datap=[255]*10
datap[1] = 0
return datap
def reFormat(fb):
global w, h,btn_color,Tag_all,vm
w = root.winfo_screenwidth()
sp=0 #starting_point
if fb==False: ## in clear(deselect func) to clear screen and resize frame widgets
sp=100
#====================================Each cell reposition===============================#
for j in range(0,total_cell):
for i in range (0,no_pin):
Tag[j][i].config(text='',width=1,height=1 )
if i<4:
Tag[j][i].place(x=sp+100+85*j,y=30*i+100)
if i>=4:
Tag[j][i].place(x=sp+125+85*j,y=30*(i-4)+100)
#====================================cell_no label===============================#
for i in range(0,total_cell):
lblcn[i].destroy()
lblcn[i]= t.Label(f2,bg='white',text=str(i+1) ,bd=2,padx=3)
lblcn[i].place(x=sp+125+85*(i),y=0+73)
#====================================Var_H===============================#
X=[]
for i in range(0,len(Var_H)):
X.append(sp+102+85*i)
X.append(sp+102+25+85*i)
#print X
for i in range(0,len(Var_H)):
Tag_H[i].destroy()
Tag_H[i] = Checkbutton(f2 , variable = Var_H[i],command=go_H, \
onvalue =1, offvalue = 0, height=1, \
width = 1,bg='lightskyblue4',fg='red')
Tag_H[i].place(x=X[i],y=225+vm)
#====================================Var_V===============================#
for i in range(0,len(Var_V)):
Tag_V[i].destroy()
Tag_V[i] = Checkbutton(f3 , variable = Var_V[i],command=go_V, \
onvalue =1, offvalue = 0, height=1, \
width = 1,bg='lightskyblue4',fg='red')
Tag_V[i].place(x=sp+30,y=30*i+100)
#====================================Var_all===============================#
Tag_all.destroy()
Tag_all =Checkbutton(f3 , variable = Var_all,command=go_all, \
onvalue =1, offvalue = 0, height=1, \
width = 1,bg='lightskyblue3',fg='red')
Tag_all.place(x=sp+30,y=225+vm)
Tag_all_ttp = CreateToolTip(Tag_all , "Select All Pins")