pymasep.interface
Submodules
- pymasep.interface.cut_scene_interface_state
- pymasep.interface.environment_interface
- pymasep.interface.interface
- pymasep.interface.interface_controller
- pymasep.interface.interface_state
- pymasep.interface.ui_board
- pymasep.interface.ui_choice
- pymasep.interface.ui_dialog_box
- pymasep.interface.ui_dice_selection
- pymasep.interface.ui_init_object_window
- pymasep.interface.ui_input
- pymasep.interface.ui_merchant
- pymasep.interface.ui_simple_input
- pymasep.interface.ui_talk
- pymasep.interface.user_event
Attributes
Board event : A square has been selected |
|
Board event : A list of squares has been validate |
|
Init windows event : all inputs have been validated |
Classes
Sub application that displays an environment and interact with user |
|
Represents the environment of the game (Interface part). This object keeps all dynamic value of the game. |
|
Abstract controller to control an agent in the environment |
|
This class implements the concept (pretty much) of Game State for the interface |
|
Board with square where token can be put. |
|
Square of the board |
|
Windows used by the user to initialize one object or agent (Characteristics in state "init") |
|
General and abstract input with label and a value to write or select |
|
UI Input that used dices results for value |
|
Interface for selecting objects to buy or to take from a container |
|
Dialogue box to choose what to say |
|
Dialog Box to display talks |
Package Contents
- class pymasep.interface.Interface(app, received_q_id, cfg, game_class_=None, interface_role=None, remote_engine_host=None, remote_engine_port=None, search_remote=False)
Bases:
pymasep.application.sub_app.SubAppSub application that displays an environment and interact with user
- Parameters:
app – main application
received_q_id – id of the queue used by the sub app to receive messages.
cfg (omegaconf.DictConfig) – Configuration of the interface.
game_class – Class of the game.
interface_role – Role of the interface. See @ConnectedSubAppInfo.
remote_engine_host (Optional[str]) – Host of the remote engine. May be None if interface is in the same process of engine.
remote_engine_port (Optional[int]) – Port of the remote engine. May be None if interface is in the same process of engine.
search_remote (bool) – True if the interface has to search the server on LAN. Default False
- Raises:
ConnectionError – If the interface does not find a server on the LAN.
- screen = None
screen to display on
- virtual_screen = None
virtual screen to render on
- virtual_screen_size = (100, 100)
size of the virtual screen to render on
- font = None
font of the system
- fontSize = 14
size of the system font
- end = False
interface loop end
- root_path
root path of the application
- ui_manager = None
pygame_gui manager instance
- ui_theme_file = None
pygame_gui theme file
- resources
displaying resource
- skip_observation
may some observations skipped?
- system_color = (255, 255, 0)
system color for displaying information
- interface_role
role of the interface. see @ConnectedSubAppInfo
- environment
environment interface
- game
- controller_interface_class_ = None
class of the controller used by the interface
- controller = None
controller used by the interface
- last_step_choose_action = None
last step the interface have chosen action
- console = None
console UI
- interface_dbg_info_index = 0
DEBUG information
- debug_info_labels = []
DEBUG labels
- fps = []
DEBUG FPS information
- engine_id = None
connected engine id
- remote_engine_host
host of the engine
- remote_engine_port
port of the engine
- load_resources()
Load the graphical resources
- Return type:
None
- init_graphics()
Init the graphical elements
- Return type:
None
- add_debug_label()
Adding a new graphical debug labels. A text can be set later to add debug info, displayed on the top of all.
- Returns:
The index of the new added label
- Return type:
int
- init_game()
Initialize game : Connect to engine, define the game and register self as a new interface
- Return type:
None
- receive_observation()
Wait for an OBSERVATION message (or END_GAME) from the engine and update the interface environment
- Return type:
None
- handle_event()
Handle interface events
- Return type:
None
- choose_action()
Let the agent choose action if conditions are respected: - The interface is a ROLE_ACTOR - The interface has received a new observation since the agent’s last action.
- Return type:
None
- send_action()
Send the action chosen by the interface. Only if the interface is a ROLE_ACTOR
- Return type:
None
- update()
update the current app state
- Return type:
None
- display_text(text, position)
quick display of a text with system font.
- Parameters:
text – text to display
position – position of the text
- Return type:
None
- render(time_delta)
Render the environment current state and other information on screen
- Return type:
None
- run()
Main interface loop
- Return type:
None
- class pymasep.interface.EnvironmentInterface(id_env=None, cfg=None)
Bases:
pymasep.common.environment.EnvironmentRepresents the environment of the game (Interface part). This object keeps all dynamic value of the game. This environment chooses the action of the agent controlled by the interface.
- Parameters:
id_env (str) – the id of the environment. If None, a new uuid will be set
cfg (omegaconf.DictConfig)
- Parm cfg:
the configuration of the environment
- controlled_agent = None
the agent controlled by the interface
- choose_action()
tell the agent controlled by interface to choose their action
- Return type:
None
- update_current_next(observation_xml, additional_info)
update the current state of the interface from the observation
- Parameters:
observation_xml (xml.etree.ElementTree.Element) – observation as XML
additional_info – additional information
- Return type:
None
- class pymasep.interface.InterfaceController(environment)
Bases:
pymasep.common.ControllerAbstract controller to control an agent in the environment
- Parameters:
environment – environment for the controller
- select_action(event)
Selection action according to the interface event
- Parameters:
event – The event (List here all events handled by)
- Returns:
True if the event has been processed
- Return type:
bool
- class pymasep.interface.InterfaceState(sub_application, container_dim=(100, 100))
Bases:
pymasep.application.sub_app_state.SubAppStateThis class implements the concept (pretty much) of Game State for the interface
- Parameters:
sub_application – the sub application where the state is defined
container_dim – pygame_ui general container dimension (in pixel)
- ui_container = None
pygame_gui container that include all pygame_gui elements for the state
- container_dim
dimension of the pygame_gui container
- init()
Initialisation of the state
- Return type:
None
- clean()
The state is destroyed. Clean all elements of the state (including ui_container)
- Return type:
None
- pause()
Pause the state. Change the ui_container display
- Return type:
None
- abstract handle_event(event)
Handle events in the state
- Parameters:
event – The event to handle
- Return type:
None
- update()
The update phase of the state. For interface, it corresponds to choose action, send action and receive observation.
- Return type:
None
- render(time_delta)
The render part : how to display the state
- Return type:
None
- on_receive_observation()
Callback when the interface receives an observation
- Return type:
None
- class pymasep.interface.UIBoard(relative_rect, manager, container, sub_application, image_surface, game_data, game_class_, origin_coord_map, square_size, player_name)
Bases:
pygame_gui.core.UIContainerBoard with square where token can be put.
- For information, layer of elements:
background : 90 agents tokens: 100 selected square: 150
- Parameters:
relative_rect (pygame.Rect) – position and dimensions of the board (pixels)
manager (pygame_gui.core.interfaces.IUIManagerInterface) – Manager (from pygame_gui)
container (pygame_gui.core.interfaces.IContainerLikeInterface) – Container of the board (form pygame_gui)
sub_application – sub application instance (the interface)
image_surface (pygame.Surface) – the image surface to display the board
game_data – the data map (see @GridTools)
game_class – the class of the game
origin_coord_map (tuple) – pixel coordinate of the origin of the (0, 0) map position
square_size (int) – size of a square of the boad
player_name (str) – name of the player handle by the board
- RUN_MODE = 'Run'
Mode of the board : Rune
- SELECT_SQUARE_MODE = 'SelectSquare'
Mode of the board : Select a square
- SELECT_PIECE_MODE = 'SelectPiece'
Mode of the board : Select a piece on the board
- background_image
bacground image of the board
- game_data
data of the board
- game_class_
- sub_application
interface pointer
- origin_coord_map
pixel origin of the (0, 0) map position
- square_size
square size of the element in pixel
- player_name
name of the player handle by the board
- agents_tokens
agent UITokens
- objects_tokens
object UITokens
- spotlight_squares
squares that are spotlight
- hovered_board_pos = None
position of the board that is hovered
- modes
possible mode of the board
- current_mode = None
current mode of the board
- board_debug_info_idx
idx of the board debug info
- last_step_updated = None
the last step when the board has been updated
- add_spotlight_square_state(board_pos, state)
Set a spotlight square at a desired state
- Parameters:
board_pos – Position on the board
state – state to set see @UIBoardElement
- Return type:
None
- remove_spotlight_square_state(board_pos, state)
Remove a spotlighted square which is at a desired state
- Parameters:
board_pos – Position on the board
state – state which will be removed
- Return type:
None
- map_pos_to_surface_pos(map_pos)
Convert a map position to the surface position (pixel)
- Parameters:
map_pos – Position on the map (tuple)
- Returns:
surface position (tuple of pixel)
- Return type:
tuple
- surface_pos_to_map_pos(surface_pos)
convert the surface position to a map position
- Parameters:
surface_pos – the surface position (pixel)
- Returns:
the map position (tuple)
- Return type:
tuple
- get_spotlight_squares_from_state(state)
get all the squares on the baard that are on a certain state
- Parameters:
state – state to find
- Returns:
List of squares
- update_with_observation(time_delta)
Part of the update directly depending on the observation and that must be called only once per observation
- Parameters:
time_delta (float) – Time passed since the last call
- update(time_delta)
Update the element of the board according to the observation
- Parameters:
time_delta (float) – Time passed since the last call
- process_event(event)
Process an event on the board.
- Parameters:
event (pygame.event.Event) – The event to process
- Returns:
True the event has been processed
- Return type:
bool
- set_mode(mode)
Set the mode of the board. :param mode: Mode of the board.
- Return type:
None
- class pymasep.interface.UIBoardSquare(manager, board, square_size, board_pos)
Bases:
UIBoardElementSquare of the board
- Parameters:
manager – Manager (from pygame_gui)
board – Board where this element is put
board_pos – Position where this element put (board coordinates)
square_size – square size (in pixel)
- surface
- pymasep.interface.SQUARE_SELECTED_EVENT
Board event : A square has been selected
- pymasep.interface.SQUARE_VALIDATION_EVENT
Board event : A list of squares has been validate
- pymasep.interface.INIT_WINDOW_VALIDATION_EVENT
Init windows event : all inputs have been validated
- class pymasep.interface.UIInitObjectWindow(rect, ui_manager, sub_application, object_to_init_name)
Bases:
pygame_gui.elements.UIWindowWindows used by the user to initialize one object or agent (Characteristics in state “init”)
- Parameters:
rect (pygame.Rect) – Position and size of the window
ui_manager (pygame_gui.UIManager) – Manager (from pygame_gui)
sub_application – the sub application (interface) that will handle the window
object_to_init_name – name of the Object or Agent to init
- _get_initializer_for_charac(charac)
Get the initializer from the charac, or from it’s ObjectState or from its Object.
- Parameters:
charac – Characteristic
- Returns:
the initializer for the charac
- _get_object_to_init()
- sub_application
interface application
- object_to_init_name
name of the agent to init
- entries
ui entries to initialize the characteristics
- font_info
font information to calcutate sizes
- margin
margin of the window
- active_player_label
name of the player to initialize the characteristics
- center_x
- pos_y
- object_to_init
- charac_to_init
- containers_to_init
- button_rect
- button_validation
button to validate the initialization
- process_event(event)
Process the events of the windows. UI_BUTTON_PRESSED is handling on this method.
- Parameters:
event (pygame.event.Event) – Event to process
- Returns:
True if the event has been processed
- Return type:
bool
- update(time_delta)
Update the element of the window according to the value of the shared Characteristics.
- Parameters:
time_delta (float) – Time passed since the last call
- class pymasep.interface.UIInput(relative_rect, manager, container, label_text, waited_type, error_resource)
Bases:
pygame_gui.core.UIContainerGeneral and abstract input with label and a value to write or select
- Parameters:
relative_rect (pygame.Rect) – position and size of the input
manager (pygame_gui.core.interfaces.IUIManagerInterface) – Manager (from pygame_gui)
container (pygame_gui.core.interfaces.IContainerLikeInterface) – Container of the UIInput (form pygame_gui)
label_text (str) – Text of the label
waited_type (type) – Expected type of the value
error_resource (pygame.image) – Image displayed when an error occurs
- font_info
- waited_type
expected type of the input value
- validated = True
is the input valid
- error_pos
position and size of the error icon
- label_pos
position of the label
- _
- error_image
error image displayed when an error occurs
- error
ui image for error
- abstract set_text(text)
Set the text of the input. To implement on subclasses. :param text: Text of the input
- Parameters:
text (str)
- abstract get_text()
Set the text of the input. To implement on subclasses.
- Returns:
Text of the input
- Return type:
str
- update(time_delta)
Update on validating value input
- Parameters:
time_delta (float) – Time passed since the last call
- validate()
Validate if the value of the UIInput respects some constraints
- Returns:
True if the value is valid
- Return type:
bool
- class pymasep.interface.UIDiceSelection(relative_rect, manager, container, label_text, dices, error_resource)
Bases:
pymasep.interface.ui_simple_input.UISimpleInputUI Input that used dices results for value
- Parameters:
relative_rect (pygame.Rect) – Position and size of the choice
manager (pygame_gui.core.interfaces.IUIManagerInterface) – Manager (from pygame_gui)
container (pygame_gui.core.interfaces.IContainerLikeInterface) – Container of the UIDiceSelection (form pygame_gui)
label_text (str) – Text of the label
error_resource (pygame.image) – Image displayed when an error occurs
dices (str)
- dices
dices to launch. See dices.py
- dice_pos
position of the dice button
- dice_button
button to launch the dices
- set_text(text)
set the result of the dices as string
- Parameters:
text (str) – result of the dice
- get_text()
return the result of the dices as string
- Returns:
result of the dices
- Return type:
str
- process_event(event)
Process event to launch dices if the user presses the button.
- Parameters:
event (pygame.event.Event) – Event that could be a UI_BUTTON_PRESSED
- Returns:
True if the event has been processed
- Return type:
bool
- validate()
Validate if the value of the UIInput respects some constraints. In this case, the value of the dice must be between min and max value of the dice expression.
- Returns:
True if the value is valid
- Return type:
bool
- class pymasep.interface.UIMerchant(relative_rect, manager, container, item_list, sub_application, object_to_init_name)
Bases:
pygame_gui.elements.UIPanelInterface for selecting objects to buy or to take from a container
- Parameters:
relative_rect (pygame.Rect) – Position and size of the window
manager (pygame_gui.core.interfaces.IUIManagerInterface) – Manager (from pygame_gui)
container (pygame_gui.core.interfaces.IContainerLikeInterface) – Container of the UIMerchant (form pygame_gui)
sub_application – the sub application (interface) that will handle the panel
object_to_init_name – name of the Object or Agent to init
item_list (List[str])
- sub_application
interface application
- object_to_init_name
name of the agent to initialize container
- selected_item_to_add = []
items to add to the container
- selected_item_to_remove = []
items to remove from the container
- item_list
list of possible items
- label_pos
cost label position
- costs
cost UI label
- list_objects_rect
list of possible items rectangle
- list_objects
UI element of possible items
- list_objects_chosen_rect
chosen objects rectangle
- list_objects_chosen
UI element of chosen items
- add_button
UI button to add items
- del_button
UI button to remove items
- process_event(event)
process event to launch dices if user press the button.
- Parameters:
event (pygame.event.Event) – event that could be a UI_BUTTON_PRESSED
- Returns:
True if the event has been processed
- Return type:
bool
- update(time_delta)
Update the UI element
- Parameters:
time_delta (float) – time delta since last call
- Return type:
None
- class pymasep.interface.UIDialogBox(rect, ui_manager, choice)
Bases:
pygame_gui.elements.UIWindowDialogue box to choose what to say
- Parameters:
rect (pygame.Rect) – Rect of the dialog box.
ui_manager (pygame_gui.core.interfaces.IUIManagerInterface) – UIManagerInterface
choice (List[Tuple[str, str]]) – List of tuples containing the link target (id the of dialog) and the displayed text
- choice
possible choices of talk
- tb_choice = []
ui text box elements
- next_y_pos = 10
- process_event(event)
Process the event UI_TEXT_BOX_LINK_CLICKED and post an TALK_EVENT
- Parameters:
event (pygame.event.Event) – The event to process.
- Return type:
bool
- class pymasep.interface.UITalk(relative_rect, manager, container, html_text, speaker_name=None)
Bases:
pygame_gui.elements.UIAutoResizingContainerDialog Box to display talks
- Parameters:
relative_rect (pygame.Rect) – position and dimensions of the dialog box (pixels)
manager (pygame_gui.core.interfaces.IUIManagerInterface) – Manager (from pygame_gui)
container (pygame_gui.core.interfaces.IContainerLikeInterface) – Container of the board (form pygame_gui)
html_text (str) – HTML text of the dialog box.
speaker_name (Optional[str]) – Name of the speaker. If None, this part of the component is not displayed.
- bubble_width = 20
size of the bubble area
- speaker_label_height = 0
height of the speaker label
- html_text
text to display on the dialog box
- speaker_name_label = None
speaker’s name ‘
- talk_label
ui label for displaying the text
- bubble_talk
image of the bubble
- _img