👩‍💻 Github

Checklist

Understanding the code

Goal:

Traditional GUI packages target GUI creation for end-users. This means that they're extensible, precisely configurable, and set up in a way that keeps code reusability high while keeping code execution low. Those great advantages all come at a cost: complexity for the programmer.

Rapid-Gui tries to approach GUI's slightly differently. Instead of attempting to provide tools that allow to create the best possible end product, it is made with the programmer in mind. As such, it can be added to code that isn't even written with GUIs in mind - one line at the top of the file is sufficient to start a new window, and with one method call your data is visualized.

Problem

Let's say we have a script that does something computation heavy, containing a long loop:

import time, random

def do_heavy_work():
    time.sleep(random.choide(range(3)))

def my_super_duper_long_function():
    pct = 0 # percentage
    for i in range(5):
        pct = i * 1/5
        do_heavy_work()
    pct = 1

And we'd like to get some visual feedback in the form of a button and a progress bar.

Solution

(Still not implemented)

1. Install rapidgui

pip3 install rapidgui

2. Launch editor, create GUI file

python3 -m rapidgui

3. Attach Gui To Your Script

import time, random
import rapidgui

app = rapidgui.load("example.json")

def do_heavy_work():
    time.sleep(random.choice(range(3)))

def my_super_duper_long_function():
    pct = 0
    app("myprogressbar").set_pct(pct)
    for i in range(20):
        pct = i * 1 / 20
        app("myprogressbar").set_pct(pct*100)
        do_heavy_work()

    app("myprogressbar").set_pct(100)
    print("Done doing heavy work.")

@app("mybutton")
def on_pressed():
    app("mybutton").set_enabled(False)
    my_super_duper_long_function()

And out comes the GUI defined in the editor, with a working button & progress bar.

Other possible use cases:

Output subprocess feedback:

subp = subprocess.spawn("ls -a")
app("MyTerminalViewer").display_subprocess(subp)

Plot data:

data = range(100)
app("MyPlot").plot(data, data) # x, y data etc.

Create forms

form = app("MyForm")
button = app("MyButton")
form.set_submit_button(button) # or add callback to button calling form.submit()

@app("MyForm")
def on_submit(text):
   print(text)

Select files

@app("MyButton")
def on_press():
    filename = app.select_file()
    folder = app.select_folder()
    files = app.select_files()

Display code, images, ...

app("MyDisplay").set_content("print('hello world')", syntax="Python")
app("MyDisplay").set_content(open('kitten.png'))

Display tables

data = [["Max", "Mustermann"] for i in range(20)]
app("MyTable").set_content(data)
app("MyTable").set_header("Firstname", "Lastname")

app("MyTable").set_editable(True)

@app("MyTable")
def on_edit(edited_data):
   pass

@app("MyButton")
def on_pressed():
    app("MyPlot").plot(app("MyTable").get_data(), range(1000))

Display checkboxes,

app("MyCheckbox").set_editable(False)
app("myCheckbox").set(False)

Setup timers

@app.timer(13, "s")
def check_server_online():
    app("MyCheckbox").set(is_server_online())

@app.timer(1, "s")
def player_count():
    app("MyLabel").set(get_player_count())

Setup keyboard shortcuts

@app.shortcut("Ctrl+S")
def save():
   self.save_file()

Current Progress

Running example:

The example in the vision has been fully realized:

goal.py

import time, random
import rapidgui

app = rapidgui.load("example.json")

def do_heavy_work():
    time.sleep(random.choice(range(3)))

def my_super_duper_long_function():
    pct = 0
    app("myprogressbar").set_pct(pct)
    for i in range(20):
        pct = i * 1 / 20
        app("myprogressbar").set_pct(pct*100)
        do_heavy_work()

    app("myprogressbar").set_pct(100)
    print("Done doing heavy work.")

@app("mybutton")
def on_pressed():
    app("mybutton").set_enabled(False)
    my_super_duper_long_function()

example.json

{
    "app-properties": {
        "width": 1000,
        "height": 500,
        "background_color": [255, 255, 255, 255]
    },

    "components" : [
        {
            "meta": {
                "type": "button",
                "identifier": "mybutton"
            },
            "properties": {
                "x": 100,
                "y": 100,
                "width": 200,
                "height": 50,
                "label_text": "Hello",
                "background_color": [164, 219, 211, 255],
                "line_color": null,
                "enabled": true
            }
        },
        {
            "meta": {
                "type": "progressbar",
                "identifier": "myprogressbar"
            },
            "properties": {
                "x": 500,
                "y": 100,
                "width": 400,
                "height": 50,
                "background_color": [230, 230, 230, 255],
                "pct": 0,
                "bar_color": [164, 219, 211, 255]
            }
        }
    ]
}

Result

Contributing

Contributions are welcome! If you need help with anything, please ask.

Table Of Contens