Example #1
0
	def toggle_action(self, action, active=None):
		'''Trigger a toggle action.

		This is a convenience method to help defining toggle actions
		in the menu or toolbar. It helps to keep the menu item
		or toolbar item in sync with your internal state.
		A typical usage to define a handler for a toggle action called
		'show_foo' would be::

			def show_foo(self, show=None):
				self.toggle_action('show_foo', active=show)

			def do_show_foo(self, show=None):
				if show is None:
					show = self.actiongroup.get_action('show_foo').get_active()

				# ... the actual logic for toggling on / off 'foo'

		This way you have a public method C{show_foo()} that can be
		called by anybody and a handler C{do_show_foo()} that is
		called when the user clicks the menu item. The trick is that
		when C{show_foo()} is called, the menu item is also updates.

		@param action: the name of the action item
		@param active: when C{None} the item is toggled with respect
		to it's current state, when C{True} or C{False} forces a state
		'''
		name = action
		action = self.actiongroup.get_action(name)
		if active is None or active != action.get_active():
			action.activate()
		else:
			method = getattr(self, 'do_'+name)
			method(active)
    def do_pane_state_changed(self, pane, *a):
        if not hasattr(self, 'actiongroup') \
        or self._block_toggle_panes:
            return

        action = self.actiongroup.get_action('toggle_panes')
        visible = bool(self.get_visible_panes())
        if visible != action.get_active():
            action.set_active(visible)
    def toggle_sidepane_focus(self, *a):
        '''Switch focus between the textview and the page index.
		Automatically opens the sidepane if it is closed
		(but sets a property to automatically close it again).
		This method is used for the (optional) <Primary><Space> keybinding.
		'''
        action = self.actiongroup.get_action('toggle_panes')
        if action.get_active():
            # side pane open
            if self.pageview.textview.is_focus():
                self.focus_sidepane()
            else:
                if self._sidepane_autoclose:
                    self.toggle_panes(False)
                else:
                    self.pageview.grab_focus()
        else:
            # open the pane
            self.toggle_panes(True)
            self._sidepane_autoclose = True

        return True  # stop