Skip to main content

Framework to build Python apps with the GASP metaphor

Project description

Demo

Gaspium

Framework to build Python apps with the GASP metaphor

This project is part of the Pyrustic Open Ecosystem.

Installation . Demo . Latest . Documentation

Table of contents

Overview

Gaspium is a framework that allows you to create applications with the GASP (GUI As Stapled Pages) metaphor.

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. You can open an arbitrary page of your application directly from the command line.

Gaspium serves as the reference implementation of the GASP concept.

Discover the GASP concept !

App

It is the main class of the Framework. An instance of the App class represents the running application. It is to this instance that the developer adds Pages.

from gaspium import App


app = App()

# ...
# Here you add pages to the app
# The first page is considered the home page
# ...

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

The App class accepts arguments like the theme to use, the geometry of the window, whether the caching should be enabled or not, et cetera. The App class also has the add method to add a page to the application, open method to open a page, start method to start the application, exit method to exit the application, et cetera.

Read the App documentation.

Page

A Page is either a function or a Viewable subclass. Each Page added to the App instance is either manually or automatically assigned a unique page identifier, the PID, and automatically referenced in the navigation bar. A page is rebuilt or not at each opening depending on whether the caching feature has been activated or not.

import tkinter as tk
from viewable import Viewable
from gaspium import App


def home_page(context):
    """Home Page. Must accept the dto argument"""
    # the dto contains some useful objects
    app = context.app
    pid = context.pid
    data = context.data
    root = context.root
    # the page function must returns the body
    # i.e. the graphical container of the page
    body = tk.Frame(root)
    label = tk.Label(body, text="Home")
    label.pack()
    return body


class LoginPage(Viewable):
    """
    Login Page
    """

    def __init__(self, context):
        """
        The constructor must accept the dto argument
        """
        super().__init__()
        # the dto contains some useful objects
        self._app = context.app
        self._pid = context.pid
        self._data = context.data
        self._root = context.root
        # the body of the page
        self._body = None

    def _build(self):
        self._body = tk.Frame(self._root)
        label = tk.Label(self._body, text="Login")
        label.pack()


def on_open_home(context):
    """
    This on_open callback must accept a dto object
    """
    # redirect to login_page
    # instead of letting the home_page open
    app = context.app
    app.open("login")


app = App(caching=False)

# Add home_page and bind the 'on_open_home' callback
# to perform a custom redirection to login_page
app.add(home_page, title="Home", on_open=on_open_home)

# Add login_page (it won't be referenced in the navigation bar)
app.add(LoginPage, pid="login", title="Login", indexable=False)

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

Play with the Demo.

Command line aware

By default, when you run a GASP application, the first page added to the App instance opens as the home page. It is possible to open an arbitrary page of the application from the command line. To do this, just put its PID (Page ID) as an argument on the command line. The strings entered after the identifier are considered as data to be sent to the page when it is opened.

$ my-app login "Alex Rustic"
# the login page will open

Batteries included

Gaspium comes with a handful of useful lightweight packages.

Name Description
Backstage Extensible command line tool for managing software projects
Cyberpunk-Theme A modern dark theme for Python apps
Shared Data exchange and persistence
Subrun Intuitive API to safely start and communicate with processes in Python
TkStyle Library to create styles and themes for Python apps
Megawidget Collection of megawidgets to build graphical user interfaces for Python apps
Viewable Python library to implement a GUI view with lifecycle
Threadom Tkinter-compatible multithreading
Suggestion Democratizing auto-complete(suggest) for Python desktop applications
Kurl Konnection URL: HTTP requests in Python with an implementation of conditional request and a responses caching system

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

Demo

A demo is available to play with as a Github Gist. Feel free to give a feedback in the comments section.

Play with the Demo.




Back to top

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gaspium-0.0.5.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

gaspium-0.0.5-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file gaspium-0.0.5.tar.gz.

File metadata

  • Download URL: gaspium-0.0.5.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.9.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.5.2

File hashes

Hashes for gaspium-0.0.5.tar.gz
Algorithm Hash digest
SHA256 4b9e171e997c3af63d5cb552bb61504e2516d9ef02be1e985b22d9a3c21bdd64
MD5 ec76339ee14ffab04ce0b00a785f2cfb
BLAKE2b-256 a842d8ca164c655791650ba83784faecdda328822892cb282c58a262267a273b

See more details on using hashes here.

File details

Details for the file gaspium-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: gaspium-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.9.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.5.2

File hashes

Hashes for gaspium-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0370819f48ab290039a499233b02869ca21651c8df5528dc1d216ac6172ed3ae
MD5 280ff56b1c17ae5342ffdde375b3a0cc
BLAKE2b-256 9d678607347b2d1904c96d31063534f8574ee0661ceac7c830acb914393e6953

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page