OSDN Git Service

revise amulet search to consider of seed1 value,
[amulettoolsmh4/main.git] / view / notebookamuletview.py
index 1af4dd3..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,30 +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.radio_button_amulet1 = xrc.XRCCTRL(self.frame, "RadioButtonAmulet1")
-        self.radio_button_amulet2 = xrc.XRCCTRL(self.frame, "RadioButtonAmulet2")
-        self.radio_button_amulet3 = xrc.XRCCTRL(self.frame, "RadioButtonAmulet3")
-        self.ID_RADIO_BUTTON_AMULET1 = xrc.XRCID("RadioButtonAmulet1")
-        self.ID_RADIO_BUTTON_AMULET2 = xrc.XRCID("RadioButtonAmulet2")
-        self.ID_RADIO_BUTTON_AMULET3 = xrc.XRCID("RadioButtonAmulet3")
-        self.amulet2radio_button_dict = {}
-        self.amulet2radio_button_dict[constnumbers.NAME_AMULET1] = self.radio_button_amulet1
-        self.amulet2radio_button_dict[constnumbers.NAME_AMULET2] = self.radio_button_amulet2
-        self.amulet2radio_button_dict[constnumbers.NAME_AMULET3] = self.radio_button_amulet3
-        self.amulet2radio_id_dict = {}
-        self.amulet2radio_id_dict[constnumbers.NAME_AMULET1] = self.ID_RADIO_BUTTON_AMULET1
-        self.amulet2radio_id_dict[constnumbers.NAME_AMULET2] = self.ID_RADIO_BUTTON_AMULET2
-        self.amulet2radio_id_dict[constnumbers.NAME_AMULET3] = self.ID_RADIO_BUTTON_AMULET3
-
-        # seed list
-        self.list_box_seeds = xrc.XRCCTRL(self.frame, "ListBoxAmuletSearchSeeds")
-        self.ID_LIST_BOX_SEEDS = xrc.XRCID("ListBoxAmuletSearchSeeds")
+        self.radiobox_amulet = xrc.XRCCTRL(self.frame, "RadioBoxAmulet")
+        self.radiobox_threshold_type = xrc.XRCCTRL(self.frame, "RadioBoxThresholdType")
+
+        # 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")
@@ -64,11 +68,34 @@ class NoteBookAmuletView():
         # set min & max of slot
         self.set_slot_minmax(constnumbers.SLOT_MIN, constnumbers.SLOT_MAX)
 
-    def bind_radio_button(self, event_func, evt=wx.EVT_RADIOBUTTON):
-        u""" ラジオボタンが押された時のイベントをセットする """
-        self.radio_button_amulet1.Bind(evt, event_func)
-        self.radio_button_amulet2.Bind(evt, event_func)
-        self.radio_button_amulet3.Bind(evt, event_func)
+    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)
+
+    def bind_radiobox_threshold_type(self, event_func, evt=wx.EVT_RADIOBOX):
+        u""" 判定値の種類のラジオボタンが押された時のイベントをセットする """
+        self.radiobox_threshold_type.Bind(evt, event_func)
 
     def bind_combobox(self, event_func, evt=wx.EVT_COMBOBOX):
         u""" コンボボタンが押された時のイベントをセットする """
@@ -111,27 +138,56 @@ class NoteBookAmuletView():
         u""" ラジオボタンの値をセットする 
             arg: (value, amulet_name)
         """
-        self.amulet2radio_button_dict[amulet_name].SetValue(value)
+        if amulet_name == constnumbers.NAME_AMULET1:
+            idx = 0
+        elif amulet_name == constnumbers.NAME_AMULET2:
+            idx = 1
+        elif amulet_name == constnumbers.NAME_AMULET3:
+            idx = 2
+        self.radiobox_amulet.SetSelection(idx)
 
     def get_radio_value(self, amulet_name=constnumbers.NAME_AMULET1):
         u""" ラジオボタンの値を得る
             return: (value)
         """
-        return self.amulet2radio_button_dict[amulet_name].GetValue()
-
-    def get_selected_radio_name(self):
-        u""" 選択されているラジオボタンのお守り名を得る 
+        if amulet_name == constnumbers.NAME_AMULET1:
+            idx = 0
+        elif amulet_name == constnumbers.NAME_AMULET2:
+            idx = 1
+        elif amulet_name == constnumbers.NAME_AMULET3:
+            idx = 2
+        return self.radiobox_amulet.GetSelection() == idx
+
+    def get_selected_amulet(self):
+        u""" 選択されているお守り名を得る 
             return: (NAME_OF_AMULET)
         """
-        if self.amulet2radio_button_dict[constnumbers.NAME_AMULET1].GetValue:
+        idx = self.radiobox_amulet.GetSelection()
+        if idx == 0:
             return constnumbers.NAME_AMULET1
-        elif self.amulet2radio_button_dict[constnumbers.NAME_AMULET2].GetValue:
+        elif idx == 1:
             return constnumbers.NAME_AMULET2
-        elif self.amulet2radio_button_dict[constnumbers.NAME_AMULET3].GetValue:
+        elif idx == 2:
             return constnumbers.NAME_AMULET3
         else:
             raise NotImplementedError("irregular radio button selected")
 
+    def get_selected_threshold_type(self):
+        u""" 選択されているラジオボタンの検索種類IDを得る
+            return: (THRESHOLD_TYPE_ID)
+        """
+        idx = self.radiobox_threshold_type.GetSelection()
+        if idx == 0:
+            return constnumbers.THRESHOLD_TYPE_ALL
+        elif idx == 1:
+            return constnumbers.THRESHOLD_TYPE_THRESHOLD1
+        elif idx == 2:
+            return constnumbers.THRESHOLD_TYPE_THRESHOLD2
+        elif idx == 3:
+            return constnumbers.THRESHOLD_TYPE_INISHIE
+        else:
+            raise NotImplementedError("irregular radio button selected")
+
     def set_selection_skill1_combobox(self, idx):
         u""" skill1のコンボボックスの選択されたインデックスをセットする """
         self.combo_box_skill1.SetSelection(idx)
@@ -183,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()