Skip to main content

A simple tool for building UIs

Project description

--DISCLAIMER-- the README below is deprecated. i am rebuilding the project from the ground up as the old project had bad architecture and was very slow.



\

dot-ui

An easy to use yet good-looking UI creation framework for Python

Contents

Basics

Creating a window

Opening a Window is as easy as creating a window object and calling open():

from dot_ui import *

win = Window()

win.open()

Opened Window

In the constructor you can specify the width, height, title, icon and whether the window should be opened in full screen mode.

Adding widgets

Adding a widget is no more compicated. You create the widget and add it to the window. It takes an x and y position as well as a width and height as optional constructor parameters:

from dot_ui import *

win = Window("Demo")

widget = Widget(10, 10)

win.add_widget(widget)

win.open()

Window with widget

Changing renderer settings

Some window and widget properties are universal and are controlled by the renderer. You can customize these settings by calling the corresponding setter on the renderer (DotRenderer by default):

from dot_ui import *

DotRenderer.set_corner_radius(0)
DotRenderer.set_shadow_offset(Vector2(-2, -2))
DotRenderer.set_shadow_radius(10)
DotRenderer.set_default_color(Color.GREEN)
DotRenderer.set_shadow_opacity(1)

win = Window(title="Demo")

widget = Widget(10, 10)

win.add_widget(widget)

win.open()

Changed renderer settings

Adding behaviours

You can add behaviours to widgets that consist of a function that is run on initialization and one that is run every tick. This is some example code that prints "Widget initialized" on initialization and prints the delta time every tick.

from dot_ui import *

win = Window(title="Demo")

def print_init(self: Widget):
    print("Widget initialized")

def print_on_tick(self: Widget, delta):
    print(delta)

widget = Widget(10, 10)

widget.add_behaviour("Print", print_on_tick, print_init)

win.add_widget(widget)

win.open()

Taking inputs

The Input class allows you to create actions that are triggered when one of multiple keys or key combinations is pressed. You can then check if these actions have been triggered. This code will print the delta time when "D" or "0" are pressed and close the widget when Crtl+Q is pressed.

from dot_ui import *

Input.add_action("Print Delta", Key.D, 0)

Input.add_action(
    "Close", 
    KeyCombination(Key.L_CTRL, Key.Q)
)

win = Window(title="Demo")


def input_demo(self: Widget, delta):
    if Input.action_pressed("Print Delta"):
        print(delta)
    
    if Input.action_just_pressed("Close"):
        self.close()


widget = Widget(10, 10)

widget.add_behaviour("Input Demo", input_demo)

win.add_widget(widget)

win.open()

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

widgeon-0.0.2.tar.gz (122.5 kB view hashes)

Uploaded Source

Built Distribution

widgeon-0.0.2-py3-none-any.whl (119.7 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