Toolbar

Toolbar

class miniworldmaker.containers.toolbar.Toolbar[source]

A Toolbar contains widgets (Buttons, Labels, …)

Public Data Attributes:

first

pagination

background_color

Background color as Tuple, e.g.

margin_left

Defines left margin

margin_right

Defines right margin

margin_top

Defines top margin

Inherited from : py: class:Container

container_width

container_height

window

size

rect

window_docking_position

width

height

Public Methods:

__init__()

Base class for toolbars.

add_widget(widget[, key])

Adds a widget to the toolbar

remove_widget(item)

Removes a widget from the toolbar.

has_widget(key)

Checks if self.widgets has key

get_widget(key)

Gets widget by key

remove_all_widgets()

repaint()

Implemented in subclasses

widget_iterator()

rtype:

list

get_event(event, data)

Implemented in subclasses

get_widget_by_position(pos)

update()

Implemented in subclasses

send_message(text)

Inherited from : py: class:Container

__init__()

Base class for toolbars.

update_width_and_height()

repaint()

Implemented in subclasses

blit_surface_to_window_surface()

remove()

Implemented in subclasses

handle_event(event, data)

get_event(event, data)

Implemented in subclasses

is_in_container(x, y)

rtype:

bool

position_is_in_container(pos)

rtype:

bool

update()

Implemented in subclasses

get_local_position(position)

rtype:

tuple

Private Methods:

_paint_widgets()

_widgets_total_height()

_set_widget_width(widget)

Inherited from : py: class:Container

_add_to_window(app, dock[, size])


__init__()[source]

Base class for toolbars.

Example

Add a Toolbar which interacts with Tokens on board via messages:

from miniworldmaker import *

board = Board()

board.add_background("images/galaxy.jpg")

toolbar = Toolbar()
button = Button("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

rocket = Token(100, 200)
rocket.add_costume("images/ship.png")
rocket.started = False
rocket.turn_left(90)
rocket.direction = "up"

@rocket.register
def act(self):
    if self.started:
            self.move()

@rocket.register
def on_sensing_not_on_board(self):
    self.remove()

board.run()
add_widget(widget, key=None)[source]

Adds a widget to the toolbar

Parameters:
  • widget – The Widget

  • key – A unique key

Returns:

_description_

Return type:

widgets.Widget

Return type:

Widget

property background_color

Background color as Tuple, e.g. (255,255,255) for white

property first
get_event(event, data)[source]

Implemented in subclasses

get_widget(key)[source]

Gets widget by key

Returns:

_description_

Return type:

_type_

Return type:

Widget

get_widget_by_position(pos)[source]
has_widget(key)[source]

Checks if self.widgets has key

Parameters:

key – The key of widget

property margin_left

Defines left margin

property margin_right

Defines right margin

property margin_top

Defines top margin

property pagination
remove_all_widgets()[source]
remove_widget(item)[source]

Removes a widget from the toolbar. Warning: Be careful when calling this method in a loop.

Parameters:

key – The key of widget which should be removed

repaint()[source]

Implemented in subclasses

send_message(text)[source]
update()[source]

Implemented in subclasses

widget_iterator()[source]
Return type:

list