-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf_theming.py
More file actions
224 lines (215 loc) · 8.17 KB
/
f_theming.py
File metadata and controls
224 lines (215 loc) · 8.17 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
from arabic_reshaper import reshape
from bidi.algorithm import get_display
from kivymd.app import MDApp
from kivymd.uix.button import MDFlatButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.screen import MDScreen
import random
from important_variables import THEME_PATH, FONT_PATH, COLORS
KV = """
<ChangeTheme>:
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
MDPersianLabel:
label_text: app.language_dialogs["rbcc"]
size_hint: .5, .2
pos_hint: {'x': .1, 'y': .65}
MDCheckbox:
id: rbcc
on_active: root.rbcc()
size_hint: .2, .2
pos_hint: {'x': .4, 'y': .65}
MDPersianLabel:
label_text: app.language_dialogs["dark_mode"]
size_hint: .2, .2
pos_hint: {'x': .725, 'y': .65}
MDCheckbox:
id: theme
on_active: root.change_theme()
size_hint: .2, .2
pos_hint: {'x': .8, 'y': .65}
MDLabel:
md_bg_color: [0.9568627450980392, 0.2627450980392157, 0.2117647058823529, 1]
size_hint: .2, .1
pos_hint: {'x': .725, 'y': .55}
MDCheckbox:
id: Red
group: "theme_color"
on_active: root.change_theme_color("Red", self)
size_hint: .2, .2
pos_hint: {'x': .8, 'y': .5}
MDLabel:
md_bg_color: [0.6117647058823529, 0.1529411764705882, 0.6901960784313725, 1]
size_hint: .2, .1
pos_hint: {'x': .425, 'y': .55}
MDCheckbox:
id: Purple
group: "theme_color"
on_active: root.change_theme_color("Purple", self)
size_hint: .2, .2
pos_hint: {'x': .5, 'y': .5}
MDLabel:
md_bg_color: [0.403921568627451, 0.2274509803921569, 0.7176470588235294, 1]
size_hint: .2, .1
pos_hint: {'x': .125, 'y': .55}
MDCheckbox:
id: DeepPurple
group: "theme_color"
on_active: root.change_theme_color("DeepPurple", self)
size_hint: .2, .2
pos_hint: {'x': .2, 'y': .5}
MDLabel:
md_bg_color: [0.1294117647058824, 0.5882352941176471, 0.9529411764705882, 1]
size_hint: .2, .1
pos_hint: {'x': .725, 'y': .35}
MDCheckbox:
id: Blue
group: "theme_color"
on_active: root.change_theme_color("Blue", self)
size_hint: .2, .2
pos_hint: {'x': .8, 'y': .3}
MDLabel:
md_bg_color: [0.0117647058823529, 0.6627450980392157, 0.9568627450980392, 1]
size_hint: .2, .1
pos_hint: {'x': .425, 'y': .35}
MDCheckbox:
id: LightBlue
group: "theme_color"
on_active: root.change_theme_color("LightBlue", self)
size_hint: .2, .2
pos_hint: {'x': .5, 'y': .3}
MDLabel:
md_bg_color: [0.2980392156862745, 0.6862745098039216, 0.3137254901960784, 1]
size_hint: .2, .1
pos_hint: {'x': .125, 'y': .35}
MDCheckbox:
id: Green
group: "theme_color"
on_active: root.change_theme_color("Green", self)
size_hint: .2, .2
pos_hint: {'x': .2, 'y': .3}
MDLabel:
md_bg_color: [1, 0.7568627450980392, 0.0274509803921569, 1]
size_hint: .2, .1
pos_hint: {'x': .725, 'y': .15}
MDCheckbox:
id: Amber
group: "theme_color"
on_active: root.change_theme_color("Amber", self)
size_hint: .2, .2
pos_hint: {'x': .8, 'y': .1}
MDLabel:
md_bg_color: [1, 0.3411764705882353, 0.1333333333333333, 1]
size_hint: .2, .1
pos_hint: {'x': .425, 'y': .15}
MDCheckbox:
id: DeepOrange
group: "theme_color"
on_active: root.change_theme_color("DeepOrange", self)
size_hint: .2, .2
pos_hint: {'x': .5, 'y': .1}
MDPersianLabel:
label_text: app.language_dialogs["auto"]
size_hint: .2, .1
pos_hint: {'x': .125, 'y': .15}
MDCheckbox:
id: random
group: "theme_color"
on_active: root.change_theme_color("random", self)
size_hint: .2, .2
pos_hint: {'x': .2, 'y': .1}
"""
class ChangeTheme(MDScreen):
open_dialog = True
def on_enter(self, *args):
with open(THEME_PATH, "r") as file:
theme = file.read().split(",")[0]
if theme == "Dark":
self.ids.theme.active = True
else:
self.ids.theme.active = False
with open(THEME_PATH, "r") as file:
rbcc = file.read().split(",")[2]
if rbcc == "True":
self.open_dialog = False
self.ids.rbcc.active = True
else:
self.ids.rbcc.active = False
with open(THEME_PATH, "r") as file:
theme_color = file.read().split(",")[1]
self.ids[theme_color].active = True
return super().on_enter(*args)
def close_app(self, instance):
self.dialog.dismiss()
MDApp.get_running_app().stop()
def cancel(self, instance):
self.dialog.dismiss()
self.open_dialog = False
current_choose = self.ids.rbcc.active
self.ids.rbcc.active = False if current_choose else True
def rbcc(self):
if self.ids.rbcc.active:
with open(THEME_PATH, "r") as file:
theme = file.read().split(",")
theme[2] = "True"
with open(THEME_PATH, "w") as file:
file.write(",".join(theme))
else:
with open(THEME_PATH, "r") as file:
theme = file.read().split(",")
theme[2] = "False"
with open(THEME_PATH, "w") as file:
file.write(",".join(theme))
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
)
]
)
if self.open_dialog:
self.dialog.open()
current_open_dialog = self.open_dialog
self.open_dialog = False if current_open_dialog else True
def change_theme(self):
if self.ids.theme.active:
with open(THEME_PATH, "r") as file:
theme = file.read().split(",")
theme[0] = """Dark"""
with open(THEME_PATH, "w") as file:
file.write(",".join(theme))
MDApp.get_running_app().theme_cls.theme_style = "Dark"
else:
with open(THEME_PATH, "r") as file:
theme = file.read().split(",")
theme[0] = "Light"
with open(THEME_PATH, "w") as file:
file.write(",".join(theme))
MDApp.get_running_app().theme_cls.theme_style = "Light"
def change_theme_color(self, color, button):
if button.active:
with open(THEME_PATH, "r") as file:
theme = file.read().split(",")
theme[1] = color
with open(THEME_PATH, "w") as file:
file.write(",".join(theme))
if color != "random":
MDApp.get_running_app().theme_cls.primary_palette = color
else:
MDApp.get_running_app().theme_cls.primary_palette = random.choice(COLORS)