36 |
36 |
37 def GetTypeList(): |
37 def GetTypeList(): |
38 _ = lambda x: x |
38 _ = lambda x: x |
39 return [_("Action"), _("Variable"), _("Inline")] |
39 return [_("Action"), _("Variable"), _("Inline")] |
40 |
40 |
41 class ActionTable(wx.grid.PyGridTableBase): |
41 class ActionTable(CustomTable): |
42 |
42 |
43 """ |
|
44 A custom wx.Grid Table using user supplied data |
|
45 """ |
|
46 def __init__(self, parent, data, colnames): |
|
47 # The base class must be initialized *first* |
|
48 wx.grid.PyGridTableBase.__init__(self) |
|
49 self.data = data |
|
50 self.colnames = colnames |
|
51 self.Parent = parent |
|
52 # XXX |
|
53 # we need to store the row length and collength to |
|
54 # see if the table has changed size |
|
55 self._rows = self.GetNumberRows() |
|
56 self._cols = self.GetNumberCols() |
|
57 |
|
58 def GetNumberCols(self): |
|
59 return len(self.colnames) |
|
60 |
|
61 def GetNumberRows(self): |
|
62 return len(self.data) |
|
63 |
|
64 def GetColLabelValue(self, col, translate=True): |
|
65 if col < len(self.colnames): |
|
66 colname = self.colnames[col] |
|
67 if translate: |
|
68 return _(colname) |
|
69 return colname |
|
70 |
|
71 def GetRowLabelValues(self, row, translate=True): |
|
72 return row |
|
73 |
|
74 def GetValue(self, row, col): |
43 def GetValue(self, row, col): |
75 if row < self.GetNumberRows(): |
44 if row < self.GetNumberRows(): |
76 colname = self.GetColLabelValue(col, False) |
45 colname = self.GetColLabelValue(col, False) |
77 name = str(self.data[row].get(colname, "")) |
46 name = str(self.data[row].get(colname, "")) |
78 if colname == "Type": |
47 if colname == "Type": |
79 return _(name) |
48 return _(name) |
80 return name |
49 return name |
81 |
50 |
82 def GetValueByName(self, row, colname): |
|
83 return self.data[row].get(colname) |
|
84 |
|
85 def SetValue(self, row, col, value): |
51 def SetValue(self, row, col, value): |
86 if col < len(self.colnames): |
52 if col < len(self.colnames): |
87 colname = self.GetColLabelValue(col, False) |
53 colname = self.GetColLabelValue(col, False) |
88 if colname == "Type": |
54 if colname == "Type": |
89 value = self.Parent.TranslateType[value] |
55 value = self.Parent.TranslateType[value] |
90 self.data[row][colname] = value |
56 self.data[row][colname] = value |
91 |
57 |
92 def ResetView(self, grid): |
|
93 """ |
|
94 (wx.Grid) -> Reset the grid view. Call this to |
|
95 update the grid if rows and columns have been added or deleted |
|
96 """ |
|
97 grid.BeginBatch() |
|
98 for current, new, delmsg, addmsg in [ |
|
99 (self._rows, self.GetNumberRows(), wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED), |
|
100 (self._cols, self.GetNumberCols(), wx.grid.GRIDTABLE_NOTIFY_COLS_DELETED, wx.grid.GRIDTABLE_NOTIFY_COLS_APPENDED), |
|
101 ]: |
|
102 if new < current: |
|
103 msg = wx.grid.GridTableMessage(self,delmsg,new,current-new) |
|
104 grid.ProcessTableMessage(msg) |
|
105 elif new > current: |
|
106 msg = wx.grid.GridTableMessage(self,addmsg,new-current) |
|
107 grid.ProcessTableMessage(msg) |
|
108 self.UpdateValues(grid) |
|
109 grid.EndBatch() |
|
110 |
|
111 self._rows = self.GetNumberRows() |
|
112 self._cols = self.GetNumberCols() |
|
113 # update the column rendering scheme |
|
114 self._updateColAttrs(grid) |
|
115 |
|
116 # update the scrollbars and the displayed part of the grid |
|
117 grid.AdjustScrollbars() |
|
118 grid.ForceRefresh() |
|
119 |
|
120 def UpdateValues(self, grid): |
|
121 """Update all displayed values""" |
|
122 # This sends an event to the grid table to update all of the values |
|
123 msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_REQUEST_VIEW_GET_VALUES) |
|
124 grid.ProcessTableMessage(msg) |
|
125 |
|
126 def _updateColAttrs(self, grid): |
58 def _updateColAttrs(self, grid): |
127 """ |
59 """ |
128 wx.Grid -> update the column attributes to add the |
60 wx.Grid -> update the column attributes to add the |
129 appropriate renderer given the column name. |
61 appropriate renderer given the column name. |
130 |
62 |
169 grid.SetCellEditor(row, col, editor) |
101 grid.SetCellEditor(row, col, editor) |
170 grid.SetCellRenderer(row, col, renderer) |
102 grid.SetCellRenderer(row, col, renderer) |
171 grid.SetReadOnly(row, col, readonly) |
103 grid.SetReadOnly(row, col, readonly) |
172 |
104 |
173 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
105 grid.SetCellBackgroundColour(row, col, wx.WHITE) |
174 if wx.Platform == '__WXMSW__': |
106 self.ResizeRow(grid, row) |
175 grid.SetRowMinimalHeight(row, 20) |
107 |
176 else: |
|
177 grid.SetRowMinimalHeight(row, 28) |
|
178 grid.AutoSizeRow(row, False) |
|
179 |
|
180 def SetData(self, data): |
|
181 self.data = data |
|
182 |
|
183 def GetData(self): |
|
184 return self.data |
|
185 |
|
186 def GetCurrentIndex(self): |
|
187 return self.CurrentIndex |
|
188 |
|
189 def SetCurrentIndex(self, index): |
|
190 self.CurrentIndex = index |
|
191 |
|
192 def AppendRow(self, row_content): |
|
193 self.data.append(row_content) |
|
194 |
|
195 def InsertRow(self, row_index, row_content): |
|
196 self.data.insert(row_index, row_content) |
|
197 |
|
198 def RemoveRow(self, row_index): |
|
199 self.data.pop(row_index) |
|
200 |
|
201 def MoveRow(self, row_index, move): |
|
202 new_index = max(0, min(row_index + move, len(self.data) - 1)) |
|
203 if new_index != row_index: |
|
204 self.data.insert(new_index, self.data.pop(row_index)) |
|
205 return new_index |
|
206 |
|
207 def Empty(self): |
|
208 self.data = [] |
|
209 |
108 |
210 [ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID, |
109 [ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID, |
211 ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON, |
110 ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON, |
212 ID_ACTIONBLOCKDIALOGDELETEBUTTON, ID_ACTIONBLOCKDIALOGUPBUTTON, |
111 ID_ACTIONBLOCKDIALOGDELETEBUTTON, ID_ACTIONBLOCKDIALOGUPBUTTON, |
213 ID_ACTIONBLOCKDIALOGDOWNBUTTON, |
112 ID_ACTIONBLOCKDIALOGDOWNBUTTON, |