def create_menu(self, menu, menu_options):
     for option_text, option_icon, option_action, option_id in menu_options[::
                                                                            -1]:
         if option_icon:  # has icon
             if not callable(option_icon):
                 option_icon = self.prep_menu_icon(option_icon)
         if option_text == "-":  # separator
             win32gui.InsertMenu(menu, 0, win32con.MF_BYPOSITION,
                                 win32con.MF_SEPARATOR, None)
         elif option_id in self.menu_actions_by_id:  # normal item
             checked = False
             if callable(option_icon):  # checkbox item
                 checked = option_icon()
                 option_icon = None  # no icon
             if checked:
                 item, extras = win32gui_struct.PackMENUITEMINFO(
                     text=option_text,
                     fState=win32con.MFS_CHECKED,
                     wID=option_id)
             else:
                 item, extras = win32gui_struct.PackMENUITEMINFO(
                     text=option_text, hbmpItem=option_icon, wID=option_id)
             win32gui.InsertMenuItem(menu, 0, 1, item)
         else:  # submenu
             submenu = win32gui.CreatePopupMenu()
             self.create_menu(submenu, option_action)
             item, extras = win32gui_struct.PackMENUITEMINFO(
                 text=option_text, hbmpItem=option_icon, hSubMenu=submenu)
             win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #2
0
    def create_menu(self, menu, menu_options):

        toggles = self.state.menu_states()

        for option_text, option_icon, option_action, option_id in menu_options[::
                                                                               -1]:
            if option_icon:
                option_icon = self.prep_menu_icon(option_icon)

            if option_id in self.menu_actions_by_id:

                state = 0
                try:
                    if toggles[option_text]:
                        state = 8
                except KeyError:
                    pass

                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=option_text,
                    hbmpItem=option_icon,
                    wID=option_id,
                    fState=state)
                win32gui.InsertMenuItem(menu, 0, 1, item)
            else:
                submenu = win32gui.CreatePopupMenu()
                self.create_menu(submenu, option_action)
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=option_text, hbmpItem=option_icon, hSubMenu=submenu)
                win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #3
0
    def create_menu(self, menu, menu_options):
        for option_text, option_action, option_id in menu_options[::-1]:

            if option_id in self.menu_actions_by_id:
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=option_text, wID=option_id)
                win32gui.InsertMenuItem(menu, 0, 1, item)
            else:
                submenu = win32gui.CreatePopupMenu()
                self.create_menu(submenu, option_action)
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=option_text, hSubMenu=submenu)
                win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #4
0
    def create_menu(self, menu, menu_options):
        for text, icon, action, id in menu_options[::-1]:
            if icon:
                icon = self.prep_menu_icon(icon)

            if id in self.menu_actions_by_id:
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=text, hbmpItem=icon, wID=id)
                win32gui.InsertMenuItem(menu, 0, 1, item)
            else:
                submenu = win32gui.CreatePopupMenu()
                self.create_menu(submenu, action)
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=text, hbmpItem=icon, hSubMenu=submenu)
                win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #5
0
 def create_menu(self, menu, menu_options):
     index = 0
     for option_text, option_icon, option_action, option_id in menu_options[::
                                                                            -1]:
         if option_icon:
             option_icon = self.prep_menu_icon(option_icon)
             self.menu_item_map[index] = (option_icon, option_text)
         if option_id in self.menu_actions_by_id:
             if option_icon:
                 item, extras = win32gui_struct.PackMENUITEMINFO(
                     fType=win32con.MFT_OWNERDRAW,
                     dwItemData=index,
                     wID=option_id)
             else:
                 item, extras = win32gui_struct.PackMENUITEMINFO(
                     text=option_text, wID=option_id)
         else:
             submenu = win32gui.CreatePopupMenu()
             self.create_menu(submenu, option_action)
             if option_icon:
                 item, extras = win32gui_struct.PackMENUITEMINFO(
                     fType=win32con.MFT_OWNERDRAW,
                     dwItemData=index,
                     wID=option_id,
                     hSubMenu=submenu)
             else:
                 item, extras = win32gui_struct.PackMENUITEMINFO(
                     text=option_text, wID=option_id, hSubMenu=submenu)
         index = index + 1
         win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #6
0
 def create_menu(self, menu, menu_options):
     index = 0
     for option_text, option_icon, option_action, option_checked, option_id in menu_options[::
                                                                                            -1]:
         menuiteminfo = dict(text=option_text, wID=option_id)
         menu_checked = self.menu_actions_by_id[option_id][1]
         if menu_checked is not None:
             checkable_menu = menu
             if menu_checked:
                 menuiteminfo.update(dict(fState=win32con.MFS_CHECKED))
         else:
             checkable_menu = None
         self.menu_actions_by_id[option_id] = (
             self.menu_actions_by_id[option_id][0], menu_checked,
             checkable_menu)
         if option_icon:
             option_icon = self.prep_menu_icon(option_icon)
             self.menu_item_map[index] = (option_icon, None)
             menuiteminfo.update(
                 dict(hbmpItem=win32con.HBMMENU_CALLBACK, dwItemData=index))
         if option_id not in self.menu_actions_by_id:
             submenu = win32gui.CreatePopupMenu()
             self.create_menu(submenu, option_action)
             menuiteminfo.update(dict(hSubMenu=submenu))
         item, extras = win32gui_struct.PackMENUITEMINFO(**menuiteminfo)
         if option_icon: index += 1
         self.log.debug('id={} menu={} {}'.format(
             option_id, menu, self.menu_actions_by_id[option_id]))
         win32gui.InsertMenuItem(menu, 0, 1, item)
 def create_menu(self, menu, menu_options):
     for option_text, option_icon, option_action, option_id in menu_options[::-1]:
         if option_icon:
             option_icon = self.prep_menu_icon(option_icon);
         
         if option_id in self.menu_actions_by_id:                
             item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
                                                             hbmpItem=option_icon,
                                                             wID=option_id);
             win32gui.InsertMenuItem(menu, 0, 1, item);
         else:
             submenu = win32gui.CreatePopupMenu();
             self.create_menu(submenu, option_action);
             item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
                                                             hbmpItem=option_icon,
                                                             hSubMenu=submenu);
             win32gui.InsertMenuItem(menu, 0, 1, item);
Beispiel #8
0
    def create_menu(self, menu):
        #        option_icon = self.prep_menu_icon(option_icon)
        item, extras = win32gui_struct.PackMENUITEMINFO(
            text=base.STR_EXIT,
            hbmpItem=None,
            wID=_ID_QUIT)

        win32gui.InsertMenuItem(menu, 0, 1, item)

        win32gui.InsertMenu(menu, 0, win32con.MF_BYPOSITION,
                            win32con.MF_SEPARATOR, None)

        win32gui.InsertMenu(menu, 0,
                            (win32con.MF_POPUP | win32con.MF_BYPOSITION),
                            self.notices_menu, base.STR_NOTICES_MENU)

        win32gui.InsertMenu(menu, 0, win32con.MF_BYPOSITION,
                            win32con.MF_SEPARATOR, None)

        win32gui.InsertMenu(menu, 0,
                            win32con.MF_POPUP | win32con.MF_BYPOSITION,
                            self.status_menu, base.STR_STATUS_MENU)

        win32gui.InsertMenu(menu, 0, win32con.MF_BYPOSITION,
                            win32con.MF_SEPARATOR, None)

        # item, extras = win32gui_struct.PackMENUITEMINFO(
        #     text=STR_OPEN_CONSOLE,
        #     hbmpItem=None,
        #     wID=_ID_OPEN_CONSOLE)
        # win32gui.InsertMenuItem(menu, 0, 1, item)

        item, extras = win32gui_struct.PackMENUITEMINFO(
            text=base.STR_OPEN_FOLDER,
            hbmpItem=None,
            wID=_ID_OPEN_FOLDER)

        win32gui.InsertMenuItem(menu, 0, 1, item)

        item, extras = win32gui_struct.PackMENUITEMINFO(
            text=base.STR_OPEN_WEBFRONT,
            hbmpItem=None,
            wID=_ID_OPEN_WEBFRONT)

        win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #9
0
 def create_menu(self, menu, menu_options):
     for menu_option in menu_options[::-1]:
         #print menu_option
         option_text, option_icon, extra_attribute, option_action, option_id= menu_option
         if option_icon:
             option_icon = self.prep_menu_icon(option_icon)
         
         if option_id in self.menu_actions_by_id:                
             item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
                                                             hbmpItem=option_icon,
                                                             wID=option_id)
             win32gui.InsertMenuItem(menu, 0, 1, item)
         else:
             submenu = win32gui.CreatePopupMenu()
             self.create_menu(submenu, option_action)
             item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
                                                             hbmpItem=option_icon,
                                                             hSubMenu=submenu)
             win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #10
0
    def create_menu(self, menu, menu_options):
        for option_text, option_icon, option_action, option_id in menu_options[::
                                                                               -1]:
            if option_icon:
                option_icon = self.prep_menu_icon(option_icon)

            if option_id in self.menu_actions_by_id:
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=option_text, hbmpItem=option_icon, wID=option_id)
                win32gui.InsertMenuItem(menu, 0, 1, item)
            elif option_text == "SEPARATOR":
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    fType=win32con.MFT_SEPARATOR)
                win32gui.InsertMenuItem(menu, 0, 1, item)
            else:
                submenu = win32gui.CreatePopupMenu()
                self.create_menu(submenu, option_action)
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=option_text, hbmpItem=option_icon, hSubMenu=submenu)
                win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #11
0
    def addNewNotice(self, notice, pop_last=False):
        self.notice_index = (self.notice_index + 1) % base.NUM_OF_NOTICES
        item, extras = win32gui_struct.PackMENUITEMINFO(
            text=notice.title,
            hbmpItem=None,
            wID=_ID_NOTICE + (self.notice_index % base.NUM_OF_NOTICES))

        win32gui.InsertMenuItem(self.notices_menu, 0, 1, item)
        if pop_last:
            win32gui.RemoveMenu(self.notices_menu, base.NUM_OF_NOTICES,
                                win32con.MF_BYPOSITION)
 def create_menu(self, menu, menu_options):
     for option_text, option_icon, option_action, option_id in menu_options[::
                                                                            -1]:
         if option_icon:
             option_icon = self.prep_menu_icon(option_icon)
         fstate = win32con.MF_BYCOMMAND
         if option_id in self.menu_actions_by_id:
             if option_action is None:
                 fstate |= win32con.MF_GRAYED
             item, extras = win32gui_struct.PackMENUITEMINFO(
                 text=option_text,
                 fState=fstate,
                 hbmpItem=option_icon,
                 wID=option_id)
             win32gui.InsertMenuItem(menu, 0, 1, item)
         else:
             submenu = win32gui.CreatePopupMenu()
             self.create_menu(submenu, option_action)
             item, extras = win32gui_struct.PackMENUITEMINFO(
                 text=option_text, hbmpItem=option_icon, hSubMenu=submenu)
             win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #13
0
    def create_menu(self, menu, menu_options):
        for menu_option in menu_options[::-1]:
            if isinstance(menu_option.icon, str):
                menu_option.icon = self.prep_menu_icon(menu_option.icon)

            if isinstance(menu_option, TraySubmenu):
                submenu = win32gui.CreatePopupMenu()
                self.create_menu(submenu, menu_option.items)
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=menu_option.text,
                    hbmpItem=menu_option.icon,
                    hSubMenu=submenu,
                    fState=menu_option.style)
                win32gui.InsertMenuItem(menu, 0, 1, item)
            elif isinstance(menu_option, TrayItem):
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=menu_option.text,
                    hbmpItem=menu_option.icon,
                    wID=menu_option._next_action_id,
                    fState=menu_option.style,
                    fType=menu_option.type)
                win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #14
0
    def create_menu(self, menu, menu_options):
        for option_text, option_icon, option_action, option_id in menu_options[::
                                                                               -1]:
            if option_icon:
                option_icon = self.prep_menu_icon(option_icon)

            if option_text == "-":
                win32gui.InsertMenu(menu, 0, win32con.MF_BYPOSITION,
                                    win32con.MF_SEPARATOR, None)
            else:
                item, extras = win32gui_struct.PackMENUITEMINFO(
                    text=option_text, hbmpItem=option_icon, wID=option_id)
                win32gui.InsertMenuItem(menu, 0, 1, item)
Beispiel #15
0
    def _create_status_menu(self):
        menu = win32gui.CreateMenu()
        for i, s in enumerate(base.status.STRINGS):
            fstate = 0
            if self.shell.user_status == i:
                fstate = win32con.MFS_CHECKED
            item, extras = win32gui_struct.PackMENUITEMINFO(
                text=base.status.STRINGS[i],
                hbmpItem=None,
                fState=fstate,
                wID=_ID_STATUS_AVAILABLE + i)
            win32gui.InsertMenuItem(menu, i, 1, item)

        self.status_menu = menu
        return self.status_menu
Beispiel #16
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)
Beispiel #17
0
 def add_item_to_menu(self, *args, **kwargs):
     menu = args[0]
     item, extras = win32gui_struct.PackMENUITEMINFO(**kwargs)
     win32gui.InsertMenuItem(menu, self.menu_counters[menu], 1, item)
     self.menu_counters[menu] += 1