-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_diagram_place.py
136 lines (113 loc) · 4.28 KB
/
show_diagram_place.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
import matplotlib.pyplot as plt
import tkinter as tk
from tkcalendar import DateEntry
import variable
import search_date
from tkinter import messagebox
import search_expense
class PlaceShow:
def __init__(self) -> None:
"""this class shows a diagram for person in period of time"""
self.win = tk.Tk()
self.win.title('show diagram')
self.win.geometry('300x70')
def translate_time(self, date) -> variable.Date:
"""check if the date exist if not make it and return date object"""
year, month, day = date.split('/')
year, month, day = int(year), int(month), int(day)
date = variable.Date(year, month, day)
sch = search_date.SearchDate()
sch.by_date(date, date)
temp = sch.run()
if len(temp) == 0:
date.add_to_database()
return date
return temp[0]
def read_text(self) -> list:
"""read all tests and return list of them"""
inp = []
inp.append(self.date_from.get())
inp.append(self.date_to.get())
return inp
def reset(self) -> None:
"""clean all Texts"""
self.date_to._set_text(self.date_to._date.strftime(''))
self.date_from._set_text(self.date_from._date.strftime(''))
def data_filter(self) -> list:
"""check if data are correct and return which text are filled """
data = self.read_text()
flag = [0 for _ in range(2)]
for i in range(len(data)):
if data[i] != '':
flag[i] = 1
if flag[0]:
try:
data[0] = self.translate_time(data[0])
except:
messagebox.showerror('date Error', 'the date is not correct')
return [],[]
if flag[1]:
try:
data[1] = self.translate_time(data[1])
except:
messagebox.showerror('date Error', 'the date is not correct')
return [],[]
return data, flag
def search(self) -> list:
"""return expenses that are in the time period"""
data, flag = self.data_filter()
if flag[0] and flag[1]:
days = search_date.SearchDate()
days.by_date(data[0], data[1])
days = days.run()
elif flag[0]:
days = search_date.SearchDate()
days.by_date(date_down=data[0])
days = days.run()
elif flag[1]:
days = search_date.SearchDate()
days.by_date(date_up=data[1])
days = days.run()
else:
days = search_date.SearchDate()
days = days.run()
sch = search_expense.SearchExpense()
sch.by_date(days)
return sch.run()
def show_button(self) -> None:
"""work when client push show button"""
places = dict()
for i in self.search():
i: variable.Expense
place = i.place.name
if place not in places:
places[place] = i.amount
else:
places[place] += i.amount
self.reset()
plt.bar(places.keys(), places.values())
plt.show()
def make_widgets(self) -> None:
"""make widgets"""
x = 0.14
y = 0.18
self.date_from=DateEntry(self.win,selectmode='day',height=1,width=10, date_pattern='yyyy/mm/dd')
self.date_from.configure(validate='none')
self.date_from._set_text(self.date_from._date.strftime(''))
self.date_from.place(relx=x, rely=y, anchor = 'w')
tk.Label(self.win, text='to: ').place(relx=x+0.375, rely=y, anchor = 'center')
self.date_to=DateEntry(self.win,selectmode='day',height=1,width=10, date_pattern='yyyy/mm/dd')
self.date_to.configure(validate='none')
self.date_to._set_text(self.date_to._date.strftime(''))
self.date_to.place(relx=x+0.45, rely=y, anchor = 'w')
exit_ = tk.Button(self.win, text='Exit', command=self.win.destroy)
show_ = tk.Button(self.win, text='Show', command=self.show_button)
show_.place(relx=0.5, rely=0.5)
exit_.place(relx=0.4, rely=0.5)
def run(self)->None:
"""run the window"""
self.make_widgets()
tk.mainloop()
if __name__ == "__main__":
dig = PlaceShow()
dig.run()