Ejemplo n.º 1
0
 def detect_win32_session_events(self, app_hwnd):
     """
     Use pywin32 to receive session notification events.
     """
     if app_hwnd is None:
         if self.tray_widget is None:
             #probably closing down, don't warn
             return
         log.warn("detect_win32_session_events(%s) missing handle!",
                  app_hwnd)
         return
     try:
         debug("detect_win32_session_events(%s)", app_hwnd)
         #register our interest in those events:
         #http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html#isenslogon
         #http://stackoverflow.com/questions/365058/detect-windows-logout-in-python
         #http://msdn.microsoft.com/en-us/library/aa383841.aspx
         #http://msdn.microsoft.com/en-us/library/aa383828.aspx
         win32ts.WTSRegisterSessionNotification(
             app_hwnd, win32ts.NOTIFY_FOR_THIS_SESSION)
         #catch all events: http://wiki.wxpython.org/HookingTheWndProc
         self.old_win32_proc = win32gui.SetWindowLong(
             app_hwnd, win32con.GWL_WNDPROC, self.MyWndProc)
     except Exception, e:
         log.error("failed to hook session notifications: %s", e)
Ejemplo n.º 2
0
 def set_global_menu(self):
     mh = getOSXMenuHelper()
     if mh.build()!=self.menu:
         log.error("the menu (%s) is not from the menu helper!", self.menu)
         return
     #redundant: the menu bar has already been set during gui init
     #using the basic the simple menu from build_menu_bar()
     self.macapp.set_menu_bar(self.menu)
     mh.add_full_menu()
     debug("OSXTray.set_global_menu() done")
Ejemplo n.º 3
0
 def set_global_menu(self):
     mh = getOSXMenuHelper()
     if mh.build()!=self.menu:
         log.error("the menu (%s) is not from the menu helper!", self.menu)
         return
     #redundant: the menu bar has already been set during gui init
     #using the basic the simple menu from build_menu_bar()
     self.macapp.set_menu_bar(self.menu)
     mh.add_full_menu()
     debug("OSXTray.set_global_menu() done")
Ejemplo n.º 4
0
 def set_icon(self, basefilename):
     if not self.macapp:
         return
     with_ext = "%s.png" % basefilename
     icon_dir = get_icon_dir()
     filename = os.path.join(icon_dir, with_ext)
     if not os.path.exists(filename):
         log.error("could not find icon '%s' in osx icon dir: %s", with_ext, icon_dir)
         return
     pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
     self.macapp.set_dock_icon_pixbuf(pixbuf)
Ejemplo n.º 5
0
 def set_icon(self, basefilename):
     if not self.macapp:
         return
     with_ext = "%s.png" % basefilename
     icon_dir = get_icon_dir()
     filename = os.path.join(icon_dir, with_ext)
     if not os.path.exists(filename):
         log.error("could not find icon '%s' in osx icon dir: %s", with_ext,
                   icon_dir)
         return
     pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
     self.macapp.set_dock_icon_pixbuf(pixbuf)
Ejemplo n.º 6
0
    def stop_win32_session_events(self, app_hwnd):
        try:
            if self.old_win32_proc and app_hwnd:
                win32api.SetWindowLong(app_hwnd, win32con.GWL_WNDPROC, self.old_win32_proc)
                self.old_win32_proc = None

            if app_hwnd:
                win32ts.WTSUnRegisterSessionNotification(app_hwnd)
            else:
                log.warn("stop_win32_session_events(%s) missing handle!", app_hwnd)
        except:
            log.error("stop_win32_session_events", exc_info=True)
Ejemplo n.º 7
0
    def stop_win32_session_events(self, app_hwnd):
        try:
            if self.old_win32_proc and app_hwnd:
                win32api.SetWindowLong(app_hwnd, win32con.GWL_WNDPROC,
                                       self.old_win32_proc)
                self.old_win32_proc = None

            if app_hwnd:
                win32ts.WTSUnRegisterSessionNotification(app_hwnd)
            else:
                log.warn("stop_win32_session_events(%s) missing handle!",
                         app_hwnd)
        except:
            log.error("stop_win32_session_events", exc_info=True)
Ejemplo n.º 8
0
 def MyWndProc(self, hWnd, msg, wParam, lParam):
     assert hWnd==self.getHWND(), "invalid hwnd: %s (expected %s)" % (hWnd, self.getHWND())
     if msg in IGNORE_EVENTS:
         debug("%s: %s / %s", IGNORE_EVENTS.get(msg), wParam, lParam)
     elif msg==WM_TRAY_EVENT:
         self.tray_event(wParam, lParam)
     elif msg==win32con.WM_ACTIVATEAPP:
         debug("WM_ACTIVATEAPP focus changed: %s / %s", wParam, lParam)
     else:
         log.warn("unexpected message: %s / %s / %s", KNOWN_WM_EVENTS.get(msg, msg), wParam, lParam)
     # Pass all messages to the original WndProc
     try:
         return win32gui.CallWindowProc(self.old_win32_proc, hWnd, msg, wParam, lParam)
     except Exception, e:
         log.error("error delegating call: %s", e)
Ejemplo n.º 9
0
 def MyWndProc(self, hWnd, msg, wParam, lParam):
     assert hWnd == self.getHWND(), "invalid hwnd: %s (expected %s)" % (
         hWnd, self.getHWND())
     if msg in IGNORE_EVENTS:
         debug("%s: %s / %s", IGNORE_EVENTS.get(msg), wParam, lParam)
     elif msg == WM_TRAY_EVENT:
         self.tray_event(wParam, lParam)
     elif msg == win32con.WM_ACTIVATEAPP:
         debug("WM_ACTIVATEAPP focus changed: %s / %s", wParam, lParam)
     else:
         log.warn("unexpected message: %s / %s / %s",
                  KNOWN_WM_EVENTS.get(msg, msg), wParam, lParam)
     # Pass all messages to the original WndProc
     try:
         return win32gui.CallWindowProc(self.old_win32_proc, hWnd, msg,
                                        wParam, lParam)
     except Exception, e:
         log.error("error delegating call: %s", e)
Ejemplo n.º 10
0
 def detect_win32_session_events(self, app_hwnd):
     """
     Use pywin32 to receive session notification events.
     """
     if app_hwnd is None:
         if self.tray_widget is None:
             #probably closing down, don't warn
             return
         log.warn("detect_win32_session_events(%s) missing handle!", app_hwnd)
         return
     try:
         debug("detect_win32_session_events(%s)", app_hwnd)
         #register our interest in those events:
         #http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html#isenslogon
         #http://stackoverflow.com/questions/365058/detect-windows-logout-in-python
         #http://msdn.microsoft.com/en-us/library/aa383841.aspx
         #http://msdn.microsoft.com/en-us/library/aa383828.aspx
         win32ts.WTSRegisterSessionNotification(app_hwnd, win32ts.NOTIFY_FOR_THIS_SESSION)
         #catch all events: http://wiki.wxpython.org/HookingTheWndProc
         self.old_win32_proc = win32gui.SetWindowLong(app_hwnd, win32con.GWL_WNDPROC, self.MyWndProc)
     except Exception, e:
         log.error("failed to hook session notifications: %s", e)