Skip to content

Commit

Permalink
refactoring hotkey naming to keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
c00lc0de committed Oct 29, 2021
1 parent 6426b75 commit 3deb87f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def produce_plain_response(request):

ui.link('Try yet another route!', '/another/route/1')

with example(ui.hotkey):
with example(ui.keyboard):
def handle_keys(e):
if e.key == 'f' and not e.key.repeat:
if e.action.keyup:
Expand All @@ -408,7 +408,7 @@ def handle_keys(e):
elif e.key.down:
ui.notify('going down')

hotkeys = ui.hotkey(handle_keys)
ui.label('Key events can be caught globally by using the hotkey element.')
keyboard = ui.keyboard(handle_keys)
ui.label('Key events can be caught globally by using the keyboard element.')

ui.run(port=8080)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Vue.component('hotkey', {
Vue.component('keyboard', {
template: `<span v-bind:id="jp_props.id" :class="jp_props.classes" :style="jp_props.style"></span>`,
methods: {
add_event_listeners() {
Expand Down
10 changes: 5 additions & 5 deletions nicegui/elements/hotkey.py → nicegui/elements/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
from ..utils import handle_exceptions, provide_arguments


class HotkeyView(CustomView):
class KeyboardView(CustomView):

def __init__(self, handle_keys: Callable):
super().__init__('hotkey', __file__, activeJSEvents=['keydown', 'keyup', 'keypress'])
super().__init__('keyboard', __file__, activeJSEvents=['keydown', 'keyup', 'keypress'])
self.allowed_events = ['keyboardEvent']
self.style = 'display: none'
self.initialize(temp=False, on_keyboardEvent=handle_exceptions(provide_arguments(handle_keys, 'key_data', 'event_type')))


class Hotkey(Element):
class Keyboard(Element):

def __init__(self, handle_keys: Callable = None):
"""
Hotkeys
Keyboard
Adds global keyboard event tracking.
:param handle_keys: callback to be executed when keyboard events occur.
"""

super().__init__(HotkeyView(handle_keys=handle_keys))
super().__init__(KeyboardView(handle_keys=handle_keys))
2 changes: 1 addition & 1 deletion nicegui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Ui:
from .elements.row import Row as row
from .elements.column import Column as column
from .elements.card import Card as card
from .elements.hotkey import Hotkey as hotkey
from .elements.keyboard import Keyboard as keyboard
from .elements.card import CardSection as card_section

from .timer import Timer as timer
Expand Down

0 comments on commit 3deb87f

Please sign in to comment.