-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
2536 lines (2179 loc) · 123 KB
/
main.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
from tkinter import ttk
import tkinter as tk
from tkcalendar import DateEntry, Calendar
from tkinter import messagebox
import customtkinter as ctk
import time
from datetime import datetime, timedelta
from calendar import month_name
import os
import configparser
import openpyxl
import math
from transation_calculator import *
class Window(ctk.CTk):
def __init__(self):
super().__init__()
self.geometry("500x550")
self.title("Money Manager")
self.resizable(False,False)
self.init_variable()
WinBackEnd(self)
self.mainloop()
def init_variable(self):
self.setting_ini_path=f"{(os.path.dirname(os.path.abspath(__file__)))}\\setting.ini"
self.current_date_var= ctk.StringVar()
self.next_reminder_var= ctk.StringVar(value="2 PM")
self.time_left_var= ctk.IntVar(value=5)
self.User_Name=ctk.StringVar()
class WinBackEnd():
def __init__(self,window):
self.window=window
Setup_result=Backend_Inital_page(self.window)
if Setup_result.Setup_result:
Backend_First_page(self.window)
class Backend_Inital_page():
def __init__(self,window):
self.window=window
self.Money_Element_list=[]
self.config= configparser.ConfigParser()
self.config.read(self.window.setting_ini_path)
try:
self.setup_user_name=self.config.get("FILE_LOCATION","setup_user_name")
except:
self.config.add_section('FILE_LOCATION')
self.config.set('FILE_LOCATION', 'location', '')
self.config.set('FILE_LOCATION', 'setup_user_name', '')
self.config.set('FILE_LOCATION', 'elements_for_money_track', '')
self.config.add_section('Keywords')
self.config.set('Keywords','keywords','')
self.config.add_section("Loan")
self.config.set("Loan", "tangents","")
with open(self.window.setting_ini_path, 'w') as config_file:
self.config.write(config_file)
self.config= configparser.ConfigParser()
self.config.read(self.window.setting_ini_path)
self.setup_user_name=self.config.get("FILE_LOCATION","setup_user_name")
self.directory_path=self.config.get("FILE_LOCATION","location")
if not self.setup_user_name:
self.directory_path="C:/Users/baniy/Documents"
self.inital_page=Inital_page(self.window,self)
self.Setup_result=False
else:
self.Setup_result=True
def database_folder_selector(self):
# setting up the location
self.directory_path=ctk.filedialog.askdirectory(title="Select Storage",initialdir=f"{os.path.expanduser('~')}\\Documents",mustexist=True)
if self.directory_path :
self.inital_page.selection_btn.configure(text="Selected ",
border_color="#D2DE32",
fg_color="green",
border_width=3,
)
elif not self.directory_path:
self.directory_pat=""
self.inital_page.selection_btn.configure(text="Select",
border_color="white",
fg_color="#4F6F52",
border_width=1,
)
Notification(self.window,f"Plz select the folder to store Data !!!!!", "red",6)
def money_track_adder(self,*args):
if self.element_name.get() != "":
return_value =self.Save_changes_in_element_name()
if return_value==0:
return
if self.element_name.get() == "New Element":
Notification(text="First Edit Inital Name of Element",window=self.window)
else:
self.button_structure("New Element",self.inital_page,len(self.Money_Element_list))
self.selection(len(self.Money_Element_list)-1,self.inital_page)
def money_track_remover(self):
self.button_instance.destroy()
self.Money_Element_list[self.index_of_selected_element]="removed"
self.element_name.delete(0,ctk.END)
def Save_changes_in_element_name(self,*args):
if self.button_instance.cget("text") != self.element_name.get():
if len(self.element_name.get())>20:
Notification(text="Too long name reduce it, (max:20)",window=self.window)
return 0
elif len(self.element_name.get()) <3:
Notification(text="Too Short name Increase it, (min:3)",window=self.window)
return 0
elif any(char in self.element_name.get() for char in['<', '>', ':', '"', '/', '\\', '|', '?', '*','.']):
Notification(text="PLz dont keep character like <, >, :, \", /, \\, |, ?, *, . and others",window=self.window)
return 0
else:
self.button_instance.configure(text=self.element_name.get())
return 1
def selection(self,index_of_element,inital_page_self):
try:
if self.element_name.get() != "":
self.Save_changes_in_element_name()
except AttributeError:pass
self.index_of_selected_element= index_of_element
for i in range(len(self.Money_Element_list)):
if self.Money_Element_list[i] == "removed":
pass
else:
self.Money_Element_list[i].configure(border_width=0,text_color="White",fg_color="#739072")
self.button_instance=self.Money_Element_list[index_of_element]
self.button_instance.configure(border_color="RED", border_width=2,text_color="black",fg_color="green")
self.element_name=inital_page_self.elements_name
self.element_name.delete(0,ctk.END)
self.element_name.insert(ctk.END, self.button_instance.cget("text"))
def button_structure(self,text,inital_page_self,index_of_element):
new_btn=ctk.CTkButton(inital_page_self.money_track_adder_frame,
text=text,
fg_color="#739072",
hover_color="green",
cursor="hand2",
command=lambda :self.selection(index_of_element,inital_page_self)
)
new_btn.pack(side="right",padx=5)
self.Money_Element_list.append(new_btn)
def Go_checker(self,*args):
if not self.directory_path:
Notification(self.window,f"Plz select the \"Folder\" !!!", "red",6)
elif not self.inital_page.Name_user.get():
Notification(self.window,f"Plz Fill the \"Name\" !!!", "red",6)
elif self.index_of_selected_element<1:
Notification(self.window,f"Plz provide atleast 2 Money Tracking Element !!!", "red",6)
else:
self.main_folder_name=f"{self.directory_path}/Money Manager"
i=0
while(os.path.exists(self.main_folder_name)):
i+=1
self.main_folder_name= f"{self.directory_path}/Money Manager{i}"
self.config.set("FILE_LOCATION", "setup_user_name", self.inital_page.Name_user.get())
self.config.set("FILE_LOCATION", "location", self.main_folder_name)
self.elements_for_money_track=[]
for element in self.Money_Element_list:
if element =="removed":
pass
else:
self.elements_for_money_track.append(element.cget("text"))
self.config.set("FILE_LOCATION","elements_for_money_track",','.join(self.elements_for_money_track))
self.config.set("Keywords","Keywords",','.join(self.elements_for_money_track))
for Each_element in self.elements_for_money_track:
Each_element= "_".join(Each_element.split(" "))
self.config[Each_element]={
f"{Each_element}_amounts":0,
f"{Each_element}_last_month":0,
f"{Each_element}_code":0,
}
with open(self.window.setting_ini_path,"w") as f:
self.config.write(f)
self.inital_page.destroy()
self.create_files()
Backend_First_page(self.window)
def create_files(self):
current_date=time.strftime("%Y_%m")
os.makedirs(self.main_folder_name, exist_ok=True)
for each_name in self.elements_for_money_track:
Each_element_folder=f"{self.main_folder_name}/{each_name}"
os.makedirs(Each_element_folder,exist_ok=True)
wb=openpyxl.Workbook()
ws=wb.active
ws.title=each_name
ws.append(["SN","Date","Keywords","Reason","Income","Expences"])
row=(tuple(ws.rows))
for each_column in row[0]:
each_column.font=Font(bold=True)
wb.save(f"{Each_element_folder}\\{each_name}'s tranjaction of {current_date}.xlsx")
# for rent file
os.makedirs(f"{self.main_folder_name}/Loan",exist_ok=True)
class Inital_page(ctk.CTkFrame):
def __init__(self,window,Backend_0th_page,):
super().__init__(window)
self.pack(fill="both",expand=True)
self.window= window
ctk.CTkLabel(self,text="Money Manager",
font=ctk.CTkFont("Showcard Gothic Regular", 40, "bold")
).place(relx=.15,rely=.02,relwidth=.7)
selection_frame= ctk.CTkFrame(self,fg_color="#D2E3C8")
selection_frame.place(relx= .08, rely = .14 ,relwidth= .84,relheight=.8)
ctk.CTkLabel(selection_frame,text="Setup Page",
text_color="#4F6F52",
font=ctk.CTkFont("Agency fb", 30, "bold")
).place(relx=.15,rely=0,relwidth=.7)
selection_inner_frame= ctk.CTkFrame(selection_frame,fg_color="#739072",corner_radius=10)
selection_inner_frame.place(relx= .08, rely = .1 ,relwidth= .84,relheight=.84)
ctk.CTkLabel(selection_inner_frame,
text_color="#000000",
text="Select the folder to save your Data",
font=ctk.CTkFont("Agency fb", 25,)
).place(relx=.02,rely=.04,relwidth=.96,)
#select button
self.selection_btn=ctk.CTkButton(selection_inner_frame,
cursor="hand2",
hover_color="green",
text="Selected Document Path",
border_color="#D2DE32",
fg_color="green",
border_width=3,
command=Backend_0th_page.database_folder_selector,
)
self.selection_btn.place(relx=.3,rely=.16,relheight=.1)
#name label
ctk.CTkLabel(selection_inner_frame,
text="Name: ",
text_color="#000000",
font=ctk.CTkFont("cambria math", 20,)
).place(relx=.06,rely=.2)
self.Name_user=ctk.CTkEntry(selection_inner_frame,
fg_color="white",
text_color="black",
corner_radius=10
)
self.Name_user.place(relx= .25,rely=.315,relwidth=.68)
ctk.CTkLabel(selection_inner_frame,
text_color="#000000",
text="ADD Element to Track Money on :",
font=ctk.CTkFont("Agency fb", 22,)
).place(relx=.02,rely=.43,relwidth=.96)
self.elements_name=ctk.CTkEntry(selection_inner_frame,fg_color="white",text_color="black")
self.elements_name.place(relx=.16,rely=.54,relwidth=.4)
ctk.CTkButton(selection_inner_frame,text="➕",
fg_color="Dark green",
hover_color="#4F6F52",
cursor="hand2",
command=Backend_0th_page.money_track_adder ,
).place(relx=.58,rely=.54,relwidth=.1)
ctk.CTkButton(selection_inner_frame,text="➖",
fg_color="red",
hover_color="#FF0060",
cursor="hand2",
command=Backend_0th_page.money_track_remover,
).place(relx=.7,rely=.54,relwidth=.1)
ctk.CTkButton(selection_inner_frame,text="✔",
fg_color="blue",
hover_color="#711DB0",
cursor="hand2",
command=Backend_0th_page.Save_changes_in_element_name,
).place(relx=.82,rely=.538,relwidth=.1)
self.money_track_adder_frame=ctk.CTkScrollableFrame(selection_inner_frame,
orientation="horizontal",
fg_color="#4F6F52",
scrollbar_button_color="black",
scrollbar_button_hover_color="#010A43")
self.money_track_adder_frame.place(relx=.04,rely=.64,relwidth=.92,relheight=.23)
#button structure
Backend_0th_page.button_structure("Hand Cash",self,0)
Backend_0th_page.selection(0,self)
ctk.CTkButton(selection_inner_frame,
text="Go..",
fg_color="#4F6F52",
cursor="star",
hover_color="green",
border_color="yellow",
border_width=1,
command=Backend_0th_page.Go_checker
).place(relx= .4,rely=.88,relheight=.1,relwidth=.2)
#binding.........
self.window.bind("<Control-s>",Backend_0th_page.Go_checker)
self.elements_name.bind("<Return>",Backend_0th_page.money_track_adder)
class Backend_First_page():
def __init__(self,window):
self.window=window
self.config=configparser.ConfigParser()
self.config.read(self.window.setting_ini_path)
self.elements=(self.config.get("FILE_LOCATION","elements_for_money_track")).split(",")
self.window.User_Name.set(self.config.get("FILE_LOCATION","setup_user_name"))
self.change_datetime()
self.first_page=First_page(self.window)
self.Button_structure(("Check","Loan"))
for i in range(0,len(self.elements),2):
if i== len(self.elements)-1:
self.Button_structure([self.elements[i]],side="bottom")
else:
self.Button_structure((self.elements[i],self.elements[i+1]))
def change_datetime(self):
current_time_struct = time.localtime()
formatted_time = time.strftime("%Y/%m/%d, %I:%M %p", current_time_struct)
self.window.current_date_var.set(formatted_time)
def Button_structure(self,texts,side="left"):
button_frame=ctk.CTkFrame(self.first_page.Tranjestion_btn_frame,fg_color="#D2E3C8")
button_frame.pack(side="top",pady=10,padx=25,fill="x")
for text in texts:
ctk.CTkButton(button_frame,
text=text,
fg_color="#4F6F52",
text_color="white",
hover_color="#739072",
cursor="hand2",
command=lambda t=text:self.Layout_caller(t),
) .pack(pady=10,padx=10,anchor="center",side=side)
def Layout_caller(self,transaction_name):
self.first_page.destroy()
if transaction_name == "Check":
Check_Layout_page_1st(self.window,)
elif transaction_name == "Loan":
Loan_BackEnd(self.window)
else:
Layout_Transaction_book(self.window,transaction_name)
class First_page(ctk.CTkFrame):
def __init__(self,window):
super().__init__(window)
self.pack(fill="both",expand=True)
self.window= window
ctk.CTkLabel(self,text="Money Manager",
font=ctk.CTkFont("Showcard Gothic Regular", 40, "bold")
).place(relx=.15,rely=.04,relwidth=.7)
self.Tranjestion_btn_frame= ctk.CTkScrollableFrame(self,fg_color="#D2E3C8")
self.Tranjestion_btn_frame.place(relx=.1,rely=.18,relheight=.48,relwidth=.8)
self.info_box= ctk.CTkFrame(self,fg_color="#739072")
self.info_box.place(relx=.173,rely=.7,relheight=.25,relwidth=.66)
#User_Name
ctk.CTkLabel(self.info_box,text=self.window.User_Name.get()).pack(anchor="center",pady=6,fill="x",padx=10)
ctk.CTkLabel(self.info_box,
text=f"Date: {self.window.current_date_var.get()}"
).pack(anchor="center",fill="x",pady=3,padx=10)
self.Ui_mode_on =True
self.MOde_btn=ctk.CTkButton(self.info_box, text="Trun OFF Ui Mode",fg_color="#4F6F52",hover_color="green", corner_radius=12, cursor="hand2",
command=self.change_ui_mode,
)
self.MOde_btn.place(relx=.3,rely=.6, relwidth= .4)
self.config=configparser.ConfigParser()
self.config.read(self.window.setting_ini_path)
def change_ui_mode(self,):
vaid_to_change=False
if self.Ui_mode_on:
result = messagebox.askyesno("Confirmation", "Do you want to Enable Command line Mode?")
if result:
vaid_to_change=True
self.Ui_mode_on=False
self.MOde_btn.configure(text="Trun On Ui Mode")
self.config.set("Ui_mode","ui_mode","False")
else:
result = messagebox.askyesno("Confirmation", "Do you want to Enable Ui Mode Again?")
if result:
vaid_to_change=True
self.Ui_mode_on=True
self.MOde_btn.configure(text="Trun OFF Ui Mode")
self.config.set("Ui_mode","ui_mode","True")
if vaid_to_change:
with open(self.window.setting_ini_path,'w') as file:
self.config.write(file)
pass
pass
class Check_Layout_page_1st(ctk.CTkFrame):
def __init__(self,window,):
super().__init__(window)
self.pack(fill="both",expand=True)
self.window= window
ctk.CTkLabel(self,text="Money Manager",
font=ctk.CTkFont("Showcard Gothic Regular", 40, "bold")
).place(relx=.15,rely=.03,relwidth=.7)
# back_btn
ctk.CTkButton(self,text="↩",cursor="hand2",
font=ctk.CTkFont(family="Elephant",size=30),
fg_color="Blue",text_color="white",
command=self.GetBack).place(relx=.04,rely=.05,relheight=.07,relwidth=.1)
self.AllElement_frame= ctk.CTkScrollableFrame(self,fg_color="#739072")
self.AllElement_frame.place(relx=.1,rely=.14,relheight=.3,relwidth=.8)
self.config=configparser.ConfigParser()
self.config.read(self.window.setting_ini_path)
self.elements=(self.config.get("FILE_LOCATION","elements_for_money_track")).split(",")
ctk.CTkLabel(self.AllElement_frame,text="Current Total Balance On:",
font=ctk.CTkFont("Showcard Gothic Regular", 20, "bold")
).pack(pady=5,anchor="center")
for each_element in self.elements:
solid_trans_name = "_".join(each_element.split(" "))
amount = float(self.config.get(solid_trans_name, f"{solid_trans_name}_amounts"))
element_line_frame=ctk.CTkFrame(self.AllElement_frame,height=30)
element_line_frame.pack(pady=6,padx=5,fill="x")
ctk.CTkLabel(element_line_frame,text=each_element,
corner_radius=0
).place(relx=.02,rely=0,relwidth=.4)
ctk.CTkLabel(element_line_frame,text=round(amount,4),
).place(relx=.44,rely=0,relwidth=.3,)
ctk.CTkButton(element_line_frame,
text="See Details",
fg_color="#4F6F52",
hover_color="#4F6F52",
cursor="hand2",
command=lambda elem= each_element: self.see_detailes(elem)
).place(relx=.75,rely=0.1,relwidth=.23,relheight=.8)
element_line_frame=ctk.CTkFrame(self.AllElement_frame,height=30)
element_line_frame.pack(pady=6,padx=5,fill="x")
ctk.CTkButton(element_line_frame,text="Click here to See Loan Detailes",
fg_color="#4F6F52",
hover_color="#31304D",
cursor="hand2",
corner_radius=10,
command=self.loan_label_box_display
).place(relx=.2,rely=0.15,relheight=.7,relwidth=.6)
self.treeView_strucutre()
def loan_label_box_display(self):
self.destroy()
Loan_check_page_2nd(self.window)
def treeView_strucutre(self):
self.Tranjestion_btn_frame= ctk.CTkFrame(self,fg_color="#739072")
self.Tranjestion_btn_frame.place(relx=.1,rely=.47,relheight=.5,relwidth=.8)
selector_frame=ctk.CTkFrame(self.Tranjestion_btn_frame, fg_color= "transparent")
selector_frame.place(relx= .05,rely=.05,relheight=.13,relwidth=.9)
self.ElementOptions=ctk.CTkOptionMenu(selector_frame,values=self.elements,
corner_radius=10,cursor="hand2",
command=self.OPtion_changed)
self.ElementOptions.place(relx=0,rely=.0,relwidth=.34)
self.button_30Day=ctk.CTkButton(selector_frame,text="30",cursor="hand2",text_color="black",hover_color='pink',
command=lambda :self.selectdays(30,self.button_30Day))
self.button_30Day.place(relx=.38,rely=.0,relwidth=.1,)
self.button_60Day=ctk.CTkButton(selector_frame,text="60",cursor="hand2",fg_color="#1A5D1A",text_color="black",hover_color='pink',
command=lambda :self.selectdays(60,self.button_60Day))
self.button_60Day.place(relx=.5,rely=.0,relwidth=.1,)
self.button_90Day=ctk.CTkButton(selector_frame,text="90",cursor="hand2",fg_color="#1A5D1A",text_color="black",hover_color='pink',
command=lambda :self.selectdays(90,self.button_90Day))
self.button_90Day.place(relx=.62,rely=.0,relwidth=.1,)
self.days_button=[self.button_30Day,self.button_60Day,self.button_90Day]
# Filter
ctk.CTkButton(selector_frame,text="Filter",
cursor="hand2",
command=self.filter_Box).place(relx=.75,rely=.0,relwidth=.2,)
# Tree view starts
self.Transaction_info_frame= ctk.CTkScrollableFrame(self.Tranjestion_btn_frame,orientation="horizontal",corner_radius=0)
self.Transaction_info_frame.place(relx=0,rely=.2,relheight=.8,relwidth=1)
style = ttk.Style()
style.configure("Treeview", font=("Times Roman",13), background="#E9EDC9")
columns = ['SN', 'Date', 'Reason', 'Income', 'Expenses']
self.treeview = ttk.Treeview(self.Transaction_info_frame, columns=columns, show='headings', selectmode='extended')
self.treeview.pack(expand=True,fill="both")
self.treeview.column('SN', width=40)
self.treeview.column('Date', width=110)
self.treeview.column('Reason', width=320,anchor=tk.CENTER)
self.treeview.column('Income', width=90,anchor=tk.CENTER)
self.treeview.column('Expenses', width=90,anchor=tk.CENTER)
for col in columns:
self.treeview.heading(col, text=col)
heading_font = ('Arial', 15, 'bold')
style.configure("Treeview.Heading", background="#e1e1e1", font=heading_font)
style.layout("Treeview", [('Treeview.treearea', {'sticky': 'nswe'})])
style.configure("Treeview.Treearea", background="#333", foreground="white")
self.selectdays(30,self.button_30Day)
def OPtion_changed(self,*args):
self.selectdays(30,self.button_30Day)
def see_detailes(self,element):
self.ElementOptions.set(element)
self.selectdays(30,self.button_30Day)
def selectdays(self,day,button_instance):
for each_btn in self.days_button:
if each_btn == button_instance:
each_btn.configure(fg_color="#A4D0A4",border_color="#DF2E38",border_width=2)
self.selected_Days_at_time=day
else:
each_btn.configure(border_width=0,fg_color="#1A5D1A")
self.fill_treeview_with_data(day, None)
def fill_treeview_with_data(self,day, _Dates_):
transaction_name=self.ElementOptions.get()
solid_trans_name = "_".join(transaction_name.split(" "))
File_path=[]
directory_path = self.config.get("FILE_LOCATION", "location")
if _Dates_== "random_dates":
last_month= self.Last_date.strftime("%m")
all_then_end_date= self.Last_date
else:
last_month =(self.config.get(solid_trans_name, f"{solid_trans_name}_last_month"))
all_then_end_date= (datetime.now()).replace(hour=0, minute=0, second=0, microsecond=0)
for caller in range(math.ceil(day/30)):
date_op=(all_then_end_date-timedelta(days=int((caller)*30)))
front_file_path=f"{directory_path}/{transaction_name}/{transaction_name}'s tranjaction of {date_op.strftime('%Y')}"
File_path.append(f"{front_file_path}_{date_op.strftime('%m')}.xlsx")
All_Rows=[]
for index,each_path in enumerate(File_path):
try:
Wb = openpyxl.load_workbook(each_path)
ws = Wb.active
RowS= list(ws.rows)
date_op=(all_then_end_date-timedelta(days=int((index)*30)))
RowS[0]=(">>","Info of",f"{date_op.strftime('%Y')}, {month_name[int(date_op.strftime('%m'))]}","")
All_Rows=All_Rows+RowS
except:pass
self.treeview.delete(*self.treeview.get_children())
for each_cell in All_Rows:
valued_cell=[]
if each_cell[1]=="Info of":
self.treeview.insert("", "end", values=[])
valued_cell=each_cell
elif str(each_cell[1].value)[0:5] == "Month":
valued_cell.extend(each_val.value for each_val in each_cell)
valued_cell.pop(2)
else:
if _Dates_ == "random_dates":
d_a_y=(each_cell[1].value).split(",")[0]
each_cells_date= datetime(int(time.strftime('%Y')), int(last_month), int(d_a_y), 0,0,0)
if self.First_date <= each_cells_date <= self.Last_date:
for each_vlaue in each_cell:
valued_cell.append(each_vlaue.value)
valued_cell.pop(2)
else:
for each_vlaue in each_cell:
valued_cell.append(each_vlaue.value)
valued_cell.pop(2)
self.treeview.insert("", "end", values=valued_cell)
def filter_Box(self):
self.filter_frame=ctk.CTkFrame(self,fg_color="#3e3838")
self.filter_frame.place(relx=.125,rely=.12,relwidth=.75,relheight=.76)
# vars
present_date = datetime.now()
self.given_month_ago = present_date - timedelta(days=self.selected_Days_at_time)
self.calendarBox_displayed=False
ctk.CTkLabel(self.filter_frame,text=":: Filter ::",text_color="black",
fg_color="#8fba9c",
corner_radius=10,
font=ctk.CTkFont("chiller", 30,"bold")).place(relx=.3,relwidth=.4,rely=.03,)
ctk.CTkButton(self.filter_frame,text="X",fg_color="red",hover_color="#B80000",
command= self.filter_frame.destroy,
).place(relx=.8,rely=.03,relwidth=.18,relheight=.05)
self.ElementOption2=ctk.CTkOptionMenu(self.filter_frame,values=self.elements,
corner_radius=10,cursor="hand2",
command= lambda *args: self.filter_selection_keeper(['no'])
)
self.ElementOption2.place(relx=.25,rely=.15,relwidth=.5)
self.Frame_of_search_Function()
self.Frame_Of_date_Function()
self.apply_btn=ctk.CTkButton(self.filter_frame,cursor="hand2", text="Apply",fg_color="#7F27FF", hover_color="#9F70FD", command= self.filter_apply_func)
self.apply_btn.place(relx=.32,rely=.92)
def date_validate_input(self,char):
if char == '' :
return True
if (char[-1:]).isdigit() or (char[-1:]) == '-' :
if len(char) <= 10:
return True
return False
def Frame_of_search_Function(self):
outer_frame=ctk.CTkFrame(self.filter_frame, fg_color="grey")
outer_frame.place(relx=.05,rely=.23,relwidth=.9,relheight= .1)
self.Search_field= ctk.CTkEntry(outer_frame)
self.Search_field.place(relx=.02,rely=.05,relheight=.9,relwidth=.8)
search_btn=ctk.CTkButton(outer_frame,text="🔍", cursor="hand2",fg_color="green",
text_color="blue",
hover_color="light green", font=ctk.CTkFont("chiller", 20,"bold"))
self.Search_field.place(relx=.02,rely=.05,relheight=.9,relwidth=.8)
pass
def Frame_Of_date_Function(self):
# date_frame
outer_date_frame= ctk.CTkFrame(self.filter_frame,fg_color="transparent")
outer_date_frame.place(relx=.035,rely=.35,relwidth=.93,relheight=.55)
self.scroll_date_frame=ctk.CTkScrollableFrame(outer_date_frame,fg_color="#9ad1aa", corner_radius=0)
self.scroll_date_frame.pack(expand=True, fill="both")
date_frame_up_part= ctk.CTkFrame(self.scroll_date_frame,fg_color="#9ad1aa",corner_radius=0,height=85)
date_frame_up_part.pack(fill= "x")
ctk.CTkLabel(date_frame_up_part,text="Select Date",font=ctk.CTkFont("Bauhaus 93", 25),text_color="black").place(relx=.32,rely=.02)
ctk.CTkLabel(date_frame_up_part,text="Start Date:",font=ctk.CTkFont("Times Roman", 20),text_color="black").place(relx=.08,rely=.3,)
ctk.CTkLabel(date_frame_up_part,text="End Date:" ,font=ctk.CTkFont("Times Roman", 20),text_color="black").place(relx=.55,rely=.3,)
start_frame = ctk.CTkFrame(date_frame_up_part,fg_color="#BBE2EC")
start_frame.place(relx=.08, rely=.66, relwidth=.4, relheight=.26)
self.start_entry = ctk.CTkEntry(start_frame,corner_radius=0,fg_color="#0A0A0A",border_color="white")
self.start_entry.place(relx= 0,rely=0, relheight=1, relwidth=.85)
ctk.CTkButton(start_frame, text="📅", corner_radius=0,
fg_color="#BBE2EC",text_color="blue",hover_color="white",
cursor="hand2",font=('Arial', 20) ,
command=lambda :self.show_calendar("S"),
).place(relx= .85,rely=0, relheight=1, relwidth=.15)
self.start_label= ctk.CTkLabel(date_frame_up_part,text="",fg_color="#1A5D1A")
end_frame = ctk.CTkFrame(date_frame_up_part,fg_color="#BBE2EC")
end_frame.place(relx=.55,rely=.66,relwidth=.4,relheight=.26)
self.end_entry = ctk.CTkEntry(end_frame,corner_radius=0,fg_color="#0A0A0A",border_color="white")
self.end_entry.place(relx= 0,rely=0, relheight=1, relwidth=.85)
ctk.CTkButton(end_frame, text="📅", corner_radius=0,
fg_color="#BBE2EC",text_color="blue",hover_color="white",
cursor="hand2",font=('Arial', 20) ,
command=lambda :self.show_calendar("E"),
).place(relx= .85,rely=0, relheight=1, relwidth=.15)
self.end_label= ctk.CTkLabel(date_frame_up_part,text="",fg_color="#1A5D1A")
# Validate input and call on_entry_change when the content changes
validate_cmd = (date_frame_up_part.register(self.date_validate_input),"%P")
self.start_entry.configure(validate="key", validatecommand=(validate_cmd))
self.end_entry.configure(validate="key", validatecommand=(validate_cmd))
self.start_entry.bind("<Return>",self.entry_field_changed)
self.end_entry.bind("<Return>",self.entry_field_changed)
self.date_frame_mid_part= ctk.CTkFrame(self.scroll_date_frame,fg_color="transparent",corner_radius=0,)
self.calendarBox = Calendar(self.date_frame_mid_part, borderwidth=2, font=('Agency fb', 14,"bold"),
year=int(self.given_month_ago.strftime("%Y")), month=int(self.given_month_ago.strftime("%m")), day=int(self.given_month_ago.strftime("%d")),
background ="#1A5D1A",
selectbackground='#00cc00', selectforeground='black',
firstweekday="sunday",
showothermonthdays =False,weekenddays=[7,7],
normalbackground='white', normalforeground='black',
weekendbackground='white', weekendforeground='black',
headersbackground='black', headersforeground='white',
date_pattern='yyyy-mm-dd',
width=400, height=300
)
self.calendarBox.pack(expand=True, fill="both",padx=30)
ctk.CTkButton(self.date_frame_mid_part,text="X",fg_color="red",hover_color="#B80000",
corner_radius=0,
command=self.cross_cal,
).place(relx=.94,rely=.03,relwidth=.06,relheight=.1)
# calendar var
self.First_date=self.given_month_ago.replace(hour=0, minute=0, second=0, microsecond=0)
self.Last_date=datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
self.start_entry.insert(ctk.END,self.First_date.strftime("%Y-%m-%d"))
self.end_entry.insert(ctk.END,self.Last_date.strftime("%Y-%m-%d"))
self.date_frame_down_part= ctk.CTkFrame(self.scroll_date_frame,fg_color="#9ad1aa",corner_radius=0,height=40)
self.date_frame_down_part.pack(expand=True,fill= "x")
b30=ctk.CTkButton(self.date_frame_down_part,text="30",cursor="hand2",fg_color="#1A5D1A",
text_color="black",hover_color='pink',
command=lambda :self.filter_selection_keeper([30,b30])
)
b30.place(relx=.3,rely=.1,relwidth=.1,)
b60=ctk.CTkButton(self.date_frame_down_part,text="60",cursor="hand2",fg_color="#1A5D1A",text_color="black",hover_color='pink',
command=lambda :self.filter_selection_keeper([60,b60])
)
b60.place(relx=.45,rely=.1,relwidth=.1,)
b90=ctk.CTkButton(self.date_frame_down_part,text="90",cursor="hand2",fg_color="#1A5D1A",text_color="black",hover_color='pink',
command=lambda :self.filter_selection_keeper([90,b90])
)
b90.place(relx=.6,rely=.1,relwidth=.1,)
self.btn_list2=[b30,b60,b90]
self.filter_selection_keeper([self.selected_Days_at_time,self.btn_list2[int(self.selected_Days_at_time/30-1)]])
def entry_field_changed(self, *args):
valid_to_change=False
First_date_= self.start_entry.get().split("-")
End_date_= self.end_entry.get().split("-")
try:
F_year,F_month,F_day=First_date_[0],First_date_[1],First_date_[2]
E_year,E_month,E_day=End_date_[0],End_date_[1],End_date_[2]
First_date_= datetime(year=int(F_year), month=int(F_month), day=int(F_day))
End_date_= datetime(year=int(E_year), month=int(E_month), day=int(E_day))
valid_to_change= True
except ValueError as error:
valid_to_change= False
if str(error) == "invalid literal for int() with base 10: ''":
error= "The Structure is Not Accepted as Date format"
valid_to_change= "Change"
Notification(self.window,error)
except IndexError as error:
valid_to_change="Change"
Notification(self.window, "Plz make sure to full fill your Date format {Y-M-D}")
if valid_to_change == "Change":
self.start_entry.delete(0, ctk.END)
self.end_entry.delete(0, ctk.END)
self.start_entry.insert(ctk.END,self.First_date.strftime("%Y-%m-%d"))
self.end_entry.insert(ctk.END,self.Last_date.strftime("%Y-%m-%d"))
elif valid_to_change == True:
self.First_date= First_date_
self.Last_date= End_date_
try:
rnads=self.start_or_end
self.reStructure_cal_box()
except:
pass
def cross_cal(self):
self.date_frame_mid_part.pack_forget()
self.start_entry.configure(fg_color="#0A0A0A",border_color="white")
self.start_label.place_forget()
self.end_entry.configure(fg_color="#0A0A0A",border_color="white")
self.end_label.place_forget()
def show_calendar(self,start_OR_end):
self.start_or_end=start_OR_end
try:
if last_called_from == start_OR_end:
if self.calendarBox_displayed:
self.calendarBox_displayed=False
else:
self.calendarBox_displayed=True
else:
last_called_from=start_OR_end
except UnboundLocalError:
self.calendarBox_displayed=True
last_called_from=start_OR_end
self.calender_design_look()
self.reStructure_cal_box()
self.date_frame_down_part.pack_forget()
self.date_frame_mid_part.pack(fill="both", expand=True)
self.date_frame_down_part.pack(expand=True,fill= "x")
self.calendarBox.configure(tooltipdelay =0,tooltipalpha=0)
self.calendarBox.bind("<<CalendarSelected>>", self.new_date_selected)
self.window.after(20, lambda: self.scroll_date_frame._parent_canvas.yview("scroll",-100, "units"))
self.window.after(20, lambda: self.scroll_date_frame._parent_canvas.yview("scroll",66, "units"))
def calender_design_look(self):
if self.start_or_end =="S":
self.calendarBox.calevent_remove("all")
self.start_entry.configure(fg_color="#1A5D1A",border_color="#167016")
self.start_label.place(relx=.08, rely=.92,relwidth=.4, relheight=.08)
self.end_entry.configure(fg_color="#0A0A0A",border_color="white")
self.end_label.place_forget()
else:
self.end_entry.configure(fg_color="#1A5D1A",border_color="#167016")
self.end_label.place(relx=.55, rely=.92,relwidth=.38, relheight=.08)
self.start_entry.configure(fg_color="#0A0A0A",border_color="white")
self.start_label.place_forget()
def reStructure_cal_box(self):
start,end=self.First_date, self.Last_date
self.calendarBox.calevent_remove("all")
self.calendarBox.tag_config("custom_tag", foreground="black", background="#E9EDC9")
self.calendarBox.tag_config("selected_date_tag", foreground="black", background="#00cc00")
# from start being called
if end != None:
self.start_entry.delete(0, ctk.END)
self.end_entry.delete(0, ctk.END)
self.start_entry.insert(ctk.END,self.First_date.strftime("%Y-%m-%d"))
self.end_entry.insert(ctk.END,self.Last_date.strftime("%Y-%m-%d"))
while start <= end:
event_id = self.calendarBox.calevent_create(start,text="", tags=["event_tag","custom_tag"], )
if (start == end):
self.calendarBox.calevent_configure(event_id, tags=["event_tag","selected_date_tag"],text="Selected End date")
if event_id == 0:
self.calendarBox.calevent_configure(event_id, tags=["event_tag","selected_date_tag"],text="Selected Start date")
start += timedelta(days=1)
if self.start_or_end =="S":
self.calendarBox.selection_set(self.First_date.strftime("%Y-%m-%d"))
else:
self.calendarBox.selection_set(self.Last_date.strftime("%Y-%m-%d"))
def new_date_selected(self,event):
for each_btn in self.btn_list2:
each_btn.configure(border_width=0,fg_color="#1A5D1A")
self.No_spefic_date=True
if self.start_or_end =="S":
self.apply_btn.configure(state="disabled")
self.First_date=datetime.combine((self.calendarBox.selection_get()), datetime.min.time())
self.calendarBox.calevent_remove("all")
self.Last_date=None
self.start_or_end= 'E'
self.calender_design_look()
self.calendarBox.selection_set(self.First_date.strftime("%Y-%m-%d"))
self.start_entry.delete(0, ctk.END)
self.end_entry.delete(0, ctk.END)
self.start_entry.insert(ctk.END,self.First_date.strftime("%Y-%m-%d"))
self.end_entry.insert(ctk.END,"0000-00-00")
else:
self.apply_btn.configure(state="enabled",cursor="hand2",)
self.Last_date=datetime.combine((self.calendarBox.selection_get()), datetime.min.time())
if self.First_date<self.Last_date:
self.calendarBox.selection_set(self.Last_date.strftime("%Y-%m-%d"))
self.show_calendar('S')
self.end_entry.delete(0, ctk.END)
self.end_entry.insert(ctk.END,self.Last_date.strftime("%Y-%m-%d"))
else:
self.start_or_end='S'
self.new_date_selected("")
def filter_selection_keeper(self,days0Relement):
self.No_spefic_date=False
if type(days0Relement[0]) is int:
for each_btn in self.btn_list2:
if each_btn == days0Relement[1]:
each_btn.configure(fg_color="#A4D0A4",border_color="#DF2E38",border_width=2)
self.select_Days_PARAMERTERS=[days0Relement[0],self.days_button[int(days0Relement[0]/30)-1]]
else:
each_btn.configure(border_width=0,fg_color="#1A5D1A")
day_total= days0Relement[0]
else:
# self.selectdays(30,self.button_30Day)
day_total=30
if self.calendarBox_displayed:
self.First_date = (datetime.now()- timedelta(days=day_total)).replace(hour=0, minute=0, second=0, microsecond=0)
self.Last_date = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
self.start_or_end="S"
self.calender_design_look()
self.reStructure_cal_box()
def filter_apply_func(self):
self.filter_frame.destroy()
self.ElementOptions.set(self.ElementOption2.get())
if self.No_spefic_date:
for each_btn in self.days_button:
each_btn.configure(border_width=0,fg_color="#1A5D1A")
self.fill_treeview_with_data(int((self.Last_date-self.First_date).days), "random_dates")
else:
self.selectdays(self.select_Days_PARAMERTERS[0],self.select_Days_PARAMERTERS[1])
def GetBack(self):
self.destroy()
WinBackEnd(self.window)
pass
class Loan_check_page_2nd(ctk.CTkFrame):
def __init__(self,window,):
super().__init__(window)
self.pack(fill="both",expand=True)
self.window= window
ctk.CTkLabel(self,text="Money Manager",
font=ctk.CTkFont("Showcard Gothic Regular", 40, "bold")
).place(relx=.15,rely=.03,relwidth=.7)
# back_btn
ctk.CTkButton(self,text="↩",cursor="hand2",
font=ctk.CTkFont(family="Elephant",size=30),
fg_color="Blue",text_color="white",
command=self.GetBack).place(relx=.04,rely=.05,relheight=.07,relwidth=.1)
# Variables
self.Drop_down_options=['All Transaction','Loan Given', 'Loan Recived', 'Not Paid OverDue',"Paid Back Trans"]
self.upper_section()
self.down_section()
def upper_section(self):
self.AllTangent_list_frame= ctk.CTkScrollableFrame(self,fg_color="#739072")
self.AllTangent_list_frame.place(relx=.05,rely=.14,relheight=.3,relwidth=.9)
self.config=configparser.ConfigParser()
self.config.read(self.window.setting_ini_path)
self.all_loan_tangents_list= (self.config.get("Loan", "tangents")).split(",")
if self.all_loan_tangents_list[0]!='':
self.No_trans_yet=False
self.all_loan_tangents_list= (self.config.get("Loan", "tangents")).split(",")
element_line_frame=ctk.CTkFrame(self.AllTangent_list_frame,height=27,corner_radius=0)
element_line_frame.pack(fill="x")
ctk.CTkLabel(element_line_frame,text="Tangent Names",
corner_radius=0
).place(relx=.02,rely=0,relwidth=.37)
ctk.CTkLabel(element_line_frame,text="Amt To Give ",
).place(relx=.404,rely=0,relwidth=.2,)
ctk.CTkLabel(element_line_frame,text="Amt To Take",
).place(relx=.608,rely=0,relwidth=.2,)
self.detailesBtn=[]
index=0
for each_tangent in self.all_loan_tangents_list:
solid_tangent_name = "_".join(each_tangent.split(" "))
try:
amount = float(self.config.get("Loan", f"{solid_tangent_name}_amt"))
if amount >= 0:
take_amt= amount
give_amt=0
elif amount< 0:
take_amt= 0
give_amt=amount
element_line_frame=ctk.CTkFrame(self.AllTangent_list_frame,height=30)
element_line_frame.pack(pady=6,padx=5,fill="x")
ctk.CTkLabel(element_line_frame,text=each_tangent,fg_color="#555555",
corner_radius=4
).place(relx=0.005,rely=.04,relwidth=.3938)
ctk.CTkLabel(element_line_frame,text=abs(give_amt),fg_color="#555555",
corner_radius=3
).place(relx=.404,rely=.04,relwidth=.2,)
ctk.CTkLabel(element_line_frame,text=abs(take_amt),fg_color="#555555",
corner_radius=3
).place(relx=.608,rely=.04,relwidth=.2,)
see_btn=ctk.CTkButton(element_line_frame,
text="See Details",
fg_color="#4F6F52",
hover_color="#4F6F52",
cursor="hand2",
border_color="red",
border_width=0,
command=lambda elem= [solid_tangent_name,index]: self.see_detailes(elem)
)
see_btn.place(relx=.81,rely=0.1,relwidth=.18,relheight=.8)