ToasterBox and SetFocus

Hi there,

Consider the small example of ToasterBox below. It opens a frame,
waits 3 seconds, and then pops up a toasterbox. When the toaster pops
up, the frame looses focus. In my real app this means that the frame
can no longer get keyboard input.

But this is exactly what i want to do: have a toaster box pop up while
the app can still get keyboard input. Is that possible at all?

When i looked in the toasterbox source code, there was one place where
a self.SetFocus() is called, that is in the ScrollUp function of the
class ToasterBoxWindow. Commenting out this function call does not
seem to
have any effect.

Calling SetFocus on the app immediately after the toasterbox appears
also does not seem to have any effect. I am confused because when i
call AcceptsFocus() on the ToasterBoxWindow it tells me that the it
can never have focus.

But how can i then prevent the app from loosing its focus when the
toasterbox appears ?

I am sure there is a simple, rational explanation for all of
this. :slight_smile:
Any ideas welcome!

Cheers
Maarten

ps: my system runs:
Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
wxPython 2.8.10.1
Fedora 10, Gnome 2.24.3

----------------------------------Beginning of Code
#!/usr/bin/python
# demoToasterBox-FocusProblem.py

import wx
import wx.lib.agw.toasterbox as toasterbox

class ToasterBoxFocusProblem(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        self.Show(True)
        timerid = wx.NewId()
        self.showtime = wx.Timer(self, timerid)
        self.showtime.Start(3000, True) # one shot timer
        self.Bind(wx.EVT_TIMER, self.RunToaster, id=timerid)

    def RunToaster(self, event):
        self.toaster = toasterbox.ToasterBox(self,
tbstyle=toasterbox.TB_COMPLEX)
        self.toaster.SetPopupPauseTime(3000)

        tbpanel = self.toaster.GetToasterBoxWindow()
        panel = wx.Panel(tbpanel, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)

        toasterButton = wx.Button(panel, wx.ID_ANY, 'Your logo here.')
        sizer.Add(toasterButton, 0, wx.EXPAND)

        sizer.Layout()
        panel.SetSizer(sizer)
        self.toaster.AddPanel(panel)

        self.toaster.Play()

app = wx.App()
ToasterBoxFocusProblem(None, -1, 'ToasterBoxFocusProblem')
app.MainLoop()
----------------------------------End of Code

Hi,

2010/1/27 Maarten Stol:

Hi there,

Consider the small example of ToasterBox below. It opens a frame,
waits 3 seconds, and then pops up a toasterbox. When the toaster pops
up, the frame looses focus. In my real app this means that the frame
can no longer get keyboard input.

But this is exactly what i want to do: have a toaster box pop up while
the app can still get keyboard input. Is that possible at all?

When i looked in the toasterbox source code, there was one place where
a self.SetFocus() is called, that is in the ScrollUp function of the
class ToasterBoxWindow. Commenting out this function call does not
seem to
have any effect.

Calling SetFocus on the app immediately after the toasterbox appears
also does not seem to have any effect. I am confused because when i
call AcceptsFocus() on the ToasterBoxWindow it tells me that the it
can never have focus.

But how can i then prevent the app from loosing its focus when the
toasterbox appears ?

I am sure there is a simple, rational explanation for all of
this. :slight_smile:
Any ideas welcome!

In the example you posted, you can not call SetFocus on the main frame
as frame themselves do not accept focus. What I did, I put a panel
inside your main frame and called:

wx.CallAfter(panel.SetFocus)

right after the toasterbox Play() function. See the attached file and
let me know if it works.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

tbissue.py (1.11 KB)

Andrea Gavana wrote:

Hi,

2010/1/27 Maarten Stol:

Hi there,

Consider the small example of ToasterBox below. It opens a frame,
waits 3 seconds, and then pops up a toasterbox. When the toaster pops
up, the frame looses focus. In my real app this means that the frame
can no longer get keyboard input.

But this is exactly what i want to do: have a toaster box pop up while
the app can still get keyboard input. Is that possible at all?

When i looked in the toasterbox source code, there was one place where
a self.SetFocus() is called, that is in the ScrollUp function of the
class ToasterBoxWindow. Commenting out this function call does not
seem to
have any effect.

Calling SetFocus on the app immediately after the toasterbox appears
also does not seem to have any effect. I am confused because when i
call AcceptsFocus() on the ToasterBoxWindow it tells me that the it
can never have focus.

But how can i then prevent the app from loosing its focus when the
toasterbox appears ?

I am sure there is a simple, rational explanation for all of
this. :slight_smile:
Any ideas welcome!

In the example you posted, you can not call SetFocus on the main frame
as frame themselves do not accept focus. What I did, I put a panel
inside your main frame and called:

wx.CallAfter(panel.SetFocus)

right after the toasterbox Play() function. See the attached file and
let me know if it works.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

Thank you Andrea,

I did not realize that frames can not have focus.

However, the problem is not solved yet. I am seeing the same behaviour with the CallAfter as without it. The main frame gets its focus back only when the toaster dies, or when i press Alt-Tab.

What behaviour did you see?

Maarten

Hi,

2010/1/27 Maarten Stol:

Andrea Gavana wrote:

Hi,

2010/1/27 Maarten Stol:

Hi there,

Consider the small example of ToasterBox below. It opens a frame,
waits 3 seconds, and then pops up a toasterbox. When the toaster pops
up, the frame looses focus. In my real app this means that the frame
can no longer get keyboard input.

But this is exactly what i want to do: have a toaster box pop up while
the app can still get keyboard input. Is that possible at all?

When i looked in the toasterbox source code, there was one place where
a self.SetFocus() is called, that is in the ScrollUp function of the
class ToasterBoxWindow. Commenting out this function call does not
seem to
have any effect.

Calling SetFocus on the app immediately after the toasterbox appears
also does not seem to have any effect. I am confused because when i
call AcceptsFocus() on the ToasterBoxWindow it tells me that the it
can never have focus.

But how can i then prevent the app from loosing its focus when the
toasterbox appears ?

I am sure there is a simple, rational explanation for all of
this. :slight_smile:
Any ideas welcome!

In the example you posted, you can not call SetFocus on the main frame
as frame themselves do not accept focus. What I did, I put a panel
inside your main frame and called:

wx.CallAfter(panel.SetFocus)

right after the toasterbox Play() function. See the attached file and
let me know if it works.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

Thank you Andrea,

I did not realize that frames can not have focus.

However, the problem is not solved yet. I am seeing the same behaviour with
the CallAfter as without it. The main frame gets its focus back only when
the toaster dies, or when i press Alt-Tab.

What behaviour did you see?

I have seen the main frame losing the focus when the toasterbox appear
but gaining it back almost immediately (the effect of wx.CallAfter).
It may be a platform difference: I tried on Windows XP SP2, Python
2.5.4, wxPython 2.8.10.1 and AGW from SVN. What is your configuration?
Does the sample I attached before behave the same?

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

Maarten mentioned being on Fedora Core 10.

I tried your CallAfter() hint on OSX, and the focus moved to
the toasterbox. That is to say, the menubar of the main window
went gray and reverted to 'active' when the toasterbox disappeared.

Using wxPython 2.8.10.1, python 2.5.4 on Snow Leopard.

Antonio

Op 27-01-10 17:34, Andrea Gavana schreef:

···

Hi,

2010/1/27 Maarten Stol:

Andrea Gavana wrote:

Hi,

2010/1/27 Maarten Stol:

Hi there,

Consider the small example of ToasterBox below. It opens a frame,
waits 3 seconds, and then pops up a toasterbox. When the toaster pops
up, the frame looses focus. In my real app this means that the frame
can no longer get keyboard input.

But this is exactly what i want to do: have a toaster box pop up while
the app can still get keyboard input. Is that possible at all?

When i looked in the toasterbox source code, there was one place where
a self.SetFocus() is called, that is in the ScrollUp function of the
class ToasterBoxWindow. Commenting out this function call does not
seem to
have any effect.

Calling SetFocus on the app immediately after the toasterbox appears
also does not seem to have any effect. I am confused because when i
call AcceptsFocus() on the ToasterBoxWindow it tells me that the it
can never have focus.

But how can i then prevent the app from loosing its focus when the
toasterbox appears ?

I am sure there is a simple, rational explanation for all of
this. :slight_smile:
Any ideas welcome!

In the example you posted, you can not call SetFocus on the main frame
as frame themselves do not accept focus. What I did, I put a panel
inside your main frame and called:

wx.CallAfter(panel.SetFocus)

right after the toasterbox Play() function. See the attached file and
let me know if it works.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

Thank you Andrea,

I did not realize that frames can not have focus.

However, the problem is not solved yet. I am seeing the same behaviour with
the CallAfter as without it. The main frame gets its focus back only when
the toaster dies, or when i press Alt-Tab.

What behaviour did you see?

I have seen the main frame losing the focus when the toasterbox appear
but gaining it back almost immediately (the effect of wx.CallAfter).
It may be a platform difference: I tried on Windows XP SP2, Python
2.5.4, wxPython 2.8.10.1 and AGW from SVN. What is your configuration?
Does the sample I attached before behave the same?

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

On my Win XP the following seems to be happening:

When the toasterbox is scrolling up I think the focus shifts
very fast between the main window and the toasterbox. This is probably
due to the self.SetFocus() in ScrollUp() in the toasterbox sources.

When Scrolling down it doesn't exhibit this behaviour, likely because
ScrollDown has no SetFocus() call at the end.

But on OSX and Linux apparently the toasterbox grabs the keyboard
focus and wx.CallAfter(panel.SetFocus) does not put it back.

Antonio

Op 27-01-10 17:34, Andrea Gavana schreef:

···

Hi,

2010/1/27 Maarten Stol:

Andrea Gavana wrote:

Hi,

2010/1/27 Maarten Stol:

Hi there,

Consider the small example of ToasterBox below. It opens a frame,
waits 3 seconds, and then pops up a toasterbox. When the toaster pops
up, the frame looses focus. In my real app this means that the frame
can no longer get keyboard input.

But this is exactly what i want to do: have a toaster box pop up while
the app can still get keyboard input. Is that possible at all?

When i looked in the toasterbox source code, there was one place where
a self.SetFocus() is called, that is in the ScrollUp function of the
class ToasterBoxWindow. Commenting out this function call does not
seem to
have any effect.

Calling SetFocus on the app immediately after the toasterbox appears
also does not seem to have any effect. I am confused because when i
call AcceptsFocus() on the ToasterBoxWindow it tells me that the it
can never have focus.

But how can i then prevent the app from loosing its focus when the
toasterbox appears ?

I am sure there is a simple, rational explanation for all of
this. :slight_smile:
Any ideas welcome!

In the example you posted, you can not call SetFocus on the main frame
as frame themselves do not accept focus. What I did, I put a panel
inside your main frame and called:

wx.CallAfter(panel.SetFocus)

right after the toasterbox Play() function. See the attached file and
let me know if it works.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

Thank you Andrea,

I did not realize that frames can not have focus.

However, the problem is not solved yet. I am seeing the same behaviour with
the CallAfter as without it. The main frame gets its focus back only when
the toaster dies, or when i press Alt-Tab.

What behaviour did you see?

I have seen the main frame losing the focus when the toasterbox appear
but gaining it back almost immediately (the effect of wx.CallAfter).
It may be a platform difference: I tried on Windows XP SP2, Python
2.5.4, wxPython 2.8.10.1 and AGW from SVN. What is your configuration?
Does the sample I attached before behave the same?

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

I was hoping the call to self.SetFocus in ScrollUp() was the cause.
However, removing this SetFocus() call from the toasterbox source code
has no visible effect on my system. The toasterbox still steals the
focus.

···

On Jan 27, 7:53 pm, Antonio Goméz Soto <antonio.gomez.s...@gmail.com> wrote:

On my Win XP the following seems to be happening:

When the toasterbox is scrolling up I think the focus shifts
very fast between the main window and the toasterbox. This is probably
due to the self.SetFocus() in ScrollUp() in the toasterbox sources.

What is your configuration?

my system runs:
Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
wxPython 2.8.10.1
Fedora 10, Gnome 2.24.3

Does the sample I attached before behave the same?

Yes it does, i regret to say :slight_smile:

···

On Jan 27, 5:34 pm, Andrea Gavana <andrea.gav...@gmail.com> wrote:

Andrea,

I have just tested my own sample code on a windows XP machine. Funny
thing is that it works better, but still not quite like i would expect
it to.

This is a XP prof 2002, SP3, Python 2.5.4, wx 2.8.10.1, running on
SunVirtualBox 3.0.4 on my Fedora 10 laptop.

During the scrolling up of the toaster the main frame's focus is lost,
but as soon as the scrolling up ends and the toaster is fully visible
the main frame gets its focus back. During the scrolling down the main
frame does not loose focus at all.

I would really like to see the scroll down behaviour during the
scrolling up too.
Is that possible?

Regards,
Maarten

···

On Jan 27, 5:34 pm, Andrea Gavana <andrea.gav...@gmail.com> wrote:

I have seen the main frame losing the focus when the toasterbox appear
but gaining it back almost immediately (the effect of wx.CallAfter).
It may be a platform difference: I tried on Windows XP SP2, Python
2.5.4, wxPython 2.8.10.1 and AGW from SVN. What is your configuration?
Does the sample I attached before behave the same?

Hi,

2010/1/28 Maarten Stol:

I have seen the main frame losing the focus when the toasterbox appear
but gaining it back almost immediately (the effect of wx.CallAfter).
It may be a platform difference: I tried on Windows XP SP2, Python
2.5.4, wxPython 2.8.10.1 and AGW from SVN. What is your configuration?
Does the sample I attached before behave the same?

Andrea,

I have just tested my own sample code on a windows XP machine. Funny
thing is that it works better, but still not quite like i would expect
it to.

This is a XP prof 2002, SP3, Python 2.5.4, wx 2.8.10.1, running on
SunVirtualBox 3.0.4 on my Fedora 10 laptop.

During the scrolling up of the toaster the main frame's focus is lost,
but as soon as the scrolling up ends and the toaster is fully visible
the main frame gets its focus back. During the scrolling down the main
frame does not loose focus at all.

I would really like to see the scroll down behaviour during the
scrolling up too.
Is that possible?

I have no idea, I will tinker it a bit and see if it is possible. The
main issue I see is that ToasterBox is a wx.Frame, and whatever trick
I can try it is bound to steal the focus one way or another. Moreover,
every platform will behave in its own way, so while I might be able to
fix it on Windows it will surely break down on GTK and/or Mac.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On Jan 27, 5:34 pm, Andrea Gavana <andrea.gav...@gmail.com> wrote: