GithubHelp home page GithubHelp logo

jacadzaca / gooey_quick Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 117 KB

Turn type-hinted Python program into a GUI application with few additional lines of code

Home Page: https://pypi.org/project/gooey-quick/

License: MIT License

Python 100.00%
gooey graphical-user-interface introspection python

gooey_quick's Introduction

gooey-quick

Turn type-hinted Python program into a GUI application with few additional lines of code

gooey-quick title card

Table of contents


Quick Start

Installation

You can install gooey-quick via pip:

pip install gooey-quick

or by cloning the repository directly:

git clone https://github.com/jacadzaca/gooey_quick.git && ./setup.py

Usage

You can integrate gooey-quick with your code as easily as so:

import gooey_quick


def some_function_you_want_to_gooeyfiy(
    name: str,
    repeat_count: int,
):
    for _ in range(repeat_count):
        print(f'Hello {name}')


if __name__ == '__main__':
    gooey_quick.run_gooey(some_function_you_want_to_gooeyfiy)

Gooey global configuration

You can set Gooey's global options by setting them in the call to gooey_quick.run_gooey like so:

import gooey_quick


def some_function_you_want_to_gooeyfiy(
    name: str,
    repeat_count: int,
):
    for _ in range(repeat_count):
        print(f'Hello {name}')


if __name__ == '__main__':
    gooey_quick.run_gooey(
        some_function_you_want_to_gooeyfiy,
        program_name='Simple demo program',
        program_description='A demo program using Gooey and gooey_quick',
    )

What is it?

gooey-quick is a library that generates a Gooey-based GUIs from methods' signatures.

Why is it?

A lot of GUI programs that are written in an office setting are wrappers around simple python code. Handcrafting GUIs can be cumbersome, while dealing with argparse-like interface becomes more annoying as the program grows (e.g. you have 6 tabs in your Advanced layout Gooey program). With gooey-quick you should forget about the above and focus on the programs' features.

How does it work?

gooey-quick uses python's built-in typing and introspection functionalities to analyze objects' signatures and generate a fancy GUI using the amazing Gooey by chriskiehl.

Examples

Simple 'Flat layout' application

#!/usr/bin/env python3
from enum import Enum
from pathlib import Path
from datetime import date, time

import gooey_quick


class UploadMethod(Enum):
    SFTP = 'SFTP'
    HTTP = 'HTTP'


def upload_file(
    file: Path,
    new_filename: str,
    chunksize: int,
    lattency: float,
    upload_date: date,
    upload_time: time,
    upload_method: UploadMethod,
):
    assert type(upload_method) is UploadMethod
    return (
        f'{file} was uploaded via {upload_method.name} on {upload_date} at '
        f'{upload_time} in chunks of size {chunksize} and with lattency of '
        f'{lattency}'
    )


if __name__ == '__main__':
    # gooey_quick.run_gooey has the same return values as the wrapped function
    return_value = gooey_quick.run_gooey(
        # the first argument is the fucntion you'd like to be converted into a Gooey program
        upload_file,
        # gooey_quick.run_gooey can be used to set Gooey's global configuration
        # see https://github.com/chriskiehl/Gooey#global-configuration for possible options
        program_name='Simple upload program',
        program_description='A demo program using Gooey and gooey_quick',
    )
    print(return_value)

Start Gooey in Advanced mode with 3 different tabs:

#!/usr/bin/env python3
from pathlib import Path
from typing import Optional
from datetime import date, datetime

import gooey_quick


def search_history(
    history_file: Path,
    wanted_phrase: str,
    min_occure_date: Optional[date] = None,
    max_occure_date: Optional[date] = None,
) -> Optional[tuple[date, str]]:
    occurance_date = date(year=2002, month=7, day=22)
    the_phrase = "wow you have discovered my secret phrase!"
    occurance_in_range = True

    if min_occure_date is not None and max_occure_date is not None:
        print(f'Looking for {wanted_phrase} from {min_occure_date} to {max_occure_date}...')
        occurance_in_range = occurance_date in range(min_occure_date, max_occure_date)

    if wanted_phrase in the_phrase and occurance_in_range:
        return f'{occurance_date}: {the_phrase}'


def append_to_history(
    history_file: Path,
    phrase: str,
    occurance_date: date = datetime.now().date()
):
    return f'Appending {phrase} to {history_file} at {occurance_date}...'


def remove_from_history(
    history_file: Path,
    phrase: str,
):
    return f'Removing {phrase} from {history_file}...'


if __name__ == '__main__':
    # when passing a dict to gooey_quick.run_gooey, the keys become
    # the tabs descriptions, while the values are the function to
    # create the gui from
    return_value = gooey_quick.run_gooey(
        {
           'Add phrase': append_to_history,
           'Remove phrase': remove_from_history,
           'Search phrases': search_history,
        },
        # set Gooey's global config as per: https://github.com/chriskiehl/Gooey#layout-customization
        navigation='TABBED',
        program_name='Gooey subparser layout from function dict',
        program_description='Presents how to create a bundeled configuration with gooey_quick',
     )
    print(return_value)

For more see the docs/examples/ directory.

Packaging

Please refer to either the official guide or this tutorial

gooey_quick's People

Contributors

dependabot[bot] avatar jacadzaca avatar

Watchers

 avatar

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.