Dynamic wxChoice update problem

89 views
Skip to first unread message

Sean DiZazzo

unread,
Mar 24, 2010, 4:21:43 PM3/24/10
to wxPython-users
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()

Sean DiZazzo

unread,
Mar 25, 2010, 9:59:37 PM3/25/10
to wxPython-users
On Mar 24, 1:21 pm, Sean DiZazzo <half.ital...@gmail.com> wrote:
> 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.

Can anyone give me a pointer?

Mike Driscoll

unread,
Mar 26, 2010, 10:01:22 AM3/26/10
to wxPython-users
Hi Sean,

What is a choice box? The closest widget I could find was the
CheckListBox. If that is the widget of which you write, then you be
able to just call SetSelection(index) to re-check the checkbox. If
that's not working, then we'll need a sample application. See
http://wiki.wxpython.org/MakingSampleApps

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Sean DiZazzo

unread,
Mar 26, 2010, 1:25:15 PM3/26/10
to wxPython-users

> What is a choice box? The closest widget I could find was the
> CheckListBox. If that is the widget of which you write, then you be
> able to just call SetSelection(index) to re-check the checkbox. If
> that's not working, then we'll need a sample application. Seehttp://wiki.wxpython.org/MakingSampleApps
>

I guess my sample code on the first post didn't make it
through...sorry.

Here it is on pastebin: http://pastebin.com/FC8vThPn

I also meant a wx.Choice widget. Please let me know what you think.

Thanks.

~Sean

Mike Driscoll

unread,
Mar 26, 2010, 1:54:42 PM3/26/10
to wxPython-users

I must have missed your code somehow...I see it now. Sorry!

From what I can see, there is no check mark on Windows XP. I was
unable to make the arrow disappear either. It is a really annoying bit
of code though since the timer is firing all the time and makes
choosing an item from the widget unduly difficult. The scripts seems
to "remember" my selection just fine though.

Sean DiZazzo

unread,
Mar 26, 2010, 2:12:14 PM3/26/10
to wxPython-users

> I must have missed your code somehow...I see it now. Sorry!
>
> From what I can see, there is no check mark on Windows XP. I was
> unable to make the arrow disappear either. It is a really annoying bit
> of code though since the timer is firing all the time and makes
> choosing an item from the widget unduly difficult. The scripts seems
> to "remember" my selection just fine though.
>

Thanks Mike. Yeah, I guess I need to rethink the design. That was
the advice I was looking for.

~Sean

Reply all
Reply to author
Forward
0 new messages