def deactivate(self): # Remove any installed menu items self._remove_menu() for view in self._window.get_views(): self.remove_document_helper(view) self._window.remove_accel_group(self._accel_group) gtk.accel_map_get().disconnect(self._accel_map_handler_id) self._window = None self._plugin = None self._accel_group = None self._action_group = None
def __init__(self, plugin, window): Signals.__init__(self) self._window = window self._plugin = plugin self._views = {} # Insert menu items self._insert_menu() # Insert document helpers for view in window.get_views(): self.add_document_helper(view) self.connect_signal(window, 'tab-added', self.on_tab_added) self.connect_signal(window, 'tab-removed', self.on_tab_removed) self._accel_group = gtk.AccelGroup() self._window.add_accel_group(self._accel_group) self._proxy_callback_map = { 'IncreaseFontSizeAction': self.on_increase_font_accel, 'DecreaseFontSizeAction': self.on_decrease_font_accel, 'ResetFontSizeAction': self.on_reset_font_accel } self._proxy_mapping = {} self._init_proxy_accels() self._accel_map_handler_id = gtk.accel_map_get().connect( 'changed', self.on_accel_map_changed)
def __init__(self, plugin, window): Signals.__init__(self) self._window = window self._plugin = plugin self._views = {} # Insert menu items self._insert_menu() # Insert document helpers for view in window.get_views(): self.add_document_helper(view) self.connect_signal(window, 'tab-added', self.on_tab_added) self.connect_signal(window, 'tab-removed', self.on_tab_removed) self._accel_group = gtk.AccelGroup() self._window.add_accel_group(self._accel_group) self._proxy_callback_map = { 'IncreaseFontSizeAction': self.on_increase_font_accel, 'DecreaseFontSizeAction': self.on_decrease_font_accel, 'ResetFontSizeAction': self.on_reset_font_accel } self._proxy_mapping = {} self._init_proxy_accels() self._accel_map_handler_id = gtk.accel_map_get().connect('changed', self.on_accel_map_changed)
def _insert_directory(self, directory, path): manager = self._window.get_ui_manager() for item in directory.subdirs: action_name = 'ExternalToolDirectory%X' % id(item) action = gtk.Action(action_name, item.name.replace('_', '__'), None, None) self._action_group.add_action(action) manager.add_ui(self._merge_id, path, action_name, action_name, gtk.UI_MANAGER_MENU, False) self._insert_directory(item, path + '/' + action_name) for item in directory.tools: action_name = 'ExternalToolTool%X' % id(item) action = gtk.Action(action_name, item.name.replace('_', '__'), item.comment, None) handler = action.connect("activate", capture_menu_action, self._window, item) action.set_data(self.ACTION_ITEM_DATA_KEY, item) action.set_data(self.ACTION_HANDLER_DATA_KEY, handler) # Make sure to replace accel accelpath = '<Actions>/ExternalToolsPluginToolActions/%s' % ( action_name, ) if item.shortcut: key, mod = gtk.accelerator_parse(item.shortcut) gtk.accel_map_change_entry(accelpath, key, mod, True) self._signals.append(gtk.accel_map_get().connect( 'changed::%s' % (accelpath, ), self.on_accelmap_changed, item)) self._action_group.add_action_with_accel(action, item.shortcut) manager.add_ui(self._merge_id, path, action_name, action_name, gtk.UI_MANAGER_MENUITEM, False)
def remove(self): if self._merge_id != 0: self._window.get_ui_manager().remove_ui(self._merge_id) self._window.get_ui_manager().remove_action_group(self._action_group) self._merge_id = 0 for action in self._action_group.list_actions(): handler = action.get_data(self.ACTION_HANDLER_DATA_KEY) if handler is not None: action.disconnect(handler) action.set_data(self.ACTION_ITEM_DATA_KEY, None) action.set_data(self.ACTION_HANDLER_DATA_KEY, None) self._action_group.remove_action(action) accelmap = gtk.accel_map_get() for s in self._signals: accelmap.disconnect(s) self._signals = []
def _insert_directory(self, directory, path): manager = self._window.get_ui_manager() for item in directory.subdirs: action_name = 'RunExternalToolDirectory%X' % id(item) action = gtk.Action(action_name, item.name.replace('_', '__'), None, None) self._action_group.add_action(action) manager.add_ui(self._merge_id, path, action_name, action_name, gtk.UI_MANAGER_MENU, False) self._insert_directory(item, path + '/' + action_name) for item in directory.tools: action_name = 'RunExternalToolTool%X' % id(item) action = gtk.Action(action_name, item.name.replace('_', '__'), item.comment, None) handler = action.connect("activate", capture_menu_action, self._window, item) action.set_data(self.ACTION_ITEM_DATA_KEY, item) action.set_data(self.ACTION_HANDLER_DATA_KEY, handler) # Make sure to replace accel accelpath = '<Actions>/RunExternalToolsPluginToolActions/%s' % (action_name, ) if item.shortcut: key, mod = gtk.accelerator_parse(item.shortcut) gtk.accel_map_change_entry(accelpath, key, mod, True) self._signals.append(gtk.accel_map_get().connect('changed::%s' % (accelpath,), self.on_accelmap_changed, item)) self._action_group.add_action_with_accel(action, item.shortcut) manager.add_ui(self._merge_id, path, action_name, action_name, gtk.UI_MANAGER_MENUITEM, False)
def start_listening(self): gtk.accel_map_get().connect('changed', self.accel_map_changed_cb)