Python framework to build apps with the GASP metaphor

Overview
Figure

Gaspium

Python framework to build apps with the GASP metaphor

This project is part of the Pyrustic Open Ecosystem.

Installation | Documentation | Latest

Table of contents

Overview

Gaspium is a framework that allows you to create applications with the GASP metaphor. To understand the GASP metaphor, please read this white paper.

In short, we define pages to which we add graphical components. Then we add these pages to an instance of the App class. The first page added is de facto the home page and it will be open when the application is started. Adding a page makes it automatically referenced in the application's navigation bar. Each graphical component can be identified with a unique identifier in order to be able to read its content or update it. Each page has a unique identifier assigned automatically or manually. You can open an arbitrary page directly from the command line.

Gaspium is suitable for:

  • building internal tools;
  • teaching GUI programming;
  • building GUI wrapper for command line scripts;
  • prototyping;
  • building utilities for yourself or other programmers;
  • lightweight commercial apps;
  • et cetera.

App

It is the main class of the framework.

Here's a code snippet:

from gaspium import App

app = App()
# by default the app is initialized with:
# title="Application", width=800, height=500,
# theme=Cyberpunk(), caching=False,
# resizable=(False, True), on_exit=None"""

# ...
# here you add pages to the app
# and the first page is considered the home page
# ...

# The last line starts the app (mainloop)
# The home page will open automatically
app.start()

Read the documentation of gaspium.App.

Page

A page is a view that is added to the instance of the App class.

Here's a code snippet:

from gaspium import App, Page


app = App()

# Define and add Page A (de facto, the home page)
page_a = Page(name="Page-A")
app.add(page_a)

# Define and add Page B.
# Assign 'page-b' as page id (pid) to this page
page_b = Page(name="Page-B", pid="page-b")
app.add(page_b)

# Define and add Page C
# The pid automatically assigned to a page
# can be retrieved via the page property 'pid'
page_c = Page(name="Page-C")
app.add(page_c)

# The home page will open automatically
app.start()

Read the documentation of gaspium.Page.

Component

A graphical component is a widget or group of widgets that you add to a page and with which the user interacts.

Here's a code snippet:

from gaspium import App, Page
from gaspium.component import Label, Entry, Button


def login(info):
    # We can retrieve via 'info' the content of the form (username, password)
    # and then process it, update the content of the page (add another component, ...),
    # pop-up some information to the user, programmatically open another page, et cetera.
    pass


def get_page():
    page = Page()
    # Add the Label graphical component
    page.add(Label, text="Login")
    # You can change the default layout config
    # with the parameters 'parent', 'side', 'anchor', 'fill', and 'expand'
    page.add(Entry, title="Username")
    page.add(Entry, title="Password", secretive=True)
    page.add(Button, on_click=login)
    return page


app = App()

page = get_page()
app.add(page)

app.start()

Read the documentation of gaspium.Component.

Demo

You can copy paste this code snippet and run it as it:

Click to expand or collapse
from gaspium import App, Page
from gaspium.component import Frame, Label, Entry, Button
from cyberpunk_theme.widget.button import get_button_red_style


def login(info):
    # We can retrieve via the named tuple 'info' the content of the form (username, password)
    # and then process it, update the content of the page (add another component, ...),
    # pop-up some information to the user, programmatically open another page, et cetera.
    app = info.app
    page = info.page
    username = page.read("username")
    password = page.read("password")
    accepted = False
    if not username or not password:
        msg = "Please submit fill the form !"
    else:
        accepted = True
        msg = "Hello {}".format(username)
    # the parameter 'blocking' tells if you want this toast to block the execution flow or not
    page.toast(msg, blocking=True)
    if accepted:
        # You can retrieve the linked data from the on_open callback associated
        # to the page 'welcome'
        app.open("welcome", data=username)


def get_page_a(app):
    page = Page(name="Home")
    # A Frame is container that fills the width of the page by default, like a row.
    # When you add a Frame to the page, it becomes implicitly the parent
    # of the next components except the next Frames
    page.add(Frame)
    # By default, components (except Frames) are packed from left to right
    # on the previously added Frame. You can change change the parent of a component
    # by using the keyword argument 'parent' that takes a component id (cid)
    page.add(Label, text="Login", color="gray")
    # The next Frame will be the container of the form
    page.add(Frame)
    # The two next lines are entries (the form)
    page.add(Entry, cid="username", title="Username")
    page.add(Entry, cid="password", title="Password", secretive=True)
    # This Frame will be the container of the next Button
    page.add(Frame)
    # add the Quit button
    on_click = lambda info, app=app: app.exit()
    page.add(Button, text="Quit", on_click=on_click, style=get_button_red_style())
    # add the login button
    page.add(Button, on_click=login)
    return page


def get_page_b():
    page = Page(pid="welcome")
    page.add(Label, text="Welcome !")
    return page


def get_page_c():
    page = Page(name="Documentation")
    page.add(Label, text="Documentation")
    return page


def get_page_d():
    page = Page(name="About")
    page.add(Label, text="About")
    return page


app = App(title="Login Demo", width=500, height=300)

# get page_a (de facto the home page)
page_a = get_page_a(app)
# add page_a
app.add(page_a)

# get page_b
page_b = get_page_b()
# this page won't be referenced in the navigation bar
app.add(page_b, indexable=False)

# get page_c
page_c = get_page_c()
# add page_c (referenced in the navigation bar under the dropdown menu 'Help')
app.add(page_c, category="Help")

# get page_d
page_d = get_page_d()
# add page_d (referenced in the navigation bar under the dropdown menu 'Help')
app.add(page_d, category="Help")

# start the app
app.start()
Figure

Demo

Installation

Gaspium is cross platform and versions under 1.0.0 will be considered Beta at best. It is built on Ubuntu with Python 3.8 and should work on Python 3.5 or newer.

For the first time

pip install gaspium

Upgrade

$ pip install gaspium --upgrade --upgrade-strategy eager

Default Components

The following components are included by default in the Gaspium framework: Button Choice Editor Entry Frame Image Label Litemark OptionMenu PathField SpinBox Table

Read the documentation !

Work in progress...

Owner
Collection of lightweight Python projects that share the same policy
Машинное обучение на ФКН ВШЭ

Курс "Машинное обучение" на ФКН ВШЭ Конспекты лекций, материалы семинаров и домашние задания (теоретические, практические, соревнования) по курсу "Маш

Evgeny Sokolov 2.2k Jan 04, 2023
Python Excuse Generator

Excuse Generator Python Excuse Generator This project is an excuse generator that provides the user with an excuse as to why they weren't paying atten

Collin Sanders 5 Jul 07, 2022
mypy plugin for PynamoDB

pynamodb-mypy A plugin for mypy which gives it deeper understanding of PynamoDB (beyond what's possible through type stubs). Usage Add it to the plugi

1 Oct 21, 2022
YBlade - Import QBlade blades into Fusion 360

YBlade - Import QBlade blades into Fusion 360 Simple script for Fusion 360 that takes QBlade blade description and constructs the blade: Usage First,

Jan Mrázek 37 Sep 25, 2022
Combines power of torch, numerical methods to conquer and solve ALL {O,P}DEs

torch_DE_solver Combines power of torch, numerical methods and math overall to conquer and solve ALL {O,P}DEs There are three examples to provide a li

Natural Systems Simulation Lab 28 Dec 12, 2022
emoji-math computes the given python expression and returns either the value or the nearest 5 emojis as measured by cosine similarity.

emoji-math computes the given python expression and returns either the value or the nearest 5 emojis as measured by cosine similarity.

Andrew White 13 Dec 11, 2022
【幼盾】个性化图片徽章服务!

【幼盾】个性化图片徽章服务! 你对方形的徽章感到无聊了吗?想要定制属于自己的开源项目徽章了吗? 快来使用unv-shield吧! unv-shield提供包含自定义图片的徽章服务,可以让你的项目主页更加个性化!

黄巍 130 Dec 23, 2022
Simple but maybe too simple config management through python data classes. We use it for machine learning.

👩‍✈️ Coqpit Simple, light-weight and no dependency config handling through python data classes with to/from JSON serialization/deserialization. Curre

coqui 67 Nov 29, 2022
A data driven app for bicycle hiring in London(UK)

bicycle_hiring_app_deployed A data driven app for bicycle hiring in London(UK). It predicts expected number of bicycle hire in London. It asks users t

Rajarshi Roy Raju 1 Dec 10, 2021
Python meta class and abstract method library with restrictions.

abcmeta Python meta class and abstract method library with restrictions. This library provides a restricted way to validate abstract methods. The Pyth

Morteza NourelahiAlamdari 8 Dec 14, 2022
App to decide weekly winners in H2H 1 Win (9 Cat)

Fantasy Weekly Winner for H2H 1 Win (9 Cat) Yahoo Fantasy API Read

Sai Atmakuri 1 Dec 31, 2021
VirtualBox Power Driver for MAAS (Metal as a Service)

vboxpower VirtualBox Power Driver for MAAS (Metal as a Service) A way to manage the power of VirtualBox virtual machines via the MAAS webhook driver.

Saeid Bostandoust 131 Dec 17, 2022
A hackers attempt at an MVP anki plugin

my anki plugin if you have found this by accident, you should probably run away this is nothing more than a hackers attempt at an MVP anki plugin I re

Chris Hall 1 Nov 02, 2021
A custom advent of code I am completing

advent-of-code-custom A custom advent of code I am doing in python. The link to the problems I am solving is here: https://github.com/seldoncode/Adven

Rocio PV 2 Dec 11, 2021
Processamento da Informação - Disciplina UFABC

Processamento da Informacao Disciplina UFABC, Linguagem de Programação Python - 2021.2 Objetivos Apresentar os fundamentos sobre manipulação e tratame

Melissa Junqueira de Barros Lins 1 Jun 12, 2022
Bad Apple printed out on the console with Python!

bad-apple Bad Apple printed out on the console with Python! Preface A word of disclaimer, while the final code is somewhat original, this project is a

CalvinLoke 186 Dec 01, 2022
Swim between bookmarks in the Windows terminal

Marlin Swim between bookmarks in the terminal! Marlin is an easy to use bookmark manager for the terminal. Choose a folder, bookmark it and swim there

wilfredinni 7 Nov 03, 2022
dta Convert Dict To Attributes!

dta (Dict to Attributes) dta is very small dict (or json) to attributes converter. It is only have 1 files and applied to every python versions.

Rukchad Wongprayoon 0 Dec 31, 2021
Simple Crud Python vs MySQL

Simple Crud Python vs MySQL The idea came when I was studying MySQ... A desire to create a python program that can give access to a "localhost" databa

Lucas 1 Jan 21, 2022
JurjenLang, an interpreted programming language

JurjenLang An interpreted programming language Getting started Follow these three steps on your computer to get started git clone https://github.com/J

JVerbruggen 5 May 03, 2022