Falko Schindler 2 роки тому
батько
коміт
9e404c5562
2 змінених файлів з 11 додано та 14 видалено
  1. 1 3
      website/example.py
  2. 10 11
      website/reference.py

+ 1 - 3
website/example.py

@@ -38,13 +38,11 @@ class example:
             _add_html_anchor(documentation.classes('text-lg documentation bold-links'))
 
             with ui.column().classes('w-full items-stretch gap-8 no-wrap xl:flex-row'):
-                code = inspect.getsource(f).splitlines()
+                code = inspect.getsource(f).split('# END OF EXAMPLE')[0].strip().splitlines()
                 indentation = len(code[0].split('@example')[0]) + 4
                 while not code[0].startswith(' ' * indentation):
                     del code[0]
                 code = [l[indentation:] for l in code]
-                while code[0].startswith('global '):
-                    del code[0]
                 code.insert(0, '```python')
                 code.insert(1, 'from nicegui import ui')
                 if code[2].split()[0] not in ['from', 'import']:

+ 10 - 11
website/reference.py

@@ -263,7 +263,6 @@ To overlay an SVG, make the `viewBox` exactly the size of the image and provide
 
     @example(ui.line_plot)
     def line_plot_example():
-        global line_checkbox
         from datetime import datetime
 
         import numpy as np
@@ -281,6 +280,16 @@ To overlay an SVG, make the `viewBox` exactly the size of the image and provide
         line_updates = ui.timer(0.1, update_line_plot, active=False)
         line_checkbox = ui.checkbox('active').bind_value(line_updates, 'active')
 
+        # END OF EXAMPLE
+        def handle_change(msg: Dict) -> None:
+            def turn_off() -> None:
+                line_checkbox.set_value(False)
+                ui.notify('Turning off that line plot to save resources on our live demo server. 😎')
+            line_checkbox.value = msg['args']
+            if line_checkbox.value:
+                ui.timer(10.0, turn_off, once=True)
+        line_checkbox.on('update:model-value', handle_change)
+
     @example(ui.linear_progress)
     def linear_progress_example():
         slider = ui.slider(min=0, max=1, step=0.01, value=0.5)
@@ -743,13 +752,3 @@ You can also set `respond=False` to send a command without waiting for a respons
         ui.label('page with custom title')
 
         # ui.run(title='My App')
-
-    # HACK: turn expensive line plot off after 10 seconds
-    def handle_change(msg: Dict) -> None:
-        def turn_off() -> None:
-            line_checkbox.set_value(False)
-            ui.notify('Turning off that line plot to save resources on our live demo server. 😎')
-        line_checkbox.value = msg['args']
-        if line_checkbox.value:
-            ui.timer(10.0, turn_off, once=True)
-    line_checkbox.on('update:model-value', handle_change)