Difficulty with wxBusyCursor (newbie question)

Hi,

I'm using wxGlade 0.6.3, wxPython 2.8.12 and python 2.7.2 on Fedora Linux
16 (all x86_64). This is my first application, so please be gentle if I'm
doing something stupid.

The (one and only) wx.Frame has a wx.ToolBar and a wx.MenuBar. One item
in each is bound to an event handler (they are both bound to the same
one).

The event handler calls wx.BeginBusyCursor(), does its processing, and
then calls wx.EndBusyCursor()

When I invoke the event from the toolbar button, all works as expected.
But when I use the menu item, the event handler is invoked, and does its
work, but the busy cursor does not appear - the default arrow pointer
remains.

I have been able to produce a minimal test application to demonstrate. It
is at:

<http://dl.dropbox.com/u/6106778/TestwxBusyCursor.py>

For convenience, there is an icon for the toolbar button, if required, at:

<http://dl.dropbox.com/u/6106778/mail.png>

Any guidance on this would be appreciated.

Thanks.

Hi Walter,

Hi,

I'm using wxGlade 0.6.3, wxPython 2.8.12 and python 2.7.2 on Fedora Linux
16 (all x86_64). This is my first application, so please be gentle if I'm
doing something stupid.

The (one and only) wx.Frame has a wx.ToolBar and a wx.MenuBar. One item
in each is bound to an event handler (they are both bound to the same
one).

The event handler calls wx.BeginBusyCursor(), does its processing, and
then calls wx.EndBusyCursor()

When I invoke the event from the toolbar button, all works as expected.
But when I use the menu item, the event handler is invoked, and does its
work, but the busy cursor does not appear - the default arrow pointer
remains.

Try the attached.

I try to keep as few references and don't use hard coded ID's, so used the return of wx.MenuItem and AddLabelTool to bind to the event instead.

I also changed from wx.NewId() to wx.ID_ANY, again more a question of preference. I use the ID_ANY when I don't care of what ID will be assigned and use wx.NewId() when I later need to know about the ID, in which case I would also assign it to a variable/attribute.

For some more tips on these things check out:

http://wiki.wxpython.org/wxPython%20Style%20Guide
http://wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind

Hope this helps
Werner

TestwxBusyCursor.py (2.18 KB)

···

On 12/22/2011 12:53 PM, Walter Hurry wrote:

Thanks for your comments, time and trouble Werner. I'll study the
differences between your version and mine, and will also look at the
links you provided. Unfortunately I may be somewhat hampered in practice
though, since the bits to which you refer are code generated by wxGlade.

Perhaps I can find a way to get wxGlade to generate it like that.

You changes don't seem to solve the problem though; your version exhibits
exactly the same behaviour - the BusyCursor shows up on clicking the
toolbar button, but not on selecting the menu item.

···

On Thu, 22 Dec 2011 14:04:19 +0100, werner wrote:

Hi Walter,

On 12/22/2011 12:53 PM, Walter Hurry wrote:

Hi,

I'm using wxGlade 0.6.3, wxPython 2.8.12 and python 2.7.2 on Fedora
Linux 16 (all x86_64). This is my first application, so please be
gentle if I'm doing something stupid.

The (one and only) wx.Frame has a wx.ToolBar and a wx.MenuBar. One item
in each is bound to an event handler (they are both bound to the same
one).

The event handler calls wx.BeginBusyCursor(), does its processing, and
then calls wx.EndBusyCursor()

When I invoke the event from the toolbar button, all works as expected.
But when I use the menu item, the event handler is invoked, and does
its work, but the busy cursor does not appear - the default arrow
pointer remains.

Try the attached.

I try to keep as few references and don't use hard coded ID's, so used
the return of wx.MenuItem and AddLabelTool to bind to the event instead.

I also changed from wx.NewId() to wx.ID_ANY, again more a question of
preference. I use the ID_ANY when I don't care of what ID will be
assigned and use wx.NewId() when I later need to know about the ID, in
which case I would also assign it to a variable/attribute.

For some more tips on these things check out:

wxPython Style Guide - wxPyWiki
self.Bind vs. self.button.Bind - wxPyWiki

Hope this helps Werner

Hi Walter,

Hi,

I'm using wxGlade 0.6.3, wxPython 2.8.12 and python 2.7.2 on Fedora
Linux 16 (all x86_64). This is my first application, so please be
gentle if I'm doing something stupid.

The (one and only) wx.Frame has a wx.ToolBar and a wx.MenuBar. One item
in each is bound to an event handler (they are both bound to the same
one).

The event handler calls wx.BeginBusyCursor(), does its processing, and
then calls wx.EndBusyCursor()

When I invoke the event from the toolbar button, all works as expected.
But when I use the menu item, the event handler is invoked, and does
its work, but the busy cursor does not appear - the default arrow
pointer remains.

Try the attached.

I try to keep as few references and don't use hard coded ID's, so used
the return of wx.MenuItem and AddLabelTool to bind to the event instead.

I also changed from wx.NewId() to wx.ID_ANY, again more a question of
preference. I use the ID_ANY when I don't care of what ID will be
assigned and use wx.NewId() when I later need to know about the ID, in
which case I would also assign it to a variable/attribute.

For some more tips on these things check out:

wxPython Style Guide - wxPyWiki
self.Bind vs. self.button.Bind - wxPyWiki

Hope this helps Werner

Thanks for your comments, time and trouble Werner. I'll study the
differences between your version and mine, and will also look at the
links you provided. Unfortunately I may be somewhat hampered in practice
though, since the bits to which you refer are code generated by wxGlade.

Oops, didn't think about that. Check on the wxGlade list if you can do the menu/toolbars like I did, otherwise make sure that assign unique ID's. You had "1" for one of them, I guess you should use wx.NewID() instead.

Perhaps I can find a way to get wxGlade to generate it like that.

You changes don't seem to solve the problem though; your version exhibits
exactly the same behaviour - the BusyCursor shows up on clicking the
toolbar button, but not on selecting the menu item.

I tried it on wxPython 2.9.2.4 and Python 2.7.2 on Win7 and I see the BusyCursor on both.

Just tried it on Ubuntu and now I see your problem too.

Werner

···

On 12/22/2011 03:30 PM, Walter Hurry wrote:

On Thu, 22 Dec 2011 14:04:19 +0100, werner wrote:

On 12/22/2011 12:53 PM, Walter Hurry wrote:

Hi Walter,

...

I tried it on wxPython 2.9.2.4 and Python 2.7.2 on Win7 and I see the BusyCursor on both.

Just tried it on Ubuntu and now I see your problem too.

Change your event handler to:

     def OnTest(self, event): # wxGlade: MyFrame.<event_handler>
         print "Starting Busy Cursor"
         wx.BeginBusyCursor()
         wx.Yield()
         sleep(2)
         wx.EndBusyCursor()
         print "Finished Busy Cursor"

i.e. add the wx.Yield() line, after that it works for me here on Ubuntu.

Werner

···

On 12/22/2011 04:10 PM, werner wrote:

Thanks! That works perfectly with both the sample application and the
real one. I'll have to look into what wx.Yield() does, as well as doing
the other reading.

Your help is much appreciated.

···

On Thu, 22 Dec 2011 16:14:18 +0100, werner wrote:

Hi Walter,

On 12/22/2011 04:10 PM, werner wrote:
...

I tried it on wxPython 2.9.2.4 and Python 2.7.2 on Win7 and I see the
BusyCursor on both.

Just tried it on Ubuntu and now I see your problem too.

Change your event handler to:

     def OnTest(self, event): # wxGlade: MyFrame.<event_handler>
         print "Starting Busy Cursor"
         wx.BeginBusyCursor() wx.Yield()
         sleep(2)
         wx.EndBusyCursor()
         print "Finished Busy Cursor"

i.e. add the wx.Yield() line, after that it works for me here on Ubuntu.

Werner