-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguiElcomandante.py
executable file
·1551 lines (1398 loc) · 75.3 KB
/
guiElcomandante.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/env python
import os, re, sys, shutil, commands
import math, ROOT
from Tkinter import *
import tkFont
sys.path.insert(1,os.path.dirname(os.path.abspath(__file__))+'/../')
from readConfg import elComandante_ini
from readConfg import elComandante_conf
#### Default color, font, and styles
Delay_MAX=8 #sec
COLUMNMAX=9
ISINI=1
ISCONF=2
TITLE2_FONT=('helvetica', 15, 'bold')
SECTION_FONT=('helvetica', 10, 'bold')
OPTION_FONT=('helvetica', 10 )
BUTTON_FONT=('helvetica', 9, 'bold' )
BUTTON2_FONT=('helvetica', 10, 'bold' )
TITLE_COLOR='gray37'
TITLE2_COLOR='gray27'
TITLE3_COLOR='gray27'
TITLE4_COLOR='gray17'
BG_MASTER='gray93'
TRUE_COLOR='OliveDrab1'
FALSE_COLOR='PeachPuff3'
ERROR_COLOR='IndianRed2'
PREVIEW_COLOR='medium sea green'
UNLOCK_COLOR='DarkOrange1'
LOCK_COLOR='goldenrod1'
RELOAD_COLOR='IndianRed2'
SAVE_COLOR='goldenrod1'
QUIT_COLOR='IndianRed2'
MENU_FULL_COLOR='LightSteelBlue1'
MENU_ROC_COLOR='light slate blue'
TYPING_COLOR='khaki1'
ENTRY_COLOR='snow'
ENTRY_LOCKED_COLOR='light grey'
#### Default inputs
DefaultConfigDir='../config'
DefaultInputIni='../config/elComandante.ini'
DefaultInputConf='../config/elComandante.conf'
if not os.path.isdir( DefaultConfigDir ):
DefaultConfigDir='config'
if not os.path.isfile( DefaultInputIni ):
DefaultInputIni='config/elComandante.ini'
if not os.path.isfile( DefaultInputConf ):
DefaultInputConf='config/elComandante.conf'
########## Main class (Very dirty....)
### Many function for creating button, menu or box
### Main interface is with function "createWidgets" from L1091
###
class interface():
#### initial parameters
def __init__(self, master=None):
self.master = master
self.master.title("guiElcomandante")
self.master["bg"]=BG_MASTER
self.master.grid()
self.isfixed=True
self.isfixed=True
self.iniClass = None
self.confClass = None
self.output=None
self.frames={}
self.framesButton={}
self.Labels={}
self.Entries={}
self.OptEntries={}
self.BoolButtons={}
self.testButtons={}
self.lastTestDirEntry={}
self.lastTestDirMenu={}
self.hasError=False
self.Menus={}
self.Vars={}
self.configDir = DefaultConfigDir
self.edited={ 'elComandante.ini':False,
'elComandante.conf':False}
self.testDefinePath=''
self.confingurePath = { 'elComandante.ini' :DefaultInputIni,
'elComandante.conf':DefaultInputConf }
self.confingureOutPut = { 'elComandante.ini' :DefaultInputIni,
'elComandante.conf':DefaultInputConf }
self.whichConfig = {'elComandante.ini' :True,
'elComandante.conf':False }
self.currentPath = self.confingurePath['elComandante.ini']
self.loadElcommandateIni();
self.loadElcommandateConf();
#### Load configure file
def loadElcommandateIni(self):
self.iniClass = elComandante_ini()
self.iniClass.getDefault(self.confingurePath['elComandante.ini'])
self.edited['elComandante.ini']=False
return
def loadElcommandateConf(self):
self.confClass = elComandante_conf()
self.confClass.getDefault(self.confingurePath['elComandante.conf'])
self.edited['elComandante.conf']=False
return
def loadTestsOptions(self):
listDir = commands.getoutput('ls '+self.testDefinePath)
self.tests = listDir.split('\n')
return
### Add empty pad for designing
def addXpad(self, frame, colmax=8, bg=BG_MASTER, width=10, height=1, row=0):
col=0
while ( col < colmax ):
pad = Label(frame, bg=bg, width=width, height=height)
pad.grid(row=row, column=col)
col+=1
return
### Make all frame and tk can be expended with window
def expendWindow(self, frame, maxRow, maxCol):
for x in range(maxCol):
Grid.columnconfigure(frame, x, weight=1)
for y in range(maxRow):
Grid.rowconfigure(frame, y, weight=1)
return
### Change elcommandate.ini and elcommandate.conf
def changeFrame(self, name):
frame = self.frames[name]
frame.tkraise()
for button in self.framesButton:
if button == name:
self.framesButton[button]['bg']=BG_MASTER
self.framesButton[button]['fg']=TITLE4_COLOR
self.whichConfig[button]=True
self.Labels[button].tkraise()
self.entryConfig.delete(0, END)
self.entryConfig.insert(0, self.confingurePath[button])
self.currentPath=self.confingurePath[button]
else:
self.framesButton[button]['bg']=ENTRY_LOCKED_COLOR
self.framesButton[button]['fg']=TITLE_COLOR
self.whichConfig[button]=False
if self.edited[name]:
self.editedlabel["text"]="*Edited..."
else:
self.editedlabel["text"]=""
#if not self.isfixed:
# self.lock()
return
### ReLoad button
def reLoadConfig(self):
if self.isfixed:
print '>> [INFO] The button is locked!'
return
if self.whichConfig['elComandante.ini']:
if os.path.isfile( self.entryConfig.get() ):
self.edited['elComandante.ini']=False
self.editedlabel["text"]=""
self.confingurePath['elComandante.ini'] = self.entryConfig.get()
self.loadElcommandateIni()
# refresh option entries
for name in self.OptEntries:
entry = self.OptEntries[name]
classType = name.split('_')[0]
section = name.split('_')[2]
option = name.split('_')[3]
if classType == 'ini':
entry.delete(0, END)
if option == 'Test' and section == 'Tests':
if not self.checkProcess(self.iniClass.Sections[section][option]):
entry['bg'] = ERROR_COLOR
entry.insert(0, self.iniClass.Sections[section][option])
else:
continue
# refresh add new test entry
self.lastClickNewTest='Ex: IV@10'
self.Entries['ini_Process_Tests_NewTest'].delete(0,END)
self.Entries['ini_Process_Tests_NewTest'].insert(0, 'Ex: IV@10')
# refresh BoolButtons
for name in self.BoolButtons:
button = self.BoolButtons[name]
classType = name.split('_')[0]
section = name.split('_')[2]
option = name.split('_')[3]
if classType == 'ini':
self.fillBoolName(button, section, option, self.iniClass.Sections[section][option])
else:
continue
# refresh menu
for name in self.Menus:
menu = self.Menus[name]
var = self.Vars[name]
section = name.split('_')[2]
option = name.split('_')[3]
if section == 'IV':
self.setDelayVar( menu, var, section, option, self.iniClass.Sections[section][option])
elif section == 'Cycle':
self.setCycleVar( menu, var, section, option, self.iniClass.Sections[section][option])
elif section == 'ModuleType':
self.setTypeVar( menu, var, section, option, self.iniClass.Sections[section][option])
self.currentPath = self.confingurePath['elComandante.ini']
else:
print ">> [ERROR] Can't find '%s'"% self.entryConfig.get()
return
elif self.whichConfig['elComandante.conf']:
if os.path.isfile( self.entryConfig.get() ):
self.confingurePath['elComandante.conf'] = self.entryConfig.get()
self.loadElcommandateConf()
self.edited['elComandante.conf']=False
self.editedlabel["text"]=""
# refresh option entries
for name in self.OptEntries:
entry = self.OptEntries[name]
classType = name.split('_')[0]
section = name.split('_')[2]
option = name.split('_')[3]
if classType == 'conf':
entry.delete(0, END)
entry.insert(0, self.confClass.Sections[section][option])
else:
continue
# refresh BoolButtons
for name in self.BoolButtons:
button = self.BoolButtons[name]
classType = name.split('_')[0]
section = name.split('_')[2]
option = name.split('_')[3]
if classType == 'conf':
self.fillBoolName(button, section, option, self.confClass.Sections[section][option])
else:
continue
# refresh dir menu and entry
for name in self.Menus:
menu = self.Menus[name]
var = self.Vars[name]
section = name.split('_')[2]
option = name.split('_')[3]
if section == 'Directories':
#self.setDirVar( menu, var, name, self.confClass.Sections[section][option])
self.setDirVar( var, name, self.confClass.Sections[section][option])
# check test dir in ini's testButtons
for tests in ['Fulltest@17','Pretest@17', 'Fulltest@-20', 'Pretest@-20']:
name = 'ini_Process_Tests_'+tests
button = self.testButtons[name]
button['command']=''
button.unbind('<Button-1>')
button.unbind('<Leave>')
if self.checkTests(button, tests):
button['bg']=FALSE_COLOR
button['text']=tests
button['command']=lambda button=button:self.activeTestButton(button)
button.bind('<Button-1>', lambda event:self.changeColorTestEntry(0))
button.bind('<Leave>', lambda event:self.changeColorTestEntry(1))
self.currentPath = self.confingurePath['elComandante.conf']
else:
print ">> [ERROR] Can't find '%s'"% self.entryConfig.get()
return
self.lock()
self.isfixed=True
### Lock button
def lock(self):
# UnLocked
if self.buttonLock['text'] == 'Unlock':
self.isfixed=False
self.buttonLock['text']='Lock'
self.buttonLock['bg']=LOCK_COLOR
self.locklabel['fg']=BG_MASTER
self.entryConfig['bg']=ENTRY_COLOR
for entry in self.Entries:
self.Entries[entry]['bg']=ENTRY_COLOR
if self.hasError:
self.Entries['ini_Process_Tests_Test']['bg']=ERROR_COLOR
# Locked
else:
self.isfixed=True
self.buttonLock['text']='Unlock'
self.buttonLock['bg']=UNLOCK_COLOR
self.locklabel['fg']='red'
self.entryConfig['bg']=ENTRY_LOCKED_COLOR
for entry in self.Entries:
self.Entries[entry]['bg']=ENTRY_LOCKED_COLOR
if self.hasError:
self.Entries['ini_Process_Tests_Test']['bg']=ERROR_COLOR
if int(self.lastClickNewCycle) <= 10:
self.Labels['ini_Process_Cycle_HideOther'].tkraise()
self.Vars['ini_Process_Cycle_nCycles'].set(self.lastClickNewCycle)
self.Menus['ini_Process_Cycle_nCycles']['bg']=MENU_FULL_COLOR
self.unTouchDir('conf_Directories_Directories_testDefinitions')
self.unTouchDir('conf_Directories_Directories_dataDir')
### Quit button
def addQUIT(self, frame, row=0, column=0, text="QUIT", bg=QUIT_COLOR, font=BUTTON2_FONT, columnspan=1, sticky='se', width=5):
self.QUIT = Button(frame, font=font, bg=bg, width=width, text=text, command=self.quit, fg=TITLE4_COLOR)
self.QUIT.grid(row=row, column=column, columnspan=columnspan, sticky=sticky)
return
def quit(self):
print '>> [INFO] Ciao~ :-D'
self.master.quit()
return
### Preview button
def addPreview(self, frame, row=0, column=0, text="Preview", bg=PREVIEW_COLOR, font=BUTTON2_FONT,columnspan=1, sticky='se', width=5):
self.PREVIEW = Button(frame, font=font, bg=bg, text=text, width=width, command=self.printConfig, fg=TITLE4_COLOR)
self.PREVIEW.grid(row=row, column=column, columnspan=columnspan, sticky=sticky)
return
def printConfig(self):
if self.whichConfig['elComandante.ini']:
self.iniClass.callConfig()
if self.whichConfig['elComandante.conf']:
self.confClass.callConfig()
return
### Save button
def addSave(self, frame, row=0, column=0, text="Save", bg=SAVE_COLOR, font=BUTTON2_FONT, columnspan=1, sticky='se', width=5):
self.SAVE = Button(frame, font=font, bg=bg, text=text, width=width, fg=TITLE4_COLOR, command= lambda:self.saveConfig() )
self.SAVE.grid(row=row, column=column, columnspan=columnspan, sticky=sticky)
def saveConfig(self):
if self.whichConfig['elComandante.ini']:
self.iniClass.makeConfig(self.confingureOutPut['elComandante.ini'])
self.edited['elComandante.ini']=False
self.editedlabel["text"]=""
if self.whichConfig['elComandante.conf']:
self.confClass.makeConfig(self.confingureOutPut['elComandante.conf'])
self.edited['elComandante.conf']=False
self.editedlabel["text"]=""
return
### Add commend label
def addLabel(self, frame, label="", name0="", name1="", row=0, column=0, sticky='nsew', columnspan=1, rowspan=1, bg=BG_MASTER, font=OPTION_FONT, fg=TITLE3_COLOR):
newLabel = Label(frame, bg=bg, font=font, fg=fg)
newLabel["text"] = name1
newLabel.grid( row=row, column=column, sticky=sticky, columnspan=columnspan, rowspan=rowspan )
term1=""
term2=""
if label!="" :
term1=label+"_"
if name0!="" :
term2=name0+"_"
self.Labels[term1+term2+name1]=newLabel
return
### Add commend entry
def addEntry(self, frame, label="", name0="", name1="", value="" , row=0, column=0, width=10, sticky='nsew', columnspan=1, rowspan=1, fg='black' ):
term1=""
term2=""
if label!="" :
term1=label+"_"
if name0!="" :
term2=name0+"_"
name=term1+term2+name1
newEntry = Entry(frame)
newEntry['width'] = width
newEntry['fg'] = fg
if self.isfixed:
newEntry['bg']=ENTRY_LOCKED_COLOR
else:
newEntry['bg']=ENTRY_COLOR
if name1 == 'Test' and name0 == 'Tests':
if not self.checkProcess(value):
newEntry['bg'] = ERROR_COLOR
newEntry.insert(0, value)
newEntry.grid( row=row, column=column, sticky=sticky, columnspan=columnspan, rowspan=rowspan)
self.Entries[name]=newEntry
return name
### Add entry for options from configure file
def addOptEntry(self, frame, label="", name0="", name1="", value="" , row=0, column=0, width=10, sticky='nsew', columnspan=1, rowspan=1, isFixed=False, classType=ISINI ):
name = self.addEntry(frame, label, name0, name1, value, row, column, width, sticky, columnspan, rowspan=rowspan)
newEntry = self.Entries[name]
if classType == ISINI:
if isFixed:
newEntry.bind('<Key>', lambda event:self.unTouchEntry(newEntry, self.iniClass.Sections[name0][name1], True))
newEntry.bind('<Leave>', lambda event:self.unTouchEntry(newEntry, self.iniClass.Sections[name0][name1]))
newEntry.bind('<Return>', lambda event:self.unTouchEntry(newEntry, self.iniClass.Sections[name0][name1], True))
newEntry.bind('<FocusOut>', lambda event:self.unTouchEntry(newEntry, self.iniClass.Sections[name0][name1]))
else:
newEntry.bind('<Key>', lambda event:self.changeEntryBG(newEntry,self.iniClass.Sections[name0][name1] ))
newEntry.bind('<Leave>', lambda event:self.checkChanging(newEntry, self.iniClass.Sections[name0][name1], name ))
newEntry.bind('<Return>', lambda event:self.ConfirmChangeOpt(newEntry, name0, name1 ))
newEntry.bind('<FocusOut>', lambda event:self.checkChanging(newEntry, self.iniClass.Sections[name0][name1],name ))
if classType == ISCONF:
if isFixed:
newEntry.bind('<Key>', lambda event:self.unTouchEntry(newEntry, self.confClass.Sections[name0][name1], True))
newEntry.bind('<Leave>', lambda event:self.unTouchEntry(newEntry, self.confClass.Sections[name0][name1]))
newEntry.bind('<Return>', lambda event:self.unTouchEntry(newEntry, self.confClass.Sections[name0][name1], True))
newEntry.bind('<FocusOut>', lambda event:self.unTouchEntry(newEntry, self.confClass.Sections[name0][name1]))
else:
newEntry.bind('<Key>', lambda event:self.changeEntryBG(newEntry,self.confClass.Sections[name0][name1] ))
newEntry.bind('<Leave>', lambda event:self.checkChanging(newEntry, self.confClass.Sections[name0][name1],name ))
newEntry.bind('<Return>', lambda event:self.ConfirmChangeOpt(newEntry, name0, name1, ISCONF ))
newEntry.bind('<FocusOut>', lambda event:self.checkChanging(newEntry, self.confClass.Sections[name0][name1],name ))
self.Entries[name]=newEntry
self.OptEntries[name]=newEntry
return
def changeEntryBG(self, entry, value, murmur=True):
if self.isfixed:
self.unTouchEntry(entry, value, murmur)
return
entry['bg']=TYPING_COLOR
if self.whichConfig['elComandante.ini']:
self.edited['elComandante.ini']=True
self.editedlabel["text"]="*Edited..."
if self.whichConfig['elComandante.conf']:
self.edited['elComandante.conf']=True
self.editedlabel["text"]="*Edited..."
return
def checkChanging(self, entry, value, name='', murmur=False ):
if self.isfixed:
self.unTouchEntry(entry, value, murmur)
return
if name == 'ini_Process_Tests_Test':
if self.hasError:
return
if value == entry.get():
entry['bg']=ENTRY_COLOR
return
def ConfirmChangeOpt(self, entry, section, option, classType=ISINI, murmur=True):
if classType == ISINI:
value = self.iniClass.Sections[section][option]
if classType == ISCONF:
value = self.confClass.Sections[section][option]
if self.isfixed:
self.unTouchEntry(entry, value, murmur)
return
newvalue = entry.get().strip()
if value != newvalue and newvalue !='':
print ">> [INFO] Change %s : %s : %s -> %s "%(section, option, value, newvalue)
if classType == ISINI:
self.iniClass.changeOptValue(section,option, newvalue)
if classType == ISCONF:
self.confClass.changeOptValue(section,option, newvalue)
entry['bg']=ENTRY_COLOR
return
def unTouchEntry(self, entry, value, murmur=False ):
if murmur:
print '>> [INFO] The entry is locked!'
entry.delete(0, END)
entry.insert(0, value)
return
def checkProcess(self, process):
newProcess = ''
size = len(process.split(','))
i=1
error=False
for tests in process.split(','):
test = tests.split('@')[0]
if test not in self.tests and test != 'IV' and test != 'Cycle':
print ">> [ERROR] Can't find '"+test+"' in '"+self.testDefinePath+"'"
print ">> Please check the test name"
error=True
if not error:
self.hasError=False
return True
else:
self.hasError=True
return False
### Add button for bool options from configure file
def addBoolButton(self, frame, label="", name0="", name1="", row=0, column=0, columnspan=1, value='', sticky='wn', width=5, classType=ISINI):
term1=""
term2=""
if label!="" :
term1=label+"_"
if name0!="" :
term2=name0+"_"
name=term1+term2+name1
newButton = Button(frame)
newButton['width'] =width
newButton['fg']=TITLE4_COLOR
newButton['font']=BUTTON_FONT
newButton['command']=lambda:self.changeBool( name, name0, name1, classType )
self.fillBoolName(newButton, name0, name1, value)
newButton.grid( row=row, column=column, sticky=sticky, columnspan=columnspan)
self.BoolButtons[name]=newButton
def fillBoolName(self, button, section, option, value):
button['text']="OFF"
button['bg']=FALSE_COLOR
if value.lower() != "true" and value.lower() != "false":
print ">> [ERROR] "+section+" '"+option+"' has wrong value '"+value+"'"
print ">> Please click the button to fix it"
button['text']='ERROR'
button['bg']=ERROR_COLOR
elif value == "True":
button['text']="ON"
button['bg']=TRUE_COLOR
return
def changeBool(self, name, section, option, classType=ISINI):
if self.isfixed:
print '>> [INFO] The button is locked!'
return
self.edited['elComandante.ini']=True
self.editedlabel["text"]="*Edited..."
if self.BoolButtons[name]['text'] == "OFF":
print ">> [INFO] Change %s : %s : False -> True "%(section, option)
self.BoolButtons[name]['text']="ON"
self.BoolButtons[name]['bg']=TRUE_COLOR
if classType == ISINI:
self.iniClass.changeOptValue(section,option,"True")
if classType == ISCONF:
self.confClass.changeOptValue(section,option,"True")
else:
print ">> [INFO] Change %s : %s : %s -> False "%(section, option, self.BoolButtons[name]['text'] )
self.BoolButtons[name]['text']="OFF"
self.BoolButtons[name]['bg']=FALSE_COLOR
if classType == ISINI:
self.iniClass.changeOptValue(section,option,"False")
if classType == ISCONF:
self.confClass.changeOptValue(section,option,"False")
return
### Add button for Tests options from configure file
def addTestButton(self, frame, label="", name0="", name1="", row=0, column=0, sticky='n', width=10, rowspan=1, columnspan=1):
term1=""
term2=""
if label!="" :
term1=label+"_"
if name0!="" :
term2=name0+"_"
name=term1+term2+name1
newButton = Button(frame)
newButton['width'] =width
newButton['text']=name1
newButton['bg']=FALSE_COLOR
newButton['fg']=TITLE4_COLOR
newButton['font']=BUTTON_FONT
newButton.grid( row=row, column=column, sticky=sticky, rowspan=rowspan, columnspan=columnspan)
if self.checkTests(newButton, name1):
newButton['command']=lambda:self.activeTestButton(newButton)
newButton.bind('<Button-1>', lambda event:self.changeColorTestEntry(0))
newButton.bind('<Leave>', lambda event:self.changeColorTestEntry(1))
self.testButtons[name]=newButton
return
def checkTests(self, button, tests):
test = tests.split('@')[0]
testfile = self.testDefinePath+'/'+test
if test=='IV' or test== 'Cycle' or test=='Add new test' or test=='Delete' or test=='Clear':
return True
elif not os.path.isfile(testfile):
print ">> [ERROR] Can't find '"+test+"' in '"+self.testDefinePath+"', or it's not a file..."
button['text']=test+'??'
button['bg']=ERROR_COLOR
return False
else:
return True
def activeTestButton(self, button):
if self.isfixed:
print '>> [INFO] The button is locked!'
return
self.edited['elComandante.ini']=True
self.editedlabel["text"]="*Edited..."
if button['text'] == 'Clear':
self.Entries['ini_Process_Tests_Test'].delete(0,END)
self.iniClass.changeOptValue('Tests','Test', '')
print ">> [INFO] Clear Tests! "
print ">> Changed Tests : "
self.hasError=False
return
tests = self.Entries['ini_Process_Tests_Test'].get()
if button['text'] == 'Delete':
restTests = ''
if tests != '':
lTests = tests.split(',')
nTests = len(lTests)-1
delTest = lTests[nTests]
i = 0
while ( i < nTests ):
if i == nTests-1:
restTests += lTests[i]
else:
restTests += lTests[i]+','
i+=1
else:
return
self.Entries['ini_Process_Tests_Test'].delete(0,END)
self.Entries['ini_Process_Tests_Test'].insert(0, restTests)
self.iniClass.changeOptValue('Tests','Test', restTests)
print ">> [INFO] Delete a test '%s'"%(delTest)
print ">> Changed Tests %s: "%(restTests)
if not self.checkProcess(restTests):
self.Entries['ini_Process_Tests_Test']['bg'] = ERROR_COLOR
return
newprocess=''
if button['text'] == 'Add new test':
self.lastClickNewTest = self.Entries['ini_Process_Tests_NewTest'].get()
if self.lastClickNewTest == '':
return
i=1
newalltests = self.lastClickNewTest.split(',')
for newTests in newalltests:
newtests = newTests.strip().split('@') #remove backspace in front/end first
newtest = newtests[0]
if len(newtests) > 2:
self.Entries['ini_Process_Tests_NewTest']['bg']=ERROR_COLOR
print '>> [ERROR] Too many arguments'
print '>> E.x: Fulltest@17,IV@10'
self.lastClickNewTest=''
if not self.checkProcess(tests):
self.Entries['ini_Process_Tests_Test']['bg'] = ERROR_COLOR
return
elif len(newtests) == 2:
isBad = False
try:
istemperature = newtests[1].split('-')
temperature = newtests[1].split('-')[1]
if len(istemperature) > 2 or istemperature[0] != '':
isBad=True
except:
temperature = newtests[1]
if not temperature.isdigit() or isBad:
self.Entries['ini_Process_Tests_NewTest']['bg']=ERROR_COLOR
print '>> [ERROR] After @ shall be digit, i.e temperature'
print '>> E.x: Fulltest@17'
self.lastClickNewTest=''
if not self.checkProcess(tests):
self.Entries['ini_Process_Tests_Test']['bg'] = ERROR_COLOR
return
if newtest in self.tests or newtest == 'IV' or newtest == 'Cycle':
if newtest == 'Cycle' and len(newtests)!=1:
self.Entries['ini_Process_Tests_NewTest']['bg']=ERROR_COLOR
print ">> [ERROR] Cycle shall not add @ and temperature"
self.lastClickNewTest=''
if not self.checkProcess(tests):
self.Entries['ini_Process_Tests_Test']['bg'] = ERROR_COLOR
return
if len(newalltests) > 1 and i<len(newalltests):
newprocess += newTests.strip()+','
else:
newprocess += newTests.strip()
i+=1
self.Entries['ini_Process_Tests_NewTest']['bg']=ENTRY_COLOR
else:
self.Entries['ini_Process_Tests_NewTest']['bg']=ERROR_COLOR
print ">> [ERROR] Not found '"+newtest+"' in "+self.testDefinePath
print ">> Please add it in '"+self.testDefinePath+"' and reload"
self.lastClickNewTest=''
if not self.checkProcess(tests):
self.Entries['ini_Process_Tests_Test']['bg'] = ERROR_COLOR
return
else:
newprocess = button['text']
if tests == '':
tests=newprocess
else:
tests+=','+newprocess
self.Entries['ini_Process_Tests_Test'].delete(0,END)
self.Entries['ini_Process_Tests_Test'].insert(0, tests)
self.iniClass.changeOptValue('Tests','Test', tests)
print ">> [INFO] Add new process %s "%(newprocess)
print ">> Changed Tests : %s "%(tests)
if not self.checkProcess(tests):
self.Entries['ini_Process_Tests_Test']['bg'] = ERROR_COLOR
return
def changeColorTestEntry(self, action):
if self.isfixed:
return
if action == 0: #<Button-1>
self.Entries['ini_Process_Tests_Test']['bg']=TYPING_COLOR
elif action == 1: #<Leave>
if not self.hasError:
self.Entries['ini_Process_Tests_Test']['bg']=ENTRY_COLOR
else:
return
### Add Menu for delay measument IV from configure file
def addDelayMenu(self, frame, label="", name0="", name1="", row=0, column=0, value='', nmax=Delay_MAX, sticky='wn', width=10):
term1=""
term2=""
if label!="" :
term1=label+"_"
if name0!="" :
term2=name0+"_"
name=term1+term2+name1
var=StringVar()
newMenu = OptionMenu( frame, var, () )
newMenu['width'] = width
newMenu['menu'].delete(0)
sec=1.
while ( sec <= nmax ):
newMenu['menu'].add_command(label=str(int(sec))+' Sec.',command=lambda sec=sec:self.chooseDelay( newMenu, sec, name0, name1, var))
sec+=1
newMenu.grid( row=row, column=column, sticky=sticky)
self.setDelayVar(newMenu, var, name0, name1, value)
self.Menus[name]=newMenu
self.Vars[name]=var
def setDelayVar(self, menu, var, section, option, value):
menu['bg'] = ERROR_COLOR
menu['fg']=TITLE4_COLOR
menu['font']=BUTTON_FONT
try:
fvalue = float(value)
menu['bg'] = MENU_FULL_COLOR
var.set(str(int(fvalue*2))+' Sec.')
except:
print ">> [ERROR] "+section+" '"+option+"' has wrong value '"+value+"'"
print ">> Please select the number to fix it"
var.set("ERROR")
def chooseDelay(self, menu, sec, section, option, var):
if self.isfixed:
print '>> [INFO] The menu is locked!'
return
value = self.iniClass.Sections[section][option]
if float(value)*2 != sec:
self.edited['elComandante.ini']=True
self.editedlabel["text"]="*Edited..."
print ">> [INFO] Change %s : %s : %s(%2.0f sec) -> %s(%2.0f sec) "%(section, option, value, float(value)*2, str(sec/2), sec)
menu['bg'] = MENU_FULL_COLOR
var.set(str(int(sec))+' Sec.')
self.iniClass.changeOptValue(section,option, str(sec/2))
return
### Add Menu for times of thermal cycle from configure file
def addnCycleMenu(self, frame, label="", name0="", name1="", row=0, column=0, value='', nmax=10, sticky='wn', width=10):
term1=""
term2=""
if label!="" :
term1=label+"_"
if name0!="" :
term2=name0+"_"
name=term1+term2+name1
var=StringVar()
newMenu = OptionMenu( frame, var, () )
newMenu['width'] = width
newMenu['menu'].delete(0)
ilabel=1
while ( ilabel <= nmax ):
newMenu['menu'].add_command(label=str(ilabel),command=lambda ilabel=ilabel:self.chooseCycle(newMenu,str(ilabel),name0,name1,var))
ilabel+=1
newMenu['menu'].add_command(label='Other', command=lambda ilabel=ilabel:self.chooseCycle(newMenu,'Other',name0,name1,var))
newMenu.grid( row=row, column=column, sticky=sticky)
self.setCycleVar(newMenu, var, name0, name1, value)
self.Menus[name]=newMenu
self.Vars[name]=var
def setCycleVar(self, menu, var, section, option, value):
menu['bg'] = ERROR_COLOR
menu['fg']=TITLE4_COLOR
menu['font']=BUTTON_FONT
if not value.isdigit():
print ">> [ERROR] "+section+" '"+option+"' has wrong value '"+value+"'"
print ">> Please select the number to fix it"
self.lastClickNewCycle=''
var.set("ERROR")
elif int(value)>10:
menu['bg'] = FALSE_COLOR
self.Entries['ini_Process_Cycle_Other'].delete(0, END)
self.Entries['ini_Process_Cycle_Other'].insert(0, str(int(value)))
self.Entries['ini_Process_Cycle_Other'].tkraise()
self.lastClickNewCycle=str(int(value))
var.set('Other')
else:
self.Labels['ini_Process_Cycle_HideOther'].tkraise()
self.Entries['ini_Process_Cycle_Other'].delete(0, END)
self.lastClickNewCycle=str(int(value))
menu['bg'] = MENU_FULL_COLOR
var.set(str(int(value)))
return
def chooseCycle(self, menu, label, section, option, var):
if self.isfixed:
print '>> [INFO] The menu is locked!'
return
value = self.iniClass.Sections[section][option]
if value != label:
self.edited['elComandante.ini']=True
self.editedlabel["text"]="*Edited..."
var.set(label)
if label == 'Other':
menu['bg'] = FALSE_COLOR
self.Entries['ini_Process_Cycle_Other'].tkraise()
else:
print ">> [INFO] Change %s : %s : %s -> %s "%(section, option, value, label)
menu['bg'] = MENU_FULL_COLOR
self.iniClass.changeOptValue(section,option,label)
self.Entries['ini_Process_Cycle_Other'].delete(0, END)
self.Entries['ini_Process_Cycle_Other'].insert(0, '')
self.Labels['ini_Process_Cycle_HideOther'].tkraise()
self.lastClickNewCycle=label
return
def chooseOtherCycle(self, entry):
newvalue = entry.get().strip()
value = self.iniClass.Sections['Cycle']['nCycles']
if value != newvalue and newvalue != '':
if not newvalue.isdigit():
print '>> [ERROR] Shall be a digit number, i.e times'
return
self.lastClickNewCycle=newvalue
if int(newvalue) <= 10:
self.Labels['ini_Process_Cycle_HideOther'].tkraise()
self.Entries['ini_Process_Cycle_Other'].delete(0, END)
self.Entries['ini_Process_Cycle_Other']['bg']=ENTRY_COLOR
self.Vars['ini_Process_Cycle_nCycles'].set(self.lastClickNewCycle)
self.Menus['ini_Process_Cycle_nCycles']['bg']=MENU_FULL_COLOR
print ">> [INFO] Change Cycle : nCycles : %s -> %s "%( value, newvalue)
self.iniClass.changeOptValue('Cycle', 'nCycles', newvalue)
entry['bg']=ENTRY_COLOR
return
def checkEmpty(self, entry):
if entry.get() == '' or int(entry.get()) <= 10:
self.Labels['ini_Process_Cycle_HideOther'].tkraise()
self.Entries['ini_Process_Cycle_Other'].delete(0, END)
self.Entries['ini_Process_Cycle_Other']['bg']=ENTRY_COLOR
self.Vars['ini_Process_Cycle_nCycles'].set(self.lastClickNewCycle)
self.Menus['ini_Process_Cycle_nCycles']['bg']=MENU_FULL_COLOR
return
### Add Menu for muduel tyes from configure file
def addMuduelTypeMenu(self, frame, label="", name0="", name1="", row=0, column=0, columnspan=1, value='', sticky='wn', width=10):
term1=""
term2=""
if label!="" :
term1=label+"_"
if name0!="" :
term2=name0+"_"
name=term1+term2+name1
var=StringVar()
newMenu = OptionMenu( frame, var, () )
newMenu['width'] = width
newMenu['menu'].delete(0)
newMenu['menu'].add_command( label="Full", command=lambda:self.chooseType( newMenu, 'Full', name0, name1, var))
newMenu['menu'].add_command( label="Roc", command=lambda:self.chooseType( newMenu, 'Roc', name0, name1, var,))
newMenu.grid( row=row, column=column, sticky=sticky, columnspan=columnspan)
self.setTypeVar( newMenu, var, name0, name1, value)
self.Menus[name]=newMenu
self.Vars[name]=var
def setTypeVar(self, menu, var, section, option, value):
menu['bg'] = ERROR_COLOR
menu['fg']=TITLE4_COLOR
menu['font']=BUTTON_FONT
if value.lower() != "full" and value.lower() != "roc":
print ">> [ERROR] "+section+" '"+option+"' has wrong value '"+value+"'"
print ">> Please select the type to fix it"
var.set("ERROR")
elif value=="Full":
menu['bg'] = MENU_FULL_COLOR
var.set(value)
elif value=="Roc":
menu['bg'] = MENU_ROC_COLOR
var.set(value)
return
def chooseType(self, menu, label, section, option, var):
if self.isfixed:
print '>> [INFO] The menu is locked!'
return
value = self.iniClass.Sections[section][option]
if value != label:
self.edited['elComandante.ini']=True
self.editedlabel["text"]="*Edited..."
print ">> [INFO] Change %s : %s : %s -> %s "%(section, option, value, label)
if label == 'Full':
menu['bg'] = MENU_FULL_COLOR
if label == 'Roc':
menu['bg'] = MENU_ROC_COLOR
var.set(label)
self.iniClass.changeOptValue(section,option,label)
return
### Add Menu for testDefinetions from configure file
def addTestDirMenu(self, frame, label="", name0="", name1="", row=0, column=0, columnspan=1, value='', sticky='wn', width=5):
term1=""
term2=""
if label!="" :
term1=label+"_"
if name0!="" :
term2=name0+"_"
name=term1+term2+name1
var=StringVar()
newMenu = OptionMenu( frame, var, () )
self.Menus[name]=newMenu
self.Vars[name]=var
newMenu['width'] = width
newMenu['menu'].delete(0)
if name1 == 'testDefinitions':
newMenu['menu'].add_command( label="$configDir", command=lambda:self.chooseTestDir( newMenu, '$configDir', name, name0, name1, var))
newMenu['menu'].add_command( label="Other", command=lambda:self.chooseTestDir( newMenu, 'Other', name, name0, name1, var,))
if name1 == 'dataDir':
newMenu['menu'].add_command( label="$baseDir", command=lambda:self.chooseTestDir( newMenu, '$baseDir', name, name0, name1, var))
newMenu['menu'].add_command( label="Other", command=lambda:self.chooseTestDir( newMenu, 'Other', name, name0, name1, var,))
newMenu.grid( row=row, column=column, sticky=sticky, columnspan=columnspan)
self.setDirVar( var, name, value)
def setDirVar(self, var, name, value):
menu = self.Menus[name]
menu['bg'] = ERROR_COLOR
menu['fg']=TITLE4_COLOR
menu['font']=BUTTON_FONT
terms = value.strip().split('/')
option = name.split('_')[3]
if terms[0]=='$configDir$':
menu['bg'] = MENU_FULL_COLOR
var.set('$configDir')
entry=''
for term in terms:
if term != '$configDir$':
entry+='/'+term
self.Entries[name].delete(0, END)
self.Entries[name].insert(0, entry)
self.lastTestDirEntry[name]=entry
self.lastTestDirMenu[name]='$configDir'
self.testDefinePath = self.configDir+entry
self.loadTestsOptions()
elif terms[0]=='<!Directories|baseDir!>':
menu['bg'] = MENU_FULL_COLOR
var.set('$baseDir')
entry=''
for term in terms:
if term != '<!Directories|baseDir!>':
entry+='/'+term
self.Entries[name].delete(0, END)
self.Entries[name].insert(0, entry)
self.lastTestDirEntry[name]=entry
self.lastTestDirMenu[name]='$baseDir'
else:
menu['bg'] = FALSE_COLOR
var.set('Other')
self.Entries[name].delete(0, END)
self.Entries[name].insert(0, value)
self.lastTestDirEntry[name]=value
self.lastTestDirMenu[name]='Other'
if option == 'testDefinitions':
self.testDefinePath = value
self.loadTestsOptions()
return
def chooseTestDir(self, menu, label, name, section, option, var):
if self.isfixed:
print '>> [INFO] The menu is locked!'
return
self.edited['elComandante.conf']=True
self.editedlabel["text"]="*Edited..."
self.Entries[name]['bg']=TYPING_COLOR
menu['bg'] = TYPING_COLOR
var.set(label)
return
def unTouchDir(self, name, murmur=False ):
if murmur:
print '>> [INFO] The all dir is locked!'
menu = self.Menus[name]
var = self.Vars[name]
var.set(self.lastTestDirMenu[name])
if var.get() == 'Other':