Window and View#

class arcade.NoOpenGLException[source]#

Bases: Exception

Exception when we can’t get an OpenGL 3.3+ context

class arcade.View(window: Window | None = None)[source]#

Bases:

Support different views/screens in a window.

add_section(section, at_index: int | None = None, at_draw_order: int | None = None) None[source]#

Adds a section to the view Section Manager.

Parameters:
  • section – the section to add to this section manager

  • at_index – inserts the section at that index for event capture and update events. If None at the end

  • at_draw_order – inserts the section in a specific draw order. Overwrites section.draw_order

clear(color: Tuple[int, int, int] | Tuple[int, int, int, int] | None = None, color_normalized: Tuple[float, float, float, float] | None = None, viewport: Tuple[int, int, int, int] | None = None)[source]#

Clears the window with the configured background color set through arcade.Window.background_color.

Parameters:
  • color

    (Optional) override the current background color with one of the following:

    1. A Color instance

    2. A 3 or 4-length RGB/RGBA tuple of byte values (0 to 255)

  • color_normalized – (Optional) override the current background color using normalized values (0.0 to 1.0). For example, (1.0, 0.0, 0.0, 1.0) making the window contents red.

  • viewport (Tuple[int, int, int, int]) – The viewport range to clear

on_draw()[source]#

Called when this view should draw

on_hide_view()[source]#

Called once when this view is hidden.

on_key_press(symbol: int, modifiers: int)[source]#

Override this function to add key press functionality.

Parameters:
  • symbol – Key that was hit

  • modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_key_release(_symbol: int, _modifiers: int)[source]#

Override this function to add key release functionality.

Parameters:
  • _symbol – Key that was hit

  • _modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_drag(x: int, y: int, dx: int, dy: int, _buttons: int, _modifiers: int)[source]#

Override this function to add mouse button functionality.

Parameters:
  • x – x position of mouse

  • y – y position of mouse

  • dx – Change in x since the last time this method was called

  • dy – Change in y since the last time this method was called

  • _buttons – Which button is pressed

  • _modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_enter(x: int, y: int)[source]#

Called when the mouse was moved into the window. This event will not be triggered if the mouse is currently being dragged.

Parameters:
  • x – x position of mouse

  • y – y position of mouse

on_mouse_leave(x: int, y: int)[source]#

Called when the mouse was moved outside of the window. This event will not be triggered if the mouse is currently being dragged. Note that the coordinates of the mouse pointer will be outside of the window rectangle.

Parameters:
  • x – x position of mouse

  • y – y position of mouse

on_mouse_motion(x: int, y: int, dx: int, dy: int)[source]#

Override this function to add mouse functionality.

Parameters:
  • x – x position of mouse

  • y – y position of mouse

  • dx – Change in x since the last time this method was called

  • dy – Change in y since the last time this method was called

on_mouse_press(x: int, y: int, button: int, modifiers: int)[source]#

Override this function to add mouse button functionality.

Parameters:
  • x – x position of the mouse

  • y – y position of the mouse

  • button – What button was hit. One of: arcade.MOUSE_BUTTON_LEFT, arcade.MOUSE_BUTTON_RIGHT, arcade.MOUSE_BUTTON_MIDDLE

  • modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_release(x: int, y: int, button: int, modifiers: int)[source]#

Override this function to add mouse button functionality.

Parameters:
  • x – x position of mouse

  • y – y position of mouse

  • button – What button was hit. One of: arcade.MOUSE_BUTTON_LEFT, arcade.MOUSE_BUTTON_RIGHT, arcade.MOUSE_BUTTON_MIDDLE

  • modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_scroll(x: int, y: int, scroll_x: int, scroll_y: int)[source]#

User moves the scroll wheel.

Parameters:
  • x – x position of mouse

  • y – y position of mouse

  • scroll_x – ammout of x pixels scrolled since last call

  • scroll_y – ammout of y pixels scrolled since last call

on_resize(width: int, height: int)[source]#

Called when the window is resized while this view is active. on_resize() is also called separately. By default this method does nothing and can be overridden to handle resize logic.

on_show()[source]#

Deprecated. Use on_show_view() instead.

on_show_view()[source]#

Called once when the view is shown.

See also

on_hide_view()

on_update(delta_time: float)[source]#

To be overridden

has_sections#

Return if the View has sections

section_manager#

lazy instantiation of the section manager

class arcade.Window(width: int = 800, height: int = 600, title: str | None = 'Arcade Window', fullscreen: bool = False, resizable: bool = False, update_rate: float = 0.016666666666666666, antialiasing: bool = True, gl_version: Tuple[int, int] = (3, 3), screen: Screen | None = None, style: str | None = None, visible: bool = True, vsync: bool = False, gc_mode: str = 'context_gc', center_window: bool = False, samples: int = 4, enable_polling: bool = True, gl_api: str = 'gl', draw_rate: float = 0.016666666666666666)[source]#

Bases: BaseWindow

The Window class forms the basis of most advanced games that use Arcade. It represents a window on the screen, and manages events.

Parameters:
  • width – Window width

  • height – Window height

  • title – Title (appears in title bar)

  • fullscreen – Should this be full screen?

  • resizable – Can the user resize the window?

  • update_rate – How frequently to run the on_update event.

  • draw_rate – How frequently to run the on_draw event. (this is the FPS limit)

  • antialiasing – Should OpenGL’s anti-aliasing be enabled?

  • gl_version – What OpenGL version to request. This is (3, 3) by default and can be overridden when using more advanced OpenGL features.

  • screen – Pass a pyglet Screen to request the window be placed on it. See pyglet’s window size & position guide to learn more.

  • style – Request a non-default window style, such as borderless. Some styles only work in certain situations. See pyglet’s guide to window style to learn more.

  • visible – Should the window be visible immediately

  • vsync – Wait for vertical screen refresh before swapping buffer This can make animations and movement look smoother.

  • gc_mode – Decides how OpenGL objects should be garbage collected (“context_gc” (default) or “auto”)

  • center_window – If true, will center the window.

  • samples – Number of samples used in antialiasing (default 4). Usually this is 2, 4, 8 or 16.

  • enable_polling – Enabled input polling capability. This makes the keyboard and mouse attributes available for use.

activate()[source]#

Activate this window.

center_window() None[source]#

Center the window on the screen.

clear(color: Tuple[int, int, int] | Tuple[int, int, int, int] | None = None, color_normalized: Tuple[float, float, float, float] | None = None, viewport: Tuple[int, int, int, int] | None = None)[source]#

Clears the window with the configured background color set through arcade.Window.background_color.

Parameters:
  • color

    (Optional) override the current background color with one of the following:

    1. A Color instance

    2. A 3 or 4-length RGB/RGBA tuple of byte values (0 to 255)

  • color_normalized – (Optional) override the current background color using normalized values (0.0 to 1.0). For example, (1.0, 0.0, 0.0, 1.0) making the window contents red.

  • viewport (Tuple[int, int, int, int]) – The viewport range to clear

close()[source]#

Close the Window.

dispatch_events()[source]#

Dispatch events

flip()[source]#

Window framebuffers normally have a back and front buffer. This method makes the back buffer visible and hides the front buffer. A frame is rendered into the back buffer, so this method displays the frame we currently worked on.

This method also garbage collect OpenGL resources before swapping the buffers.

get_location() Tuple[int, int][source]#

Return the X/Y coordinates of the window

Returns:

x, y of window location

get_size() Tuple[int, int][source]#

Get the size of the window.

Returns:

(width, height)

get_system_mouse_cursor(name)[source]#

Get the system mouse cursor

hide_view()[source]#

Hide the currently active view (if any) returning us back to on_draw and on_update functions in the window.

This is not necessary to call if you are switching views. Simply call show_view again.

maximize()[source]#

Maximize the window.

minimize()[source]#

Minimize the window.

on_draw()[source]#

Override this function to add your custom drawing code.

on_key_press(symbol: int, modifiers: int)[source]#

Called once when a key gets pushed down.

Override this function to add key press functionality.

Tip

If you want the length of key presses to affect gameplay, you also need to override on_key_release().

Parameters:
  • symbol – Key that was just pushed down

  • modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_key_release(symbol: int, modifiers: int)[source]#

Called once when a key gets released.

Override this function to add key release functionality.

Situations that require handling key releases include:

  • Rhythm games where a note must be held for a certain amount of time

  • ‘Charging up’ actions that change strength depending on how long a key was pressed

  • Showing which keys are currently pressed down

Parameters:
  • symbol – Key that was just released

  • modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_drag(x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int)[source]#

Called repeatedly while the mouse moves with a button down.

Override this function to handle dragging.

Parameters:
  • x – x position of mouse

  • y – y position of mouse

  • dx – Change in x since the last time this method was called

  • dy – Change in y since the last time this method was called

  • buttons – Which button is pressed

  • modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_enter(x: int, y: int)[source]#

Called once whenever the mouse enters the window area on screen.

This event will not be triggered if the mouse is currently being dragged.

Parameters:
  • x

  • y

on_mouse_leave(x: int, y: int)[source]#

Called once whenever the mouse leaves the window area on screen.

This event will not be triggered if the mouse is currently being dragged. Note that the coordinates of the mouse pointer will be outside of the window rectangle.

Parameters:
  • x

  • y

on_mouse_motion(x: int, y: int, dx: int, dy: int)[source]#

Called repeatedly while the mouse is moving over the window.

Override this function to respond to changes in mouse position.

Parameters:
  • x – x position of mouse within the window in pixels

  • y – y position of mouse within the window in pixels

  • dx – Change in x since the last time this method was called

  • dy – Change in y since the last time this method was called

on_mouse_press(x: int, y: int, button: int, modifiers: int)[source]#

Called once whenever a mouse button gets pressed down.

Override this function to handle mouse clicks. For an example of how to do this, see arcade’s built-in aiming and shooting bullets demo.

Parameters:
  • x – x position of the mouse

  • y – y position of the mouse

  • button

    What button was pressed. This will always be one of the following:

    • arcade.MOUSE_BUTTON_LEFT

    • arcade.MOUSE_BUTTON_RIGHT

    • arcade.MOUSE_BUTTON_MIDDLE

  • modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_release(x: int, y: int, button: int, modifiers: int)[source]#

Called once whenever a mouse button gets released.

Override this function to respond to mouse button releases. This may be useful when you want to use the duration of a mouse click to affect gameplay.

Parameters:
  • x – x position of mouse

  • y – y position of mouse

  • button – What button was hit. One of: arcade.MOUSE_BUTTON_LEFT, arcade.MOUSE_BUTTON_RIGHT, arcade.MOUSE_BUTTON_MIDDLE

  • modifiers – Bitwise ‘and’ of all modifiers (shift, ctrl, num lock) active during this event. See Modifiers.

on_mouse_scroll(x: int, y: int, scroll_x: int, scroll_y: int)[source]#

Called repeatedly while a mouse scroll wheel moves.

Override this function to respond to scroll events. The scroll arguments may be positive or negative to indicate direction, but the units are unstandardized. How many scroll steps you receive may vary wildly between computers depending a number of factors, including system settings and the input devices used (i.e. mouse scrollwheel, touchpad, etc).

Warning

Not all users can scroll easily!

Only some input devices support horizontal scrolling. Standard vertical scrolling is common, but some laptop touchpads are hard to use.

This means you should be careful about how you use scrolling. Consider making it optional to maximize the number of people who can play your game!

Parameters:
  • x – x position of mouse

  • y – y position of mouse

  • scroll_x – number of steps scrolled horizontally since the last call of this function

  • scroll_y – number of steps scrolled vertically since the last call of this function

on_resize(width: int, height: int)[source]#

Override this function to add custom code to be called any time the window is resized. The main responsibility of this method is updating the projection and the viewport.

If you are not changing the default behavior when overriding, make sure you call the parent’s on_resize first:

def on_resize(self, width: int, height: int):
    super().on_resize(width, height)
    # Add extra resize logic here
Parameters:
  • width – New width

  • height – New height

on_update(delta_time: float)[source]#

Move everything. Perform collision checks. Do all the game logic here.

Parameters:

delta_time – Time interval since the last time the function was called.

run() None[source]#

Run the main loop. After the window has been set up, and the event hooks are in place, this is usually one of the last commands on the main program. This is a blocking function starting pyglet’s event loop meaning it will start to dispatch events such as on_draw and on_update.

set_caption(caption)[source]#

Set the caption for the window.

set_draw_rate(rate: float)[source]#

Set how often the on_draw function should be run. For example, set.set_draw_rate(1 / 60) will set the draw rate to 60 frames per second.

set_exclusive_keyboard(exclusive=True)[source]#

Capture all keyboard input.

set_exclusive_mouse(exclusive=True)[source]#

Capture the mouse.

set_fullscreen(fullscreen: bool = True, screen: Window | None = None, mode: ScreenMode | None = None, width: float | None = None, height: float | None = None)[source]#

Set if we are full screen or not.

Parameters:
  • fullscreen

  • screen – Which screen should we display on? See get_screens()

  • mode – The screen will be switched to the given mode. The mode must have been obtained by enumerating Screen.get_modes. If None, an appropriate mode will be selected from the given width and height.

  • width

  • height

set_location(x, y)[source]#

Set location of the window.

set_max_size(width: int, height: int)[source]#

Wrap the Pyglet window call to set maximum size

Parameters:
  • width – width in pixels.

  • height – height in pixels.

Raises ValueError:

set_maximum_size(width, height)[source]#

Set largest window size.

set_min_size(width: int, height: int)[source]#

Wrap the Pyglet window call to set minimum size

Parameters:
  • width – width in pixels.

  • height – height in pixels.

set_minimum_size(width: int, height: int)[source]#

Set smallest window size.

set_mouse_platform_visible(platform_visible=None)[source]#

Warning

You are probably looking for set_mouse_visible()!

This method was implemented to prevent PyCharm from displaying linter warnings. Most users will never need to set platform-specific visibility as the defaults from pyglet will usually handle their needs automatically.

For more information on what this means, see the documentation for pyglet.window.Window.set_mouse_platform_visible().

set_mouse_visible(visible: bool = True)[source]#

Set whether to show the system’s cursor while over the window

By default, the system mouse cursor is visible whenever the mouse is over the window. To hide the cursor, pass False to this function. Pass True to make the cursor visible again.

The window will continue receiving mouse events while the cursor is hidden, including movements and clicks. This means that functions like on_mouse_motion() and t’on_mouse_press() will continue to work normally.

You can use this behavior to visually replace the system mouse cursor with whatever you want. One example is a game character that is always at the most recent mouse position in the window.

Note

Advanced users can try using system cursor state icons

It may be possible to use system icons representing cursor interaction states such as hourglasses or resize arrows by using features arcade.Window inherits from the underlying pyglet window class. See the pyglet overview on cursors for more information.

Parameters:

visible – Whether to hide the system mouse cursor

set_size(width: int, height: int)[source]#

Ignore the resizable flag and set the size

Parameters:
  • width

  • height

set_update_rate(rate: float)[source]#

Set how often the on_update function should be dispatched. For example, self.set_update_rate(1 / 60) will set the update rate to 60 times per second.

Parameters:

rate – Update frequency in seconds

set_visible(visible: bool = True)[source]#

Set if the window is visible or not. Normally, a program’s window is visible.

Parameters:

visible

set_vsync(vsync: bool)[source]#

Set if we sync our draws to the monitors vertical sync rate.

show_view(new_view: View)[source]#

Select the view to show in the next frame. This is not a blocking call showing the view. Your code will continue to run after this call and the view will appear in the next dispatch of on_update/on_draw`.

Calling this function is the same as setting the arcade.Window.current_view attribute.

Parameters:

new_view – View to show

switch_to()[source]#

Switch the this window.

test(frames: int = 10)[source]#

Used by unit test cases. Runs the event loop a few times and stops.

Parameters:

frames

use()[source]#

Bind the window’s framebuffer for rendering commands

background_color#

Get or set the background color for this window. This affects what color the window will contain when clear() is called.

Examples:

# Use Arcade's built in Color values
window.background_color = arcade.color.AMAZON

# Set the background color with a custom Color instance
MY_RED = arcade.types.Color(255, 0, 0)
window.background_color = MY_RED

# Set the background color directly from an RGBA tuple
window.background_color = 255, 0, 0, 255

# (Discouraged)
# Set the background color directly from an RGB tuple
# RGB tuples will assume 255 as the opacity / alpha value
window.background_color = 255, 0, 0
Type:

Color

center#

Returns the coordinates of the center of the window.

center_x#

Returns the X-coordinate of the center of the window.

center_y#

Returns the Y-coordinate of the center of the window.

ctx#

The OpenGL context for this window.

Type:

arcade.ArcadeContext

current_view#

This property returns the current view being shown. To set a different view, call the arcade.Window.show_view() method.

default_camera#

Provides a reference to the default arcade camera. Automatically sets projection and view to the size of the screen. Good for resetting the screen.

headless#

If this is a headless window

Type:

bool

arcade.get_screens() List[source]#

Return a list of screens. So for a two-monitor setup, this should return a list of two screens. Can be used with arcade.Window to select which window we full-screen on.

Returns:

List of screens, one for each monitor.

arcade.open_window(width: int, height: int, window_title: str | None = None, resizable: bool = False, antialiasing: bool = True) Window[source]#

This function opens a window. For ease-of-use we assume there will only be one window, and the programmer does not need to keep a handle to the window. This isn’t the best architecture, because the window handle is stored in a global, but it makes things easier for programmers if they don’t have to track a window pointer.

Parameters:
  • width – Width of the window.

  • height – Height of the window.

  • window_title – Title of the window.

  • resizable – Whether the user can resize the window.

  • antialiasing – Smooth the graphics?

Returns:

Handle to window

arcade.close_window() None[source]#

Closes the current window, and then runs garbage collection. The garbage collection is necessary to prevent crashing when opening/closing windows rapidly (usually during unit tests).

arcade.exit() None[source]#

Exits the application.

arcade.finish_render()[source]#

Swap buffers and displays what has been drawn.

Warning

If you are extending the Window class, this function should not be called. The event loop will automatically swap the window framebuffer for you after on_draw.

arcade.get_display_size(screen_id: int = 0) Tuple[int, int][source]#

Return the width and height of a monitor.

The size of the primary monitor is returned by default.

Parameters:

screen_id – The screen number

Returns:

Tuple containing the width and height of the screen

arcade.get_window() Window[source]#

Return a handle to the current window.

Returns:

Handle to the current window.

arcade.run()[source]#

Run the main loop. After the window has been set up, and the event hooks are in place, this is usually one of the last commands on the main program. This is a blocking function starting pyglet’s event loop meaning it will start to dispatch events such as on_draw and on_update.

arcade.schedule(function_pointer: Callable, interval: float)[source]#

Schedule a function to be automatically called every interval seconds. The function/callable needs to take a delta time argument similar to on_update. This is a float representing the number of seconds since it was scheduled or called.

A function can be scheduled multiple times, but this is not recommended.

Warning

Scheduled functions should always be unscheduled using arcade.unschedule(). Having lingering scheduled functions will lead to crashes.

Example:

def some_action(delta_time):
    print(delta_time)

# Call the function every second
arcade.schedule(some_action, 1)
# Unschedule
Parameters:
  • function_pointer – Pointer to the function to be called.

  • interval – Interval to call the function (float or integer)

arcade.schedule_once(function_pointer: Callable, delay: float)[source]#

Schedule a function to be automatically called once after delay seconds. The function/callable needs to take a delta time argument similar to on_update. This is a float representing the number of seconds since it was scheduled or called.

Example:

def some_action(delta_time):
    print(delta_time)

# Call the function once after 1 second
arcade.schedule_one(some_action, 1)
Parameters:
  • function_pointer – Pointer to the function to be called.

  • delay – Delay in seconds

arcade.set_background_color(color: Tuple[int, int, int, int]) None[source]#

Set the color arcade.Window.clear() will use when clearing the window. This only needs to be called when the background color changes.

Note

A shorter and faster way to set background color is using arcade.Window.background_color.

Examples:

# Use Arcade's built in color values
arcade.set_background_color(arcade.color.AMAZON)

# Specify RGB value directly (red)
arcade.set_background_color((255, 0, 0))
Parameters:

RGBA255 – List of 3 or 4 values in RGB/RGBA format.

arcade.set_window(window: 'Window' | None) None[source]#

Set a handle to the current window.

Parameters:

window – Handle to the current window.

arcade.start_render() None[source]#

Clears the window.

More practical alternatives to this function is arcade.Window.clear() or arcade.View.clear().

arcade.unschedule(function_pointer: Callable)[source]#

Unschedule a function being automatically called.

Example:

def some_action(delta_time):
    print(delta_time)

arcade.schedule(some_action, 1)
arcade.unschedule(some_action)
Parameters:

function_pointer – Pointer to the function to be unscheduled.

class arcade.Section(left: int, bottom: int, width: int, height: int, *, name: str | None = None, accept_keyboard_keys: bool | Iterable = True, accept_mouse_events: bool | Iterable = True, prevent_dispatch: Iterable | None = None, prevent_dispatch_view: Iterable | None = None, local_mouse_coordinates: bool = False, enabled: bool = True, modal: bool = False, draw_order: int = 1)[source]#

Bases:

A Section represents a rectangular portion of the viewport Events are dispatched to the section based on it’s position on the screen.

Parameters:
  • left – the left position of this section

  • bottom – the bottom position of this section

  • width – the width of this section

  • height – the height of this section

  • name – the name of this section

  • accept_keyboard_keys (Union[bool, Iterable]) – whether or not this section captures keyboard keys through. keyboard events. If the param is an iterable means the keyboard keys that are captured in press/release events: for example: [arcade.key.UP, arcade.key.DOWN] will only capture this two keys

  • accept_mouse_events (Union[bool, Iterable]) – whether or not this section captures mouse events. If the param is an iterable means the mouse events that are captured. for example: [‘on_mouse_press’, ‘on_mouse_release’] will only capture this two events.

  • prevent_dispatch – a list of event names that will not be dispatched to subsequent sections. You can pass None (default) or {True} to prevent the dispatch of all events.

  • prevent_dispatch_view – a list of event names that will not be dispatched to the view. You can pass None (default) or {True} to prevent the dispatch of all events to the view.

  • local_mouse_coordinates – if True the section mouse events will receive x, y coordinates section related to the section dimensions and position (not related to the screen)

  • enabled – if False the section will not capture any events

  • modal – if True the section will be a modal section: will prevent updates and event captures on other sections. Will also draw last (on top) but capture events first.

  • draw_order – The order this section will have when on_draw is called. The lower the number the earlier this will get draw. This can be different from the event capture order or the on_update order which is defined by the insertion order.

get_xy_screen_relative(section_x: int, section_y: int)[source]#

Returns screen coordinates from section coordinates

get_xy_section_relative(screen_x: int, screen_y: int)[source]#

returns section coordinates from screen coordinates

mouse_is_on_top(x: int, y: int) bool[source]#

Check if the current mouse position is on top of this section

on_draw()[source]#
on_hide_section()[source]#
on_key_press(symbol: int, modifiers: int)[source]#
on_key_release(_symbol: int, _modifiers: int)[source]#
on_mouse_drag(x: int, y: int, dx: int, dy: int, _buttons: int, _modifiers: int)[source]#
on_mouse_enter(x: int, y: int)[source]#
on_mouse_leave(x: int, y: int)[source]#
on_mouse_motion(x: int, y: int, dx: int, dy: int)[source]#
on_mouse_press(x: int, y: int, button: int, modifiers: int)[source]#
on_mouse_release(x: int, y: int, button: int, modifiers: int)[source]#
on_mouse_scroll(x: int, y: int, scroll_x: int, scroll_y: int)[source]#
on_resize(width: int, height: int)[source]#
on_show_section()[source]#
on_update(delta_time: float)[source]#
overlaps_with(section: Section) bool[source]#

Checks if this section overlaps with another section

should_receive_mouse_event(x: int, y: int) bool[source]#

Check if the current section should receive a mouse event at a given position

bottom#

The bottom edge of this section

draw_order#

Returns the draw order state The lower the number the earlier this section will get draw

enabled#

Enables or disables this section

height#

The height of this section

left#

Left edge of this section

modal#

Returns the modal state (Prevent the following sections from receiving input events and updating)

right#

Right edge of this section

section_manager#

Returns the section manager

top#

Top edge of this section

view#

The view this section is set on

width#

The width of this section

window#

The view window

class arcade.SectionManager(view: View)[source]#

Bases:

This manages the different Sections a View has. Actions such as dispatching the events to the correct Section, draw order, etc.

add_section(section: Section, at_index: int | None = None, at_draw_order: int | None = None) None[source]#

Adds a section to this Section Manager Will trigger section.on_show_section if section is enabled

Parameters:
  • section – the section to add to this section manager

  • at_index – inserts the section at that index for event capture and update events. If None at the end

  • at_draw_order – inserts the section in a specific draw order. Overwrites section.draw_order

clear_sections() None[source]#

Removes all sections and calls on_hide_section for each one if enabled

disable() None[source]#

Disable all sections Disabling a section will trigger section.on_hide_section

disable_all_keyboard_events() None[source]#

Removes the keyboard event handling from all sections

dispatch_keyboard_event(event: str, *args, **kwargs) bool | None[source]#

Generic method to dispatch keyboard events to the correct sections

Parameters:
  • event – the keyboard event name to dispatch

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

dispatch_mouse_enter_leave_events(event_origin: str, x: int, y: int, *args, **kwargs) bool | None[source]#

This helper method will dispatch mouse enter / leave events to sections based on ‘on_mouse_motion’ and ‘on_mouse_drag’ events. Will also dispatch the event (event_origin) that called this method

Parameters:
  • event_origin – the mouse event name that called this method. This event will be called here.

  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

dispatch_mouse_event(event: str, x: int, y: int, *args, current_section: Section | None = None, **kwargs) bool | None[source]#

Generic method to dispatch mouse events to the correct Sections

Parameters:
  • event – the mouse event name to dispatch

  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • current_section – the section this mouse event should be delivered to. If None, will retrive all sections that should recieve this event based on x, y coordinates

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

enable() None[source]#

Enables all sections Enabling a section will trigger section.on_show_section

get_first_section(x: int, y: int, *, event_capture: bool = True) Section | None[source]#

Returns the first section based on x,y position

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • event_capture – True will use event capture dimensions, False will use section draw size

Returns:

a section if match the params otherwise None

get_section_by_name(name: str) Section | None[source]#

Returns the first section with the given name :param name: the name of the section you want :return: the first section with the provided name. None otherwise

get_sections(x: int, y: int, *, event_capture: bool = True) Generator[Section, None, None][source]#

Returns a list of sections based on x,y position

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • event_capture – True will use event capture dimensions, False will use section draw size

Returns:

a generator with the sections that match the params

on_draw() None[source]#

Called on each event loop to draw It automatically calls camera.use() for each section that has a camera and resets the camera effects by calling the default SectionManager camera afterwards if needed. The SectionManager camera defaults to a camera that has the viewport and projection for the whole screen

on_hide_view() None[source]#

Called when the view is hide The View.on_hide_view is called before this by the Window.hide_view method

on_key_press(*args, **kwargs) bool | None[source]#

Triggers the on_key_press event on the appropiate sections or view

Parameters:
  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_key_release(*args, **kwargs) bool | None[source]#

Triggers the on_key_release event on the appropiate sections or view

Parameters:
  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_mouse_drag(x: int, y: int, *args, **kwargs) bool | None[source]#

This method dispatches the on_mouse_drag and also calculates if on_mouse_enter/leave should be fired

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_mouse_enter(x: int, y: int, *args, **kwargs) bool | None[source]#

Triggered when the mouse enters the window space Will trigger on_mouse_enter on the appropiate sections or view

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_mouse_leave(x: int, y: int, *args, **kwargs) bool | None[source]#

Triggered when the mouse leaves the window space Will trigger on_mouse_leave on the appropiate sections or view

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_mouse_motion(x: int, y: int, *args, **kwargs) bool | None[source]#

This method dispatches the on_mouse_motion and also calculates if on_mouse_enter/leave should be fired

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_mouse_press(x: int, y: int, *args, **kwargs) bool | None[source]#

Triggers the on_mouse_press event on the appropiate sections or view

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_mouse_release(x: int, y: int, *args, **kwargs) bool | None[source]#

Triggers the on_mouse_release event on the appropiate sections or view

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_mouse_scroll(x: int, y: int, *args, **kwargs) bool | None[source]#

Triggers the on_mouse_scroll event on the appropiate sections or view

Parameters:
  • x – the x axis coordinate

  • y – the y axis coordinate

  • args – any other position arguments that should be deliverd to the dispatched event

  • kwargs – any other keyword arguments that should be delivered to the dispatched event

Returns:

EVENT_HANDLED or EVENT_UNHANDLED, or whatever the dispatched method returns

on_resize(width: int, height: int) None[source]#

Called when the window is resized.

Parameters:
  • width – the new width of the screen

  • height – the new height of the screen

on_show_view() None[source]#

Called when the view is shown The View.on_show_view is called before this by the Window.show_view method

on_update(delta_time: float) None[source]#

Called on each event loop.

Parameters:

delta_time – the delta time since this method was called last time

remove_section(section: Section) None[source]#

Removes a section from this section manager

Parameters:

section – the section to remove

sort_section_event_order() None[source]#

This will sort sections on event capture order (and update) based on insertion order and section.modal

sort_sections_draw_order() None[source]#

This will sort sections on draw order based on section.draw_order and section.modal

has_sections#

Returns true if this section manager has sections

is_current_view#

Returns if this section manager view is the current on the view window a.k.a.: is the view that is currently being shown

sections#

Property that returns the list of sections