--- a/dialogs/ActionBlockDialog.py Wed Oct 12 23:47:48 2011 +0200
+++ b/dialogs/ActionBlockDialog.py Fri Oct 14 19:26:29 2011 +0200
@@ -24,6 +24,8 @@
import wx
import wx.grid
+from controls import CustomGrid
+
#-------------------------------------------------------------------------------
# Action Block Dialog
#-------------------------------------------------------------------------------
@@ -169,6 +171,11 @@
grid.SetReadOnly(row, col, readonly)
grid.SetCellBackgroundColour(row, col, wx.WHITE)
+ if wx.Platform == '__WXMSW__':
+ grid.SetRowMinimalHeight(row, 20)
+ else:
+ grid.SetRowMinimalHeight(row, 28)
+ grid.AutoSizeRow(row, False)
def SetData(self, data):
self.data = data
@@ -184,19 +191,21 @@
def AppendRow(self, row_content):
self.data.append(row_content)
+
+ def InsertRow(self, row_index, row_content):
+ self.data.insert(row_index, row_content)
def RemoveRow(self, row_index):
self.data.pop(row_index)
- def MoveRow(self, row_index, move, grid):
+ def MoveRow(self, row_index, move):
new_index = max(0, min(row_index + move, len(self.data) - 1))
if new_index != row_index:
self.data.insert(new_index, self.data.pop(row_index))
- grid.SetGridCursor(new_index, grid.GetGridCursorCol())
+ return new_index
def Empty(self):
self.data = []
- self.editors = []
[ID_ACTIONBLOCKDIALOG, ID_ACTIONBLOCKDIALOGVARIABLESGRID,
ID_ACTIONBLOCKDIALOGSTATICTEXT1, ID_ACTIONBLOCKDIALOGADDBUTTON,
@@ -260,7 +269,7 @@
label=_('Actions:'), name='staticText1', parent=self,
pos=wx.Point(0, 0), size=wx.Size(0, 17), style=0)
- self.ActionsGrid = wx.grid.Grid(id=ID_ACTIONBLOCKDIALOGVARIABLESGRID,
+ self.ActionsGrid = CustomGrid(id=ID_ACTIONBLOCKDIALOGVARIABLESGRID,
name='ActionsGrid', parent=self, pos=wx.Point(0, 0),
size=wx.Size(0, 0), style=wx.VSCROLL)
self.ActionsGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
@@ -269,28 +278,27 @@
False, 'Sans'))
self.ActionsGrid.DisableDragGridSize()
self.ActionsGrid.EnableScrolling(False, True)
- self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnActionsGridCellChange)
-
+ if wx.VERSION >= (2, 6, 0):
+ self.ActionsGrid.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnActionsGridCellChange)
+ else:
+ wx.grid.EVT_GRID_CELL_CHANGE(self.ActionsGrid, self.OnActionsGridCellChange)
+
self.AddButton = wx.Button(id=ID_ACTIONBLOCKDIALOGADDBUTTON, label=_('Add'),
name='AddButton', parent=self, pos=wx.Point(0, 0),
size=wx.DefaultSize, style=0)
- self.Bind(wx.EVT_BUTTON, self.OnAddButton, id=ID_ACTIONBLOCKDIALOGADDBUTTON)
-
+
self.DeleteButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDELETEBUTTON, label=_('Delete'),
name='DeleteButton', parent=self, pos=wx.Point(0, 0),
size=wx.DefaultSize, style=0)
- self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, id=ID_ACTIONBLOCKDIALOGDELETEBUTTON)
-
+
self.UpButton = wx.Button(id=ID_ACTIONBLOCKDIALOGUPBUTTON, label='^',
name='UpButton', parent=self, pos=wx.Point(0, 0),
size=wx.Size(32, 32), style=0)
- self.Bind(wx.EVT_BUTTON, self.OnUpButton, id=ID_ACTIONBLOCKDIALOGUPBUTTON)
-
+
self.DownButton = wx.Button(id=ID_ACTIONBLOCKDIALOGDOWNBUTTON, label='v',
name='DownButton', parent=self, pos=wx.Point(0, 0),
size=wx.Size(32, 32), style=0)
- self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_ACTIONBLOCKDIALOGDOWNBUTTON)
-
+
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
if wx.VERSION >= (2, 5, 0):
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId())
@@ -302,7 +310,6 @@
def __init__(self, parent):
self._init_ctrls(parent)
- self.DefaultValue = {"Qualifier" : "N", "Duration" : "", "Type" : "Action", "Value" : "", "Indicator" : ""}
self.Table = ActionTable(self, [], GetActionTableColnames())
typelist = GetTypeList()
self.TypeList = ",".join(map(_,typelist))
@@ -311,6 +318,15 @@
self.ColAlignements = [wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT, wx.ALIGN_LEFT]
self.ActionsGrid.SetTable(self.Table)
+ self.ActionsGrid.SetDefaultValue({"Qualifier" : "N",
+ "Duration" : "",
+ "Type" : "Action",
+ "Value" : "",
+ "Indicator" : ""})
+ self.ActionsGrid.SetButtons({"Add": self.AddButton,
+ "Delete": self.DeleteButton,
+ "Up": self.UpButton,
+ "Down": self.DownButton})
self.ActionsGrid.SetRowLabelSize(0)
for col in range(self.Table.GetNumberCols()):
@@ -321,38 +337,17 @@
self.ActionsGrid.AutoSizeColumn(col, False)
self.Table.ResetView(self.ActionsGrid)
-
+ self.ActionsGrid.SetFocus()
+ self.ActionsGrid.RefreshButtons()
+
def OnOK(self, event):
- self.ActionsGrid.SetGridCursor(0, 0)
+ self.ActionsGrid.CloseEditControl()
self.EndModal(wx.ID_OK)
- def OnAddButton(self, event):
- self.Table.AppendRow(self.DefaultValue.copy())
- self.Table.ResetView(self.ActionsGrid)
+ def OnActionsGridCellChange(self, event):
+ wx.CallAfter(self.Table.ResetView, self.ActionsGrid)
event.Skip()
-
- def OnDeleteButton(self, event):
- row = self.ActionsGrid.GetGridCursorRow()
- self.Table.RemoveRow(row)
- self.Table.ResetView(self.ActionsGrid)
- event.Skip()
-
- def OnUpButton(self, event):
- row = self.ActionsGrid.GetGridCursorRow()
- self.Table.MoveRow(row, -1, self.ActionsGrid)
- self.Table.ResetView(self.ActionsGrid)
- event.Skip()
-
- def OnDownButton(self, event):
- row = self.ActionsGrid.GetGridCursorRow()
- self.Table.MoveRow(row, 1, self.ActionsGrid)
- self.Table.ResetView(self.ActionsGrid)
- event.Skip()
-
- def OnActionsGridCellChange(self, event):
- self.Table.ResetView(self.ActionsGrid)
- event.Skip()
-
+
def SetQualifierList(self, list):
self.QualifierList = "," + ",".join(list)
self.DurationList = list
@@ -385,6 +380,9 @@
row["Indicator"] = ""
self.Table.AppendRow(row)
self.Table.ResetView(self.ActionsGrid)
+ if len(actions) > 0:
+ self.ActionsGrid.SetGridCursor(0, 0)
+ self.ActionsGrid.RefreshButtons()
def GetValues(self):
values = []