Window(bpy_struct)
base class — bpy_struct
- class bpy.types.Window(bpy_struct)
Open window
- height
Window height (in [0, 32767], default 0, readonly)
- Type:
int
- modal_operators
A list of currently running modal operators (default None, readonly)
- Type:
- stereo_3d_display
Settings for stereo 3D display (readonly, never None)
- Type:
- support_hdr_color
The window has a HDR graphics buffer that wide gamut and high dynamic range colors can be written to, in extended sRGB color space. (default False, readonly)
- Type:
bool
- width
Window width (in [0, 32767], default 0, readonly)
- Type:
int
- x
Horizontal location of the window (in [-32768, 32767], default 0, readonly)
- Type:
int
- y
Vertical location of the window (in [-32768, 32767], default 0, readonly)
- Type:
int
- cursor_warp(x, y)
Set the cursor position
- Parameters:
x (int) – (in [-inf, inf])
y (int) – (in [-inf, inf])
- cursor_set(cursor)
Set the cursor
- Parameters:
cursor (Literal[Window Cursor Items]) – cursor
- cursor_modal_set(cursor)
Set the cursor, so the previous cursor can be restored
- Parameters:
cursor (Literal[Window Cursor Items]) – cursor
- cursor_modal_restore()
Restore the previous cursor after calling
cursor_modal_set
- event_simulate(type, value, *, unicode='', x=0, y=0, shift=False, ctrl=False, alt=False, oskey=False, hyper=False)
event_simulate
- Parameters:
type (Literal[Event Type Items]) – Type
value (Literal[Event Value Items]) – Value
unicode (str) – (optional)
x (int) – (in [-inf, inf], optional)
y (int) – (in [-inf, inf], optional)
shift (bool) – Shift, (optional)
ctrl (bool) – Ctrl, (optional)
alt (bool) – Alt, (optional)
oskey (bool) – OS Key, (optional)
hyper (bool) – Hyper, (optional)
- Returns:
Item, Added key map item
- Return type:
- find_playing_scene(*, scrub=False)
find_playing_scene
- Parameters:
scrub (bool) – Scrubbing, Check if time in the scene is being scrubbed (optional)
- Returns:
Scene, Scene that is currently playing
- Return type:
- classmethod bl_rna_get_subclass(id, default=None, /)
- Parameters:
id (str) – The RNA type identifier.
default (
bpy.types.Struct| None) – The value to return when not found.
- Returns:
The RNA type or default when not found.
- Return type:
- classmethod bl_rna_get_subclass_py(id, default=None, /)
- Parameters:
id (str) – The RNA type identifier.
default (type | None) – The value to return when not found.
- Returns:
The class or default when not found.
- Return type:
type
- screenshot(*, region=None, use_alpha=False)
Capture the windows pixel data.
- Parameters:
region (tuple[tuple[int, int], tuple[int, int]] | None) – The region to capture, or
Noneto capture all. Each int pair represents a pixel coordinate (the end value is not inclusive, matching Python slicing): ((min_x, min_y), (max_x, max_y))use_alpha (bool) – When false the alpha channel is fully opaque. Otherwise alpha values from the window’s frame-buffer are returned as-is.
- Returns:
A read-only
memoryviewof shape(height, width, 4)and format'B', viewing the captured RGBA pixels (rows ordered from bottom to top).- Return type:
memoryview
Save 3D Viewport to a PNG
Capture the 3D viewport’s main region from the current window and write it to a PNG file using
imbuf.import bpy import imbuf window = bpy.context.window # Locate the 3D viewport (if any). region = None for area in window.screen.areas: if area.type == 'VIEW_3D': for region_iter in area.regions: if region_iter.type == 'WINDOW': region = region_iter break break if region is not None: # The end coordinate is not inclusive, like Python slicing. region_rect = ( (region.x, region.y), (region.x + region.width, region.y + region.height), ) pixels = window.screenshot(region=region_rect) height, width = pixels.shape[0], pixels.shape[1] ibuf = imbuf.new((width, height)) ibuf.file_type = 'PNG' with ibuf.with_buffer('BYTE', write=True) as buf: # The cast produces a zero-copy 1-D view of the same bytes. # Currently only 1-D copies are supported by Python. buf.cast('B')[:] = pixels.cast('B') imbuf.write(ibuf, filepath="/tmp/viewport.png")