OSDN Git Service

revise database generator for seed1 decision & threshold2 & inishie
[amulettoolsmh4/main.git] / view / notebookseed1view.py
1 # -*- coding: utf-8 -*-
2
3 # GUIのメインフレームにおけるSeed1特定Notebookのview
4 # 2013/12/15 written by kei9
5 import wx
6 from wx import xrc
7 import wx.grid
8
9 import constnumbers
10
11
12 class NoteBookSeed1View():
13     u""" メインのフレームのSeed1特定タブ """
14     SEPARATER = u"/"
15     def __init__(self, frame):
16         self.frame = frame
17         self._init_view()
18         self._init_event()
19
20     def _init_view(self):
21         # initialize view
22
23         # buttons
24         self.radiobox_tenun = xrc.XRCCTRL(self.frame, "RadioBoxTenun")
25         self.button_search = xrc.XRCCTRL(self.frame, "ButtonSeed1Search")
26         self.button_clear = xrc.XRCCTRL(self.frame, "ButtonSeed1Clear")
27
28         self.spin_ctrl_amulet_num = xrc.XRCCTRL(self.frame, "SpinCtrlSeed1AmuletNum")
29
30         # load combo boxes
31         self.combobox_amulet_list = [xrc.XRCCTRL(self.frame, "ComboBoxSeed1Amulet1"),
32                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Amulet2"),
33                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Amulet3"),
34                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Amulet4"),
35                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Amulet5"),
36                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Amulet6"),
37                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Amulet7")]
38         self.combobox_skill_list = [xrc.XRCCTRL(self.frame, "ComboBoxSeed1Skill1"),
39                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Skill2"),
40                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Skill3"),
41                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Skill4"),
42                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Skill5"),
43                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Skill6"),
44                 xrc.XRCCTRL(self.frame, "ComboBoxSeed1Skill7")]
45
46         # text ctrl
47         self.text_ctrl_result = xrc.XRCCTRL(self.frame, "TextCtrl1Seed1Result")
48
49         # grid
50         self.grid_seed1 = xrc.XRCCTRL(self.frame, "GridSeed1Table")
51         u"""Tableを結果TextCtrlで示し、No.をrowラベル、行にはseed1, 天運個数、
52         1-7枠目の値を表示する。1-7枠目をお守りの種類とスキル名で分けると面倒なので
53         合体させて1つの行で表示した方がいいかもしれない。この場合は行数は9となる"""
54         self.grid_seed1.CreateGrid(constnumbers.NUM_SEED1_GRID_ROW, constnumbers.NUM_SEED1_GRID_COL)
55         self.grid_seed1.SetColLabelValue(0, constnumbers.LABEL_FORMAT_SEED1_GRID_COL1)
56         self.grid_seed1.SetColLabelValue(1, constnumbers.LABEL_FORMAT_SEED1_GRID_COL2)
57         for i in range(2, constnumbers.NUM_SEED1_GRID_COL):
58             self.grid_seed1.SetColLabelValue(i, 
59                     constnumbers.LABEL_FORMAT_SEED1_GRID_COL_AFTER2.format(i-1))
60         self.grid_seed1.DisableDragGridSize()
61         self.grid_seed1.EnableEditing(False)
62
63         self._amulet_names = []
64         self._amuletname2skillnames_dict = {}
65
66     def set_amuletname_skillnames_dict(self, amulet_names, amuletname2skillnames_dict):
67         u"""お守り名とそのお守りに対応する第1スキルの辞書をセットする"""
68         self._amulet_names = amulet_names
69         self._amuletname2skillnames_dict = amuletname2skillnames_dict
70         for amu_combo, skill_combo in zip(self.combobox_amulet_list, self.combobox_skill_list):
71             amu_combo.SetItems(self._amulet_names)
72             amu_combo.SetSelection(0)
73             skill_combo.SetItems(self._amuletname2skillnames_dict[self._amulet_names[0]])
74             skill_combo.SetSelection(0)
75
76     def _init_event(self):
77         u""" イベントの登録 """
78         self.spin_ctrl_amulet_num.Bind(wx.EVT_SPINCTRL, self.OnSpinCtrlChanged)
79         self.grid_seed1.Bind(wx.EVT_SIZE, self.OnGridSizeChanged)
80         for amu_combo in self.combobox_amulet_list:
81             amu_combo.Bind(wx.EVT_COMBOBOX, self.OnAmuletComboChanged)
82
83     def OnSpinCtrlChanged(self, event):
84         u""" SpinCtrlの値が変わった時のイベント。
85         設定できるコンボボックスの数を調節する """
86         val = self.spin_ctrl_amulet_num.GetValue()
87         for combo1, combo2 in zip(self.combobox_amulet_list[:val], self.combobox_skill_list[:val]):
88             combo1.Enable()
89             combo2.Enable()
90         for combo1, combo2 in zip(self.combobox_amulet_list[val:], self.combobox_skill_list[val:]):
91             combo1.Disable()
92             combo2.Disable()
93
94     def OnGridSizeChanged(self, event):
95         u""" Gridサイズの変更時 """
96         width, height = self.grid_seed1.GetParent().GetSize()
97         each_width = (width - 60) / (constnumbers.NUM_SEED1_GRID_COL) # consider margin size
98         self.grid_seed1.SetRowLabelSize(45)
99         for col in range(constnumbers.NUM_SEED1_GRID_COL):
100             self.grid_seed1.SetColSize(col, each_width) 
101
102     def OnAmuletComboChanged(self, event):
103         u""" お守りの種類を選択するコンボボックス変更時 """
104         obj = event.GetEventObject()
105         for amu_combo, skill_combo in zip(self.combobox_amulet_list, self.combobox_skill_list):
106             if obj == amu_combo:
107                 amu_name = amu_combo.GetStringSelection()
108                 if amu_name in self._amuletname2skillnames_dict:
109                     skill_combo.SetItems(self._amuletname2skillnames_dict[amu_name])
110                     skill_combo.SetSelection(0)
111                 break
112
113     def bind_button_search(self, event_func, evt=wx.EVT_BUTTON):
114         u""" 検索ボタンへのイベント登録 """
115         self.button_search.Bind(evt, event_func)
116
117     def bind_button_clear(self, event_func, evt=wx.EVT_BUTTON):
118         u""" クリアボタンへのイベント登録 """
119         self.button_clear.Bind(evt, event_func)
120
121     def get_tenun_radio_key(self):
122         u""" 天運の錬金で使用したお守りの種類を示すkeyを返す """
123         idx = self.radiobox_tenun.GetSelection()
124         if idx == 0:
125             return constnumbers.KEY_TENUN555
126         elif idx == 1:
127             return constnumbers.KEY_TENUN888
128         else:
129             return None
130
131     def get_selected_amulets_and_names(self):
132         u"""選択されているお守りの種類名とスキル1の名前のペアをリストとして返す"""
133         result_num = self.spin_ctrl_amulet_num.GetValue()
134         result_list = []
135         for i, amu_combo, skill_combo in zip(
136                 range(result_num), self.combobox_amulet_list, self.combobox_skill_list):
137             amulet_name = amu_combo.GetStringSelection()
138             skill_name = skill_combo.GetStringSelection()
139             result_list.append((amulet_name, skill_name))
140         return result_list
141
142     def clear_highlight(self):
143         u""" セルの強調表示をクリアする """
144         for row in range(self.grid_seed1.GetNumberRows()):
145             for col in range(self.grid_seed1.GetNumberCols()):
146                 self.grid_seed1.SetCellBackgroundColour(row, col, wx.NullColor)
147
148     def update_highlight(self, skill_names, color=u"Yellow"):
149         u""" 指定されたスキル名に一致するセルを強調表示する """
150         for row in range(self.grid_seed1.GetNumberRows()):
151             for col in range(2, self.grid_seed1.GetNumberCols()):
152                 val = self.grid_seed1.GetCellValue(row, col)
153                 try:
154                     amu_name, skill_name = val.split(self.SEPARATER)
155                     if skill_name in skill_names:
156                         self.grid_seed1.SetCellBackgroundColour(row, col, color)
157                     else:
158                         self.grid_seed1.SetCellBackgroundColour(row, col, wx.NullColor)
159                 except ValueError as e:
160                     #cannot unpack
161                     self.grid_seed1.SetCellBackgroundColour(row, col, wx.NullColor)
162
163     def set_seed1_dict(self, seed1_dict, select_seed1=None):
164         u""" seed1から(no, table_no, result_num, amulet_names, skill_names)への辞書を元に、
165         noを列ラベルとする表を作成する
166         select_seed1がNoneでなければ、対応する行を選択状態とする"""
167         row_num = len(seed1_dict)
168         diff = row_num - self.grid_seed1.GetNumberRows()
169         if diff > 0:
170             self.grid_seed1.AppendRows(diff, False)
171         elif diff < 0:
172             self.grid_seed1.DeleteRows(0, -diff, False)
173
174         for row, seed1 in enumerate(
175                 sorted(seed1_dict.keys(), key=lambda x: seed1_dict[x][0])): # order by no
176             no, table_no, result_num, amu_names, skill_names = seed1_dict[seed1]
177             self.grid_seed1.SetRowLabelValue(row, u"{0}".format(no))
178             self.grid_seed1.SetCellValue(row, 0, "{0}".format(seed1))
179             self.grid_seed1.SetCellValue(row, 1, "{0}".format(result_num))
180             for col, amu_name, skill_name in zip(
181                     range(2, constnumbers.NUM_SEED1_GRID_COL), amu_names, skill_names):
182                 if amu_name is not None and skill_name is not None:
183                     val = u"{0}{1}{2}".format(
184                         constnumbers.AMULET_NAME_TO_SHORT_NAME_DICT[amu_name], self.SEPARATER, skill_name)
185                     self.grid_seed1.SetCellValue(row, col, val)
186                 else:
187                     self.grid_seed1.SetCellValue(row, col, u"")
188             if seed1 == select_seed1:
189                 self.grid_seed1.MakeCellVisible(row, 0)
190                 self.grid_seed1.SelectRow(row)
191
192     def clear_combobox(self):
193         u""" comboboxの選択されたインデックスを0にする """
194         for amu_combo, skill_combo in zip(self.combobox_amulet_list, self.combobox_skill_list):
195             amu_combo.SetSelection(0)
196             skill_combo.SetSelection(0)
197
198     def clear_seed1_grid(self):
199         u""" 表の値をクリアする """
200         for row in range(self.grid_seed1.GetNumberRows()):
201             self.grid_seed1.SetRowLabelValue(row, u"")
202             for col in range(self.grid_seed1.GetNumberCols()):
203                 self.grid_seed1.SetCellValue(row, col, u"")
204         self.clear_highlight()
205
206     def clear_text_result(self):
207         u""" 結果を示すTextCtrlから値のクリア """
208         self.text_ctrl_result.SetValue(u"")
209
210     def set_text_result(self, value):
211         u""" 結果を示すTextCtrlへの値のセット """
212         self.text_ctrl_result.SetValue(value)
213