Wxpython: updating a dict or other appropriate data type from a wx.lib.sheet.CSheet object

If I have a laptop with three spreadsheet widgets, what is the best way to change spreadsheet spreadsheets, update the dictionary (or maybe sqlite file?). Do all wx grid objects have a built-in dictionary associated with SetNumberRows and SetNumberCols? Basically I am looking for a guide on working with user data from a spreadsheet widget, as in this example, adapted from a tutorial on python.org:

class ExSheet(wx.lib.sheet.CSheet): def __init__(self, parent): sheet.CSheet.__init__(self, parent) self.SetLabelBackgroundColour('#CCFF66') self.SetNumberRows(50) self.SetNumberCols(50) class Notebook(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM) self.sheet1 = ExSheet(nb) self.sheet2 = ExSheet(nb) self.sheet3 = ExSheet(nb) nb.AddPage(self.sheet1, "Sheet1") nb.AddPage(self.sheet2, "Sheet2") nb.AddPage(self.sheet3, "Sheet3") self.sheet1.SetFocus() self.StatusBar() 
+3
source share
1 answer

Use wxGrid with wxGridTableBase instead

Here is a simple example:

 import wx, wx.grid class GridData(wx.grid.PyGridTableBase): _cols = "abc".split() _data = [ "1 2 3".split(), "4 5 6".split(), "7 8 9".split() ] def GetColLabelValue(self, col): return self._cols[col] def GetNumberRows(self): return len(self._data) def GetNumberCols(self): return len(self._cols) def GetValue(self, row, col): return self._data[row][col] def SetValue(self, row, col, val): self._data[row][col] = val class Test(wx.Frame): def __init__(self): wx.Frame.__init__(self, None) self.data = GridData() grid = wx.grid.Grid(self) grid.SetTable(self.data) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Show() def OnClose(self, event): print self.data._data event.Skip() app = wx.PySimpleApp() app.TopWindow = Test() app.MainLoop() 
+4
source

All Articles