X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..bc93670d3b2b69ea2cdd799444b57dce24b8be94:/wxPython/demo/GridCustTable.py diff --git a/wxPython/demo/GridCustTable.py b/wxPython/demo/GridCustTable.py index 58fb015cd3..cc151f9ac7 100644 --- a/wxPython/demo/GridCustTable.py +++ b/wxPython/demo/GridCustTable.py @@ -1,8 +1,6 @@ from wxPython.wx import * from wxPython.grid import * -import string - #--------------------------------------------------------------------------- class CustomDataTable(wxPyGridTableBase): @@ -14,7 +12,7 @@ class CustomDataTable(wxPyGridTableBase): self.log = log self.colLabels = ['ID', 'Description', 'Severity', 'Priority', 'Platform', - 'Opened?', 'Fixed?', 'Tested?'] + 'Opened?', 'Fixed?', 'Tested?', 'TestFloat'] self.dataTypes = [wxGRID_VALUE_NUMBER, wxGRID_VALUE_STRING, @@ -23,12 +21,14 @@ class CustomDataTable(wxPyGridTableBase): wxGRID_VALUE_CHOICE + ':all,MSW,GTK,other', wxGRID_VALUE_BOOL, wxGRID_VALUE_BOOL, - wxGRID_VALUE_BOOL] + wxGRID_VALUE_BOOL, + wxGRID_VALUE_FLOAT + ':6,2', + ] self.data = [ - [1010, "The foo doesn't bar", "major", 1, 'MSW', 1, 1, 1], - [1011, "I've got a wicket in my wocket", "wish list", 2, 'other', 0, 0, 0], - [1012, "Rectangle() returns a triangle", "critical", 5, 'all', 0, 0, 0] + [1010, "The foo doesn't bar", "major", 1, 'MSW', 1, 1, 1, 1.12], + [1011, "I've got a wicket in my wocket", "wish list", 2, 'other', 0, 0, 0, 1.50], + [1012, "Rectangle() returns a triangle", "critical", 5, 'all', 0, 0, 0, 1.56] ] @@ -43,7 +43,10 @@ class CustomDataTable(wxPyGridTableBase): return len(self.data[0]) def IsEmptyCell(self, row, col): - return not self.data[row][col] + try: + return not self.data[row][col] + except IndexError: + return True # Get/Set values in the table. The Python version of these # methods can handle any data-type, (as long as the Editor and @@ -80,7 +83,7 @@ class CustomDataTable(wxPyGridTableBase): # Called to determine the kind of editor/renderer to use by # default, doesn't necessarily have to be the same type used - # nativly by the editor/renderer if they know how to convert. + # natively by the editor/renderer if they know how to convert. def GetTypeName(self, row, col): return self.dataTypes[col] @@ -88,11 +91,11 @@ class CustomDataTable(wxPyGridTableBase): # editor and renderer. This allows you to enforce some type-safety # in the grid. def CanGetValueAs(self, row, col, typeName): - colType = string.split(self.dataTypes[col], ':')[0] + colType = self.dataTypes[col].split(':')[0] if typeName == colType: - return true + return True else: - return false + return False def CanSetValueAs(self, row, col, typeName): return self.CanGetValueAs(row, col, typeName) @@ -114,11 +117,11 @@ class CustTableGrid(wxGrid): # The second parameter means that the grid is to take ownership of the # table and will destroy it when done. Otherwise you would need to keep # a reference to it and call it's Destroy method later. - self.SetTable(table, true) + self.SetTable(table, True) self.SetRowLabelSize(0) self.SetMargins(0,0) - self.AutoSizeColumns(false) + self.AutoSizeColumns(False) EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick) @@ -136,8 +139,22 @@ class CustTableGrid(wxGrid): class TestFrame(wxFrame): def __init__(self, parent, log): wxFrame.__init__(self, parent, -1, "Custom Table, data driven Grid Demo", size=(640,480)) - grid = CustTableGrid(self, log) + p = wxPanel(self, -1, style=0) + grid = CustTableGrid(p, log) + b = wxButton(p, -1, "Another Control...") + b.SetDefault() + EVT_BUTTON(self, b.GetId(), self.OnButton) + EVT_SET_FOCUS(b, self.OnButtonFocus) + bs = wxBoxSizer(wxVERTICAL) + bs.Add(grid, 1, wxGROW|wxALL, 5) + bs.Add(b) + p.SetSizer(bs) + + def OnButton(self, evt): + print "button selected" + def OnButtonFocus(self, evt): + print "button focus" #--------------------------------------------------------------------------- @@ -146,7 +163,7 @@ if __name__ == '__main__': import sys app = wxPySimpleApp() frame = TestFrame(None, sys.stdout) - frame.Show(true) + frame.Show(True) app.MainLoop()