182 def SetCurrentIndex(self, index): |
189 def SetCurrentIndex(self, index): |
183 self.CurrentIndex = index |
190 self.CurrentIndex = index |
184 |
191 |
185 def AppendRow(self, row_content): |
192 def AppendRow(self, row_content): |
186 self.data.append(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) |
187 |
197 |
188 def RemoveRow(self, row_index): |
198 def RemoveRow(self, row_index): |
189 self.data.pop(row_index) |
199 self.data.pop(row_index) |
190 |
200 |
191 def MoveRow(self, row_index, move, grid): |
201 def MoveRow(self, row_index, move): |
192 new_index = max(0, min(row_index + move, len(self.data) - 1)) |
202 new_index = max(0, min(row_index + move, len(self.data) - 1)) |
193 if new_index != row_index: |
203 if new_index != row_index: |
194 self.data.insert(new_index, self.data.pop(row_index)) |
204 self.data.insert(new_index, self.data.pop(row_index)) |
195 grid.SetGridCursor(new_index, grid.GetGridCursorCol()) |
205 return new_index |
196 |
206 |
197 def Empty(self): |
207 def Empty(self): |
198 self.data = [] |
208 self.data = [] |
199 self.editors = [] |
|
200 |
209 |
201 [ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID, |
210 [ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID, |
202 ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON, |
211 ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON, |
203 ID_ACTIONBLOCKDIALOGDELETEBUTTON, ID_ACTIONBLOCKDIALOGUPBUTTON, |
212 ID_ACTIONBLOCKDIALOGDELETEBUTTON, ID_ACTIONBLOCKDIALOGUPBUTTON, |
204 ID_ACTIONBLOCKDIALOGDOWNBUTTON, |
213 ID_ACTIONBLOCKDIALOGDOWNBUTTON, |
258 |
267 |
259 self.staticText1 = wx.StaticText(id=ID_ACTIONBLOCKDIALOGSTATICTEXT1, |
268 self.staticText1 = wx.StaticText(id=ID_ACTIONBLOCKDIALOGSTATICTEXT1, |
260 label=_('Actions:'), name='staticText1', parent=self, |
269 label=_('Actions:'), name='staticText1', parent=self, |
261 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
270 pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0) |
262 |
271 |
263 self.ActionsGrid = wx.grid.Grid(id=ID_ACTIONBLOCKDIALOGVARIABLESGRID, |
272 self.ActionsGrid = CustomGrid(id=ID_ACTIONBLOCKDIALOGVARIABLESGRID, |
264 name='ActionsGrid', parent=self, pos=wx.Point(0, 0), |
273 name='ActionsGrid', parent=self, pos=wx.Point(0, 0), |
265 size=wx.Size(0, 0), style=wx.VSCROLL) |
274 size=wx.Size(0, 0), style=wx.VSCROLL) |
266 self.ActionsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
275 self.ActionsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False, |
267 'Sans')) |
276 'Sans')) |
268 self.ActionsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
277 self.ActionsGrid.SetLabelFont(wx.Font(10, 77, wx.NORMAL, wx.NORMAL, |
269 False, 'Sans')) |
278 False, 'Sans')) |
270 self.ActionsGrid.DisableDragGridSize() |
279 self.ActionsGrid.DisableDragGridSize() |
271 self.ActionsGrid.EnableScrolling(False, True) |
280 self.ActionsGrid.EnableScrolling(False, True) |
272 self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnActionsGridCellChange) |
281 if wx.VERSION >= (2, 6, 0): |
273 |
282 self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnActionsGridCellChange) |
|
283 else: |
|
284 wx.grid.EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange) |
|
285 |
274 self.AddButton = wx.Button(id=ID_ACTIONBLOCKDIALOGADDBUTTON, label=_('Add'), |
286 self.AddButton = wx.Button(id=ID_ACTIONBLOCKDIALOGADDBUTTON, label=_('Add'), |
275 name='AddButton', parent=self, pos=wx.Point(0, 0), |
287 name='AddButton', parent=self, pos=wx.Point(0, 0), |
276 size=wx.DefaultSize, style=0) |
288 size=wx.DefaultSize, style=0) |
277 self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_ACTIONBLOCKDIALOGADDBUTTON) |
289 |
278 |
|
279 self.DeleteButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDELETEBUTTON, label=_('Delete'), |
290 self.DeleteButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDELETEBUTTON, label=_('Delete'), |
280 name='DeleteButton', parent=self, pos=wx.Point(0, 0), |
291 name='DeleteButton', parent=self, pos=wx.Point(0, 0), |
281 size=wx.DefaultSize, style=0) |
292 size=wx.DefaultSize, style=0) |
282 self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_ACTIONBLOCKDIALOGDELETEBUTTON) |
293 |
283 |
|
284 self.UpButton = wx.Button(id=ID_ACTIONBLOCKDIALOGUPBUTTON, label='^', |
294 self.UpButton = wx.Button(id=ID_ACTIONBLOCKDIALOGUPBUTTON, label='^', |
285 name='UpButton', parent=self, pos=wx.Point(0, 0), |
295 name='UpButton', parent=self, pos=wx.Point(0, 0), |
286 size=wx.Size(32, 32), style=0) |
296 size=wx.Size(32, 32), style=0) |
287 self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_ACTIONBLOCKDIALOGUPBUTTON) |
297 |
288 |
|
289 self.DownButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v', |
298 self.DownButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v', |
290 name='DownButton', parent=self, pos=wx.Point(0, 0), |
299 name='DownButton', parent=self, pos=wx.Point(0, 0), |
291 size=wx.Size(32, 32), style=0) |
300 size=wx.Size(32, 32), style=0) |
292 self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_ACTIONBLOCKDIALOGDOWNBUTTON) |
301 |
293 |
|
294 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
302 self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) |
295 if wx.VERSION >= (2, 5, 0): |
303 if wx.VERSION >= (2, 5, 0): |
296 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
304 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) |
297 else: |
305 else: |
298 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
306 self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
300 self._init_sizers() |
308 self._init_sizers() |
301 |
309 |
302 def __init__(self, parent): |
310 def __init__(self, parent): |
303 self._init_ctrls(parent) |
311 self._init_ctrls(parent) |
304 |
312 |
305 self.DefaultValue = {"Qualifier" : "N", "Duration" : "", "Type" : "Action", "Value" : "", "Indicator" : ""} |
|
306 self.Table = ActionTable(self, [], GetActionTableColnames()) |
313 self.Table = ActionTable(self, [], GetActionTableColnames()) |
307 typelist = GetTypeList() |
314 typelist = GetTypeList() |
308 self.TypeList = ",".join(map(_,typelist)) |
315 self.TypeList = ",".join(map(_,typelist)) |
309 self.TranslateType = dict([(_(value), value) for value in typelist]) |
316 self.TranslateType = dict([(_(value), value) for value in typelist]) |
310 self.ColSizes = [60, 90, 80, 110, 80] |
317 self.ColSizes = [60, 90, 80, 110, 80] |
311 self.ColAlignements = [wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT] |
318 self.ColAlignements = [wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT] |
312 |
319 |
313 self.ActionsGrid.SetTable(self.Table) |
320 self.ActionsGrid.SetTable(self.Table) |
|
321 self.ActionsGrid.SetDefaultValue({"Qualifier" : "N", |
|
322 "Duration" : "", |
|
323 "Type" : "Action", |
|
324 "Value" : "", |
|
325 "Indicator" : ""}) |
|
326 self.ActionsGrid.SetButtons({"Add": self.AddButton, |
|
327 "Delete": self.DeleteButton, |
|
328 "Up": self.UpButton, |
|
329 "Down": self.DownButton}) |
314 self.ActionsGrid.SetRowLabelSize(0) |
330 self.ActionsGrid.SetRowLabelSize(0) |
315 |
331 |
316 for col in range(self.Table.GetNumberCols()): |
332 for col in range(self.Table.GetNumberCols()): |
317 attr = wx.grid.GridCellAttr() |
333 attr = wx.grid.GridCellAttr() |
318 attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
334 attr.SetAlignment(self.ColAlignements[col], wx.ALIGN_CENTRE) |
319 self.ActionsGrid.SetColAttr(col, attr) |
335 self.ActionsGrid.SetColAttr(col, attr) |
320 self.ActionsGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
336 self.ActionsGrid.SetColMinimalWidth(col, self.ColSizes[col]) |
321 self.ActionsGrid.AutoSizeColumn(col, False) |
337 self.ActionsGrid.AutoSizeColumn(col, False) |
322 |
338 |
323 self.Table.ResetView(self.ActionsGrid) |
339 self.Table.ResetView(self.ActionsGrid) |
324 |
340 self.ActionsGrid.SetFocus() |
|
341 self.ActionsGrid.RefreshButtons() |
|
342 |
325 def OnOK(self, event): |
343 def OnOK(self, event): |
326 self.ActionsGrid.SetGridCursor(0, 0) |
344 self.ActionsGrid.CloseEditControl() |
327 self.EndModal(wx.ID_OK) |
345 self.EndModal(wx.ID_OK) |
328 |
346 |
329 def OnAddButton(self, event): |
347 def OnActionsGridCellChange(self, event): |
330 self.Table.AppendRow(self.DefaultValue.copy()) |
348 wx.CallAfter(self.Table.ResetView, self.ActionsGrid) |
331 self.Table.ResetView(self.ActionsGrid) |
|
332 event.Skip() |
349 event.Skip() |
333 |
350 |
334 def OnDeleteButton(self, event): |
|
335 row = self.ActionsGrid.GetGridCursorRow() |
|
336 self.Table.RemoveRow(row) |
|
337 self.Table.ResetView(self.ActionsGrid) |
|
338 event.Skip() |
|
339 |
|
340 def OnUpButton(self, event): |
|
341 row = self.ActionsGrid.GetGridCursorRow() |
|
342 self.Table.MoveRow(row, -1, self.ActionsGrid) |
|
343 self.Table.ResetView(self.ActionsGrid) |
|
344 event.Skip() |
|
345 |
|
346 def OnDownButton(self, event): |
|
347 row = self.ActionsGrid.GetGridCursorRow() |
|
348 self.Table.MoveRow(row, 1, self.ActionsGrid) |
|
349 self.Table.ResetView(self.ActionsGrid) |
|
350 event.Skip() |
|
351 |
|
352 def OnActionsGridCellChange(self, event): |
|
353 self.Table.ResetView(self.ActionsGrid) |
|
354 event.Skip() |
|
355 |
|
356 def SetQualifierList(self, list): |
351 def SetQualifierList(self, list): |
357 self.QualifierList = "," + ",".join(list) |
352 self.QualifierList = "," + ",".join(list) |
358 self.DurationList = list |
353 self.DurationList = list |
359 |
354 |
360 def SetVariableList(self, list): |
355 def SetVariableList(self, list): |