defgui


Namedefgui JSON
Version 0.2 PyPI version JSON
download
home_pagehttps://github.com/davidho123/defgui
SummaryDecorator for Fast Generation of Function Input Output Components with Tkinter or Streamlit
upload_time2024-06-25 11:35:31
maintainerNone
docs_urlNone
authordavidho
requires_pythonNone
licenseMIT
keywords python gui defgui function tkinter streamlit
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
![logo](logo.png)

[中文](README-zh.md)

This module is a function decorator that automatically generates corresponding GUI components based on the function's parameters and return values.
## Table of Contents
* [Overview](README.md##overview)
* [Features](README.md##features)
* [Usage](README.md##usage)
* [Version Notes](README.md##version-notes)

## Overview
This module is inspired by [magicgui](https://github.com/pyapp-kit/magicgui), thank you to the author.
This module has two branches: one based on tkinter and one based on streamlit.
Main differences from magicgui:
1. Magicgui uses pyqt and pyside as tools, while this module uses tkinter and streamlit.
2. This module only provides a decorator to generate components, not separate GUI components.
3. This module can return the input values of input components, which is convenient for separate use.

## Features
Basic function: Use a decorator to automatically generate corresponding GUI components based on the function's parameters and return values.

**tkinter branch**
* Based mainly on tkinter and the typing and ctypes libraries from the Python standard library. No third-party dependencies like pyside are required.
* Based on the principle of easy use, this branch has only one decorator function and no other parameter settings.
* The output components generated by this branch are consistent with the number of return values.
* DPI adaptation is automatically performed, and the interface will not be blurred.
* Currently supported parameter types: int, float, str, List[str]

**streamlit branch**
* Based mainly on streamlit.
* This branch allows you to set whether input components are placed horizontally or vertically.
* When placed horizontally, you can set the column width ratio for each component.
* You can set whether to display the execute button and whether to perform function calculations.
* Returns the input values of each component and the function execution result values for subsequent separate use.

## Usage
```python
pip install defgui
```
You can use it directly by adding a decorator to the function.
### Note: When defining the function, the parameters need to have type annotations, otherwise an error will be reported.

### 1. Using the tkinter branch
- Currently supported type annotations for this branch: int, float, str, List[str]
- Click the automatically generated run button to display the output results.
```python
from defgui import defgui_tkinter
from typing import List
# Define the function
@defgui_tkinter
def example_function(a: int, b: float, c: str, d: List[str]) -> tuple:
    """Example function that returns a tuple of four values."""
    return a + 1, b + 1, "str:%s" % (c), d
# Run the function
example_function()
```
Running results

![png](result.png)

### 2. Using the streamlit branch
- Currently supported type annotations for this branch: int, float, str, bool, list, datetime.date
- For list parameters, if not assigned a value, the generated component will not have any options and will appear grey and unavailable. It is recommended to assign a value to the list parameter before running it.
- For datetime.date parameters, if not assigned a value, the generated date component will default to the current date.
- When defining the function, the parameters can be positional or keyword parameters, but they must have type annotations, otherwise an error will be reported.
- This branch of the decorator has 3 default parameters: horizontal=True, col_size=None, execute=True
- **horizontal=True:** Input components are placed horizontally by default.
- **col_size=None:** Column size is not set by default, and the column width is divided evenly according to the number of input components.
- **execute=True:** The execute button is displayed by default, and function calculations are performed. False will not display it.
- When the decorated function is executed, it defaults to returning the input values of the input components and the result values. The input values are of list type, and the order of list items is consistent with the order of function parameters.
- The decorated function can be executed with or without values assigned.

#### (1) Executing with parameter assignment, components placed horizontally, and the execute button displayed
```python
from defgui import defgui_streamlit
import streamlit as st
import datetime
st.set_page_config(layout="wide")
st.title("Streamlit Decorator App")
@defgui_streamlit(horizontal=True, col_size=[1, 1, 1, 2, 2], execute=True)
def greet(date: datetime.date, name: str, age: int = 20, food: list = []) -> str:
    return f"{date}, Hello, {name}! You are {age} years old, you like {food}"
input_values, results = greet(name="david", food=["apple", "banana"])
st.write(input_values[1])
```
![png](defgui_streamlit_h.png)

#### (2) Executing without parameter assignment, components placed vertically, and the execute button not displayed
```python
from defgui import defgui_streamlit
import streamlit as st
import datetime
st.set_page_config(layout="wide")
st.title("Streamlit Decorator App")
@defgui_streamlit(horizontal=False, col_size=None, execute=False)
def greet(date: datetime.date, name: str, age: int, food: list) -> str:
    return f"{date}, Hello, {name}! You are {age} years old, you like {food}"
cols = st.columns(3)
with cols[0]:
    greet()
```
![png](defgui_streamlit_c.png)

## Version Notes
v 0.2
Added a decorator based on streamlit

v 0.1
Decorator based on tkinter

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/davidho123/defgui",
    "name": "defgui",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, gui, defgui, function, tkinter, streamlit",
    "author": "davidho",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/fe/6a/2adde9835f1ff2fea950a8f8ff21bdb31dba778852480d27bb87a86f8554/defgui-0.2.tar.gz",
    "platform": null,
    "description": "\r\n![logo](logo.png)\r\n\r\n[\u4e2d\u6587](README-zh.md)\r\n\r\nThis module is a function decorator that automatically generates corresponding GUI components based on the function's parameters and return values.\r\n## Table of Contents\r\n* [Overview](README.md##overview)\r\n* [Features](README.md##features)\r\n* [Usage](README.md##usage)\r\n* [Version Notes](README.md##version-notes)\r\n\r\n## Overview\r\nThis module is inspired by [magicgui](https://github.com/pyapp-kit/magicgui), thank you to the author.\r\nThis module has two branches: one based on tkinter and one based on streamlit.\r\nMain differences from magicgui:\r\n1. Magicgui uses pyqt and pyside as tools, while this module uses tkinter and streamlit.\r\n2. This module only provides a decorator to generate components, not separate GUI components.\r\n3. This module can return the input values of input components, which is convenient for separate use.\r\n\r\n## Features\r\nBasic function: Use a decorator to automatically generate corresponding GUI components based on the function's parameters and return values.\r\n\r\n**tkinter branch**\r\n* Based mainly on tkinter and the typing and ctypes libraries from the Python standard library. No third-party dependencies like pyside are required.\r\n* Based on the principle of easy use, this branch has only one decorator function and no other parameter settings.\r\n* The output components generated by this branch are consistent with the number of return values.\r\n* DPI adaptation is automatically performed, and the interface will not be blurred.\r\n* Currently supported parameter types: int, float, str, List[str]\r\n\r\n**streamlit branch**\r\n* Based mainly on streamlit.\r\n* This branch allows you to set whether input components are placed horizontally or vertically.\r\n* When placed horizontally, you can set the column width ratio for each component.\r\n* You can set whether to display the execute button and whether to perform function calculations.\r\n* Returns the input values of each component and the function execution result values for subsequent separate use.\r\n\r\n## Usage\r\n```python\r\npip install defgui\r\n```\r\nYou can use it directly by adding a decorator to the function.\r\n### Note: When defining the function, the parameters need to have type annotations, otherwise an error will be reported.\r\n\r\n### 1. Using the tkinter branch\r\n- Currently supported type annotations for this branch: int, float, str, List[str]\r\n- Click the automatically generated run button to display the output results.\r\n```python\r\nfrom defgui import defgui_tkinter\r\nfrom typing import List\r\n# Define the function\r\n@defgui_tkinter\r\ndef example_function(a: int, b: float, c: str, d: List[str]) -> tuple:\r\n    \"\"\"Example function that returns a tuple of four values.\"\"\"\r\n    return a + 1, b + 1, \"str\uff1a%s\" % (c), d\r\n# Run the function\r\nexample_function()\r\n```\r\nRunning results\r\n\r\n![png](result.png)\r\n\r\n### 2. Using the streamlit branch\r\n- Currently supported type annotations for this branch: int, float, str, bool, list, datetime.date\r\n- For list parameters, if not assigned a value, the generated component will not have any options and will appear grey and unavailable. It is recommended to assign a value to the list parameter before running it.\r\n- For datetime.date parameters, if not assigned a value, the generated date component will default to the current date.\r\n- When defining the function, the parameters can be positional or keyword parameters, but they must have type annotations, otherwise an error will be reported.\r\n- This branch of the decorator has 3 default parameters: horizontal=True, col_size=None, execute=True\r\n- **horizontal=True:** Input components are placed horizontally by default.\r\n- **col_size=None:** Column size is not set by default, and the column width is divided evenly according to the number of input components.\r\n- **execute=True:** The execute button is displayed by default, and function calculations are performed. False will not display it.\r\n- When the decorated function is executed, it defaults to returning the input values of the input components and the result values. The input values are of list type, and the order of list items is consistent with the order of function parameters.\r\n- The decorated function can be executed with or without values assigned.\r\n\r\n#### (1) Executing with parameter assignment, components placed horizontally, and the execute button displayed\r\n```python\r\nfrom defgui import defgui_streamlit\r\nimport streamlit as st\r\nimport datetime\r\nst.set_page_config(layout=\"wide\")\r\nst.title(\"Streamlit Decorator App\")\r\n@defgui_streamlit(horizontal=True, col_size=[1, 1, 1, 2, 2], execute=True)\r\ndef greet(date: datetime.date, name: str, age: int = 20, food: list = []) -> str:\r\n    return f\"{date}, Hello, {name}! You are {age} years old, you like {food}\"\r\ninput_values, results = greet(name=\"david\", food=[\"apple\", \"banana\"])\r\nst.write(input_values[1])\r\n```\r\n![png](defgui_streamlit_h.png)\r\n\r\n#### (2) Executing without parameter assignment, components placed vertically, and the execute button not displayed\r\n```python\r\nfrom defgui import defgui_streamlit\r\nimport streamlit as st\r\nimport datetime\r\nst.set_page_config(layout=\"wide\")\r\nst.title(\"Streamlit Decorator App\")\r\n@defgui_streamlit(horizontal=False, col_size=None, execute=False)\r\ndef greet(date: datetime.date, name: str, age: int, food: list) -> str:\r\n    return f\"{date}, Hello, {name}! You are {age} years old, you like {food}\"\r\ncols = st.columns(3)\r\nwith cols[0]:\r\n    greet()\r\n```\r\n![png](defgui_streamlit_c.png)\r\n\r\n## Version Notes\r\nv 0.2\r\nAdded a decorator based on streamlit\r\n\r\nv 0.1\r\nDecorator based on tkinter\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Decorator for Fast Generation of Function Input Output Components with Tkinter or Streamlit",
    "version": "0.2",
    "project_urls": {
        "Homepage": "https://github.com/davidho123/defgui"
    },
    "split_keywords": [
        "python",
        " gui",
        " defgui",
        " function",
        " tkinter",
        " streamlit"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fe6a2adde9835f1ff2fea950a8f8ff21bdb31dba778852480d27bb87a86f8554",
                "md5": "a7c66342ecdda1949f053268ae49ccc6",
                "sha256": "a52809dee01c1b5016d5b21227144d90c0dc08b1b29a5c44c27d7a9b77e80bec"
            },
            "downloads": -1,
            "filename": "defgui-0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a7c66342ecdda1949f053268ae49ccc6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7044,
            "upload_time": "2024-06-25T11:35:31",
            "upload_time_iso_8601": "2024-06-25T11:35:31.207336Z",
            "url": "https://files.pythonhosted.org/packages/fe/6a/2adde9835f1ff2fea950a8f8ff21bdb31dba778852480d27bb87a86f8554/defgui-0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-25 11:35:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "davidho123",
    "github_project": "defgui",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "defgui"
}
        
Elapsed time: 0.24598s