Seeking advice on sizing a wx.Grid and individiual column widths and
restricting cell contents of specific columns to a choice of terms. Should I
be using a GridSizer, GridBagSizer, or GridFlexBagSizer?
The current view is attached as a .png file (if the maillist allows
attachments). The code follows (with blank lines removed to save space):
class pwAir(wx.Panel):
def __init__(self, *args, **kwds):
wx.Panel.__init__(self, *args, **kwds)
topBox = wx.BoxSizer(wx.VERTICAL)
commentBox = wx.BoxSizer(wx.HORIZONTAL)
# Define grid widget
airGrid = gridlib.Grid(self)
self.nRows = 25
self.nCols = 9
self.flag = 0
self.colLabels = ['Emitter', 'Date', 'Time', 'Collector', 'PM', 'PM10', \
'PM2.5', 'Opacity', 'Comment']
airGrid.CreateGrid(self.nRows, self.nCols)
# simple cell formatting
airGrid.SetColSize(0,800)
airGrid.SetColSize(1,500)
airGrid.SetColSize(2,500)
airGrid.SetColSize(3,800)
airGrid.SetColSize(4,100)
airGrid.SetColSize(5,100)
airGrid.SetColSize(6,100)
airGrid.SetColSize(7,80)
airGrid.SetColSize(8,2000)
airGrid.SetColLabelValue(0, "Emission Unit")
airGrid.SetColLabelValue(1, "Date")
airGrid.SetColLabelValue(2, "Time")
airGrid.SetColLabelValue(3, "Collector")
airGrid.SetColLabelValue(4, "PM")
airGrid.SetColLabelValue(5, "PM10")
airGrid.SetColLabelValue(6, "PM2.5")
airGrid.SetColLabelValue(7, "Opacity")
airGrid.SetColLabelValue(8, "Data Explanation")
airGrid.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_BOTTOM)
airGrid.AutoSizeColumns(setAsMin = True)
airGrid.attr = wx.grid.GridCellAttr()
airGrid.attr.SetTextColour(wx.BLACK)
airGrid.attr.SetBackgroundColour(wx.RED)
airGrid.attr.SetFont(wx.Font(10, wx.ROMAN, wx.NORMAL, wx.BOLD))
airGrid.SetColLabelAlignment(wx.ALIGN_CENTER, wx.ALIGN_BOTTOM)
airGrid.SetLabelBackgroundColour('DARKOLIVEGREEN')
airGrid.SetLabelFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
airGrid.SetLabelTextColour('WHEAT')
airGrid.SetDefaultCellOverflow(False)
r = gridlib.GridCellAutoWrapStringRenderer()
airGrid.SetCellRenderer(9, 1, r)
editor = gridlib.GridCellTextEditor()
editor.SetParameters('10')
airGrid.SetCellEditor(0, 4, editor)
airGrid.moveTo = None
airGrid.Bind(wx.EVT_IDLE, self.OnIdle)
# Comments
lab = wx.StaticText(self, -1, "Comments: ")
self.comment = wx.TextCtrl(self, -1, size = (500, 50),
style = wx.TAB_TRAVERSAL|wx.TE_PROCESS_ENTER|wx.RAISED_BORDER|
wx.TE_MULTILINE|wx.TE_BESTWRAP)
commentBox.Add(lab, 0, wx.ALL, 5)
commentBox.Add(self.comment, 0, wx.ALL, 5)
# Define buttons
self.AddButton = wx.Button(self, wx.ID_ADD)
self.EditButton = wx.Button(self, wx.ID_EDIT)
self.CancelButton = wx.Button(self, wx.ID_CANCEL)
btn1Sizer = wx.StdDialogButtonSizer()
btn1Sizer.Add(self.AddButton, 0, wx.ALL, 0)
btn1Sizer.Add(self.EditButton, 0, wx.ALL, 0)
btn1Sizer.Add(self.CancelButton)
self.Bind(wx.EVT_BUTTON, self.OnAdd, self.AddButton)
self.Bind(wx.EVT_BUTTON, self.OnEdit, self.EditButton)
self.Bind(wx.EVT_BUTTON, self.OnCancel, self.CancelButton)
btn1Sizer.Realize()
topBox.Add(airGrid, 0, wx.ALIGN_CENTER|wx.ALL, 5)
topBox.Add(commentBox, 0, wx.ALIGN_CENTER|wx.ALL, 5)
topBox.Add(btn1Sizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
self.SetSizer(topBox)
topBox.Fit(self)
I've looked at the wx.Widgets on-line docs page without learning just how
to tune this code.
Besides sizing, I'd like the number of rows to increase as needed and
limit data entry (in the last column in this grid) to a list of possible
values.
Suggestions, recommendations, and other advice needed.
Thanks in advance,
Rich