SuperCollider 3.9dev Classes (extension) | GUI | External Control > Keyboard

KeyDownActionsEditor
ExtensionExtension

an editor allowing to set keyboard-shortcuts resp. edit the actions connmected to the shortcuts.
Inherits from: KeyDownActions : Object

Description

KeyDownActionsEditor allows you to define and edit an unlimited number of key-down actions for a given GUI-element. It's based on View: -keyDownAction but adds some WYSIWYG functionality within its GUI.

To edit or remove a shortcut you'll have to click the edit-button first. The shortcut-field (next to the label "shortcut:") will get set to whatever key you hit - also during editing the action - it's advisable to first edit the action and to set the key afterwards.

Class Methods

KeyDownActionsEditor.new(parent, name, bounds, shortcutsDict, showMods: true)

Create a new KeyDownActionsEditor for the given shortcuts in shortcutsDict

Arguments:

parent

a View - if none is provided it will get created internally

name

a String or a Symbol, added to the window's title.

bounds

a Rect, denoting position and size

shortcutsDict

a Dictionary shortcuts (keys and actions) to be displayed in the editor

showMods

whether to expose modifier-keys in the editor (e.g. set to false for editing KeyDownActions: *globalShortcuts)

Returns:

a KeyDownActionsEditor

Inherited class methods

Instance Methods

.result

Query the values currently set in the editor.

Returns:

.setShortcuts(view)

Set the keyDownActions of the given View to the current values of the editor.

NOTE: Though in most cases argument view will be an object of type View this doesn't necessarily have to be the case. At least the following classes do have a method keyDownAction implemented as well: ViewHolder2, SplineGui, ScaledUserView, SMPTEView and possibly others as well well. A KeyDownActionsEditor may be used in connection with these too. Note also the corresponding class-method KeyDownActions: *setShortcuts which works independently from a given KeyDownActionsEditor

Returns:

this (a KeyDownActionsEditor)

.window

The editor's Window

Returns:

Inherited instance methods

Examples

// the editor is a GUI element that can be initialised
// as part of a composite view or a standalone
k = KeyDownActionsEditor.new;

(
// just an example dict
// you shouldn't need to do this
// a KeyDownActionsEditor can be initialised without shortcuts as well
// all shortcuts added via GUI will get stored in an IdentityDictionary
// like the one below
// note the mixed keys

t = IdentityDictionary[
    'alt + i' -> (
        func: "{ |view| view.background_(Color.red) }",
        keyCode: KeyDownActions.keyCodes[$i],
        modifierQt: KeyDownActions.modifiersQt[\alt],
        modifierCocoa: KeyDownActions.modifiersCocoa[\alt]
    ),
    $i -> (
        func: "{ |view| view.background_(Color.green) }",
        keyCode: KeyDownActions.keyCodes[$i]
    )
];

// create a window and set its shortcuts to what is in k.result
w = Window("shortcuts test").onClose_({ f.close }).front;

f = Window("Shortcuts Editor", 400@300).front;
k = KeyDownActionsEditor(f, bounds: f.bounds.width@(f.bounds.height-40), shortcutsDict: t);
b = Button(f, Rect(f.bounds.width-100, f.bounds.height-30, 90, 20)).states_([["set Shortcuts", Color.white, Color.red]]).action_({ |btn| k.result.postln; k.setShortcuts(w.view) });
)