pooltool.interact

An endpoint for classes that enable interaction

Overview

Classes

Game

This class runs the pooltool application

ShotViewer

An interface for viewing shots from within python.

Classes

class pooltool.interact.Game(config=ShowBaseConfig.default())[source]

This class runs the pooltool application

Bases: Interface

Methods:

enter_game()[source]

Close the menu, setup the visualization, and start the game

create_system()[source]

Create the multisystem and game objects

FIXME This is where menu options for game type and further specifications should plug into.

class pooltool.interact.ShotViewer(config=ShowBaseConfig.default())[source]

An interface for viewing shots from within python.

Important

For instructions on how to use the interactive interface, see The Interface.

Important

Only one instance of this class can be created per python process. You’ll receive a runtime error if you try. Instead, create one instance and use it for the lifetime of your python process.

For usage, see show().

Bases: Interface

Methods:

show(shot_or_shots: pooltool.system.datatypes.System | pooltool.system.datatypes.MultiSystem, title: str = '', camera_state: pooltool.ani.camera.CameraState | None = None)[source]

Opens the interactive interface for one or more shots.

Important

For instructions on how to use the interactive interface, see The Interface.

Parameters:

Example

This example visualizes a single shot.

>>> import pooltool as pt
>>> system = pt.System.example()

Make sure the shot is simulated, otherwise it will make for a boring visualization:

>>> pt.simulate(system, inplace=True)

Create a ShotViewer object:

>>> gui = pt.ShotViewer()

Now visualize the shot:

>>> gui.show(system)

(Press escape to exit the interface and continue script execution)

Example

This example explains the order in which events and script execution happens.

import pooltool as pt
system = pt.System.example()
pt.simulate(system, inplace=True)

# This line takes a view seconds to execute. It will generate a visible
# window. Once the window has been generated, script execution continues
gui = pt.ShotViewer()

# When this line is called, the window is populated with an animated
# scene of the shot.
gui.show(system)

# This line will not execute until <esc> is pressed while the window is
# active.
print('script continues')

# For subsequent calls to `show`, you must use the same `ShotViewer`
# object:
gui.show(system)