nicegui widgets
wolfgangfahl / nicegui_widgets Goto Github PK
View Code? Open in Web Editor NEWnicegui widgets
Home Page: http://ngdemo.bitplan.com
License: Apache License 2.0
nicegui widgets
Home Page: http://ngdemo.bitplan.com
License: Apache License 2.0
in case the url e.g. in a RESTFul service is created by arbitrary parameters and might need encoding due to special chars in the restful parameters
import getpass
import os
import signal
from functools import wraps
from unittest import TestCase
from ngwidgets.profiler import Profiler
class Basetest(TestCase):
"""
base test case
"""
@staticmethod
def timeout(seconds):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
def signal_handler(signum, frame):
raise TimeoutError(f"Test timed out after {seconds} seconds")
signal.signal(signal.SIGALRM, signal_handler)
signal.alarm(seconds)
try:
return func(*args, **kwargs)
finally:
signal.alarm(0)
return wrapper
return decorator
Allow testing of RESTFul interfaces via FastAPI Testclient in a straightforward way.
migrate justpy jpwidgets code to nicegui:
class HideShow(jp.Div):
"""
Create a Div with visibility (hid/show) toogle
"""
TRIANGLE_LEFT = "◀"
TRIANGLE_DOWN = "▼"
def __init__(
self,
hide_show_label: tuple,
show_content: bool = True,
**kwargs):
"""
constructor
Args:
content: justpy component with the content to hide/show
hide_show_label: labels to be shown if the content is hidden/shown.
show_content: If True show the content at page load otherwise the content is hidden.
**kwargs: additional justpy arguments
"""
# first add the hide/show button to my parent
a=kwargs.get("a")
self.label_if_shown, self.label_if_hidden = hide_show_label
self.btn = jp.Button(a=a, text=self._getStatusLabel(show_content), on_click=self.toggleHideShow)
# then create a div component
jp.Div.__init__(self,**kwargs)
self._setShowContent(show_content)
def _setShowContent(self,show_content:bool):
"""
set my show_content state via my data container
"""
self.data["show_content"]=show_content
self.hidden(not show_content)
def _getStatusLabel(self,show_content:bool) -> str:
"""
Returns the Icon of the current status
"""
if show_content:
icon = self.TRIANGLE_DOWN
label = self.label_if_shown
else:
icon = self.TRIANGLE_LEFT
label = self.label_if_hidden if self.label_if_hidden is not None else self.label_if_shown
return f"{label} {icon}"
def toggleHideShow(self, _msg:dict):
"""
Toggle the visibility status of the content
"""
show_content = not self.data["show_content"]
self._setShowContent(show_content)
self.btn.text = self._getStatusLabel(show_content)
with an optional log_view
see https://mozilla.github.io/pdf.js/examples/ and
https://jsfiddle.net/pdfjs/wagvs9Lf/ for the html and javascript code examples
reload should always render
Prompts for the development of the 'Yaml' class within the 'yaml' module:
usage
niceuser -h
usage: niceuser [-h] -u USERNAME -p PASSWORD -c PROJECT [-a]
Manage user data.
options:
-h, --help show this help message and exit
-u USERNAME, --username USERNAME
The username.
-p PASSWORD, --password PASSWORD
The password.
-c PROJECT, --project PROJECT
The configuration name/project
-a, --add Add a user. Otherwise, checks the password.
As e.g. being used by nicetrack, nicescad and nicepdf
Addition of a new class named Tristate
to the NiceGUI widgets project. This class provides a tri-state toggle input component that leverages predefined Unicode icon sets for visual representation, handling state changes entirely within Python without relying on JavaScript logic for state management.
The Tristate
component allows users to cycle through three states, each represented by a distinct Unicode icon. It's designed to integrate seamlessly with the existing NiceGUI application structure, offering a reactive UI component that updates its display based on user interactions.
Here are the key features of the Tristate
module:
arrows
- Left Arrow (←
), Up-Down Arrow (↕️
), Right Arrow (→
)ballot
- Ballot Box (☐
), Ballot Box with Check (☑️
), Ballot Box with X (☒️
)check
- Checkbox (☐
), Question Mark (❔
), Checkmark (✔️
)circles
- Circle (⭘
), Bullseye (🎯
), Fisheye (🔘
)electrical
- Plug (🔌
), Battery Half (🔋
), Lightning (⚡
)faces
- Sad Face (☹️
), Neutral Face (😐
), Happy Face (☺️
)hands
- Thumbs Down (👎
), Hand (✋
), Thumbs Up (👍
)hearts
- Empty Heart (♡
), Half Heart (❤️
), Full Heart (❤️
)locks
- Unlocked (🔓
), Locked with Pen (🔏
), Locked (🔒
)marks
- Question Mark (❓
), Check Mark (✅
), Cross Mark (❌
)moons
- New Moon (🌑
), Half Moon (🌓
), Full Moon (🌕
)musical_notes
- Single Note (♪
), Double Note (♫
), Multiple Notes (🎶
)stars
- Empty Star (☆
), Half Star (★
), Full Star (★
)traffic_lights
- Red (🔴
), Yellow (🟡
), Green (🟢
)weather
- Cloud (☁️
), Sun (☀️
), Thunderstorm (⛈️
)The Tristate
class should be developed adhering to the following criteria:
black
and isort
.The Tristate
module is inspired by the following resources:
make app available to eg. TestClient
e.g. to improve datetime handling
async def setup_content_div(self, setup_content: Optional[Callable] = None) -> None:
"""
Sets up the content frame of the web server's user interface. This includes setting up the menu,
the main content as specified by the 'setup_content' callable (if provided), and the footer.
The method orchestrates the layout and initialization of these UI components.
Args:
setup_content (Optional[Callable]): A callable that is responsible for setting up the main
content of the web server's UI. This could be a function
that adds widgets or other UI elements to the content area.
If None, no additional content setup is performed.
Default is None.
Returns:
None: This method does not return anything.
Note:
This method is asynchronous and should be awaited when called.
"""
# Setting up the menu
self.setup_menu()
with ui.element("div").classes("w-full h-full") as self.content_div:
# If a content setup callable is provided, execute it to setup the main content
if setup_content:
setup_content()
# Setting up the footer
await self.setup_footer()
What to do if people do not follow
nicegui solutions bazaar - Howto
and the result is e.g. multiple or wrong entries in
nicegui solutions bazaar
refactor base class with a single input (http/file) as the core element of a website
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.