Git Product home page Git Product logo

nicegui_widgets's Introduction

nicegui_widgets's People

Contributors

tholzheim avatar wolfgangfahl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tholzheim lapnd

nicegui_widgets's Issues

add url_encode option to Link.create

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

add timeout decorator to Basetest class

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

add HideShow widget

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)

yaml support

Prompts for the development of the 'Yaml' class within the 'yaml' module:

  1. Develop a Python class named 'Yaml' in a module called 'yaml'. This class should focus on converting dataclass instances to YAML format, specifically for use in object-oriented programming.
  2. Implement methods in the 'Yaml' class for formatting multi-line string attributes using YAML block scalar style and excluding attributes with None values from the YAML output.
  3. Add a method to handle multi-line strings in the 'Yaml' class, ensuring they are formatted as block scalars in the YAML output.
  4. Include functionality to recursively remove None values from dataclass instances before conversion in the 'Yaml' class.
  5. The 'Yaml' class should only process dataclass instances, with error handling to raise a ValueError for non-dataclass objects.
  6. Write a comprehensive test suite for the 'Yaml' class within the context of the 'ngwidgets.basetest' framework. The tests should verify correct block scalar formatting, omission of None values, and general accuracy of the YAML conversion.
  7. Emphasize the use of Google-style docstrings, comprehensive comments, and type hints throughout the 'Yaml' class and its test suite.
  8. Adhere strictly to the provided instructions, and if there are any assumptions or uncertainties, seek clarification before proceeding.

add user handling

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.

add tristate module

Feature Request: Addition of Tristate Module to NiceGUI Widgets

Summary

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.

Details

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:

  • Tri-state functionality: unchecked, checked, and indeterminate.
  • Unicode icons for visual state representation.
  • Python-managed state cycling with no dependence on JavaScript for logic.
  • Reactivity handled within Python to update the Vue component's props.
  • Custom event emission on state changes with support for user-defined callback functions.

Example Icon Sets for Tristate Module

  • Arrows: arrows - Left Arrow (), Up-Down Arrow (↕️), Right Arrow ()
  • Ballot: ballot - Ballot Box (), Ballot Box with Check (☑️), Ballot Box with X (☒️)
  • Check: check - Checkbox (), Question Mark (), Checkmark (✔️)
  • Circles: circles - Circle (), Bullseye (🎯), Fisheye (🔘)
  • Electrical: electrical - Plug (🔌), Battery Half (🔋), Lightning ()
  • Faces: faces - Sad Face (☹️), Neutral Face (😐), Happy Face (☺️)
  • Hands: hands - Thumbs Down (👎), Hand (), Thumbs Up (👍)
  • Hearts: hearts - Empty Heart (), Half Heart (❤️), Full Heart (❤️)
  • Locks: locks - Unlocked (🔓), Locked with Pen (🔏), Locked (🔒)
  • Marks: marks - Question Mark (), Check Mark (), Cross Mark ()
  • Moons: moons - New Moon (🌑), Half Moon (🌓), Full Moon (🌕)
  • Musical Notes: musical_notes - Single Note (), Double Note (), Multiple Notes (🎶)
  • Stars: stars - Empty Star (), Half Star (), Full Star ()
  • Traffic Lights: traffic_lights - Red (🔴), Yellow (🟡), Green (🟢)
  • Weather: weather - Cloud (☁️), Sun (☀️), Thunderstorm (⛈️)

Implementation Details

The Tristate class should be developed adhering to the following criteria:

  • Use of google style docstrings for clear documentation.
  • Type hints for all methods and properties for better code clarity.
  • Code formatting according to PEP 8 standards, utilizing black and isort.
  • An explicit call to an update method that forces the NiceGUI framework to re-render the component on state changes.

References

The Tristate module is inspired by the following resources:

add setup_content_div

 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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.