def _execute_command(self, cmdindex): ''' Execute an external command. cmdindex should be an integer from 0 to 9, representing the command that should be executed. ''' manager = openwith.OpenWithManager() commands = [cmd for cmd in manager.get_commands() if not cmd.is_separator()] if len(commands) > cmdindex: commands[cmdindex].execute(self._window)
''' openwith_menu.py - Menu shell for the Open with... menu. ''' from gi.repository import Gtk from mcomix import openwith # Reference to the OpenWith command manager _openwith_manager = openwith.OpenWithManager() # Reference to the edit dialog (to keep only one instance) _openwith_edit_diag = None class OpenWithMenu(Gtk.Menu): def __init__(self, ui, window): ''' Constructor. ''' super(OpenWithMenu, self).__init__() self._window = window self._openwith_manager = _openwith_manager actiongroup = Gtk.ActionGroup(name='mcomix-openwith') actiongroup.add_actions([('edit_commands', Gtk.STOCK_EDIT, _('_Edit commands'), None, None, self._edit_commands)]) action = actiongroup.get_action('edit_commands') action.set_accel_group(ui.get_accel_group()) self.edit_button = action.create_menu_item() self.append(self.edit_button) self._construct_menu()