|
Hi all,
I'm writing a simple GUI app with wxPython and would like to implement a "minize to tray" functionality. Did a bit googling and basically found the solution to be: 1. Handle the ICONIZE event to Hide() the window 2. Handle the LEFT_DCLICKE event of the icon to do - Iconize(False) - Show(True) - Raise() It worked quite well under Windows. But on Linux, when trying to restore the window, it sorta flashed back for 1/2 second and disappear again. Is there a cross platform way of doing this? My environment: python 2.5 + wxPython 2.8.4 Thanks, |
|
Wenzhi Liang wrote:
> Hi all, > > I'm writing a simple GUI app with wxPython and would like to implement > a "minize to tray" > functionality. Did a bit googling and basically found the solution to be: > > 1. Handle the ICONIZE event to Hide() the window > 2. Handle the LEFT_DCLICKE event of the icon to do > - Iconize(False) > - Show(True) > - Raise() > > It worked quite well under Windows. But on Linux, when trying to > restore the window, it > sorta flashed back for 1/2 second and disappear again. Is there a > cross platform way of > doing this? > > My environment: > python 2.5 + wxPython 2.8.4 I think we'll need a sample to play with to figure this out. -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! |
|
AFAIK wx.EVT_ICONIZE is also generated when restoring from taskbar.
You should add "if event.Iconized():" before calling Hide() -Roee. On Nov 13, 2007 12:51 AM, Robin Dunn <[hidden email]> wrote: > Wenzhi Liang wrote: > > Hi all, > > > > I'm writing a simple GUI app with wxPython and would like to implement > > a "minize to tray" > > functionality. Did a bit googling and basically found the solution to be: > > > > 1. Handle the ICONIZE event to Hide() the window > > 2. Handle the LEFT_DCLICKE event of the icon to do > > - Iconize(False) > > - Show(True) > > - Raise() > > > > It worked quite well under Windows. But on Linux, when trying to > > restore the window, it > > sorta flashed back for 1/2 second and disappear again. Is there a > > cross platform way of > > doing this? > > > > My environment: > > python 2.5 + wxPython 2.8.4 > > I think we'll need a sample to play with to figure this out. > > -- > Robin Dunn > Software Craftsman > http://wxPython.org Java give you jitters? Relax with wxPython! > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > |
|
Thanks for the reply. Here is the code I use:
init() self.Bind(wx.EVT_ICONIZE, self.OnIconify) self.tbicon.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate) def OnTaskBarActivate(self, evt): print 'OnTaskBarActivate...' if self.IsIconized(): self.Iconize(False) if not self.IsShown(): self.Show(True) self.Raise() def OnIconify(self, e): """ Being minimized, hide self, which removes the program from the taskbar. """ print 'OnIconify...' if not self.IsIconized(): self.Iconize(True) self.Show(False) Indeed when I double click on the tray icon, I got: OnTaskBarActivate... OnIconify... OnIconify... Which is a little bit strange. Why is the latter two event triggered? Regards, On Nov 13, 2007 11:54 AM, roee shlomo <[hidden email]> wrote: > AFAIK wx.EVT_ICONIZE is also generated when restoring from taskbar. > You should add "if event.Iconized():" before calling Hide() > > -Roee. > > > On Nov 13, 2007 12:51 AM, Robin Dunn <[hidden email]> wrote: > > Wenzhi Liang wrote: > > > Hi all, > > > > > > I'm writing a simple GUI app with wxPython and would like to implement > > > a "minize to tray" > > > functionality. Did a bit googling and basically found the solution to be: > > > > > > 1. Handle the ICONIZE event to Hide() the window > > > 2. Handle the LEFT_DCLICKE event of the icon to do > > > - Iconize(False) > > > - Show(True) > > > - Raise() > > > > > > It worked quite well under Windows. But on Linux, when trying to > > > restore the window, it > > > sorta flashed back for 1/2 second and disappear again. Is there a > > > cross platform way of > > > doing this? > > > > > > My environment: > > > python 2.5 + wxPython 2.8.4 > > > > I think we'll need a sample to play with to figure this out. > > > > -- > > Robin Dunn > > Software Craftsman > > http://wxPython.org Java give you jitters? Relax with wxPython! > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [hidden email] > > For additional commands, e-mail: [hidden email] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > |
Indeed when I double click on the tray icon, I got: you should only get one "OnIconify..." when double clicking (and this is what I get on ubuntu). As I said EVT_ICONIZE is also triggered on restore in wxGTK.
In case your code doesn't work try this demo: import wx #-------------------------- Create Icon -------------------------- def GetMondrianData(): return \ '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\ \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\ ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\ o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\ \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\ \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\ \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82' def GetMondrianBitmap(): return wx.BitmapFromImage(GetMondrianImage()) def GetMondrianImage(): import cStringIO stream = cStringIO.StringIO(GetMondrianData()) return wx.ImageFromStream(stream) def GetMondrianIcon(): icon = wx.EmptyIcon() icon.CopyFromBitmap(GetMondrianBitmap()) return icon #------------------------------------------------------------------------- class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "Test TaskBarIcon") self.icon = GetMondrianIcon() self.SetIcon(self.icon) self.tbicon = wx.TaskBarIcon() self.Bind(wx.EVT_ICONIZE, self.OnIconify) self.tbicon.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate) self.Show() def OnTaskBarActivate(self, evt): print 'OnTaskBarActivate...' if self.IsIconized(): self.Iconize(False) self.Show() self.Raise() self.tbicon.RemoveIcon() def OnIconify(self, evt): print 'OnIconify...' if evt.Iconized(): self.Iconize(True) self.Hide() self.tbicon.SetIcon(self.icon) if __name__ == "__main__": app = wx.App("") frame = TestFrame() app.MainLoop() |
|
On Nov 15, 2007 10:00 PM, roee shlomo <[hidden email]> wrote:
> > > Indeed when I double click on the tray icon, I got: > > OnTaskBarActivate... > > OnIconify... > > OnIconify... > you should only get one "OnIconify..." when double clicking (and this is > what I get on ubuntu). As I said EVT_ICONIZE is also triggered on restore in > wxGTK. > In case your code doesn't work try this demo: > > > def OnIconify(self, evt): > print 'OnIconify...' > if evt.Iconized(): That did the trick. :) Thanks. > self.Iconize(True) > self.Hide() > self.tbicon.SetIcon(self.icon) > |
| Powered by Nabble | Edit this page |
