OSDN Git Service

revise database generator for seed1 decision & threshold2 & inishie
[amulettoolsmh4/main.git] / view / notebookskill2view.py
1 # -*- coding: utf-8 -*-
2
3 # GUIのメインフレームにおけるSkill2一覧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 class NoteBookSkill2View():
12     u""" メインのフレームのスキル2一覧タブ """
13     def __init__(self, frame):
14         self.frame = frame
15         self._init_view()
16
17     def _init_view(self):
18         # initialize view
19         self.skill2_grid = xrc.XRCCTRL(self.frame, "GridSecondSkill")
20         self.ID_SKILL2_GRID = xrc.XRCID("GridSecondSkill")
21         self.skill2_grid.Bind(wx.EVT_SIZE, self.OnSkill2GridSize)
22
23         self.button_skill2_search = xrc.XRCCTRL(self.frame, "ButtonSeedSkillSearch")
24         self.button_skill2_clear = xrc.XRCCTRL(self.frame, "ButtonSeedSkillClear")
25         self.ID_BUTTON_SKILL2_SEARCH = xrc.XRCID("ButtonSeedSkillSearch")
26         self.ID_BUTTON_SKILL2_CLEAR = xrc.XRCID("ButtonSeedSkillClear")
27
28         # load skill2 grid value
29         self.skill2_grid.CreateGrid(constnumbers.NUM_SKILL2_GRID_ROW, constnumbers.NUM_SKILL2_GRID_COL)
30         self.skill2_grid.SetColLabelValue(0, constnumbers.NAME_AMULET1)
31         self.skill2_grid.SetColLabelValue(1, constnumbers.NAME_AMULET2)
32         self.skill2_grid.SetColLabelValue(2, constnumbers.NAME_AMULET3)
33         self.skill2_grid.SetColLabelValue(3, constnumbers.NAME_THRESHOLD1)
34         self.skill2_grid.SetColLabelValue(4, constnumbers.NAME_THRESHOLD2)
35         for i in range(constnumbers.NUM_SKILL2_GRID_ROW):
36             self.skill2_grid.SetRowLabelValue(i, constnumbers.LABEL_FORMAT_SKILL2_GRID_ROW.format(i+1))
37         self.skill2_grid.DisableDragGridSize()
38         self.skill2_grid.EnableEditing(False)
39
40         # text ctrl
41         self.text_ctrl_seed2_select = xrc.XRCCTRL(self.frame, "TextCtrlSeedSelect")
42         self.text_ctrl_result = xrc.XRCCTRL(self.frame, "TextCtrlSkillResult")
43         self.text_ctrl_inishie_skill2 = xrc.XRCCTRL(self.frame, "TextCtrlInishieSkill")
44         self.text_ctrl_inishie_threshold1 = xrc.XRCCTRL(self.frame, "TextCtrlInishieThreshold1")
45         self.text_ctrl_inishie_threshold2 = xrc.XRCCTRL(self.frame, "TextCtrlInishieThreshold2")
46
47         self.list_box_amulet_prospect = xrc.XRCCTRL(self.frame, "ListBoxSeedSkillAmuletProspect")
48         self.ID_LIST_BOX_AMULET_PROSPECT = xrc.XRCID("ListBoxSeedSkillAmuletProspect")
49
50     def OnSkill2GridSize(self, event):
51         u""" Gridリサイズ時に親パネルのwidthに応じて自動で横に伸長する """
52         width, height = self.skill2_grid.GetParent().GetSize()
53         each_width = (width - 50) / (constnumbers.NUM_SKILL2_GRID_COL) # consider margin size
54         self.skill2_grid.SetRowLabelSize(40)
55         for col in range(constnumbers.NUM_SKILL2_GRID_COL):
56             self.skill2_grid.SetColSize(col, each_width)
57
58     def bind_button_search(self, event_func, evt=wx.EVT_BUTTON):
59         u""" 検索ボタンへのイベント登録 """
60         self.button_skill2_search.Bind(evt, event_func)
61
62     def bind_button_clear(self, event_func, evt=wx.EVT_BUTTON):
63         u""" クリアボタンへのイベント登録 """
64         self.button_skill2_clear.Bind(evt, event_func)
65
66     def set_skill2_highlight(self, skill_names, threshold1, threshold2, color="Yellow"):
67         u""" スキル名、判定値1,2での条件を満たすセルをハイライトする """
68         skill_cols = [constnumbers.DICT_SKILL2_GRID_COL[x]
69                 for x in [constnumbers.KEY_AMULET1, constnumbers.KEY_AMULET2, constnumbers.KEY_AMULET3]]
70         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
71             for col in skill_cols:
72                 val = self.skill2_grid.GetCellValue(row, col)
73                 if val in skill_names:
74                     self.skill2_grid.SetCellBackgroundColour(row, col, color)
75                 else:
76                     self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
77
78         # threshold
79         th_cols = [constnumbers.DICT_SKILL2_GRID_COL[x]
80                 for x in [constnumbers.KEY_THRESHOLD1, constnumbers.KEY_THRESHOLD2]]
81         th_vals = [threshold1, threshold2]
82         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
83             for col, th_val in zip(th_cols, th_vals):
84                 val = self.skill2_grid.GetCellValue(row, col)
85                 if val.isdigit() and int(val) >= th_val:
86                     self.skill2_grid.SetCellBackgroundColour(row, col, color)
87                 else:
88                     self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
89         self._set_inishie_highlight(skill_names, threshold1, threshold2, color)
90
91     def _set_inishie_highlight(self, skill_names, threshold1, threshold2, color="Yellow"):
92         u"""いにしえの錬金結果のハイライト"""
93         val = self.text_ctrl_inishie_skill2.GetValue()
94         if val in skill_names:
95             self.text_ctrl_inishie_skill2.SetBackgroundColour(color)
96         else:
97             self.text_ctrl_inishie_skill2.SetBackgroundColour(wx.NullColor)
98
99         for txt_ctrl, th_val in zip([self.text_ctrl_inishie_threshold1, self.text_ctrl_inishie_threshold2],
100                 [threshold1, threshold2]):
101             val = txt_ctrl.GetValue()
102             if val.isdigit() and int(val) >= th_val:
103                 txt_ctrl.SetBackgroundColour(color)
104             else:
105                 txt_ctrl.SetBackgroundColour(wx.NullColor)
106
107     def clear_skill2_highlight(self):
108         u""" 表のハイライトをクリアする """
109         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
110             for col in range(constnumbers.NUM_SKILL2_GRID_COL):
111                self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
112         self.text_ctrl_inishie_skill2.SetBackgroundColour(wx.NullColor)
113         self.text_ctrl_inishie_threshold1.SetBackgroundColour(wx.NullColor)
114         self.text_ctrl_inishie_threshold2.SetBackgroundColour(wx.NullColor)
115
116     def clear_skill2_grid(self):
117         u""" セルの内容をクリアする """
118         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
119             for col in range(constnumbers.NUM_SKILL2_GRID_COL):
120                self.skill2_grid.SetCellValue(row, col, u"")
121
122     def set_result_text(self, value):
123         u""" 結果の表示TextCtrlのセット """
124         self.text_ctrl_result.SetValue(value)
125
126     def clear_result_text(self):
127         u""" 結果の表示TextCtrlのクリア """
128         self.text_ctrl_result.SetValue(u"")
129
130     def set_skill2_by_col_key(self, column_key, values):
131         u""" キーに対応する行に値をまとめて登録する """
132         col = constnumbers.DICT_SKILL2_GRID_COL[column_key]
133         for row, val in zip( range(constnumbers.NUM_SKILL2_GRID_ROW), values):
134             self.skill2_grid.SetCellValue(row, col, val)
135
136     def set_seed2_value(self, value):
137         u""" TextCtrlに与えられた値をセットする"""
138         self.text_ctrl_seed2_select.SetValue(u"{0}".format(value))
139
140     def get_seed2_value(self):
141         u""" TextCtrlから入力されたSeed2の値を得る。数値に変換できない時はNoneを返す"""
142         seed = self.text_ctrl_seed2_select.GetValue()
143         if seed.isdigit():
144             return int(seed)
145         else:
146             return None
147
148     def set_items_amulet_prospects(self, items):
149         u""" お守り予測リストにアイテムをセットする """
150         self.list_box_amulet_prospect.SetItems(items)
151
152     def clear_items_amulet_prospects(self):
153         u""" お守り予測リストからアイテムをクリアする """
154         self.list_box_amulet_prospect.Clear()
155
156     def clear_inishie(self):
157         u""" いにしえの錬金の結果のクリア """
158         self.text_ctrl_inishie_skill2.SetValue(u"")
159         self.text_ctrl_inishie_threshold1.SetValue(u"")
160         self.text_ctrl_inishie_threshold2.SetValue(u"")
161
162     def set_inishie(self, skill_name, threshold1, threshold2):
163         u""" いにしえの錬金の対応する値のセット """
164         self.text_ctrl_inishie_skill2.SetValue(u"{0}".format(skill_name))
165         self.text_ctrl_inishie_threshold1.SetValue(u"{0}".format(threshold1))
166         self.text_ctrl_inishie_threshold2.SetValue(u"{0}".format(threshold2))