1. Ian Kemp
  2. thg

Commits

TK Soh  committed 0408bcd

cmenu: support icon on submenu entries

  • Participants
  • Parent commits 1379b4f
  • Branches default

Comments (0)

Files changed (1)

File tortoise/contextmenu.py

View file
  • Ignore whitespace
         self.icon = icon
 
 class TortoiseSubmenu(object):
-    def __init__(self, menutext, menulist):
+    def __init__(self, menutext, menulist, icon=None):
         self.menutext = menutext
         self.menulist = menulist
+        self.icon = icon
         
 class TortoiseMenuSep(object):
     def __init__(self):
                 subcommands = menu_info.menulist
                 submenu, idCmd = self.create_submenu(subcommands,
                         idCmd, idCmdFirst)
-                item, _ = win32gui_struct.PackMENUITEMINFO(
-                        text=menu_info.menutext,
-                        hSubMenu=submenu, 
-                        wID=idCmdFirst + idCmd)
+                opt = {
+                    'text' : menu_info.menutext,
+                    'wID' : idCmdFirst + idCmd,
+                    'hSubMenu' : submenu, 
+                }
+
+                if menu_info.icon:
+                    icon_path = get_icon_path("tortoise", menu_info.icon)
+                    if icon_path:
+                        opt['hbmpChecked'] = opt['hbmpUnchecked'] = \
+                                icon_to_bitmap(icon_path, type="MENUCHECK")
+                
+                item, _ = win32gui_struct.PackMENUITEMINFO(**opt)
                 win32gui.InsertMenuItem(menu, idCmdFirst + idCmd, True, item)
                 self._handlers[idCmd] = ("", lambda x,y: 0)
             elif type(menu_info) == TortoiseMenu: