-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGUIEventBinder.py
More file actions
373 lines (268 loc) · 11.2 KB
/
GUIEventBinder.py
File metadata and controls
373 lines (268 loc) · 11.2 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
372
import wx
import gui
import threading
_user_pool_ = None
def init(Pool):
global _user_pool_
_user_pool_ = Pool
Main_MenuBar_File_Handler.bindEvent()
Main_MenuBar_Edit_Handler.bindEvent()
Main_MenuBar_Operation_Handler.bindEvent()
Main_MenuBar_Help_Handler.bindEvent()
Main_Member_Menu_Handler.bindEvent()
Config_Button_Handler.bindEvent()
Config_Choice_Handler.bindEvent()
Config_TextCtrl_Handler.bindEvent()
Config_ListCtrl_Selected_Handler.bindEvent()
def getUserOpFromTextCtrl():
global _user_pool_
account = gui.frame_configure.textctrl_account.GetLineText(0)
userop = _user_pool_.getUserOp(account)
return userop
def bind_main_menu_event(handler, source, attr_names):
for i in attr_names:
gui.frame_main.Bind(wx.EVT_MENU, getattr(handler, i), getattr(source, i))
# Frame Main MenuBar Handler
class Main_MenuBar_File_Handler:
@staticmethod
def bindEvent():
events = ('run', 'save', 'save_as', 'import_from_xlsx', 'exit')
bind_main_menu_event(Main_MenuBar_File_Handler, gui.frame_main.menu_bar.file, events)
@staticmethod
def run(event):
_user_pool_.runTakeAll()
@staticmethod
def save(event):
pass
@staticmethod
def save_as(event):
pass
@staticmethod
def import_from_xlsx(event):
dlg = wx.FileDialog(gui.frame_main, u"选择导入文件 *.xlsx", style=wx.FD_DEFAULT_STYLE)
dlg.SetWildcard('*.xlsx')
if dlg.ShowModal() == wx.ID_OK:
path_name = dlg.GetPath()
threading.Thread(target=_user_pool_.loadFromXlsx, args=(path_name,)).start()
dlg.Destroy()
@staticmethod
def exit(event):
exit()
class Main_MenuBar_Operation_Handler:
@staticmethod
def bindEvent():
events = ('login', 'login_all', 'take', 'take_all', 'verify', 'verify_all')
bind_main_menu_event(Main_MenuBar_Operation_Handler, gui.frame_main.menu_bar.operation, events)
@staticmethod
def login(event):
Main_Member_Menu_Handler.login(event)
@staticmethod
def login_all(event):
_user_pool_.runLoginAll()
@staticmethod
def take(event):
Main_Member_Menu_Handler.take(event)
@staticmethod
def take_all(event):
_user_pool_.runTakeAll()
@staticmethod
def verify(event):
Main_Member_Menu_Handler.verify(event)
@staticmethod
def verify_all(event):
_user_pool_.runVerifyAll()
class Main_MenuBar_Edit_Handler:
@staticmethod
def bindEvent():
events = ('add', 'delete', 'delete_all')
bind_main_menu_event(Main_MenuBar_Edit_Handler, gui.frame_main.menu_bar.edit, events)
@staticmethod
def add(event):
gui.frame_configure.textctrl_account.Clear()
gui.frame_configure.textctrl_password.Clear()
gui.frame_configure.textctrl_keys.Clear()
gui.frame_configure.textctrl_account.Enable(True)
gui.frame_configure.Show(True)
@staticmethod
def delete(event):
Main_Member_Menu_Handler.delete(event)
@staticmethod
def delete_all(event):
pass
class Main_MenuBar_Help_Handler:
@staticmethod
def bindEvent():
events = ('help', 'about')
bind_main_menu_event(Main_MenuBar_Help_Handler, gui.frame_main.menu_bar.help, events)
@staticmethod
def help(event):
pass
@staticmethod
def about(event):
dlg = gui.About_Dialog(gui.frame_main)
dlg.ShowModal()
dlg.Destroy()
# Frame Main Member Menu Handler
class Main_Member_Menu_Handler:
@staticmethod
def bindEvent():
events = ('view', 'configure', 'login', 'take', 'verify', 'delete')
bind_main_menu_event(Main_Member_Menu_Handler, gui.frame_main.listctrl_member.menu, events)
@staticmethod
def view(event):
gui.frame_configure.textctrl_account.Clear()
gui.frame_configure.textctrl_password.Clear()
gui.frame_configure.textctrl_keys.Clear()
gui.frame_configure.textctrl_account.Enable(False)
index = gui.frame_main.listctrl_member.GetFirstSelected()
if index == -1:
return
item = _user_pool_.queue[index].user
gui.frame_configure.textctrl_account.write(item.account)
gui.frame_configure.textctrl_keys.write(item.keys)
gui.frame_configure.Show(True)
@staticmethod
def login(event):
index = gui.frame_main.listctrl_member.GetFirstSelected()
userop = _user_pool_.queue[index]
if index != -1:
threading.Thread(target=userop.login, name='Menu_Login').start()
@staticmethod
def take(event):
index = gui.frame_main.listctrl_member.GetFirstSelected()
userop = _user_pool_.queue[index]
if index != -1:
menu_text = gui.frame_main.listctrl_member.menu.take.GetText()
if 'Stop' in menu_text:
threading.Thread(target=userop.taker.stop, name='Menu_Stop').start()
elif 'Take' in menu_text:
threading.Thread(target=userop.takeCourse, name='Menu_Take').start()
@staticmethod
def configure(event):
Main_Member_Menu_Handler.view(event)
@staticmethod
def verify(event):
index = gui.frame_main.listctrl_member.GetFirstSelected()
userop = _user_pool_.queue[index]
threading.Thread(target=userop.verify).start()
@staticmethod
def delete(event):
gui.frame_configure.textctrl_account.Clear()
gui.frame_configure.textctrl_password.Clear()
gui.frame_configure.textctrl_keys.Clear()
gui.frame_configure.textctrl_account.Enable(False)
index = gui.frame_main.listctrl_member.GetFirstSelected()
if index == -1:
return
_user_pool_.delete(index)
# Frame Configure Button Handler
def bind_config_button_event(handler, source, attr_names):
for i in attr_names:
gui.frame_configure.Bind(wx.EVT_BUTTON, getattr(handler, i), getattr(source, 'button_%s' % i))
class Config_Button_Handler:
@staticmethod
def bindEvent():
events = ('login', 'load_course', 'load_usercourse', 'save_settings')
bind_config_button_event(Config_Button_Handler, gui.frame_configure, events)
@staticmethod
def login(event):
def after():
gui.frame_configure.button_login.Enable(True)
gui.frame_configure.textctrl_password.Clear()
def add_or_delete(userop):
if not userop.user.ready:
_user_pool_.remove(userop)
else:
gui.frame_configure.textctrl_account.Enable(False)
gui.frame_configure.textctrl_password.Clear()
if not gui.frame_configure.textctrl_account.IsEnabled():
gui.frame_configure.button_login.Enable(False)
password = gui.frame_configure.textctrl_password.GetLineText(0)
userop = getUserOpFromTextCtrl()
if password:
userop.user.password = password
threading.Thread(target=userop.login).start()
userop.join(exec_foo=after)
else:
account = gui.frame_configure.textctrl_account.GetLineText(0)
password = gui.frame_configure.textctrl_password.GetLineText(0)
keys = gui.frame_configure.textctrl_keys.GetLineText(0)
userop = _user_pool_.add(account, password, keys)
threading.Thread(target=userop.login).start()
userop.join(exec_foo=add_or_delete, args=(userop,))
@staticmethod
def load_course(event):
gui.frame_configure.button_load_course.Enable(False)
userop = getUserOpFromTextCtrl()
threading.Thread(target=userop.taker.puller.displayCourse).start()
userop.join(gui.frame_configure.button_load_course.Enable, args=(True,))
@staticmethod
def load_usercourse(event):
gui.frame_configure.button_load_usercourse.Enable(False)
userop = getUserOpFromTextCtrl()
threading.Thread(target=userop.taker.puller.displayUserCourse).start()
userop.join(gui.frame_configure.button_load_usercourse.Enable, args=(True,))
# @staticmethod
# def export(event):
# pass
@staticmethod
def save_settings(event):
dlg = wx.MessageDialog(gui.frame_configure, u'你确定要保存设置吗?',
u'提示', wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.YES:
userop = getUserOpFromTextCtrl()
userop.user.keys = gui.frame_configure.textctrl_keys.GetLineText(0)
userop.user.force_post = gui.frame_configure.checkbox_force.GetValue()
timer_refresh = gui.frame_configure.spinctrl_timer.GetValue()
if userop.user.timer_refresh != timer_refresh:
userop.user.timer_refresh = timer_refresh
userop.cancelGetNotice()
userop.timingGetNotice()
userop.user.delay_range = [gui.frame_configure.spinctrl_start.GetValue(),
gui.frame_configure.spinctrl_end.GetValue()]
# Frame Configure Choice Handler
class Config_Choice_Handler:
@staticmethod
def bindEvent():
gui.frame_configure.Bind(wx.EVT_CHOICE, Config_Choice_Handler.season,
gui.frame_configure.choice_season)
@staticmethod
def season(event):
selected_index = gui.frame_configure.choice_season.GetCurrentSelection()
userop = getUserOpFromTextCtrl()
userop.taker.puller.season_code.setSeletedIndex(selected_index)
# Frame Configure Choice Handler
class Config_TextCtrl_Handler:
@staticmethod
def bindEvent():
gui.frame_configure.Bind(wx.EVT_TEXT, Config_TextCtrl_Handler.keys,
gui.frame_configure.textctrl_keys)
@staticmethod
def keys(event):
if gui.frame_configure.listctrl_optional.style == 0: # STYLE_OPTIONAL
userop = getUserOpFromTextCtrl()
if userop:
userop.taker.puller.displayTarget()
def bind_config_menu_event(handler, source, attr_names):
for i in attr_names:
gui.frame_configure.Bind(wx.EVT_MENU, getattr(handler, i), getattr(source, i))
# Frame Configure Selected Handler
class Config_ListCtrl_Selected_Handler:
@staticmethod
def bindEvent():
items = ('delete',)
bind_config_menu_event(Config_ListCtrl_Selected_Handler, gui.frame_configure.listctrl_selected.menu, items)
@staticmethod
def delete(event):
index = gui.frame_configure.listctrl_selected.GetFirstSelected()
if index != -1:
userop = getUserOpFromTextCtrl()
course = userop.taker.puller.selected.index(index)
dlg = wx.MessageDialog(gui.frame_configure, u'你确定要退选课程:[%s] ?' % course.__str__(),
u'提示', wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.YES:
if userop.taker.postCancel():
wx.MessageDialog(gui.frame_configure, u'退选成功!', u'完成', wx.OK | wx.ICON_INFORMATION)
else:
wx.MessageDialog(gui.frame_configure, u'退选失败,(详情请看主窗口的logs的ServerMsg)。', u'错误',
wx.OK | wx.ICON_ERROR)