/
MeshWare_console.py
1298 lines (1072 loc) · 52.3 KB
/
MeshWare_console.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
##-----------------------------------------------------------------##
## _ __ __ ##
## /\/\ ___ ___| |__/ / /\ \ \__ _ _ __ ___ ##
## / \ / _ \/ __| '_ \ \/ \/ / _` | '__/ _ \ ##
## / /\/\ \ __/\__ \ | | \ /\ / (_| | | | __/ ##
## \/ \/\___||___/_| |_|\/ \/ \__,_|_| \___| ##
## ___ _ ##
## / __\___ _ __ ___ ___ | | ___ ##
## / / / _ \| '_ \/ __|/ _ \| |/ _ \ ##
## / /__| (_) | | | \__ \ (_) | | __/ ##
## \____/\___/|_| |_|___/\___/|_|\___| ##
## ##
## #------------------ MeshWare Console ------------------# ##
## # Concept & Design : Zachary J.J. Roper # ##
## # Coding Commenced : 2016-02-10 # ##
## # Coding Completed : xxxx-xx-xx # ##
## #-----------------------------------------------# ##
##-----------------------------------------------------------------##
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import tkinter.font
import os
import webbrowser
import ast
import datetime
import uuid
import collections
import calendar
path = ('/Users/zroper/Desktop/GitHub/MeshWare')
os.chdir(path)
def get_calendar(locale, fwday):
# instantiate proper calendar class
if locale is None:
return calendar.TextCalendar(fwday)
else:
return calendar.LocaleTextCalendar(fwday, locale)
class Load_Dict:
def __init__(self):
verbsraw = open('action_verbs.txt','r')
verbsraw.readlines()
verbs = [verb.strip().lower() for verb in verbsraw]
verbsraw.close()
global verb_dict
verb_dict = dict.fromkeys(verbs)
verb_dict = {}
global test_verb_dict
test_verb_dict = {}
## test_verb_dict = {'invest':{'TSLA',
## 'BTC',
## },
## 'run':{'Tues',
## '5 miles'
## },
## 'write':{'abstract': {'length':'300 words',
## 'dedline':'Wed'
## },
## 'manuscript':{'methods',
## 'intro',
## 'results',
## 'discussion'
## }
## },
## 'code':{'experiment',
## 'button factory'
## },
## 'eat':{'buy': {'eggs',
## 'milk'
## },
## 'cook':{'ziti',
## 'steaks'
## }
## },
## 'play':{'ukulele',
## 'heros',
## }
## }
def Load_Button_Values(input_dict):
button_syles_list = ('grey', 'gold', 'red', 'green')
style_grey = ttk.Style()
style_grey.theme_use("default")
style_grey.configure("grey.TButton",
foreground="white",
background="grey")
style_gold = ttk.Style()
style_gold.theme_use("default")
style_gold.configure("gold.TButton",
foreground="black",
background="yellow")
style_red = ttk.Style()
style_red.theme_use("default")
style_red.configure("red.TButton",
foreground="black",
background="red")
style_green = ttk.Style()
style_green.theme_use("default")
style_green.configure("green.TButton",
foreground="black",
background="green2")
style_orange = ttk.Style()
style_orange.theme_use("default")
style_orange.configure("orange.TButton",
foreground="black",
background="orange")
style_purple = ttk.Style()
style_purple.theme_use("default")
style_purple.configure("purple.TButton",
foreground="white",
background="purple")
style_blue = ttk.Style()
style_blue.theme_use("default")
style_blue.configure("blue.TButton",
foreground="white",
background="blue")
style_pink = ttk.Style()
style_pink.theme_use("default")
style_pink.configure("pink.TButton",
foreground="black",
background="DeepPink2")
rowloc = -1
global subtaskbuttonsgrid
subtaskbuttonsgrid = {}
global taskbuttonspack
taskbuttonspack = {}
global subtaskentrygrid
subtaskentrygrid = {}
task_list = list(input_dict.keys())
global somethingnew
somethingnew = {}
global gridbuttonsiter
gridbuttonsiter = {}
for x in sorted(task_list):
taskbuttonspack['{0}'.format(x)]={'fill': BOTH,
'padx': 5,
'pady': 1}
subtask_dict = sorted(input_dict[x])
gridbuttonsiter['{0}'.format(x)] = subtask_dict
rowloc += 1
columnloc = 0
for z in subtask_dict:
subtaskbuttonsgrid['{0}'.format(z)]={'sticky': W+E+N+S,
'row': rowloc,
'column': columnloc,
'padx': 5,
'pady': 1,}
subtaskentrygrid['{0}'.format(z)]={'sticky': W+E+N+S,
'row': rowloc,
'column': columnloc,
'padx': 5,
'pady': 4}
somethingnew['{0}'.format(x)] = ('{0}'.format(z))
columnloc += 1
class Build_Dicts:
def __init__(self, master):
pass
## self.default_value_elements = ['parent name','children names','genesis date',
## 'hard deadline','soft deadline',
## 'completion date','weblink',
## 'filelink','parent defcon',
## 'self defcon','children defcon',
## 'self name','self id']
## self.write_value_elements = ['word length','text snippet','estimated duration']
## self.buy_value_elements = ['price','shipping','frequency']
def main_dict(input_key = ''):
test_verb_dict[input_key] = {}
def sub_dict(input_key = '', input_value = ''):
default_value_elements = ('parent name','children names','genesis date',
'hard deadline','soft deadline',
'completion date','weblink',
'filelink','parent defcon',
'self defcon','children defcon',
'self name','self id')
write_value_elements = ('word length','text snippet','estimated duration')
buy_value_elements = ('price','shipping','frequency')
if input_key == 'write':
sub_dict_builder_list = default_value_elements + write_value_elements
sub_dict_builder_dict = dict.fromkeys(sub_dict_builder_list)
elif input_key == 'buy':
sub_dict_builder_list = default_value_elements + buy_value_elements
sub_dict_builder_dict = dict.fromkeys(sub_dict_builder_list)
else:
sub_dict_builder_dict = dict.fromkeys(default_value_elements)
i = 0
for key in sub_dict_builder_dict.keys():
## sub_dict_builder_dict[key] = {('<no value>'): {}}
i = i + 1
sub_dict_builder_dict[key] = {('empty_%d' % i): {}}
test_verb_dict[input_key][input_value] = sub_dict_builder_dict
test_verb_dict[input_key][input_value]['genesis date'] = {str(datetime.datetime.now()): {}}
test_verb_dict[input_key][input_value]['parent'] = {input_key:{}}
test_verb_dict[input_key][input_value]['self id'] = {str(uuid.uuid4()): {}}
test_verb_dict[input_key][input_value]['self name'] = {input_value: {}}
class Input_Frame:
def __init__(self, master, frame):
self.frame1 = Frame(master)
self.frame1.pack(side = TOP)
self.entryframe0 = Frame(self.frame1)
self.entryframe0.pack(fill = X, expand = True)
self.entryframe1 = Frame(self.frame1)
self.entryframe1.pack(fill = X, expand = True)
self.entryframe2 = Frame(self.frame1)
self.entryframe2.pack(fill = X, expand = True)
self.entryframe3 = Frame(self.frame1)
self.entryframe3.pack(fill = X, expand = True)
self.label0 = Label(self.entryframe0,
text ='Verb:')
self.label0.pack(fill = X, expand = True, side = LEFT)
global verbentry0
verbentry0 = Entry(self.entryframe0,
width = 15)
verbentry0.pack(fill = X, expand = True)
verbentry0.focus_set
self.label1 = Label(self.entryframe1,
text ='Noun:')
self.label1.pack(fill = X, expand = True, side = LEFT)
self.e1 = Entry(self.entryframe1,
width = 15)
self.e1.pack(fill = X, expand = True)
self.label2 = Label(self.entryframe2,
text ='SubNoun:')
self.label2.pack(fill = X, expand = True, side = LEFT)
self.e2 = Entry(self.entryframe2,
width = 15)
self.e2.pack(fill = X, expand = True)
self.label3 = Label(self.entryframe3,
text ='Noun:')
self.label3.pack(fill = X, expand = True, side = LEFT)
self.e3 = Entry(self.entryframe3,
width = 15)
self.e3.pack(fill = X, expand = True)
self.add_task_button = ttk.Button(self.frame1,
text="submit",
width=10,
command=self.addTask_callback,
style = 'main.TButton')
self.add_task_button.pack()
self.remove_task_button = ttk.Button(self.frame1,
text="remove",
width=10,
command=self.removeTask_callback,
style = 'main.TButton')
self.remove_task_button.pack()
self.clear_task_button = ttk.Button(self.frame1,
text="hide",
command=self.clearTask_callback,
style = 'main.TButton')
self.clear_task_button.pack()
self.go_home_button = ttk.Button(self.frame1,
text="home",
width=10,
command=self.go_home_callback,
style = 'main.TButton')
self.go_home_button.pack()
## self.drill_task_button = ttk.Button(self.frame1,
## text="drill",
## width=10,
## command= self.sub_button_function,
## style = 'main.TButton')
## self.drill_task_button.pack()
self.entryframe4 = Frame(self.frame1)
self.entryframe4.pack(fill = X, expand = True)
self.label4 = Label(self.entryframe4,
text ='Output Filename:')
self.label4.pack(fill = X, expand = True, side = TOP)
self.e4 = Entry(self.entryframe4,
width = 15)
self.e4.pack(fill = X, expand = True, side = LEFT)
filetype_list = ['','.txt','.csv']
self.save_file_ext = StringVar()
self.save_file_ext.set('.txt')
self.opt0 = ttk.OptionMenu(self.entryframe4, self.save_file_ext, *filetype_list)
self.opt0.pack(fill = X, expand = True)
self.save_task_button = ttk.Button(self.frame1,
text="save",
width=10,
command= self.save_session,
style = 'main.TButton')
self.save_task_button.pack()
self.entryframe5 = Frame(self.frame1)
self.entryframe5.pack(fill = X, expand = True)
self.label5 = Label(self.entryframe5,
text ='Input Filename:')
self.label5.pack(fill = X, expand = True, side = TOP)
self.e5 = Entry(self.entryframe5,
width = 15)
self.e5.insert(0, "mylist_2_15_2016")
self.e5.pack(fill = X, expand = True, side = LEFT)
filetype_list = ['','.txt','.csv']
self.load_file_ext = StringVar()
self.load_file_ext.set('.txt')
self.opt1 = ttk.OptionMenu(self.entryframe5, self.load_file_ext, *filetype_list)
self.opt1.pack(fill = X, expand = True)
self.load_task_button = ttk.Button(self.frame1,
text="load",
width=10,
command= self.load_session,
style = 'main.TButton')
self.load_task_button.pack()
def open_link(link_name):
if link_name == ('art of the deal'):
webbrowser.open('http://www.funnyordie.com/videos/ad38087bac/donald-trump-art-of-the-deal-movie')
elif link_name == ('malcolm in the middle'):
webbrowser.open('http://www.netflix.com/browse/my-list')
def sub_button_function(button_dict):
for g,h in button_dict.items():
submittedVerb = g
submittedVP0 = h
newdict = test_verb_dict[submittedVerb][submittedVP0]
Load_Dict.Load_Button_Values(newdict)
Input_Frame.clearTask_callback()
Build_Buttons.pack_grid_subbuttons()
def sub_button_save_function(some_dict):
## print(some_dict)
pass
for g,h in some_dict.items():
x = g ## parent
for j,k in h.items():
y = j ## self
for r,s in k.items():
z = r ## property name
textfield = s ## property value (entry_object)
## print(textfield.cget('state'))
## function 1
if textfield.cget('state') == 'normal': ## if the text field is enabled, then on button press
input_property = textfield.get("1.0",END) ## get the input text from the text field
## print(input_property)
global test_verb_dict
test_verb_dict[x][y][z] = {input_property.strip(): {}} ## and assign that text to the working dict
textfield.configure(state='disabled',
background='black',
foreground='white',
relief = FLAT) ## disable the text box
textfield.tag_configure('justify', justify='center')
textfield.tag_add('justify', 1.0, "end")
## function 2
elif textfield.cget('state') == 'disabled': ## if the text field is diabled, then on button press
textfield.configure(state='normal',
background='white',
foreground='black',
relief = SUNKEN) ## enable the text field
textfield.tag_configure('justify', justify='left')
def save_session(self):
save_name = self.e4.get()
ext_name = self.save_file_ext.get()
filename = save_name + ext_name
if save_name != (''):
target = open(filename, 'w')
target.write(str(test_verb_dict))
target.close()
messagebox.showinfo(title = 'MeshWare', message = ('Session has been saved as %s ' % filename))
else:
messagebox.showinfo(title = 'MeshWare', message = ('a filename is required!'))
def load_session(self):
load_name = self.e5.get()
ext_name = self.load_file_ext.get()
filename = load_name + ext_name
if load_name != (''):
with open(filename,'r') as loadedverbsraw:
global test_verb_dict
test_verb_dict = ast.literal_eval(loadedverbsraw.read())
Load_Dict.Load_Button_Values(test_verb_dict)
else:
messagebox.showinfo(title = 'MeshWare', message = ('a filename is required!'))
self.clearTask_callback()
Build_Buttons.pack_grid_buttons()
def transfer_text_callback(buttontext = ''):
#print(buttontext)
global verbentry0
verbentry0.delete(0, END)
verbentry0.insert(0, buttontext)
def go_home_callback(self):
Load_Dict.Load_Button_Values(test_verb_dict)
self.clearTask_callback()
Build_Buttons.pack_grid_buttons()
def addTask_callback(self):
global verbentry0
submittedVerb = verbentry0.get()
submittedVP0 = self.e1.get()
submittedVPA = self.e2.get()
submittedVP1 = self.e3.get()
if submittedVerb == (''):
messagebox.showinfo(title = 'MeshWare', message = ('a main task is required'))
return
if submittedVerb != (''):
novelverb = submittedVerb in test_verb_dict
if novelverb == False:
print('verb sent to dict')
Build_Dicts.main_dict(submittedVerb)
elif novelverb == True:
print('verb alread in dict')
if test_verb_dict[submittedVerb] != (''):
tasklist = test_verb_dict[submittedVerb]
else:
tasklist = ()
if submittedVerb != (''):
if submittedVP0 != (''):
novelverb0 = submittedVP0 in tasklist #Returns True if present, False if novel
if novelverb0 == False:
print('first task sent to verb dict')
Build_Dicts.sub_dict(submittedVerb, submittedVP0)
elif novelverb0 == True:
print('first task already in dict')
## messagebox.showinfo(title = 'MeshWare', message = ("%s %s is already in the dictionary" % (submittedVerb, submittedVP0)
elif submittedVP1 == (''):
print('no first task submitted')
## messagebox.showinfo(title = 'MeshWare', message = ('no first task submitted')
if submittedVP1 != (''):
novelverb1 = submittedVP1 in tasklist #Returns True if present, False if novel
if novelverb1 == False:
print('second task sent to dict')
Build_Dicts.sub_dict(submittedVerb, submittedVP1)
elif novelverb1 == True:
print('second task already in dict')
## messagebox.showinfo(title = 'MeshWare', message = ("%s %s is already in the dictionary" % (submittedVerb, submittedVP1)
elif submittedVP1 == (''):
print('no second task submitted')
Load_Dict.Load_Button_Values(test_verb_dict)
self.clearTask_callback()
Build_Buttons.pack_grid_buttons()
def removeTask_callback(self):
global verbentry0
submittedVerb = verbentry0.get()
submittedVP0 = self.e1.get()
## submittedVPA = self.e2.get()
## submittedVP1 = self.e3.get()
if submittedVerb != (''):
novelverb = submittedVerb in test_verb_dict #Returns True if present, False if novel
if novelverb == True:
iter_dict = {}
iter_dict = test_verb_dict[submittedVerb]
if submittedVP0 != (''):
noveltask = submittedVP0 in iter_dict #Returns True if present, False if novel
if noveltask == True:
trashdict = {}
trashdict = iter_dict.pop(submittedVP0)
test_verb_dict[submittedVerb].update(iter_dict)
messagebox.showinfo(title = 'MeshWare', message = ("%s %s has been removed from the dictionary" % (submittedVerb, submittedVP0)))
else:
messagebox.showinfo(title = 'MeshWare', message = ('%s %s is not in the dictionary' % (submittedVerb, submittedVP0)))
else:
deletekeyconfirm = messagebox.askokcancel('Delete Dictionary Key',
('Are you sure you want to delete the following verb from the dictionary?\n\n **%s**' % submittedVerb))
if deletekeyconfirm == True:
test_verb_dict.pop(submittedVerb)
else:
messagebox.showerror(title = 'MeshWare', message = ('%s is not in the dictionary' % submittedVerb))
return
else:
messagebox.showerror(title = 'MeshWare', message = ('a main task and subtask are required'))
return
Load_Dict.Load_Button_Values(test_verb_dict)
self.clearTask_callback()
Build_Buttons.pack_grid_buttons()
def clearTask_callback(self=0):
global buttonframe
buttonframe.pack_forget()
buttonframe.destroy()
buttonframe = Frame(tasks_tab_frame,
relief = SUNKEN,
bg = 'grey')
buttonframe.pack(side = LEFT, fill = BOTH, expand = True)
##Pack paned window in tasks tab
global tasks_tab_panedwindow
tasks_tab_panedwindow = ttk.Panedwindow(buttonframe, orient = HORIZONTAL)
tasks_tab_panedwindow.pack(fill = BOTH, expand = True)
##Add panes to Task tab paned window
global ttpw_taskpane
ttpw_taskpane = ttk.Frame(tasks_tab_panedwindow, relief = SUNKEN)
tasks_tab_panedwindow.add(ttpw_taskpane, weight = 1)
global ttpw_subtaskpane
ttpw_subtaskpane = ttk.Frame(tasks_tab_panedwindow, relief = SUNKEN)
tasks_tab_panedwindow.add(ttpw_subtaskpane, weight = 4)
def genTask_callback():
pass
class Build_Buttons:
def __init__(self, master):
pass
def pack_buttons(self=0):
##Tasks pane
task_label_frame = ttk.Frame(ttpw_taskpane)
task_label_frame.pack(fill = X)
task_label = Label(task_label_frame, text = 'Tasks', justify = 'center')
task_label.pack(fill = X)
frame = Frame(ttpw_taskpane,
relief = SUNKEN,
bg = 'grey')
frame.pack(fill = BOTH, expand = True)
for f in sorted(taskbuttonspack):
if f == 'buy':
button = ttk.Button(frame,
text = f.upper(),
style = 'gold.TButton')
elif f == 'write':
button = ttk.Button(frame,
text = f.upper(),
style = 'red.TButton')
else:
button = ttk.Button(frame,
text = f.title(),
style = 'grey.TButton')
button.config(command = lambda i=f: Input_Frame.transfer_text_callback(i))
setattr(frame, f, button)
button.pack(**taskbuttonspack[f])
def grid_buttons(self=0):
##Subtasks pane
ttpw_subtask_label_frame = ttk.Frame(ttpw_subtaskpane)
ttpw_subtask_label_frame.pack(fill = BOTH)
ttpw_subtask_label = Label(ttpw_subtask_label_frame, text = ' Subtasks ', justify = 'center')
ttpw_subtask_label.pack(fill = X)
frame = Frame(ttpw_subtaskpane,
relief = SUNKEN,
bg = 'black')
frame.pack(fill = BOTH, expand = True)
for g, t in gridbuttonsiter.items():
for f in t:
#print(g)
#print(f)
defcon = test_verb_dict[g][f]['self defcon']
#print(defcon)
if defcon == {'1':{}}:
b_style = 'red.TButton'
elif defcon == {'2':{}}:
b_style = 'pink.TButton'
elif defcon == {'3':{}}:
b_style = 'orange.TButton'
elif defcon == {'4':{}}:
b_style = 'gold.TButton'
elif defcon == {'5':{}}:
b_style = 'green.TButton'
elif defcon == {'6':{}}:
b_style = 'blue.TButton'
elif defcon == {'7':{}}:
b_style = 'purple.TButton'
else:
b_style = 'grey.TButton'
q = {}
q[g] = f
button = ttk.Button(frame,
text = f,
style = b_style)
button.config(command = lambda i=q: Input_Frame.sub_button_function(i))
setattr(frame, f, button)
button.grid(**subtaskbuttonsgrid[f])
def pack_grid_buttons():
Build_Buttons.pack_buttons()
Build_Buttons.grid_buttons()
def pack_subbuttons(self=0):
##Tasks pane
task_label_frame = ttk.Frame(ttpw_taskpane)
task_label_frame.pack(fill = X)
task_label = Label(task_label_frame, text = 'Property', justify = 'center')
task_label.pack(fill = X)
frame = Frame(ttpw_taskpane,
relief = SUNKEN,
bg = 'grey')
frame.pack(fill = BOTH, expand = True)
for f in sorted(taskbuttonspack):
## if f == 'invest':
## button = ttk.Button(frame,
## text = f.upper(),
## style = 'gold.TButton')
## elif f == 'write':
## button = ttk.Button(frame,
## text = f.upper(),
## style = 'red.TButton')
## else:
property_name = f
parent_name = somethingnew['parent'].lower()
self_name = somethingnew['self name'].lower()
field = property_dict[parent_name][self_name][property_name]
pp_dict = {parent_name: {self_name: {property_name: field}}}
## print(pp_dict)
## property name buttons need the following variables when packed,
## parent_name
## self_name
## property_name (currently f from taskbuttonspack)
## entry_object
button = ttk.Button(frame,
text = f.title(),
style = 'grey.TButton')
button.config(command = lambda i=pp_dict: Input_Frame.sub_button_save_function(i))
if f == 'genesis date' or f == 'self id' or f == 'parent' or f == 'self name':
button.config(state=DISABLED)
setattr(frame, f, button)
button.pack(**taskbuttonspack[f])
def grid_subbuttons(self = 0):
##Properties pane
ttpw_subtask_label_frame = ttk.Frame(ttpw_subtaskpane)
ttpw_subtask_label_frame.pack(fill = BOTH)
ttpw_subtask_label = Label(ttpw_subtask_label_frame, text = ' Values ', justify = 'center')
ttpw_subtask_label.pack(fill = X)
frame = Frame(ttpw_subtaskpane,
relief = SUNKEN,
bg = 'black')
frame.pack(fill = BOTH, expand = True)
parent_name = somethingnew['parent'].lower()
self_name = somethingnew['self name'].lower()
property_name = somethingnew.keys()
global property_dict
property_dict = {parent_name:{self_name:{}}}
for h in somethingnew.keys():
property_dict[parent_name][self_name] = {h:{}}
for g, f in somethingnew.items():
if f[:6] != 'empty_':
field = Text(frame,
height = 1,
width = 30,
background='black',
foreground='white',
relief = FLAT)
field.insert(END, f)
field.tag_configure('center', justify='center')
field.tag_add('center', 1.0, "end")
field.config(state=DISABLED)
setattr(frame, f, field)
field.grid(**subtaskentrygrid[f])
else:
field = Text(frame,
height = 1,
width = 30)
field.insert(END, f)
setattr(frame, f, field)
field.grid(**subtaskentrygrid[f])
field_state = field.cget('state')
property_dict[parent_name][self_name][g] = field
## print(property_dict)
def pack_grid_subbuttons():
Build_Buttons.grid_subbuttons()
Build_Buttons.pack_subbuttons()
##class Schedule_Tasks:
##
## def __init__(self, master):
## pass
##
## def calculate_time(self=0):
## due_date = test_verb_dict[parent][self]['hard deadline']
## current_date = {str(datetime.datetime.now()): {}}
## time_left = due_date - current_date
class Calendar(ttk.Frame):
# XXX ToDo: cget and configure
datetime = calendar.datetime.datetime
timedelta = calendar.datetime.timedelta
def __init__(self, master=None, **kw):
"""
WIDGET-SPECIFIC OPTIONS
locale, firstweekday, year, month, selectbackground,
selectforeground
"""
# remove custom options from kw before initializating ttk.Frame
fwday = kw.pop('firstweekday', calendar.MONDAY)
year = kw.pop('year', self.datetime.now().year)
month = kw.pop('month', self.datetime.now().month)
locale = kw.pop('locale', None)
sel_bg = kw.pop('selectbackground', '#ecffc4')
sel_fg = kw.pop('selectforeground', '#05640e')
self._date = self.datetime(year, month, 1)
self._selection = None # no date selected
ttk.Frame.__init__(self, master, **kw)
self._cal = get_calendar(locale, fwday)
self.__setup_styles() # creates custom styles
self.__place_widgets() # pack/grid used widgets
self.__config_calendar() # adjust calendar columns and setup tags
# configure a canvas, and proper bindings, for selecting dates
self.__setup_selection(sel_bg, sel_fg)
# store items ids, used for insertion later
self._items = [self._calendar.insert('', 'end', values='')
for _ in range(6)]
# insert dates in the currently empty calendar
self._build_calendar()
# set the minimal size for the widget
self._calendar.bind('<Map>', self.__minsize)
def __setitem__(self, item, value):
if item in ('year', 'month'):
raise AttributeError("attribute '%s' is not writeable" % item)
elif item == 'selectbackground':
self._canvas['background'] = value
elif item == 'selectforeground':
self._canvas.itemconfigure(self._canvas.text, item=value)
else:
ttk.Frame.__setitem__(self, item, value)
def __getitem__(self, item):
if item in ('year', 'month'):
return getattr(self._date, item)
elif item == 'selectbackground':
return self._canvas['background']
elif item == 'selectforeground':
return self._canvas.itemcget(self._canvas.text, 'fill')
else:
r = ttk.tclobjs_to_py({item: ttk.Frame.__getitem__(self, item)})
return r[item]
def __setup_styles(self):
# custom ttk styles
style = ttk.Style(self.master)
arrow_layout = lambda dir: (
[('Button.focus', {'children': [('Button.%sarrow' % dir, None)]})]
)
style.layout('L.TButton', arrow_layout('left'))
style.layout('R.TButton', arrow_layout('right'))
def __place_widgets(self):
# header frame and its widgets
hframe = ttk.Frame(self)
lbtn = ttk.Button(hframe, style='L.TButton', command=self._prev_month)
rbtn = ttk.Button(hframe, style='R.TButton', command=self._next_month)
self._header = ttk.Label(hframe, width=15, anchor='center')
# the calendar
self._calendar = ttk.Treeview(show='', selectmode='none', height=7)
# pack the widgets
hframe.pack(in_=self, side='top', pady=4, anchor='center')
lbtn.grid(in_=hframe)
self._header.grid(in_=hframe, column=1, row=0, padx=12)
rbtn.grid(in_=hframe, column=2, row=0)
self._calendar.pack(in_=self, expand=1, fill='both', side='bottom')
def __config_calendar(self):
cols = self._cal.formatweekheader(3).split()
self._calendar['columns'] = cols
self._calendar.tag_configure('header', background='grey90')
self._calendar.insert('', 'end', values=cols, tag='header')
# adjust its columns width
font = tkinter.font.Font()
maxwidth = max(font.measure(col) for col in cols)
for col in cols:
self._calendar.column(col, width=maxwidth, minwidth=maxwidth,
anchor='e')
def __setup_selection(self, sel_bg, sel_fg):
self._font = tkinter.font.Font()
self._canvas = canvas = tkinter.Canvas(self._calendar,
background=sel_bg, borderwidth=0, highlightthickness=0)
canvas.text = canvas.create_text(0, 0, fill=sel_fg, anchor='w')
canvas.bind('<ButtonPress-1>', lambda evt: canvas.place_forget())
self._calendar.bind('<Configure>', lambda evt: canvas.place_forget())
self._calendar.bind('<ButtonPress-1>', self._pressed)
def __minsize(self, evt):
width, height = self._calendar.master.geometry().split('x')
height = height[:height.index('+')]
self._calendar.master.minsize(width, height)
def _build_calendar(self):
year, month = self._date.year, self._date.month
# update header text (Month, YEAR)
header = self._cal.formatmonthname(year, month, 0)
self._header['text'] = header.title()
# update calendar shown dates
cal = self._cal.monthdayscalendar(year, month)
for indx, item in enumerate(self._items):
week = cal[indx] if indx < len(cal) else []
fmt_week = [('%02d' % day) if day else '' for day in week]
self._calendar.item(item, values=fmt_week)
def _show_selection(self, text, bbox):
"""Configure canvas for a new selection."""
x, y, width, height = bbox
textw = self._font.measure(text)
canvas = self._canvas
canvas.configure(width=width, height=height)
canvas.coords(canvas.text, width - textw, height / 2 - 1)
canvas.itemconfigure(canvas.text, text=text)
canvas.place(in_=self._calendar, x=x, y=y)
# Callbacks
def _pressed(self, evt):
"""Clicked somewhere in the calendar."""
x, y, widget = evt.x, evt.y, evt.widget
item = widget.identify_row(y)
column = widget.identify_column(x)
if not column or not item in self._items:
# clicked in the weekdays row or just outside the columns
return
item_values = widget.item(item)['values']
if not len(item_values): # row is empty for this month
return
text = item_values[int(column[1]) - 1]
if not text: # date is empty
return
bbox = widget.bbox(item, column)
if not bbox: # calendar not visible yet
return
# update and then show selection
text = '%02d' % text
self._selection = (text, item, column)
self._show_selection(text, bbox)
def _prev_month(self):
"""Updated calendar to show the previous month."""
self._canvas.place_forget()
self._date = self._date - self.timedelta(days=1)
self._date = self.datetime(self._date.year, self._date.month, 1)
self._build_calendar() # reconstuct calendar
def _next_month(self):
"""Update calendar to show the next month."""
self._canvas.place_forget()
year, month = self._date.year, self._date.month
self._date = self._date + self.timedelta(
days=calendar.monthrange(year, month)[1] + 1)
self._date = self.datetime(self._date.year, self._date.month, 1)
self._build_calendar() # reconstruct calendar
# Properties
@property
def selection(self):
"""Return a datetime representing the current selected date."""
if not self._selection:
return None
year, month = self._date.year, self._date.month
return self.datetime(year, month, int(self._selection[0]))
def main():
root = Tk()
root.title('MeshWare Console')
root.resizable(True, True)
root.configure(background = 'grey')
sizex = 700
sizey = 600
posx = 0
posy = 0
root.geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
style_main = ttk.Style()
style_main.theme_use("default")
style_main.configure("main.TButton",
foreground="black",)
s = ttk.Style()
s.theme_use("default")
s.configure("TProgressbar", thickness=22)
## s.configure('TButton', background = 'gold')
#s.configure('TFrame', background = '#e1d8b9')
##style = ttk.Style()
##root.style.configure('TFrame', background = '#e1d8b9')
##root.style.configure('TButton', background = '#e1d8b9')
##root.style.configure('TLabel', background = '#e1d8b9', font = ('Arial', 11))
##root.style.configure('Header.TLabel', font = ('Arial', 18, 'bold'))
root.option_add('*tearOff', False)
menubar = Menu(root)
root.config(menu = menubar)
file = Menu(menubar)
edit = Menu(menubar)
help_ = Menu(menubar)
menubar.add_cascade(menu = file, label = 'File')
menubar.add_cascade(menu = edit, label = 'Edit')
menubar.add_cascade(menu = help_, label = 'Help')
file.add_command(label = 'New', command = lambda: print('New File'))
file.add_separator()
file.add_command(label = 'Open...', command = lambda: print('Opening File...'))
file.add_command(label = 'Save', command = lambda: print('Saving File...'))
file.entryconfig('New', accelerator = 'Ctrl+N')
#from PIL import Image
#from PIL import ImageTk
#image = Image.open("C:\\Users\\Zachary Roper\\Desktop\\MWlogo1.jpg")
#logo = ImageTk.PhotoImage(image)
#file.entryconfig('Open...', image = logo, compound = 'left')
#file.entryconfig('Open...', state = 'disabled')
file.delete('Save')
save = Menu(file)