grid - wxpython wxgrid attributes -


i'm having trouble highlighting alternative rows in grid. having created grid , filled data, highlighting alternative rows works expected. when new data loaded, delete rows, add new rows required, , time grid highlighting raises exception unhandled typeerror. has me stumped- suggestions? code below produces same error (click button twice):-

import wx import wx.grid gridlib app = wx.app()  def highlightrows(event):    row in range(0, mygrid.getnumberrows(), 2):       if row < mygrid.getnumberrows():          mygrid.setrowattr(row, attr)    mygrid.forcerefresh()    mygrid.refresh()  frame = wx.frame(none, title="highlight woes") panel = wx.panel(frame) mygrid = gridlib.grid(panel) mygrid.creategrid(12, 8) sizer = wx.boxsizer(wx.vertical) sizer.add(mygrid, 1, wx.expand) panel.setsizer(sizer)  btn = wx.button(panel,  -1, 'highlight rows') sizer.add(btn) btn.bind(wx.evt_button, highlightrows)  attr = wx.grid.gridcellattr() attr.setbackgroundcolour('#eeeeee')  frame.show() app.mainloop() 

in example, gridcellattr instance has gone out of scope , been deleted second time press button. i'm surprised worked first time, honest. when click button twice, following error:

typeerror: in method 'grid_setrowattr', expected argument 3 of type 'wxgridcellattr *' 

digging bit deeper, if @ 3rd argument, see following:

<wx.grid.gridcellattr; proxy of wxpython wrapper deleted gridcellattr object! (the c++ object no longer exists.) > 

anyway, here's 1 simple approach worked every time me:

import wx import wx.grid gridlib  ######################################################################## class myform(wx.frame):     """"""      #----------------------------------------------------------------------     def __init__(self):         """constructor"""         wx.frame.__init__(self, parent=none, title="a simple grid")         panel = wx.panel(self)          self.mygrid = gridlib.grid(panel)         self.mygrid.creategrid(12, 8)          sizer = wx.boxsizer(wx.vertical)         sizer.add(self.mygrid, 1, wx.expand)          btn = wx.button(panel, label='highlight rows')         sizer.add(btn)         btn.bind(wx.evt_button, self.highlightrows)          panel.setsizer(sizer)      #----------------------------------------------------------------------     def highlightrows(self, event):         """"""         attr = wx.grid.gridcellattr()         attr.setbackgroundcolour('#eeeeee')         row in range(0, self.mygrid.getnumberrows(), 2):             if row < self.mygrid.getnumberrows():                 self.mygrid.setrowattr(row, attr)         self.mygrid.forcerefresh()         self.mygrid.refresh()  if __name__ == "__main__":     app = wx.app(false)     frame = myform().show()     app.mainloop() 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -