-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoforese.py
192 lines (164 loc) · 6.63 KB
/
noforese.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
# -*- coding: utf-8 -*-
#
# This file created with KivyCreatorProject
# <https://github.com/HeaTTheatR/KivyCreatorProgect
#
# Copyright (c) 2020 Ivanov Yuri and KivyMD
#
# For suggestions and questions:
#
# LICENSE: MIT
import os
import sys
from ast import literal_eval
import os
import sys
from ast import literal_eval
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.config import ConfigParser
from kivy.logger import PY2
from kivy.clock import Clock
from kivy.utils import get_hex_from_color
from kivy.properties import ObjectProperty, StringProperty
from main import __version__
from libs.translation import Translation
from libs.uix.baseclass.startscreen import StartScreen
from libs.uix.lists import Lists
from kivymd.app import MDApp
from kivymd.toast import toast
from dialogs import card
class noforese(MDApp):
title = 'noforese'
icon = 'icon.png'
nav_drawer = ObjectProperty()
lang = StringProperty('en')
def __init__(self, **kvargs):
super(noforese, self).__init__(**kvargs)
Window.bind(on_keyboard=self.events_program)
Window.soft_input_mode = 'below_target'
self.list_previous_screens = ['base']
self.window = Window
self.config = ConfigParser()
self.manager = None
self.window_language = None
self.exit_interval = False
self.dict_language = literal_eval(
open(
os.path.join(self.directory, 'data', 'locales', 'locales.txt')).read()
)
self.translation = Translation(
self.lang, 'Ttest', os.path.join(self.directory, 'data', 'locales')
)
def get_application_config(self):
return super(noforese, self).get_application_config(
'{}/%(appname)s.ini'.format(self.directory))
def build_config(self, config):
config.adddefaultsection('General')
config.setdefault('General', 'language', 'en')
def set_value_from_config(self):
self.config.read(os.path.join(self.directory, 'noforese.ini'))
self.lang = self.config.get('General', 'language')
def build(self):
self.set_value_from_config()
self.load_all_kv_files(os.path.join(self.directory, 'libs', 'uix', 'kv'))
self.screen = StartScreen()
self.manager = self.screen.ids.manager
self.nav_drawer = self.screen.ids.nav_drawer
return self.screen
def load_all_kv_files(self, directory_kv_files):
for kv_file in os.listdir(directory_kv_files):
kv_file = os.path.join(directory_kv_files, kv_file)
if os.path.isfile(kv_file):
if not PY2:
with open(kv_file, encoding='utf-8') as kv:
Builder.load_string(kv.read())
else:
Builder.load_file(kv_file)
def events_program(self, instance, keyboard, keycode, text, modifiers):
if keyboard in (1001, 27):
if self.nav_drawer.state == 'open':
self.nav_drawer.toggle_nav_drawer()
self.back_screen(event=keyboard)
elif keyboard in (282, 319):
pass
return True
def back_screen(self, event=None):
if event in (1001, 27):
if self.manager.current == 'base':
self.dialog_exit()
return
try:
self.manager.current = self.list_previous_screens.pop()
except:
self.manager.current = 'base'
self.screen.ids.action_bar.title = self.title
self.screen.ids.action_bar.left_action_items = \
[['menu', lambda x: self.nav_drawer.toggle_nav_drawer()]]
def show_about(self, *args):
self.nav_drawer.toggle_nav_drawer()
self.screen.ids.about.ids.label.text = \
self.translation._(
u'[size=20][b]noforese[/b][/size]\n\n'
u'[b]Version:[/b] {version}\n'
u'[b]License:[/b] MIT\n\n'
u'[size=20][b]Developer[/b][/size]\n\n'
u'[ref=SITE_PROJECT]'
u'[color={link_color}]PAzter1101[/color][/ref]\n\n'
u'[b]Source code:[/b] '
u'[ref=https://github.com/ir1110/noforese.git]'
u'[color={link_color}]GitHub[/color][/ref]').format(
version=__version__,
link_color=get_hex_from_color(self.theme_cls.primary_color)
)
self.manager.current = 'about'
self.screen.ids.action_bar.left_action_items = \
[['chevron-left', lambda x: self.back_screen(27)]]
def show_license(self, *args):
self.nav_drawer.toggle_nav_drawer()
if not PY2:
self.screen.ids.license.ids.text_license.text = \
self.translation._('%s') % open(
os.path.join(self.directory, 'LICENSE'), encoding='utf-8').read()
else:
self.screen.ids.license.ids.text_license.text = \
self.translation._('%s') % open(
os.path.join(self.directory, 'LICENSE')).read()
self.manager.current = 'license'
self.screen.ids.action_bar.left_action_items = \
[['chevron-left', lambda x: self.back_screen(27)]]
self.screen.ids.action_bar.title = \
self.translation._('MIT LICENSE')
def select_locale(self, *args):
def select_locale(name_locale):
for locale in self.dict_language.keys():
if name_locale == self.dict_language[locale]:
self.lang = locale
self.config.set('General', 'language', self.lang)
self.config.write()
dict_info_locales = {}
for locale in self.dict_language.keys():
dict_info_locales[self.dict_language[locale]] = \
['locale', locale == self.lang]
if not self.window_language:
self.window_language = card(
Lists(
dict_items=dict_info_locales,
events_callback=select_locale, flag='one_select_check'
),
size=(.85, .55)
)
self.window_language.open()
def dialog_exit(self):
def check_interval_press(interval):
self.exit_interval += interval
if self.exit_interval > 5:
self.exit_interval = False
Clock.unschedule(check_interval_press)
if self.exit_interval:
sys.exit(0)
Clock.schedule_interval(check_interval_press, 1)
toast(self.translation._('Press Back to Exit'))
def on_lang(self, instance, lang):
self.translation.switch_lang(lang)