-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf_setting.py
More file actions
273 lines (242 loc) · 9.35 KB
/
f_setting.py
File metadata and controls
273 lines (242 loc) · 9.35 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
273
from b_manage_users import change_name, change_password, name_is_new, current_user_name, user_type
from important_variables import FONT_PATH, LANGUAGE_PATH
import pygame
from kivy.clock import Clock
from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen
from kivymd.uix.dialog import MDDialog
from f_components import MDFlatButton
from arabic_reshaper import reshape
from bidi.algorithm import get_display
KV = """
<ApplicationSettings>:
MDFloatLayout:
MDRectangleFlatIconButton:
button_text: app.language_dialogs["exit"]
icon: "location-exit"
on_release: root.manager.current = "home"
pos_hint: {'x': 0, 'y': .9}
size_hint: .2, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["manage_database"]
icon: "database-cog"
on_release: root.go_to_database_manager_page()
pos_hint: {'x': .3, 'y': .65}
size_hint: .4, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change_theme"]
icon: "palette"
on_release: root.manager.current = "change_theme"
pos_hint: {'x': .3, 'y': .475}
size_hint: .4, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["edit_account"]
icon: "account-cog"
on_release: root.manager.current = "account_setting"
pos_hint: {'x': .3, 'y': .3}
size_hint: .4, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change_language"]
icon: "translate"
on_release: root.change_language()
pos_hint: {'x': .3, 'y': .125}
size_hint: .4, .1
<AccountSetting>:
MDFloatLayout:
MDRectangleFlatIconButton:
button_text: app.language_dialogs["exit"]
icon: "location-exit"
on_release: root.manager.current = "settings"
pos_hint: {'x': 0, 'y': .9}
size_hint: .2, .1
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change_username"]
icon: "rename-box"
on_release: root.manager.current = "change_admins_name"
pos_hint: {'x': .2, 'y': .6}
size_hint: .6, .2
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change_password"]
icon: "key-variant"
on_release: root.manager.current = "change_admins_password"
pos_hint: {'x': .2, 'y': .3}
size_hint: .6, .2
<ChangeAdminsPassword>:
GridLayout:
cols: 1
size_hint: None, None
size: 400, 100
pos_hint: {'center_x': 0.5, 'center_y': 0.6}
spacing: 25, 25
MDPasswordTextField:
id: password
hint_text: app.persian(app.language_dialogs["password"])
font_name_hint_text: app.FONT_PATH
MDPasswordTextField:
id: passwordtwo
hint_text: app.persian(app.language_dialogs["confirm_password"])
font_name_hint_text: app.FONT_PATH
BoxLayout:
orientation: 'horizontal'
size_hint: None, None
size: 200, 50
pos_hint: {'center_x': 0.5, 'center_y': 0.3}
spacing: 25
MDFlatButton:
text: app.persian(app.language_dialogs["cancel"])
font_name: app.FONT_PATH
on_release: root.manager.current = "account_setting"
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change_password"]
icon: "key-variant"
on_release: root.change_password()
<ChangeAdminsName>:
GridLayout:
cols: 1
size_hint: None, None
size: 400, 100
pos_hint: {'center_x': 0.5, 'center_y': 0.6}
spacing: 25, 25
MDTextFieldPersian:
id: new_name
persian_hint_text: app.language_dialogs["new_username"]
font_size: 20
halign: "left"
BoxLayout:
orientation: 'horizontal'
size_hint: None, None
size: 200, 50
pos_hint: {'center_x': 0.5, 'center_y': 0.3}
spacing: 25
MDFlatButton:
text: app.persian(app.language_dialogs["cancel"])
font_name: app.FONT_PATH
on_release: root.manager.current = "account_setting"
MDRectangleFlatIconButton:
button_text: app.language_dialogs["change_username"]
icon: "rename-box"
on_release: root.change_name()
"""
class ApplicationSettings(MDScreen):
def close_app(self, instance):
self.dialog.dismiss()
MDApp.get_running_app().stop()
def cancel(self, instance):
self.dialog.dismiss()
with open(LANGUAGE_PATH, "r") as file:
current_lang = file.read()
new_lang = "per" if current_lang == "eng" else "eng"
with open(LANGUAGE_PATH, "w") as file:
file.write(new_lang)
def change_language(self):
with open(LANGUAGE_PATH, "r") as file:
current_lang = file.read()
new_lang = "per" if current_lang == "eng" else "eng"
with open(LANGUAGE_PATH, "w") as file:
file.write(new_lang)
persian_text = MDApp.get_running_app(
).language_dialogs["reopen_application_alert"]
text = "[font={}]{}[/font]".format(FONT_PATH,
get_display(reshape(persian_text)))
self.dialog = MDDialog(
title=text,
buttons=[
MDFlatButton(
text=get_display(
reshape(MDApp.get_running_app().language_dialogs["cancel"])),
font_name=FONT_PATH,
on_release=self.cancel
),
MDFlatButton(
text=get_display(
reshape(MDApp.get_running_app().language_dialogs["close_application"])),
font_name=FONT_PATH,
on_release=self.close_app
)
]
)
self.dialog.open()
def go_to_database_manager_page(self):
if user_type(current_user_name()) in ("creator", "admin"):
self.manager.current = "database_setting"
else:
persian_text = MDApp.get_running_app(
).language_dialogs["admin_and_manager"]
text = "[font={}]{}[/font]".format(FONT_PATH,
get_display(reshape(persian_text)))
self.dialog = MDDialog(
title=text,
buttons=[
MDFlatButton(
text=get_display(
reshape(
MDApp.get_running_app(
).language_dialogs["i_got_it"]
)
),
font_name=FONT_PATH,
on_release=lambda instance: self.dialog.dismiss()
)
]
)
self.dialog.open()
class AccountSetting(MDScreen):
pass
class ChangeAdminsName(MDScreen):
do_shortcuts = False
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.event = Clock.schedule_interval(self.update, 1 / 10)
def on_leave(self, *args):
self.do_shortcuts = False
return super().on_leave(*args)
def update(self, dt):
if self.do_shortcuts:
keys = pygame.key.get_pressed()
if keys[pygame.K_RETURN]:
self.change_name()
def on_enter(self):
self.do_shortcuts = True
def change_name(self):
if name_is_new(self.ids.new_name.str):
change_name(current_user_name(), self.ids.new_name.str)
self.manager.current = "home"
else:
persian_text = MDApp.get_running_app().language_dialogs["name_duplicated_error"]
text = "[font={}]{}[/font]".format(FONT_PATH,
get_display(reshape(persian_text)))
self.dialog = MDDialog(
title=text,
buttons=[
MDFlatButton(
text=get_display(
reshape(
MDApp.get_running_app(
).language_dialogs["i_got_it"]
)
),
font_name=FONT_PATH,
on_release=lambda instance: self.dialog.dismiss()
)
]
)
self.dialog.open()
class ChangeAdminsPassword(MDScreen):
do_shortcuts = False
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.event = Clock.schedule_interval(self.update, 1 / 10)
def on_leave(self, *args):
self.do_shortcuts = False
return super().on_leave(*args)
def update(self, dt):
if self.do_shortcuts:
keys = pygame.key.get_pressed()
if keys[pygame.K_RETURN]:
self.change_password()
def on_enter(self):
self.do_shortcuts = True
def change_password(self):
if self.ids.password.text != "" and self.ids.passwordtwo.text != "" and self.ids.password.text == self.ids.passwordtwo.text:
change_password(self.ids.passwordtwo.text, current_user_name())
self.manager.current = "home"