OSDN Git Service

change skill2 table to wx.Grid and implement auto column size of Grid
[amulettoolsmh4/main.git] / amulettool.py
index 8821308..b95ae2c 100644 (file)
@@ -19,6 +19,7 @@ import convertcoding
 
 SETTING_FILE = u"settings"
 SETTING_THRESHOLD1 = u"threshold1"
+SETTING_THRESHOLD2 = u"threshold2"
 SETTING_SKILLS = u"skills"
 
 def _get_base_dir():
@@ -174,8 +175,10 @@ class AmuletToolController(wx.App):
         u""" Spin Ctrlの最大最小をセット"""
         min1, max1, min2, max2 = self.db_accessor.get_skill_minmax()
         self.frame_view.spin_ctrl_amulet_search_slot_num.SetRange(view.SLOT_MIN, view.SLOT_MAX)
-        self.frame_view.spin_ctrl_highlight.SetRange(view.THRESHOLD1_MIN, view.THRESHOLD1_MAX)
-        self.frame_view.spin_ctrl_highlight.SetValue(self._highlight_threshold1)
+        self.frame_view.spin_ctrl_highlight1.SetRange(view.THRESHOLD1_MIN, view.THRESHOLD1_MAX)
+        self.frame_view.spin_ctrl_highlight2.SetRange(view.THRESHOLD2_MIN, view.THRESHOLD2_MAX)
+        self.frame_view.spin_ctrl_highlight1.SetValue(self._highlight_threshold1)
+        self.frame_view.spin_ctrl_highlight2.SetValue(self._highlight_threshold2)
 
     def _set_check_list_views(self):
         u""" CheckListBoxの値のセット """
@@ -245,16 +248,17 @@ class AmuletToolController(wx.App):
         if seed.isdigit():
             seed = int(seed)
             skill_dict, threshold1_dict = self.db_accessor.select_skills_from_seeds([seed])
-
+            grid = self.frame_view.skill2_grid
             try:
-                text_ctrl_dict = self.frame_view.text_ctrl_seed_skill_dict
                 for amu_key, amu_name in zip([view.KEY_AMULET1, view.KEY_AMULET2, view.KEY_AMULET3], 
                     [view.NAME_AMULET1, view.NAME_AMULET2, view.NAME_AMULET3]):
                     amu_id = self._amulet_name2id_dict[amu_name]
-                    for txt_ctr, skill_id in zip(text_ctrl_dict[amu_key], skill_dict[amu_id][seed]):
-                        txt_ctr.SetValue(self._skill_id2name_dict[skill_id])
-                for txt_ctr, threshold1 in zip(text_ctrl_dict[view.KEY_THRESHOLD1], threshold1_dict[seed]):
-                    txt_ctr.SetValue(u"{0}".format(threshold1))
+                    amu_col = view.DICT_SKILL2_GRID_COL[amu_key]
+                    for row, skill_id in enumerate(skill_dict[amu_id][seed]):
+                        grid.SetCellValue(row, amu_col, self._skill_id2name_dict[skill_id])
+                th1_col = view.DICT_SKILL2_GRID_COL[view.KEY_THRESHOLD1]
+                for row, threshold1 in enumerate(threshold1_dict[seed]):
+                    grid.SetCellValue(row, th1_col, u"{0}".format(threshold1))
                 self._update_highlight()
 
             except KeyError, e:
@@ -264,15 +268,13 @@ class AmuletToolController(wx.App):
 
     def OnClickSkillClear(self, evt):
         u""" clear skills from seed """
-        text_ctrl_dict = self.frame_view.text_ctrl_seed_skill_dict
-        for amu_key, amu_name in zip([view.KEY_AMULET1, view.KEY_AMULET2, view.KEY_AMULET3], 
-            [view.NAME_AMULET1, view.NAME_AMULET2, view.NAME_AMULET3]):
-            amu_id = self._amulet_name2id_dict[amu_name]
-            for txt_ctr in text_ctrl_dict[amu_key]:
-                txt_ctr.Clear()
-        for txt_ctr in text_ctrl_dict[view.KEY_THRESHOLD1]:
-            txt_ctr.Clear()
+
+        grid = self.frame_view.skill2_grid
+        for row in range(view.NUM_SKILL2_GRID_ROW):
+            for col in range(view.NUM_SKILL2_GRID_COL):
+                grid.SetCellValue(row, col, "")
         self.frame_view.list_box_seed_skill_amulet_prospect.Clear() 
+        self._update_highlight()
 
     def OnClickAmuletRadio(self, evt):
         u""" switch skill lists by amulet id """
@@ -375,7 +377,8 @@ class AmuletToolController(wx.App):
 
     def OnClickSettingOK(self, evt):
         u""" get settings of setting tab """
-        self._highlight_threshold1 = self.frame_view.spin_ctrl_highlight.GetValue()
+        self._highlight_threshold1 = self.frame_view.spin_ctrl_highlight1.GetValue()
+        self._highlight_threshold2 = self.frame_view.spin_ctrl_highlight2.GetValue()
         self._highlight_skills = set([self._skill_name2id_dict[x] for x in 
                 self.frame_view.check_list_box_highlight_skill.GetCheckedStrings()
                 if x in self._skill_name2id_dict])
@@ -384,7 +387,9 @@ class AmuletToolController(wx.App):
     def OnClickSettingClear(self, evt):
         u""" reset settings of setting tab """
         self._highlight_threshold1 = view.HIGHLIGHT_THRESHOLD1
-        self.frame_view.spin_ctrl_highlight.SetValue(view.HIGHLIGHT_THRESHOLD1)
+        self._highlight_threshold2 = view.HIGHLIGHT_THRESHOLD2
+        self.frame_view.spin_ctrl_highlight1.SetValue(view.HIGHLIGHT_THRESHOLD1)
+        self.frame_view.spin_ctrl_highlight2.SetValue(view.HIGHLIGHT_THRESHOLD2)
         self._highlight_skills = set()
         for idx in self.frame_view.check_list_box_highlight_skill.GetChecked():
             self.frame_view.check_list_box_highlight_skill.Check(idx, False)
@@ -392,21 +397,23 @@ class AmuletToolController(wx.App):
 
     def _update_highlight(self):
         u""" update highlight cells """
-        text_dict = self.frame_view.text_ctrl_seed_skill_dict
+        grid = self.frame_view.skill2_grid
         for key in [view.KEY_AMULET1, view.KEY_AMULET2, view.KEY_AMULET3]:
-            for text_ctrl in text_dict[key]:
-                val = text_ctrl.GetValue()
+            col = view.DICT_SKILL2_GRID_COL[key]
+            for row in range(view.NUM_SKILL2_GRID_ROW):
+                val = grid.GetCellValue(row, col)
                 if (val in self._skill_name2id_dict and
                         self._skill_name2id_dict[val] in self._highlight_skills):
-                    text_ctrl.SetBackgroundColour("Yellow")
+                    grid.SetCellBackgroundColour(row, col, "Yellow")
                 else:
-                    text_ctrl.SetBackgroundColour(wx.NullColor)
-        for text_ctrl in text_dict[view.KEY_THRESHOLD1]:
-            val = text_ctrl.GetValue()
+                    grid.SetCellBackgroundColour(row, col, wx.NullColor)
+        col = view.DICT_SKILL2_GRID_COL[view.KEY_THRESHOLD1]
+        for row in range(view.NUM_SKILL2_GRID_ROW):
+            val = grid.GetCellValue(row, col)
             if val.isdigit() and int(val) >= self._highlight_threshold1:
-                text_ctrl.SetBackgroundColour("Yellow")
+                grid.SetCellBackgroundColour(row, col, "Yellow")
             else:
-                text_ctrl.SetBackgroundColour(wx.NullColor)
+                grid.SetCellBackgroundColour(row, col, wx.NullColor)
 
 
     def _show_error_dialog(self, message=u"予期せぬエラーが発生しました", caption=u"エラー"):
@@ -450,6 +457,7 @@ class AmuletToolController(wx.App):
     def _write_settings(self):
         with open(SETTING_FILE, mode="w") as f:
             data = {SETTING_THRESHOLD1:self._highlight_threshold1, 
+                    SETTING_THRESHOLD2:self._highlight_threshold2, 
                     SETTING_SKILLS:self._highlight_skills}
             pickle.dump(data, f)
 
@@ -459,12 +467,15 @@ class AmuletToolController(wx.App):
                 try:
                     data = pickle.load(f)
                     self._highlight_threshold1 = data[SETTING_THRESHOLD1] 
+                    self._highlight_threshold2 = data[SETTING_THRESHOLD2] 
                     self._highlight_skills = data[SETTING_SKILLS]
                 except EOFError, e:
                     self._highlight_threshold1 = view.HIGHLIGHT_THRESHOLD1
+                    self._highlight_threshold2 = view.HIGHLIGHT_THRESHOLD2
                     self._highlight_skills = set()
         else:
             self._highlight_threshold1 = view.HIGHLIGHT_THRESHOLD1
+            self._highlight_threshold2 = view.HIGHLIGHT_THRESHOLD2
             self._highlight_skills = set()
 
 if __name__ == "__main__":