OSDN Git Service

change skill2 table to wx.Grid and implement auto column size of Grid
[amulettoolsmh4/main.git] / view / mainframeview.py
index 9854315..6306087 100644 (file)
@@ -4,7 +4,7 @@
 # 2013/12/05 written by kei9
 import wx
 from wx import xrc
-import wx.lib.intctrl
+import wx.grid
 
 import constnumbers
 
@@ -59,6 +59,12 @@ class MainFrameView():
         self.amulet2radio_id_dict[constnumbers.NAME_AMULET2] = self.ID_RADIO_BUTTON_AMULET2
         self.amulet2radio_id_dict[constnumbers.NAME_AMULET3] = self.ID_RADIO_BUTTON_AMULET3
 
+        #load grid
+        self.skill2_grid = xrc.XRCCTRL(self.frame, "GridSecondSkill")
+        self.ID_SKILL2_GRID = xrc.XRCID("GridSecondSkill")
+        self._load_grid()
+        self.skill2_grid.Bind(wx.EVT_SIZE, self.OnGridSize)
+
         # menu
         self.ID_MENU_ITEM_EXIT = xrc.XRCID("wxID_EXIT") # same as wx.ID_EXIT
         self.ID_MENU_ITEM_ABOUT = xrc.XRCID("wxID_ABOUT") # same as wx.ID_ABOUT
@@ -83,22 +89,12 @@ class MainFrameView():
         self.spin_ctrl_amulet_search_slot_num = xrc.XRCCTRL(self.frame, "SpinCtrlAmuletSearchSlotNumber")
         self.ID_SPIN_CTRL_AMULET_SKILL1_VAL = xrc.XRCID("SpinCtrlAmuletSearchSkill1Value")
         self.ID_SPIN_CTRL_AMULET_SKILL2_VAL = xrc.XRCID("SpinCtrlAmuletSearchSkill2Value")
-        self.spin_ctrl_highlight = xrc.XRCCTRL(self.frame, "SpinCtrlHighlightThreshold1")
+        self.spin_ctrl_highlight1 = xrc.XRCCTRL(self.frame, "SpinCtrlHighlightThreshold1")
+        self.spin_ctrl_highlight2 = xrc.XRCCTRL(self.frame, "SpinCtrlHighlightThreshold2")
 
         # load custom ctrl
-        panel = xrc.XRCCTRL(self.frame, "CheckListBoxPos")
-        #panel = xrc.XRCCTRL(self.frame, "NoteBookPanelSettings")
-        self.ID_CHECK_LIST_BOX_HIGHLIGHT_SKILL = wx.NewId()
-        #self.check_list_box_highlight_skill = wx.CheckListBox(self.frame, self.ID_CHECK_LIST_BOX_HIGHLIGHT_SKILL)
-        self.check_list_box_highlight_skill = wx.CheckListBox(panel, id=self.ID_CHECK_LIST_BOX_HIGHLIGHT_SKILL,
-                name="CheckListBoxHighlightSkills")
-        #self.res.AttachUnknownControl("CheckListBoxHighlightSkills", self.check_list_box_highlight_skill, panel) # list isn't shown. why?
-
-        vbox = wx.BoxSizer(wx.VERTICAL)
-        vbox.Add(self.check_list_box_highlight_skill, 1, wx.EXPAND)
-        panel.SetSizer(vbox)
-
-        #panel.Fit()
+        self.ID_CHECK_LIST_BOX_HIGHLIGHT_SKILL = xrc.XRCID("CheckListBoxHighlight")
+        self.check_list_box_highlight_skill =  xrc.XRCCTRL(self.frame, "CheckListBoxHighlight")
 
         # set explanation text
         self.text_ctrl_seed_explain.SetValue(constnumbers.SEED_DECISION_EXPLANATION)
@@ -143,39 +139,26 @@ class MainFrameView():
         self.text_ctrl_seed_select = xrc.XRCCTRL(self.frame, "TextCtrlSeedSelect")
         self.text_ctrl_amulet_search_result = xrc.XRCCTRL(self.frame, "TextCtrlAmuletSearchResult")
         self.text_ctrl_flow = xrc.XRCCTRL(self.frame, "TextCtrlFlow")
-        self.text_ctrl_seed_skill_dict = {}
-        self.text_ctrl_seed_skill_dict[constnumbers.KEY_AMULET1] = [
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet1_1"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet1_2"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet1_3"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet1_4"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet1_5"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet1_6"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet1_7")]
-        self.text_ctrl_seed_skill_dict[constnumbers.KEY_AMULET2] = [
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet2_1"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet2_2"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet2_3"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet2_4"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet2_5"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet2_6"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet2_7")]
-        self.text_ctrl_seed_skill_dict[constnumbers.KEY_AMULET3] = [
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet3_1"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet3_2"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet3_3"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet3_4"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet3_5"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet3_6"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillAmulet3_7")]
-        self.text_ctrl_seed_skill_dict[constnumbers.KEY_THRESHOLD1] = [
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillThreshold1_1"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillThreshold1_2"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillThreshold1_3"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillThreshold1_4"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillThreshold1_5"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillThreshold1_6"),
-                xrc.XRCCTRL(self.frame, "TextCtrlSeedSkillThreshold1_7")]
+
+    def _load_grid(self):
+        # load grid value
+        self.skill2_grid.CreateGrid(constnumbers.NUM_SKILL2_GRID_ROW, constnumbers.NUM_SKILL2_GRID_COL)
+        self.skill2_grid.SetColLabelValue(0, constnumbers.NAME_AMULET1)
+        self.skill2_grid.SetColLabelValue(1, constnumbers.NAME_AMULET2)
+        self.skill2_grid.SetColLabelValue(2, constnumbers.NAME_AMULET3)
+        self.skill2_grid.SetColLabelValue(3, constnumbers.NAME_THRESHOLD1)
+        self.skill2_grid.SetColLabelValue(4, constnumbers.NAME_THRESHOLD2)
+        for i in range(constnumbers.NUM_SKILL2_GRID_ROW):
+            self.skill2_grid.SetRowLabelValue(i, constnumbers.LABEL_FORMAT_SKILL2_GRID_ROW.format(i))
+        self.skill2_grid.DisableDragGridSize()
+        self.skill2_grid.EnableEditing(False)
+
+    def OnGridSize(self, event):
+        width, height = self.skill2_grid.GetParent().GetSize()
+        each_width = (width - 50) / (constnumbers.NUM_SKILL2_GRID_COL) # consider margin size
+        self.skill2_grid.SetRowLabelSize(40)
+        for col in range(constnumbers.NUM_SKILL2_GRID_COL):
+            self.skill2_grid.SetColSize(col, each_width) 
 
     def Show(self):
         self.frame.Show()
@@ -215,6 +198,6 @@ class MainFrameView():
 
 if __name__ == "__main__":
     app = wx.App(False)
-    mainframe = MainFrameView()
+    mainframe = MainFrameView(u"mainframe.xrc")
     mainframe.Show()
     app.MainLoop()