pyglet.canvas
Display and screen management.
Rendering is performed on a Canvas, which conceptually could be an
off-screen buffer, the content area of a pyglet.window.Window, or an
entire screen. Currently, canvases can only be created with windows (though
windows can be set fullscreen).
Windows and canvases must belong to a Display. On Windows and Mac OS X
there is only one display, which can be obtained with get_display().
Linux supports multiple displays, corresponding to discrete X11 display
connections and screens. get_display() on Linux returns the default
display and screen 0 (localhost:0.0); if a particular screen or display is
required then Display can be instantiated directly.
Within a display one or more screens are attached. A Screen often
corresponds to a physical attached monitor, however a monitor or projector set
up to clone another screen will not be listed. Use Display.get_screens()
to get a list of the attached screens; these can then be queried for their
sizes and virtual positions on the desktop.
The size of a screen is determined by its current mode, which can be changed
by the application; see the documentation for Screen.
New in version 1.2.
- class Canvas
Abstract drawing area.
Canvases are used internally by pyglet to represent drawing areas – either within a window or full-screen.
New in version 1.2.
- display
Display this canvas was created on.
- class Display
A display device supporting one or more screens.
New in version 1.2.
- __init__(name: str = None, x_screen: int = None) None
Create a display connection for the given name and screen.
On X11,
nameis of the form"hostname:display", where the default is usually":1". On X11,x_screengives the X screen number to use with this display. A pyglet display can only be used with one X screen; open multiple display connections to access multiple X screens.Note that TwinView, Xinerama, xrandr and other extensions present multiple monitors on a single X screen; this is usually the preferred mechanism for working with multiple monitors under X11 and allows each screen to be accessed through a single pyglet`~pyglet.canvas.Display`
On platforms other than X11,
nameandx_screenare ignored; there is only a single display device on these systems.
- get_default_screen() Screen
Get the default (primary) screen as specified by the user’s operating system preferences.
- Return type:
- get_screens() list[pyglet.canvas.base.Screen]
Get the available screens.
A typical multi-monitor workstation comprises one
Displaywith multipleScreens. This method returns a list of screens which can be enumerated to select one for full-screen display.For the purposes of creating an OpenGL config, the default screen will suffice.
- Return type:
list of
Screen
- get_windows() list[pyglet.window.Window]
Get the windows currently attached to this display.
- class Screen
A virtual monitor that supports fullscreen windows.
Screens typically map onto a physical display such as a monitor, television or projector. Selecting a screen for a window has no effect unless the window is made fullscreen, in which case the window will fill only that particular virtual screen.
The
widthandheightattributes of a screen give the current resolution of the screen. Thexandyattributes give the global location of the top-left corner of the screen. This is useful for determining if screens are arranged above or next to one another.Use
get_screens()orget_default_screen()to obtain an instance of this class.- get_best_config(
- template: Config = None,
Get the best available GL config.
Any required attributes can be specified in
template. If no configuration matches the template,NoSuchConfigExceptionwill be raised. A configuration supported by the platform that best fulfils the needs described by the template.- Deprecated:
- Parameters:
template (
Config) – A configuration with desired attributes filled in.- Return type:
- get_closest_mode(width: int, height: int) ScreenMode
Get the screen mode that best matches a given size.
If no supported mode exactly equals the requested size, a larger one is returned; or
Noneif no mode is large enough. :rtype:ScreenModeNew in version 1.2.
- get_matching_configs(
- template: Config,
Get a list of configs that match a specification.
Any attributes specified in template will have values equal to or greater in each returned config. If no configs satisfy the template, an empty list is returned.
- Deprecated:
- Parameters:
template (
Config) – A configuration with desired attributes filled in.- Return type:
- get_mode() ScreenMode
Get the current display mode for this screen. :rtype:
ScreenModeNew in version 1.2.
- get_modes() list[pyglet.canvas.base.ScreenMode]
Get a list of screen modes supported by this screen. :rtype:
list[ScreenMode]New in version 1.2.
- set_mode(mode: ScreenMode) None
Set the display mode for this screen.
The mode must be one previously returned by
get_mode()orget_modes().- Return type:
- display
Display this screen belongs to.
- height
Height of the screen, in pixels.
- width
Width of the screen, in pixels.
- x
Left edge of the screen on the virtual desktop.
- y
Top edge of the screen on the virtual desktop.
- class ScreenMode
Screen resolution and display settings.
Applications should not construct ScreenMode instances themselves; see
Screen.get_modes().The
depthandratevariables may beNoneif the operating system does not provide relevant data.New in version 1.2.
- get_display() Display
Get the default display device.
If there is already a
Displayconnection, that display will be returned. Otherwise, a defaultDisplayis created and returned. If multiple display connections are active, an arbitrary one is returned. :rtype:DisplayNew in version 1.2.
- class Display
A display device supporting one or more screens.
New in version 1.2.
- __init__(name: str = None, x_screen: int = None) None
Create a display connection for the given name and screen.
On X11,
nameis of the form"hostname:display", where the default is usually":1". On X11,x_screengives the X screen number to use with this display. A pyglet display can only be used with one X screen; open multiple display connections to access multiple X screens.Note that TwinView, Xinerama, xrandr and other extensions present multiple monitors on a single X screen; this is usually the preferred mechanism for working with multiple monitors under X11 and allows each screen to be accessed through a single pyglet`~pyglet.canvas.Display`
On platforms other than X11,
nameandx_screenare ignored; there is only a single display device on these systems.
- get_default_screen() Screen
Get the default (primary) screen as specified by the user’s operating system preferences.
- Return type:
- get_screens() list[pyglet.canvas.base.Screen]
Get the available screens.
A typical multi-monitor workstation comprises one
Displaywith multipleScreens. This method returns a list of screens which can be enumerated to select one for full-screen display.For the purposes of creating an OpenGL config, the default screen will suffice.
- Return type:
list of
Screen
- get_windows() list[pyglet.window.Window]
Get the windows currently attached to this display.
- class Screen
A virtual monitor that supports fullscreen windows.
Screens typically map onto a physical display such as a monitor, television or projector. Selecting a screen for a window has no effect unless the window is made fullscreen, in which case the window will fill only that particular virtual screen.
The
widthandheightattributes of a screen give the current resolution of the screen. Thexandyattributes give the global location of the top-left corner of the screen. This is useful for determining if screens are arranged above or next to one another.Use
get_screens()orget_default_screen()to obtain an instance of this class.- get_best_config(
- template: Config = None,
Get the best available GL config.
Any required attributes can be specified in
template. If no configuration matches the template,NoSuchConfigExceptionwill be raised. A configuration supported by the platform that best fulfils the needs described by the template.- Deprecated:
- Parameters:
template (
Config) – A configuration with desired attributes filled in.- Return type:
- get_closest_mode(width: int, height: int) ScreenMode
Get the screen mode that best matches a given size.
If no supported mode exactly equals the requested size, a larger one is returned; or
Noneif no mode is large enough. :rtype:ScreenModeNew in version 1.2.
- get_matching_configs(
- template: Config,
Get a list of configs that match a specification.
Any attributes specified in template will have values equal to or greater in each returned config. If no configs satisfy the template, an empty list is returned.
- Deprecated:
- Parameters:
template (
Config) – A configuration with desired attributes filled in.- Return type:
- get_mode() ScreenMode
Get the current display mode for this screen. :rtype:
ScreenModeNew in version 1.2.
- get_modes() list[pyglet.canvas.base.ScreenMode]
Get a list of screen modes supported by this screen. :rtype:
list[ScreenMode]New in version 1.2.
- set_mode(mode: ScreenMode) None
Set the display mode for this screen.
The mode must be one previously returned by
get_mode()orget_modes().- Return type:
- display
Display this screen belongs to.
- height
Height of the screen, in pixels.
- width
Width of the screen, in pixels.
- x
Left edge of the screen on the virtual desktop.
- y
Top edge of the screen on the virtual desktop.