wx.adv.TaskBarIcon.showBalloon: How To avoid create a new taskbar icon to make a notification?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

wx.adv.TaskBarIcon.showBalloon: How To avoid create a new taskbar icon to make a notification?

Alex Vincent
Hi guys!
    I want to make a balloon with a icon in taskbar, with the code below, but each notification will create a new icon.
    Here's my code, hope you can help me out :)

class MyTaskBarIcon(wx.adv.TaskBarIcon):
    ICON = "icon.ico"
    TITLE = "Demo"

    def __init__(self):
        wx.adv.TaskBarIcon.__init__(self)
        self.SetIcon(wx.Icon(self.ICON), self.TITLE)


class MyApp(wx.App):
    def OnInit(self):
        MyTaskBarIcon()
       
return True


def taskbar_show_notification(title, msg, duration=5):
    MyTaskBarIcon.ShowBalloon(MyTaskBarIcon(), title, msg, duration)

taskbar_show_notification
('Test', 'Test Message')


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.adv.TaskBarIcon.showBalloon: How To avoid create a new taskbar icon to make a notification?

Tim Roberts
Alex Vincent wrote:
> Hi guys!
>     I want to make a balloon with a icon in taskbar, with the code
> below, but each notification will create a new icon.
>     Here's my code, hope you can help me out :)

Well, yes.  You create and then throw away a MyTaskBarIcon instance in
the MyApp constructor, and then you create a new MyTaskBarIcon every
time you call ShowBalloon.

If you only want one, then save the instance you create in the
constructor and use it:

class MyApp(wx.App):
    def OnInit(self):
        global taskbaricon
        taskbaricon = MyTaskBarIcon()

def taskbar_show_notification(title, msg, duration=5):
    taskbaricon.ShowBalloon( title, msg, duration )   

However, if you're really calling this outside of any class, then
there's really no need to create the object in the wx.App constructor. 
You might as well just do it at a global level.

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.