-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
233 lines (159 loc) · 6.29 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
import os
from typing import Text
from kivymd.app import MDApp
from kivy.core.window import Window
from kivy.lang import Builder
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.behaviors import FakeRectangularElevationBehavior
from kivy.utils import platform
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.dialog import MDDialog
from kivymd.uix.boxlayout import MDBoxLayout
from kivy.factory import Factory
from kivymd.uix.bottomsheet import MDCustomBottomSheet, MDListBottomSheet
import json
import webbrowser
from textblob import TextBlob
if os.path.exists('langgo_data.json'):
with open('langgo_data.json','r') as f:
data = json.load(f)
else:
data = {'theme': 'Dark','color':'Brown'}
with open('langgo_data.json','w') as f:
json.dump(data, f)
with open('language.json','r') as s:
language_dict = json.load(s)
if (platform != 'android'):
# from android.permissions import request_permissions, Permission
# request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
Window.size = (360, 640)
sm = ScreenManager()
# all screens
class NavBar(FakeRectangularElevationBehavior, MDFloatLayout):
pass
class langtoSelect(MDBoxLayout):
pass
class profilecard(MDBoxLayout):
pass
class Homescreen(Screen):
def translate_text(self, from_text):
for key, value in language_dict.items():
if key == Main.to_language:
text = TextBlob(from_text)
translated_text = text.translate(to=value)
break
self.ids.to_text.text = str(translated_text)
class Settingscreen(Screen):
color_sheet = None
profile_sheet = None
def toggle_bottomcolorsheet(self):
# ['Red', 'Pink', 'Purple', 'DeepPurple', 'Indigo', 'Blue', 'LightBlue',
# 'Cyan', 'Teal', 'Green', 'LightGreen', 'Lime', 'Yellow', 'Amber', 'Orange',
# 'DeepOrange', 'Brown', 'Gray', 'BlueGray']
self.color_sheet = MDListBottomSheet(radius=12)
data1 = {
'Red':"", 'Pink':"", 'Purple':"",
'DeepPurple':"", 'Indigo':"",
'Blue':"", 'LightBlue':"",'Cyan':"",
'Teal':"", 'Green':"", 'LightGreen':"",
'Lime':"", 'Yellow':"", 'Amber':"",
'Orange':"", 'DeepOrange':"", 'Brown':"",
'Gray':"", 'BlueGray':""
}
for items in data1.items():
self.color_sheet.add_item(
items[0],
lambda x, y=items[0]: app.change_primary_color(y),
icon='circle-outline',
)
self.color_sheet.open()
def toggle_profile(self):
self.profile_sheet = MDCustomBottomSheet(
screen=Factory.profile_card(),
radius=12
)
self.profile_sheet.open()
sm.add_widget(Homescreen(name="Home"))
sm.add_widget(Settingscreen(name="Settings"))
# main class of app
class Main(MDApp):
to_dialog = None
to_language = ""
def __init__(self, **kwargs):
self.title = "Langgo"
super().__init__(**kwargs)
def goto_mail(self):
webbrowser.open('mailto:[email protected]')
def show_to_option(self):
self.to_dialog = MDDialog(
radius=[20,7,20,7],
title="To : ",
type="custom",
content_cls=langtoSelect(),
)
self.to_dialog.open()
def close_to(self):
if self.to_dialog.open:
self.to_dialog.dismiss(force=True)
else:
pass
def to_select(self, lang):
Main.to_language = lang
# dark and light theme changer
def toggle_theme(self):
if self.theme_cls.theme_style == "Dark":
self.theme_cls.theme_style = "Light"
data['theme'] = 'Light'
self.root.ids.nav_icon2.text_color = app.theme_cls.primary_color
self.root.ids.nav_icon1.text_color = [0,0,0,1]
else:
self.theme_cls.theme_style = "Dark"
data['theme'] = 'Dark'
self.root.ids.nav_icon2.text_color = app.theme_cls.primary_color
self.root.ids.nav_icon1.text_color = [1,1,1,1]
with open('langgo_data.json','w') as f:
json.dump(data, f)
def change_primary_color(self, color):
print(color)
if color != "":
self.theme_cls.primary_palette = color
data['color'] = color
if self.theme_cls.theme_style == "Dark":
self.root.ids.nav_icon2.text_color = app.theme_cls.primary_color
self.root.ids.nav_icon1.text_color = [1,1,1,1]
else:
self.root.ids.nav_icon2.text_color = app.theme_cls.primary_color
self.root.ids.nav_icon1.text_color = [0,0,0,1]
with open('langgo_data.json','w') as f:
json.dump(data, f)
def select_nav(self, instance):
if instance in self.root.ids.values():
current_id = list(self.root.ids.keys())[list(self.root.ids.values()).index(instance)]
for i in range(2):
if f"nav_icon{i+1}" == current_id:
self.root.ids[f"nav_icon{i+1}"].text_color = app.theme_cls.primary_color
else:
if app.theme_cls.theme_style == "Light":
self.root.ids[f"nav_icon{i+1}"].text_color = [0,0,0,1]
else:
self.root.ids[f"nav_icon{i+1}"].text_color = [1,1,1,1]
# donot remove build method
def build(self):
# ['Red', 'Pink', 'Purple', 'DeepPurple', 'Indigo', 'Blue', 'LightBlue',
# 'Cyan', 'Teal', 'Green', 'LightGreen', 'Lime', 'Yellow', 'Amber', 'Orange',
# 'DeepOrange', 'Brown', 'Gray', 'BlueGray']
# themes and palette
self.theme_cls.material_style = "M3"
if data != None:
self.theme_cls.theme_style = data['theme']
self.theme_cls.primary_palette = data['color']
else:
pass
Builder.load_file('screens/Homescreen.kv')
Builder.load_file('screens/Settingscreen.kv')
Builder.load_file('screens/langto.kv')
Builder.load_file('screens/profile_card.kv')
return Builder.load_file('screens/mainapp.kv')
if __name__ == "__main__":
app = Main()
app.run()