示例#1
0
    def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        dynamic_actions = dict()
        dynamic_options = []
        if self.AMC:
            dynamic_options = self._add_ids_to_menu_options(
                list(self.AMC()), dynamic_actions)
        self.all_actions = {}
        self.all_actions.update(self.static_actions)
        self.all_actions.update(dynamic_actions)
        self.create_menu(menu, dynamic_options + self.static_options)
        #win32gui.SetMenuDefaultItem(menu, 1000, 0)

        pos = win32gui.GetCursorPos()
        # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
        try:
            win32gui.BringWindowToTop(self.hwnd)
            win32gui.SetForegroundWindow(self.hwnd)
        except Exception as e:
            if e.args and e.args[0] == 0:
                # (0, 'SetForegroundWindow', 'No error message is available')
                # 设置foreground失败,一般为全屏时调用异常
                pass
            else:
                logger.warn('exception while showing menu. ignored.',
                            exc_info=1)
        win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1],
                                0, self.hwnd, None)
        win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
示例#2
0
 def show_menu2(self):
     menu = win32gui.CreatePopupMenu()
     self.create_menu(menu, self.menu_options2)
     pos = win32gui.GetCursorPos()
     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)
示例#3
0
文件: win32.py 项目: eavatar/ava.node
    def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu, self.menu_options)

        pos = win32gui.GetCursorPos()
        # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
        win32gui.SetForegroundWindow(self.shell.main_frame.hwnd)
        win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1],
                                0, self.shell.main_frame.hwnd, None)
示例#4
0
 def show_menu(self):
   menu = win32gui.CreatePopupMenu()
   self.create_menu(menu, self.menu_options)
   #win32gui.SetMenuDefaultItem(menu, 1000, 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)
示例#5
0
    def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu)

        pos = win32gui.GetCursorPos()
        win32gui.SetForegroundWindow(self.shell.main_frame.hwnd)
        win32gui.TrackPopupMenu(menu,
                                win32con.TPM_LEFTALIGN,
                                pos[0],
                                pos[1],
                                0,
                                self.shell.main_frame.hwnd,
                                None)
示例#6
0
 def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
     if lparam == win32con.WM_LBUTTONUP or lparam == win32con.WM_RBUTTONUP:  #if left or right click
         #print "Click."
         menu = gui.CreatePopupMenu()
         #gui.AppendMenu( menu, win32con.MF_STRING, 1024, "Generate balloon") # this is where you define the actions
         gui.AppendMenu(menu, win32con.MF_STRING, 1024,
                        "Exit")  # for the right-click menu
         pos = gui.GetCursorPos()
         gui.SetForegroundWindow(self.hwnd)
         gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0,
                            self.hwnd, None)
         gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
         return 1
示例#7
0
    def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        self.create_menu(menu, self.menu_options)
        #win32gui.SetMenuDefaultItem(menu, 1000, 0)

        try:
            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)
        except pywintypes.error:
            # Weird PyWin/win32gui bug, just ignore it for now
            logging.debug('win32gui problem, cannot show SysTray menu')
示例#8
0
    def show_menu(self):
        hmenu = win32gui.CreatePopupMenu()
        self.create_menu(hmenu)

        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 Exception as exc:
            logger.debug(exc, exc_info=True)
            return
        win32gui.TrackPopupMenu(hmenu, win32con.TPM_LEFTALIGN, pos[0], pos[1],
                                0, self.hwnd, None)
        win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0,
                             0)  # send a null message, seems useless
示例#9
0
    def show_menu(self):
        menu = win32gui.CreatePopupMenu()
        count = 0

        for count, (option_text, option_id) in enumerate(self.menu_entries):
            win32gui.AppendMenu(
                menu,
                win32con.MF_STRING | win32con.MF_GRAYED | win32con.MF_DISABLED,
                option_id, option_text)

        win32gui.InsertMenu(menu, count + 1, win32con.MF_BYPOSITION,
                            win32con.MF_SEPARATOR, None)
        win32gui.InsertMenuItem(
            menu, count + 2, 1,
            win32gui_struct.PackMENUITEMINFO(
                text="Quit", wID=0, hbmpItem=win32con.HBMMENU_MBAR_CLOSE)[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)
示例#10
0
 def show_menu(self):
     menu_options = self.menu_cb()
     menu_options = menu_options + [('Quit', None, self.QUIT),]
     self._next_action_id = self.FIRST_ID
     self.menu_actions_by_id = set()
     menu_options = self._add_ids_to_menu_options(menu_options)
     self.menu_actions_by_id = dict(self.menu_actions_by_id)
     del self._next_action_id
     menu = win32gui.CreatePopupMenu()
     self.create_menu(menu, menu_options)
     #win32gui.SetMenuDefaultItem(menu, 1000, 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)