Skip to main content

A small example package

Project description

PyApplicationFramework

Introduction

The PyApplicationFramework is a set of library wrappers related to application development in Python. This framework allows developers to write a GUI application more simply, with a programming paradigm similar to SwiftUI. The declarative syntax of User Interface markup, inspired by SwiftUI, is one of the critical functionalities in this project.

A Basic "Hello, World!" Code with Explanation

import wx

class HelloWorldFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)
        self.SetTitle("HelloWorldWindow")
        panel = wx.Panel(self)
        sizer = wx.BoxSizer(wx.VERTICAL)
        text = wx.StaticText(panel, label="Hello, World!")
        sizer.Add(text)
        panel.SetSizer(sizer)

if __name__ == "__main__":
    app = wx.App()
    frame = HelloWorldFrame(None)
    frame.Show()
    app.MainLoop()

The code above creates a simple window with an text "Hello, World!" at the top-left corner of it as shown as the image below: helloworld

The code below written with PyApplicationFramework is a code which shows the same result:

import wx
from pyappframework.ui import Window
from pyappframework.ui.controls import Panel, StaticText

class HelloWorldWindow(Window):
    def __init__(self, *args, **kw):
        super().__init__(*args, **kw)
        self.SetTitle("HelloWorldWindow")

    def body(self) -> Panel:
        return (
            Panel(wx.BoxSizer(wx.VERTICAL))
                .body [[
                StaticText(label="Hello, World!")
            ]]
        )

if __name__ == "__main__":
    app = wx.App()
    frame = HelloWorldWindow()
    frame.Show()
    app.MainLoop()

As you can see, you can recognize the hierarchical structures of the UI, without using external markup language (like XRC), which is still needed to instantiate every single control defined inside of it.

Mutable Values

Mutations of a variable or an attribute defined by class Mutable[]() can be observed by adding an event handler or synchronized to one or more attributes of the views or controls.

import wx
import pyappframework as pyaf
from pyappframework import ui
from pyappframework.ui import controls as ctl

class MutableWindow(ui.Window):
    def __init__(self, *args, **kw):
        self.textbox_value = pyaf.Mutable[str]("Initial value")
        super().__init__(*args, **kw)
        self.SetTitle("MutableWindow")

    def body(self) -> ctl.Panel:
        return (
            ctl.ScrollablePanel(wx.BoxSizer(wx.VERTICAL))
            .body [[
                ctl.StaticText(label=self.textbox_value)
                    .sizer(wx.SizerFlags().Border(wx.TOP | wx.LEFT)),
                ctl.TextCtrl(value=self.textbox_value)
                    .sizer(proportion=0, flag=wx.EXPAND),
                ctl.SearchCtrl(value=self.textbox_value)
                    .sizer(proportion=0, flag=wx.EXPAND),
            ]]
        )

if __name__ == "__main__":
    app = wx.App()
    frame = MutableWindow()
    frame.Show()
    app.MainLoop()

mutable

Default Controls

  • Button
  • CheckBox
  • Choice
  • CollapsiblePanel
  • Control
  • DataViewCtrl
  • Gauge
  • InfoBar
  • ListBox
  • Notebook
  • Panel
  • Plot
  • ScrollablePanel
  • SearchCtrl
  • SplitterWindow
  • StaticBitmap
  • StaticBox
  • StaticLine
  • StaticText
  • TextCtrl
  • ToolBar
  • TreeCtrl
  • WebView

Controls with Additional Requirements

  • GLCanvas (PyOpenGL)
  • Plot (matplotlib)

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

pyappframework-0.0.dev0.tar.gz (216.1 kB view hashes)

Uploaded Source

Built Distribution

pyappframework-0.0.dev0-py3-none-any.whl (25.4 kB view hashes)

Uploaded Python 3

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