Skip to content

Instantly share code, notes, and snippets.

@Bouke
Created November 12, 2012 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bouke/4059634 to your computer and use it in GitHub Desktop.
Save Bouke/4059634 to your computer and use it in GitHub Desktop.
OSX: wx, Grid, ChoiceEditor and empty cell -> render issue
import wx
import wx.grid
class Frame1(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, id=-1, name='', parent=None,
pos=wx.Point(100, 100), size=wx.Size(480, 250),
style=wx.DEFAULT_FRAME_STYLE, title='Spam & Eggs')
self.SetClientSize(wx.Size(400, 250))
self.scrolledWindow1 = wx.ScrolledWindow(id=-1,
name='scrolledWindow1', parent=self, pos=wx.Point(0, 0),
size=wx.Size(400, 250), style=wx.HSCROLL | wx.VSCROLL)
self.grid1 = wx.grid.Grid(id=-1, name='grid1',
parent=self.scrolledWindow1, pos=wx.Point(0, 0),
size=wx.Size(400, 250), style=0)
self.grid1.CreateGrid(14, 2)
self.grid1.SetDefaultEditor(wx.grid.GridCellChoiceEditor(['A', 'B', 'C'], allowOthers=True))
self.grid1.MakeCellVisible(13, 0)
self.grid1.SetGridCursor(12, 0)
self.grid1.Bind(wx.grid.EVT_GRID_EDITOR_CREATED, self.editor_created)
self.grid1.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.editor_shown)
def editor_created(self, event):
self.control = event.GetControl()
event.Skip()
def editor_shown(self, event):
cursor = event.Row, event.Col
value = self.grid1.GetCellValue(*cursor)
if not value:
self.grid1.SetCellValue(cursor[0], cursor[1], ' ')
def unfix():
self.control.SetValue(value)
self.control.Popup()
# @todo should set the cell value back to empty value here,
# but that triggers the bug again.
wx.CallAfter(unfix)
event.Skip()
if __name__ == '__main__':
app = wx.App()
frame = Frame1(None)
frame.Show(True)
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment