Browse Source

remove automatic dependency management

Falko Schindler 2 năm trước cách đây
mục cha
commit
63e7a3bc97

+ 0 - 8
nicegui/elements/chart.py

@@ -2,12 +2,8 @@ from typing import Dict
 
 import justpy as jp
 
-from .. import globals
-from ..task_logger import create_task
 from .element import Element
 
-jp.template_options['highcharts'] = False
-
 
 class Chart(Element):
 
@@ -21,7 +17,3 @@ class Chart(Element):
         view = jp.HighCharts(temp=False)
         view.options = self.options = jp.Dict(**options)
         super().__init__(view)
-
-        if not jp.template_options['highcharts'] and globals.loop and globals.loop.is_running():
-            create_task(self.page.run_javascript('location.reload()'))
-        jp.template_options['highcharts'] = True

+ 2 - 1
nicegui/elements/colors.py

@@ -2,11 +2,12 @@ from ..routes import add_dependencies
 from .custom_view import CustomView
 from .element import Element
 
+add_dependencies(__file__)
+
 
 class ColorsView(CustomView):
 
     def __init__(self, primary, secondary, accent, positive, negative, info, warning):
-        add_dependencies(__file__)
         super().__init__('colors',
                          primary=primary,
                          secondary=secondary,

+ 2 - 1
nicegui/elements/custom_example.py

@@ -2,11 +2,12 @@ from ..routes import add_dependencies
 from .custom_view import CustomView
 from .element import Element
 
+add_dependencies(__file__)
+
 
 class CustomExampleView(CustomView):
 
     def __init__(self, on_change):
-        add_dependencies(__file__)
         super().__init__('custom_example', value=0)
 
         self.on_change = on_change

+ 2 - 1
nicegui/elements/interactive_image.py

@@ -10,11 +10,12 @@ from ..routes import add_dependencies
 from .custom_view import CustomView
 from .element import Element
 
+add_dependencies(__file__)
+
 
 class InteractiveImageView(CustomView):
 
     def __init__(self, source: str, on_mouse: Callable, events: List[str], cross: bool):
-        add_dependencies(__file__)
         super().__init__('interactive_image', source=source, events=events, cross=cross, svg_content='')
         self.allowed_events = ['onMouse', 'onConnect']
         self.initialize(onMouse=on_mouse, onConnect=self.on_connect)

+ 2 - 1
nicegui/elements/joystick.py

@@ -4,6 +4,8 @@ from ..routes import add_dependencies
 from .custom_view import CustomView
 from .element import Element
 
+add_dependencies(__file__, ['nipplejs.min.js'])
+
 
 class JoystickView(CustomView):
 
@@ -12,7 +14,6 @@ class JoystickView(CustomView):
                  on_move: Optional[Callable],
                  on_end: Optional[Callable],
                  **options: Any):
-        add_dependencies(__file__, ['nipplejs.min.js'])
         super().__init__('joystick', **options)
 
         self.on_start = on_start

+ 2 - 1
nicegui/elements/keyboard.py

@@ -6,11 +6,12 @@ from ..routes import add_dependencies
 from .custom_view import CustomView
 from .element import Element
 
+add_dependencies(__file__)
+
 
 class KeyboardView(CustomView):
 
     def __init__(self, on_key: Callable, repeating: bool):
-        add_dependencies(__file__)
         super().__init__('keyboard', active_js_events=['keydown', 'keyup'], repeating=repeating)
         self.allowed_events = ['keyboardEvent']
         self.style = 'display: none'

+ 2 - 1
nicegui/elements/log.py

@@ -13,11 +13,12 @@ from ..task_logger import create_task
 from .custom_view import CustomView
 from .element import Element
 
+add_dependencies(__file__)
+
 
 class LogView(CustomView):
 
     def __init__(self, lines: Deque[str], max_lines: int):
-        add_dependencies(__file__)
         super().__init__('log', max_lines=max_lines)
         self.lines = lines
         self.allowed_events = ['onConnect']

+ 9 - 8
nicegui/elements/scene.py

@@ -14,6 +14,15 @@ from .custom_view import CustomView
 from .element import Element
 from .scene_object3d import Object3D
 
+add_dependencies(__file__, [
+    'three.min.js',
+    'CSS2DRenderer.js',
+    'CSS3DRenderer.js',
+    'OrbitControls.js',
+    'STLLoader.js',
+    'tween.umd.min.js',
+])
+
 
 @dataclass
 class SceneCamera:
@@ -37,14 +46,6 @@ class SceneCamera:
 class SceneView(CustomView):
 
     def __init__(self, *, width: int, height: int, on_click: Optional[Callable]):
-        add_dependencies(__file__, [
-            'three.min.js',
-            'CSS2DRenderer.js',
-            'CSS3DRenderer.js',
-            'OrbitControls.js',
-            'STLLoader.js',
-            'tween.umd.min.js',
-        ])
         super().__init__('scene', width=width, height=height)
         self.on_click = on_click
         self.allowed_events = ['onConnect', 'onClick']

+ 0 - 8
nicegui/elements/table.py

@@ -2,12 +2,8 @@ from typing import Dict
 
 import justpy as jp
 
-from .. import globals
-from ..task_logger import create_task
 from .element import Element
 
-jp.template_options['aggrid'] = False
-
 
 class Table(Element):
 
@@ -21,7 +17,3 @@ class Table(Element):
         view = jp.AgGrid(temp=False)
         view.options = self.options = jp.Dict(**options)
         super().__init__(view)
-
-        if not jp.template_options['aggrid'] and globals.loop and globals.loop.is_running():
-            create_task(self.page.run_javascript('location.reload()'))
-        jp.template_options['aggrid'] = True

+ 0 - 1
nicegui/globals.py

@@ -26,7 +26,6 @@ disconnect_handlers: List[Union[Callable, Awaitable]] = []
 startup_handlers: List[Union[Callable, Awaitable]] = []
 shutdown_handlers: List[Union[Callable, Awaitable]] = []
 has_auto_index_page: bool = False
-dependencies: Dict[str, List[str]] = {}
 
 
 def find_route(function: Callable) -> str:

+ 0 - 6
nicegui/routes.py

@@ -62,12 +62,6 @@ def get(self, path: str):
 
 
 def add_dependencies(py_filepath: str, dependencies: List[str] = []) -> None:
-    if py_filepath in globals.dependencies:
-        return
-    if globals.loop and globals.loop.is_running():
-        raise RuntimeError('can not add new dependencies after startup')
-    globals.dependencies[py_filepath] = dependencies
-
     vue_filepath = os.path.splitext(os.path.realpath(py_filepath))[0] + '.js'
 
     for dependency in dependencies:

+ 0 - 34
tests/test_dependencies.py

@@ -1,34 +0,0 @@
-import pytest
-from nicegui import ui
-from selenium.common.exceptions import NoSuchElementException
-
-from .user import User
-
-
-def test_keyboard_before_startup(user: User):
-    @ui.page('/')
-    def page():
-        ui.keyboard()
-
-    user.open('/')
-    assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
-    assert user.selenium.find_element_by_tag_name('span')
-
-
-def test_keyboard_after_startup(user: User):
-    @ui.page('/')
-    def page():
-        def add_keyboard():
-            with row:
-                ui.keyboard()
-        row = ui.row()
-        ui.button('activate keyboard', on_click=add_keyboard)
-
-    user.open('/')
-    assert not any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
-    with pytest.raises(NoSuchElementException):
-        user.selenium.find_element_by_tag_name('span')
-    user.click('activate keyboard')
-    assert any(s.endswith('keyboard.js') for s in user.get_attributes('script', 'src'))
-    user.sleep(1)
-    assert user.selenium.find_element_by_tag_name('span')  # FIXME: ptw fails (which is correct) while pytest does not