OSDN Git Service

d145fa300a4e69d0678f66407dc48c318cac243a
[amulettoolsmh4/main.git] / amulettool.py
1 # -*- coding: utf-8 -*-
2
3 # お守りスキルのSeed特定ツールのコントロールクラス
4 # 2013/12/04 written by kei9
5
6 import threading
7 import time
8 import os.path
9
10 import wx
11
12 import view
13 import model
14
15
16 class AmuletToolController(wx.App):
17     u""" アプリケーションの制御クラス """
18     def OnInit(self):
19         self.frame_view = view.MainFrameView("view")
20         
21         self._init_events()
22
23         self.frame_view.Show()
24
25         self._init_database()
26         return True
27
28     def _init_events(self):
29         u"""イベント登録"""
30         frame = self.frame_view.frame
31
32         # menu event
33         frame.Bind(wx.EVT_MENU, self.OnClose, id=self.frame_view.ID_MENU_ITEM_EXIT)
34         frame.Bind(wx.EVT_MENU, self.OnAboutBox, id=self.frame_view.ID_MENU_ITEM_ABOUT)
35
36     def _init_database(self):
37         u""" DBの初期設定 """
38
39         if not os.path.exists(model.DB_FILE_NAME):
40             u""" DBが存在しない時は再生成する """
41             frame = self.frame_view.frame
42             generator = model.DataBaseGenerator(model.DB_FILE_NAME)
43             #generator = model.DataBaseGenerator()
44
45             dlg_view = view.GaugeDialogView("view")
46             def _loop():
47                 while t1.is_alive():
48                     dlg_view.gauge.Pulse()
49                     time.sleep(0.2)
50                 dlg_view.finish_generation()
51
52             t1 = threading.Thread(target=generator.generate_db)
53             t2 = threading.Thread(target=_loop)
54             t1.start()
55             t2.start()
56
57             dlg_view.ShowModal()
58             t1.join()
59             t2.join()
60             dlg_view.Destroy()
61
62         # access to db
63         db_accessor = model.DataBaseAccessor(model.DB_FILE_NAME)
64
65
66
67
68     def OnClose(self, evt):
69         self.frame_view.Close()
70
71     def OnAboutBox(self, evt):
72         info = self.frame_view.GetAboutInfo()
73         wx.AboutBox(info)
74
75 if __name__ == "__main__":
76     app = AmuletToolController(False)
77     app.MainLoop()