(self, menuitems, menu, terminal)
Add our menu items to the menu
Add our menu items to the menu
Add our menu items to the menu
def callback(self, menuitems, menu, terminal):
        """Add our menu items to the menu"""
        submenus = {}
        item = Gtk.MenuItem.new_with_mnemonic(_('_Custom Commands'))
        menuitems.append(item)

        submenu = Gtk.Menu()
        item.set_submenu(submenu)

        menuitem = Gtk.MenuItem.new_with_mnemonic(_('_Preferences'))
        menuitem.connect("activate", self.configure)
        submenu.append(menuitem)

        menuitem = Gtk.SeparatorMenuItem()
        submenu.append(menuitem)

        theme = Gtk.IconTheme.get_default()
        for command in [ self.cmd_list[key] for key in sorted(self.cmd_list.keys()) ] :
          if not command['enabled']:
            continue
          exe = command['command'].split(' ')[0]
          iconinfo = theme.choose_icon([exe], Gtk.IconSize.MENU, Gtk.IconLookupFlags.USE_BUILTIN)
          leaf_name = command['name'].split('/')[-1]
          branch_names = command['name'].split('/')[:-1]
          target_submenu = submenu
          parent_submenu = submenu
          for idx in range(len(branch_names)):
            lookup_name = '/'.join(branch_names[0:idx+1])
            target_submenu = submenus.get(lookup_name, None)
            if not target_submenu:
              item = Gtk.MenuItem(_(branch_names[idx]))
              parent_submenu.append(item)
              target_submenu = Gtk.Menu()
              item.set_submenu(target_submenu)
              submenus[lookup_name] = target_submenu
            parent_submenu = target_submenu
          if iconinfo:
            image = Gtk.Image()
            image.set_from_icon_name(exe, Gtk.IconSize.MENU)
            menuitem = Gtk.ImageMenuItem(leaf_name)
            menuitem.set_image(image)
          else:
            menuitem = Gtk.MenuItem(leaf_name)
          terminals = terminal.terminator.get_target_terms(terminal)
          menuitem.connect("activate", self._execute, {'terminals' : terminals, 'command' : command['command'] })
          target_submenu.append(menuitem)
def callback ( self , menuitems , menu , terminal ) : submenus = { } item = Gtk . MenuItem . new_with_mnemonic ( _ ( '_Custom Commands' ) ) menuitems . append ( item ) submenu = Gtk . Menu ( ) item . set_submenu ( submenu ) menuitem = Gtk . MenuItem . new_with_mnemonic ( _ ( '_Preferences' ) ) menuitem . connect ( "activate" , self . configure ) submenu . append ( menuitem ) menuitem = Gtk . SeparatorMenuItem ( ) submenu . append ( menuitem ) theme = Gtk . IconTheme . get_default ( ) for command in [ self . cmd_list [ key ] for key in sorted ( self . cmd_list . keys ( ) ) ] : if not command [ 'enabled' ] : continue exe = command [ 'command' ] . split ( ' ' ) [ 0 ] iconinfo = theme . choose_icon ( [ exe ] , Gtk . IconSize . MENU , Gtk . IconLookupFlags . USE_BUILTIN ) leaf_name = command [ 'name' ] . split ( '/' ) [ - 1 ] branch_names = command [ 'name' ] . split ( '/' ) [ : - 1 ] target_submenu = submenu parent_submenu = submenu for idx in range ( len ( branch_names ) ) : lookup_name = '/' . join ( branch_names [ 0 : idx + 1 ] ) target_submenu = submenus . get ( lookup_name , None ) if not target_submenu : item = Gtk . MenuItem ( _ ( branch_names [ idx ] ) ) parent_submenu . append ( item ) target_submenu = Gtk . Menu ( ) item . set_submenu ( target_submenu ) submenus [ lookup_name ] = target_submenu parent_submenu = target_submenu if iconinfo : image = Gtk . Image ( ) image . set_from_icon_name ( exe , Gtk . IconSize . MENU ) menuitem = Gtk . ImageMenuItem ( leaf_name ) menuitem . set_image ( image ) else : menuitem = Gtk . MenuItem ( leaf_name ) terminals = terminal . terminator . get_target_terms ( terminal ) menuitem . connect ( "activate" , self . _execute , { 'terminals' : terminals , 'command' : command [ 'command' ] } ) target_submenu . append ( menuitem )