Interface Documentation

Interface class

class pygameyagui.Interface(title='', fps=120, window_width=800, window_height=600, show_status_bar=True, show_controls=True, screen_bg_color=(100, 100, 100))

This is the class that has to be instantiated once and only once to create the interface object.

It will configure the FPS rate, window dimensions, status bar, controls and background color. It should be called after pygame.init() and uses pygame.display.set_mode() and pygame.time.Clock() to configure pygame environment.

Parameters:
  • title (str (optional)) – The window title.

  • fps (int [>0] (optional)) – Frames Per Second rate to update the screen. It does not influence the rate of simulation (IPS - Iteration per Seconds) which is only limited by the processing power of the CPU.

  • window_width (int [>0] (optional)) – The window width in pixelsels.

  • window_height (int [>0] (optional)) – The window height in pixelsels.

  • show_status_bar (bool (optional)) – Flag to show or hide the status bar.

  • show_controls (bool (optional)) – Flag to show or hide the controls at the top right corner of the screen. Buttons for pause/resume, reload simulations and toolboxes (pygameyagui.Toolbox) list is located at the controls.

  • screen_bg_color (tuple (0<R,G,B<255) (optional)) – Screen background color in the format (R,G,B).

Interface methods

Interface.config(title=None, fps=None, window_width=None, window_height=None, show_status_bar=None, show_controls=None, screen_bg_color=None)

Use this to change the interface settings during runtime.

All the parameters of this methods can be set during the interface instantiation. However, one may need (programatically) to change this parameters during the execution of a simulation.

Although all parameters in this method default to None, internally they will be left unchanged if not passed. Therefore, any combination of parameters can be passed as arguments. Also, this method can be called anytime and anywhere after the interface instantiation.

Please, do refer to the parameters description of the pygameyagui.Interface.

Return type:

NoneType

Interface.active()

Use this for the condition on the simulation loop while.

It will return True by default and keep the simulation loop running. Use pygameyagui.Interface.deactivate() method to set it to False.

Return type:

bool

Interface.deactivate()

Use this anywhere if you want to end the simulation loop.

It will make the pygameyagui.Interface.active() method return False. Depending how you organize your program this might close the Pygame window

Return type:

NoneType

Interface.events()

Use this method to get the Pygame events.

This method is required to be called once and only once in the simulation loop. It should be called on each iteration at the very top of the simulation loop.

Return type:

Pygame.Eventlist

Interface.running()

Use this to know if the simulation will be updated.

It is equivalent to know if time is passing.

It will return False by the default if show_controls at pygameyagui.Interface is set to True. On the other hand, it will return True by the default if show_controls is set to False.

See also: pygameyagui.Interface.pause(), pygameyagui.Interface.resume() and pygameyagui.Interface.pause_and_reset()

Return type:

bool

Interface.setting()

Use this to know if a setup is needed.

It will return True during the execution of the first simulation iteration or if a restart condition is met. Otherwise, returns False.

The restart condition is met if:

  • The Reload button at the interface controls is clicked;

  • Any widget set to be a emitter is trigged

See also: pygameyagui.Interface.reset() and pygameyagui.Interface.pause_and_reset()

Return type:

bool

Interface.show()

Use this method show the toolboxes, controls and status bar.

This method is required to be called once and only once in the simulation loop. It should be called on each iteration at the very bottom of the simulation loop. Also, it handles all the events that concerns the graphical interface.

Return type:

NoneType

Interface.pause()

Use this to pause the simulation update process.

It is equivalent to freeze time.

See also: pygameyagui.Interface.running(), pygameyagui.Interface.resume() and pygameyagui.Interface.pause_and_reset()

Return type:

NoneType

Interface.resume()

Use this to resume the simulation update process.

It is equivalent to unfreeze time.

See also: pygameyagui.Interface.running(), pygameyagui.Interface.pause() and pygameyagui.Interface.pause_and_reset()

Return type:

NoneType

Interface.reset()

Use this to reset the simulation.

It is equivalent to zero time. It will make pygameyagui.Interface.setting() return True.

See also: pygameyagui.Interface.setting() and pygameyagui.Interface.pause_and_reset()

Return type:

NoneType

Interface.pause_and_reset()

Use this to pause and reset the simulation.

It is equivalent to zero and stop time. It will make pygameyagui.Interface.setting() return True and pygameyagui.Interface.running() return False.

See also: pygameyagui.Interface.setting() and pygameyagui.Interface.running()

Return type:

NoneType

Interface.contains_point(point)

This checks if a point is inside the window.

Parameters:

point (tuple) – A pair of two integers/floats that represents a point.

Return type:

bool

Interface.variables()

This creates a dummy object from a dummy class to use as a global variable.

As long as this is created in the global scope, you can use this to set attributes that act like global without having to deal with declaring global variables. This is a hack it should be avoided if possible.

Return type:

Variable

Interface properties

property Interface.window_width

Get the window width in pixels (int).

property Interface.window_height

Get the window height in pixels (int).

property Interface.window_center

Get the pair of x and y coordinate for the center of the window in pixels (tuple).

property Interface.window_toplef

Get the pair of x and y coordinate for the top left corner of the window in pixels (tuple).

property Interface.window_topright

Get the pair of x and y coordinate for the top right corner of the window in pixels (tuple).

property Interface.window_bottomleft

Get the pair of x and y coordinate for the bottom left corner of the window in pixels (tuple).

property Interface.window_bottomright

Get the pair of x and y coordinate for the bottom right corner of the window in pixels (tuple).

property Interface.window_midtop

Get the pair of x and y coordinate for the mid top position of the window in pixels (tuple).

property Interface.window_midbottom

Get the pair of x and y coordinate for the mid bottom position of the window in pixels (tuple).

property Interface.window_midleft

Get the pair of x and y coordinate for the mid left position of the window in pixels (tuple).

property Interface.window_midright

Get the pair of x and y coordinate for the mid right position of the window in pixels (tuple).

property Interface.window_rect

Get the Pygame Rect for the window (Pygame.Rect).

property Interface.mouse

Get the pair of x and y coordinates for the mouse position inside the window in pixels (tuple)

property Interface.mouse_x

Get the x coordinate of the mouse position inside the window in pixels (int).

property Interface.mouse_y

Get the y coordinate of the mouse position inside the window in pixels (int).

property Interface.surface

Get the Pygame Surface of the window (Pygame.Surface).

property Interface.window_bg_color

Get the current window background color in the format RGB (tuple)

property Interface.time

Get the current time in seconds since the simulation was started or last resetted (float)

property Interface.dt

Get the elapsed time between the current frame and previous frame in seconds (float)

property Interface.fps

Get the target FPS value (int).

Note: This is the value set at pygameyagui.Interface or configured using pygameyagui.Interface.config(). It is not the actual FPS which is varies and its average is shown at the status bar.

property Interface.iteration_count

Get the number of iteration since the simulation was started (int).

Note: This will not be resetted with time.