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)
def set_dock_icon(self): if not self.default_icon_filename: return filename = os.path.abspath(self.default_icon_filename) if not os.path.exists(filename): log.warn("cannot set dock icon, file '%s' not found!", filename) return debug("OSXTray.set_dock_icon() loading icon from %s", filename) pixbuf = gtk.gdk.pixbuf_new_from_file(filename) self.macapp.set_dock_icon_pixbuf(pixbuf)
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)
def tray_event(self, wParam, lParam): x, y = win32api.GetCursorPos() size = win32api.GetSystemMetrics(win32con.SM_CXSMICON) self.recalculate_geometry(x, y, size, size) if lParam in BALLOON_EVENTS: debug("WM_TRAY_EVENT: %s", BALLOON_EVENTS.get(lParam)) elif lParam==win32con.WM_MOUSEMOVE: debug("WM_TRAY_EVENT: WM_MOUSEMOVE") if self.mouseover_cb: self.mouseover_cb(x, y) elif lParam in BUTTON_MAP: debug("WM_TRAY_EVENT: click %s", BUTTON_MAP.get(lParam)) else: log.warn("WM_TRAY_EVENT: unknown event: %s / %s", wParam, lParam)
def tray_event(self, wParam, lParam): x, y = win32api.GetCursorPos() size = win32api.GetSystemMetrics(win32con.SM_CXSMICON) self.recalculate_geometry(x, y, size, size) if lParam in BALLOON_EVENTS: debug("WM_TRAY_EVENT: %s", BALLOON_EVENTS.get(lParam)) elif lParam == win32con.WM_MOUSEMOVE: debug("WM_TRAY_EVENT: WM_MOUSEMOVE") if self.mouseover_cb: self.mouseover_cb(x, y) elif lParam in BUTTON_MAP: debug("WM_TRAY_EVENT: click %s", BUTTON_MAP.get(lParam)) else: log.warn("WM_TRAY_EVENT: unknown event: %s / %s", wParam, lParam)
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)
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)
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)