Dynamic wxChoice update problem

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()

Can anyone give me a pointer?

···

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.

Hi Sean,

···

On Mar 25, 8:59 pm, Sean DiZazzo <half.ital...@gmail.com> wrote:

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?

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

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

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.

···

On Mar 26, 12:25 pm, Sean DiZazzo <half.ital...@gmail.com> wrote:

> 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

Blog: http://blog.pythonlibrary.org

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