forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'nicegui/main' into feature/client_data
- Loading branch information
Showing
90 changed files
with
1,057 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import theme | ||
from message import message | ||
|
||
from nicegui import APIRouter, ui | ||
|
||
# NOTE: the APIRouter does not yet work with NiceGUI On Air (see https://github.com/zauberzeug/nicegui/discussions/2792) | ||
router = APIRouter(prefix='/c') | ||
|
||
|
||
@router.page('/') | ||
def example_page(): | ||
with theme.frame('- Page C -'): | ||
message('Page C') | ||
ui.label('This page and its subpages are created using an APIRouter.') | ||
ui.link('Item 1', '/c/items/1').classes('text-xl text-grey-8') | ||
ui.link('Item 2', '/c/items/2').classes('text-xl text-grey-8') | ||
ui.link('Item 3', '/c/items/3').classes('text-xl text-grey-8') | ||
|
||
|
||
@router.page('/items/{item_id}', dark=True) | ||
def item(item_id: str): | ||
with theme.frame(f'- Page C{item_id} -'): | ||
message(f'Item #{item_id}') | ||
ui.link('go back', router.prefix).classes('text-xl text-grey-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import theme | ||
from message import message | ||
|
||
from nicegui import ui | ||
|
||
|
||
class ClassExample: | ||
|
||
def __init__(self) -> None: | ||
"""The page is created as soon as the class is instantiated. | ||
This can obviously also be done in a method, if you want to decouple the instantiation of the object from the page creation. | ||
""" | ||
@ui.page('/b') | ||
def page_b(): | ||
with theme.frame('- Page B -'): | ||
message('Page B') | ||
ui.label('This page is defined in a class.') |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import theme | ||
from message import message | ||
|
||
from nicegui import ui | ||
|
||
|
||
def create() -> None: | ||
@ui.page('/a') | ||
def page_a(): | ||
with theme.frame('- Page A -'): | ||
message('Page A') | ||
ui.label('This page is defined in a function.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
from message import message | ||
|
||
from nicegui import ui | ||
|
||
|
||
def content() -> None: | ||
message('This is the home page.').classes('font-bold') | ||
ui.label('Use the menu on the top right to navigate.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
import example_c | ||
import example_pages | ||
import api_router_example | ||
import class_example | ||
import function_example | ||
import home_page | ||
import theme | ||
|
||
from nicegui import app, ui | ||
|
||
|
||
# here we use our custom page decorator directly and just put the content creation into a separate function | ||
# Example 1: use a custom page decorator directly and putting the content creation into a separate function | ||
@ui.page('/') | ||
def index_page() -> None: | ||
with theme.frame('Homepage'): | ||
home_page.content() | ||
|
||
|
||
# this call shows that you can also move the whole page creation into a separate file | ||
example_pages.create() | ||
# Example 2: use a function to move the whole page creation into a separate file | ||
function_example.create() | ||
|
||
# we can also use the APIRouter as described in https://nicegui.io/documentation/page#modularize_with_apirouter | ||
app.include_router(example_c.router) | ||
# Example 3: use a class to move the whole page creation into a separate file | ||
class_example.ClassExample() | ||
|
||
# Example 4: use APIRouter as described in https://nicegui.io/documentation/page#modularize_with_apirouter | ||
app.include_router(api_router_example.router) | ||
|
||
ui.run(title='Modularization Example') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Zeromq Example | ||
|
||
This example is a basic Zeromq implementation with NiceGUI. | ||
It shows how to stream data from a ZeroMQ socket to a NiceGUI plot. | ||
|
||
In order to do this, the zmq Python library is used to create a publisher and a subscriber. | ||
The main interesting aspect is that the zmq.async library is used to create a subscriber that can be used in an asyncio loop, which is necessary to run the NiceGUI server. | ||
|
||
## Running the example | ||
|
||
There are two components to this example: the publisher and the NiceGUI server. | ||
|
||
In addition to the normal NiceGUI dependencies, the zmq library must be installed (see requirements.txt). | ||
|
||
### Running the publisher | ||
|
||
The publisher is a simple Python script that sends random data to a ZeroMQ socket. | ||
To run it, simply execute the following command: | ||
|
||
```bash | ||
python zmq-server.py | ||
``` | ||
|
||
### Running the NiceGUI server | ||
|
||
The NiceGUI server is a Python script that creates a plot and updates it with data from the ZeroMQ socket. | ||
To run it, execute the following command: | ||
|
||
```bash | ||
python main.py | ||
``` | ||
|
||
### Results | ||
|
||
Once both the publisher and GUI server are running, you will see an updating plot on the UI. | ||
|
||
![plot](images/plot.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.