pooltool.interact¶
An endpoint for classes that enable interaction¶
Overview¶
This class runs the pooltool application |
|
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:
- 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:
shot_or_shots (Union[pooltool.system.datatypes.System, pooltool.system.datatypes.MultiSystem]) --
The shot or collection of shots to visualize. This can be a single
pooltool.system.datatypes.System
object or apooltool.system.datatypes.MultiSystem
object containing multiple systems.Note
If a multisystem is passed, the systems can be scrolled through by pressing n (next) and p (previous).
title (str) -- The title to display in the visualization. Defaults to an empty string.
camera_state (Optional[pooltool.ani.camera.CameraState]) -- The initial camera state that the visualization is rendered with.
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)