-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameofLife_gui.py
1950 lines (1693 loc) · 85.9 KB
/
GameofLife_gui.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
try:
import tkinter as tk
import tkinter.font as tkFont
import tkinter.ttk as ttk
from tkinter.messagebox import *
except ImportError:
import Tkinter as tk
import Tkinter.font as tkFont
import Tkinter.ttk as ttk
from tkMessageBox import *
import sys
import time
from datetime import date
from datetime import timedelta
import datetime
from math import *
import os
#from button import *
import pickle
from array import array
class popupwindow(object):
def __init__(self, master, name=None, pt_val=5, realm="work", context=None, duedate=None, repeat=None, repeat_time=None, repeat_reset=None):
top=self.top=tk.Toplevel(master)
# top.geometry('300x600')
row_val=0
self.l=ttk.Label(top,text="Add task information").grid(column=0, row=row_val)#, sticky=(N, W, E, S))
self.name=tk.StringVar()
row_val+=1
name_label=ttk.Label(top, text="Name: ").grid(column=0, row=row_val)
name_entry=ttk.Entry(top, textvariable=self.name).grid(column=1, row=row_val)
if name!=None:
self.name.set(name)
row_val+=1
pt_val_label=ttk.Label(top, text="Point value: ").grid(column=0, row=row_val)
self.pts=tk.StringVar()
pt_val_entry=ttk.Entry(top, textvariable=self.pts).grid(column=1, row=row_val)
self.pts.set(pt_val)
row_val+=1
#TODO need to make this configurable -- global variable?
realms={" ", "home", "well-being", "health", "work"}
realm_label=ttk.Label(top, text="Realm: ").grid(column=0, row=row_val)
self.realm=tk.StringVar(master)
realm_menu=ttk.OptionMenu(top, self.realm, *realms)
if realm!=None:
self.realm.set(realm)
else:
self.realm.set("work")
realm_menu.grid(column=1, row=row_val)
row_val+=1
context_label=ttk.Label(top, text="Context: ").grid(column=0, row=row_val)
self.context=tk.StringVar()
context_entry=ttk.Entry(top, textvariable=self.context).grid(column=1, row=row_val)
if context!=None:
self.context.set(context)
row_val+=1
due_label=ttk.Label(top, text="Due date: ").grid(column=0, row=row_val)
self.due=tk.StringVar()
due_entry=ttk.Entry(top, textvariable=self.due).grid(column=1, row=row_val)
row_val+=1
rpt={" ", "no", "yes"}
repeat_label=ttk.Label(top, text="Repeat: ").grid(column=0, row=row_val)
self.repeat=tk.StringVar(master)
repeat_menu=ttk.OptionMenu(top, self.repeat, *rpt)
if repeat!=None:
self.repeat.set(repeat)
else:
self.repeat.set("no")
repeat_menu.grid(column=1, row=row_val)
row_val+=1
rpt_time_label=ttk.Label(top, text="Repeat time (days): ").grid(column=0, row=row_val)
self.repeat_time=tk.StringVar(master)
rpt_time_entry=ttk.Entry(top, textvariable=self.repeat_time).grid(column=1, row=row_val)
if repeat_time!=None:
self.repeat_time.set(repeat_time)
row_val+=1
rst={" ", "from initiation", "from completion"}
rpt_reset_label=ttk.Label(top, text="Repeat reset: ").grid(column=0, row=row_val)
self.rst=tk.StringVar(master)
rst_menu=ttk.OptionMenu(top, self.rst, *rpt)
if repeat_reset!=None:
self.rst.set(repeat_reset)
else:
self.rst.set("from completion")
rst_menu.grid(column=1, row=row_val)
row_val+=1
self.b=ttk.Button(top,text='Ok',command=self.cleanup)
self.b.grid(column=0, row=row_val)
def cleanup(self):
if self.rst.get()=="from completion":
self.reset=1
if self.rst.get()=="from initiation":
self.reset=0
if self.repeat.get()=="yes":
self.repeat="Y"
elif self.repeat.get()=="no":
self.repeat="N"
else:
self.repeat=self.repeat.get()
me.add_challenge_basic(name=self.name.get(), pt_val=self.pts.get(), realm=self.realm.get(), context=self.context.get(), due_date=self.due.get(), repeat=self.repeat, repeat_time=self.repeat_time.get(), repeat_reset=self.reset)
print("repeat? ", self.repeat)
if self.repeat=="yes":
askyesno("Habit?", "Add this to the habit bank?")
me.add_habit(name=self.name.get(), pt_val=self.pts.get(), realm=self.realm.get(), context=self.context.get(), repeat_time=self.repeat_time.get())
self.top.destroy()
class habitwindow(object):
def __init__(self, master):
self.tree = None
self.master=master
top=self.top=tk.Toplevel(master)
top.title("Habit bank")
self.container=container = ttk.Frame(self.top, width=100, height=10)
container.pack(fill='both', expand=True)
temp=ttk.Label(container, text="what's up!?")
#this should just display all the habits so far
self._setup_widgets()
self._build_tree()
def _setup_widgets(self):
# s = """click on header to sort by that column
#to change width of column drag boundary
# """
msg = ttk.Label(self.top, wraplength="4i", justify="left", anchor="n",
padding=(2, 2, 2, 6), text="Click to add habit to todo list, Ok to finish")
msg.pack(fill='x')
# create a treeview with dual scrollbars
self.tree = ttk.Treeview(self.top, columns=habit_header, show="headings")
vsb = ttk.Scrollbar(orient="vertical",
command=self.tree.yview)
hsb = ttk.Scrollbar(orient="horizontal",
command=self.tree.xview)
self.tree.configure(yscrollcommand=vsb.set,
xscrollcommand=hsb.set)
self.tree.pack()
self.b=ttk.Button(self.top,text='Ok',command=self.cleanup)
self.b.pack()
## self.tree.grid(column=0, row=0, sticky='nsew', in_=self.top)
## vsb.grid(column=1, row=0, sticky='ns', in_=container)
## hsb.grid(column=0, row=1, sticky='ew', in_=container)
## container.grid_columnconfigure(0, weight=1)
## container.grid_rowconfigure(0, weight=1)
def _build_tree(self):
for col in habit_header:
self.tree.heading(col, text=col.title(),
command=lambda c=col: sortby(self.tree, c, 0))
# adjust the column's width to the header string
self.tree.column(col,
width=tkFont.Font().measure(col.title()))
for task_item in me.habitlist:
print("in habit list loop")
item=[]
print(task_item.uniq_id)
print(habit_header)
print(task_item)
#make this into a list that the following can understand
for col_val in habit_header:
if col_val == "Habit #":
item.append(str(task_item.uniq_id))
print(task_item.uniq_id)
print(item)
# item.append(tk.Checkbutton(self, command=me.toggle_completed(task_item.uniq_id)))
if col_val == "name":
item.append(str(task_item.name))
if col_val == "realm":
item.append(str(task_item.realm))
if col_val == "context":
item.append(str(task_item.context))
if col_val == "points":
item.append(str(task_item.pt_val))
self.tree.insert('', 'end', values=item, tags=(task_item.uniq_id))
self.tree.tag_bind(task_item.uniq_id, '<<TreeviewSelect>>', self.addhabit)
count=0
# adjust column's width if necessary to fit each value
for ix, val in enumerate(item):
# print("ix, val", ix, val)
# print("count", count)
count=count+1
col_w = tkFont.Font().measure(val)
if self.tree.column(habit_header[ix],width=None)<col_w:
self.tree.column(habit_header[ix], width=col_w)
def addhabit(self, event):
item_id = str(self.tree.focus())
item=self.tree.item(item_id)
values=item['values']
uid=item['tags']
uid=uid[0]
newhabit=me.habitlist[uid]
self.w=popupwindow(self.master, name=newhabit.name, pt_val=newhabit.pt_val, realm=newhabit.realm, context=newhabit.context, repeat="yes", repeat_time=newhabit.repeat_time)
self.master.wait_window(self.w.top)
def cleanup(self):
## if self.habit=="yes":
## me.add_habit(name=self.name.get(), pt_val=self.pts.get(), realm=self.realm.get(), context=self.context.get(), due_date=self.due.get(), repeat=self.repeat.get())
self.top.destroy()
class MultiColumnListbox(tk.Frame):
"""use a ttk.TreeView as a multicolumn ListBox"""
def __init__(self, master):
super(MultiColumnListbox, self).__init__()
self.tree = None
self.master=master
self.no_completed=True
self._setup_widgets()
self._build_tree()
def _setup_widgets(self):
# s = """click on header to sort by that column
#to change width of column drag boundary
# """
# msg = ttk.Label(wraplength="4i", justify="left", anchor="n",
# padding=(10, 2, 10, 6), text=s)
# msg.pack(fill='x')
container = ttk.Frame()
container.pack(fill='both', expand=True)
# create a treeview with dual scrollbars
self.tree = ttk.Treeview(columns=view_header, show="headings")
vsb = ttk.Scrollbar(orient="vertical",
command=self.tree.yview)
hsb = ttk.Scrollbar(orient="horizontal",
command=self.tree.xview)
self.tree.configure(yscrollcommand=vsb.set,
xscrollcommand=hsb.set)
self.tree.grid(column=0, row=0, sticky='nsew', in_=container)
vsb.grid(column=1, row=0, sticky='ns', in_=container)
hsb.grid(column=0, row=1, sticky='ew', in_=container)
container.grid_columnconfigure(0, weight=1)
container.grid_rowconfigure(0, weight=1)
add_button=ttk.Button(self.master, text="Add task", command=self.add_popup)
add_button.pack(side=tk.LEFT)
habit_button=ttk.Button(self.master, text="Add habit", command=self.habit_popup)
habit_button.pack(side=tk.LEFT)
remove_button=ttk.Button(self.master, text="Remove completed", command=self.remove_completed)
remove_button.pack(pady=20, padx=20, side=tk.RIGHT)
def remove_completed(self):
for item_id in self.tree.get_children():
tree_val=self.tree.item(item_id)
if "completed" in tree_val["tags"]:
self.tree.delete(item_id)
def add_popup(self):
self.w=popupwindow(self.master)
self.master.wait_window(self.w.top)
#grab the task that was just added to challenge list and put it in the display
task_item=me.challengelist[-1]
# for task_item in me.challengelist:
# print(task_item)
item=[]
for col_val in view_header:
if col_val == "Task #":
item.append(str(task_item.uniq_id))
if col_val == "name":
item.append(str(task_item.name))
if col_val == "realm":
item.append(str(task_item.realm))
if col_val == "context":
item.append(str(task_item.context))
if col_val == "points":
item.append(str(task_item.pt_val))
if col_val == "due date":
item.append(str(task_item.due_date))
self.tree.insert('', 'end', values=item, tags=(task_item.uniq_id, "uncompleted"))
def habit_popup(self):
#habitwindow is a popup that displays habits
self.h=habitwindow(self.master)
self.master.wait_window(self.h.top)
#grab the task that was just added to challenge list and put it in the display
task_item=me.challengelist[-1]
item=[]
for col_val in view_header:
if col_val == "Task #":
item.append(str(task_item.uniq_id))
if col_val == "name":
item.append(str(task_item.name))
if col_val == "realm":
item.append(str(task_item.realm))
if col_val == "context":
item.append(str(task_item.context))
if col_val == "points":
item.append(str(task_item.pt_val))
if col_val == "due date":
item.append(str(task_item.due_date))
self.tree.insert('', 'end', values=item, tags=(task_item.uniq_id, "uncompleted"))
def entryValue(self):
print(self.w.realm)
print(self.w.name)
def onClick(self, event):
item_id = str(self.tree.focus())
item=self.tree.item(item_id)
uid=item['tags']
uid=uid[0]
completed=0
completed=me.toggle_completed(uid)
active=me.get_active(uid)
if completed=="Y":
temp_val=item['values']
temp_tags=item['tags']
type(temp_val)
self.tree.delete(item_id)
self.tree.insert('', 'end', values=temp_val, tags=(temp_tags[0], "completed"))
if completed=="N":
temp_val=item['values']
temp_tags=item['tags']
type(temp_val)
self.tree.delete(item_id)
self.tree.insert('', 'end', values=temp_val, tags=(temp_tags[0], "uncompleted"))
def _build_tree(self):
for col in view_header:
self.tree.heading(col, text=col.title(),
command=lambda c=col: sortby(self.tree, c, 0))
# adjust the column's width to the header string
self.tree.column(col,
width=tkFont.Font().measure(col.title()))
for task_item in me.challengelist:
#skip completed challenges if no_completed is True
if task_item.active=="Y" and task_item.completed=="N":
#if not (self.no_completed==True and task_item.completed=="Y"):
item=[]
# print(task_item.uniq_id)
# print(view_header)
#make this into a list that the following can understand
for col_val in view_header:
if col_val == "Task #":
item.append(str(task_item.uniq_id))
# print(task_item.uniq_id)
# print(item)
# item.append(tk.Checkbutton(self, command=me.toggle_completed(task_item.uniq_id)))
if col_val == "name":
item.append(str(task_item.name))
if col_val == "realm":
item.append(str(task_item.realm))
if col_val == "context":
item.append(str(task_item.context))
if col_val == "points":
item.append(str(task_item.pt_val))
if col_val == "due date":
item.append(str(task_item.due_date))
self.tree.tag_configure("completed", background='orange')
if task_item.completed=='Y': comp_val="completed"
if task_item.completed=='N': comp_val="uncompleted"
self.tree.insert('', 'end', values=item, tags=(task_item.uniq_id, comp_val))
self.tree.tag_bind(task_item.uniq_id, '<<TreeviewSelect>>', self.onClick)
count=0
# adjust column's width if necessary to fit each value
for ix, val in enumerate(item):
# print("ix, val", ix, val)
# print("count", count)
count=count+1
col_w = tkFont.Font().measure(val)
if self.tree.column(view_header[ix],width=None)<col_w:
self.tree.column(view_header[ix], width=col_w)
def sortby(tree, col, descending):
"""sort tree contents when a column header is clicked on"""
# grab values to sort
data = [(tree.set(child, col), child) \
for child in tree.get_children('')]
# if the data to be sorted is numeric change to float
#data = change_numeric(data)
# now sort the data in place
data.sort(reverse=descending)
for ix, item in enumerate(data):
tree.move(item[1], '', ix)
# switch the heading so it will sort in the opposite direction
tree.heading(col, command=lambda col=col: sortby(tree, col, \
int(not descending)))
class avatar:
def __init__(self):
#search current directory for save file
directory=os.getcwd()
print(directory)
if os.path.isfile(directory+"/Life_challenge_file.txt") and os.path.isfile(directory+"/Life_points_file.txt") and os.path.isfile(directory+"/Life_preferences.txt" and os.path.isfile(directory+"/Life_habit_file.txt")):
f=open(directory+'/Life_challenge_file.txt', mode='rb')
self.challengelist=pickle.load(f)
f.close()
f=open(directory+'/Life_points_file.txt', mode='rb')
self.record=pickle.load(f)
f.close()
f=open(directory+'/Life_preferences.txt', mode='rb')
self.prefs=pickle.load(f)
f.close()
f=open(directory+"/Life_habit_file.txt", 'wb')
self.habitlist=pickle.load(f)
f.close()
elif os.path.isfile(directory+"/Life_challenge_file.txt"):
f=open(directory+'/Life_challenge_file.txt', mode='rb')
self.challengelist=pickle.load(f)
f.close()
num_realms=4
num_subrealms=[2,6,2,2]
realm_names=["home", "work", "health", "well-being"]
ideal_pts=[20, 60, 20, 20]
self.prefs=prefs(num_realms, num_subrealms, realm_names, ideal_pts)
today=datetime.datetime.combine(date.today(), datetime.time(0, 0))
self.record=points(today, [0, 0, 0, 0])
if os.path.isfile(directory+"/Life_habit_file.txt"):
f=open(directory+"/Life_habit_file.txt", 'rb')
self.habitlist=pickle.load(f)
f.close()
else:
self.habitlist=[]
self.add_habit(name="eat fruit", realm="health", pt_val=1, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="eat grains", realm="health", pt_val=1, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="work inbox <10", realm="work", pt_val=2, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="yahoo inbox <50 or delete 50", realm="home", pt_val=2, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="read a paper", realm="work", pt_val=5, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="check urgent, important and this week folders", realm="work", pt_val=2, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="write something", realm="work", pt_val=10, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
else:
#if no file then initialize object
self.avatar_initial_setup()
self.refresh_challenges()
self.save_challenges()
def avatar_initial_setup(self):
directory=os.getcwd()
# print(directory)
if os.path.isfile(directory+"/Life_preferences.txt"):
f=open(directory+"/Life_preferences.txt", mode='rb')
pickle.load(f)
f.close()
else:
num_realms=4
num_subrealms=[2,6,2,2]
realm_names=["home", "work", "health", "well-being"]
# self.level=0
# self.points=0
ideal_pts=[20, 60, 20, 20]
self.prefs=prefs(num_realms, num_subrealms, realm_names, ideal_pts)
today=datetime.datetime.combine(date.today(), datetime.time(0, 0))
self.record=points(today, [0, 0, 0, 0])
self.challengelist=[]
if os.path.isfile(directory+"/Life_habit file.txt"):
f=open(directory+"/Life_habit_file.txt", 'wb')
pickle.load(f)
f.close()
else:
self.habitlist=[]
self.add_habit(name="eat fruit", realm="health", pt_val=1, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y")
self.add_habit(name="eat grains", realm="health", pt_val=1, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y")
self.add_habit(name="work inbox <10", realm="work", pt_val=2, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="yahoo inbox <50 or delete 50", realm="home", pt_val=2, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="read a paper", realm="work", pt_val=5, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="check urgent, important and this week folders", realm="work", pt_val=2, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_habit(name="write something", realm="work", pt_val=10, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)), repeat="Y", repeat_time=1)
self.add_challenge_basic(name="finish program edits", realm="well-being", pt_val=1, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)))
self.add_challenge_basic(name="relax", realm="well-being", pt_val=1, date_created=datetime.datetime.combine(date.today(), datetime.time(0, 0)))
## f=open(directory+"/Life_challenge_file.txt", 'wb')
## pickle.dump(self.challengelist, f)
## f.close()
##
## f=open(directory+"/Life_preferences.txt", 'wb')
## pickle.dump(self.prefs, f)
## f.close()
##
### print("Here's what it looks like now", self.record.date, self.record.realm_pts)
## f=open(directory+"/Life_points_file.txt", 'wb')
## pickle.dump(self.record, f)
## f.close()
self.save_challenges()
def wrapper(self):
option=""
while option !='Q':
option=input('\nOptions:\nA: add challenges\nC: complete challenges\nD: delete challenges\nP: plan or print\nQ: quit\n')
if option=="A":
option2=input('A: add single\nAM: add multiple\nAC:add completed\nAS: add sub\n')
if option2=='A':
self.add_challenge()
if option2=='AM':
self.add_challenges()
if option2=='AC':
self.add_competed_challenge()
if option2=='AS':
self.add_subchallenge()
elif option=="C":
option2=input("CM: complete multiple\nCR: complete on different day\nCRM: complete multiple on different day\n(Or just enter challenge number)\n")
if option2.isdigit():
self.complete(int(option2))
if option2=="CM":
num="-1"
while num !="-1":
num=input("challenge number: (-1 to stop)")
if int(num) > -1:
self.complete(int(num))
if option2=="CR":
self.retro_complete()
if option2=="CRM":
self.retro_comp_multiple()
elif option=='D':
uniq_id=input("which challenge: ")
self.delete_challenge(int(uniq_id))
elif option=='P':
option2=input("PW: print week\nPA: print active\nPR: print realm\nPC: print context\nPS: print sorted\nPB: print bosses\nPNW: plan next week\n")
if option2=="PW":
self.print_week()
if option2=="PA":
self.print_active()
if option2=="PC":
context=input("which context: ")
self.print_challenges(context=context)
if option2=="PB":
self.print_bosses()
if option2=="PR":
realm=input("which realm: ")
self.print_challenges(realm=realm)
if option2=="PS":
self.print_sorted()
if option2=="PNW":
self.plan_next_week()
elif option=='Q':
return
def add_completed_challenge(self):
self.add_challenge(completed='Y', active='N')
def plan_next_week(self, realm="work"):
self.print_overdue()
print("active challenges (not daily, not currently planned)")
length=range(len(self.challengelist))
# self.print_todos(realm)
print("\nDue dates in the next two weeks")
self.print_due(14, realm)
print("\nPlanned activities in the next two weeks")
self.print_todo(14, realm)
one_day=timedelta(days=1)
day=datetime.datetime.combine(date.today(), datetime.time(0, 0))
count=range(8)
daysofweek=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
for j in count:
print("\n")
dow=day.weekday()
print("Unassigned tasks:")
for i in length:
if self.challengelist[i].planned_date==None and self.challengelist[i].completed=="N" and \
self.challengelist[i].realm==realm and self.challengelist[i].repeat=="N":
if self.challengelist[i].isboss=="Y":
print("BOSS ")#, end="")
if self.challengelist[i].active=="N" and self.challengelist[i].isboss=="N":
print("(")#, end="")
print(self.challengelist[i].uniq_id, self.challengelist[i].short_print())#, end="")
if self.challengelist[i].active=="N" and self.challengelist[i].isboss=="N":
print(")")
else:
print("")
print("\nPlanned for ", daysofweek[dow], day)
self.print_todotoday(day=day)
print("\n")
task=1
while task !="0":
print("Day: ", daysofweek[dow], day)
task=input("What task would you like to add (enter task #, 0 to move on, 'new' to add new challenge): ")
if type(task) == str and task == "new":
self.add_challenge(planned_date=datetime.datetime.combine(day,datetime.time(0, 0)))
elif task !="0" and task !="":
day=datetime.datetime.combine(day,datetime.time(0, 0))
self.change_tododate(int(task), day)
day=day+one_day
self.save_challenges()
def bib(self, uniq_id, days=1):
"""bump it back a day"""
index=self.uniq2index(uniq_id)
one_day=timedelta(days=days)
if self.challengelist[index].planned_date != "None":
self.challengelist[index].planned_date=self.challengelist[index].planned_date+one_day
def print_week(self, realm="work"):
self.print_overdue()
print("\nUpcoming due dates")
self.print_due(7,realm)
print("\nTODO list")
self.print_todo(7, realm)
def delete_challenge(self, uniq_id):
num=self.uniq2index(uniq_id)
print("Deleting challenge ", self.challengelist[num].name)
sure=input("Y/N?")
if sure=="Y":
self.challengelist.pop(num)
print("deleted")
length=range(len(self.challengelist))
for i in length:
if self.challengelist[i].unlocked_by !="" and self.challengelist[i].unlocked_by!=[]:
for uniq_id in self.challengelist[i].unlocked_by:
self.challengelist[i].unlocked_by.remove(uniq_id)
#
def uncomplete(self, uniq_id):
num=self.uniq2index(uniq_id)
if self.challengelist[num].completed=="N":
print("this challenge has not yet been completed ")
return
self.challengelist[num].completed='N'
self.challengelist[num].active='Y'
if self.challengelist[num].pt_val=="var":
pt_val=float(input("What is the point value: "))
else:
pt_val=self.challengelist[num].pt_val
date_cnt=-1
for it in self.record.date:
date_cnt+=1
if it==datetime.datetime.date(self.challengelist[num].date_completed):
realm_cnt=-1
for name in self.prefs.realm_names:
realm_cnt+=1
if self.challengelist[num].realm==name:
self.record.realm_pts[date_cnt][realm_cnt]=self.record.realm_pts[date_cnt][realm_cnt]-float(pt_val)
print(self.record.date[date_cnt])
print(self.prefs.realm_names[0], self.record.realm_pts[date_cnt][0])
print(self.prefs.realm_names[1], self.record.realm_pts[date_cnt][1])
print(self.prefs.realm_names[2], self.record.realm_pts[date_cnt][2])
print(self.prefs.realm_names[3], self.record.realm_pts[date_cnt][3])
self.challengelist[num].date_completed=None
def update_pts(self, realm, date, pt_val):
found=0
date_cnt=-1
# print("adding pt val: ", pt_val)
# if type(date) == datetime.datetime:
# date=date.date()
print(self.record.date)
print(date_cnt)
for it in self.record.date:
date_cnt=date_cnt+1
print(date_cnt)
print(it.date())
print(date.date())
if it.date()==date.date():
print("in the loop")
realm_cnt=-1
for name in self.prefs.realm_names:
realm_cnt=realm_cnt+1
if realm==name:
# print(self.record.realm_pts[date_cnt][realm_cnt])
self.record.realm_pts[date_cnt][realm_cnt]=self.record.realm_pts[date_cnt][realm_cnt]+pt_val
found=1
print("found", found)
if found==0: #today's date isn't found in points, so make a new column for today
self.record.date.append(date.today())
self.record.realm_pts.append([0,0,0,0])
realm_cnt=-1
date_cnt=date_cnt+1 #just move to the next one
print(date_cnt)
for name in self.prefs.realm_names:
realm_cnt=realm_cnt+1
if realm==name:
print(self.record.realm_pts)
print(date_cnt)
print(realm_cnt)
print(pt_val)
self.record.realm_pts[date_cnt][realm_cnt]=self.record.realm_pts[date_cnt][realm_cnt]+float(pt_val)
# print(self.record.date[date_cnt])
# print(self.prefs.realm_names[0], self.record.realm_pts[date_cnt][0])
# print(self.prefs.realm_names[1], self.record.realm_pts[date_cnt][1])
# print(self.prefs.realm_names[2], self.record.realm_pts[date_cnt][2])
# print(self.prefs.realm_names[3], self.record.realm_pts[date_cnt][3])
def uniq2index(self, uniq_id):
length=range(len(self.challengelist))
# print("looking for: ", uniq_id)
num=[]
if type(uniq_id=='str'):
uniq_id=int(uniq_id)
for i in length:
if self.challengelist[i].uniq_id == uniq_id:
num.append(i)
if len(num) >1:
print("more than one challenge match that number")
return
if len(num)==0:
print("no challenge found ", uniq_id)
return
return int(num[0])
def complete(self, uniq_id, date_completed=datetime.datetime.combine(date.today(), datetime.time(0, 0)), comments=""):
num=int(self.uniq2index(int(uniq_id)))
if self.challengelist[num].completed=="Y":
print("this challenge has already been completed! ")
return
print("Congratulations on completing ", self.challengelist[num].name)
print("repeat is", self.challengelist[num].repeat)
self.challengelist[num].completed='Y'
self.challengelist[num].active='N'
self.challengelist[num].date_completed=date_completed
if self.challengelist[num].pt_val=="var":
pt_val=float(input("What is the point value: "))
else:
pt_val=float(self.challengelist[num].pt_val)
# print("pt_val before update pts: ", pt_val)
# comments=input("Any comments? ")
if (self.challengelist[num].repeat=='N' or self.challengelist[num].repeat=="no") and comments != "":
self.challengelist[num].comments.append(comments)
self.update_pts(self.challengelist[num].realm, date_completed, pt_val)
self.refresh_challenges()
if self.challengelist[num].repeat=='Y' or self.challengelist[num].repeat=="yes":
print("repeat is yes")
me.chain_length(self.challengelist[num].name, num)
self.challengelist[num].completed="N"
repeat_time=timedelta(days=int(self.challengelist[num].repeat_time))
#repeat_reset allows you to have the reset be x days from the last complete or x days from the last appearance
if int(self.challengelist[num].repeat_reset)==0: #i.e. this resets from time last one appeared
next_active=self.challengelist[num].date_created+repeat_time
if int(self.challengelist[num].repeat_reset)==1:
next_active=datetime.datetime.combine(date.today()+repeat_time, datetime.time(0, 0))
print("setting to be active tomorrow")
if not hasattr(me.challengelist[num], 'notes'):
self.challengelist[num].notes=[]
if self.challengelist[num].comments==None:
self.challengelist[num].comments=[]
elif type(self.challengelist[num].comments) != list:
self.challengelist[num].comments=[self.challengelist[num].comments]
if comments != "":
self.challengelist[num].comments.append(comments)
if self.challengelist[num].date_completed==None:
old_completed=[]
print("None")
elif type(self.challengelist[num].date_completed)!=list:
old_completed=[self.challengelist[num].date_completed]
print("not list")
else:
old_completed=self.challengelist[num].date_completed
print("list")
old_completed.append(date_completed)
self.challengelist[num].date_completed=old_completed
self.challengelist[num].next_active=next_active
self.challengelist[num].active="N"
self.add_challenge(name=self.challengelist[num].name, \
context=self.challengelist[num].context, \
pt_val=self.challengelist[num].pt_val,\
realm=self.challengelist[num].realm, \
subrealm=self.challengelist[num].subrealm, \
repeat=self.challengelist[num].repeat, \
repeat_time=self.challengelist[num].repeat_time, \
repeat_reset=self.challengelist[num].repeat_reset, \
isboss=self.challengelist[num].isboss, \
boss=self.challengelist[num].boss, \
date_last_comp=date_completed , \
active="N",\
notes="",\
unlocked_by=[],\
due_date=None,\
planned_date=None,\
next_active=next_active)
self.save_challenges()
def retro_complete(self, uniq_id=0, date_comp=None):
"""Add a completed challenge on a previous day"""
if date_comp==None:
date_comp=me.get_date()
if uniq_id==0:
uniq_id=input("which challenge? ")
me.complete(uniq_id, date_comp)
def retro_comp_multiple(self):
date_comp=me.get_date()
uniq_id=input("which challenge? ")
while uniq_id != 'q':
me.complete(uniq_id, date_comp)
uniq_id=input("which challenge (q to quit)? ")
def print_pts(self, dd=7):
today=date.today()
one_week=timedelta(days=dd)
length=range(len(self.record.date))
totals=[]
for i in range(self.prefs.num_realms):
totals.append(0.0)
for i in length:
if self.record.date[i]>today-one_week:
print(self.record.date[i], self.record.realm_pts[i])
for j in range(self.prefs.num_realms):
totals[j]=totals[j]+self.record.realm_pts[i][j]
# print("total now: ", totals[j])
print("Totals")
for i in range(self.prefs.num_realms):
print(self.prefs.realm_names[i]+": "+str(totals[i]))
print("Percentages vs ideal: ")
for i in range(self.prefs.num_realms):
print(self.prefs.realm_names[i]+": "+str(int(100*totals[i]/self.prefs.ideal_pts[i]))+"%")
def print_repeating(self):
length=range(len(self.challengelist))
for i in length:
if self.challengelist[i].active=="Y" and self.challengelist[i].repeat=="Y":
print(self.challengelist[i].uniq_id, self.challengelist[i].short_print())
def print_weekly(self):
length=range(len(self.challengelist))
for i in length:
if self.challengelist[i].active=="Y" and self.challengelist[i].repeat=="Y" and self.challengelist[i].repeat_time==7:
print(self.challengelist[i].uniq_id, self.challengelist[i].short_print())
def print_daily(self):
length=range(len(self.challengelist))
for i in length:
if self.challengelist[i].active=="Y" and self.challengelist[i].repeat=="Y" and self.challengelist[i].repeat_time==1:
print(self.challengelist[i].uniq_id, self.challengelist[i].short_print())
def print_threegoodthings(self):
length=range(len(self.challengelist))
for i in length:
if self.challengelist[i].name=="three good things":
print(self.challengelist[i].date_completed, self.challengelist[i].comments)
def chain_length(self, challenge, last, printit=0):
length=range(len(self.challengelist))
count=0
dates=[]
#first run through all the challenges and look for others with the same name, count them and make
#file called "dates" that holds all the dates
for i in length:
if self.challengelist[i].name==challenge and self.challengelist[i].completed=="Y":
count=count+1
if printit == 1:
print(self.challengelist[i].date_completed)
dates.append(self.challengelist[i].date_completed)
length=range(count-1, 0, -1)
one_day=timedelta(days=int(self.challengelist[last].repeat_time))
old_date=dates[count-1]
count2=1
#now count backwards through the dates you've collected and see how long they are sequential (i.e. to see
#how many days in a row the challenge has been done).
for i in length:
if dates[i]== old_date-one_day:
count2=count2+1
old_date=dates[i]
else:
i=0
if count2 == 7:
print("You're on a streak! 7 in a row!!")
if count2 == 21:
print ("I think you've got it. 21 in a row! You advance to the next level on this challenge.")
self.challengelist[last].repeat_time=2*self.challengelist[last].repeat_time
print("You've done "+challenge+" " +str(count)+" days total and "+str(count2)+" days in a row")
def print_active(self):
length=range(len(self.challengelist))
count=0
for i in length:
if self.challengelist[i].active=="Y":
count=count+1
print(self.challengelist[i].uniq_id, self.challengelist[i].short_print())
print(str(count)+" active challenges")
def get_active(self, uid):
return self.challengelist[uid].active
def print_sorted(self):
length=range(len(self.challengelist))
count=0
for j in self.prefs.realm_names:
print("\nRealm: ", j)
for i in length:
if self.challengelist[i].active=="Y" and self.challengelist[i].realm==j:
count=count+1
print(self.challengelist[i].uniq_id, self.challengelist[i].short_print())
#run through one more time to find challenges that aren't labeled correctly
for i in length:
found=0
for j in self.prefs.realm_names:
if self.challengelist[i].active=="Y" and self.challengelist[i].realm==j:
found=1
if self.challengelist[i].active=="Y" and found==0:
print("!!! Missing appropriate realm")
print(i, self.challengelist[i].long_print())
count=count+1
print("\n"+str(count)+" active challenges")
def print_work(self):
length=range(len(self.challengelist))
for i in length:
if self.challengelist[i].realm=="work":
print(self.challengelist[i].uniq_id, self.challengelist[i].short_print())
def print_due(self, numdays, realm):
due=[]
length=range(len(self.challengelist))
diff=timedelta(days=numdays)
for i in length:
if self.challengelist[i].due_date != None:
# print(i)
due_date=datetime.datetime.combine(self.challengelist[i].due_date, datetime.time(0, 0))
today=datetime.datetime.combine(date.today(),datetime.time(0, 0))
if due_date<=today+diff and self.challengelist[i].active=="Y" and self.challengelist[i].realm==realm: