OSDN Git Service

revise amulet search to consider of seed1 value,
[amulettoolsmh4/main.git] / view / notebookamuletview.py
index 8a587a7..3f79f19 100644 (file)
@@ -13,6 +13,7 @@ class NoteBookAmuletView():
     def __init__(self, frame):
         self.frame = frame
         self._init_view()
+        self._init_event()
 
     def _init_view(self):
         # initialize view
@@ -20,18 +21,33 @@ class NoteBookAmuletView():
         # button
         self.button_search = xrc.XRCCTRL(self.frame, "ButtonAmuletSearchSearch")
         self.button_clear = xrc.XRCCTRL(self.frame, "ButtonAmuletSearchClear")
-        self.button_skill = xrc.XRCCTRL(self.frame, "ButtonAmuletSearchSkill")
+        self.button_skill = xrc.XRCCTRL(self.frame, "ButtonAmuletSearchSkill2")
         self.ID_BUTTON_SEARCH = xrc.XRCID("ButtonAmuletSearchSearch")
         self.ID_BUTTON_CLEAR = xrc.XRCID("ButtonAmuletSearchClear")
-        self.ID_BUTTON_SKILL = xrc.XRCID("ButtonAmuletSearchSkill")
+        self.ID_BUTTON_SKILL = xrc.XRCID("ButtonAmuletSearchSkill2")
 
         # radio button
         self.radiobox_amulet = xrc.XRCCTRL(self.frame, "RadioBoxAmulet")
         self.radiobox_threshold_type = xrc.XRCCTRL(self.frame, "RadioBoxThresholdType")
 
-        # seed list
-        self.list_box_seeds = xrc.XRCCTRL(self.frame, "ListBoxAmuletSearchSeeds")
-        self.ID_LIST_BOX_SEEDS = xrc.XRCID("ListBoxAmuletSearchSeeds")
+        # seed2s list
+        self.grid_seed2s = xrc.XRCCTRL(self.frame, "GridAmuletSeed2s")
+        self.grid_seed2s.CreateGrid(1, constnumbers.NUM_AMULET_SEED2S_GRID_COL)
+        self.grid_seed2s.SetColLabelValue(0, constnumbers.LABEL_FORMAT_AMULET_SEED2S_GRID_COL1)
+        self.grid_seed2s.SetColLabelValue(1, constnumbers.LABEL_FORMAT_AMULET_SEED2S_GRID_COL2)
+        self.grid_seed2s.SetColLabelValue(2, constnumbers.LABEL_FORMAT_AMULET_SEED2S_GRID_COL3)
+        self.grid_seed2s.DisableDragGridSize()
+        self.grid_seed2s.EnableEditing(False)
+        self.grid_seed2s.SetSelectionMode(wx.grid.Grid.wxGridSelectRows)
+
+        # seed1s list
+        self.grid_seed1s = xrc.XRCCTRL(self.frame, "GridAmuletSeed1s")
+        self.grid_seed1s.CreateGrid(1, constnumbers.NUM_AMULET_SEED1S_GRID_COL)
+        self.grid_seed1s.SetColLabelValue(0, constnumbers.LABEL_FORMAT_AMULET_SEED1S_GRID_COL1)
+        self.grid_seed1s.SetColLabelValue(1, constnumbers.LABEL_FORMAT_AMULET_SEED1S_GRID_COL2)
+        self.grid_seed1s.DisableDragGridSize()
+        self.grid_seed1s.EnableEditing(False)
+        self.grid_seed1s.SetRowLabelSize(1)
 
         # spin ctrl
         self.spin_ctrl_skill1_val = xrc.XRCCTRL(self.frame, "SpinCtrlAmuletSearchSkill1Value")
@@ -52,6 +68,27 @@ class NoteBookAmuletView():
         # set min & max of slot
         self.set_slot_minmax(constnumbers.SLOT_MIN, constnumbers.SLOT_MAX)
 
+    def _init_event(self):
+        # initialize event
+        self.grid_seed1s.Bind(wx.EVT_SIZE, self.OnSeed1GridSizeChanged)
+        self.grid_seed2s.Bind(wx.EVT_SIZE, self.OnSeed2GridSizeChanged)
+
+    def OnSeed1GridSizeChanged(self, event):
+        u""" Seed1Gridサイズの変更時 """
+        width, height = self.grid_seed1s.GetParent().GetSize()
+        each_width = (width) / (constnumbers.NUM_AMULET_SEED1S_GRID_COL) # consider margin size
+        self.grid_seed1s.SetRowLabelValue(0, u"")
+        for col in range(constnumbers.NUM_AMULET_SEED1S_GRID_COL):
+            self.grid_seed1s.SetColSize(col, each_width)
+
+    def OnSeed2GridSizeChanged(self, event):
+        u""" Seed2Gridサイズの変更時 """
+        width, height = self.grid_seed2s.GetParent().GetSize()
+        each_width = (width - 60) / (constnumbers.NUM_AMULET_SEED2S_GRID_COL) # consider margin size
+        self.grid_seed2s.SetRowLabelSize(45)
+        for col in range(constnumbers.NUM_AMULET_SEED2S_GRID_COL):
+            self.grid_seed2s.SetColSize(col, each_width)
+
     def bind_radiobox_amulet(self, event_func, evt=wx.EVT_RADIOBOX):
         u""" お守り種類のラジオボタンが押された時のイベントをセットする """
         self.radiobox_amulet.Bind(evt, event_func)
@@ -202,22 +239,77 @@ class NoteBookAmuletView():
         u""" 結果表示用のTextCtrlに値をセットする """
         self.text_ctrl_result.SetValue(value)
 
-    def set_listbox_items(self, items):
-        u""" Seed一覧のListBoxに値をセットする。
+    def set_grid_seed2s_items(self, items_dict):
+        u""" Seed2一覧のGridに値をセットする。
+        引数はSeed2 -> (str_renkin_type, tenun555_num, tenun888)の辞書とする。
         Noneが与えられた時はClearする"""
-        if items is not None:
-            self.list_box_seeds.SetItems(items)
-        else:
-            self.list_box_seeds.Clear()
-
-    def get_string_selection_listbox(self):
-        u""" Seed一覧のListBoxの選択された値を得る。"""
-        return self.list_box_seeds.GetStringSelection()
 
-    def set_selection_listbox(self, idx):
-        u""" Seed一覧のListBoxの選択されたインデックスをセットする。"""
-        self.list_box_seeds.SetSelection(idx)
-
-    def clear_listbox_items(self):
-        u""" Seed一覧のListBoxから値をClearする"""
-        self.list_box_seeds.Clear()
+        if items_dict is not None:
+            row_num = len(items_dict)
+            diff = row_num - self.grid_seed2s.GetNumberRows()
+            if diff > 0:
+                self.grid_seed2s.AppendRows(diff, False)
+            elif diff < 0:
+                self.grid_seed2s.DeleteRows(0, -diff, False)
+
+            for row, seed2 in enumerate(sorted(items_dict.keys())):
+                self.grid_seed2s.SetRowLabelValue(row, u"{0}".format(seed2))
+                renkin_type, tenun555_num, tenun888_num = items_dict[seed2]
+                self.grid_seed2s.SetCellValue(row, 0, renkin_type)
+                self.grid_seed2s.SetCellValue(row, 1, u"{0}".format(tenun555_num))
+                self.grid_seed2s.SetCellValue(row, 2, u"{0}".format(tenun888_num))
+        else:
+            self.clear_grid_seed2s()
+
+    def set_grid_seed1s_items(self, tenun555_seed1s, tenun888_seed1s):
+        u""" Seed1一覧のGridに天運555と天運888のSeed1の値をセットする。"""
+        self.clear_grid_seed1s()
+        max_len = max([len(tenun555_seed1s, tenun888_seed2s)])
+        diff = max_len - self.grid_seed2s.GetNumberRows()
+        if diff > 0:
+            self.grid_seed1s.AppendRows(diff, False)
+        elif diff < 0:
+            self.grid_seed1s.DeleteRows(0, -diff, False)
+
+        for row in range(max_len):
+            self.grid_seed1s.SetRowLabelValue(row, u"")
+        for row, seed1 in enumerate(sorted(tenun555_seed1s)):
+            self.grid_seed1s.SetCellValue(row, 0, seed1)
+        for row, seed1 in enumerate(sorted(tenun888_seed1s)):
+            self.grid_seed1s.SetCellValue(row, 1, seed1)
+
+    def get_grid_selected_seed2(self):
+        u""" Seed2一覧のGridの選択されたSeed2の値を得る。"""
+        rows = [x for x in self.grid_seed2s.GetSelectedRows()]
+        print rows
+        if len(rows) > 0:
+            return int(self.grid_seed2s.GetRowLabelValue(rows[0]))
+        else:
+            return None
+
+    def set_grid_seed2s_selected_idx(self, idx):
+        u""" Seed2一覧のGridの選択された行を選択状態にする。"""
+        if idx >= 0 and idx < self.grid_seed2s.GetNumberRows():
+            self.grid_seed2s.MakeCellVisible(idx, 0)
+            self.grid_seed2s.SelectRow(idx)
+
+    def clear_grid_seed2s(self):
+        u""" Seed2一覧のGridから値をClearする"""
+        for row in range(self.grid_seed2s.GetNumberRows()):
+            self.grid_seed2s.SetRowLabelValue(row, u"")
+            for col in range(self.grid_seed2s.GetNumberCols()):
+                self.grid_seed2s.SetCellValue(row, col, u"")
+        self.grid_seed2s.ClearSelection()
+
+    def clear_grid_seed1s(self):
+        u""" Seed1一覧のGridから値をClearする"""
+        for row in range(self.grid_seed1s.GetNumberRows()):
+            self.grid_seed1s.SetRowLabelValue(row, u"")
+            for col in range(self.grid_seed1s.GetNumberCols()):
+                self.grid_seed1s.SetCellValue(row, col, u"")
+        self.grid_seed1s.ClearSelection()
+
+    def clear_grid(self):
+        u"""Gridの値をクリアする"""
+        self.clear_grid_seed1s()
+        self.clear_grid_seed2s()