def OnTaskbarNotify(self, hwnd, msg, wparam, lparam): if lparam == win32con.WM_RBUTTONUP: menu = win32gui.CreatePopupMenu() win32gui.AppendMenu(menu, win32con.MF_STRING, SEARCH_MENU_ID, "Search") win32gui.AppendMenu(menu, win32con.MF_STRING, PREFERENCES_MENU_ID, "Preferences") win32gui.AppendMenu(menu, win32con.MF_STRING, HELP_MENU_ID, "Help") win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 1002, "") if maay.globalvars.indexer.isPaused(): win32gui.AppendMenu(menu, win32con.MF_STRING, PAUSE_INDEXING_MENU_ID, "Pause indexing for 15 minutes more") win32gui.AppendMenu(menu, win32con.MF_STRING, RESUME_INDEXING_MENU_ID, "Resume indexing") else: win32gui.AppendMenu(menu, win32con.MF_STRING, PAUSE_INDEXING_MENU_ID, "Pause indexing") win32gui.AppendMenu(menu, win32con.MF_STRING, EXIT_MENU_ID, "Exit") win32gui.SetMenuDefaultItem(menu, SEARCH_MENU_ID, 0) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) elif lparam == win32con.WM_LBUTTONDBLCLK: webbrowser.open("http://127.0.0.1:%d/maay/resultspool" % maay.constants.MAAY_PORT, autoraise=1) return 1
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam): if lparam == win32con.WM_RBUTTONUP: menu = win32gui.CreatePopupMenu() win32gui.AppendMenu(menu, win32con.MF_STRING, Win32MaayTaskbar.SEARCH_MENU_ID, "Search") win32gui.AppendMenu(menu, win32con.MF_STRING, Win32MaayTaskbar.INDEXATION_MENU_ID, "Manage Folders") win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 1002, "") win32gui.AppendMenu(menu, win32con.MF_STRING, Win32MaayTaskbar.HOMEPAGE_MENU_ID, "Maay Homepage") win32gui.SetMenuDefaultItem(menu, Win32MaayTaskbar.SEARCH_MENU_ID, 0) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) elif lparam == win32con.WM_LBUTTONDBLCLK: webbrowser.open("http://127.0.0.1:%s/" % self.node.NODE_CONFIG.webserver_port, autoraise=1) return 1
def get_popup(self): menu = win32gui.CreatePopupMenu() (item, _) = win32gui_struct.PackMENUITEMINFO(text=u'Quit', wID=self.IDI_QUIT) win32gui.InsertMenuItem(menu, 0, 1, item) win32gui.SetMenuDefaultItem(menu, 0, self.IDI_QUIT) (item, _) = win32gui_struct.PackMENUITEMINFO(text=u'Test', wID=123) win32gui.InsertMenuItem(menu, 0, 1, item) return menu
def create_menu(self): menu = win32gui.CreatePopupMenu() item, extras = win32gui_struct.PackMENUITEMINFO( text = self.app_state.gettext('Close'), hbmpItem=win32con.HBMMENU_MBAR_CLOSE, wID=EXIT_COMMAND ) win32gui.InsertMenuItem( menu, 0, 1, item ) win32gui.SetMenuDefaultItem( menu, EXIT_COMMAND, 0 ) item, extras = win32gui_struct.PackMENUITEMINFO( text = self.app_state.gettext('Open'), hbmpChecked = None, hbmpUnchecked = None, wID=OPEN_COMMAND ) win32gui.InsertMenuItem( menu, 0, 1, item ) win32gui.SetForegroundWindow(self.window_id) x, y = win32gui.GetCursorPos() win32gui.TrackPopupMenu( menu, win32con.TPM_LEFTALIGN, x, y, 0, self.window_id, None ) win32gui.PostMessage( self.window_id, win32con.WM_NULL, 0, 0 )
def on_rightclick(self, systray): #self.change_tooltip("You right clicked me.") menu = win32gui.CreatePopupMenu() win32gui.AppendMenu( menu, win32con.MF_STRING, 1023, "About") if len(self.custom_menu_items) > 0: for menu_item in self.custom_menu_items.values(): if callable(menu_item['func']): try: is_checked = menu_item['func'](self, get_state = True) except Exception as e: print(e) else: is_checked = False flags = win32con.MF_STRING | (win32con.MF_CHECKED if is_checked else 0) win32gui.AppendMenu( menu, flags, menu_item['id'], menu_item['text']) win32gui.AppendMenu( menu, win32con.MF_SEPARATOR, -1, "") win32gui.AppendMenu( menu, win32con.MF_STRING, 1024, "E&xit") win32gui.SetMenuDefaultItem(menu, 0, True) pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam): if lparam == win32con.WM_LBUTTONUP: pass elif lparam == win32con.WM_LBUTTONDBLCLK: self.OnCommand(hwnd, win32con.WM_COMMAND, self.MENU_OPEN_CLAM, 0) elif lparam == win32con.WM_RBUTTONUP: if self._nomenu: hwnd = win32gui.FindWindow('#32770', 'Blindata Update') if hwnd: try: win32gui.ShowWindow(hwnd, win32con.SW_SHOW) win32gui.SetForegroundWindow(hwnd) win32gui.SetFocus(hwnd) except Exception, e: print 'ShowWindow Error: %s' % str(e) return 1 # create scheduler menu scheduler_popup = win32gui.CreatePopupMenu() win32gui.AppendMenu(scheduler_popup, win32con.MF_STRING, self.MENU_CONFIGURESCHEDULER, "&Configure Scheduler") if not self._processes: flags = win32con.MF_GRAYED else: flags = 0 # create scheduled tasks menu tasks_popup = win32gui.CreatePopupMenu() i = 0 for scan in self._scheduledScans: win32gui.AppendMenu(tasks_popup, win32con.MF_STRING, self.MENU_RUNSCHEDULE + i, scan.Description) i += 1 if not i: flags2 = win32con.MF_GRAYED else: flags2 = 0 win32gui.InsertMenu( scheduler_popup, self.MENU_CONFIGURESCHEDULER, win32con.MF_BYCOMMAND | win32con.MF_POPUP | flags2, tasks_popup, "&Run Scheduled Scan") win32gui.InsertMenu( scheduler_popup, flags, win32con.MF_BYCOMMAND | win32con.MF_STRING | flags, self.MENU_TERMINATESCHEDULE, "&Stop All Running Tasks Now") # create reports menu reports_popup = win32gui.CreatePopupMenu() if not len(self._config.Get('ClamAV', 'LogFile')): flags = win32con.MF_GRAYED else: flags = 0 win32gui.InsertMenu( reports_popup, 0, win32con.MF_BYCOMMAND | win32con.MF_STRING | flags, self.MENU_SHOWSCANLOG, "&Virus Scan Report") if not len(self._config.Get('Updates', 'DBUpdateLogFile')): flags = win32con.MF_GRAYED else: flags = 0 win32gui.InsertMenu( reports_popup, self.MENU_SHOWSCANLOG, win32con.MF_BYCOMMAND | win32con.MF_STRING | flags, self.MENU_SHOWUPDATELOG, "&Virus Database Update Report") # create main menu menu = win32gui.CreatePopupMenu() win32gui.AppendMenu(menu, win32con.MF_STRING, self.MENU_OPEN_CLAM, "&Open Blindata") win32gui.AppendMenu(menu, win32con.MF_STRING, self.MENU_UPDATE_DB, "&Download Virus Database Update") win32gui.AppendMenu(menu, win32con.MF_STRING, self.MENU_CONFIGURE, "&Configure Blindata") win32gui.AppendMenu(menu, win32con.MF_POPUP, scheduler_popup, "&Scheduler") win32gui.AppendMenu(menu, win32con.MF_POPUP, reports_popup, "Display &Reports") win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 0, "") win32gui.AppendMenu(menu, win32con.MF_STRING, self.MENU_CHECK_UPDATE, "Check &Latest Version") win32gui.AppendMenu(menu, win32con.MF_STRING, self.MENU_CLAMWIN_WEB, "&Visit Blindata Website") win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 0, "") win32gui.AppendMenu(menu, win32con.MF_STRING, self.MENU_EXIT, "&Exit") pos = win32gui.GetCursorPos() # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp try: win32gui.SetForegroundWindow(self.hwnd) except: pass try: win32gui.SetMenuDefaultItem(menu, 0, 1) except NameError: pass win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.SendMessage(self.hwnd, win32con.WM_NULL, 0, 0)
for menu_item in self.custom_menu_items.itervalues(): if callable(menu_item['func']): try: is_checked = menu_item['func'](self, get_state=True) except Exception, e: print e else: is_checked = False flags = win32con.MF_STRING | (win32con.MF_CHECKED if is_checked else 0) win32gui.AppendMenu(menu, flags, menu_item['id'], menu_item['text']) win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, -1, "") win32gui.AppendMenu(menu, win32con.MF_STRING, 1024, "E&xit") win32gui.SetMenuDefaultItem(menu, 0, True) pos = get_cursor_pos() # From MSDN: # To display a context menu for a notification icon, the current window must be the foreground window # before the application calls TrackPopupMenu or TrackPopupMenuEx. Otherwise, the menu will not disappear # when the user clicks outside of the menu or the window that created the menu (if it is visible). # However, when the current window is the foreground window, the second time this menu is displayed, # it displays and then immediately disappears. To correct this, you must force a task switch # to the application that called TrackPopupMenu. This is done by posting a benign message to the window # or thread. win32gui.SetForegroundWindow(self.hwnd) win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None) win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0) def add_menu_item(self, text, func):