This repository was archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_management.py
More file actions
371 lines (327 loc) · 12.6 KB
/
GUI_management.py
File metadata and controls
371 lines (327 loc) · 12.6 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# Last edit date : 2019.09.15 - compile check!
# Compile main.py to run the whole program.
# Compile this code file to run this file
# This control GUI part of lexical_learning_program with PyQt5, Qt designer.
# To use source code, install "PyQt5" using "pip install PyQt5".
# Import part Start
import sys
import time
import random
from PyQt5 import *
from PyQt5.QtWidgets import *
from PyQt5 import uic
from PyQt5.QAxContainer import *
from PyQt5.QtGui import *
import Get_word_dictionary as gwd
# Import part End
# Varible declare Start
app = QApplication(sys.argv)
pass_the_stage = 0
selected_level = 0
selected_word = " "
now_check_word = "\0"
stage = 1
step = 0
word_list = []
# Varible declare Start
# First_page_Start
form_class_first = uic.loadUiType("GUI_files\First_page.ui")[0]
class First_page(QMainWindow, form_class_first):
def __init__(self):
super().__init__()
self.setUI()
def setUI(self):
self.setupUi(self)
self.exit.clicked.connect(self.exitf)
self.start_button.clicked.connect(self.buttonClick)
def exitf(self):
print("Exit lexical_learning_program")
exit(0)
def buttonClick(self):
global pass_the_stage
pass_the_stage = 1
self.close()
#First_page_End
# Second_page_Start
form_class_second = uic.loadUiType("GUI_files\Second_page.ui")[0]
class Second_page(QMainWindow, form_class_second):
def __init__(self):
super().__init__()
self.setUI()
def setUI(self):
self.setupUi(self)
self.exit.clicked.connect(self.exitf)
self.e_5_button.clicked.connect(self.button_click_e_5)
self.e_6_button.clicked.connect(self.button_click_e_6)
self.m_1_button.clicked.connect(self.button_click_m_1)
self.m_2_button.clicked.connect(self.button_click_m_2)
self.test_button.clicked.connect(self.button_click_test)
def exitf(self):
print("Exit lexical_learning_program.")
exit(0)
# Setting level function Start
def button_click_e_5(self):
global selected_level
global pass_the_stage
selected_level = 1
pass_the_stage = 1
self.close()
def button_click_e_6(self):
global selected_level
global pass_the_stage
selected_level = 2
pass_the_stage = 1
self.close()
def button_click_m_1(self):
global selected_level
global pass_the_stage
selected_level = 3
pass_the_stage = 1
self.close()
def button_click_m_2(self):
global selected_level
global pass_the_stage
selected_level = 4
pass_the_stage = 1
self.close()
def button_click_m_3(self):
global selected_level
global pass_the_stage
selected_level = 5
pass_the_stage = 1
self.close()
def button_click_test(self):
global selected_level
global pass_the_stage
selected_level = 0
pass_the_stage = 1
self.close()
# Setting level function Start
# Second_page_End
# Third_page_Start
form_class_third = uic.loadUiType("GUI_files\Third_page.ui")[0]
class Third_page(QMainWindow, form_class_third):
def __init__(self):
super().__init__()
self.setUI()
def setUI(self):
self.setupUi(self)
global selected_word
global now_check_word
global step
if step == 1: # Word step
now_check_word = selected_word
self.text_to_user.setText(now_check_word)
self.answer_true_false.setText("단어를 입력해 주세요.")
self.step_show.setText("Step : 1")
self.enter_text.setText("")
if step == 2: # Word's meaning step
now_check_word = gwd.meaning_of_word
self.text_to_user.setText(now_check_word)
self.answer_true_false.setText("단어의 뜻을 입력해 주세요.")
self.step_show.setText("Step : 2")
self.enter_text.setText("")
if step == 3: # Word's example step
now_check_word = gwd.example_of_word
self.text_to_user.setText(now_check_word)
self.answer_true_false.setText("단어의 예문을 입력해 주세요.")
self.step_show.setText("Step : 3")
self.enter_text.setText("")
self.exit.clicked.connect(self.exitf) # Exit button connect
self.check_button.clicked.connect(self.buttonClick) # Check button connect
def buttonClick(self): # Check Button clicked
global now_check_word
global step
global recheck_bool
print(now_check_word)
# Next step or next word
if(self.enter_text.toPlainText() != now_check_word ):
# Typing Error - Show comment
if step == 1:
recheck_bool = recheck_bool + 1
self.answer_true_false.setText("입력하신 단어에 오타가 존재합니다.")
recheck_bool = recheck_bool + 1
if step == 2:
self.answer_true_false.setText("입력하신 문장에 오타가 존재합니다.")
recheck_bool = recheck_bool + 1
if step == 3:
self.answer_true_false.setText("입력하신 문장에 오타가 존재합니다.")
recheck_bool = recheck_bool + 1
else:
# Typing Correct - Next step & word
if step == 1: # First step -> Second step
step = 2
now_check_word = gwd.meaning_of_word
self.text_to_user.setText(now_check_word)
self.answer_true_false.setText("단어의 뜻을 입력해 주세요.")
self.step_show.setText("Step : 2")
self.enter_text.setText("")
return
if step == 2: # Second step -> Third step
step = 3
now_check_word = gwd.example_of_word
self.text_to_user.setText(now_check_word)
self.answer_true_false.setText("단어의 예문을 입력해 주세요.")
self.step_show.setText("Step : 3")
self.enter_text.setText("")
return
if step == 3: # Next word
global pass_the_stage
global selected_word
global word_list
pass_the_stage = 1
if recheck_bool != 0: # Typing error
word_list.append(word_list.pop(0)) # Move content to end of list
else: # No typing error
word_list.pop(0) # remove the word
if len(word_list) != 0: # Next word
selected_word = word_list[0] # Selected_word = next word
gwd.Get_Need_Content(selected_word) # Getting word info
self.close()
def exitf(self): # Just_for_Test_level
global word_list
print("Saving data...")
print("Do not exit program! It can gets error!")
if selected_level == 1: # Using in
fp = open("Data\data_e5.dat","w",encoding = "UTF-8")
elif selected_level == 2:
fp = open("Data\data_e6.dat","w",encoding = "UTF-8")
elif selected_level == 3:
fp = open("Data\data_m1.dat","w",encoding = "UTF-8")
elif selected_level == 4:
fp = open("Data\data_m2.dat","w",encoding = "UTF-8")
elif selected_level == 5:
fp = open("Data\data_m3.dat","w",encoding = "UTF-8")
else:
fp = open("Data\data_TEST.dat","w",encoding = "UTF-8")
for i in word_list:
if i != word_list[-1]:
fp.write(i)
fp.write("\n")
else:
fp.write(i)
fp.close()
print("Exit lexical_learning_program.")
exit(0)
# Third_page_End
def Control_First_Second_GUI(): # Control Frist, Second page GUI
global pass_the_stage
Start_First_GUI()
check_x_button(1)
pass_the_stage = 0
Start_Second_GUI()
check_x_button(2)
pass_the_stage = 0
def Control_Third_GUI(): # Control Third page GUI
global pass_the_stage
global step
global selected_word
global recheck_bool
get_word_from_file()
check_level_finished()
selected_word = word_list[0]
gwd.Get_Need_Content(selected_word) # Get word info
while len(word_list): # Run when word_list have element
recheck_bool = 0
step = 1
Start_Third_GUI()
check_x_button(3)
pass_the_stage = 0
saving_data() # word_list don't have element
def Start_First_GUI(): # Load First_page
First_App = First_page()
First_App.show()
app.exec_()
def Start_Second_GUI(): # Load Second_page
Second_App = Second_page()
Second_App.show()
app.exec_()
def Start_Third_GUI(): # Load Third_page
Third_App = Third_page()
Third_App.show()
app.exec_()
def check_x_button(stage): # Click "X" button isn't allowed.
global pass_the_stage # Reload GUI
while 1:
if pass_the_stage == 1:
return
else:
if stage == 1:
Start_First_GUI()
check_x_button(1)
elif stage == 2:
Start_Second_GUI()
check_x_button(2)
else:
Start_Third_GUI()
check_x_button(3)
def get_word_from_file(): # Data folder files loading
global word_list
global selected_level
if selected_level == 1:
print("Loading elementary 5 lexical level.")
fp = open("Data\data_e5.dat","rt",encoding = "UTF-8")
elif selected_level == 2:
print("Loading elementary 6 lexical level.")
fp = open("Data\data_e6.dat","rt",encoding = "UTF-8")
elif selected_level == 3:
print("Loading middle 1 lexical level.")
fp = open("Data\data_m1.dat","rt",encoding = "UTF-8")
elif selected_level == 4:
print("Loading middle 2 lexical level.")
fp = open("Data\data_m2.dat","rt",encoding = "UTF-8")
elif selected_level == 5:
print("Loading middle 3 lexical level.")
fp = open("Data\data_m3.dat","rt",encoding = "UTF-8")
else:
print("Loading TEST lexical level.")
fp = open("Data\data_TEST.dat","rt",encoding = "UTF-8")
word_list = fp.readlines()
for i in range(len(word_list)-1): # Remove word_list's content's line feed.
word_list[i] = word_list[i][:len(word_list[i])-1]
fp.close()
random.shuffle(word_list) # Mix the list
def saving_data(): # Save data with blank
if selected_level == 1: # Using in
fp = open("Data\data_e5.dat","w",encoding = "UTF-8")
elif selected_level == 2:
fp = open("Data\data_e6.dat","w",encoding = "UTF-8")
elif selected_level == 3:
fp = open("Data\data_m1.dat","w",encoding = "UTF-8")
elif selected_level == 4:
fp = open("Data\data_m2.dat","w",encoding = "UTF-8")
elif selected_level == 5:
fp = open("Data\data_m3.dat","w",encoding = "UTF-8")
else:
fp = open("Data\data_TEST.dat","w",encoding = "UTF-8")
fp.close()
def check_level_finished():
global word_list
if len(word_list) == 0:
if selected_level == 1:
print("Elementary 5 lexical level is already done.")
print("Try different lexical level.")
print("If you want to start this level again, copy Data_backup\data_e5.dat to Data\data_e5.dat")
elif selected_level == 2:
print("Elementary 6 lexical level is already done.")
print("Try different lexical level.")
print("If you want to start this level again, copy Data_backup\data_e6.dat to Data\data_e6.dat")
elif selected_level == 3:
print("Middle 1 lexical level is already done.")
print("Try different lexical level.")
print("If you want to start this level again, copy Data_backup\data_m1.dat to Data\data_m1.dat")
elif selected_level == 4:
print("Middle 2 lexical level is already done.")
print("Try different lexical level.")
print("If you want to start this level again, copy Data_backup\data_m2.dat to Data\data_m2.dat")
elif selected_level == 5:
print("Middle 3 lexical level is already done.")
print("Try different lexical level.")
print("If you want to start this level again, copy Data_backup\data_m3.dat to Data\data_m3.dat")
else:
print("TEST lexical level is already done.")
print("Try different lexical level.")
print("If you want to start this level again, copy Data_backup\data_TEST.dat to Data\data_TEST.dat")
print("After 10 seconds, lexical_learning_program exits.")
time.sleep(10) # User need check!
exit(0)