1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
"""
Copyright (c) 2015, Jairus Martin.
Distributed under the terms of the MIT License.
The full license is in the file COPYING.txt, distributed with this software.
Created on Aug 29, 2015
"""
import sys
from atom.api import Bool, Event, ForwardTyped, List, Typed, observe
from enaml.core.declarative import d_
from enaml.widgets.control import Control, ProxyControl
if sys.version_info.major < 3:
str = basestring # noqa: F821
class ProxyKeyEvent(ProxyControl):
#: Reference to the declaration
declaration = ForwardTyped(lambda: KeyEvent)
def set_enabled(self, enabled):
raise NotImplementedError
def set_keys(self, keys):
raise NotImplementedError
class KeyEvent(Control):
#: Proxy reference
proxy = Typed(ProxyKeyEvent)
#: List of keys that or codes to filter
#: Can be a key letter or code and including modifiers
#: Ex. Ctrl + r, up, esc, etc..
#: If empty will fire for any key combination
keys = d_(List(str))
#: Listen for events
enabled = d_(Bool(True))
#: Fire multiple times when the key is held
repeats = d_(Bool(True))
#: Pressed event
pressed = d_(Event(dict), writable=False)
#: Released event
released = d_(Event(dict), writable=False)
@observe("enabled", "keys")
def _update_proxy(self, change):
"""An observer which sends state change to the proxy."""
super(KeyEvent, self)._update_proxy(change)
|