Toolbar Widgets

ToolbarWidget

class miniworldmaker.containers.widgets.Widget[source]

A Widget which can be placed in the Toolbar.

A widget can have ‘text’ and an ‘image’.

Public Data Attributes:

text_align

Defines how text is aligned.

text_padding_left

Left text_padding

text_padding_top

Top text_padding

text_padding_top_left

Top-left text_padding

img_width

Width of image.

margin_bottom

Margin below widget

margin_top

Margin above widget

margin_left

left margin

margin_right

right margin

height

Widget height

width

Widget width (read only value)

background_color

tuple

dirty

text

The text which is displayed on the widget.

Public Methods:

__init__()

get_local_pos(position)

on_setup()

Overwrite this method if you want to add custom setup-code

on_mouse_left(mouse_pos)

set_background_color(value)

rtype:

Widget

clear()

remove()

Removes the widget from toolbar

set_text(text)

Sets text of widget.

set_image(_img_source)

sets image of widget

set_border([color, width])

sets border of widget

__str__()

Return str(self).

register(method)

Used as decorator e.g.

send_message(text)

Private Methods:

_repaint()

Repaints the widget.


property background_color: tuple

tuple

Type:

rtype

clear()[source]
property dirty
get_local_pos(position)[source]
property height: int

Widget height

Return type:

int

property img_width: float

Width of image. (Height will be autoset by padding-left, padding-top and padding.right)

Return type:

float

property margin_bottom: int

Margin below widget

Return type:

int

property margin_left: int

left margin

Return type:

int

property margin_right: int

right margin

Return type:

int

property margin_top: int

Margin above widget

Return type:

int

on_mouse_left(mouse_pos)[source]
on_setup()[source]

Overwrite this method if you want to add custom setup-code

register(method)[source]

Used as decorator e.g. @register def method…

Return type:

callable

remove()[source]

Removes the widget from toolbar

send_message(text)[source]
set_background_color(value)[source]
Return type:

Widget

set_border(color=(0, 0, 0, 255), width=1)[source]

sets border of widget

Parameters:
  • color (_type_) – _description_

  • width (_type_) – _description_

set_image(_img_source)[source]

sets image of widget

Parameters:

_img_source (str) – path to image or tuple with color

set_text(text)[source]

Sets text of widget.

int and float values are converted to string.

property text: str

The text which is displayed on the widget.

Return type:

str

property text_align

Defines how text is aligned.

If widget has an image, text is aligned left, else it can be set to “left”, “center” or “right”.

property text_padding_left: int

Left text_padding

Return type:

int

property text_padding_top: int

Top text_padding

Return type:

int

property text_padding_top_left: tuple

Top-left text_padding

Return type:

tuple

property width: int

Widget width (read only value)

Return type:

int

ToolbarButton

class miniworldmaker.containers.widgets.Button(text, img_path=None)[source]

A Toolbar Button

The Button can receive events.

If the button is clicked

Parameters:
  • text (str) – _description_

  • img_path (str) – path to an image

Public Data Attributes:

Inherited from : py: class:Widget

text_align

Defines how text is aligned.

text_padding_left

Left text_padding

text_padding_top

Top text_padding

text_padding_top_left

Top-left text_padding

img_width

Width of image.

margin_bottom

Margin below widget

margin_top

Margin above widget

margin_left

left margin

margin_right

right margin

height

Widget height

width

Widget width (read only value)

background_color

tuple

dirty

text

The text which is displayed on the widget.

Public Methods:

__init__(text[, img_path])

on_mouse_left(mouse_pos)

This event is called when the button is clicked -

Inherited from : py: class:Widget

__init__(text[, img_path])

get_local_pos(position)

on_setup()

Overwrite this method if you want to add custom setup-code

on_mouse_left(mouse_pos)

This event is called when the button is clicked -

set_background_color(value)

rtype:

Widget

clear()

remove()

Removes the widget from toolbar

set_text(text)

Sets text of widget.

set_image(_img_source)

sets image of widget

set_border([color, width])

sets border of widget

__str__()

Return str(self).

register(method)

Used as decorator e.g.

send_message(text)

Private Methods:

Inherited from : py: class:Widget

_repaint()

Repaints the widget.


on_mouse_left(mouse_pos)[source]

This event is called when the button is clicked -

By default, a message with the button text is then sent to the board.

Examples

Send a event on button-click:

toolbar = Toolbar()
button = ToolbarButton("Start Rocket")
toolbar.add_widget(button)
board.add_container(toolbar, "right")

@board.register
def on_message(self, message):
    if message == "Start Rocket":
        rocket.started = True

ToolbarLabel

class miniworldmaker.containers.widgets.Label(text, img_path=None)[source]

Public Data Attributes:

Inherited from : py: class:Widget

text_align

Defines how text is aligned.

text_padding_left

Left text_padding

text_padding_top

Top text_padding

text_padding_top_left

Top-left text_padding

img_width

Width of image.

margin_bottom

Margin below widget

margin_top

Margin above widget

margin_left

left margin

margin_right

right margin

height

Widget height

width

Widget width (read only value)

background_color

tuple

dirty

text

The text which is displayed on the widget.

Public Methods:

__init__(text[, img_path])

Inherited from : py: class:Widget

__init__(text[, img_path])

get_local_pos(position)

on_setup()

Overwrite this method if you want to add custom setup-code

on_mouse_left(mouse_pos)

set_background_color(value)

rtype:

Widget

clear()

remove()

Removes the widget from toolbar

set_text(text)

Sets text of widget.

set_image(_img_source)

sets image of widget

set_border([color, width])

sets border of widget

__str__()

Return str(self).

register(method)

Used as decorator e.g.

send_message(text)

Private Methods:

Inherited from : py: class:Widget

_repaint()

Repaints the widget.