Hi!
I'm trying to dynamically update a choice box based on a timer firing
every second or so. The timer records the selected item, then updates
the items (which may change over time) and finally sets the selection
back to what it was before the update. I know the selected item might
disappear, etc. I'm not worried about that at this point.
It basically works, but I get a few problems from updating the
selection programatically. First off, the check next to the selected
item disappears after the timer goes off. Second, if the gui is too
close to the top of the screen, the arrow at the top of the choice
list will pop away and empty items will appear at the bottom of the
list. I'm running this on OSX at the moment, but Windows was even
worse.
How can I get around these problems?
Here's what i have...
···
~~~~~~~~~~~~~~~~~~~~~~
import wx, os
class MyFrame(wx.Frame):
def __init__(self, parent, id, title=None, pos=None, size=None,
style=None):
wx.Frame.__init__(self, parent, id, title=title, pos=pos,
size=size, style=style)
self.sourcedir = "/tmp"
self.chooser = wx.Choice(self, id=-1,
pos=wx.DefaultPosition,
size=wx.DefaultSize, choices=[])
self.timer = wx.Timer(self)
self.timer.Start(2000, oneShot=False)
self.Bind(wx.EVT_TIMER, self.updateChoice)
def updateChoice(self, evt):
sel = self.chooser.GetStringSelection()
self.chooser.SetItems([c for c in os.listdir(self.sourcedir)
if not c.startswith(".")])
self.chooser.SetStringSelection(sel)
class MyApp(wx.PySimpleApp):
def OnInit(self):
frame = MyFrame(None, -1, title='Test',
pos=wx.DefaultPosition,
style=wx.SYSTEM_MENU|wx.CAPTION|
wx.CLOSE_BOX|wx.CLIP_CHILDREN)
frame.Show(True)
self.SetTopWindow(frame)
return True
if __name__ == "__main__":
app = MyApp()
app.MainLoop()