Re: wxpython:how to minimize to taskbar



On Aug 28, 9:10 am, Jimmy <mcknight0...@xxxxxxxxx> wrote:
I'm kinda newbie to python and wxPython. Now I'm confronting a thorny
problem: how can I make my program minimize to the taskbar
represented as an ico, and when there is some message from network
coming, it will pop out?

Warning. I have not tested this. I happened to have some old code
that would iconify to the system tray. Here's what I think you need
to do. (If it does not work, just yell and I'll try to hack something
together for you.)

Inside the ctor of your mainframe, you'll need to construct a
wxTaskBarIcon (I derive from it). This is my code that derives from
wxTaskBarIcon. The comments should give you a good idea of how this
thing works. I *think* this will shove the icon in the system tray,
even if you're not `iconified` -- so only create it if you want to
show up in the system tray.

## My wxTaskBarIcon derived object...
"""
Taskbar icon.

Not much functionality here, not even a menu. In the future, this
will be a
good place to allow dclient functionality from the systray.
"""

from wx import TaskBarIcon, EVT_TASKBAR_LEFT_DCLICK

class ddTaskBarIcon(TaskBarIcon):
def __init__(self, icon, tooltip, frame):
TaskBarIcon.__init__(self)
self.SetIcon(icon, tooltip)
self.frame = frame

#
# At the very least, restore the frame if double clicked. Add
other
# events later.
#
self.Bind(EVT_TASKBAR_LEFT_DCLICK, self.on_left_dclick)

def on_left_dclick(self, e):
if self.frame.IsIconized():
self.frame.Iconize(False)
if not self.frame.IsShown():
self.frame.Show(True)
self.frame.Raise()

def CreatePopupMenu(self):
"""
Override with menu functionality, later.
"""
return None

Next is where I use it in my wxFrame derived object. This is the code
in my ctor.
# ddTaskBarIcon is defined above...
self.trayicon = ddTaskBarIcon(self.frame_icon, "Dap Daemon", self)

# Handle the window being `iconized` (err minimized)
self.Bind(wx.EVT_ICONIZE, self.on_iconify)

# This is the event handler referenced in the ctor above
def on_iconify(self, e):
"""
Being minimized, hide self, which removes the program from the
taskbar.
"""
self.Hide()

So how does this work? Well, the ddTaskBarIcon (err, i realize this
is a misnomer) is constructed, which puts an icon in the system tray.
The icon has a dbl-click event handler that will `raise` and show the
window if necessary.

The iconify event handler will hide the window if a minimize event
occurs. This keeps the window from showing up in the windows taskbar.

Thats the magic. YMMV.

FWIW - the code I reference is over 5 years old and still runs with
wxPython 2.8ish... Kudos to Robin Dunn and crew. Great job.

jw

.



Relevant Pages

  • Re: Task bar icon tips buried
    ... > launch section or the system tray section of the task bar, the icon info ... > window is buried underneath/behind the task bar. ... Taskbar Properties> uncheck box to keep taskbar on top of other windows. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: I need a component for REMOTE PC Control
    ... win -runapp paramether. ... I see the problem with taskbar and icon too. ... > small window for a fraction of a second, ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Hello Windows 7, so long Vista...
    ... I have always made the taskbar double height, and then made the bottom row the "Quick Launch" area, and the top row is where the open/minimized windows go. ... I don't want my program launch icon becoming the opened/minimized icon, ... The transparent Window over top of the IE taskbar icon even overlaps each instance so you can see that you have more than one open. ...
    (microsoft.public.windows.vista.general)
  • Re: wxpython:how to minimize to taskbar
    ... Taskbar icon. ... The icon has a dbl-click event handler that will `raise` and show the ... window if necessary. ...
    (comp.lang.python)
  • Re: XP Taskbar Anomaly, Help?
    ... icon mode so the icons line up in the taskbar. ... that clicking an iconin the taskbar does NOT ... A restart does fix it for me and it stays fixed for sometime but always ... The wrong window comes forward when I click a task bar icon. ...
    (microsoft.public.windowsxp.basics)