tymber — GUI toolkit

Binaries: https://github.com/thomasfuhringer/tymber/bin

Source code: https://github.com/thomasfuhringer/tymber


Hello World

This simple program displays a window with a button that has a callback to close it.

import tymber as ty

def button__on_click(button):
    button.parent.close()

app = ty.Application(ty.Window("Tymber", width=360, height=280))
label = ty.Label(app.window, "label", 20, 60, -20, 22, "Hello World!")
label.align_h = ty.Align.center
button = ty.Button(app.window, "button", -70, -40, 50, 20, "Close")
button.on_click = button__on_click
app.run()

Module Functions and Constants

tymber.message(message[, title])

Shows a message box displaying the string message, using the string title as window title.

tymber.set_setting(key1, key2, subkey, value)

Stores the byte object value as a configuration setting.

tymber.get_setting(key1, key2, subkey)

Retrieves the object stored using set_setting.

tymber.play_sound([filename])

Plays the .wav file in filename or the default chime.

tymber.joystick_status([stick_no])

Gets the status of joystick stick_no and returns a tuple (xpos, ypos, zpos, rpos, upos, button1, button2, button3, button4).

tymber.app

Singleton instance of Application class.

tymber.default_coordinate

Value to assign to top or left coordinate of Window to show it using MS Windows’ default positioning.

tymber.center

Value to assign to top or left coordinate of Window to show it centered.

tymber.version_info

The version number as a tuple of integers.

tymber.copyright

Copyright notice.

Enumerations

tymber.Align

Enum for alignment of text in widgets, possible values: left, right, center, top, bottom, block

tymber.StockIcon

Enum icons included: file_open, file_new, save, ok, no, window, find

tymber.Key

Enum keyboad keys: enter, tab, escape, delete, space, left, right, up, down, f1

Classes

Application

class tymber.Application(window)

The app singleton. Only one instance can be created and it is globally available as tymber.app.

Attributes and methods

window

Main Window

run()

Call run on window.

Window

class tymber.Window([caption, left, top, width, height, visible])

A GUI window which serves as a canvas to hold Widget objects.

Attributes and methods

caption

A str to appear as the Windows’s title.

left

Distance from left edge of desktop, if negative from right. Default: tymber.default_coordinate

top

Distance from top edge of desktop, if negative from bottom

width

Width or, if zero or negative, distance of right edge from right edge of desktop

height
Height or, if zero or negative, distance of bottom edge from bottom edge of desktop
visible

By default True.

children

A Dict of Widgets contained.

position

A tuple with the (x, y) position of the widget on the screen.

size

A tuple with the (width, height) of the widget on the screen.

icon

Icon

tool_bar

ToolBar

status_bar

StatusBar

before_close

Callback. If it returns False the window will stay open.

on_close

Callback when closing.

focus

Widget holding the focus.

on_focus_change

Callback when focus was moved to new widget.

min_width

Minimum width

min_height
Minimum height
run()

Show as dialog (modal).

close()

Hide the window and, if run modal, return from run. (Does not destroy it).

set_timer(callback[, interval, wait])

Sets a timer to fire after wait seconds every interval seconds.

del_timer()

Deletes the timer.

key_pressed(key)

Returns True if key is pressed.

Widget

class tymber.Widget(parent, key[, left, top, width, height, caption, data_type, format, visible])

Widget is the base class from which all data aware widgets that can be displayed on a Window are derived.

The construtor parameters are also available as attributes:

parent

Can be a Window, MdiWindow or Widget that holds the widget.

key

The string that is used to reference the widget in the parent’s children dict.

left

Distance from left edge of parent, if negative from right.

top

Distance from top edge of parent, if negative from bottom

width

Width or, if zero or negative, distance of right edge from right edge of parent

height

Height or, if zero or negative, distance of bottom edge from bottom edge of parent

caption

Text used e.g. for Label or Entry

data_type

The Python data type the widget can hold.

format

The Python format string in the str.format() syntax that is used to render the data.

visible

By default True

enabled

If False widget is grayed.

Label

class tymber.Label

Shows boilerplate text on the Window.

align_h

Enum Align of horizontal text alignment.

align_v

Enum Align of vertical text alignment.

text_color

A tuple of RGB integers.

Entry

class tymber.Entry

Single line data entry. After leaving the widget, the entered text is parsed and converted into a value of data_type and available as data.

Attributes and methods

data

The value the Entry holds.

read_only

Editing not possible.

password

Characters are not legible.

input_data

The currently entered input converted to the Entry’s data type, but not yet committed to data, for validation purposes.

input_string

The currently entered input string, but not yet committed to data, for validation purposes.

align_horiz

Horizontal alignment. By default tymber.Align.left for data type str and tymber.Align.right for numeric data types

on_key

Callback when key is pressed

on_leave

Callback, return True if ready for focus to move on.

multiline

Characters are not legible.

ComboBox

class tymber.ComboBox

ComboBox which allows selection from a drop down list of data values.

append(value[, key])

Appends o tuple of (value, key) to the list of available items. key is displayed in the widget, value returned as data If key is not given, value will be assumed.

Button

class tymber.Button

Push button to trigger a callback.

on_click

If a callable is assigned here it is called when the button is clicked.

Tab

class tymber.Tab

A tabbed notebook container. Holds TabPage objects.

TabPage

class tymber.TabPage(parent)

Page in a Tab Widget. parent in contructor must be the Tab object.

Box

class tymber.Box

Container that can hold other Widgets.

A Splitter object holds two Box Widgets.

children

A Dict of Widgets contained.

Splitter

class tymber.Splitter

A widget with two adjustable panes. Each one is a Box object.

box1

Box object on the left or top.

box2

Box object on the right or bottom.

vertical

If True panes are arranged top/bottom.

position

Position of the separator, if negative from left or bottom

spacing

Width of the separator

Canvas

class tymber.Canvas

A widget for basic drawing. It sports two buffers (index 0 and 1). By default buffer 0 is active and live.

set_pen([red, green, blue, alpha, width])

Color and thickness to be used for drawing and filling. Default: (0, 0, 0, 255, 1)

point(x, y)

Draws a point at the given coordinates.

line(x1, y1, x2, y2)

Draws a line from x1, y1 to x2, y2

rectangle(x, y, width, height[, fill])

Draws a rectangle.

polygon(points[, fill])

Draws a polygon from list of [x,y] coordinates in points.

ellipse(x, y, width, height[, fill])

Draws an ellipse.

text(x, y, x2, y2, string)

Writes string into the given rectangle.

image(x, y, data[, width, height])

Puts an image at the given position. If width or height is given, the image will be scaled retaining aspect ratio. data is to be either a ‘str’ holding file name or ‘bytes’ holding the data in memory.

resize_buffer([index, width, height, x, y])

Changes the size of the buffer. If index is not given active_buffer will be used. If width and height are not given the canvas’ are applied. If given the current content will be moved to x and y.

copy_buffer(index1, index1)

Copy the content of buffer 1 to 2.

clear_buffer([index])

Clears the buffer. If index is not given, the active_buffer will be used.

renew_buffer([index, width, height])

Creates a new buffer. If index is not given active_buffer will be used. If width and height are not given the canvas’ are applied.

refresh()

Triggers the paint process.

on_resize

Callback when the widget gets resized. Parameters: widget

active_buffer

Index of the buffer to be used for drawing operations. Default: 0

live_buffer

Index of the buffer to be displayed when the OS refreshes the screen. Default: 0

on_mouse_move

Callback when the mouse is moved. Parameters: widget, x, y

on_mouse_wheel

Callback when the left mouse wheel was turned. Parameters: widget, delta, x, y

on_l_button_down

Callback when the left mouse button is pressed. Parameters: widget, x, y

on_l_button_up

Callback when the left mouse button is released. Parameters: widget, x, y

anti_alias

Drawing operations should be done in a callback which is assigned here.

ToolBar

class tymber.ToolBar(window)

Tool bar attached to window.

children

A Dict of items contained.

append_item(item)

item must be a MenuItem

append_separator()

Adds a separator line

set_enabled(item, enabled)

item must be a MenuItem. If enabled is False the button is grayed.

Icon

class tymber.Icon(source)

An icon to be used in MenuItem, Toolbar and Window objects.

source must be a ‘str’ of the file name or ‘bytes’ holding the data.

StatusBar

class tymber.StatusBar(window[, borders])

Status bar attached to window. borders is a List of ‘int’ defining the lengths of parts if more than one are to be used.

set_text(text[, part])

part is an int.

set_text(part)

ImageView

class tymber.ImageView

Displays a bitmap. data must be a ‘str’ of the file name or ‘bytes’ holding the data. If stretch is True it will be stretched keeping aspect ratio.

ListView

class tymber.ListView

Displays a list of data in a table.

data

List that holds the data

columns

List of Lists that define the columns. Format: [caption, data_type, width, data_format] if width is None the the column is hidden.

row

Index of row currently selected, or None.

on_selection_changed

Callback when a row was selected. Parameters: widget

on_double_click

Callback when a row was double clicked. Parameters: widget, index

add_row(data[, index])

Adds a row with data after index . If index is not given row will be used. In case row is None the new row will be appended.

update_row(data[, index])

Replaces the row with data. If index is not given row will be used.

delete_row(index)

Removes the row at index.

FileSelector

class tymber.FileSelector(caption[, path])

File selection dialog. path is the initial path.

run()

Show it modal. Returns the file name if selected or None.

MdiArea

class tymber.MdiArea

Can hold MdiWindow objects.

tile()

Arrange child windows in tile format.

active_child

Child window that has the focus

on_activated

Callback when new child was activated

maximized

Child windows are shown maximized

menu

Menu to hold windows

MdiWindow

class tymber.MdiWindow

A window to be displayed inside an MdiArea

parent

MdiArea that holds the MdiWindow

close()

Remove the window from the parent’s children collection (and consequently destroy it).