浏览代码

code review

Falko Schindler 3 年之前
父节点
当前提交
67a00266ba
共有 2 个文件被更改,包括 10 次插入9 次删除
  1. 5 4
      main.py
  2. 5 5
      nicegui/elements/hotkey.py

+ 5 - 4
main.py

@@ -362,7 +362,7 @@ with example(ui.page):
 
     ui.link('Visit other page', '/other_page')
 
-add_route = """###Route
+add_route = """### Route
 
 Add a new route by calling `ui.add_route` with a starlette route including a path and a function to be called. 
 Routed paths must start with a `'/'`.
@@ -376,7 +376,8 @@ with example(add_route):
 
     ui.link('Try the new route!', '/new/route')
 
-get_decorator = """###Get decorator
+get_decorator = """### Get decorator
+
 Syntactic sugar to add routes.
 Decorating a function with the `@ui.get` makes it available at the specified endpoint, e.g. `'/another/route/1'`.
 """
@@ -391,7 +392,7 @@ with example(get_decorator):
     ui.link('Try yet another route!', '/another/route/1')
 
 with example(ui.hotkey):
-    ui.hotkey(keys=['f', 'g', ], on_keydown=lambda: ui.notify('F+G keys were pressed.'))
-    ui.label('Hover over this square and press and release the keys F+G .')
+    ui.hotkey(keys=['f', 'g'], on_keydown=lambda: ui.notify('Keys F and G were pressed.'))
+    ui.label('Hover over this square and press and release the keys F and G.')
 
 ui.run(port=8080)

+ 5 - 5
nicegui/elements/hotkey.py

@@ -7,22 +7,22 @@ from ..utils import handle_exceptions, provide_arguments
 
 class HotkeyView(CustomView):
 
-    def __init__(self, keys: list, on_keydown: Callable):
+    def __init__(self, keys: list[str], on_keydown: Callable):
         super().__init__('hotkey', __file__, keys=keys)
         self.on_keydown = on_keydown
-        self.allowed_events = ['onKeydown', ]
+        self.allowed_events = ['onKeydown']
         self.style = 'display: none'
         self.initialize(temp=False, onKeydown=handle_exceptions(provide_arguments(on_keydown)))
 
 
 class Hotkey(Element):
 
-    def __init__(self, keys: list, on_keydown: Callable = None):
+    def __init__(self, keys: list[str], on_keydown: Callable = None):
         """Hotkeys
 
         Adds a hotkey action to an element.
 
-        :param key: the character that the action should be associated with, e.g. 'f'
-        :param on_keydown: callback to be executed when the specified key is pressed while the parents is active
+        :param keys: list of characters that the action should be associated with, e.g. ['f', 'g']
+        :param on_keydown: callback to be executed when the specified keys are pressed while the parent is hovered
         """
         super().__init__(HotkeyView(keys=keys, on_keydown=on_keydown))