wxpython:how to minimize to taskbar

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jimmy

    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?

  • kyosohma@gmail.com

    #2
    Re: wxpython:how to minimize to taskbar

    On Aug 28, 9:10 am, Jimmy <mcknight0...@g mail.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

    Comment

    • programmer.py@gmail.com

      #3
      Re: wxpython:how to minimize to taskbar

      On Aug 28, 9:10 am, Jimmy <mcknight0...@g mail.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_LEF T_DCLICK

      class ddTaskBarIcon(T askBarIcon):
      def __init__(self, icon, tooltip, frame):
      TaskBarIcon.__i nit__(self)
      self.SetIcon(ic on, tooltip)
      self.frame = frame

      #
      # At the very least, restore the frame if double clicked. Add
      other
      # events later.
      #
      self.Bind(EVT_T ASKBAR_LEFT_DCL ICK, self.on_left_dc lick)

      def on_left_dclick( self, e):
      if self.frame.IsIc onized():
      self.frame.Icon ize(False)
      if not self.frame.IsSh own():
      self.frame.Show (True)
      self.frame.Rais e()

      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(s elf.frame_icon, "Dap Daemon", self)

      # Handle the window being `iconized` (err minimized)
      self.Bind(wx.EV T_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

      Comment

      • kyosohma@gmail.com

        #4
        Re: wxpython:how to minimize to taskbar

        On Aug 28, 9:50 am, "programmer...@ gmail.com"
        <programmer...@ gmail.comwrote:
        On Aug 28, 9:10 am, Jimmy <mcknight0...@g mail.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_LEF T_DCLICK
        >
        class ddTaskBarIcon(T askBarIcon):
        def __init__(self, icon, tooltip, frame):
        TaskBarIcon.__i nit__(self)
        self.SetIcon(ic on, tooltip)
        self.frame = frame
        >
        #
        # At the very least, restore the frame if double clicked. Add
        other
        # events later.
        #
        self.Bind(EVT_T ASKBAR_LEFT_DCL ICK, self.on_left_dc lick)
        >
        def on_left_dclick( self, e):
        if self.frame.IsIc onized():
        self.frame.Icon ize(False)
        if not self.frame.IsSh own():
        self.frame.Show (True)
        self.frame.Rais e()
        >
        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(s elf.frame_icon, "Dap Daemon", self)
        >
        # Handle the window being `iconized` (err minimized)
        self.Bind(wx.EV T_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

        Comment

        Working...