]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/GridCustTable.py
Fix incorrect #if in OnSysTell
[wxWidgets.git] / wxPython / demo / GridCustTable.py
index 58fb015cd3bed65de70674c3ab063cdd88316dda..8bfec553949d8e4e0a0737391b963cef3ca624ae 100644 (file)
@@ -1,34 +1,32 @@
-from wxPython.wx import *
-from wxPython.grid import *
 
-import string
+import  wx
+import  wx.grid as gridlib
 
 #---------------------------------------------------------------------------
 
-class CustomDataTable(wxPyGridTableBase):
-    """
-    """
-
+class CustomDataTable(gridlib.PyGridTableBase):
     def __init__(self, log):
-        wxPyGridTableBase.__init__(self)
+        gridlib.PyGridTableBase.__init__(self)
         self.log = log
 
         self.colLabels = ['ID', 'Description', 'Severity', 'Priority', 'Platform',
-                          'Opened?', 'Fixed?', 'Tested?']
-
-        self.dataTypes = [wxGRID_VALUE_NUMBER,
-                          wxGRID_VALUE_STRING,
-                          wxGRID_VALUE_CHOICE + ':only in a million years!,wish list,minor,normal,major,critical',
-                          wxGRID_VALUE_NUMBER + ':1,5',
-                          wxGRID_VALUE_CHOICE + ':all,MSW,GTK,other',
-                          wxGRID_VALUE_BOOL,
-                          wxGRID_VALUE_BOOL,
-                          wxGRID_VALUE_BOOL]
+                          'Opened?', 'Fixed?', 'Tested?', 'TestFloat']
+
+        self.dataTypes = [gridlib.GRID_VALUE_NUMBER,
+                          gridlib.GRID_VALUE_STRING,
+                          gridlib.GRID_VALUE_CHOICE + ':only in a million years!,wish list,minor,normal,major,critical',
+                          gridlib.GRID_VALUE_NUMBER + ':1,5',
+                          gridlib.GRID_VALUE_CHOICE + ':all,MSW,GTK,other',
+                          gridlib.GRID_VALUE_BOOL,
+                          gridlib.GRID_VALUE_BOOL,
+                          gridlib.GRID_VALUE_BOOL,
+                          gridlib.GRID_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 +41,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
@@ -64,9 +65,10 @@ class CustomDataTable(wxPyGridTableBase):
             self.SetValue(row, col, value)
 
             # tell the grid we've added a row
-            msg = wxGridTableMessage(self,                             # The table
-                                     wxGRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
-                                     1)                                # how many
+            msg = gridlib.GridTableMessage(self,            # The table
+                    gridlib.GRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it
+                    1                                       # how many
+                    )
 
             self.GetView().ProcessTableMessage(msg)
 
@@ -80,7 +82,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 +90,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)
@@ -105,23 +107,22 @@ class CustomDataTable(wxPyGridTableBase):
 
 
 
-class CustTableGrid(wxGrid):
+class CustTableGrid(gridlib.Grid):
     def __init__(self, parent, log):
-        wxGrid.__init__(self, parent, -1)
+        gridlib.Grid.__init__(self, parent, -1)
 
         table = CustomDataTable(log)
 
         # 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)
-
-        EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
+        self.AutoSizeColumns(False)
 
+        gridlib.EVT_GRID_CELL_LEFT_DCLICK(self, self.OnLeftDClick)
 
 
     # I do this because I don't like the default behaviour of not starting the
@@ -133,20 +134,38 @@ class CustTableGrid(wxGrid):
 
 #---------------------------------------------------------------------------
 
-class TestFrame(wxFrame):
+class TestFrame(wx.Frame):
     def __init__(self, parent, log):
-        wxFrame.__init__(self, parent, -1, "Custom Table, data driven Grid  Demo", size=(640,480))
-        grid = CustTableGrid(self, log)
 
+        wx.Frame.__init__(
+            self, parent, -1, "Custom Table, data driven Grid  Demo", size=(640,480)
+            )
+
+        p = wx.Panel(self, -1, style=0)
+        grid = CustTableGrid(p, log)
+        b = wx.Button(p, -1, "Another Control...")
+        b.SetDefault()
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        b.Bind(wx.EVT_SET_FOCUS, self.OnButtonFocus)
+        bs = wx.BoxSizer(wx.VERTICAL)
+        bs.Add(grid, 1, wx.GROW|wx.ALL, 5)
+        bs.Add(b)
+        p.SetSizer(bs)
+
+    def OnButton(self, evt):
+        print "button selected"
+
+    def OnButtonFocus(self, evt):
+        print "button focus"
 
 
 #---------------------------------------------------------------------------
 
 if __name__ == '__main__':
     import sys
-    app = wxPySimpleApp()
+    app = wx.PySimpleApp()
     frame = TestFrame(None, sys.stdout)
-    frame.Show(true)
+    frame.Show(True)
     app.MainLoop()