Browse Source

Merge branch 'zauberzeug:main' into splitter

Andy Bulka 2 years ago
parent
commit
592c308db1

+ 10 - 0
.github/DISCUSSION_TEMPLATE/ideas.yml

@@ -0,0 +1,10 @@
+body:
+  - type: textarea
+    id: content
+    attributes:
+      label: Idea
+      description: |
+        If possible, give a [minimal reproducible code example](https://en.wikipedia.org/wiki/Minimal_reproducible_example).
+        Put source code in [fenced code blocks with syntax highlighting](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting).
+    validations:
+      required: true

+ 11 - 0
.github/DISCUSSION_TEMPLATE/q-a.yml

@@ -0,0 +1,11 @@
+body:
+  - type: textarea
+    id: content
+    attributes:
+      label: Question
+      description: |
+        Search through [existing questions](https://github.com/zauberzeug/nicegui/discussions/categories/q-a) first.
+        If possible, give a [minimal reproducible code example](https://en.wikipedia.org/wiki/Minimal_reproducible_example).
+        Put source code in [fenced code blocks with syntax highlighting](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting).
+    validations:
+      required: true

+ 1 - 1
.github/ISSUE_TEMPLATE/config.yml

@@ -1,4 +1,4 @@
-blank_issues_enabled: true
+blank_issues_enabled: false
 contact_links:
   - name: Have an idea or a feature requests?
     url: https://github.com/zauberzeug/nicegui/discussions/categories/ideas-feature-requests

+ 15 - 0
.github/ISSUE_TEMPLATE/issue.yml

@@ -0,0 +1,15 @@
+name: Report an issue
+description: Report a bug or some other unexpected behavior.
+body:
+  - type: textarea
+    id: content
+    attributes:
+      label: Description
+      description: |
+        1. What are you trying to do?
+          If possible, give a [minimal reproducible code example](https://en.wikipedia.org/wiki/Minimal_reproducible_example).
+          Put source code in [fenced code blocks with syntax highlighting](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting).
+        2. What do you expect to happen?
+        3. What happens instead?
+    validations:
+      required: true

+ 0 - 10
.github/ISSUE_TEMPLATE/report-an-issue.md

@@ -1,10 +0,0 @@
----
-name: Report an issue
-about: Report a bug or some other unexpected behavior.
-title: ''
-labels: ''
-assignees: ''
-
----
-
-

+ 0 - 14
citation.cff

@@ -1,14 +0,0 @@
-cff-version: 1.2.0
-message: If you use this software, please cite it as below.
-authors:
-- family-names: Schindler
-  given-names: Falko
-  orcid: https://orcid.org/0009-0003-5359-835X
-- family-names: Trappe
-  given-names: Rodja
-  orcid: https://orcid.org/0009-0009-4735-6227
-title: 'NiceGUI: Web-based interfaces with Python. The nice way.'
-version: v1.2.3
-date-released: '2023-03-30'
-url: https://github.com/zauberzeug/nicegui
-doi: 10.5281/zenodo.7785517

+ 2 - 2
main.py

@@ -301,7 +301,7 @@ The command searches for `main.py` in in your current directory and makes the ap
 def documentation_page():
     add_head_html()
     add_header()
-    menu = side_menu()
+    side_menu()
     ui.add_head_html('<style>html {scroll-behavior: auto;}</style>')
     with ui.column().classes('w-full p-8 lg:p-16 max-w-[1250px] mx-auto'):
         section_heading('Reference, Demos and more', '*NiceGUI* Documentation')
@@ -309,7 +309,7 @@ def documentation_page():
             'This is the documentation for NiceGUI >= 1.0. '
             'Documentation for older versions can be found at [https://0.9.nicegui.io/](https://0.9.nicegui.io/reference).'
         ).classes('bold-links arrow-links')
-        documentation.create_full(menu)
+        documentation.create_full()
 
 
 @ui.page('/documentation/{name}')

+ 5 - 0
nicegui/app.py

@@ -4,10 +4,15 @@ from fastapi import FastAPI
 from fastapi.staticfiles import StaticFiles
 
 from . import globals
+from .native import Native
 
 
 class App(FastAPI):
 
+    def __init__(self, **kwargs) -> None:
+        super().__init__(**kwargs)
+        self.native = Native()
+
     def on_connect(self, handler: Union[Callable, Awaitable]) -> None:
         """Called every time a new client connects to NiceGUI.
 

+ 8 - 0
nicegui/native.py

@@ -0,0 +1,8 @@
+from dataclasses import dataclass, field
+from typing import Any, Dict
+
+
+@dataclass
+class Native:
+    start_args: Dict[str, Any] = field(default_factory=dict)
+    window_args: Dict[str, Any] = field(default_factory=dict)

+ 4 - 2
nicegui/native_mode.py

@@ -15,8 +15,10 @@ with warnings.catch_warnings():
 
 
 def open_window(url: str, title: str, width: int, height: int, fullscreen: bool) -> None:
-    webview.create_window(title, url=url, width=width, height=height, fullscreen=fullscreen)
-    webview.start(storage_path=tempfile.mkdtemp())
+    window_kwargs = dict(url=url, title=title, width=width, height=height, fullscreen=fullscreen)
+    window_kwargs.update(globals.app.native.window_args)
+    webview.create_window(**window_kwargs)
+    webview.start(storage_path=tempfile.mkdtemp(), **globals.app.native.start_args)
 
 
 def activate(url: str, title: str, width: int, height: int, fullscreen: bool) -> None:

+ 30 - 7
website/documentation.py

@@ -2,7 +2,7 @@ import uuid
 
 from nicegui import app, ui
 
-from .demo import bash_window, python_window
+from . import demo
 from .documentation_tools import element_demo, heading, intro_demo, load_demo, subheading, text_demo
 
 CONSTANT_UUID = str(uuid.uuid4())
@@ -55,7 +55,7 @@ def create_intro() -> None:
             ui.number().bind_value(demo, 'number')
 
 
-def create_full(menu: ui.element) -> None:
+def create_full() -> None:
     heading('Basic Elements')
     load_demo(ui.label)
     load_demo(ui.icon)
@@ -548,6 +548,7 @@ def create_full(menu: ui.element) -> None:
             ui.input('G').classes('w-12').on('keydown.space', lambda: ui.notify('You pressed space.'))
             ui.input('H').classes('w-12').on('keydown.y.shift', lambda: ui.notify('You pressed Shift+Y'))
             ui.input('I').classes('w-12').on('keydown.once', lambda: ui.notify('You started typing.'))
+
     heading('Configuration')
 
     @element_demo(ui.run, browser_title='My App')
@@ -556,6 +557,28 @@ def create_full(menu: ui.element) -> None:
 
         # ui.run(title='My App')
 
+    # HACK: switch color to white for the next demo
+    demo_BROWSER_BGCOLOR = demo.BROWSER_BGCOLOR
+    demo.BROWSER_BGCOLOR = '#ffffff'
+
+    @text_demo('Native Mode', '''
+        You can run NiceGUI in native mode by setting `native=True` in `ui.run`.
+        The parameters `window_size` and `fullscreen` can be used to configure the initial window size and whether the window should be fullscreen.
+        Apart from that, you can use `app.native` to define additional keyword arguments for the internally called `webview.create_window` and `webview.start` functions.
+        These keyword arguments overrule the `ui.run` parameters.
+    ''')
+    def native_mode_demo():
+        from nicegui import app
+
+        ui.label('app running in native mode')
+
+        app.native.window_args['resizable'] = False
+        app.native.start_args['debug'] = True
+
+        # ui.run(native=True, window_size=(400, 300), fullscreen=False)
+    # HACK: restore color
+    demo.BROWSER_BGCOLOR = demo_BROWSER_BGCOLOR
+
     @text_demo('Environment Variables', '''
         You can set the following environment variables to configure NiceGUI:
 
@@ -580,7 +603,7 @@ def create_full(menu: ui.element) -> None:
         A convenient alternative is the use of our [pre-built multi-arch Docker image](https://hub.docker.com/r/zauberzeug/nicegui) which contains all necessary dependencies.
         With this command you can launch the script `main.py` in the current directory on the public port 80:
     ''').classes('bold-links arrow-links')
-    with bash_window(classes='max-w-lg w-full h-52'):
+    with demo.bash_window(classes='max-w-lg w-full h-52'):
         ui.markdown('''
             ```bash
             docker run -p 80:8080 -v $(pwd)/:/app/ \\
@@ -592,7 +615,7 @@ def create_full(menu: ui.element) -> None:
         The `-d` tells docker to run in background and `--restart always` makes sure the container is restarted if the app crashes or the server reboots.
         Of course this can also be written in a Docker compose file:
     ''')
-    with python_window('docker-compose.yml', classes='max-w-lg w-full h-52'):
+    with demo.python_window('docker-compose.yml', classes='max-w-lg w-full h-52'):
         ui.markdown('''
             ```yaml
             app:
@@ -626,7 +649,7 @@ def create_full(menu: ui.element) -> None:
     ''').classes('bold-links arrow-links')
 
     with ui.row().classes('w-full items-stretch'):
-        with python_window(classes='max-w-lg w-full'):
+        with demo.python_window(classes='max-w-lg w-full'):
             ui.markdown('''
                 ```python
                 from nicegui import ui
@@ -636,7 +659,7 @@ def create_full(menu: ui.element) -> None:
                 ui.run(reload=False)
                 ```
             ''')
-        with python_window('build.py', classes='max-w-lg w-full'):
+        with demo.python_window('build.py', classes='max-w-lg w-full'):
             ui.markdown('''
                 ```python
                 import os
@@ -698,7 +721,7 @@ def create_full(menu: ui.element) -> None:
           That is why the build script invokes PyInstaller using `python -m PyInstaller` rather than just `pyinstaller`.
     ''').classes('bold-links arrow-links')
 
-    with bash_window(classes='max-w-lg w-full h-42 self-center'):
+    with demo.bash_window(classes='max-w-lg w-full h-42 self-center'):
         ui.markdown('''
             ```bash
             python -m venv venv