OSDN Git Service

change skill2 table to wx.Grid and implement auto column size of Grid
[amulettoolsmh4/main.git] / amulettool.py
index e52b0e1..b95ae2c 100644 (file)
@@ -1,3 +1,4 @@
+#!/usr/bin/python
 # -*- coding: utf-8 -*-
 
 # お守りスキルのSeed特定ツールのコントロールクラス
@@ -14,9 +15,11 @@ import wx
 
 import view
 import model
+import convertcoding
 
 SETTING_FILE = u"settings"
 SETTING_THRESHOLD1 = u"threshold1"
+SETTING_THRESHOLD2 = u"threshold2"
 SETTING_SKILLS = u"skills"
 
 def _get_base_dir():
@@ -26,14 +29,16 @@ def _get_base_dir():
         basedir = sys._MEIPASS
     else:
         # we are running in a normal Python environment
-        basedir = os.path.dirname(__file__)
-    return basedir
+        #1basedir = os.path.dirname(__file__)
+        basedir = os.path.dirname(os.path.abspath(__file__))
+    return convertcoding.convert_unicode(basedir)
+
 
 class AmuletToolController(wx.App):
     u""" アプリケーションの制御クラス """
     def OnInit(self):
         self._read_settings()
-        self.frame_view = view.MainFrameView(os.path.join(_get_base_dir(), "view", view.XRC_MAIN_FRAME))
+        self.frame_view = view.MainFrameView(os.path.join(_get_base_dir(), u"view", view.XRC_MAIN_FRAME))
 
         self._init_events()
 
@@ -87,7 +92,7 @@ class AmuletToolController(wx.App):
                 generator = model.DataBaseGenerator(model.DB_FILE_NAME)
                 #generator = model.DataBaseGenerator()
 
-                dlg_view = view.GaugeDialogView(os.path.join(_get_base_dir(), "view", view.XRC_GAUGE_DIALOG))
+                dlg_view = view.GaugeDialogView(os.path.join(_get_base_dir(), u"view", view.XRC_GAUGE_DIALOG))
                 def _loop():
                     while t1.is_alive():
                         dlg_view.gauge.Pulse()
@@ -170,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の値のセット """
@@ -241,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:
@@ -260,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 """
@@ -371,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])
@@ -380,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)
@@ -388,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"エラー"):
@@ -446,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)
 
@@ -455,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__":