-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_window.py
More file actions
272 lines (208 loc) · 10.4 KB
/
main_window.py
File metadata and controls
272 lines (208 loc) · 10.4 KB
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
import tkinter
from tkinter import *
from tkinter.filedialog import askopenfilename, askdirectory, asksaveasfilename, asksaveasfile, askopenfile, \
askopenfiles
from resourses.constants import *
# from main import run
import shelve
import db_helper
import db_viewer
import login
import reports
import raw_query
import search
import custom_widgets
toolbar = None
grid_viewer_toolbar1 = None
main_frame = None
statusbar = None
status_label = None
selected_item_label = None
# shelve.open(writeback=True)
# все загруженные записи будут сохраняться в кэше и автоматически записываться обратно в файл при закрытии хранилища.
def make_menu(root, account):
root_menu = Menu(root)
root.config(menu=root_menu)
file_menu = Menu(root_menu, tearoff=False)
# file_menu.add_command(label='Открыть...', command=do_nothing)
open_menu = Menu(file_menu, tearoff=False)
open_menu.add_command(label='Таблицы...', command=(lambda: db_viewer.run(TABLES, root, account)))
open_menu.add_command(label='Представления...', command=(lambda: db_viewer.run(VIEWS, root, account)))
file_menu.add_cascade(label='Открыть', menu=open_menu)
file_menu.add_separator()
file_menu.add_command(label='Настройки...', command=do_nothing)
file_menu.add_separator()
file_menu.add_command(label='Выход из аккаунта', command=(lambda: login.run(root)))
file_menu.add_command(label='Выход', command=root.quit)
root_menu.add_cascade(label='Файл', menu=file_menu)
report_menu = Menu(root_menu, tearoff=False)
# report_names = db_helper.get_report_names()
# print('REPORT NAMES :', report_names)
# print('get_number_of_kilometers_traveled :', db_helper.get_number_of_kilometers_traveled(2))
# print('get_driver_path_lengths :', db_helper.get_driver_path_lengths())
# print('get_profit_on_period :', db_helper.get_profit_on_period((12, 1, 2015), (12, 4, 2015)))
# print('count_costs_on_company_development :',
# db_helper.count_costs_on_company_development((12, 3, 2015), (13, 3, 2015)))
# print('year_profit_statistics :', db_helper.year_profit_statistics())
report_menu.add_command(label='Сгенерировать...', command=(lambda: reports.run(root, account)))
root_menu.add_cascade(label='Отчет', menu=report_menu)
tools_menu = Menu(root_menu, tearoff=False)
tools_menu.add_command(label='Поиск по соединению таблиц...', command=(lambda: search.run(root, account)))
if account.is_admin():
tools_menu.add_command(label='SQL запрос к базе данных...', command=(lambda: raw_query.make_raw_query(root)))
tools_menu.add_separator()
tools_menu.add_command(label='Статистика', command=(lambda: do_nothing()))
root_menu.add_cascade(label='Инструменты', menu=tools_menu)
help_menu = Menu(root_menu, tearoff=False)
help_menu.add_command(label='Просмотреть справку')
help_menu.add_separator()
help_menu.add_command(label='О программе')
root_menu.add_cascade(label='Справка', menu=help_menu)
# open_menu = Menu(root_menu, tearoff=False)
# root_menu.add_cascade(label='Открыть', menu=open_menu)
class ToolbarButton(Button):
def __init__(self, parent, **options):
Button.__init__(self, parent, **options)
self.config(font=TOOLBAR_BUTTON_FONT)
# self.config(fg='black', bg='#FFF') # FFA
self.config(fg='black', bg='#BBF')
# self.config(fg='black', bg='#CCC')
# self.bind('<>', )
self.config(activebackground='#DDF')
# self.bind('<Tab>', self.config(bg='yellow'))
# self.bind('<Escape>', self.config(bg='#BBF'))
def make_toolbar(root, account):
global toolbar
toolbar = Frame(root)
toolbar.pack(side=TOP, fill=X)
toolbar.config(padx=5, pady=3)
toolbar.config(bg='#CCF') # FFA
clear_main_frame_button = ToolbarButton(toolbar, text='Очистить main_frame')
# clear_main_frame_button.pack(side=LEFT, fill=Y)
clear_main_frame_button.config(command=(lambda: clear_main_frame(root, account)))
open_table_button = ToolbarButton(toolbar, text='Таблицы')
open_table_button.pack(side=LEFT, fill=Y)
open_table_button.config(command=(lambda: db_viewer.run(TABLES, root, account)))
open_view_button = ToolbarButton(toolbar, text='Представления')
open_view_button.pack(side=LEFT, fill=Y)
open_view_button.config(command=(lambda: db_viewer.run(VIEWS, root, account, )))
if account.is_admin():
make_row_query_button = ToolbarButton(toolbar, text='SQL запрос к базе данных...')
make_row_query_button.pack(side=LEFT, fill=Y)
make_row_query_button.config(command=(lambda: raw_query.make_raw_query(root)))
make_report_button = ToolbarButton(toolbar, text='Отчеты')
make_report_button.pack(side=LEFT, fill=Y)
make_report_button.config(command=(lambda: reports.run(root, account)))
make_report_button = ToolbarButton(toolbar, text='Поиск по соединению таблиц')
make_report_button.pack(side=LEFT, fill=Y)
make_report_button.config(command=(lambda: search.run(root, account)))
logout_button = ToolbarButton(toolbar)
logout_image_path = '../TransportationsDBInterface/resourses/logout2.png'
logout_image = PhotoImage(file=logout_image_path)
logout_button.config(image=logout_image, bg='#CCF', relief=FLAT)
logout_button.image = logout_image
logout_button.config(width=50, height=50)
logout_button.pack(side=RIGHT)
logout_button.config(command=(lambda: login.run(root)))
logout_button.config(activebackground='#CCF', bd=0)
preferencies_button = ToolbarButton(toolbar, text='Настройки')
blue_referencies_path = '../TransportationsDBInterface/resourses/blue_preferencies2.png'
blue_referencies_image = PhotoImage(file=blue_referencies_path)
preferencies_button.config(image=blue_referencies_image, bg='#CCF', relief=FLAT) # bg='#CCF'
preferencies_button.image = blue_referencies_image
preferencies_button.pack(side=RIGHT, fill=Y)
preferencies_button.config(activebackground='#CCF', bd=0)
search_button = ToolbarButton(toolbar)
lens_image_path = '../TransportationsDBInterface/resourses/blue_lens.png'
lens_image = PhotoImage(file=lens_image_path)
search_button.config(image=lens_image, bg='#CCF',
relief=FLAT) # relief ::= FLAT, SUNKEN, RAISED, GROOVE, SOLID, RIDGE
search_button.image = lens_image
search_button.config(width=50, height=50)
search_button.pack(side=RIGHT)
# search_button.bind('<ButtonPress>', lambda event: search_button.config(bg='#CCF'))
search_button.config(activebackground='#CCF', bd=0)
def clear_grid_viewer_toolbar1():
global grid_viewer_toolbar
if not (grid_viewer_toolbar is None):
grid_viewer_toolbar_copy = grid_viewer_toolbar.children.copy()
for key, widget in grid_viewer_toolbar_copy.items():
widget.destroy()
# grid_viewer_toolbar
def make_grid_viewer_toolbar1(root, account):
global grid_viewer_toolbar
grid_viewer_toolbar = Frame(root)
grid_viewer_toolbar.pack(side=TOP, fill=X)
grid_viewer_toolbar.config(padx=5, pady=3)
grid_viewer_toolbar.config(bg='#CCF') # FFA
class StatusbarLabel(Label):
def __init__(self, parent, **options):
Label.__init__(self, parent, **options)
self.config(font=STATUSBAR_LABEL_FONT)
def clear_selected_item_label():
selected_item_label.config(text='')
def make_statusbar(root, account):
global statusbar
global status_label
global selected_item_label
statusbar = Frame(root)
statusbar.pack(side=BOTTOM, fill=X)
status_label = StatusbarLabel(statusbar)
status_label.config(text='')
status_label.pack(side=LEFT)
selected_item_label = StatusbarLabel(statusbar)
selected_item_label.config(text='')
selected_item_label.pack(side=LEFT, padx=50)
account_label = StatusbarLabel(statusbar)
account_label.config(text=account.get_rights() + ' : ' + account.name)
account_label.pack(side=RIGHT)
# widget.bind("<Control-Shift-KeyPress-q>", callback)
def clear_main_frame(root, account):
root.title(ROOT_TITLE + ' [' + account.get_rights() + ']')
global main_frame
main_frame_copy = main_frame.children.copy()
for key, widget in main_frame_copy.items():
widget.destroy()
bg_path = '../TransportationsDBInterface/resourses/gradient.png'
bi = PhotoImage(file=bg_path)
# blabel = Label(root, bg='#9AF')
blabel = Label(main_frame, image=bi) # , text='asd') # , bg='#9AF')
# blabel.place(x=-220, y=-50, relwidth=1.5, relheight=1.3)
blabel.image = bi
blabel.place(x=0, y=0, relwidth=1, relheight=1)
# status_label['text'] = 'main_frame очищен'
print('main_frame очищен')
def make_main_frame(root):
global main_frame
main_frame = Frame(root)
main_frame.pack(expand=YES, fill=BOTH)
# main_frame.config(image=)
# main_frame.config(bg='red')
bg_path = '../TransportationsDBInterface/resourses/gradient.png'
bi = PhotoImage(file=bg_path)
# blabel = Label(root, bg='#9AF')
blabel = Label(main_frame, image=bi) # , text='asd') # , bg='#9AF')
# blabel.place(x=-220, y=-50, relwidth=1.5, relheight=1.3)
blabel.image = bi
blabel.place(x=0, y=0, relwidth=1, relheight=1)
# blabel.pack(expand=YES, fill=BOTH)
show_demo_main_frame_button = False
if show_demo_main_frame_button:
btn = Button(main_frame, text='SDLFhds')
btn.pack(expand=YES)
def run(root, account):
# print(account.login, account.name, account.password, account.rights)
root.title(ROOT_TITLE + ' [' + account.get_rights() + ']')
make_menu(root, account)
# make_toolbar(root, account)
# make_grid_viewer_toolbar(root, account)
make_main_frame(root)
make_toolbar(root, account)
make_statusbar(root, account)
# print()
# print('MAIN_WINDOW [main_window.main_frame] ::', main_frame)
# print('MAIN_WINDOW [main_window.status_label] ::', status_label)
# b = Button(root, text='Statusbar')
# b.pack()
# b.config(command=(lambda: print('MAIN_WINDOW [main_window.statusbar] ::', statusbar)
# or print('MAIN_WINDOW [main_window.main_frame] ::', main_frame)))