OSDN Git Service

2c587eb942ac3ff56c0f2298f3a183880d1790a2
[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))
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_inishie_skill2 = xrc.XRCCTRL(self.frame, "TextCtrlInishieSkill")
43         self.text_ctrl_inishie_threshold1 = xrc.XRCCTRL(self.frame, "TextCtrlInishieThreshold1")
44         self.text_ctrl_inishie_threshold2 = xrc.XRCCTRL(self.frame, "TextCtrlInishieThreshold2")
45
46         self.list_box_amulet_prospect = xrc.XRCCTRL(self.frame, "ListBoxSeedSkillAmuletProspect")
47         self.ID_LIST_BOX_AMULET_PROSPECT = xrc.XRCID("ListBoxSeedSkillAmuletProspect")
48
49     def OnSkill2GridSize(self, event):
50         u""" Gridリサイズ時に親パネルのwidthに応じて自動で横に伸長する """
51         width, height = self.skill2_grid.GetParent().GetSize()
52         each_width = (width - 50) / (constnumbers.NUM_SKILL2_GRID_COL) # consider margin size
53         self.skill2_grid.SetRowLabelSize(40)
54         for col in range(constnumbers.NUM_SKILL2_GRID_COL):
55             self.skill2_grid.SetColSize(col, each_width)
56
57     def bind_button_search(self, event_func, evt=wx.EVT_BUTTON):
58         u""" 検索ボタンへのイベント登録 """
59         self.button_skill2_search.Bind(evt, event_func)
60
61     def bind_button_clear(self, event_func, evt=wx.EVT_BUTTON):
62         u""" クリアボタンへのイベント登録 """
63         self.button_skill2_clear.Bind(evt, event_func)
64
65     def set_skill2_highlight(self, skill_names, threshold1, threshold2, color="Yellow"):
66         u""" スキル名、判定値1,2での条件を満たすセルをハイライトする """
67         skill_cols = [constnumbers.DICT_SKILL2_GRID_COL[x]
68                 for x in [constnumbers.KEY_AMULET1, constnumbers.KEY_AMULET2, constnumbers.KEY_AMULET3]]
69         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
70             for col in skill_cols:
71                 val = self.skill2_grid.GetCellValue(row, col)
72                 if val in skill_names:
73                     self.skill2_grid.SetCellBackgroundColour(row, col, color)
74                 else:
75                     self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
76
77         # threshold
78         th_cols = [constnumbers.DICT_SKILL2_GRID_COL[x]
79                 for x in [constnumbers.KEY_THRESHOLD1, constnumbers.KEY_THRESHOLD2]]
80         th_vals = [threshold1, threshold2]
81         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
82             for col, th_val in zip(th_cols, th_vals):
83                 val = self.skill2_grid.GetCellValue(row, col)
84                 if val.isdigit() and int(val) >= th_val:
85                     self.skill2_grid.SetCellBackgroundColour(row, col, color)
86                 else:
87                     self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
88         self._set_inishie_highlight(skill_names, threshold1, threshold2, color)
89
90     def _set_inishie_highlight(self, skill_names, threshold1, threshold2, color="Yellow"):
91         u"""いにしえの錬金結果のハイライト"""
92         val = self.text_ctrl_inishie_skill2.GetValue()
93         if val in skill_names:
94             self.text_ctrl_inishie_skill2.SetBackgroundColour(color)
95         else:
96             self.text_ctrl_inishie_skill2.SetBackgroundColour(wx.NullColor)
97
98         for txt_ctrl, th_val in zip([self.text_ctrl_inishie_threshold1, self.text_ctrl_inishie_threshold2],
99                 [threshold1, threshold2]):
100             val = txt_ctrl.GetValue()
101             if val.isdigit() and int(val) >= th_val:
102                 txt_ctrl.SetBackgroundColour(color)
103             else:
104                 txt_ctrl.SetBackgroundColour(wx.NullColor)
105
106     def clear_skill2_highlight(self):
107         u""" 表のハイライトをクリアする """
108         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
109             for col in range(constnumbers.NUM_SKILL2_GRID_COL):
110                self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
111         self.text_ctrl_inishie_skill2.SetBackgroundColour(wx.NullColor)
112         self.text_ctrl_inishie_threshold1.SetBackgroundColour(wx.NullColor)
113         self.text_ctrl_inishie_threshold2.SetBackgroundColour(wx.NullColor)
114
115     def clear_skill2_grid(self):
116         u""" セルの内容をクリアする """
117         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
118             for col in range(constnumbers.NUM_SKILL2_GRID_COL):
119                self.skill2_grid.SetCellValue(row, col, u"")
120
121     def set_skill2_by_col_key(self, column_key, values):
122         u""" キーに対応する行に値をまとめて登録する """
123         col = constnumbers.DICT_SKILL2_GRID_COL[column_key]
124         for row, val in zip( range(constnumbers.NUM_SKILL2_GRID_ROW), values):
125             self.skill2_grid.SetCellValue(row, col, val)
126
127     def set_seed2_value(self, value):
128         u""" TextCtrlに与えられた値をセットする"""
129         self.text_ctrl_seed2_select.SetValue(u"{0}".format(value))
130
131     def get_seed2_value(self):
132         u""" TextCtrlから入力されたSeed2の値を得る。数値に変換できない時はNoneを返す"""
133         seed = self.text_ctrl_seed2_select.GetValue()
134         if seed.isdigit():
135             return int(seed)
136         else:
137             return None
138
139     def set_items_amulet_prospects(self, items):
140         u""" お守り予測リストにアイテムをセットする """
141         self.list_box_amulet_prospect.SetItems(items)
142
143     def clear_items_amulet_prospects(self):
144         u""" お守り予測リストからアイテムをクリアする """
145         self.list_box_amulet_prospect.Clear()
146
147     def clear_inishie(self):
148         u""" いにしえの錬金の結果のクリア """
149         self.text_ctrl_inishie_skill2.SetValue(u"")
150         self.text_ctrl_inishie_threshold1.SetValue(u"")
151         self.text_ctrl_inishie_threshold2.SetValue(u"")
152
153     def set_inishie(self, skill_name, threshold1, threshold2):
154         u""" いにしえの錬金の対応する値のセット """
155         self.text_ctrl_inishie_skill2.SetValue(u"{0}".format(skill_name))
156         self.text_ctrl_inishie_threshold1.SetValue(u"{0}".format(threshold1))
157         self.text_ctrl_inishie_threshold2.SetValue(u"{0}".format(threshold2))