- Should make specifying keybindings externally easy, through resources.
- Should be easy like
(listen)
- Should be consistent with rest of event system.
-
Target widget
-
This is where the binding is installed using input map and action map. It could be omitted when the action is a widget and the scope is global (see below).
-
The keystroke(s). (
:key
) -
Allow resources
-
Required? If not, what's the default?
-
Action to execute (
:to
) -
A function (generate Action object)
-
A widget. Use the widget's action, or programmatically invoke, i.e.
(.doClick)
-
An action
-
:none
suppresses actions? -
Required? If not, what's the default value?
-
Scope of the binding (
:scope
) -
Only when the widget is focused (
:local
) -
When the widget or any descendant has focus (default) (
:descendants
) -
When current frame has focus (
:global
)
If :global
is the default scope that gives the highest probability it will actually work, but could lead to weird behavior. For example, when there are tabs, global bindings are active in all tabs. hmmm.
Same as (listen)
, a function that removes the binding and restores the previous one.
- listen-key
- bind-key
- on-key
- with-key
- bind-keypress
; Map keys to calculator buttons
(let [b1 (button :text "1" ... handlers ...)
...
b9 (button :text "2" ... handlers ...)
grid (grid-panel :columns 3 [b1 ... b9])]
(bind-key grid :key "1" :to b1 :scope :global)
(bind-key grid :key "2" :to b2 :scope :global)
...)
- The choice of where to attach the binding is confusing. On the button? On the container with
:scope
:descendants
? - Decision depends a lot on focus
another notional example with fewer keyword args:
; Map keys to calculator buttons
(let [b1 (button :text "1" ... handlers ...)
...
b9 (button :text "2" ... handlers ...)
grid (grid-panel :columns 3 [b1 ... b9])]
(bind-key grid "1" b1 :scope :global)
(bind-key grid "2" b2 :scope :global)
...)
Here, we assume the key and action are always required and make them positional. :scope
is optional, so it remains a keyword arg.
http://download.oracle.com/javase/tutorial/uiswing/misc/keybinding.html
Greg. Thanks! I'm glad you find it useful. Have seesaw and piccolo been getting along pretty well for you? Is there anything that could be changed or added in Seesaw to make that easier? Just checking.
On the key binding stuff, I ended up going with the more terse version. See https://github.com/daveray/seesaw/blob/develop/src/seesaw/keymap.clj#L46. I don't know if I chose correctly or not. Deciding between positional and keyword arguments is an ongoing struggle for me :)