patchSkencil - Patches: patch #4489, Context dependent keymaps

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #4489: Context dependent keymaps

Submitter:  Valentin Ungureanu <vung>
Submitted:  Thu 06 Oct 2005 09:09:50 AM UTC
   
 
Category:  0.7.x Priority:  5 - Normal
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open

Thu 06 Oct 2005 09:09:50 AM UTC, original submission:  


This patch implements a new mechanism for context dependent
keymaps:

    - the app context has a keymap

    - each ToolInstance has a keymap

    - the canvas (in fact any object that can connect to
      key_press) sends the relevant parts of the event to the
      app context

    - the app context searches the corresponding command in the
      keymap of the active tool (and if not found, in its own
      keymap) and executes it.

This arrangement makes it very easy to have the same shortcut do
the thing that makes more sense in a given context.
For example Ctrl-A can select all the objects in the drawing if
the Select tool is active, all the nodes when editing a curve,
all the characters when editing text and so on just by having a
binding for 'C-a' in the keymaps of the respective tools.

In addition, a tool implemented in an external script can very
naturally override a shortcut (and this way of defining shortcuts
it's even a bit self documenting since command names are
generally descriptive):

class SomeToolInstance(ToolInstance):

    title = 'Some Tool'
    keymap = Keymap([('some_command', 's'),
                     ('select_all_whatever', 'C-a')])

    # rest of class definition


Things to note:
Some keymaps were instantiated with a second argument that
handles "special keys" (Shift, etc.), namely a dict created from
gtk.keysyms.

Trying to import gtk.keysyms without X running raises a
RuntimeError.  Sketch/UI/__init__.py now contains a hack that
avoids this error; I'm not sure if it is the best way to
handle this but having the keysyms as a dict in Sketch.UI.keysyms
is convenient. This dict is now the default value for the
special_keys argument of Keymap (instead of None).


Sketch/Editor/keystrokes.py
    Keystrokes are moved from Sketch/Editor/__init__.py to a
    separate file so that they can be imported into tools.py

The rest is just adding the relevant imports and keymaps to the
tool classes and a small test.


Valentin Ungureanu <vung>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #8902:  keymaps.diff added by vung (22KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

 

Follows 1 latest change.

Date Changed by Updated Field Previous Value => Replaced by
2005-10-06 vung Attached File- Added keymaps.diff, #5279

Back to the top

Powered by Savane 3.13-4448.
Corresponding source code