473,396 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

wxpython:how to minimize to taskbar

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?

Aug 28 '07 #1
3 14239
On Aug 28, 9:10 am, Jimmy <mcknight0...@gmail.comwrote:
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?
Look at the wxPython demo source code. I found the code I needed in
the main.py file under the DemoTaskBarIcon class, which is a subclass
of wx.TaskBarIcon. You can't view it by running the demo. You have to
open the main.py file itself. On my Windows box, it's found here:
C:\Program Files\wxPython2.8 Docs and Demos\demo

You'll have to call a handler when you receive a message from the
network that basically calls your program's "show" command.

Mike

Aug 28 '07 #2
On Aug 28, 9:10 am, Jimmy <mcknight0...@gmail.comwrote:
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

Aug 28 '07 #3
On Aug 28, 9:50 am, "programmer...@gmail.com"
<programmer...@gmail.comwrote:
On Aug 28, 9:10 am, Jimmy <mcknight0...@gmail.comwrote:
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
I've been dinking around with getting one of my programs to minimize
to the system tray for quite a while. I could get the icon, but I
could not get an event to fire when I minimized. Thanks for the code.
Now it works.

Mike

Aug 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Curzio Basso | last post by:
Hi all, I have a problem for which I wasn't able to find an answer anywhere else, maybe someone can give me a hint... I designed with XRCed a small GUI (the code is at the bottom of the...
0
by: matthiasjanes | last post by:
Dear all, I'm very new to wxPython. I'm using the wxglade ide to make a Gui. question is: Let's say I have a very simple frame with to menu entrys: LoadPanel1 and LoadPanel2 ...
1
by: Erik Bethke | last post by:
Hello All, I now have a wx.NO_BORDER frame that I have written dragging code for... I like my window this way as it looks sleeker and I am now installing some image buttons. Now I would like...
2
by: Brent W. Hughes | last post by:
I'm running some code that takes a long time to finish. I would like the user to be able to do other things while it is running. It seems to me there is a function I can call to tell wxPython to...
1
by: w.p. | last post by:
Hello! I want change default tab traversing in my app. But i don't know how to do it :( Belowe i include simple example - i want change default tab order: radiobutton "mode11" -> radiobutton...
0
by: André | last post by:
I'm trying to change an app so that it uses gettext for translations rather than the idiosyncratic way I am using. I've tried the example on the wxPython wiki...
0
by: dirvine | last post by:
Hi All Does anyone have any peice of wxPython code thats cross platform and allows an app to be minimised in the system tray. I am hoping for windows/kde/gnome/darwin if possible. I have been...
7
by: John Salerno | last post by:
I was reading in the wxPython wiki that most of the time you don't have to include the id parameter at all, and you can just use keyword arguments for other parameters. But I'm having trouble...
3
by: Leo Lee | last post by:
I need a window's handle to be passed to external c++. Thanks in advance
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.