World > Toolbar#
- class miniworlds.worlds.gui.toolbar.Toolbar(*args, **kwargs)[Quellcode]#
Eine Symbolleiste enthält Widgets (Schaltflächen, Beschriftungen, …)
Öffentliche Datenattribute:
Background color as Tuple, e.g. (255,255,255) for white.
Defines left margin
Defines right margin
Defines top margin
Defines bottom margin
Inherited from
GUIactorsevent_managerclockframeappbackgroundslayoutdatamousedrawmusicsoundis_runningInherited from
WorldTick rate defines how often the method
act()will be called.Bilder pro Sekunde auf dem Bildschirm angezeigt.
Gets the horizontal size of the world in pixels.
Gets the vertical size of the world in pixels.
Gets the number of horizontal pixels (columns) visible in the world.
Gets the number of vertical pixels (rows) visible in the world.
Gets the world size as a tuple (width, height), in pixels.
Returns the currently active background.
Returns True if the world has at least one background appearance.
event_managerclockframeappbackgroundslayoutdatamousedrawsoundis_runningInherited from
WorldBasewindowsizetopleftwidthheightclass_nameregistered_eventsReturns the set of all event names that are currently registered.
is_runningevent_managerÖffentliche Methoden:
__init__()Base class for toolbars.
implemented in subclasses
remove(item)Removes a widget from the toolbar.
has_widget(key)Checks if self.widgets has key
get_widget(key)Gets widget by key
reorder()send_message(text)Sends a broadcast message to the world and all actors.
scroll_up(value)scroll_down(value)can_scroll_down(value)can_scroll_up(value)on_new_actor(actor)on_remove_actor(actor)Inherited from
GUIadd(actor)Inherited from
World__init__([x, y])Initializes the class and manages actor sprites.
contains_position(pos)Checks if position is in the world.
contains_rect(rect)Returns True if the entire rectangle is fully inside the world.
contains_rect_any(rect)Returns True if any part of the rectangle is inside the world.
set_columns(value)Internal method to set columns and sync world width.
set_rows(value)Internal method to set rows and sync world height.
Returns the current active background from the backgrounds manager.
switch_background(background)Switches the current background to a specified one.
remove_background([background])Removes a background from the world.
set_background(source)Sets a new background and replaces the current active background.
add_background(source)Adds a new background to the world and sets it as the active one.
start()Starts or resumes the world.
stop([frames])Stops the world immediately or after a delay in frames.
run([fullscreen, fit_desktop, replit, ...])Starts the main application loop of the Miniworlds engine.
is_in_world(position)Checks whether a given world position lies within the world's boundaries.
send_message(message[, data])Sends a broadcast message to the world and all actors.
quit([exit_code])Immediately quits the application and closes the game window.
reset()Resets the world Creates a new world with init-function - recreates all actors and actors on the world.
get_from_pixel(position)Converts a screen pixel position into a valid world position if inside bounds.
to_pixel(position)Converts a world position to a screen pixel position.
on_setup()Hook method to define initial setup logic when the world is created.
detect_actors(position)Gets all actors which are found at a specific position (in global world coordinates)
get_actors_from_pixel(pixel)Returns a list of all actors located at the given screen pixel position.
distance_to(pos1, pos2)Calculates the Euclidean distance between two positions.
direction_to(pos1, pos2)Calculates the angle from pos1 to pos2 in degrees.
Inherited from
WorldBase__init__()remove(actor)Implemented in subclasses
on_change()implemented in subclasses
on_new_actor(actor)on_remove_actor(actor)get_world_connector(actor)screenshot([filename])Saves a screenshot of the current window surface to a file.
get_events()Prints a list of all events that can be registered in this world.
register(method)Registers a method as a world event handler.
Private Data Attributes:
_abc_impl_fps_tick_rate_timed_objects_dynamic_actors_registered_methods_mainloop_collision_manager_default_start_runningInherited from
GUI_abc_impl_fps_tick_rate_timed_objects_dynamic_actors_registered_methods_mainloop_collision_manager_default_start_runningInherited from
World_abc_impl_fps_tick_rate_timed_objects_dynamic_actors_registered_methods_mainloop_collision_manager_default_start_runningInherited from
WorldBase_abc_impl_default_start_runningPrivate Methoden:
_get_mainloopmanager_class()_add_widget(widget[, key])_widgets_total_height()_set_widget_width(widget)Inherited from
GUI_get_world_connector_class()needed by get_world_connector in parent class
Inherited from
World_validate_parameters(x, y)_clear()Clears the world's state: event queue, all backgrounds, and all actors.
Inherited from
WorldBase_after_init_setup()_get_mainloopmanager_class()_get_camera_manager_class()_get_world_connector_class()needed by get_world_connector in parent class
_create_event_manager()_unregister(method)Unregisters a previously registered world method.
_start_listening()Enables input listening for the world.
_stop_listening()Disables input listening for the world.
- __init__()[Quellcode]#
Base class for toolbars.
Example
Fügen Sie eine Toolbar hinzu, die über Nachrichten mit Actors in der Welt interagiert:
from miniworlds import * world = World() world.add_background("images/galaxy.jpg") toolbar = Toolbar() button = Button("Start Rocket") toolbar.add(button) world.add_container.add_right(toolbar) @world.register def on_message(self, message): if message == "Start Rocket": rocket.started = True rocket = Actor(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_the_world(self): self.remove() world.run()
- actors: pygame.sprite.LayeredDirty#
- app: app.App#
- property background_color#
Hintergrundfarbe als Tupel, z.B. (255,255,255) für Weiß
- backgrounds: backgrounds_manager.BackgroundsManager#
- can_scroll_down(value)[Quellcode]#
- Parameter:
value (_type_) – beschreibung
- Rückgabe:
beschreibung
- Rückgabetyp:
_type_
- can_scroll_up(value)[Quellcode]#
- clock: pygame.time.Clock#
- data: data_manager.DataManager#
- draw: draw_manager.DrawManager#
- event_manager: event_manager.EventManager#
- frame: int#
- get_widget(key)[Quellcode]#
Gets widget by key
- Rückgabetyp:
BaseWidget- Rückgabe:
beschreibung
- Rückgabetyp:
_type_
- has_widget(key)[Quellcode]#
Checks if self.widgets has key
- Parameter:
key – Der Schlüssel des Widgets
- is_running: bool#
- layout: layout_manager.Layoutmanager#
- mouse: mouse_manager.MouseManager#
- music: world_music_manager.MusicManager#
- on_change()[Quellcode]#
implemented in subclasses
on_change() is called, after world is added to window, resized, …
- on_new_actor(actor)[Quellcode]#
- on_remove_actor(actor)[Quellcode]#
- property padding_bottom#
Defines bottom margin
- property padding_left#
Defines left margin
- property padding_right#
Defines right margin
- property padding_top#
Defines top margin
- remove(item)[Quellcode]#
Entfernt ein Widget aus der Toolbar. Warnung: Seien Sie vorsichtig, wenn Sie diese Methode in einer Schleife aufrufen.
- Parameter:
key – Der Schlüssel des Widgets, das entfernt werden soll
- remove_all_widgets()[Quellcode]#
- reorder()[Quellcode]#
- scroll_down(value)[Quellcode]#
- scroll_up(value)[Quellcode]#
- send_message(text)[Quellcode]#
Sends a broadcast message to the world and all actors.
The message is dispatched through the event system and can be handled by any registered method in the world or its actors.
- Parameter:
message – The name of the message/event to send.
data – Optional additional data to pass with the message.
Example
>>> world.send_message("explode", {"power": 10})
- sound: world_sound_manager.SoundManager#
- update_width_and_height()[Quellcode]#
- widgets: OrderedDict['widget_base.BaseWidget']#