-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
213 lines (178 loc) · 8.85 KB
/
main.py
File metadata and controls
213 lines (178 loc) · 8.85 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
import PySimpleGUI as sg
from app_statics.gui_layout import *
from app_statics.functions import *
sg.theme("Reddit")
##### ##### Layout ##### #####
image_formula_latex_column = sg.Column([
[sg.Image(filename="output_images/formula.png", key="image_formula_latex", expand_y=True)]
], element_justification='c', vertical_alignment='center',
expand_x=True, expand_y=True, key="show_latex_formula", visible=False)
##### Tab Group #####
main_column_left_tabs = sg.TabGroup([[
sg.Tab(normal[lang], normal_layout, key="normal"),
sg.Tab(function[lang], function_layout, key="function"),
sg.Tab(alphabet[lang], alphabet_layout, key="alphabet"),
]], font=FONT, expand_x=True)
main_column_right_tabs = sg.TabGroup([[
sg.Tab(limit[lang], limit_layout, key="limit", font=FONT),
sg.Tab(sigma[lang], sigma_layout, key="sigma", font=FONT),
sg.Tab(diff[lang], differential_layout, key="diff", font=FONT),
sg.Tab(integral[lang], integral_layout, key="integral", font=FONT),
]], font=FONT, expand_x=True)
##### Output #####
multiline_formula_tex = sg.Output(key='output_tex', font=FONT_output, pad=((0, 0), (0, 0)), size=(100, 6), expand_x=True)
output_frame = sg.Frame(output_frame_title[lang], [[multiline_formula_tex]], font=FONT_output, expand_x=True)
layout = [[output_frame],
[main_column_left_tabs, main_column_right_tabs],
[image_formula_latex_column]
]
window = sg.Window(title[lang], layout, icon="", use_default_focus=False, resizable=True, finalize=True)
set_bind(window)
# -------------------------------------
# イベント毎の処理
# -------------------------------------
focus = ""
space = ""
diff_selected = "x"
int_selected = "dx"
while True:
event, values = window.read() #type:ignore
if event == sg.WIN_CLOSED or event == None:
break
#Diff / Change Image
elif event in "diff_select":
diff_selected = values["diff_select"]
window["diff_img"].update(filename="images/diff/diff_{0}.png".format(diff_selected))
#Integral
elif event in "integral_select":
int_selected = values["integral_select"]
#get Focus
elif event in binds:
focus = str(event).replace("+Input", "")
#All Clear
elif event == "allclear":
if focus in limit_tab:
for box in limit_tab:
window["{0}".format(box)].update(space) #type:ignore
elif focus in sum_tab:
for box in sum_tab:
window["{0}".format(box)].update(space) #type:ignore
elif focus in diff_tab:
for box in diff_tab:
window["{0}".format(box)].update(space) #type:ignore
elif focus in integral_tab:
for box in integral_tab:
window["{0}".format(box)].update(space) #type:ignore
#括弧含む
elif event in brackets:
if focus != "":
text = values["{0}".format(focus)]
text = text + window[event].get_text() + "(" #type:ignore
window["{0}".format(focus)].update(text) #type:ignore
#逆三角関数
elif event in triangle_brackets:
if focus != "":
value = str(event)
text = values["{0}".format(focus)] + value + "("
window["{0}".format(focus)].update(text) #type:ignore
#Other Bottons
elif event in all_btns_keys:
if focus != "":
text = values["{0}".format(focus)]
#values[event] occur error
text = text + window[event].get_text() #type:ignore
window["{0}".format(focus)].update(text) # type: ignore
#2乗
elif event in "power_twice":
if focus != "":
text = values["{0}".format(focus)]
if text != "":
text = text + "**(2)"
window["{0}".format(focus)].update(text) # type: ignore
#Add
#極限
elif event in "add_limit":
if values["limit_formula"] != "":
#All
if values["limit_start"] != "" and values["limit_end"] != "":
window["output_tex"].update(space) #type:ignore
tex_start = transform_latex(values["limit_start"])
tex_end = transform_latex(values["limit_end"])
tex_formula = transform_latex(values["limit_formula"])
limit_tex = r"""$$\lim_{{{0} \to {1}}}{{{2}}}$$""".format(tex_start, tex_end, tex_formula)
print(limit_tex)
window["show_latex_formula"].update(visible=True)
window["image_formula_latex"].update(filename=autosize_latex(limit_tex))
elif values["limit_start"] == "" and values["limit_end"] == "":
window["output_tex"].update(space) #type:ignore
#一般方程式
tex = r"""$${0}$$""".format(transform_latex(values["limit_formula"]))
print(tex)
window["show_latex_formula"].update(visible=True)
window["image_formula_latex"].update(filename=autosize_latex(tex))
#数列
elif event in "add_sum":
if values["sum_formula"] != "":
if values["sum_func"] != "":
#関数のみの数列
if values["sum_end"] == "" and values["sum_start"] == "":
window["output_tex"].update(space) #type:ignore
tex_func = values["sum_func"]
tex_formula = transform_latex(values["sum_formula"])
sum_func_tex = r"""$$\sum_{{{0}}}^{{}}{{{1}}}$$""".format(tex_func, tex_formula)
print(sum_func_tex)
window["show_latex_formula"].update(visible=True)
window["image_formula_latex"].update(filename=autosize_latex(sum_func_tex))
#全て入力された状態
elif values["sum_end"] != "" and values["sum_start"] != "":
window["output_tex"].update(space) #type:ignore
tex_func = transform_latex(values["sum_func"])
tex_start = transform_latex(values["sum_start"])
tex_end = transform_latex(values["sum_end"])
tex_formula = transform_latex(values["sum_formula"])
sum_tex = r"""$$\sum_{{{0}={1}}}^{{{2}}}{{{3}}}$$""".format(tex_func, tex_start, tex_end, tex_formula)
print(sum_tex)
window["show_latex_formula"].update(visible=True)
window["image_formula_latex"].update(filename=autosize_latex(sum_tex))
elif values["sum_func"] == "" and values["sum_end"] == "" and values["sum_start"] == "":
window["output_tex"].update(space) #type:ignore
#一般方程式
tex = r"""$${0}$$""".format(transform_latex(values["sum_formula"]))
print(tex)
window["show_latex_formula"].update(visible=True)
window["image_formula_latex"].update(filename=autosize_latex(tex))
#微分
elif event in "add_diff":
if values["diff_formula"] != "":
window["output_tex"].update(space) #type:ignore
diff = transform_latex(values["diff_formula"])
diff_tex = r"""$$\frac{{d}}{{d{0}}}{{{1}}}$$""".format(diff_selected, diff)
print(diff_tex)
window["show_latex_formula"].update(visible=True)
window["image_formula_latex"].update(filename=autosize_latex(diff_tex))
#積分
elif event in "add_integral":
if values["integral_formula"] != "":
if values["integral_start"] != "" and values["integral_end"] != "":
window["output_tex"].update(space) #type:ignore
#定積分
tex_start = transform_latex(values["integral_start"])
tex_end = transform_latex(values["integral_end"])
tex_formula = transform_latex(values["integral_formula"])
integral_int_tex = r"""$$\int\limits_{{{0}}}^{{{1}}}{{{2}}}{{{3}}}$$""".format(tex_start, tex_end, tex_formula, int_selected)
print(integral_int_tex)
window["show_latex_formula"].update(visible=True)
window["image_formula_latex"].update(filename=autosize_latex(integral_int_tex))
elif values["integral_start"] == "" and values["integral_end"] == "":
window["output_tex"].update(space) #type:ignore
#不定積分
tex_formula = transform_latex(values["integral_formula"])
integral_tex = r"""$$\int{{{0}}}{{{1}}}$$""".format(tex_formula, int_selected)
print(integral_tex)
window["show_latex_formula"].update(visible=True)
window["image_formula_latex"].update(filename=autosize_latex(integral_tex))
#Clear
elif event in clear_btn:
if focus != "":
window["{0}".format(focus)].update(space) #type:ignore
window.close()