-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
135 lines (119 loc) · 6.29 KB
/
main.py
File metadata and controls
135 lines (119 loc) · 6.29 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
import kivy
kivy.require("1.9.1")
from configuration import WINDOW_WIDTH, WINDOW_HEIGHT
from kivy.config import Config
Config.set("graphics", "width", WINDOW_WIDTH)
Config.set("graphics", "height", WINDOW_HEIGHT)
Config.write()
import json
from plyer import orientation
from theme import Theme
from src import Toast
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.core.text import LabelBase
LabelBase.register(
fn_regular="asset/Consolas.ttf",
name="consolas")
if kivy.platform != "android":
Window.size = (WINDOW_WIDTH, WINDOW_HEIGHT)
Window.left = 5
Window.top = 30
from kivy.app import App
from newUI import MainScreenWidget
class MatrixCalculator(App):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.icon = "asset/icon.png"
try:
with open("config.json") as f: self.Matrixconfig = json.load(f)
except json.decoder.JSONDecodeError:
with open("config.json", "w") as f: json.dump({"Allmatrix": ["A", "B", "C", "D", "E", "F"]}, f)
with open("config.json") as f: self.Matrixconfig = json.load(f)
self.allVariables()
self.CT = Theme()
self.CT.CurrentTheme = getattr(self.CT, (self.Matrixconfig.get("CurrentTheme") if self.Matrixconfig.get("CurrentTheme") else "ORIGINAL"))
def restart(self, theme: str):
self.Matrixconfig["CurrentTheme"] = theme
self.matrixCalc.addField()
self.matrixCalc.MatrixFunctions.MatrixResult.coloredResultString = self.matrixCalc.MatrixFunctions.MatrixResult.resultString
self.saveConfig()
self.realWidget.clear_widgets()
self.CT.CurrentTheme = getattr(self.CT, self.Matrixconfig.get("CurrentTheme"))
self.matrixCalc = MainScreenWidget()
self.realWidget.add_widget(self.matrixCalc)
Toast(f"Current Theme: {theme}", duration=3).start()
def allVariables(self):
config = self.Matrixconfig
self.allMatrixHolder = dict()
for name in self.Matrixconfig.get("Allmatrix"):
self.allMatrixHolder[name] = [3 if not config.get(f"{name}Rows") else config.get(f"{name}Rows"),
3 if not config.get(f"{name}Cols") else config.get(f"{name}Cols"),
[["0" for _ in range(10)] for __ in range(10)] if not config.get(f"{name}EValue") else config.get(f"{name}EValue")]
self.graphSave = 0 if not config.get("GraphSaveCount") else config.get("GraphSaveCount")
def saveConfig(self):
allName = list(self.allMatrixHolder.keys())
holder = self.allMatrixHolder
self.matrixCalc.addTheme()
self.Matrixconfig["CurrentFirst"] = self.matrixCalc.MatrixFunctions.firstMatrixHolder.name
self.Matrixconfig["CurrentSecond"] = self.matrixCalc.MatrixFunctions.secondMatrixHolder.name
for index in range(len(self.allMatrixHolder)):
self.Matrixconfig[f"{allName[index]}Rows"] = holder.get(f"{allName[index]}")[0]
self.Matrixconfig[f"{allName[index]}Cols"] = holder.get(f"{allName[index]}")[1]
self.Matrixconfig[f"{allName[index]}EValue"] = holder.get(f"{allName[index]}")[2]
self.Matrixconfig["ResultList"] = self.matrixCalc.MatrixFunctions.MatrixResult.resultList
self.Matrixconfig["CResultString"] = self.matrixCalc.MatrixFunctions.MatrixResult.coloredResultString
self.Matrixconfig["ResultString"] = self.matrixCalc.MatrixFunctions.MatrixResult.resultString
self.Matrixconfig["ResultRows"] = self.matrixCalc.MatrixFunctions.MatrixResult.resultRows
self.Matrixconfig["ResultCols"] = self.matrixCalc.MatrixFunctions.MatrixResult.resultCols
self.Matrixconfig["LastScreen"] = self.matrixCalc.sm.old_Screen
self.Matrixconfig["CurrentScreen"] = self.matrixCalc.sm.current
self.Matrixconfig["GraphSaveCount"] = self.graphSave
if hasattr(self.matrixCalc, "graph"):
self.Matrixconfig["Nodes"] = self.matrixCalc.graph.saveAllNodes()
self.Matrixconfig["CameraX"] = self.matrixCalc.graph.cameraX
self.Matrixconfig["CameraY"] = self.matrixCalc.graph.cameraY
with open("config.json", "w") as f: json.dump(self.Matrixconfig, f, indent=4, separators=(',', ': '))
def on_stop(self):
self.saveConfig()
self.Matrixconfig["LastScreen"] = "Main"
self.Matrixconfig["CurrentScreen"] = "Main"
with open("config.json", "w") as f: json.dump(self.Matrixconfig, f, indent=4, separators=(',', ': '))
return super().on_stop()
def on_start(self):
if kivy.platform == "android": orientation.set_portrait()
Window.bind(on_keyboard=self.hook_keyboard)
return super().on_start()
def hook_keyboard(self, _, key, *__):
if key == 27:
self.matrixCalc.addTheme()
if self.matrixCalc.MatrixFunctions.MatrixResult.isFullSize:
if self.matrixCalc.MatrixFunctions.MatrixResult.isGraphShowing:
self.matrixCalc.MatrixFunctions.MatrixResult.close_plot()
else:
self.matrixCalc.MatrixFunctions.MatrixResult.closeResult()
elif self.matrixCalc.MatrixFunctions.allFunctionsWidget.opened:
self.matrixCalc.MatrixFunctions.allFunctionsWidget.close()
elif self.matrixCalc.sm.current == "Theme":
self.matrixCalc.sm.transition.direction = "right"
self.matrixCalc.sm.change_Screen = self.matrixCalc.sm.old_Screen
elif self.matrixCalc.sm.current == "Field":
self.matrixCalc.sm.transition.direction = "right"
self.matrixCalc.sm.change_Screen = "Main"
elif self.matrixCalc.sm.current == "Graph":
self.matrixCalc.graph.removeAll()
self.matrixCalc.sm.transition.direction = "right"
self.matrixCalc.sm.change_Screen = self.matrixCalc.sm.old_Screen
elif self.matrixCalc.exitScreen.isExitScreen:
self.matrixCalc.exitScreen.close()
self.stop()
else: self.matrixCalc.exitScreen.show()
return True
def build(self):
self.realWidget = Widget()
self.matrixCalc = MainScreenWidget()
self.realWidget.add_widget(self.matrixCalc)
return self.realWidget
if __name__ == "__main__":
MatrixCalculator().run()
# print("FUCK")