Hi,
Following on from my first question here I am trying to create a new ‘Select’ mode but am having some difficulty in understanding how a new mode is registered.
According to the code comment in ‘ModeRegistry’ is I need to define ‘ACTION_NAME’ with a name that matches an Action defined in ‘resources.xml’. So basing my code on the ‘FreehandMode’ I created this basic class:
class SelectMode(gui.mode.BrushworkModeMixin, gui.mode.ScrollableModeMixin, gui.mode.InteractionMode):
ACTION_NAME = 'SelectMode'
permitted_switch_actions = set()
_OPTIONS_WIDGET = None
IS_LIVE_UPDATEABLE = True
MOTION_QUEUE_PRIORITY = GLib.PRIORITY_DEFAULT_IDLE
def __init__(self, ignore_modifiers=True, **args):
super(SelectMode, self).__init__(**args)
logger.info("Select initialised.")
self.cursor_hidden_tdws = set()
pointer_behavior = gui.mode.Behavior.PAINT_LINE
scroll_behavior = gui.mode.Behavior.CHANGE_VIEW
@classmethod
def get_name(cls):
return _(u"Select an Area")
def get_usage(self):
return _(u"Select an area of the canvas")
def button_press_cb(self, tdw, event):
logger.info("Button pressed.")
super().button_press_cb(tdw, event)
def button_release_cb(self, tdw, event):
logger.info("Button released.")
super().button_release_cb(tdw, event)
I then added the following to ‘resources.xml’
<object class="GtkAction" id="SelectMode">
<property name="label" translatable="yes" context="Menu→File (labels), Accel Editor (labels)">Select</property>
<property name="short-label" translatable="yes" context="Toolbar (short labels)">Select</property>
<property name="tooltip" translatable="yes" context="Toolbar (tooltips), Accel Editor (descriptions)">Select a rectangular area of canvas.</property>
<signal name="activate" handler="mode_flip_action_activated_cb" />
</object>
I also add a ‘menuitem’ to ‘menu.xml’ and that gets me a menu option under ‘Edit’ however my ‘SelectMode’ class never seems to get instantiated and the button callbacks are never called. I’ve confirmed this by adding a logging statement to L114 on ‘mode.py’ where new is defined and I never see ‘SelectMode’ logged. I have also tried to ‘break’ an existing mode by changing it’s ACTION_NAME, but I always see it being registered.
- Are there additional steps I need to do to register a mode?
- I note that there are ‘Flip’ and normal modes and I am not sure which I should register … possibly both? I am guessing the difference is something to do with one being related to a button on the tool bar and the other within the menus.