OSDN Git Service

change skill2 table to wx.Grid and implement auto column size of Grid
[amulettoolsmh4/main.git] / view / mainframeview.py
1 # -*- coding: utf-8 -*-
2
3 # GUIのメインフレーム
4 # 2013/12/05 written by kei9
5 import wx
6 from wx import xrc
7 import wx.grid
8
9 import constnumbers
10
11 class MainFrameView():
12     u""" メインのフレームクラス """
13     def __init__(self, filename):
14         self.res = wx.xrc.XmlResource(filename)
15         self._init_frame()
16
17     def _init_frame(self):
18         # load controls
19         self.frame = self.res.LoadFrame(None, "MainFrame")
20
21         self.note_book = xrc.XRCCTRL(self.frame, "NoteBookMain")
22
23         # buttons
24         self.button_seed_seaerch = xrc.XRCCTRL(self.frame, "ButtonSeedSearch")
25         self.button_seed_clear = xrc.XRCCTRL(self.frame, "ButtonSeedClear")
26         self.button_skill_from_seed_search = xrc.XRCCTRL(self.frame, "ButtonSkillFromSeedSearch")
27         self.button_skill_search = xrc.XRCCTRL(self.frame, "ButtonSeedSkillSearch")
28         self.button_skill_clear = xrc.XRCCTRL(self.frame, "ButtonSeedSkillClear")
29         self.button_amulet_search_seaerch = xrc.XRCCTRL(self.frame, "ButtonAmuletSearchSearch")
30         self.button_amulet_search_clear = xrc.XRCCTRL(self.frame, "ButtonAmuletSearchClear")
31         self.button_amulet_search_skill = xrc.XRCCTRL(self.frame, "ButtonAmuletSearchSkill")
32         self.button_setting_ok = xrc.XRCCTRL(self.frame, "ButtonSettingOK")
33         self.button_setting_clear = xrc.XRCCTRL(self.frame, "ButtonSettingClear")
34
35         self.ID_BUTTON_SEED_SEARCH = xrc.XRCID("ButtonSeedSearch")
36         self.ID_BUTTON_SEED_CLEAR = xrc.XRCID("ButtonSeedClear")
37         self.ID_BUTTON_SKILL_FROM_SEED_SEARCH = xrc.XRCID("ButtonSkillFromSeedSearch")
38         self.ID_BUTTON_SKILL_SEARCH = xrc.XRCID("ButtonSeedSkillSearch")
39         self.ID_BUTTON_SKILL_CLEAR = xrc.XRCID("ButtonSeedSkillClear")
40         self.ID_BUTTON_AMULET_SEARCH_SEARCH = xrc.XRCID("ButtonAmuletSearchSearch")
41         self.ID_BUTTON_AMULET_SEARCH_CLEAR = xrc.XRCID("ButtonAmuletSearchClear")
42         self.ID_BUTTON_AMULET_SEARCH_SKILL = xrc.XRCID("ButtonAmuletSearchSkill")
43         self.ID_BUTTON_SETTING_OK = xrc.XRCID("ButtonSettingOK")
44         self.ID_BUTTON_SETTING_CLEAR = xrc.XRCID("ButtonSettingClear")
45
46         # radio button
47         self.radio_button_amulet1 = xrc.XRCCTRL(self.frame, "RadioButtonAmulet1")
48         self.radio_button_amulet2 = xrc.XRCCTRL(self.frame, "RadioButtonAmulet2")
49         self.radio_button_amulet3 = xrc.XRCCTRL(self.frame, "RadioButtonAmulet3")
50         self.ID_RADIO_BUTTON_AMULET1 = xrc.XRCID("RadioButtonAmulet1")
51         self.ID_RADIO_BUTTON_AMULET2 = xrc.XRCID("RadioButtonAmulet2")
52         self.ID_RADIO_BUTTON_AMULET3 = xrc.XRCID("RadioButtonAmulet3")
53         self.amulet2radio_button_dict = {}
54         self.amulet2radio_button_dict[constnumbers.NAME_AMULET1] = self.radio_button_amulet1
55         self.amulet2radio_button_dict[constnumbers.NAME_AMULET2] = self.radio_button_amulet2
56         self.amulet2radio_button_dict[constnumbers.NAME_AMULET3] = self.radio_button_amulet3
57         self.amulet2radio_id_dict = {}
58         self.amulet2radio_id_dict[constnumbers.NAME_AMULET1] = self.ID_RADIO_BUTTON_AMULET1
59         self.amulet2radio_id_dict[constnumbers.NAME_AMULET2] = self.ID_RADIO_BUTTON_AMULET2
60         self.amulet2radio_id_dict[constnumbers.NAME_AMULET3] = self.ID_RADIO_BUTTON_AMULET3
61
62         #load grid
63         self.skill2_grid = xrc.XRCCTRL(self.frame, "GridSecondSkill")
64         self.ID_SKILL2_GRID = xrc.XRCID("GridSecondSkill")
65         self._load_grid()
66         self.skill2_grid.Bind(wx.EVT_SIZE, self.OnGridSize)
67
68         # menu
69         self.ID_MENU_ITEM_EXIT = xrc.XRCID("wxID_EXIT") # same as wx.ID_EXIT
70         self.ID_MENU_ITEM_ABOUT = xrc.XRCID("wxID_ABOUT") # same as wx.ID_ABOUT
71
72         # load text ctrls
73         self._load_text_ctrls()
74
75         # load combo box
76         self._load_combo_boxes()
77
78         # load list box
79         self.list_box_seed = xrc.XRCCTRL(self.frame, "ListBoxSeed")
80         self.list_box_amulet_search_seeds = xrc.XRCCTRL(self.frame, "ListBoxAmuletSearchSeeds")
81         self.list_box_seed_skill_amulet_prospect = xrc.XRCCTRL(self.frame, "ListBoxSeedSkillAmuletProspect")
82         self.ID_LIST_BOX_SEED = xrc.XRCID("ListBoxSeed")
83         self.ID_LIST_BOX_AMULET_SEARCH_SEEDS = xrc.XRCID("ListBoxAmuletSearchSeeds")
84         self.ID_LIST_BOX_SEED_SKILL_AMULET_PROSPECT = xrc.XRCID("ListBoxSeedSkillAmuletProspect")
85
86         # load spin ctrl
87         self.spin_ctrl_amulet_search_skill1_val = xrc.XRCCTRL(self.frame, "SpinCtrlAmuletSearchSkill1Value")
88         self.spin_ctrl_amulet_search_skill2_val = xrc.XRCCTRL(self.frame, "SpinCtrlAmuletSearchSkill2Value")
89         self.spin_ctrl_amulet_search_slot_num = xrc.XRCCTRL(self.frame, "SpinCtrlAmuletSearchSlotNumber")
90         self.ID_SPIN_CTRL_AMULET_SKILL1_VAL = xrc.XRCID("SpinCtrlAmuletSearchSkill1Value")
91         self.ID_SPIN_CTRL_AMULET_SKILL2_VAL = xrc.XRCID("SpinCtrlAmuletSearchSkill2Value")
92         self.spin_ctrl_highlight1 = xrc.XRCCTRL(self.frame, "SpinCtrlHighlightThreshold1")
93         self.spin_ctrl_highlight2 = xrc.XRCCTRL(self.frame, "SpinCtrlHighlightThreshold2")
94
95         # load custom ctrl
96         self.ID_CHECK_LIST_BOX_HIGHLIGHT_SKILL = xrc.XRCID("CheckListBoxHighlight")
97         self.check_list_box_highlight_skill =  xrc.XRCCTRL(self.frame, "CheckListBoxHighlight")
98
99         # set explanation text
100         self.text_ctrl_seed_explain.SetValue(constnumbers.SEED_DECISION_EXPLANATION)
101         self.text_ctrl_flow.SetValue(constnumbers.SECOND_SKILL_FLOW)
102
103     def _load_combo_boxes(self):
104         # load combo boxes
105         self.combo_box_skill_dict = {}
106         self.combo_box_skill_dict[constnumbers.KEY_AMULET1] = [
107                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet1_1"),
108                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet1_2"),
109                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet1_3"),
110                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet1_4"),
111                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet1_5"),
112                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet1_6"),
113                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet1_7")]
114         self.combo_box_skill_dict[constnumbers.KEY_AMULET2] = [
115                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet2_1"),
116                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet2_2"),
117                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet2_3"),
118                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet2_4"),
119                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet2_5"),
120                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet2_6"),
121                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet2_7")]
122         self.combo_box_skill_dict[constnumbers.KEY_AMULET3] = [
123                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet3_1"),
124                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet3_2"),
125                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet3_3"),
126                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet3_4"),
127                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet3_5"),
128                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet3_6"),
129                 xrc.XRCCTRL(self.frame, "ComboBoxAmulet3_7")]
130         self.combo_box_amulet_search_skill1 = xrc.XRCCTRL(self.frame, "ComboBoxAmuletSearchSkill1")
131         self.combo_box_amulet_search_skill2 = xrc.XRCCTRL(self.frame, "ComboBoxAmuletSearchSkill2")
132         self.ID_COMBO_BOX_AMULET_SEARCH_SKILL1 = xrc.XRCID("ComboBoxAmuletSearchSkill1")
133         self.ID_COMBO_BOX_AMULET_SEARCH_SKILL2 = xrc.XRCID("ComboBoxAmuletSearchSkill2")
134
135     def _load_text_ctrls(self):
136         # load text ctrls
137         self.text_ctrl_seed_explain = xrc.XRCCTRL(self.frame, "TextCtrlSeedExplain")
138         self.text_ctrl_seed_result = xrc.XRCCTRL(self.frame, "TextCtrlSeedResults")
139         self.text_ctrl_seed_select = xrc.XRCCTRL(self.frame, "TextCtrlSeedSelect")
140         self.text_ctrl_amulet_search_result = xrc.XRCCTRL(self.frame, "TextCtrlAmuletSearchResult")
141         self.text_ctrl_flow = xrc.XRCCTRL(self.frame, "TextCtrlFlow")
142
143     def _load_grid(self):
144         # load grid value
145         self.skill2_grid.CreateGrid(constnumbers.NUM_SKILL2_GRID_ROW, constnumbers.NUM_SKILL2_GRID_COL)
146         self.skill2_grid.SetColLabelValue(0, constnumbers.NAME_AMULET1)
147         self.skill2_grid.SetColLabelValue(1, constnumbers.NAME_AMULET2)
148         self.skill2_grid.SetColLabelValue(2, constnumbers.NAME_AMULET3)
149         self.skill2_grid.SetColLabelValue(3, constnumbers.NAME_THRESHOLD1)
150         self.skill2_grid.SetColLabelValue(4, constnumbers.NAME_THRESHOLD2)
151         for i in range(constnumbers.NUM_SKILL2_GRID_ROW):
152             self.skill2_grid.SetRowLabelValue(i, constnumbers.LABEL_FORMAT_SKILL2_GRID_ROW.format(i))
153         self.skill2_grid.DisableDragGridSize()
154         self.skill2_grid.EnableEditing(False)
155
156     def OnGridSize(self, event):
157         width, height = self.skill2_grid.GetParent().GetSize()
158         each_width = (width - 50) / (constnumbers.NUM_SKILL2_GRID_COL) # consider margin size
159         self.skill2_grid.SetRowLabelSize(40)
160         for col in range(constnumbers.NUM_SKILL2_GRID_COL):
161             self.skill2_grid.SetColSize(col, each_width) 
162
163     def Show(self):
164         self.frame.Show()
165
166     def Close(self):
167         self.frame.Close(True)
168
169     def DisableNoteBook(self):
170         self.note_book.Disable()
171
172     def EnableNoteBook(self):
173         self.note_book.Enable()
174         
175     def OnAboutBox(self, evt):
176         u""" Show About Box """
177         info = wx.AboutDialogInfo()
178         info.Name = constnumbers.NAME
179         info.Version = constnumbers.VERSION
180         info.Copyright = constnumbers.COPYRIGHT
181         info.Description = constnumbers.DESCRIPTION
182         info.WebSite = (constnumbers.WEBSITE_LINK, constnumbers.WEBSITE_TEXT)
183         info.Developers = constnumbers.DEVELOPERS
184         info.License = constnumbers.LICENSE_TEXT
185         wx.AboutBox(info)
186
187     def GetAboutInfo(self):
188         u""" create About info """
189         info = wx.AboutDialogInfo()
190         info.Name = constnumbers.NAME
191         info.Version = constnumbers.VERSION
192         info.Copyright = constnumbers.COPYRIGHT
193         info.Description = constnumbers.DESCRIPTION
194         info.WebSite = (constnumbers.WEBSITE_LINK, constnumbers.WEBSITE_TEXT)
195         info.Developers = constnumbers.DEVELOPERS
196         info.License = constnumbers.LICENSE_TEXT
197         return info
198
199 if __name__ == "__main__":
200     app = wx.App(False)
201     mainframe = MainFrameView(u"mainframe.xrc")
202     mainframe.Show()
203     app.MainLoop()