OSDN Git Service

revise gui
[amulettoolsmh4/main.git] / amulettool.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # お守りスキルのSeed特定ツールのコントロールクラス
5 # 2013/12/04 written by kei9
6
7 import threading
8 import time
9 import os.path
10 import sys
11 import pickle
12 import sqlite3
13
14 import wx
15
16 import view
17 import model
18 import convertcoding
19
20 SETTING_FILE = u"settings"
21 SETTING_THRESHOLD1 = u"threshold1"
22 SETTING_THRESHOLD2 = u"threshold2"
23 SETTING_SKILLS = u"skills"
24
25 def _get_base_dir():
26     u""" for pyinstaller 2.1 """
27     if getattr(sys, 'frozen', False):
28         # we are running in a |PyInstaller| bundle
29         basedir = sys._MEIPASS
30     else:
31         # we are running in a normal Python environment
32         #1basedir = os.path.dirname(__file__)
33         basedir = os.path.dirname(os.path.abspath(__file__))
34     return convertcoding.convert_unicode(basedir)
35
36
37 class AmuletToolController(wx.App):
38     u""" アプリケーションの制御クラス """
39     def OnInit(self):
40         self._read_settings()
41         self.frame_view = view.MainFrameView(os.path.join(_get_base_dir(), u"view", view.XRC_MAIN_FRAME))
42
43         self._init_events()
44
45         self.frame_view.Show()
46
47         self.frame_view.DisableNoteBook()
48
49         self._init_database()
50         self._init_notebook_seed1()
51         self._init_notebook_seed2()
52         self._init_notebook_skill2()
53         self._init_notebook_setting()
54         self._init_notebook_amulet()
55
56         self.frame_view.EnableNoteBook()
57         return True
58
59     def _init_events(self):
60         u"""イベント登録"""
61         frame = self.frame_view.frame
62
63         # menu event
64         frame.Bind(wx.EVT_MENU, self.OnClose, id=self.frame_view.ID_MENU_ITEM_EXIT)
65         frame.Bind(wx.EVT_MENU, self.OnAboutBox, id=self.frame_view.ID_MENU_ITEM_ABOUT)
66         frame.Bind(wx.EVT_CLOSE, self.CloseHandler)
67
68         # button event
69
70     def _init_database(self):
71         u""" DBの初期設定 """
72
73         if not os.path.exists(model.DB_FILE_NAME):
74             u""" DBが存在しない時は再生成する """
75             frame = self.frame_view.frame
76             try:
77                 generator = model.DataBaseGenerator(model.DB_FILE_NAME)
78                 #generator = model.DataBaseGenerator()
79
80                 dlg_view = view.GaugeDialogView(os.path.join(_get_base_dir(), u"view", view.XRC_GAUGE_DIALOG))
81                 def _loop():
82                     while t1.is_alive():
83                         dlg_view.gauge.Pulse()
84                         time.sleep(0.2)
85                     dlg_view.finish_generation()
86
87                 t1 = threading.Thread(target=generator.generate_db)
88                 t2 = threading.Thread(target=_loop)
89                 t1.start()
90                 t2.start()
91
92                 dlg_view.ShowModal()
93                 t1.join()
94                 t2.join()
95                 dlg_view.Destroy()
96             except sqlite3.Error as e:
97                 self._show_error_dialog(u"データベース生成中にエラーが発生しました")
98
99         # access to db
100         try:
101             self.db_accessor = model.DataBaseAccessor(model.DB_FILE_NAME)
102         except sqlite3.Error as e:
103             self._show_error_dialog(u"データベースが壊れています")
104
105         # get dictionaries
106         (self._skill_id2name_dict, 
107             self._skill_name2id_dict,
108             self._amulet_id2name_dict, 
109             self._amulet_name2id_dict,
110             self._amulet_id2skill1_id_dict,
111             self._amulet_id2skill2_id_dict) = self.db_accessor.get_dicts()
112
113     def _init_notebook_seed1(self):
114         u""" Seed1特定タブのviewの初期化 """
115         self.notebook_seed1_view = self.frame_view.notebook_seed1_view
116         self.notebook_seed1_view.bind_button_search(self.OnClickSeed1Search)
117         self.notebook_seed1_view.bind_button_clear(self.OnClickSeed1Clear)
118
119         u" 各種お守りの第1スキル選択のセット "
120         amu_names, name2skill1s = [], {}
121         for amu_id in sorted(self._amulet_id2name_dict.keys()):
122             name = self._amulet_id2name_dict[amu_id]
123             amu_names.append(name)
124             name2skill1s[name] = [self._skill_id2name_dict[skill_id]
125                     for skill_id in self._amulet_id2skill1_id_dict[amu_id]]
126         self.notebook_seed1_view.set_amuletname_skillnames_dict(amu_names, name2skill1s)
127
128     def _init_notebook_seed2(self):
129         u""" Seed2特定タブのviewの初期化 """
130         self.notebook_seed2_view = self.frame_view.notebook_seed2_view
131         self.notebook_seed2_view.bind_button_search(self.OnClickSeed2Search)
132         self.notebook_seed2_view.bind_button_clear(self.OnClickSeed2Clear)
133         self.notebook_seed2_view.bind_button_skill2(self.OnClickSkill2SearchFromSeed2)
134
135         u" 各種お守りの第2スキル選択 "
136         for amu_key, amu_name in zip([view.KEY_AMULET1, view.KEY_AMULET2, view.KEY_AMULET3], 
137                 [view.NAME_AMULET1, view.NAME_AMULET2, view.NAME_AMULET3]):
138             amu_id = self._amulet_name2id_dict[amu_name]
139             skill_ids = self._amulet_id2skill2_id_dict[amu_id]
140             skill_names = [view.VAL_NO_SKILL] + [self._skill_id2name_dict[x] for x in skill_ids]
141             self.notebook_seed2_view.set_skill_names(amu_key, skill_names)
142         self.notebook_seed2_view.set_skill_selected_idx(0)
143
144     def _init_notebook_skill2(self):
145         u""" Seed2によるSkill2一覧タブのviewの初期化 """
146         self.notebook_skill2_view = self.frame_view.notebook_skill2_view
147         self.notebook_skill2_view.bind_button_search(self.OnClickSkillSearch)
148         self.notebook_skill2_view.bind_button_clear(self.OnClickSkillClear)
149
150     def _update_notebook_amulet(self, amulet_id=None):
151         u""" お守り検索タブのviewの更新
152         amulet_id が Noneでない場合、お守りの種類に応じてComboboxを再設定する
153         また、選択中のスキルに応じて最大最小を設定する"""
154         #min1, max1, min2, max2 = self.db_accessor.get_skill_minmax()
155         #self.notebook_amulet_view.set_skill_minmax(min1, max1, min2, max2)
156
157         if amulet_id is not None:
158             for i, skill_dict in enumerate([self._amulet_id2skill1_id_dict, self._amulet_id2skill2_id_dict]):
159                 skill_ids = skill_dict[amulet_id]
160                 skill_names = [self._skill_id2name_dict[_id] for _id in skill_ids]
161                 if i == 0:
162                     self.notebook_amulet_view.set_items_skill1_combobox(skill_names)
163                     skill1_selected = skill_ids[0]
164                     self.notebook_amulet_view.set_selection_skill1_combobox(0)
165                 elif i == 1:
166                     self.notebook_amulet_view.set_items_skill2_combobox([view.VAL_NO_SKILL] + skill_names)
167                     self.notebook_amulet_view.set_selection_skill2_combobox(0)  # select No Skill
168         else:
169             amulet_name = self.notebook_amulet_view.get_selected_amulet()
170             amulet_id = self._amulet_name2id_dict[amulet_name]
171
172         # settting min max
173         skill1_str = self.notebook_amulet_view.get_string_selection_skill1_combobox()
174         skill2_str = self.notebook_amulet_view.get_string_selection_skill2_combobox()
175         skill1_id = self._skill_name2id_dict[skill1_str] if skill1_str in self._skill_name2id_dict else None
176         skill2_id = self._skill_name2id_dict[skill2_str] if skill2_str in self._skill_name2id_dict else None
177
178         if skill2_id is None:
179             minmax_dict = self.db_accessor.select_minmax_from_skill_ids(amulet_id, [skill1_id])
180             min1, max1 = minmax_dict[skill1_id][0], minmax_dict[skill1_id][1]
181             min2, max2 = 0, 0
182         else:
183             minmax_dict = self.db_accessor.select_minmax_from_skill_ids(amulet_id, [skill1_id, skill2_id])
184             min1, max1 = minmax_dict[skill1_id][0], minmax_dict[skill1_id][1]
185             min2, max2 = minmax_dict[skill2_id][2], minmax_dict[skill2_id][3]
186         self.notebook_amulet_view.set_skill_minmax(min1, max1, min2, max2)
187
188     def _update_notebook_amulet_seed2s(self):
189         u"""お守り検索タブのSeed2リストを更新する"""
190         set_items = []
191         threshold_type = self.notebook_amulet_view.get_selected_threshold_type()
192         if threshold_type == view.THRESHOLD_TYPE_ALL:
193             include_th1, include_th2, include_ini = True, True, True
194         elif threshold_type == view.THRESHOLD_TYPE_THRESHOLD1:
195             include_th1, include_th2, include_ini = True, False, False
196         elif threshold_type == view.THRESHOLD_TYPE_THRESHOLD2:
197             include_th1, include_th2, include_ini = False, True, False
198         elif threshold_type == view.THRESHOLD_TYPE_INISHIE:
199             include_th1, include_th2, include_ini = False, False, True
200
201         seed2_set = self.threshold1_seed2_set | self.threshold2_seed2_set | self.threshold_inishie_set
202         for seed in seed2_set:
203             type_set, include = [], False
204             if seed in self.threshold1_seed2_set:
205                 type_set.append(u"判定値1")
206                 if include_th1:
207                     include = True
208             if seed in self.threshold2_seed2_set:
209                 type_set.append(u"判定値2")
210                 if include_th2:
211                     include = True
212             if seed in self.threshold_inishie_set: # seed in inishie_set
213                 type_set.append(u"いにしえ")
214                 if include_ini:
215                     include = True
216             if include:
217                 set_items.append(u"{0:06d}: (".format(seed) + u",".join(type_set) + u")")
218         self.notebook_amulet_view.set_listbox_items(set_items)
219         if len(set_items) > 0:
220             self.notebook_amulet_view.set_selection_listbox(0)
221             self.notebook_amulet_view.set_skill_button_enable(True)
222         else:
223             self.notebook_amulet_view.set_skill_button_enable(False)
224
225     def _init_notebook_amulet(self):
226         u""" お守り検索タブの初期設定 """
227         self.notebook_amulet_view = self.frame_view.notebook_amulet_view
228         self.notebook_amulet_view.bind_radiobox_amulet(self.OnClickAmuletRadioAmulet)
229         self.notebook_amulet_view.bind_radiobox_threshold_type(self.OnClickAmuletRadioThresholdType)
230         self.notebook_amulet_view.bind_combobox(self.OnClickAmuletCombo)
231         self.notebook_amulet_view.bind_button_search(self.OnClickAmuletSearch)
232         self.notebook_amulet_view.bind_button_clear(self.OnClickAmuletClear)
233         self.notebook_amulet_view.bind_button_skill(self.OnClickSkillSearchFromAmulet)
234
235         amu_id = self._amulet_name2id_dict[view.NAME_AMULET1]
236         self.notebook_amulet_view.set_radio_value(True, view.NAME_AMULET1)
237         self._update_notebook_amulet(amu_id)
238
239         self.threshold1_seed2_set, self.threshold2_seed2_set, self.threshold_inishie_set = set(), set(), set()
240
241     def _init_notebook_setting(self):
242         u""" 設定タブの初期設定 """
243         self.notebook_setting_view = self.frame_view.notebook_setting_view
244         self.notebook_setting_view.bind_button_ok(self.OnClickSettingOK)
245         self.notebook_setting_view.bind_button_clear(self.OnClickSettingClear)
246         self.notebook_setting_view.set_skill_strings(self._skill_name2id_dict.keys())
247         self._update_notebook_setting()
248
249     def _update_notebook_setting(self):
250         u"""設定タブの値更新"""
251         self.notebook_setting_view.set_threshold(self._highlight_threshold1, 
252                 self._highlight_threshold2)
253         self.notebook_setting_view.set_checked_strings([self._skill_id2name_dict[x] for x in self._highlight_skills])
254
255     def _update_highlight(self):
256         u""" update highlight cells """
257         skill_names = [self._skill_id2name_dict[x] for x in self._highlight_skills]
258         self.notebook_skill2_view.set_skill2_highlight(
259                 skill_names, self._highlight_threshold1, self._highlight_threshold2)
260         self.notebook_seed1_view.update_highlight(skill_names)
261
262     u""" Seed1 view's event"""
263     def OnClickSeed1Search(self, evt):
264         u""" search seed1s from selected skill1s """
265         tenun_key = self.notebook_seed1_view.get_tenun_radio_key()
266         amu_skill_name_list = self.notebook_seed1_view.get_selected_amulets_and_names()
267         if tenun_key == view.KEY_TENUN555:
268             tenun_key = model.KEY_TENUN555
269         elif tenun_key == view.KEY_TENUN888:
270             tenun_key = model.KEY_TENUN888
271         else:
272             raise KeyError(u"key '{0}' not found in TENUN KEYS".format(tenun_key))
273         amu_skill_id_list = [(self._amulet_name2id_dict[x], self._skill_name2id_dict[y]) for x, y in amu_skill_name_list]
274         seed1s = self.db_accessor.select_seed1s_tenun(amu_skill_id_list, tenun_key)
275         if len(seed1s) == 0:
276             self.notebook_seed1_view.set_text_result(u"条件に一致するSeed1は見つかりません")
277             self.notebook_seed1_view.clear_seed1_grid()
278         elif len(seed1s) == 1:
279             seed1 = [x for x in seed1s][0]
280             table_no, no = self.db_accessor.select_table_nos_from_seed1(seed1s, tenun_key)[seed1]
281             self.notebook_seed1_view.set_text_result(
282                     u"Seed1: {0}, テーブルNo: {1}, 通し番号: {2}".format(seed1, table_no, no))
283             # list of (no, seed1)
284             near_num = view.NEAR_SEED1_NUMBERS
285             no_seed1_list = self.db_accessor.select_near_seed1s_from_seed1(
286                     seed1, near_num, near_num, tenun_key)
287             seed1_list = [x[1] for x in no_seed1_list]
288
289             # seed1 -> (no, table_no, result_num, amu_ids, skill_id2)
290             result_dict = self.db_accessor.select_all_from_seed1s(seed1_list, tenun_key)
291             for key, val in result_dict.items():
292                 _no, _table_no, _result_num, _amu_ids, _skill_ids = val
293                 _amu_names = [self._amulet_id2name_dict[x] 
294                         if x in self._amulet_id2name_dict else None for x in _amu_ids]
295                 _skill_names = [self._skill_id2name_dict[x] 
296                         if x in self._skill_id2name_dict else None for x in _skill_ids]
297                 result_dict[key] = (_no, _table_no, _result_num, _amu_names, _skill_names)
298             self.notebook_seed1_view.set_seed1_dict(result_dict, seed1)
299             skill_names = [self._skill_id2name_dict[x] for x in self._highlight_skills]
300             self.notebook_seed1_view.update_highlight(skill_names)
301         else:
302             self.notebook_seed1_view.set_text_result(
303                     u"Seed1は{0}件あります。条件を絞ってください".format(len(seed1s)))
304             self.notebook_seed1_view.clear_seed1_grid()
305
306     def OnClickSeed1Clear(self, evt):
307         u""" clear seed1s from selected skill1s """
308         self.notebook_seed1_view.clear_combobox()
309         self.notebook_seed1_view.clear_seed1_grid()
310         self.notebook_seed1_view.clear_text_result()
311
312     u""" Seed2 view's event """
313     def OnClickSeed2Search(self, evt):
314         u""" search seed2s from selected skill2s """
315         amu_id2skill_id_list_dict = {}
316         for amu_key, amu_name in zip([view.KEY_AMULET1, view.KEY_AMULET2, view.KEY_AMULET3], 
317                 [view.NAME_AMULET1, view.NAME_AMULET2, view.NAME_AMULET3]):
318             amu_id = self._amulet_name2id_dict[amu_name]
319             names = self.notebook_seed2_view.get_selected_skill_names(amu_key)
320             ls = [self._skill_name2id_dict[name] if name in self._skill_name2id_dict else None 
321                     for name in names]
322             amu_id2skill_id_list_dict[amu_id] = ls
323         seed_sets = self.db_accessor.select_seed2s(amu_id2skill_id_list_dict)
324         self.notebook_seed2_view.set_result_text(u"""Seedの候補は{0}個です。""".format(len(seed_sets)))
325
326         if len(seed_sets) > 0:
327             self.notebook_seed2_view.set_seed_lists([u"{0:06d}".format(seed) for seed in seed_sets])
328             self.notebook_seed2_view.set_skill2_button_enable(True)
329         else:
330             self.notebook_seed2_view.clear_seed_list()
331             self.notebook_seed2_view.set_skill2_button_enable(False)
332
333     def OnClickSeed2Clear(self, evt):
334         u""" reset seed2 search settings of combo box"""
335         self.notebook_seed2_view.set_skill_selected_idx(0)
336         self.notebook_seed2_view.clear_seed_list()
337         self.notebook_seed2_view.set_result_text(u"")
338         self.notebook_seed2_view.set_skill2_button_enable(False)
339
340     def OnClickSkill2SearchFromSeed2(self, evt):
341         u""" change page to skill2 search from seed2"""
342         seed2 = self.notebook_seed2_view.get_selected_seed2()
343         if seed2 is not None:
344             self.notebook_skill2_view.set_seed2_value(seed2)
345             self.frame_view.note_book.SetSelection(view.SKILL_SEARCH_PAGE)
346             self.OnClickSkillSearch(evt)
347
348     u""" Skill2 search from Seed2's event """
349     def OnClickSkillSearch(self, evt):
350         u""" skill search from seed2"""
351         seed2 = self.notebook_skill2_view.get_seed2_value()
352         if seed2 is not None:
353             skill_dict, threshold1_dict, threshold2_dict = self.db_accessor.select_skill2s_from_seed2s([seed2])
354             try:
355                 for amu_key, amu_name in zip([view.KEY_AMULET1, view.KEY_AMULET2, view.KEY_AMULET3], 
356                         [view.NAME_AMULET1, view.NAME_AMULET2, view.NAME_AMULET3]):
357                     amu_id = self._amulet_name2id_dict[amu_name]
358                     skill_names = [self._skill_id2name_dict[x] for x in skill_dict[amu_id][seed2]]
359                     self.notebook_skill2_view.set_skill2_by_col_key(amu_key, skill_names)
360                 th_vals = [u"{0}".format(x) for x in threshold1_dict[seed2]]
361                 self.notebook_skill2_view.set_skill2_by_col_key(view.KEY_THRESHOLD1, th_vals)
362                 th_vals = [u"{0}".format(x) for x in threshold2_dict[seed2]]
363                 self.notebook_skill2_view.set_skill2_by_col_key(view.KEY_THRESHOLD2, th_vals)
364                 #inishie
365                 skill_id, th1, th2 = self.db_accessor.select_inishie_skill2_from_seed2([seed2])[seed2]
366                 self.notebook_skill2_view.set_inishie(self._skill_id2name_dict[skill_id], th1, th2)
367                 # explanation
368                 table_no, no = self.db_accessor.select_table_nos_from_seed2([seed2])[seed2]
369                 self.notebook_skill2_view.set_result_text(
370                         u"SEED2:{2}は通し番号{1}、テーブルNo{0}です".format(table_no, no, seed2))
371             except KeyError, e:
372                 self._show_message_dialog(message=u"指定されたSeed値は存在しません")
373             finally:
374                 self._update_highlight()
375
376         else:
377             self._show_message_dialog(message=u"Seed値には数字を入力してください")
378
379     def OnClickSkillClear(self, evt):
380         u""" clear skills from seed """
381         self.notebook_skill2_view.clear_skill2_grid()
382         self.notebook_skill2_view.clear_skill2_highlight()
383         self.notebook_skill2_view.clear_items_amulet_prospects()
384         self.notebook_skill2_view.clear_result_text()
385         self.notebook_skill2_view.clear_inishie()
386
387     u""" amulet search event """
388     def OnClickAmuletRadioAmulet(self, evt):
389         u""" switch skill lists by amulet id """
390         #btn_id = evt.GetId()
391         amulet_name = self.notebook_amulet_view.get_selected_amulet()
392         amu_id = self._amulet_name2id_dict[amulet_name]
393         self._update_notebook_amulet(amu_id)
394         self.notebook_amulet_view.set_result_text_ctrl_value(u"")
395         self.notebook_amulet_view.set_skill_button_enable(False)
396         self.notebook_amulet_view.clear_listbox_items()
397
398     def OnClickAmuletRadioThresholdType(self, evt):
399         u""" switch seed lists by threshold_type """
400         self._update_notebook_amulet_seed2s()
401
402     def OnClickAmuletCombo(self, evt):
403         u""" switch skill minmax by amulet id and skill_id"""
404         self._update_notebook_amulet()
405
406     def OnClickAmuletSearch(self, evt):
407         u""" search seeds from amulet condition """
408         skill1_name, skill2_name = self.notebook_amulet_view.get_string_selection_skill_names()
409         skill1_val, skill2_val = self.notebook_amulet_view.get_skill_values()
410         slot_val = self.notebook_amulet_view.get_slot_value()
411         amulet_name = self.notebook_amulet_view.get_selected_amulet()
412         amu_id = self._amulet_name2id_dict[amulet_name]
413
414         if skill1_name == skill2_name:
415             self._show_message_dialog(message=u"異なるスキルを選択してください")
416         elif skill1_val == 0:
417             self._show_message_dialog(message=u"第1スキルの値には0以外を指定してください")
418         else:
419             skill1_id = self._skill_name2id_dict[skill1_name]
420             if skill2_name in self._skill_name2id_dict:
421                 skill2_id = self._skill_name2id_dict[skill2_name]
422             else:
423                 skill2_id = None # for skill2 is 0
424             suff_dict = {}
425             tup = self.db_accessor.get_sufficient_value(
426                 amu_id, skill1_id, skill2_id, skill1_val, skill2_val)
427             if tup is not None:
428                 suff_val = tup[0]
429                 (threshold, self.threshold1_seed2_set, self.threshold2_seed2_set, 
430                     self.threshold_inishie_set) = self.db_accessor.select_seed2s_from_sufficient_val(
431                         amu_id, suff_val, slot_val, skill2_id)
432                 seed2_set = self.threshold1_seed2_set | self.threshold2_seed2_set | self.threshold_inishie_set
433                 self._update_notebook_amulet_seed2s()
434                 if len(seed2_set) > 0:
435                     self.notebook_amulet_view.set_result_text_ctrl_value(
436 u"""指定されたお守りの充足値:\t{0}
437 必要な判定値:\t{1}\n判定値1:\t{2}個のSeed2で出現\n判定値2:\t{3}個のSeed2で出現\nいにしえ:\t{4}個のSeed2で出現
438 全体:\t{5}個のSeed2で出現""".format(
439                             suff_val, threshold, len(self.threshold1_seed2_set), len(self.threshold2_seed2_set), len(self.threshold_inishie_set), len(seed2_set)))
440                 else:
441                     self.notebook_amulet_view.set_result_text_ctrl_value(
442 u"""指定されたお守りの充足値:\t{0}\n必要な判定値:\t{1}
443 指定されたお守りは見つかりませんでした""".format(suff_val, threshold))
444                     self.notebook_amulet_view.set_skill_button_enable(False)
445                     self.notebook_amulet_view.clear_listbox_items()
446             else:
447                 self.threshold1_seed2_set, self.threshold2_seed2_set, self.threshold_inishie_set = set(), set(), set()
448                 self.notebook_amulet_view.set_result_text_ctrl_value(
449                     u"エラー。充足値が計算できません")
450                 self.notebook_amulet_view.set_skill_button_enable(False)
451                 self.notebook_amulet_view.clear_listbox_items()
452
453     def OnClickAmuletClear(self, evt):
454         u""" clear amulet conditions """
455         self.notebook_amulet_view.set_radio_value(True, view.NAME_AMULET1)
456         amu_id = self._amulet_name2id_dict[view.NAME_AMULET1]
457         self._update_notebook_amulet(amu_id)
458         self.notebook_amulet_view.set_skill_button_enable(False)
459         self.notebook_amulet_view.set_result_text_ctrl_value(u"")
460         self.notebook_amulet_view.clear_listbox_items()
461
462     def OnClickSkillSearchFromAmulet(self, evt):
463         u""" change page to skill search from amulet"""
464         seed = self.notebook_amulet_view.get_string_selection_listbox().split(u":")[0]
465         if seed.isdigit():
466             self.notebook_skill2_view.set_seed2_value(seed)
467             self.frame_view.note_book.SetSelection(view.SKILL_SEARCH_PAGE)
468             self.OnClickSkillSearch(evt)
469
470     u""" settings' event """
471     def OnClickSettingOK(self, evt):
472         u""" get settings of setting tab """
473         (self._highlight_threshold1, 
474                 self._highlight_threshold2) = self.frame_view.notebook_setting_view.get_threshold()
475         self._highlight_skills = set([self._skill_name2id_dict[x] for x in 
476                 self.frame_view.notebook_setting_view.get_checked_strings()
477                 if x in self._skill_name2id_dict])
478         self._update_highlight()
479
480     def OnClickSettingClear(self, evt):
481         u""" reset settings of setting tab """
482         self._highlight_threshold1 = view.HIGHLIGHT_THRESHOLD1
483         self._highlight_threshold2 = view.HIGHLIGHT_THRESHOLD2
484         self._highlight_skills = set()
485         self._update_notebook_setting()
486         self._update_highlight()
487
488
489     def _show_error_dialog(self, message=u"予期せぬエラーが発生しました", caption=u"エラー"):
490         u""" エラーダイアログを表示し、
491         OKボタンが押されたらアプリケーションを終了する
492         """
493         dlg = wx.MessageDialog(self.frame_view.frame, 
494             message,
495             caption, wx.OK | wx.ICON_ERROR)
496         dlg.ShowModal()
497         dlg.Destroy()
498         wx.Exit()
499     
500     def _show_message_dialog(self, message, caption=u"メッセージ"):
501         u""" メッセージダイアログを表示する
502         """
503         dlg = wx.MessageDialog(self.frame_view.frame, 
504             message,
505             caption, wx.OK | wx.ICON_INFORMATION)
506         dlg.ShowModal()
507         dlg.Destroy()
508
509     def CloseHandler(self, evt):
510         dlg = wx.MessageDialog(parent = self.frame_view.frame,
511                 message = u"終了します。よろしいですか?", 
512                 caption = u"終了確認", 
513                 style = wx.YES_NO)
514         result = dlg.ShowModal()
515         dlg.Destroy()
516         if result == wx.ID_YES:
517             self._write_settings()
518             wx.Exit()
519
520     def OnClose(self, evt):
521         self.frame_view.Close()
522
523     def OnAboutBox(self, evt):
524         info = self.frame_view.GetAboutInfo()
525         wx.AboutBox(info)
526
527     def _write_settings(self):
528         with open(SETTING_FILE, mode="w") as f:
529             data = {SETTING_THRESHOLD1:self._highlight_threshold1, 
530                     SETTING_THRESHOLD2:self._highlight_threshold2, 
531                     SETTING_SKILLS:self._highlight_skills}
532             pickle.dump(data, f)
533
534     def _read_settings(self):
535         if os.path.exists(SETTING_FILE):
536             with open(SETTING_FILE, mode="r") as f:
537                 try:
538                     data = pickle.load(f)
539                     self._highlight_threshold1 = data[SETTING_THRESHOLD1] 
540                     self._highlight_threshold2 = data[SETTING_THRESHOLD2] 
541                     self._highlight_skills = data[SETTING_SKILLS]
542                 except EOFError, e:
543                     self._highlight_threshold1 = view.HIGHLIGHT_THRESHOLD1
544                     self._highlight_threshold2 = view.HIGHLIGHT_THRESHOLD2
545                     self._highlight_skills = set()
546         else:
547             self._highlight_threshold1 = view.HIGHLIGHT_THRESHOLD1
548             self._highlight_threshold2 = view.HIGHLIGHT_THRESHOLD2
549             self._highlight_skills = set()
550
551 if __name__ == "__main__":
552     app = AmuletToolController(False)
553     app.MainLoop()
554