Erste Version
No files matched your search
@@ -0,0 +1,148 @@
|
||||
from briefcase.bootstraps.base import BaseGuiBootstrap
|
||||
|
||||
|
||||
class PygameCEGuiBootstrap(BaseGuiBootstrap):
|
||||
display_name_annotation = "does not support iOS/Android/Web deployment"
|
||||
|
||||
def app_source(self):
|
||||
return """\
|
||||
import importlib.metadata
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pygame
|
||||
|
||||
|
||||
SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
|
||||
BGCOLOR = (255, 255, 255)
|
||||
|
||||
|
||||
def main():
|
||||
# Linux desktop environments use an app's .desktop file to integrate the app
|
||||
# in to their application menus. The .desktop file of this app will include
|
||||
# the StartupWMClass key, set to app's formal name. This helps associate the
|
||||
# app's windows to its menu item.
|
||||
#
|
||||
# For association to work, any windows of the app must have WMCLASS property
|
||||
# set to match the value set in app's desktop file. For pygame_ce, this is
|
||||
# set using the SDL_VIDEO_X11_WMCLASS environment variable.
|
||||
|
||||
# Find the name of the module that was used to start the app
|
||||
app_module = sys.modules["__main__"].__package__
|
||||
# Retrieve the app's metadata
|
||||
metadata = importlib.metadata.metadata(app_module)
|
||||
|
||||
os.environ["SDL_VIDEO_X11_WMCLASS"] = metadata["Formal-Name"]
|
||||
|
||||
pygame.init()
|
||||
pygame.display.set_caption(metadata["Formal-Name"])
|
||||
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
||||
|
||||
running = True
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
running = False
|
||||
break
|
||||
|
||||
screen.fill(BGCOLOR)
|
||||
pygame.display.flip()
|
||||
|
||||
pygame.quit()
|
||||
"""
|
||||
|
||||
def pyproject_table_briefcase_app_extra_content(self):
|
||||
return """
|
||||
requires = [
|
||||
"pygame-ce",
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_macOS(self):
|
||||
return """\
|
||||
universal_build = true
|
||||
requires = [
|
||||
"std-nslog~=1.0.0",
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_linux(self):
|
||||
return """\
|
||||
requires = [
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_linux_system_debian(self):
|
||||
return """\
|
||||
system_requires = [
|
||||
]
|
||||
|
||||
system_runtime_requires = [
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_linux_system_rhel(self):
|
||||
return """\
|
||||
system_requires = [
|
||||
]
|
||||
|
||||
system_runtime_requires = [
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_linux_system_suse(self):
|
||||
return """\
|
||||
system_requires = [
|
||||
]
|
||||
|
||||
system_runtime_requires = [
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_linux_system_arch(self):
|
||||
return """\
|
||||
system_requires = [
|
||||
]
|
||||
|
||||
system_runtime_requires = [
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_linux_appimage(self):
|
||||
return """\
|
||||
manylinux = "manylinux_2_28"
|
||||
|
||||
system_requires = [
|
||||
]
|
||||
|
||||
linuxdeploy_plugins = [
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_linux_flatpak(self):
|
||||
return """\
|
||||
flatpak_runtime = "org.freedesktop.Platform"
|
||||
flatpak_runtime_version = "23.08"
|
||||
flatpak_sdk = "org.freedesktop.Sdk"
|
||||
"""
|
||||
|
||||
def pyproject_table_windows(self):
|
||||
return """\
|
||||
requires = [
|
||||
]
|
||||
"""
|
||||
|
||||
def pyproject_table_iOS(self):
|
||||
return """\
|
||||
supported = false
|
||||
"""
|
||||
|
||||
def pyproject_table_android(self):
|
||||
return """\
|
||||
supported = false
|
||||
"""
|
||||
|
||||
def pyproject_table_web(self):
|
||||
return """\
|
||||
supported = false
|
||||
"""
|
||||
@@ -0,0 +1,474 @@
|
||||
# pygame-ce - Python Game Library
|
||||
# Copyright (C) 2000-2001 Pete Shinners
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Pete Shinners
|
||||
# pete@shinners.org
|
||||
"""Pygame is a set of Python modules designed for writing games.
|
||||
It is written on top of the excellent SDL library. This allows you
|
||||
to create fully featured games and multimedia programs in the python
|
||||
language. The package is highly portable, with games running on
|
||||
Windows, macOS, OS X, BeOS, FreeBSD, IRIX, and Linux."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import platform
|
||||
|
||||
# Choose Windows display driver
|
||||
if os.name == "nt":
|
||||
pygame_dir = os.path.split(__file__)[0]
|
||||
dll_parents = {pygame_dir}
|
||||
try:
|
||||
# For editable support, add some more folders where DLLs are available.
|
||||
# This block only executes under an editable install. In a "normal"
|
||||
# install, the json file will not be installed at the supplied path.
|
||||
with open(
|
||||
os.path.join(
|
||||
os.path.dirname(pygame_dir), "buildconfig", "win_dll_dirs.json"
|
||||
),
|
||||
encoding="utf-8",
|
||||
) as f:
|
||||
import json
|
||||
|
||||
dll_parents.update(json.load(f))
|
||||
del json
|
||||
except (FileNotFoundError, ValueError):
|
||||
pass
|
||||
|
||||
d = "" # define variable here so that we can consistently delete it
|
||||
for d in dll_parents:
|
||||
# adding to PATH is the legacy way, os.add_dll_directory is the new
|
||||
# and recommended method. For extra safety we do both
|
||||
os.environ["PATH"] = os.environ["PATH"] + ";" + d
|
||||
os.add_dll_directory(d)
|
||||
|
||||
# cleanup namespace
|
||||
del pygame_dir, dll_parents, d
|
||||
|
||||
# when running under X11, always set the SDL window WM_CLASS to make the
|
||||
# window managers correctly match the pygame window.
|
||||
elif "DISPLAY" in os.environ and "SDL_VIDEO_X11_WMCLASS" not in os.environ:
|
||||
os.environ["SDL_VIDEO_X11_WMCLASS"] = os.path.basename(sys.argv[0])
|
||||
|
||||
|
||||
def _attribute_undefined(name):
|
||||
raise RuntimeError(f"{name} is not available")
|
||||
|
||||
|
||||
class MissingModule:
|
||||
_NOT_IMPLEMENTED_ = True
|
||||
|
||||
def __init__(self, name, urgent=0):
|
||||
self.name = name
|
||||
exc_type, exc_msg, _ = sys.exc_info()
|
||||
if exc_type is not None:
|
||||
self.info = str(exc_msg)
|
||||
self.reason = f"{exc_type.__name__}: {self.info}"
|
||||
else:
|
||||
self.info = "<no info>"
|
||||
self.reason = f"<no exception>: {self.info}"
|
||||
self.urgent = urgent
|
||||
if urgent:
|
||||
self.warn()
|
||||
|
||||
def __getattr__(self, var):
|
||||
if not self.urgent:
|
||||
self.warn()
|
||||
self.urgent = 1
|
||||
missing_msg = f"{self.name} module not available ({self.reason})"
|
||||
raise NotImplementedError(missing_msg)
|
||||
|
||||
def __bool__(self):
|
||||
return False
|
||||
|
||||
def warn(self):
|
||||
msg_type = "import" if self.urgent else "use"
|
||||
message = f"{msg_type} {self.name}: {self.info}\n({self.reason})"
|
||||
try:
|
||||
import warnings
|
||||
|
||||
level = 4 if self.urgent else 3
|
||||
warnings.warn(message, RuntimeWarning, level)
|
||||
except ImportError:
|
||||
print(message)
|
||||
|
||||
|
||||
# This is a special loader for WebAssembly platform
|
||||
# where pygame is in fact statically linked
|
||||
# mixing single phase (C) and multiphase modules (cython)
|
||||
if sys.platform in ("wasi", "emscripten"):
|
||||
try:
|
||||
import pygame.base as pygame_static
|
||||
except ModuleNotFoundError:
|
||||
pygame_static = None
|
||||
|
||||
if pygame_static:
|
||||
pygame = sys.modules[__name__]
|
||||
|
||||
# cython modules use multiphase initialisation when not in builtin Inittab.
|
||||
|
||||
from pygame import _sdl2
|
||||
|
||||
import importlib.machinery
|
||||
|
||||
loader = importlib.machinery.FrozenImporter
|
||||
spec = importlib.machinery.ModuleSpec("", loader)
|
||||
pygame_static.import_cython(spec)
|
||||
del loader, spec
|
||||
del pygame_static
|
||||
|
||||
|
||||
# we need to import like this, each at a time. the cleanest way to import
|
||||
# our modules is with the import command (not the __import__ function)
|
||||
# isort: skip_file
|
||||
|
||||
# first, the "required" modules
|
||||
from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
|
||||
from pygame.constants import * # now has __all__ pylint: disable=wildcard-import; lgtm[py/polluting-import]
|
||||
from pygame.version import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
|
||||
from pygame.rwobject import encode_string, encode_file_path
|
||||
|
||||
|
||||
import pygame.rect
|
||||
|
||||
Rect = pygame.rect.Rect
|
||||
FRect = pygame.rect.FRect
|
||||
|
||||
|
||||
import pygame.color
|
||||
|
||||
Color = pygame.color.Color
|
||||
|
||||
import pygame.bufferproxy
|
||||
|
||||
BufferProxy = pygame.bufferproxy.BufferProxy
|
||||
|
||||
import pygame.math
|
||||
|
||||
Vector2 = pygame.math.Vector2
|
||||
Vector3 = pygame.math.Vector3
|
||||
|
||||
|
||||
from pygame.base import __version__
|
||||
|
||||
# next, the "standard" modules
|
||||
# we still allow them to be missing for stripped down pygame distributions
|
||||
try:
|
||||
import pygame.display
|
||||
except (ImportError, OSError):
|
||||
display = MissingModule("display", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.draw
|
||||
except (ImportError, OSError):
|
||||
draw = MissingModule("draw", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.event
|
||||
from pygame.event import Event
|
||||
except (ImportError, OSError):
|
||||
event = MissingModule("event", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.image
|
||||
except (ImportError, OSError):
|
||||
image = MissingModule("image", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.joystick
|
||||
from pygame.joystick import Joystick
|
||||
except (ImportError, OSError):
|
||||
joystick = MissingModule("joystick", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.key
|
||||
except (ImportError, OSError):
|
||||
key = MissingModule("key", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.mouse
|
||||
except (ImportError, OSError):
|
||||
mouse = MissingModule("mouse", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.cursors
|
||||
from pygame.cursors import Cursor
|
||||
except (ImportError, OSError):
|
||||
cursors = MissingModule("cursors", urgent=1)
|
||||
|
||||
def Cursor(*args): # pylint: disable=unused-argument
|
||||
_attribute_undefined("pygame.Cursor")
|
||||
|
||||
|
||||
try:
|
||||
import pygame.pixelcopy
|
||||
except (ImportError, OSError):
|
||||
pixelcopy = MissingModule("pixelcopy", urgent=1)
|
||||
|
||||
|
||||
try:
|
||||
import pygame.surflock
|
||||
from pygame.surface import Surface, SurfaceType
|
||||
except (ImportError, OSError):
|
||||
|
||||
def Surface(size, flags, depth, masks): # pylint: disable=unused-argument
|
||||
_attribute_undefined("pygame.Surface")
|
||||
|
||||
SurfaceType = Surface
|
||||
|
||||
# sprite.py is using pygame.surface.Surface type
|
||||
try:
|
||||
import pygame.sprite
|
||||
except (ImportError, OSError):
|
||||
sprite = MissingModule("sprite", urgent=1)
|
||||
|
||||
|
||||
try:
|
||||
import pygame.mask
|
||||
from pygame.mask import Mask
|
||||
except (ImportError, OSError):
|
||||
mask = MissingModule("mask", urgent=0)
|
||||
|
||||
def Mask(size, fill): # pylint: disable=unused-argument
|
||||
_attribute_undefined("pygame.Mask")
|
||||
|
||||
|
||||
try:
|
||||
from pygame.pixelarray import PixelArray
|
||||
except (ImportError, OSError):
|
||||
|
||||
def PixelArray(surface): # pylint: disable=unused-argument
|
||||
_attribute_undefined("pygame.PixelArray")
|
||||
|
||||
|
||||
try:
|
||||
import pygame.time
|
||||
from pygame.time import Clock
|
||||
except (ImportError, OSError):
|
||||
time = MissingModule("time", urgent=1)
|
||||
|
||||
try:
|
||||
import pygame.transform
|
||||
except (ImportError, OSError):
|
||||
transform = MissingModule("transform", urgent=1)
|
||||
|
||||
# lastly, the "optional" pygame modules
|
||||
if "PYGAME_FREETYPE" in os.environ:
|
||||
try:
|
||||
import pygame.ftfont as font
|
||||
|
||||
sys.modules["pygame.font"] = font
|
||||
except (ImportError, OSError):
|
||||
pass
|
||||
try:
|
||||
import pygame.font
|
||||
import pygame.sysfont
|
||||
|
||||
from pygame.font import Font
|
||||
|
||||
pygame.font.SysFont = pygame.sysfont.SysFont
|
||||
pygame.font.get_fonts = pygame.sysfont.get_fonts
|
||||
pygame.font.match_font = pygame.sysfont.match_font
|
||||
except (ImportError, OSError):
|
||||
font = MissingModule("font", urgent=0)
|
||||
|
||||
# try to load pygame.mixer_music before mixer, for py2app...
|
||||
try:
|
||||
import pygame.mixer_music
|
||||
|
||||
# del pygame.mixer_music
|
||||
# print("NOTE2: failed importing pygame.mixer_music in lib/__init__.py")
|
||||
except (ImportError, OSError):
|
||||
pass
|
||||
|
||||
try:
|
||||
import pygame.mixer
|
||||
from pygame.mixer import Sound
|
||||
from pygame.mixer import Channel
|
||||
except (ImportError, OSError):
|
||||
mixer = MissingModule("mixer", urgent=0)
|
||||
|
||||
try:
|
||||
import pygame.scrap
|
||||
except (ImportError, OSError):
|
||||
scrap = MissingModule("scrap", urgent=0)
|
||||
|
||||
# Two lazily imported modules to avoid loading numpy unnecessarily
|
||||
|
||||
from importlib.util import LazyLoader, find_spec, module_from_spec
|
||||
|
||||
|
||||
def lazy_import(name):
|
||||
"""Lazily import a pygame module.
|
||||
|
||||
See https://docs.python.org/3/library/importlib.html#implementing-lazy-imports
|
||||
Only load the module upon its first attribute access.
|
||||
|
||||
Lazily imported modules are directly referenced in packager_imports function.
|
||||
"""
|
||||
fullname = "pygame." + name
|
||||
spec = find_spec(fullname)
|
||||
if spec is None or spec.loader is None:
|
||||
return MissingModule(name, urgent=0)
|
||||
loader = LazyLoader(spec.loader)
|
||||
spec.loader = loader
|
||||
module = module_from_spec(spec)
|
||||
sys.modules[fullname] = module
|
||||
loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
# Check if numpy is available for surfarray and sndarray modules
|
||||
numpy_missing = find_spec("numpy") is None
|
||||
|
||||
try:
|
||||
if numpy_missing:
|
||||
# Always fails here. Need the error message for MissingModule.reason
|
||||
import numpy # pylint: disable=ungrouped-imports
|
||||
# Check that module dependencies are not missing, or get error message
|
||||
import pygame.pixelcopy # pylint: disable=ungrouped-imports
|
||||
except (ImportError, OSError):
|
||||
surfarray = MissingModule("surfarray", urgent=0)
|
||||
else:
|
||||
surfarray = lazy_import("surfarray")
|
||||
|
||||
try:
|
||||
if numpy_missing:
|
||||
# Always fails here. Need the error message for MissingModule.reason
|
||||
import numpy # pylint: disable=ungrouped-imports
|
||||
# Check that module dependencies are not missing, or get error message
|
||||
import pygame.mixer # pylint: disable=ungrouped-imports
|
||||
except (ImportError, OSError):
|
||||
sndarray = MissingModule("sndarray", urgent=0)
|
||||
else:
|
||||
sndarray = lazy_import("sndarray")
|
||||
|
||||
del LazyLoader, find_spec, lazy_import, module_from_spec, numpy_missing
|
||||
|
||||
try:
|
||||
import pygame._debug
|
||||
from pygame._debug import print_debug_info
|
||||
except (ImportError, OSError):
|
||||
debug = MissingModule("_debug", urgent=0)
|
||||
|
||||
try:
|
||||
import pygame.system
|
||||
from pygame._data_classes import PowerState as power_state
|
||||
|
||||
power_state.__module__ = "pygame.system"
|
||||
del power_state
|
||||
except (ImportError, OSError):
|
||||
system = MissingModule("system", urgent=0)
|
||||
|
||||
try:
|
||||
from pygame.window import Window
|
||||
except (ImportError, OSError):
|
||||
|
||||
def Window(title="pygame window", size=(640, 480), position=None, **kwargs): # pylint: disable=unused-argument
|
||||
_attribute_undefined("pygame.Window")
|
||||
|
||||
|
||||
try:
|
||||
import pygame.typing
|
||||
except (ImportError, OSError):
|
||||
typing = MissingModule("typing", urgent=0)
|
||||
|
||||
|
||||
# there's also a couple "internal" modules not needed
|
||||
# by users, but putting them here helps "dependency finder"
|
||||
# programs get everything they need (like py2exe)
|
||||
try:
|
||||
import pygame.imageext
|
||||
|
||||
del pygame.imageext
|
||||
except (ImportError, OSError):
|
||||
pass
|
||||
|
||||
# this internal module needs to be included for dependency
|
||||
# finders, but can't be deleted, as some tests need it
|
||||
try:
|
||||
import pygame.pkgdata
|
||||
|
||||
except (ImportError, OSError):
|
||||
pass
|
||||
|
||||
|
||||
def packager_imports():
|
||||
"""Some additional imports that py2app/py2exe will want to see.
|
||||
|
||||
This function is never executed.
|
||||
Some tools scan the source code for import statements.
|
||||
"""
|
||||
import atexit
|
||||
import numpy
|
||||
import OpenGL.GL
|
||||
import pygame.macosx
|
||||
import pygame.colordict
|
||||
|
||||
# lazy imports
|
||||
import pygame.surfarray
|
||||
import pygame.sndarray
|
||||
|
||||
|
||||
# make Rects pickleable
|
||||
|
||||
import copyreg
|
||||
|
||||
|
||||
def __rect_constructor(x, y, w, h):
|
||||
return Rect(x, y, w, h)
|
||||
|
||||
|
||||
def __rect_reduce(r):
|
||||
assert isinstance(r, Rect)
|
||||
return __rect_constructor, (r.x, r.y, r.w, r.h)
|
||||
|
||||
|
||||
copyreg.pickle(Rect, __rect_reduce, __rect_constructor)
|
||||
|
||||
|
||||
# make Colors pickleable
|
||||
def __color_constructor(r, g, b, a):
|
||||
return Color(r, g, b, a)
|
||||
|
||||
|
||||
def __color_reduce(c):
|
||||
assert isinstance(c, Color)
|
||||
return __color_constructor, (c.r, c.g, c.b, c.a)
|
||||
|
||||
|
||||
copyreg.pickle(Color, __color_reduce, __color_constructor)
|
||||
|
||||
if "PYGAME_HIDE_SUPPORT_PROMPT" not in os.environ:
|
||||
import sysconfig
|
||||
|
||||
python_version = platform.python_version()
|
||||
|
||||
if (
|
||||
sys.platform not in ("wasi", "emscripten")
|
||||
and (sys.version_info >= (3, 13, 0))
|
||||
and sysconfig.get_config_var("Py_GIL_DISABLED")
|
||||
):
|
||||
python_version += f"t, {'' if sys._is_gil_enabled() else 'No '}GIL"
|
||||
|
||||
print(
|
||||
f"pygame-ce {ver} (SDL {'.'.join(map(str, get_sdl_version()))}, "
|
||||
f"Python {python_version})"
|
||||
)
|
||||
del python_version, sysconfig
|
||||
|
||||
# cleanup namespace
|
||||
del pygame, os, sys, platform, MissingModule, copyreg, packager_imports
|
||||
@@ -0,0 +1,677 @@
|
||||
# buildconfig/stubs/gen_stubs.py
|
||||
# A script to auto-generate locals.pyi, constants.pyi and __init__.pyi typestubs
|
||||
# IMPORTANT NOTE: Do not edit this file by hand!
|
||||
# ruff: noqa: I001
|
||||
|
||||
from . import (
|
||||
display as display,
|
||||
draw as draw,
|
||||
event as event,
|
||||
font as font,
|
||||
image as image,
|
||||
key as key,
|
||||
mixer as mixer,
|
||||
mouse as mouse,
|
||||
time as time,
|
||||
cursors as cursors,
|
||||
joystick as joystick,
|
||||
math as math,
|
||||
mask as mask,
|
||||
pixelcopy as pixelcopy,
|
||||
sndarray as sndarray,
|
||||
sprite as sprite,
|
||||
surfarray as surfarray,
|
||||
transform as transform,
|
||||
scrap as scrap,
|
||||
version as version,
|
||||
base as base,
|
||||
bufferproxy as bufferproxy,
|
||||
color as color,
|
||||
colordict as colordict,
|
||||
mixer_music as mixer_music,
|
||||
pixelarray as pixelarray,
|
||||
rect as rect,
|
||||
rwobject as rwobject,
|
||||
surface as surface,
|
||||
surflock as surflock,
|
||||
sysfont as sysfont,
|
||||
_debug as _debug,
|
||||
system as system,
|
||||
geometry as geometry,
|
||||
window as window,
|
||||
typing as typing,
|
||||
)
|
||||
|
||||
from .rect import Rect as Rect, FRect as FRect
|
||||
from .surface import Surface as Surface, SurfaceType as SurfaceType
|
||||
from .color import Color as Color
|
||||
from .pixelarray import PixelArray as PixelArray
|
||||
from .math import Vector2 as Vector2, Vector3 as Vector3
|
||||
from .cursors import Cursor as Cursor
|
||||
from .bufferproxy import BufferProxy as BufferProxy
|
||||
from .mask import Mask as Mask
|
||||
from ._debug import print_debug_info as print_debug_info
|
||||
from .event import Event as Event
|
||||
from .font import Font as Font
|
||||
from .mixer import Sound as Sound, Channel as Channel
|
||||
from .time import Clock as Clock
|
||||
from .joystick import Joystick as Joystick
|
||||
from .window import Window as Window
|
||||
from .base import (
|
||||
__version__ as __version__,
|
||||
BufferError as BufferError,
|
||||
HAVE_NEWBUF as HAVE_NEWBUF,
|
||||
error as error,
|
||||
get_array_interface as get_array_interface,
|
||||
get_error as get_error,
|
||||
get_init as get_init,
|
||||
get_sdl_byteorder as get_sdl_byteorder,
|
||||
get_sdl_version as get_sdl_version,
|
||||
init as init,
|
||||
quit as quit,
|
||||
register_quit as register_quit,
|
||||
set_error as set_error,
|
||||
)
|
||||
|
||||
from .rwobject import (
|
||||
encode_file_path as encode_file_path,
|
||||
encode_string as encode_string,
|
||||
)
|
||||
|
||||
from .version import SDL as SDL, rev as rev, ver as ver, vernum as vernum
|
||||
from .constants import (
|
||||
ACTIVEEVENT as ACTIVEEVENT,
|
||||
ANYFORMAT as ANYFORMAT,
|
||||
APPACTIVE as APPACTIVE,
|
||||
APPINPUTFOCUS as APPINPUTFOCUS,
|
||||
APPMOUSEFOCUS as APPMOUSEFOCUS,
|
||||
APP_DIDENTERBACKGROUND as APP_DIDENTERBACKGROUND,
|
||||
APP_DIDENTERFOREGROUND as APP_DIDENTERFOREGROUND,
|
||||
APP_LOWMEMORY as APP_LOWMEMORY,
|
||||
APP_TERMINATING as APP_TERMINATING,
|
||||
APP_WILLENTERBACKGROUND as APP_WILLENTERBACKGROUND,
|
||||
APP_WILLENTERFOREGROUND as APP_WILLENTERFOREGROUND,
|
||||
ASYNCBLIT as ASYNCBLIT,
|
||||
AUDIODEVICEADDED as AUDIODEVICEADDED,
|
||||
AUDIODEVICEREMOVED as AUDIODEVICEREMOVED,
|
||||
AUDIO_ALLOW_ANY_CHANGE as AUDIO_ALLOW_ANY_CHANGE,
|
||||
AUDIO_ALLOW_CHANNELS_CHANGE as AUDIO_ALLOW_CHANNELS_CHANGE,
|
||||
AUDIO_ALLOW_FORMAT_CHANGE as AUDIO_ALLOW_FORMAT_CHANGE,
|
||||
AUDIO_ALLOW_FREQUENCY_CHANGE as AUDIO_ALLOW_FREQUENCY_CHANGE,
|
||||
AUDIO_S16 as AUDIO_S16,
|
||||
AUDIO_S16LSB as AUDIO_S16LSB,
|
||||
AUDIO_S16MSB as AUDIO_S16MSB,
|
||||
AUDIO_S16SYS as AUDIO_S16SYS,
|
||||
AUDIO_S8 as AUDIO_S8,
|
||||
AUDIO_U16 as AUDIO_U16,
|
||||
AUDIO_U16LSB as AUDIO_U16LSB,
|
||||
AUDIO_U16MSB as AUDIO_U16MSB,
|
||||
AUDIO_U16SYS as AUDIO_U16SYS,
|
||||
AUDIO_U8 as AUDIO_U8,
|
||||
BIG_ENDIAN as BIG_ENDIAN,
|
||||
BLENDFACTOR_DST_ALPHA as BLENDFACTOR_DST_ALPHA,
|
||||
BLENDFACTOR_DST_COLOR as BLENDFACTOR_DST_COLOR,
|
||||
BLENDFACTOR_ONE as BLENDFACTOR_ONE,
|
||||
BLENDFACTOR_ONE_MINUS_DST_ALPHA as BLENDFACTOR_ONE_MINUS_DST_ALPHA,
|
||||
BLENDFACTOR_ONE_MINUS_DST_COLOR as BLENDFACTOR_ONE_MINUS_DST_COLOR,
|
||||
BLENDFACTOR_ONE_MINUS_SRC_ALPHA as BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
BLENDFACTOR_ONE_MINUS_SRC_COLOR as BLENDFACTOR_ONE_MINUS_SRC_COLOR,
|
||||
BLENDFACTOR_SRC_ALPHA as BLENDFACTOR_SRC_ALPHA,
|
||||
BLENDFACTOR_SRC_COLOR as BLENDFACTOR_SRC_COLOR,
|
||||
BLENDFACTOR_ZERO as BLENDFACTOR_ZERO,
|
||||
BLENDMODE_ADD as BLENDMODE_ADD,
|
||||
BLENDMODE_BLEND as BLENDMODE_BLEND,
|
||||
BLENDMODE_MOD as BLENDMODE_MOD,
|
||||
BLENDMODE_MUL as BLENDMODE_MUL,
|
||||
BLENDMODE_NONE as BLENDMODE_NONE,
|
||||
BLENDOPERATION_ADD as BLENDOPERATION_ADD,
|
||||
BLENDOPERATION_MAXIMUM as BLENDOPERATION_MAXIMUM,
|
||||
BLENDOPERATION_MINIMUM as BLENDOPERATION_MINIMUM,
|
||||
BLENDOPERATION_REV_SUBTRACT as BLENDOPERATION_REV_SUBTRACT,
|
||||
BLENDOPERATION_SUBTRACT as BLENDOPERATION_SUBTRACT,
|
||||
BLEND_ADD as BLEND_ADD,
|
||||
BLEND_ALPHA_SDL2 as BLEND_ALPHA_SDL2,
|
||||
BLEND_MAX as BLEND_MAX,
|
||||
BLEND_MIN as BLEND_MIN,
|
||||
BLEND_MULT as BLEND_MULT,
|
||||
BLEND_PREMULTIPLIED as BLEND_PREMULTIPLIED,
|
||||
BLEND_RGBA_ADD as BLEND_RGBA_ADD,
|
||||
BLEND_RGBA_MAX as BLEND_RGBA_MAX,
|
||||
BLEND_RGBA_MIN as BLEND_RGBA_MIN,
|
||||
BLEND_RGBA_MULT as BLEND_RGBA_MULT,
|
||||
BLEND_RGBA_SUB as BLEND_RGBA_SUB,
|
||||
BLEND_RGB_ADD as BLEND_RGB_ADD,
|
||||
BLEND_RGB_MAX as BLEND_RGB_MAX,
|
||||
BLEND_RGB_MIN as BLEND_RGB_MIN,
|
||||
BLEND_RGB_MULT as BLEND_RGB_MULT,
|
||||
BLEND_RGB_SUB as BLEND_RGB_SUB,
|
||||
BLEND_SUB as BLEND_SUB,
|
||||
BUTTON_LEFT as BUTTON_LEFT,
|
||||
BUTTON_MIDDLE as BUTTON_MIDDLE,
|
||||
BUTTON_RIGHT as BUTTON_RIGHT,
|
||||
BUTTON_WHEELDOWN as BUTTON_WHEELDOWN,
|
||||
BUTTON_WHEELUP as BUTTON_WHEELUP,
|
||||
BUTTON_X1 as BUTTON_X1,
|
||||
BUTTON_X2 as BUTTON_X2,
|
||||
CLIPBOARDUPDATE as CLIPBOARDUPDATE,
|
||||
CONTROLLERAXISMOTION as CONTROLLERAXISMOTION,
|
||||
CONTROLLERBUTTONDOWN as CONTROLLERBUTTONDOWN,
|
||||
CONTROLLERBUTTONUP as CONTROLLERBUTTONUP,
|
||||
CONTROLLERDEVICEADDED as CONTROLLERDEVICEADDED,
|
||||
CONTROLLERDEVICEREMAPPED as CONTROLLERDEVICEREMAPPED,
|
||||
CONTROLLERDEVICEREMOVED as CONTROLLERDEVICEREMOVED,
|
||||
CONTROLLERSENSORUPDATE as CONTROLLERSENSORUPDATE,
|
||||
CONTROLLERTOUCHPADDOWN as CONTROLLERTOUCHPADDOWN,
|
||||
CONTROLLERTOUCHPADMOTION as CONTROLLERTOUCHPADMOTION,
|
||||
CONTROLLERTOUCHPADUP as CONTROLLERTOUCHPADUP,
|
||||
CONTROLLER_AXIS_INVALID as CONTROLLER_AXIS_INVALID,
|
||||
CONTROLLER_AXIS_LEFTX as CONTROLLER_AXIS_LEFTX,
|
||||
CONTROLLER_AXIS_LEFTY as CONTROLLER_AXIS_LEFTY,
|
||||
CONTROLLER_AXIS_MAX as CONTROLLER_AXIS_MAX,
|
||||
CONTROLLER_AXIS_RIGHTX as CONTROLLER_AXIS_RIGHTX,
|
||||
CONTROLLER_AXIS_RIGHTY as CONTROLLER_AXIS_RIGHTY,
|
||||
CONTROLLER_AXIS_TRIGGERLEFT as CONTROLLER_AXIS_TRIGGERLEFT,
|
||||
CONTROLLER_AXIS_TRIGGERRIGHT as CONTROLLER_AXIS_TRIGGERRIGHT,
|
||||
CONTROLLER_BUTTON_A as CONTROLLER_BUTTON_A,
|
||||
CONTROLLER_BUTTON_B as CONTROLLER_BUTTON_B,
|
||||
CONTROLLER_BUTTON_BACK as CONTROLLER_BUTTON_BACK,
|
||||
CONTROLLER_BUTTON_DPAD_DOWN as CONTROLLER_BUTTON_DPAD_DOWN,
|
||||
CONTROLLER_BUTTON_DPAD_LEFT as CONTROLLER_BUTTON_DPAD_LEFT,
|
||||
CONTROLLER_BUTTON_DPAD_RIGHT as CONTROLLER_BUTTON_DPAD_RIGHT,
|
||||
CONTROLLER_BUTTON_DPAD_UP as CONTROLLER_BUTTON_DPAD_UP,
|
||||
CONTROLLER_BUTTON_GUIDE as CONTROLLER_BUTTON_GUIDE,
|
||||
CONTROLLER_BUTTON_INVALID as CONTROLLER_BUTTON_INVALID,
|
||||
CONTROLLER_BUTTON_LEFTSHOULDER as CONTROLLER_BUTTON_LEFTSHOULDER,
|
||||
CONTROLLER_BUTTON_LEFTSTICK as CONTROLLER_BUTTON_LEFTSTICK,
|
||||
CONTROLLER_BUTTON_MAX as CONTROLLER_BUTTON_MAX,
|
||||
CONTROLLER_BUTTON_RIGHTSHOULDER as CONTROLLER_BUTTON_RIGHTSHOULDER,
|
||||
CONTROLLER_BUTTON_RIGHTSTICK as CONTROLLER_BUTTON_RIGHTSTICK,
|
||||
CONTROLLER_BUTTON_START as CONTROLLER_BUTTON_START,
|
||||
CONTROLLER_BUTTON_X as CONTROLLER_BUTTON_X,
|
||||
CONTROLLER_BUTTON_Y as CONTROLLER_BUTTON_Y,
|
||||
DIRECTION_BTT as DIRECTION_BTT,
|
||||
DIRECTION_LTR as DIRECTION_LTR,
|
||||
DIRECTION_RTL as DIRECTION_RTL,
|
||||
DIRECTION_TTB as DIRECTION_TTB,
|
||||
DOUBLEBUF as DOUBLEBUF,
|
||||
DROPBEGIN as DROPBEGIN,
|
||||
DROPCOMPLETE as DROPCOMPLETE,
|
||||
DROPFILE as DROPFILE,
|
||||
DROPTEXT as DROPTEXT,
|
||||
FINGERDOWN as FINGERDOWN,
|
||||
FINGERMOTION as FINGERMOTION,
|
||||
FINGERUP as FINGERUP,
|
||||
FLASH_BRIEFLY as FLASH_BRIEFLY,
|
||||
FLASH_CANCEL as FLASH_CANCEL,
|
||||
FLASH_UNTIL_FOCUSED as FLASH_UNTIL_FOCUSED,
|
||||
FLIP_HORIZONTAL as FLIP_HORIZONTAL,
|
||||
FLIP_NONE as FLIP_NONE,
|
||||
FLIP_VERTICAL as FLIP_VERTICAL,
|
||||
FONT_CENTER as FONT_CENTER,
|
||||
FONT_LEFT as FONT_LEFT,
|
||||
FONT_RIGHT as FONT_RIGHT,
|
||||
FULLSCREEN as FULLSCREEN,
|
||||
GL_ACCELERATED_VISUAL as GL_ACCELERATED_VISUAL,
|
||||
GL_ACCUM_ALPHA_SIZE as GL_ACCUM_ALPHA_SIZE,
|
||||
GL_ACCUM_BLUE_SIZE as GL_ACCUM_BLUE_SIZE,
|
||||
GL_ACCUM_GREEN_SIZE as GL_ACCUM_GREEN_SIZE,
|
||||
GL_ACCUM_RED_SIZE as GL_ACCUM_RED_SIZE,
|
||||
GL_ALPHA_SIZE as GL_ALPHA_SIZE,
|
||||
GL_BLUE_SIZE as GL_BLUE_SIZE,
|
||||
GL_BUFFER_SIZE as GL_BUFFER_SIZE,
|
||||
GL_CONTEXT_DEBUG_FLAG as GL_CONTEXT_DEBUG_FLAG,
|
||||
GL_CONTEXT_FLAGS as GL_CONTEXT_FLAGS,
|
||||
GL_CONTEXT_FORWARD_COMPATIBLE_FLAG as GL_CONTEXT_FORWARD_COMPATIBLE_FLAG,
|
||||
GL_CONTEXT_MAJOR_VERSION as GL_CONTEXT_MAJOR_VERSION,
|
||||
GL_CONTEXT_MINOR_VERSION as GL_CONTEXT_MINOR_VERSION,
|
||||
GL_CONTEXT_PROFILE_COMPATIBILITY as GL_CONTEXT_PROFILE_COMPATIBILITY,
|
||||
GL_CONTEXT_PROFILE_CORE as GL_CONTEXT_PROFILE_CORE,
|
||||
GL_CONTEXT_PROFILE_ES as GL_CONTEXT_PROFILE_ES,
|
||||
GL_CONTEXT_PROFILE_MASK as GL_CONTEXT_PROFILE_MASK,
|
||||
GL_CONTEXT_RELEASE_BEHAVIOR as GL_CONTEXT_RELEASE_BEHAVIOR,
|
||||
GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH as GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH,
|
||||
GL_CONTEXT_RELEASE_BEHAVIOR_NONE as GL_CONTEXT_RELEASE_BEHAVIOR_NONE,
|
||||
GL_CONTEXT_RESET_ISOLATION_FLAG as GL_CONTEXT_RESET_ISOLATION_FLAG,
|
||||
GL_CONTEXT_ROBUST_ACCESS_FLAG as GL_CONTEXT_ROBUST_ACCESS_FLAG,
|
||||
GL_DEPTH_SIZE as GL_DEPTH_SIZE,
|
||||
GL_DOUBLEBUFFER as GL_DOUBLEBUFFER,
|
||||
GL_FRAMEBUFFER_SRGB_CAPABLE as GL_FRAMEBUFFER_SRGB_CAPABLE,
|
||||
GL_GREEN_SIZE as GL_GREEN_SIZE,
|
||||
GL_MULTISAMPLEBUFFERS as GL_MULTISAMPLEBUFFERS,
|
||||
GL_MULTISAMPLESAMPLES as GL_MULTISAMPLESAMPLES,
|
||||
GL_RED_SIZE as GL_RED_SIZE,
|
||||
GL_SHARE_WITH_CURRENT_CONTEXT as GL_SHARE_WITH_CURRENT_CONTEXT,
|
||||
GL_STENCIL_SIZE as GL_STENCIL_SIZE,
|
||||
GL_STEREO as GL_STEREO,
|
||||
GL_SWAP_CONTROL as GL_SWAP_CONTROL,
|
||||
HAT_CENTERED as HAT_CENTERED,
|
||||
HAT_DOWN as HAT_DOWN,
|
||||
HAT_LEFT as HAT_LEFT,
|
||||
HAT_LEFTDOWN as HAT_LEFTDOWN,
|
||||
HAT_LEFTUP as HAT_LEFTUP,
|
||||
HAT_RIGHT as HAT_RIGHT,
|
||||
HAT_RIGHTDOWN as HAT_RIGHTDOWN,
|
||||
HAT_RIGHTUP as HAT_RIGHTUP,
|
||||
HAT_UP as HAT_UP,
|
||||
HIDDEN as HIDDEN,
|
||||
HWACCEL as HWACCEL,
|
||||
HWPALETTE as HWPALETTE,
|
||||
HWSURFACE as HWSURFACE,
|
||||
IS_CE as IS_CE,
|
||||
JOYAXISMOTION as JOYAXISMOTION,
|
||||
JOYBALLMOTION as JOYBALLMOTION,
|
||||
JOYBUTTONDOWN as JOYBUTTONDOWN,
|
||||
JOYBUTTONUP as JOYBUTTONUP,
|
||||
JOYDEVICEADDED as JOYDEVICEADDED,
|
||||
JOYDEVICEREMOVED as JOYDEVICEREMOVED,
|
||||
JOYHATMOTION as JOYHATMOTION,
|
||||
KEYDOWN as KEYDOWN,
|
||||
KEYMAPCHANGED as KEYMAPCHANGED,
|
||||
KEYUP as KEYUP,
|
||||
KMOD_ALT as KMOD_ALT,
|
||||
KMOD_CAPS as KMOD_CAPS,
|
||||
KMOD_CTRL as KMOD_CTRL,
|
||||
KMOD_GUI as KMOD_GUI,
|
||||
KMOD_LALT as KMOD_LALT,
|
||||
KMOD_LCTRL as KMOD_LCTRL,
|
||||
KMOD_LGUI as KMOD_LGUI,
|
||||
KMOD_LMETA as KMOD_LMETA,
|
||||
KMOD_LSHIFT as KMOD_LSHIFT,
|
||||
KMOD_META as KMOD_META,
|
||||
KMOD_MODE as KMOD_MODE,
|
||||
KMOD_NONE as KMOD_NONE,
|
||||
KMOD_NUM as KMOD_NUM,
|
||||
KMOD_RALT as KMOD_RALT,
|
||||
KMOD_RCTRL as KMOD_RCTRL,
|
||||
KMOD_RGUI as KMOD_RGUI,
|
||||
KMOD_RMETA as KMOD_RMETA,
|
||||
KMOD_RSHIFT as KMOD_RSHIFT,
|
||||
KMOD_SHIFT as KMOD_SHIFT,
|
||||
KSCAN_0 as KSCAN_0,
|
||||
KSCAN_1 as KSCAN_1,
|
||||
KSCAN_2 as KSCAN_2,
|
||||
KSCAN_3 as KSCAN_3,
|
||||
KSCAN_4 as KSCAN_4,
|
||||
KSCAN_5 as KSCAN_5,
|
||||
KSCAN_6 as KSCAN_6,
|
||||
KSCAN_7 as KSCAN_7,
|
||||
KSCAN_8 as KSCAN_8,
|
||||
KSCAN_9 as KSCAN_9,
|
||||
KSCAN_A as KSCAN_A,
|
||||
KSCAN_AC_BACK as KSCAN_AC_BACK,
|
||||
KSCAN_APOSTROPHE as KSCAN_APOSTROPHE,
|
||||
KSCAN_B as KSCAN_B,
|
||||
KSCAN_BACKSLASH as KSCAN_BACKSLASH,
|
||||
KSCAN_BACKSPACE as KSCAN_BACKSPACE,
|
||||
KSCAN_BREAK as KSCAN_BREAK,
|
||||
KSCAN_C as KSCAN_C,
|
||||
KSCAN_CAPSLOCK as KSCAN_CAPSLOCK,
|
||||
KSCAN_CLEAR as KSCAN_CLEAR,
|
||||
KSCAN_COMMA as KSCAN_COMMA,
|
||||
KSCAN_CURRENCYSUBUNIT as KSCAN_CURRENCYSUBUNIT,
|
||||
KSCAN_CURRENCYUNIT as KSCAN_CURRENCYUNIT,
|
||||
KSCAN_D as KSCAN_D,
|
||||
KSCAN_DELETE as KSCAN_DELETE,
|
||||
KSCAN_DOWN as KSCAN_DOWN,
|
||||
KSCAN_E as KSCAN_E,
|
||||
KSCAN_END as KSCAN_END,
|
||||
KSCAN_EQUALS as KSCAN_EQUALS,
|
||||
KSCAN_ESCAPE as KSCAN_ESCAPE,
|
||||
KSCAN_EURO as KSCAN_EURO,
|
||||
KSCAN_F as KSCAN_F,
|
||||
KSCAN_F1 as KSCAN_F1,
|
||||
KSCAN_F10 as KSCAN_F10,
|
||||
KSCAN_F11 as KSCAN_F11,
|
||||
KSCAN_F12 as KSCAN_F12,
|
||||
KSCAN_F13 as KSCAN_F13,
|
||||
KSCAN_F14 as KSCAN_F14,
|
||||
KSCAN_F15 as KSCAN_F15,
|
||||
KSCAN_F2 as KSCAN_F2,
|
||||
KSCAN_F3 as KSCAN_F3,
|
||||
KSCAN_F4 as KSCAN_F4,
|
||||
KSCAN_F5 as KSCAN_F5,
|
||||
KSCAN_F6 as KSCAN_F6,
|
||||
KSCAN_F7 as KSCAN_F7,
|
||||
KSCAN_F8 as KSCAN_F8,
|
||||
KSCAN_F9 as KSCAN_F9,
|
||||
KSCAN_G as KSCAN_G,
|
||||
KSCAN_GRAVE as KSCAN_GRAVE,
|
||||
KSCAN_H as KSCAN_H,
|
||||
KSCAN_HELP as KSCAN_HELP,
|
||||
KSCAN_HOME as KSCAN_HOME,
|
||||
KSCAN_I as KSCAN_I,
|
||||
KSCAN_INSERT as KSCAN_INSERT,
|
||||
KSCAN_INTERNATIONAL1 as KSCAN_INTERNATIONAL1,
|
||||
KSCAN_INTERNATIONAL2 as KSCAN_INTERNATIONAL2,
|
||||
KSCAN_INTERNATIONAL3 as KSCAN_INTERNATIONAL3,
|
||||
KSCAN_INTERNATIONAL4 as KSCAN_INTERNATIONAL4,
|
||||
KSCAN_INTERNATIONAL5 as KSCAN_INTERNATIONAL5,
|
||||
KSCAN_INTERNATIONAL6 as KSCAN_INTERNATIONAL6,
|
||||
KSCAN_INTERNATIONAL7 as KSCAN_INTERNATIONAL7,
|
||||
KSCAN_INTERNATIONAL8 as KSCAN_INTERNATIONAL8,
|
||||
KSCAN_INTERNATIONAL9 as KSCAN_INTERNATIONAL9,
|
||||
KSCAN_J as KSCAN_J,
|
||||
KSCAN_K as KSCAN_K,
|
||||
KSCAN_KP0 as KSCAN_KP0,
|
||||
KSCAN_KP1 as KSCAN_KP1,
|
||||
KSCAN_KP2 as KSCAN_KP2,
|
||||
KSCAN_KP3 as KSCAN_KP3,
|
||||
KSCAN_KP4 as KSCAN_KP4,
|
||||
KSCAN_KP5 as KSCAN_KP5,
|
||||
KSCAN_KP6 as KSCAN_KP6,
|
||||
KSCAN_KP7 as KSCAN_KP7,
|
||||
KSCAN_KP8 as KSCAN_KP8,
|
||||
KSCAN_KP9 as KSCAN_KP9,
|
||||
KSCAN_KP_0 as KSCAN_KP_0,
|
||||
KSCAN_KP_1 as KSCAN_KP_1,
|
||||
KSCAN_KP_2 as KSCAN_KP_2,
|
||||
KSCAN_KP_3 as KSCAN_KP_3,
|
||||
KSCAN_KP_4 as KSCAN_KP_4,
|
||||
KSCAN_KP_5 as KSCAN_KP_5,
|
||||
KSCAN_KP_6 as KSCAN_KP_6,
|
||||
KSCAN_KP_7 as KSCAN_KP_7,
|
||||
KSCAN_KP_8 as KSCAN_KP_8,
|
||||
KSCAN_KP_9 as KSCAN_KP_9,
|
||||
KSCAN_KP_DIVIDE as KSCAN_KP_DIVIDE,
|
||||
KSCAN_KP_ENTER as KSCAN_KP_ENTER,
|
||||
KSCAN_KP_EQUALS as KSCAN_KP_EQUALS,
|
||||
KSCAN_KP_MINUS as KSCAN_KP_MINUS,
|
||||
KSCAN_KP_MULTIPLY as KSCAN_KP_MULTIPLY,
|
||||
KSCAN_KP_PERIOD as KSCAN_KP_PERIOD,
|
||||
KSCAN_KP_PLUS as KSCAN_KP_PLUS,
|
||||
KSCAN_L as KSCAN_L,
|
||||
KSCAN_LALT as KSCAN_LALT,
|
||||
KSCAN_LANG1 as KSCAN_LANG1,
|
||||
KSCAN_LANG2 as KSCAN_LANG2,
|
||||
KSCAN_LANG3 as KSCAN_LANG3,
|
||||
KSCAN_LANG4 as KSCAN_LANG4,
|
||||
KSCAN_LANG5 as KSCAN_LANG5,
|
||||
KSCAN_LANG6 as KSCAN_LANG6,
|
||||
KSCAN_LANG7 as KSCAN_LANG7,
|
||||
KSCAN_LANG8 as KSCAN_LANG8,
|
||||
KSCAN_LANG9 as KSCAN_LANG9,
|
||||
KSCAN_LCTRL as KSCAN_LCTRL,
|
||||
KSCAN_LEFT as KSCAN_LEFT,
|
||||
KSCAN_LEFTBRACKET as KSCAN_LEFTBRACKET,
|
||||
KSCAN_LGUI as KSCAN_LGUI,
|
||||
KSCAN_LMETA as KSCAN_LMETA,
|
||||
KSCAN_LSHIFT as KSCAN_LSHIFT,
|
||||
KSCAN_LSUPER as KSCAN_LSUPER,
|
||||
KSCAN_M as KSCAN_M,
|
||||
KSCAN_MENU as KSCAN_MENU,
|
||||
KSCAN_MINUS as KSCAN_MINUS,
|
||||
KSCAN_MODE as KSCAN_MODE,
|
||||
KSCAN_N as KSCAN_N,
|
||||
KSCAN_NONUSBACKSLASH as KSCAN_NONUSBACKSLASH,
|
||||
KSCAN_NONUSHASH as KSCAN_NONUSHASH,
|
||||
KSCAN_NUMLOCK as KSCAN_NUMLOCK,
|
||||
KSCAN_NUMLOCKCLEAR as KSCAN_NUMLOCKCLEAR,
|
||||
KSCAN_O as KSCAN_O,
|
||||
KSCAN_P as KSCAN_P,
|
||||
KSCAN_PAGEDOWN as KSCAN_PAGEDOWN,
|
||||
KSCAN_PAGEUP as KSCAN_PAGEUP,
|
||||
KSCAN_PAUSE as KSCAN_PAUSE,
|
||||
KSCAN_PERIOD as KSCAN_PERIOD,
|
||||
KSCAN_POWER as KSCAN_POWER,
|
||||
KSCAN_PRINT as KSCAN_PRINT,
|
||||
KSCAN_PRINTSCREEN as KSCAN_PRINTSCREEN,
|
||||
KSCAN_Q as KSCAN_Q,
|
||||
KSCAN_R as KSCAN_R,
|
||||
KSCAN_RALT as KSCAN_RALT,
|
||||
KSCAN_RCTRL as KSCAN_RCTRL,
|
||||
KSCAN_RETURN as KSCAN_RETURN,
|
||||
KSCAN_RGUI as KSCAN_RGUI,
|
||||
KSCAN_RIGHT as KSCAN_RIGHT,
|
||||
KSCAN_RIGHTBRACKET as KSCAN_RIGHTBRACKET,
|
||||
KSCAN_RMETA as KSCAN_RMETA,
|
||||
KSCAN_RSHIFT as KSCAN_RSHIFT,
|
||||
KSCAN_RSUPER as KSCAN_RSUPER,
|
||||
KSCAN_S as KSCAN_S,
|
||||
KSCAN_SCROLLLOCK as KSCAN_SCROLLLOCK,
|
||||
KSCAN_SCROLLOCK as KSCAN_SCROLLOCK,
|
||||
KSCAN_SEMICOLON as KSCAN_SEMICOLON,
|
||||
KSCAN_SLASH as KSCAN_SLASH,
|
||||
KSCAN_SPACE as KSCAN_SPACE,
|
||||
KSCAN_SYSREQ as KSCAN_SYSREQ,
|
||||
KSCAN_T as KSCAN_T,
|
||||
KSCAN_TAB as KSCAN_TAB,
|
||||
KSCAN_U as KSCAN_U,
|
||||
KSCAN_UNKNOWN as KSCAN_UNKNOWN,
|
||||
KSCAN_UP as KSCAN_UP,
|
||||
KSCAN_V as KSCAN_V,
|
||||
KSCAN_W as KSCAN_W,
|
||||
KSCAN_X as KSCAN_X,
|
||||
KSCAN_Y as KSCAN_Y,
|
||||
KSCAN_Z as KSCAN_Z,
|
||||
K_0 as K_0,
|
||||
K_1 as K_1,
|
||||
K_2 as K_2,
|
||||
K_3 as K_3,
|
||||
K_4 as K_4,
|
||||
K_5 as K_5,
|
||||
K_6 as K_6,
|
||||
K_7 as K_7,
|
||||
K_8 as K_8,
|
||||
K_9 as K_9,
|
||||
K_AC_BACK as K_AC_BACK,
|
||||
K_AMPERSAND as K_AMPERSAND,
|
||||
K_ASTERISK as K_ASTERISK,
|
||||
K_AT as K_AT,
|
||||
K_BACKQUOTE as K_BACKQUOTE,
|
||||
K_BACKSLASH as K_BACKSLASH,
|
||||
K_BACKSPACE as K_BACKSPACE,
|
||||
K_BREAK as K_BREAK,
|
||||
K_CAPSLOCK as K_CAPSLOCK,
|
||||
K_CARET as K_CARET,
|
||||
K_CLEAR as K_CLEAR,
|
||||
K_COLON as K_COLON,
|
||||
K_COMMA as K_COMMA,
|
||||
K_CURRENCYSUBUNIT as K_CURRENCYSUBUNIT,
|
||||
K_CURRENCYUNIT as K_CURRENCYUNIT,
|
||||
K_DELETE as K_DELETE,
|
||||
K_DOLLAR as K_DOLLAR,
|
||||
K_DOWN as K_DOWN,
|
||||
K_END as K_END,
|
||||
K_EQUALS as K_EQUALS,
|
||||
K_ESCAPE as K_ESCAPE,
|
||||
K_EURO as K_EURO,
|
||||
K_EXCLAIM as K_EXCLAIM,
|
||||
K_F1 as K_F1,
|
||||
K_F10 as K_F10,
|
||||
K_F11 as K_F11,
|
||||
K_F12 as K_F12,
|
||||
K_F13 as K_F13,
|
||||
K_F14 as K_F14,
|
||||
K_F15 as K_F15,
|
||||
K_F2 as K_F2,
|
||||
K_F3 as K_F3,
|
||||
K_F4 as K_F4,
|
||||
K_F5 as K_F5,
|
||||
K_F6 as K_F6,
|
||||
K_F7 as K_F7,
|
||||
K_F8 as K_F8,
|
||||
K_F9 as K_F9,
|
||||
K_GREATER as K_GREATER,
|
||||
K_HASH as K_HASH,
|
||||
K_HELP as K_HELP,
|
||||
K_HOME as K_HOME,
|
||||
K_INSERT as K_INSERT,
|
||||
K_KP0 as K_KP0,
|
||||
K_KP1 as K_KP1,
|
||||
K_KP2 as K_KP2,
|
||||
K_KP3 as K_KP3,
|
||||
K_KP4 as K_KP4,
|
||||
K_KP5 as K_KP5,
|
||||
K_KP6 as K_KP6,
|
||||
K_KP7 as K_KP7,
|
||||
K_KP8 as K_KP8,
|
||||
K_KP9 as K_KP9,
|
||||
K_KP_0 as K_KP_0,
|
||||
K_KP_1 as K_KP_1,
|
||||
K_KP_2 as K_KP_2,
|
||||
K_KP_3 as K_KP_3,
|
||||
K_KP_4 as K_KP_4,
|
||||
K_KP_5 as K_KP_5,
|
||||
K_KP_6 as K_KP_6,
|
||||
K_KP_7 as K_KP_7,
|
||||
K_KP_8 as K_KP_8,
|
||||
K_KP_9 as K_KP_9,
|
||||
K_KP_DIVIDE as K_KP_DIVIDE,
|
||||
K_KP_ENTER as K_KP_ENTER,
|
||||
K_KP_EQUALS as K_KP_EQUALS,
|
||||
K_KP_MINUS as K_KP_MINUS,
|
||||
K_KP_MULTIPLY as K_KP_MULTIPLY,
|
||||
K_KP_PERIOD as K_KP_PERIOD,
|
||||
K_KP_PLUS as K_KP_PLUS,
|
||||
K_LALT as K_LALT,
|
||||
K_LCTRL as K_LCTRL,
|
||||
K_LEFT as K_LEFT,
|
||||
K_LEFTBRACKET as K_LEFTBRACKET,
|
||||
K_LEFTPAREN as K_LEFTPAREN,
|
||||
K_LESS as K_LESS,
|
||||
K_LGUI as K_LGUI,
|
||||
K_LMETA as K_LMETA,
|
||||
K_LSHIFT as K_LSHIFT,
|
||||
K_LSUPER as K_LSUPER,
|
||||
K_MENU as K_MENU,
|
||||
K_MINUS as K_MINUS,
|
||||
K_MODE as K_MODE,
|
||||
K_NUMLOCK as K_NUMLOCK,
|
||||
K_NUMLOCKCLEAR as K_NUMLOCKCLEAR,
|
||||
K_PAGEDOWN as K_PAGEDOWN,
|
||||
K_PAGEUP as K_PAGEUP,
|
||||
K_PAUSE as K_PAUSE,
|
||||
K_PERCENT as K_PERCENT,
|
||||
K_PERIOD as K_PERIOD,
|
||||
K_PLUS as K_PLUS,
|
||||
K_POWER as K_POWER,
|
||||
K_PRINT as K_PRINT,
|
||||
K_PRINTSCREEN as K_PRINTSCREEN,
|
||||
K_QUESTION as K_QUESTION,
|
||||
K_QUOTE as K_QUOTE,
|
||||
K_QUOTEDBL as K_QUOTEDBL,
|
||||
K_RALT as K_RALT,
|
||||
K_RCTRL as K_RCTRL,
|
||||
K_RETURN as K_RETURN,
|
||||
K_RGUI as K_RGUI,
|
||||
K_RIGHT as K_RIGHT,
|
||||
K_RIGHTBRACKET as K_RIGHTBRACKET,
|
||||
K_RIGHTPAREN as K_RIGHTPAREN,
|
||||
K_RMETA as K_RMETA,
|
||||
K_RSHIFT as K_RSHIFT,
|
||||
K_RSUPER as K_RSUPER,
|
||||
K_SCROLLLOCK as K_SCROLLLOCK,
|
||||
K_SCROLLOCK as K_SCROLLOCK,
|
||||
K_SEMICOLON as K_SEMICOLON,
|
||||
K_SLASH as K_SLASH,
|
||||
K_SPACE as K_SPACE,
|
||||
K_SYSREQ as K_SYSREQ,
|
||||
K_TAB as K_TAB,
|
||||
K_UNDERSCORE as K_UNDERSCORE,
|
||||
K_UNKNOWN as K_UNKNOWN,
|
||||
K_UP as K_UP,
|
||||
K_a as K_a,
|
||||
K_b as K_b,
|
||||
K_c as K_c,
|
||||
K_d as K_d,
|
||||
K_e as K_e,
|
||||
K_f as K_f,
|
||||
K_g as K_g,
|
||||
K_h as K_h,
|
||||
K_i as K_i,
|
||||
K_j as K_j,
|
||||
K_k as K_k,
|
||||
K_l as K_l,
|
||||
K_m as K_m,
|
||||
K_n as K_n,
|
||||
K_o as K_o,
|
||||
K_p as K_p,
|
||||
K_q as K_q,
|
||||
K_r as K_r,
|
||||
K_s as K_s,
|
||||
K_t as K_t,
|
||||
K_u as K_u,
|
||||
K_v as K_v,
|
||||
K_w as K_w,
|
||||
K_x as K_x,
|
||||
K_y as K_y,
|
||||
K_z as K_z,
|
||||
LIL_ENDIAN as LIL_ENDIAN,
|
||||
LOCALECHANGED as LOCALECHANGED,
|
||||
MIDIIN as MIDIIN,
|
||||
MIDIOUT as MIDIOUT,
|
||||
MOUSEBUTTONDOWN as MOUSEBUTTONDOWN,
|
||||
MOUSEBUTTONUP as MOUSEBUTTONUP,
|
||||
MOUSEMOTION as MOUSEMOTION,
|
||||
MOUSEWHEEL as MOUSEWHEEL,
|
||||
MULTIGESTURE as MULTIGESTURE,
|
||||
NOEVENT as NOEVENT,
|
||||
NOFRAME as NOFRAME,
|
||||
NULL_VIDEODRIVER as NULL_VIDEODRIVER,
|
||||
NUMEVENTS as NUMEVENTS,
|
||||
OPENGL as OPENGL,
|
||||
OPENGLBLIT as OPENGLBLIT,
|
||||
PREALLOC as PREALLOC,
|
||||
QUIT as QUIT,
|
||||
RENDER_DEVICE_RESET as RENDER_DEVICE_RESET,
|
||||
RENDER_TARGETS_RESET as RENDER_TARGETS_RESET,
|
||||
RESIZABLE as RESIZABLE,
|
||||
RLEACCEL as RLEACCEL,
|
||||
RLEACCELOK as RLEACCELOK,
|
||||
SCALED as SCALED,
|
||||
SCRAP_BMP as SCRAP_BMP,
|
||||
SCRAP_CLIPBOARD as SCRAP_CLIPBOARD,
|
||||
SCRAP_PBM as SCRAP_PBM,
|
||||
SCRAP_PPM as SCRAP_PPM,
|
||||
SCRAP_SELECTION as SCRAP_SELECTION,
|
||||
SCRAP_TEXT as SCRAP_TEXT,
|
||||
SCROLL_ERASE as SCROLL_ERASE,
|
||||
SCROLL_REPEAT as SCROLL_REPEAT,
|
||||
SHOWN as SHOWN,
|
||||
SRCALPHA as SRCALPHA,
|
||||
SRCCOLORKEY as SRCCOLORKEY,
|
||||
SWSURFACE as SWSURFACE,
|
||||
SYSTEM_CURSOR_ARROW as SYSTEM_CURSOR_ARROW,
|
||||
SYSTEM_CURSOR_CROSSHAIR as SYSTEM_CURSOR_CROSSHAIR,
|
||||
SYSTEM_CURSOR_HAND as SYSTEM_CURSOR_HAND,
|
||||
SYSTEM_CURSOR_IBEAM as SYSTEM_CURSOR_IBEAM,
|
||||
SYSTEM_CURSOR_NO as SYSTEM_CURSOR_NO,
|
||||
SYSTEM_CURSOR_SIZEALL as SYSTEM_CURSOR_SIZEALL,
|
||||
SYSTEM_CURSOR_SIZENESW as SYSTEM_CURSOR_SIZENESW,
|
||||
SYSTEM_CURSOR_SIZENS as SYSTEM_CURSOR_SIZENS,
|
||||
SYSTEM_CURSOR_SIZENWSE as SYSTEM_CURSOR_SIZENWSE,
|
||||
SYSTEM_CURSOR_SIZEWE as SYSTEM_CURSOR_SIZEWE,
|
||||
SYSTEM_CURSOR_WAIT as SYSTEM_CURSOR_WAIT,
|
||||
SYSTEM_CURSOR_WAITARROW as SYSTEM_CURSOR_WAITARROW,
|
||||
SYSWMEVENT as SYSWMEVENT,
|
||||
TEXTEDITING as TEXTEDITING,
|
||||
TEXTINPUT as TEXTINPUT,
|
||||
TEXTUREACCESS_STATIC as TEXTUREACCESS_STATIC,
|
||||
TEXTUREACCESS_STREAMING as TEXTUREACCESS_STREAMING,
|
||||
TEXTUREACCESS_TARGET as TEXTUREACCESS_TARGET,
|
||||
TIMER_RESOLUTION as TIMER_RESOLUTION,
|
||||
USEREVENT as USEREVENT,
|
||||
USEREVENT_DROPFILE as USEREVENT_DROPFILE,
|
||||
VIDEOEXPOSE as VIDEOEXPOSE,
|
||||
VIDEORESIZE as VIDEORESIZE,
|
||||
WINDOWCLOSE as WINDOWCLOSE,
|
||||
WINDOWDISPLAYCHANGED as WINDOWDISPLAYCHANGED,
|
||||
WINDOWENTER as WINDOWENTER,
|
||||
WINDOWEXPOSED as WINDOWEXPOSED,
|
||||
WINDOWFOCUSGAINED as WINDOWFOCUSGAINED,
|
||||
WINDOWFOCUSLOST as WINDOWFOCUSLOST,
|
||||
WINDOWHIDDEN as WINDOWHIDDEN,
|
||||
WINDOWHITTEST as WINDOWHITTEST,
|
||||
WINDOWICCPROFCHANGED as WINDOWICCPROFCHANGED,
|
||||
WINDOWLEAVE as WINDOWLEAVE,
|
||||
WINDOWMAXIMIZED as WINDOWMAXIMIZED,
|
||||
WINDOWMINIMIZED as WINDOWMINIMIZED,
|
||||
WINDOWMOVED as WINDOWMOVED,
|
||||
WINDOWPOS_CENTERED as WINDOWPOS_CENTERED,
|
||||
WINDOWPOS_UNDEFINED as WINDOWPOS_UNDEFINED,
|
||||
WINDOWRESIZED as WINDOWRESIZED,
|
||||
WINDOWRESTORED as WINDOWRESTORED,
|
||||
WINDOWSHOWN as WINDOWSHOWN,
|
||||
WINDOWSIZECHANGED as WINDOWSIZECHANGED,
|
||||
WINDOWTAKEFOCUS as WINDOWTAKEFOCUS,
|
||||
)
|
||||
@@ -0,0 +1,5 @@
|
||||
import os
|
||||
|
||||
|
||||
def get_hook_dirs():
|
||||
return [os.path.dirname(__file__)]
|
||||
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
binaries hook for pygame seems to be required for pygame 2.0 Windows.
|
||||
Otherwise, some essential DLLs will not be transferred to the exe.
|
||||
|
||||
And also put hooks for datas, resources that pygame uses, to work
|
||||
correctly with pyinstaller
|
||||
"""
|
||||
|
||||
import os
|
||||
import platform
|
||||
|
||||
from pygame import __file__ as pygame_main_file
|
||||
|
||||
# Get pygame's folder
|
||||
pygame_folder = os.path.dirname(os.path.abspath(pygame_main_file))
|
||||
|
||||
# datas is the variable that pyinstaller looks for while processing hooks
|
||||
datas = []
|
||||
|
||||
|
||||
# A helper to append the relative path of a resource to hook variable - datas
|
||||
def _append_to_datas(file_path):
|
||||
res_path = os.path.join(pygame_folder, file_path)
|
||||
if os.path.exists(res_path):
|
||||
datas.append((res_path, "pygame"))
|
||||
|
||||
|
||||
# First append the font file, then based on the OS, append pygame icon file
|
||||
_append_to_datas("freesansbold.ttf")
|
||||
if platform.system() == "Darwin":
|
||||
_append_to_datas("pygame_icon_mac.bmp")
|
||||
else:
|
||||
_append_to_datas("pygame_icon.bmp")
|
||||
|
||||
if platform.system() == "Windows":
|
||||
from PyInstaller.utils.hooks import collect_dynamic_libs
|
||||
|
||||
pre_binaries = collect_dynamic_libs("pygame")
|
||||
binaries = []
|
||||
|
||||
for b in pre_binaries:
|
||||
binary, location = b
|
||||
# settles all the DLLs into the top level folder, which prevents duplication
|
||||
# with the DLLs already being put there.
|
||||
binaries.append((binary, "."))
|
||||
@@ -0,0 +1,175 @@
|
||||
import time
|
||||
|
||||
import cv2
|
||||
import numpy
|
||||
import pygame
|
||||
|
||||
|
||||
def list_cameras():
|
||||
return [0]
|
||||
|
||||
|
||||
def list_cameras_darwin():
|
||||
import subprocess
|
||||
from xml.etree import ElementTree
|
||||
|
||||
# pylint: disable=consider-using-with
|
||||
flout, _ = subprocess.Popen(
|
||||
"system_profiler -xml SPCameraDataType",
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
).communicate()
|
||||
|
||||
last_text = None
|
||||
cameras = []
|
||||
|
||||
for node in ElementTree.fromstring(flout).iterfind("./array/dict/array/dict/*"):
|
||||
if last_text == "_name":
|
||||
cameras.append(node.text)
|
||||
last_text = node.text
|
||||
|
||||
return cameras
|
||||
|
||||
|
||||
class Camera:
|
||||
# device should not have a default argument!!
|
||||
# leaving here for compatibility, but I fixed the stubs.
|
||||
def __init__(self, device=0, size=(640, 480), mode="RGB"):
|
||||
self._device_index = device
|
||||
self._size = size
|
||||
|
||||
if mode == "RGB":
|
||||
self._fmt = cv2.COLOR_BGR2RGB
|
||||
elif mode == "YUV":
|
||||
self._fmt = cv2.COLOR_BGR2YUV
|
||||
elif mode == "HSV":
|
||||
self._fmt = cv2.COLOR_BGR2HSV
|
||||
else:
|
||||
raise ValueError("Not a supported mode")
|
||||
|
||||
self._open = False
|
||||
|
||||
# all of this could have been done in the constructor, but creating
|
||||
# the VideoCapture is very time-consuming, so it makes more sense in the
|
||||
# actual start() method
|
||||
def start(self):
|
||||
if self._open:
|
||||
return
|
||||
|
||||
self._cam = cv2.VideoCapture(self._device_index)
|
||||
|
||||
if not self._cam.isOpened():
|
||||
raise ValueError("Could not open camera.")
|
||||
|
||||
self._cam.set(cv2.CAP_PROP_FRAME_WIDTH, self._size[0])
|
||||
self._cam.set(cv2.CAP_PROP_FRAME_HEIGHT, self._size[1])
|
||||
|
||||
w = self._cam.get(cv2.CAP_PROP_FRAME_WIDTH)
|
||||
h = self._cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
||||
self._size = (int(w), int(h))
|
||||
|
||||
self._flipx = False
|
||||
self._flipy = False
|
||||
self._brightness = 1
|
||||
|
||||
self._frametime = 1 / self._cam.get(cv2.CAP_PROP_FPS)
|
||||
self._last_frame_time = 0
|
||||
|
||||
self._open = True
|
||||
|
||||
def stop(self):
|
||||
if self._open:
|
||||
self._cam.release()
|
||||
self._cam = None
|
||||
self._open = False
|
||||
|
||||
def _check_open(self):
|
||||
if not self._open:
|
||||
raise pygame.error("Camera must be started")
|
||||
|
||||
def get_size(self):
|
||||
self._check_open()
|
||||
|
||||
return self._size
|
||||
|
||||
def set_controls(self, hflip=None, vflip=None, brightness=None):
|
||||
self._check_open()
|
||||
|
||||
if hflip is not None:
|
||||
self._flipx = bool(hflip)
|
||||
if vflip is not None:
|
||||
self._flipy = bool(vflip)
|
||||
if brightness is not None:
|
||||
self._cam.set(cv2.CAP_PROP_BRIGHTNESS, brightness)
|
||||
|
||||
return self.get_controls()
|
||||
|
||||
def get_controls(self):
|
||||
self._check_open()
|
||||
|
||||
return (self._flipx, self._flipy, self._cam.get(cv2.CAP_PROP_BRIGHTNESS))
|
||||
|
||||
def query_image(self):
|
||||
self._check_open()
|
||||
|
||||
current_time = time.time()
|
||||
if current_time - self._last_frame_time > self._frametime:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_image(self, dest_surf=None):
|
||||
self._check_open()
|
||||
|
||||
self._last_frame_time = time.time()
|
||||
|
||||
_, image = self._cam.read()
|
||||
|
||||
image = cv2.cvtColor(image, self._fmt)
|
||||
|
||||
flip_code = None
|
||||
if self._flipx:
|
||||
if self._flipy:
|
||||
flip_code = -1
|
||||
else:
|
||||
flip_code = 1
|
||||
elif self._flipy:
|
||||
flip_code = 0
|
||||
|
||||
if flip_code is not None:
|
||||
image = cv2.flip(image, flip_code)
|
||||
|
||||
image = numpy.fliplr(image)
|
||||
image = numpy.rot90(image)
|
||||
|
||||
surf = pygame.surfarray.make_surface(image)
|
||||
|
||||
if dest_surf:
|
||||
dest_surf.blit(surf, (0, 0))
|
||||
return dest_surf
|
||||
|
||||
return surf
|
||||
|
||||
def get_raw(self):
|
||||
self._check_open()
|
||||
|
||||
self._last_frame_time = time.time()
|
||||
|
||||
_, image = self._cam.read()
|
||||
|
||||
return image.tobytes()
|
||||
|
||||
|
||||
class CameraMac(Camera):
|
||||
def __init__(self, device=0, size=(640, 480), mode="RGB"):
|
||||
if isinstance(device, int):
|
||||
_dev = device
|
||||
elif isinstance(device, str):
|
||||
_dev = list_cameras_darwin().index(device)
|
||||
else:
|
||||
raise TypeError(
|
||||
"OpenCV-Mac backend can take device indices or names, ints or strings, not ",
|
||||
str(type(device)),
|
||||
)
|
||||
|
||||
super().__init__(_dev, size, mode)
|
||||
@@ -0,0 +1,13 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class PowerState:
|
||||
battery_percent: int | None
|
||||
battery_seconds: int | None
|
||||
on_battery: bool
|
||||
no_battery: bool
|
||||
charging: bool
|
||||
charged: bool
|
||||
plugged_in: bool
|
||||
has_battery: bool
|
||||
@@ -0,0 +1,186 @@
|
||||
"""Debug functionality that allows for more useful issue reporting"""
|
||||
|
||||
import importlib
|
||||
import platform
|
||||
import sys
|
||||
import traceback
|
||||
from os import environ
|
||||
|
||||
from pygame.system import get_cpu_instruction_sets
|
||||
from pygame.version import ver
|
||||
|
||||
|
||||
def str_from_tuple(version_tuple):
|
||||
"""Converts a tuple like (2, 0, 20) into a string joined by periods
|
||||
|
||||
Args:
|
||||
version_tuple: tuple(version_major, version_minor, version_patch)
|
||||
|
||||
Returns:
|
||||
str: "major.minor.patch"
|
||||
"""
|
||||
if version_tuple is None:
|
||||
return "None"
|
||||
|
||||
strs = map(str, version_tuple)
|
||||
return ".".join(strs)
|
||||
|
||||
|
||||
def attempt_import(module, function_name, output_str=""):
|
||||
"""Attempts to import function_name from module
|
||||
|
||||
Args:
|
||||
module: string representing module name
|
||||
function_name: string representing function name to be imported
|
||||
output_str: optional string to prepend error messages to if one occurs
|
||||
|
||||
Returns:
|
||||
tuple(str, bool, Any):
|
||||
[0]: output_str + error_message
|
||||
[1]: True if successful, False if failed
|
||||
[2]: if successful, the thing that was imported, else None
|
||||
"""
|
||||
try:
|
||||
mod = importlib.import_module(module)
|
||||
i = getattr(mod, function_name)
|
||||
success = True
|
||||
except (ImportError, AttributeError):
|
||||
i = None
|
||||
output_str += f"There was a problem with {module} import\n"
|
||||
output_str += "A default value will be returned for the version\n"
|
||||
output_str += traceback.format_exc() + "\n" + "=" * 20 + "\n"
|
||||
success = False
|
||||
|
||||
return (output_str, success, i)
|
||||
|
||||
|
||||
def _get_platform_info():
|
||||
"""
|
||||
Internal helper to get platform information
|
||||
"""
|
||||
cpu_inst_dict = get_cpu_instruction_sets()
|
||||
sse2 = "Yes" if cpu_inst_dict["SSE2"] else "No"
|
||||
avx2 = "Yes" if cpu_inst_dict["AVX2"] else "No"
|
||||
neon = "Yes" if cpu_inst_dict["NEON"] else "No"
|
||||
ret = f"Platform:\t\t{platform.platform()}\n"
|
||||
ret += f"System:\t\t\t{platform.system()}\n"
|
||||
ret += f"System Version:\t\t{platform.version()}\n"
|
||||
ret += f"Processor:\t\t{platform.processor()}\tSSE2: {sse2}\tAVX2: {avx2}\tNEON: {neon}\n"
|
||||
ret += (
|
||||
f"Architecture:\t\tBits: {platform.architecture()[0]}\t"
|
||||
f"Linkage: {platform.architecture()[1]}\n\n"
|
||||
)
|
||||
|
||||
ret += f"Python:\t\t\t{platform.python_implementation()} {sys.version}\n"
|
||||
ret += (
|
||||
f"GIL Enabled:\t\t{sys._is_gil_enabled()}\n"
|
||||
if hasattr(sys, "_is_gil_enabled")
|
||||
else "GIL Enabled:\t\tTrue\n"
|
||||
)
|
||||
ret += f"pygame version:\t\t{ver}\n"
|
||||
return ret
|
||||
|
||||
|
||||
def print_debug_info(filename=None):
|
||||
"""Gets debug information for reporting bugs. Prints to console
|
||||
if filename is not specified, otherwise writes to that file
|
||||
(note: if filename is not an empty file, it will overwrite whatever is
|
||||
in there)
|
||||
|
||||
Args:
|
||||
filename: string name of the file to save
|
||||
"""
|
||||
debug_str = ""
|
||||
|
||||
# keyword for compat with getters
|
||||
def default_return(linked=True):
|
||||
# pylint: disable=unused-argument
|
||||
return (-1, -1, -1)
|
||||
|
||||
from pygame.base import get_sdl_version
|
||||
from pygame.display import (
|
||||
get_driver as get_display_driver,
|
||||
get_init as display_init,
|
||||
)
|
||||
|
||||
debug_str, *mixer = attempt_import("pygame.mixer", "get_driver", debug_str)
|
||||
get_mixer_driver = mixer[1] if mixer[0] else lambda: None
|
||||
|
||||
debug_str, *mixer = attempt_import("pygame.mixer", "get_init", debug_str)
|
||||
mixer_init = mixer[1] if mixer[0] else lambda: False
|
||||
|
||||
debug_str, *mixer = attempt_import(
|
||||
"pygame.mixer", "get_sdl_mixer_version", debug_str
|
||||
)
|
||||
get_sdl_mixer_version = mixer[1] if mixer[0] else default_return
|
||||
|
||||
debug_str, *font = attempt_import("pygame.font", "get_sdl_ttf_version", debug_str)
|
||||
if not font[0]:
|
||||
get_sdl_ttf_version = default_return
|
||||
else:
|
||||
get_sdl_ttf_version = font[1]
|
||||
|
||||
debug_str, *image = attempt_import(
|
||||
"pygame.image", "get_sdl_image_version", debug_str
|
||||
)
|
||||
if not image[0]:
|
||||
get_sdl_image_version = default_return
|
||||
else:
|
||||
get_sdl_image_version = image[1]
|
||||
|
||||
debug_str, *freetype = attempt_import("pygame.freetype", "get_version", debug_str)
|
||||
if not freetype[0]:
|
||||
ft_version = default_return
|
||||
else:
|
||||
ft_version = freetype[1]
|
||||
|
||||
debug_str += _get_platform_info()
|
||||
|
||||
debug_str += (
|
||||
f"SDL versions:\t\tLinked: {str_from_tuple(get_sdl_version())}\t"
|
||||
f"Compiled: {str_from_tuple(get_sdl_version(linked=False))}\n"
|
||||
)
|
||||
|
||||
debug_str += (
|
||||
f"SDL Mixer versions:\tLinked: {str_from_tuple(get_sdl_mixer_version())}\t"
|
||||
f"Compiled: {str_from_tuple(get_sdl_mixer_version(linked=False))}\n"
|
||||
)
|
||||
|
||||
debug_str += (
|
||||
f"SDL Font versions:\tLinked: {str_from_tuple(get_sdl_ttf_version())}\t"
|
||||
f"Compiled: {str_from_tuple(get_sdl_ttf_version(linked=False))}\n"
|
||||
)
|
||||
|
||||
debug_str += (
|
||||
f"SDL Image versions:\tLinked: {str_from_tuple(get_sdl_image_version())}\t"
|
||||
f"Compiled: {str_from_tuple(get_sdl_image_version(linked=False))}\n"
|
||||
)
|
||||
|
||||
debug_str += (
|
||||
f"Freetype versions:\tLinked: {str_from_tuple(ft_version())}\t"
|
||||
f"Compiled: {str_from_tuple(ft_version(linked=False))}\n\n"
|
||||
)
|
||||
|
||||
if display_init():
|
||||
driver = get_display_driver()
|
||||
if driver.upper() != "X11":
|
||||
debug_str += f"Display Driver:\t\t{driver}\n"
|
||||
else:
|
||||
is_xwayland = (environ.get("XDG_SESSION_TYPE") == "wayland") or (
|
||||
"WAYLAND_DISPLAY" in environ
|
||||
)
|
||||
debug_str += f"Display Driver:\t\t{driver} ( xwayland == {is_xwayland} )\n"
|
||||
else:
|
||||
debug_str += "Display Driver:\t\tDisplay Not Initialized\n"
|
||||
|
||||
if mixer_init():
|
||||
debug_str += f"Mixer Driver:\t\t{get_mixer_driver()}"
|
||||
else:
|
||||
debug_str += "Mixer Driver:\t\tMixer Not Initialized"
|
||||
|
||||
if filename is None:
|
||||
print(debug_str)
|
||||
|
||||
else:
|
||||
with open(filename, "w", encoding="utf8") as debugfile:
|
||||
debugfile.write(debug_str)
|
||||
@@ -0,0 +1,7 @@
|
||||
from collections.abc import Callable
|
||||
|
||||
def str_from_tuple(version_tuple: tuple[int, int, int] | None) -> str: ...
|
||||
def attempt_import(
|
||||
module: str, function_name: str, output_str: str = ""
|
||||
) -> tuple[str, bool, Callable | None]: ...
|
||||
def print_debug_info(filename: str | None = None) -> None: ...
|
||||
@@ -0,0 +1,148 @@
|
||||
from collections.abc import Iterable
|
||||
from typing import Any, Protocol, final
|
||||
|
||||
from pygame.color import Color
|
||||
from pygame.rect import Rect
|
||||
from pygame.surface import Surface
|
||||
from pygame.typing import ColorLike, IntPoint, Point, RectLike, SequenceLike
|
||||
from pygame.window import Window
|
||||
|
||||
class _DrawableClass(Protocol):
|
||||
# Object that has the draw method that accepts area and dest arguments
|
||||
def draw(self, area: RectLike | None = None, dest: RectLike | None = None): ...
|
||||
|
||||
@final
|
||||
class Renderer:
|
||||
def __init__(
|
||||
self,
|
||||
window: Window,
|
||||
index: int = -1,
|
||||
accelerated: int = -1,
|
||||
vsync: bool = False,
|
||||
target_texture: bool = False,
|
||||
) -> None: ...
|
||||
def blit(
|
||||
self,
|
||||
source: "Texture" | "Image" | _DrawableClass,
|
||||
dest: RectLike | None = None,
|
||||
area: RectLike | None = None,
|
||||
special_flags: int = 0,
|
||||
) -> Rect: ...
|
||||
def clear(self) -> None: ...
|
||||
def draw_line(self, p1: Point, p2: Point) -> None: ...
|
||||
def draw_point(self, point: Point) -> None: ...
|
||||
def draw_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
|
||||
def draw_rect(self, rect: RectLike) -> None: ...
|
||||
def draw_triangle(self, p1: Point, p2: Point, p3: Point) -> None: ...
|
||||
def fill_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
|
||||
def fill_rect(self, rect: RectLike) -> None: ...
|
||||
def fill_triangle(self, p1: Point, p2: Point, p3: Point) -> None: ...
|
||||
def get_viewport(self) -> Rect: ...
|
||||
def coordinates_to_window(self, point: Point) -> tuple[float, float]: ...
|
||||
def coordinates_from_window(self, point: Point) -> tuple[float, float]: ...
|
||||
def present(self) -> None: ...
|
||||
def set_viewport(self, area: RectLike | None) -> None: ...
|
||||
def to_surface(
|
||||
self, surface: Surface | None = None, area: RectLike | None = None
|
||||
) -> Surface: ...
|
||||
@property
|
||||
def draw_blend_mode(self) -> int: ...
|
||||
@draw_blend_mode.setter
|
||||
def draw_blend_mode(self, value: int) -> None: ...
|
||||
@property
|
||||
def draw_color(self) -> Color: ...
|
||||
@draw_color.setter
|
||||
def draw_color(self, value: ColorLike) -> None: ...
|
||||
@property
|
||||
def logical_size(self) -> tuple[int, int]: ...
|
||||
@logical_size.setter
|
||||
def logical_size(self, value: IntPoint) -> None: ...
|
||||
@property
|
||||
def scale(self) -> tuple[float, float]: ...
|
||||
@scale.setter
|
||||
def scale(self, value: Point) -> None: ...
|
||||
@property
|
||||
def target(self) -> "Texture": ...
|
||||
@target.setter
|
||||
def target(self, value: "Texture") -> None: ...
|
||||
@classmethod
|
||||
def compose_custom_blend_mode(
|
||||
cls, color_mode: SequenceLike[int], alpha_mode: SequenceLike[int]
|
||||
) -> int: ...
|
||||
@classmethod
|
||||
def from_window(cls, window: Window) -> Renderer: ...
|
||||
|
||||
@final
|
||||
class Texture:
|
||||
def __init__(
|
||||
self,
|
||||
renderer: Renderer,
|
||||
size: Iterable[int],
|
||||
depth: int = 0,
|
||||
static: bool = False,
|
||||
streaming: bool = False,
|
||||
target: bool = False,
|
||||
scale_quality: int | None = None,
|
||||
) -> None: ...
|
||||
@property
|
||||
def alpha(self) -> int: ...
|
||||
@alpha.setter
|
||||
def alpha(self, value: int) -> None: ...
|
||||
@property
|
||||
def blend_mode(self) -> int: ...
|
||||
@blend_mode.setter
|
||||
def blend_mode(self, value: int) -> None: ...
|
||||
@property
|
||||
def color(self) -> Color: ...
|
||||
@color.setter
|
||||
def color(self, value: ColorLike) -> None: ...
|
||||
@property
|
||||
def width(self) -> int: ...
|
||||
@property
|
||||
def height(self) -> int: ...
|
||||
@property
|
||||
def renderer(self) -> Renderer: ...
|
||||
@classmethod
|
||||
def from_surface(cls, renderer: Renderer, surface: Surface) -> Texture: ...
|
||||
def draw(
|
||||
self,
|
||||
srcrect: RectLike | None = None,
|
||||
dstrect: RectLike | None = None,
|
||||
angle: float = 0.0,
|
||||
origin: Iterable[int] | None = None,
|
||||
flip_x: bool = False,
|
||||
flip_y: bool = False,
|
||||
) -> None: ...
|
||||
def draw_triangle(
|
||||
self,
|
||||
p1_xy: Point,
|
||||
p2_xy: Point,
|
||||
p3_xy: Point,
|
||||
p1_uv: Point = (0.0, 0.0),
|
||||
p2_uv: Point = (1.0, 1.0),
|
||||
p3_uv: Point = (0.0, 1.0),
|
||||
p1_mod: ColorLike = (255, 255, 255, 255),
|
||||
p2_mod: ColorLike = (255, 255, 255, 255),
|
||||
p3_mod: ColorLike = (255, 255, 255, 255),
|
||||
) -> None: ...
|
||||
def draw_quad(
|
||||
self,
|
||||
p1_xy: Point,
|
||||
p2_xy: Point,
|
||||
p3_xy: Point,
|
||||
p4_xy: Point,
|
||||
p1_uv: Point = (0.0, 0.0),
|
||||
p2_uv: Point = (1.0, 0.0),
|
||||
p3_uv: Point = (1.0, 1.0),
|
||||
p4_uv: Point = (0.0, 1.0),
|
||||
p1_mod: ColorLike = (255, 255, 255, 255),
|
||||
p2_mod: ColorLike = (255, 255, 255, 255),
|
||||
p3_mod: ColorLike = (255, 255, 255, 255),
|
||||
p4_mod: ColorLike = (255, 255, 255, 255),
|
||||
) -> None: ...
|
||||
def get_rect(self, **kwargs: Any) -> Rect: ...
|
||||
def update(self, surface: Surface, area: RectLike | None = None) -> None: ...
|
||||
|
||||
@final
|
||||
class Image:
|
||||
pass
|
||||
@@ -0,0 +1,4 @@
|
||||
if __import__("sys").platform not in ("wasi", "emscripten"):
|
||||
from .audio import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
|
||||
from .sdl2 import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
|
||||
from .video import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
|
||||
@@ -0,0 +1,3 @@
|
||||
from pygame._sdl2.audio import *
|
||||
from pygame._sdl2.sdl2 import *
|
||||
from pygame._sdl2.video import *
|
||||
@@ -0,0 +1,55 @@
|
||||
from collections.abc import Callable
|
||||
from typing import Optional
|
||||
|
||||
AUDIO_U8: int
|
||||
AUDIO_S8: int
|
||||
AUDIO_U16LSB: int
|
||||
AUDIO_S16LSB: int
|
||||
AUDIO_U16MSB: int
|
||||
AUDIO_S16MSB: int
|
||||
AUDIO_U16: int
|
||||
AUDIO_S16: int
|
||||
AUDIO_S32LSB: int
|
||||
AUDIO_S32MSB: int
|
||||
AUDIO_S32: int
|
||||
AUDIO_F32LSB: int
|
||||
AUDIO_F32MSB: int
|
||||
AUDIO_F32: int
|
||||
|
||||
AUDIO_ALLOW_FREQUENCY_CHANGE: int
|
||||
AUDIO_ALLOW_FORMAT_CHANGE: int
|
||||
AUDIO_ALLOW_CHANNELS_CHANGE: int
|
||||
AUDIO_ALLOW_ANY_CHANGE: int
|
||||
|
||||
def get_audio_device_names(iscapture: bool = False) -> list[str]: ...
|
||||
|
||||
class AudioDevice:
|
||||
def __init__(
|
||||
self,
|
||||
devicename: Optional[str],
|
||||
iscapture: bool,
|
||||
frequency: int,
|
||||
audioformat: int,
|
||||
numchannels: int,
|
||||
chunksize: int,
|
||||
allowed_changes: int,
|
||||
callback: Callable[[AudioDevice, memoryview], None],
|
||||
) -> None: ...
|
||||
@property
|
||||
def iscapture(self) -> bool: ...
|
||||
@property
|
||||
def deviceid(self) -> int: ...
|
||||
@property
|
||||
def devicename(self) -> Optional[str]: ...
|
||||
@property
|
||||
def callback(self) -> Callable[[AudioDevice, memoryview], None]: ...
|
||||
@property
|
||||
def frequency(self) -> int: ...
|
||||
@property
|
||||
def audioformat(self) -> int: ...
|
||||
@property
|
||||
def numchannels(self) -> int: ...
|
||||
@property
|
||||
def chunksize(self) -> int: ...
|
||||
def pause(self, pause_on: int) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
@@ -0,0 +1,34 @@
|
||||
from typing import final
|
||||
|
||||
from pygame.joystick import JoystickType
|
||||
from pygame.typing import ColorLike
|
||||
|
||||
def init() -> None: ...
|
||||
def get_init() -> bool: ...
|
||||
def quit() -> None: ...
|
||||
def is_controller(device_index: int) -> bool: ...
|
||||
def get_count() -> int: ...
|
||||
@final
|
||||
class Controller:
|
||||
def __new__(cls, device_index: int) -> Controller: ...
|
||||
def __init__(self, device_index: int) -> None: ...
|
||||
@classmethod
|
||||
def from_joystick(cls, joystick: JoystickType) -> Controller: ...
|
||||
def get_init(self) -> bool: ...
|
||||
def init(self) -> None: ...
|
||||
def quit(self) -> None: ...
|
||||
@property
|
||||
def id(self) -> int: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
def attached(self) -> bool: ...
|
||||
def as_joystick(self) -> JoystickType: ...
|
||||
def get_axis(self, axis: int) -> int: ...
|
||||
def get_button(self, button: int) -> bool: ...
|
||||
def get_mapping(self) -> dict[str, str]: ...
|
||||
def set_mapping(self, mapping: dict[str, str]) -> int: ...
|
||||
def rumble(
|
||||
self, low_frequency: float, high_frequency: float, duration: int
|
||||
) -> bool: ...
|
||||
def stop_rumble(self) -> None: ...
|
||||
def set_led(self, color: ColorLike, /) -> bool: ...
|
||||
@@ -0,0 +1,35 @@
|
||||
from collections.abc import Mapping
|
||||
|
||||
from pygame.joystick import JoystickType
|
||||
|
||||
def init() -> None: ...
|
||||
def get_init() -> bool: ...
|
||||
def quit() -> None: ...
|
||||
def set_eventstate(state: bool) -> None: ...
|
||||
def get_eventstate() -> bool: ...
|
||||
def update() -> None: ...
|
||||
def get_count() -> int: ...
|
||||
def is_controller(index: int) -> bool: ...
|
||||
def name_forindex(index: int) -> str | None: ...
|
||||
|
||||
class Controller:
|
||||
def __init__(self, index: int) -> None: ...
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
@property
|
||||
def id(self) -> int: ...
|
||||
def init(self) -> None: ...
|
||||
def get_init(self) -> bool: ...
|
||||
def quit(self) -> None: ...
|
||||
@staticmethod
|
||||
def from_joystick(joy: JoystickType) -> Controller: ...
|
||||
def attached(self) -> bool: ...
|
||||
def as_joystick(self) -> JoystickType: ...
|
||||
def get_axis(self, axis: int) -> int: ...
|
||||
def get_button(self, button: int) -> bool: ...
|
||||
def get_mapping(self) -> dict[str, str]: ...
|
||||
def set_mapping(self, mapping: Mapping[str, str]) -> int: ...
|
||||
def rumble(
|
||||
self, low_frequency: float, high_frequency: float, duration: int
|
||||
) -> bool: ...
|
||||
def stop_rumble(self) -> None: ...
|
||||
@@ -0,0 +1,14 @@
|
||||
INIT_TIMER: int
|
||||
INIT_AUDIO: int
|
||||
INIT_VIDEO: int
|
||||
INIT_JOYSTICK: int
|
||||
INIT_HAPTIC: int
|
||||
INIT_GAMECONTROLLER: int
|
||||
INIT_EVENTS: int
|
||||
INIT_NOPARACHUTE: int
|
||||
INIT_EVERYTHING: int
|
||||
|
||||
class error(RuntimeError):
|
||||
def __init__(self, message: str | None = None) -> None: ...
|
||||
|
||||
def init_subsystem(flags: int) -> None: ...
|
||||
@@ -0,0 +1,12 @@
|
||||
from typing import TypedDict
|
||||
|
||||
class _FingerDict(TypedDict):
|
||||
id: int
|
||||
x: float
|
||||
y: float
|
||||
pressure: float
|
||||
|
||||
def get_num_devices() -> int: ...
|
||||
def get_device(index: int, /) -> int: ...
|
||||
def get_num_fingers(device_id: int, /) -> int: ...
|
||||
def get_finger(touchid: int, index: int) -> _FingerDict | None: ...
|
||||
@@ -0,0 +1,159 @@
|
||||
from collections.abc import Generator, Iterable
|
||||
from typing import Any
|
||||
|
||||
from pygame.color import Color
|
||||
from pygame.rect import Rect
|
||||
from pygame.surface import Surface
|
||||
from pygame.typing import ColorLike, Point, RectLike
|
||||
from pygame.window import Window as Window
|
||||
|
||||
WINDOWPOS_UNDEFINED: int
|
||||
WINDOWPOS_CENTERED: int
|
||||
|
||||
SCALEQUALITY_NEAREST: int
|
||||
SCALEQUALITY_LINEAR: int
|
||||
SCALEQUALITY_BEST: int
|
||||
|
||||
class RendererDriverInfo:
|
||||
name: str
|
||||
flags: int
|
||||
num_texture_formats: int
|
||||
max_texture_width: int
|
||||
max_texture_height: int
|
||||
|
||||
def get_drivers() -> Generator[RendererDriverInfo, None, None]: ...
|
||||
def get_grabbed_window() -> Window | None: ...
|
||||
|
||||
class Texture:
|
||||
def __init__(
|
||||
self,
|
||||
renderer: Renderer,
|
||||
size: Iterable[int],
|
||||
depth: int = 0,
|
||||
static: bool = False,
|
||||
streaming: bool = False,
|
||||
target: bool = False,
|
||||
scale_quality: int | None = None,
|
||||
) -> None: ...
|
||||
@staticmethod
|
||||
def from_surface(renderer: Renderer, surface: Surface) -> Texture: ...
|
||||
renderer: Renderer
|
||||
width: int
|
||||
height: int
|
||||
alpha: int
|
||||
blend_mode: int
|
||||
|
||||
@property
|
||||
def color(self) -> Color: ...
|
||||
@color.setter
|
||||
def color(self, value: ColorLike) -> None: ...
|
||||
def get_rect(self, **kwargs: Any) -> Rect: ...
|
||||
def draw(
|
||||
self,
|
||||
srcrect: RectLike | None = None,
|
||||
dstrect: RectLike | None = None,
|
||||
angle: float = 0.0,
|
||||
origin: Iterable[int] | None = None,
|
||||
flip_x: bool = False,
|
||||
flip_y: bool = False,
|
||||
) -> None: ...
|
||||
def draw_triangle(
|
||||
self,
|
||||
p1_xy: Point,
|
||||
p2_xy: Point,
|
||||
p3_xy: Point,
|
||||
p1_uv: Point = (0.0, 0.0),
|
||||
p2_uv: Point = (1.0, 1.0),
|
||||
p3_uv: Point = (0.0, 1.0),
|
||||
p1_mod: Iterable[int] = (255, 255, 255, 255),
|
||||
p2_mod: Iterable[int] = (255, 255, 255, 255),
|
||||
p3_mod: Iterable[int] = (255, 255, 255, 255),
|
||||
) -> None: ...
|
||||
def draw_quad(
|
||||
self,
|
||||
p1_xy: Point,
|
||||
p2_xy: Point,
|
||||
p3_xy: Point,
|
||||
p4_xy: Point,
|
||||
p1_uv: Point = (0.0, 0.0),
|
||||
p2_uv: Point = (1.0, 0.0),
|
||||
p3_uv: Point = (1.0, 1.0),
|
||||
p4_uv: Point = (0.0, 1.0),
|
||||
p1_mod: Iterable[int] = (255, 255, 255, 255),
|
||||
p2_mod: Iterable[int] = (255, 255, 255, 255),
|
||||
p3_mod: Iterable[int] = (255, 255, 255, 255),
|
||||
p4_mod: Iterable[int] = (255, 255, 255, 255),
|
||||
) -> None: ...
|
||||
def update(self, surface: Surface, area: RectLike | None = None) -> None: ...
|
||||
|
||||
class Image:
|
||||
def __init__(
|
||||
self,
|
||||
texture_or_image: Texture | Image,
|
||||
srcrect: RectLike | None = None,
|
||||
) -> None: ...
|
||||
def get_rect(self) -> Rect: ...
|
||||
def draw(
|
||||
self, srcrect: RectLike | None = None, dstrect: RectLike | None = None
|
||||
) -> None: ...
|
||||
angle: float
|
||||
origin: Iterable[float] | None
|
||||
flip_x: bool
|
||||
flip_y: bool
|
||||
alpha: float
|
||||
blend_mode: int
|
||||
texture: Texture
|
||||
srcrect: Rect
|
||||
|
||||
@property
|
||||
def color(self) -> Color: ...
|
||||
@color.setter
|
||||
def color(self, value: ColorLike) -> None: ...
|
||||
|
||||
class Renderer:
|
||||
def __init__(
|
||||
self,
|
||||
window: Window,
|
||||
index: int = -1,
|
||||
accelerated: int = -1,
|
||||
vsync: bool = False,
|
||||
target_texture: bool = False,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def from_window(cls, window: Window) -> Renderer: ...
|
||||
draw_blend_mode: int
|
||||
@property
|
||||
def draw_color(self) -> Color: ...
|
||||
@draw_color.setter
|
||||
def draw_color(self, value: ColorLike) -> None: ...
|
||||
def clear(self) -> None: ...
|
||||
def present(self) -> None: ...
|
||||
def get_viewport(self) -> Rect: ...
|
||||
def set_viewport(self, area: RectLike | None) -> None: ...
|
||||
logical_size: Iterable[int]
|
||||
def coordinates_to_window(self, point: Point) -> tuple[float, float]: ...
|
||||
def coordinates_from_window(self, point: Point) -> tuple[float, float]: ...
|
||||
scale: Iterable[float]
|
||||
target: Texture | None
|
||||
def blit(
|
||||
self,
|
||||
source: Texture | Image,
|
||||
dest: RectLike | None = None,
|
||||
area: RectLike | None = None,
|
||||
special_flags: int = 0,
|
||||
) -> Rect: ...
|
||||
def draw_line(self, p1: Point, p2: Point) -> None: ...
|
||||
def draw_point(self, point: Point) -> None: ...
|
||||
def draw_rect(self, rect: RectLike) -> None: ...
|
||||
def fill_rect(self, rect: RectLike) -> None: ...
|
||||
def draw_triangle(self, p1: Point, p2: Point, p3: Point) -> None: ...
|
||||
def fill_triangle(self, p1: Point, p2: Point, p3: Point) -> None: ...
|
||||
def draw_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
|
||||
def fill_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
|
||||
def to_surface(
|
||||
self, surface: Surface | None = None, area: RectLike | None = None
|
||||
) -> Surface: ...
|
||||
@staticmethod
|
||||
def compose_custom_blend_mode(
|
||||
color_mode: tuple[int, int, int], alpha_mode: tuple[int, int, int]
|
||||
) -> int: ...
|
||||
@@ -0,0 +1 @@
|
||||
from .video import Window # pylint: disable=wildcard-import
|
||||
@@ -0,0 +1 @@
|
||||
from pygame._sdl2.video import Window as Window
|
||||
@@ -0,0 +1,28 @@
|
||||
import warnings
|
||||
|
||||
warnings.warn(
|
||||
"The ._sprite submodule is deprecated since 2.4.0. Please use pygame.sprite instead.",
|
||||
category=DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
from pygame.sprite import (
|
||||
AbstractGroup,
|
||||
DirtySprite,
|
||||
Group,
|
||||
GroupSingle,
|
||||
LayeredDirty,
|
||||
LayeredUpdates,
|
||||
RenderClear,
|
||||
RenderPlain,
|
||||
RenderUpdates,
|
||||
Sprite,
|
||||
collide_circle,
|
||||
collide_circle_ratio,
|
||||
collide_mask,
|
||||
collide_rect,
|
||||
collide_rect_ratio,
|
||||
groupcollide,
|
||||
spritecollide,
|
||||
spritecollideany,
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
__version__: str
|
||||
|
||||
class error(RuntimeError): ...
|
||||
class BufferError(Exception): ...
|
||||
|
||||
# Always defined
|
||||
HAVE_NEWBUF: int = 1
|
||||
|
||||
def init() -> tuple[int, int]: ...
|
||||
def quit() -> None: ...
|
||||
def get_init() -> bool: ...
|
||||
def get_error() -> str: ...
|
||||
def set_error(error_msg: str, /) -> None: ...
|
||||
def get_sdl_version(linked: bool = True) -> tuple[int, int, int]: ...
|
||||
def get_sdl_byteorder() -> int: ...
|
||||
def register_quit(callable: Callable[[], Any], /) -> None: ...
|
||||
|
||||
# undocumented part of pygame API, kept here to make stubtest happy
|
||||
def get_array_interface(arg: Any, /) -> dict: ...
|
||||
@@ -0,0 +1,27 @@
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
class BufferProxy:
|
||||
@property
|
||||
def parent(self) -> Any: ...
|
||||
@property
|
||||
def length(self) -> int: ...
|
||||
@property
|
||||
def raw(self) -> bytes: ...
|
||||
# possibly going to be deprecated/removed soon, in which case these
|
||||
# typestubs must be removed too
|
||||
@property
|
||||
def __array_interface__(self) -> dict[str, Any]: ...
|
||||
@property
|
||||
def __array_struct__(self) -> Any: ...
|
||||
if sys.version_info >= (3, 12):
|
||||
def __buffer__(self, flags: int, /) -> memoryview[int]: ...
|
||||
def __release_buffer__(self, view: memoryview[int], /) -> None: ...
|
||||
def __new__(
|
||||
cls, parent: Any
|
||||
) -> BufferProxy: ... # TODO: parent: TypedDict | Protocol
|
||||
def write(
|
||||
self,
|
||||
buffer: str | bytes, # Any "read-only bytes-like-object" is valid
|
||||
offset: int = 0,
|
||||
) -> None: ...
|
||||
@@ -0,0 +1,184 @@
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
import warnings
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from pygame import error
|
||||
|
||||
_is_init = False
|
||||
|
||||
|
||||
class AbstractCamera(ABC):
|
||||
# set_controls and get_controls are not a part of the AbstractCamera ABC,
|
||||
# because implementations of the same can vary across different Camera
|
||||
# types
|
||||
@abstractmethod
|
||||
def __init__(self, *args, **kwargs):
|
||||
""" """
|
||||
|
||||
@abstractmethod
|
||||
def start(self):
|
||||
""" """
|
||||
|
||||
@abstractmethod
|
||||
def stop(self):
|
||||
""" """
|
||||
|
||||
@abstractmethod
|
||||
def get_size(self):
|
||||
""" """
|
||||
|
||||
@abstractmethod
|
||||
def query_image(self):
|
||||
""" """
|
||||
|
||||
@abstractmethod
|
||||
def get_image(self, dest_surf=None):
|
||||
""" """
|
||||
|
||||
@abstractmethod
|
||||
def get_raw(self):
|
||||
""" """
|
||||
|
||||
|
||||
def _pre_init_placeholder():
|
||||
if not _is_init:
|
||||
raise error("pygame.camera is not initialized")
|
||||
|
||||
# camera was init, and yet functions are not monkey patched. This should
|
||||
# not happen
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
def _pre_init_placeholder_varargs(*_, **__):
|
||||
_pre_init_placeholder()
|
||||
|
||||
|
||||
class _PreInitPlaceholderCamera(AbstractCamera):
|
||||
def __init__(self, *args, **kwargs):
|
||||
_pre_init_placeholder()
|
||||
|
||||
start = _pre_init_placeholder_varargs
|
||||
stop = _pre_init_placeholder_varargs
|
||||
get_controls = _pre_init_placeholder_varargs
|
||||
set_controls = _pre_init_placeholder_varargs
|
||||
get_size = _pre_init_placeholder_varargs
|
||||
query_image = _pre_init_placeholder_varargs
|
||||
get_image = _pre_init_placeholder_varargs
|
||||
get_raw = _pre_init_placeholder_varargs
|
||||
|
||||
|
||||
list_cameras = _pre_init_placeholder
|
||||
Camera = _PreInitPlaceholderCamera
|
||||
|
||||
|
||||
def _colorspace_not_available(*args):
|
||||
raise RuntimeError("pygame is not built with colorspace support")
|
||||
|
||||
|
||||
try:
|
||||
from pygame import _camera
|
||||
|
||||
colorspace = _camera.colorspace
|
||||
except ImportError:
|
||||
# Should not happen in most cases
|
||||
colorspace = _colorspace_not_available
|
||||
|
||||
|
||||
def _setup_backend(backend):
|
||||
global list_cameras, Camera
|
||||
if backend == "opencv-mac":
|
||||
from pygame import _camera_opencv
|
||||
|
||||
list_cameras = _camera_opencv.list_cameras_darwin
|
||||
Camera = _camera_opencv.CameraMac
|
||||
|
||||
elif backend == "opencv":
|
||||
from pygame import _camera_opencv
|
||||
|
||||
list_cameras = _camera_opencv.list_cameras
|
||||
Camera = _camera_opencv.Camera
|
||||
|
||||
elif backend in ("_camera (msmf)", "_camera (v4l2)"):
|
||||
from pygame import _camera
|
||||
|
||||
list_cameras = _camera.list_cameras
|
||||
Camera = _camera.Camera
|
||||
|
||||
else:
|
||||
raise ValueError("unrecognized backend name")
|
||||
|
||||
|
||||
def get_backends():
|
||||
possible_backends = []
|
||||
|
||||
if sys.platform == "win32" and int(platform.win32_ver()[0].split(".")[0]) >= 8:
|
||||
possible_backends.append("_camera (MSMF)")
|
||||
|
||||
if sys.platform == "linux":
|
||||
possible_backends.append("_camera (V4L2)")
|
||||
|
||||
if "darwin" in sys.platform:
|
||||
possible_backends.append("OpenCV-Mac")
|
||||
|
||||
possible_backends.append("OpenCV")
|
||||
|
||||
# see if we have any user specified defaults in environments.
|
||||
camera_env = os.environ.get("PYGAME_CAMERA", "").lower()
|
||||
if camera_env == "opencv": # prioritize opencv
|
||||
if "OpenCV" in possible_backends:
|
||||
possible_backends.remove("OpenCV")
|
||||
possible_backends = ["OpenCV"] + possible_backends
|
||||
|
||||
return possible_backends
|
||||
|
||||
|
||||
def init(backend=None):
|
||||
global _is_init
|
||||
# select the camera module to import here.
|
||||
|
||||
backends = [b.lower() for b in get_backends()]
|
||||
if not backends:
|
||||
raise error("No camera backends are supported on your platform!")
|
||||
|
||||
backend = backends[0] if backend is None else backend.lower()
|
||||
if backend not in backends:
|
||||
warnings.warn(
|
||||
"We don't think this is a supported backend on this system, "
|
||||
"but we'll try it...",
|
||||
Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
try:
|
||||
_setup_backend(backend)
|
||||
except ImportError:
|
||||
emsg = f"Backend '{backend}' is not supported on your platform!"
|
||||
if backend in ("opencv", "opencv-mac"):
|
||||
dep = "OpenCV"
|
||||
emsg += (
|
||||
f" Make sure you have '{dep}' installed to be able to use this backend"
|
||||
)
|
||||
|
||||
raise error(emsg)
|
||||
|
||||
_is_init = True
|
||||
|
||||
|
||||
def quit():
|
||||
global _is_init, Camera, list_cameras
|
||||
# reset to their respective pre-init placeholders
|
||||
list_cameras = _pre_init_placeholder
|
||||
Camera = _PreInitPlaceholderCamera
|
||||
|
||||
_is_init = False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# try to use this camera stuff with the pygame camera example.
|
||||
import pygame.examples.camera
|
||||
|
||||
# pygame.camera.Camera = Camera
|
||||
# pygame.camera.list_cameras = list_cameras
|
||||
pygame.examples.camera.main()
|
||||
@@ -0,0 +1,53 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Literal
|
||||
|
||||
from pygame.surface import Surface
|
||||
from pygame.typing import IntPoint
|
||||
|
||||
def get_backends() -> list[str]: ...
|
||||
def init(backend: str | None = None) -> None: ...
|
||||
def quit() -> None: ...
|
||||
def list_cameras() -> list[str] | list[int]: ...
|
||||
def colorspace(
|
||||
surface: Surface, color: Literal["YUV", "HSV"], dest_surface: Surface = ..., /
|
||||
) -> Surface: ...
|
||||
|
||||
class AbstractCamera(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self, *args, **kwargs) -> None: ...
|
||||
@abstractmethod
|
||||
def start(self) -> None: ...
|
||||
@abstractmethod
|
||||
def stop(self) -> None: ...
|
||||
@abstractmethod
|
||||
def get_size(self) -> tuple[int, int]: ...
|
||||
@abstractmethod
|
||||
def query_image(self) -> bool: ...
|
||||
@abstractmethod
|
||||
def get_image(self, dest_surf: Surface | None = None) -> Surface: ...
|
||||
@abstractmethod
|
||||
def get_raw(self) -> bytes: ...
|
||||
# set_controls and get_controls are not a part of the AbstractCamera ABC,
|
||||
# because implementations of the same can vary across different Camera
|
||||
# types
|
||||
|
||||
class Camera(AbstractCamera):
|
||||
def __init__(
|
||||
self,
|
||||
device: str | int,
|
||||
size: IntPoint = (640, 480),
|
||||
format: str = "RGB",
|
||||
) -> None: ...
|
||||
def start(self) -> None: ...
|
||||
def stop(self) -> None: ...
|
||||
def get_controls(self) -> tuple[bool, bool, int]: ...
|
||||
def set_controls(
|
||||
self,
|
||||
hflip: bool = ...,
|
||||
vflip: bool = ...,
|
||||
brightness: int = ...,
|
||||
) -> tuple[bool, bool, int]: ...
|
||||
def get_size(self) -> tuple[int, int]: ...
|
||||
def query_image(self) -> bool: ...
|
||||
def get_image(self, surface: Surface | None = None) -> Surface: ...
|
||||
def get_raw(self) -> bytes: ...
|
||||
@@ -0,0 +1,411 @@
|
||||
import sys
|
||||
from collections.abc import Collection, Iterator
|
||||
from typing import Any, ClassVar, SupportsIndex, overload
|
||||
|
||||
from pygame.typing import ColorLike
|
||||
from typing_extensions import deprecated # added in 3.13
|
||||
|
||||
THECOLORS: dict[str, tuple[int, int, int, int]]
|
||||
|
||||
# Color confirms to the Collection ABC, since it also confirms to
|
||||
# Sized, Iterable and Container ABCs
|
||||
class Color(Collection[int]):
|
||||
"""Pygame object for color representations.
|
||||
|
||||
The ``Color`` class represents ``RGBA`` color values using a value range of
|
||||
0 to 255 inclusive. It allows basic arithmetic operations — binary
|
||||
operations ``+``, ``-``, ``*``, ``//``, ``%``, and unary operation ``~`` — to
|
||||
create new colors, supports conversions to other color spaces such as ``HSV``
|
||||
or ``HSL`` and lets you adjust single color channels.
|
||||
Alpha defaults to 255 (fully opaque) when not given.
|
||||
The arithmetic operations and ``correct_gamma()`` method preserve subclasses.
|
||||
For the binary operators, the class of the returned color is that of the
|
||||
left hand color object of the operator.
|
||||
|
||||
Color objects support swizzling for their ``RGBA`` attributes, which allows
|
||||
the creation of new color objects with the corresponding swizzled attributes
|
||||
as its ``RGBA`` attributes. For example, ``color.bgra`` provides a shortcut to
|
||||
doing ``Color(color.b, color.g, color.r, color.a)``. Swizzling with other than
|
||||
4 attributes will return a tuple consisting of the corresponding elements
|
||||
instead of a color object.
|
||||
|
||||
Color objects support equality comparison with other color objects and 3 or
|
||||
4 element tuples of integers. There was a bug in pygame 1.8.1
|
||||
where the default alpha was 0, not 255 like previously.
|
||||
|
||||
Color objects export the C level array interface. The interface exports a
|
||||
read-only one dimensional unsigned byte array of the same assigned length
|
||||
as the color. The new buffer interface is also exported, with the same
|
||||
characteristics as the array interface.
|
||||
|
||||
The floor division, ``//``, and modulus, ``%``, operators do not raise
|
||||
an exception for division by zero. Instead, if a color, or alpha, channel
|
||||
in the right hand color is 0, then the result is 0. For example: ::
|
||||
|
||||
# These expressions are True
|
||||
Color(255, 255, 255, 255) // Color(0, 64, 64, 64) == Color(0, 3, 3, 3)
|
||||
Color(255, 255, 255, 255) % Color(64, 64, 64, 0) == Color(63, 63, 63, 0)
|
||||
|
||||
Use ``int(color)`` to return the immutable integer value of the color,
|
||||
usable as a ``dict`` key. This integer value differs from the mapped
|
||||
pixel values of :meth:`pygame.Surface.get_at_mapped`,
|
||||
:meth:`pygame.Surface.map_rgb` and :meth:`pygame.Surface.unmap_rgb`.
|
||||
It can be passed as a ``color_value`` argument to :class:`Color`
|
||||
(useful with sets).
|
||||
|
||||
See :doc:`color_list` for samples of the available named colors.
|
||||
|
||||
:param int r: red value in the range of 0 to 255 inclusive
|
||||
:param int g: green value in the range of 0 to 255 inclusive
|
||||
:param int b: blue value in the range of 0 to 255 inclusive
|
||||
:param int a: (optional) alpha value in the range of 0 to 255 inclusive,
|
||||
default is 255
|
||||
:param color_value: color value (see note below for the supported formats)
|
||||
|
||||
.. note::
|
||||
Supported ``color_value`` formats:
|
||||
|
||||
| - **Color object:** clones the given :class:`Color` object
|
||||
|
||||
| - **Color name: str:** name of the color to use, e.g. ``'red'``
|
||||
(all the supported name strings can be found in the
|
||||
:doc:`color_list`, with sample swatches)
|
||||
|
||||
| - **HTML color format str:** ``'#rrggbbaa'`` or ``'#rrggbb'``,
|
||||
where rr, gg, bb, and aa are 2-digit hex numbers in the range
|
||||
of 0 to 0xFF inclusive, the aa (alpha) value defaults to 0xFF
|
||||
if not provided
|
||||
|
||||
| - **hex number str:** ``'0xrrggbbaa'`` or ``'0xrrggbb'``, where
|
||||
rr, gg, bb, and aa are 2-digit hex numbers in the range of 0x00
|
||||
to 0xFF inclusive, the aa (alpha) value defaults to 0xFF if not
|
||||
provided
|
||||
|
||||
| - **int:** int value of the color to use, using hex numbers can
|
||||
make this parameter more readable, e.g. ``0xrrggbbaa``, where rr,
|
||||
gg, bb, and aa are 2-digit hex numbers in the range of 0x00 to
|
||||
0xFF inclusive, note that the aa (alpha) value is not optional for
|
||||
the int format and must be provided
|
||||
|
||||
| - **tuple/list of int color values:** ``(R, G, B, A)`` or
|
||||
``(R, G, B)``, where R, G, B, and A are int values in the range of
|
||||
0 to 255 inclusive, the A (alpha) value defaults to 255 if not
|
||||
provided
|
||||
|
||||
:type color_value: Color or str or int or tuple(int, int, int, [int]) or
|
||||
list(int, int, int, [int])
|
||||
|
||||
:returns: a newly created :class:`Color` object
|
||||
:rtype: Color
|
||||
|
||||
.. versionchanged:: 2.5.6
|
||||
``bytes(Color(...))`` (assuming `bytes <https://docs.python.org/3/library/stdtypes.html#bytes>`_ is
|
||||
the built-in type) now returns a ``bytes`` object (of length 4) with the RGBA values of the color,
|
||||
as opposed to :class:`Color` being interpreted as an integer (think ``int(Color(...))``) causing it
|
||||
to return a ``bytes`` object filled with 0s the length of said integer.
|
||||
.. versionchangedold:: 2.0.0
|
||||
Support for tuples, lists, and :class:`Color` objects when creating
|
||||
:class:`Color` objects.
|
||||
.. versionchangedold:: 1.9.2 Color objects export the C level array interface.
|
||||
.. versionchangedold:: 1.9.0 Color objects support 4-element tuples of integers.
|
||||
.. versionchangedold:: 1.8.1 New implementation of the class.
|
||||
"""
|
||||
|
||||
r: int
|
||||
"""Gets or sets the red value of the Color.
|
||||
|
||||
The red value of the Color.
|
||||
"""
|
||||
|
||||
g: int
|
||||
"""Gets or sets the green value of the Color.
|
||||
|
||||
The green value of the Color.
|
||||
"""
|
||||
|
||||
b: int
|
||||
"""Gets or sets the blue value of the Color.
|
||||
|
||||
The blue value of the Color.
|
||||
"""
|
||||
|
||||
a: int
|
||||
"""Gets or sets the alpha value of the Color.
|
||||
|
||||
The alpha value of the Color.
|
||||
"""
|
||||
|
||||
cmy: tuple[float, float, float]
|
||||
"""Gets or sets the CMY representation of the Color.
|
||||
|
||||
The ``CMY`` representation of the Color. The ``CMY`` components are in
|
||||
the ranges ``C`` = [0, 1], ``M`` = [0, 1], ``Y`` = [0, 1]. Note that this
|
||||
will not return the absolutely exact ``CMY`` values for the set ``RGB``
|
||||
values in all cases. Due to the ``RGB`` mapping from 0-255 and the
|
||||
``CMY`` mapping from 0-1 rounding errors may cause the ``CMY`` values to
|
||||
differ slightly from what you might expect.
|
||||
"""
|
||||
|
||||
hsva: tuple[float, float, float, float]
|
||||
"""Gets or sets the HSVA representation of the Color.
|
||||
|
||||
The ``HSVA`` representation of the Color. The ``HSVA`` components are in
|
||||
the ranges ``H`` = [0, 360], ``S`` = [0, 100], ``V`` = [0, 100], A = [0,
|
||||
100]. Note that this will not return the absolutely exact ``HSV`` values
|
||||
for the set ``RGB`` values in all cases. Due to the ``RGB`` mapping from
|
||||
0-255 and the ``HSV`` mapping from 0-100 and 0-360 rounding errors may
|
||||
cause the ``HSV`` values to differ slightly from what you might expect.
|
||||
"""
|
||||
|
||||
hsla: tuple[float, float, float, float]
|
||||
"""Gets or sets the HSLA representation of the Color.
|
||||
|
||||
The ``HSLA`` representation of the Color. The ``HSLA`` components are in
|
||||
the ranges ``H`` = [0, 360], ``S`` = [0, 100], ``L`` = [0, 100], A = [0,
|
||||
100]. Note that this will not return the absolutely exact ``HSL`` values
|
||||
for the set ``RGB`` values in all cases. Due to the ``RGB`` mapping from
|
||||
0-255 and the ``HSL`` mapping from 0-100 and 0-360 rounding errors may
|
||||
cause the ``HSL`` values to differ slightly from what you might expect.
|
||||
"""
|
||||
|
||||
i1i2i3: tuple[float, float, float]
|
||||
"""Gets or sets the I1I2I3 representation of the Color.
|
||||
|
||||
The ``I1I2I3`` representation of the Color. The ``I1I2I3`` components are
|
||||
in the ranges ``I1`` = [0, 1], ``I2`` = [-0.5, 0.5], ``I3`` = [-0.5,
|
||||
0.5]. Note that this will not return the absolutely exact ``I1I2I3``
|
||||
values for the set ``RGB`` values in all cases. Due to the ``RGB``
|
||||
mapping from 0-255 and the ``I1I2I3`` mapping from 0-1 rounding errors
|
||||
may cause the ``I1I2I3`` values to differ slightly from what you might
|
||||
expect.
|
||||
"""
|
||||
|
||||
normalized: tuple[float, float, float, float]
|
||||
"""Gets or sets the normalized representation of the Color.
|
||||
|
||||
The ``Normalized`` representation of the Color. The components of the ``Normalized``
|
||||
representation represent the basic ``RGBA`` values but normalized the
|
||||
ranges of the values are ``r`` = [0, 1], ``g`` = [0, 1], ``b`` = [0, 1]
|
||||
and ``a`` = [0, 1] respectively. Note that this will not return the absolutely exact
|
||||
``Normalized`` values for the set ``RGBA`` values in all cases.
|
||||
Due to the ``RGB`` mapping from 0-255 and the ``Normalized`` mapping from 0-1
|
||||
rounding errors may cause the ``Normalized`` values to differ
|
||||
slightly from what you might expect.
|
||||
|
||||
.. versionadded:: 2.5.0
|
||||
"""
|
||||
|
||||
hex: str
|
||||
"""Gets or sets the stringified hexadecimal representation of the Color.
|
||||
|
||||
The stringified hexadecimal representation of the Color. The hexadecimal string
|
||||
is formatted as ``"#rrggbbaa"`` where rr, gg, bb, and aa are two digit hex numbers
|
||||
in the range from 0x00 to 0xff.
|
||||
|
||||
Setting this property means changing the color channels in place. Both lowercase
|
||||
and uppercase letters are allowed, the alpha can be omitted (defaults to 0xff) and
|
||||
the string can start with either ``#`` or ``0x``.
|
||||
|
||||
.. versionadded:: 2.5.4
|
||||
"""
|
||||
|
||||
__hash__: ClassVar[None] # type: ignore[assignment]
|
||||
@property
|
||||
def __array_struct__(self) -> Any: ...
|
||||
if sys.version_info >= (3, 12):
|
||||
def __buffer__(self, flags: int, /) -> memoryview[int]: ...
|
||||
|
||||
@overload
|
||||
def __init__(self, r: int, g: int, b: int, a: int = 255) -> None: ...
|
||||
@overload
|
||||
def __init__(self, rgbvalue: ColorLike) -> None: ...
|
||||
@overload
|
||||
def __getitem__(self, i: SupportsIndex) -> int: ...
|
||||
@overload
|
||||
def __getitem__(self, s: slice) -> tuple[int, ...]: ...
|
||||
def __setitem__(self, key: int, value: int) -> None: ...
|
||||
def __iter__(self) -> Iterator[int]: ...
|
||||
def __add__(self, other: Color) -> Color: ...
|
||||
def __sub__(self, other: Color) -> Color: ...
|
||||
def __mul__(self, other: Color) -> Color: ...
|
||||
def __floordiv__(self, other: Color) -> Color: ...
|
||||
def __mod__(self, other: Color) -> Color: ...
|
||||
def __int__(self) -> int: ...
|
||||
def __float__(self) -> float: ...
|
||||
def __bytes__(self) -> bytes: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __index__(self) -> int: ...
|
||||
def __invert__(self) -> Color: ...
|
||||
def __contains__(self, other: int) -> bool: ... # type: ignore[override]
|
||||
def __getattribute__(self, name: str) -> Color | tuple[int, ...]: ...
|
||||
def __setattr__(self, name: str, value: Color | tuple[int, ...]) -> None: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def from_cmy(cls, object: tuple[float, float, float], /) -> Color: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def from_cmy(cls, c: float, m: float, y: float, /) -> Color: ...
|
||||
@classmethod # type: ignore
|
||||
def from_cmy(cls, *args) -> Color: # type: ignore
|
||||
"""Returns a Color object from a CMY representation.
|
||||
|
||||
Creates a Color object from the given CMY components. Refer to :attr:`Color.cmy`
|
||||
for more information.
|
||||
|
||||
.. versionadded:: 2.3.1
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def from_hsva(cls, object: tuple[float, float, float, float], /) -> Color: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def from_hsva(cls, h: float, s: float, v: float, a: float, /) -> Color: ...
|
||||
@classmethod # type: ignore
|
||||
def from_hsva(cls, *args) -> Color: # type: ignore
|
||||
"""Returns a Color object from an HSVA representation.
|
||||
|
||||
Creates a Color object from the given HSVA components. Refer to :attr:`Color.hsva`
|
||||
for more information.
|
||||
|
||||
.. versionadded:: 2.3.1
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def from_hsla(cls, object: tuple[float, float, float, float], /) -> Color: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def from_hsla(cls, h: float, s: float, l: float, a: float, /) -> Color: ...
|
||||
@classmethod # type: ignore
|
||||
def from_hsla(cls, *args) -> Color: # type: ignore
|
||||
"""Returns a Color object from an HSLA representation.
|
||||
|
||||
Creates a Color object from the given HSLA components. Refer to :attr:`Color.hsla`
|
||||
for more information.
|
||||
|
||||
.. versionadded:: 2.3.1
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def from_i1i2i3(cls, object: tuple[float, float, float], /) -> Color: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def from_i1i2i3(cls, i1: float, i2: float, i3: float, /) -> Color: ...
|
||||
@classmethod # type: ignore
|
||||
def from_i1i2i3(cls, *args) -> Color: # type: ignore
|
||||
"""Returns a Color object from a I1I2I3 representation.
|
||||
|
||||
Creates a Color object from the given I1I2I3 components. Refer to :attr:`Color.i1i2i3`
|
||||
for more information.
|
||||
|
||||
.. versionadded:: 2.3.1
|
||||
"""
|
||||
|
||||
@overload
|
||||
@classmethod
|
||||
def from_normalized(cls, object: tuple[float, float, float, float], /) -> Color: ...
|
||||
@overload
|
||||
@classmethod
|
||||
def from_normalized(cls, r: float, g: float, b: float, a: float, /) -> Color: ...
|
||||
@classmethod # type: ignore
|
||||
def from_normalized(cls, *args) -> Color: # type: ignore
|
||||
"""Returns a Color object from a Normalized representation.
|
||||
|
||||
Creates a Color object from the given Normalized components. Refer to :attr:`Color.normalized`
|
||||
for more information.
|
||||
|
||||
.. versionadded:: 2.5.0
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def from_hex(cls, hex: str, /) -> Color:
|
||||
"""Returns a Color object from a Hexadecimal representation.
|
||||
|
||||
Creates a Color object from the given Hexadecimal components. Refer to :attr:`Color.hex`
|
||||
for more information.
|
||||
|
||||
.. versionadded:: 2.5.6
|
||||
"""
|
||||
|
||||
def normalize(self) -> tuple[float, float, float, float]:
|
||||
"""Returns the normalized RGBA values of the Color.
|
||||
|
||||
Returns the normalized ``RGBA`` values of the Color as floating point
|
||||
values.
|
||||
"""
|
||||
|
||||
def correct_gamma(self, gamma: float, /) -> Color:
|
||||
"""Applies a certain gamma value to the Color.
|
||||
|
||||
Applies a certain gamma value to the Color and returns a new Color with
|
||||
the adjusted ``RGBA`` values.
|
||||
"""
|
||||
|
||||
@deprecated("since 2.1.3. Use unpacking instead")
|
||||
def set_length(self, length: int, /) -> None:
|
||||
"""Set the number of elements in the Color to 1,2,3, or 4.
|
||||
|
||||
DEPRECATED: You may unpack the values you need like so,
|
||||
``r, g, b, _ = pygame.Color(100, 100, 100)``
|
||||
If you only want r, g and b
|
||||
Or
|
||||
``r, g, *_ = pygame.Color(100, 100, 100)``
|
||||
if you only want r and g
|
||||
|
||||
The default Color length is 4. Colors can have lengths 1,2,3 or 4. This
|
||||
is useful if you want to unpack to r,g,b and not r,g,b,a. If you want to
|
||||
get the length of a Color do ``len(acolor)``.
|
||||
|
||||
.. deprecated:: 2.1.3
|
||||
.. versionaddedold:: 1.9.0
|
||||
"""
|
||||
|
||||
def grayscale(self) -> Color:
|
||||
"""Returns the grayscale of a Color.
|
||||
|
||||
Returns a new Color object which represents the grayscaled version of self, using the luminosity formula,
|
||||
which weights red, green, and blue according to their relative contribution to perceived brightness.
|
||||
|
||||
.. versionadded:: 2.1.4
|
||||
"""
|
||||
|
||||
def lerp(self, color: ColorLike, amount: float) -> Color:
|
||||
"""Returns a linear interpolation to the given Color.
|
||||
|
||||
Returns a Color which is a linear interpolation between self and the
|
||||
given Color in RGBA space. The second parameter determines how far
|
||||
between self and other the result is going to be.
|
||||
It must be a value between 0 and 1 where 0 means self and 1 means
|
||||
other will be returned.
|
||||
|
||||
.. versionaddedold:: 2.0.1
|
||||
"""
|
||||
|
||||
def premul_alpha(self) -> Color:
|
||||
"""Returns a Color where the r,g,b components have been multiplied by the alpha.
|
||||
|
||||
Returns a new Color where each of the red, green and blue color
|
||||
channels have been multiplied by the alpha channel of the original
|
||||
color. The alpha channel remains unchanged.
|
||||
|
||||
This is useful when working with the ``BLEND_PREMULTIPLIED`` blending mode
|
||||
flag for :meth:`pygame.Surface.blit()`, which assumes that all surfaces using
|
||||
it are using pre-multiplied alpha colors.
|
||||
|
||||
.. versionaddedold:: 2.0.0
|
||||
"""
|
||||
|
||||
@overload
|
||||
def update(self, r: int, g: int, b: int, a: int = 255, /) -> None: ...
|
||||
@overload
|
||||
def update(self, rgbvalue: ColorLike, /) -> None: ...
|
||||
def update(self, *args) -> None: # type: ignore
|
||||
"""Sets the elements of the color.
|
||||
|
||||
Sets the elements of the color. See parameters for :meth:`pygame.Color` for the
|
||||
parameters of this function. If the alpha value was not set it will not change.
|
||||
|
||||
.. versionaddedold:: 2.0.1
|
||||
"""
|
||||
@@ -0,0 +1,692 @@
|
||||
# pygame-ce - Python Game Library
|
||||
# Copyright (C) 2000-2003 Pete Shinners
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Pete Shinners
|
||||
# pete@shinners.org
|
||||
|
||||
"""A dictionary of RGBA tuples indexed by color names.
|
||||
|
||||
See https://pyga.me/docs/ref/color_list.html for sample swatches.
|
||||
"""
|
||||
|
||||
THECOLORS = {
|
||||
"aliceblue": (240, 248, 255, 255),
|
||||
"antiquewhite": (250, 235, 215, 255),
|
||||
"antiquewhite1": (255, 239, 219, 255),
|
||||
"antiquewhite2": (238, 223, 204, 255),
|
||||
"antiquewhite3": (205, 192, 176, 255),
|
||||
"antiquewhite4": (139, 131, 120, 255),
|
||||
"aqua": (0, 255, 255, 255),
|
||||
"aquamarine": (127, 255, 212, 255),
|
||||
"aquamarine1": (127, 255, 212, 255),
|
||||
"aquamarine2": (118, 238, 198, 255),
|
||||
"aquamarine3": (102, 205, 170, 255),
|
||||
"aquamarine4": (69, 139, 116, 255),
|
||||
"azure": (240, 255, 255, 255),
|
||||
"azure1": (240, 255, 255, 255),
|
||||
"azure3": (193, 205, 205, 255),
|
||||
"azure2": (224, 238, 238, 255),
|
||||
"azure4": (131, 139, 139, 255),
|
||||
"beige": (245, 245, 220, 255),
|
||||
"bisque": (255, 228, 196, 255),
|
||||
"bisque1": (255, 228, 196, 255),
|
||||
"bisque2": (238, 213, 183, 255),
|
||||
"bisque3": (205, 183, 158, 255),
|
||||
"bisque4": (139, 125, 107, 255),
|
||||
"black": (0, 0, 0, 255),
|
||||
"blanchedalmond": (255, 235, 205, 255),
|
||||
"blue": (0, 0, 255, 255),
|
||||
"blue1": (0, 0, 255, 255),
|
||||
"blue2": (0, 0, 238, 255),
|
||||
"blue3": (0, 0, 205, 255),
|
||||
"blue4": (0, 0, 139, 255),
|
||||
"blueviolet": (138, 43, 226, 255),
|
||||
"brown": (165, 42, 42, 255),
|
||||
"brown1": (255, 64, 64, 255),
|
||||
"brown2": (238, 59, 59, 255),
|
||||
"brown3": (205, 51, 51, 255),
|
||||
"brown4": (139, 35, 35, 255),
|
||||
"burlywood": (222, 184, 135, 255),
|
||||
"burlywood1": (255, 211, 155, 255),
|
||||
"burlywood2": (238, 197, 145, 255),
|
||||
"burlywood3": (205, 170, 125, 255),
|
||||
"burlywood4": (139, 115, 85, 255),
|
||||
"cadetblue": (95, 158, 160, 255),
|
||||
"cadetblue1": (152, 245, 255, 255),
|
||||
"cadetblue2": (142, 229, 238, 255),
|
||||
"cadetblue3": (122, 197, 205, 255),
|
||||
"cadetblue4": (83, 134, 139, 255),
|
||||
"chartreuse": (127, 255, 0, 255),
|
||||
"chartreuse1": (127, 255, 0, 255),
|
||||
"chartreuse2": (118, 238, 0, 255),
|
||||
"chartreuse3": (102, 205, 0, 255),
|
||||
"chartreuse4": (69, 139, 0, 255),
|
||||
"chocolate": (210, 105, 30, 255),
|
||||
"chocolate1": (255, 127, 36, 255),
|
||||
"chocolate2": (238, 118, 33, 255),
|
||||
"chocolate3": (205, 102, 29, 255),
|
||||
"chocolate4": (139, 69, 19, 255),
|
||||
"coral": (255, 127, 80, 255),
|
||||
"coral1": (255, 114, 86, 255),
|
||||
"coral2": (238, 106, 80, 255),
|
||||
"coral3": (205, 91, 69, 255),
|
||||
"coral4": (139, 62, 47, 255),
|
||||
"cornflowerblue": (100, 149, 237, 255),
|
||||
"cornsilk": (255, 248, 220, 255),
|
||||
"cornsilk1": (255, 248, 220, 255),
|
||||
"cornsilk2": (238, 232, 205, 255),
|
||||
"cornsilk3": (205, 200, 177, 255),
|
||||
"cornsilk4": (139, 136, 120, 255),
|
||||
"crimson": (220, 20, 60, 255),
|
||||
"cyan": (0, 255, 255, 255),
|
||||
"cyan1": (0, 255, 255, 255),
|
||||
"cyan2": (0, 238, 238, 255),
|
||||
"cyan3": (0, 205, 205, 255),
|
||||
"cyan4": (0, 139, 139, 255),
|
||||
"darkblue": (0, 0, 139, 255),
|
||||
"darkcyan": (0, 139, 139, 255),
|
||||
"darkgoldenrod": (184, 134, 11, 255),
|
||||
"darkgoldenrod1": (255, 185, 15, 255),
|
||||
"darkgoldenrod2": (238, 173, 14, 255),
|
||||
"darkgoldenrod3": (205, 149, 12, 255),
|
||||
"darkgoldenrod4": (139, 101, 8, 255),
|
||||
"darkgray": (169, 169, 169, 255),
|
||||
"darkgreen": (0, 100, 0, 255),
|
||||
"darkgrey": (169, 169, 169, 255),
|
||||
"darkkhaki": (189, 183, 107, 255),
|
||||
"darkmagenta": (139, 0, 139, 255),
|
||||
"darkolivegreen": (85, 107, 47, 255),
|
||||
"darkolivegreen1": (202, 255, 112, 255),
|
||||
"darkolivegreen2": (188, 238, 104, 255),
|
||||
"darkolivegreen3": (162, 205, 90, 255),
|
||||
"darkolivegreen4": (110, 139, 61, 255),
|
||||
"darkorange": (255, 140, 0, 255),
|
||||
"darkorange1": (255, 127, 0, 255),
|
||||
"darkorange2": (238, 118, 0, 255),
|
||||
"darkorange3": (205, 102, 0, 255),
|
||||
"darkorange4": (139, 69, 0, 255),
|
||||
"darkorchid": (153, 50, 204, 255),
|
||||
"darkorchid1": (191, 62, 255, 255),
|
||||
"darkorchid2": (178, 58, 238, 255),
|
||||
"darkorchid3": (154, 50, 205, 255),
|
||||
"darkorchid4": (104, 34, 139, 255),
|
||||
"darkred": (139, 0, 0, 255),
|
||||
"darksalmon": (233, 150, 122, 255),
|
||||
"darkseagreen": (143, 188, 143, 255),
|
||||
"darkseagreen1": (193, 255, 193, 255),
|
||||
"darkseagreen2": (180, 238, 180, 255),
|
||||
"darkseagreen3": (155, 205, 155, 255),
|
||||
"darkseagreen4": (105, 139, 105, 255),
|
||||
"darkslateblue": (72, 61, 139, 255),
|
||||
"darkslategray": (47, 79, 79, 255),
|
||||
"darkslategray1": (151, 255, 255, 255),
|
||||
"darkslategray2": (141, 238, 238, 255),
|
||||
"darkslategray3": (121, 205, 205, 255),
|
||||
"darkslategray4": (82, 139, 139, 255),
|
||||
"darkslategrey": (47, 79, 79, 255),
|
||||
"darkturquoise": (0, 206, 209, 255),
|
||||
"darkviolet": (148, 0, 211, 255),
|
||||
"deeppink": (255, 20, 147, 255),
|
||||
"deeppink1": (255, 20, 147, 255),
|
||||
"deeppink2": (238, 18, 137, 255),
|
||||
"deeppink3": (205, 16, 118, 255),
|
||||
"deeppink4": (139, 10, 80, 255),
|
||||
"deepskyblue": (0, 191, 255, 255),
|
||||
"deepskyblue1": (0, 191, 255, 255),
|
||||
"deepskyblue2": (0, 178, 238, 255),
|
||||
"deepskyblue3": (0, 154, 205, 255),
|
||||
"deepskyblue4": (0, 104, 139, 255),
|
||||
"dimgray": (105, 105, 105, 255),
|
||||
"dimgrey": (105, 105, 105, 255),
|
||||
"dodgerblue": (30, 144, 255, 255),
|
||||
"dodgerblue1": (30, 144, 255, 255),
|
||||
"dodgerblue2": (28, 134, 238, 255),
|
||||
"dodgerblue3": (24, 116, 205, 255),
|
||||
"dodgerblue4": (16, 78, 139, 255),
|
||||
"firebrick": (178, 34, 34, 255),
|
||||
"firebrick1": (255, 48, 48, 255),
|
||||
"firebrick2": (238, 44, 44, 255),
|
||||
"firebrick3": (205, 38, 38, 255),
|
||||
"firebrick4": (139, 26, 26, 255),
|
||||
"floralwhite": (255, 250, 240, 255),
|
||||
"forestgreen": (34, 139, 34, 255),
|
||||
"fuchsia": (255, 0, 255, 255),
|
||||
"gainsboro": (220, 220, 220, 255),
|
||||
"ghostwhite": (248, 248, 255, 255),
|
||||
"gold": (255, 215, 0, 255),
|
||||
"gold1": (255, 215, 0, 255),
|
||||
"gold2": (238, 201, 0, 255),
|
||||
"gold3": (205, 173, 0, 255),
|
||||
"gold4": (139, 117, 0, 255),
|
||||
"goldenrod": (218, 165, 32, 255),
|
||||
"goldenrod1": (255, 193, 37, 255),
|
||||
"goldenrod2": (238, 180, 34, 255),
|
||||
"goldenrod3": (205, 155, 29, 255),
|
||||
"goldenrod4": (139, 105, 20, 255),
|
||||
"gray": (190, 190, 190, 255),
|
||||
"gray0": (0, 0, 0, 255),
|
||||
"gray1": (3, 3, 3, 255),
|
||||
"gray2": (5, 5, 5, 255),
|
||||
"gray3": (8, 8, 8, 255),
|
||||
"gray4": (10, 10, 10, 255),
|
||||
"gray5": (13, 13, 13, 255),
|
||||
"gray6": (15, 15, 15, 255),
|
||||
"gray7": (18, 18, 18, 255),
|
||||
"gray8": (20, 20, 20, 255),
|
||||
"gray9": (23, 23, 23, 255),
|
||||
"gray10": (26, 26, 26, 255),
|
||||
"gray11": (28, 28, 28, 255),
|
||||
"gray12": (31, 31, 31, 255),
|
||||
"gray13": (33, 33, 33, 255),
|
||||
"gray14": (36, 36, 36, 255),
|
||||
"gray15": (38, 38, 38, 255),
|
||||
"gray16": (41, 41, 41, 255),
|
||||
"gray17": (43, 43, 43, 255),
|
||||
"gray18": (46, 46, 46, 255),
|
||||
"gray19": (48, 48, 48, 255),
|
||||
"gray20": (51, 51, 51, 255),
|
||||
"gray21": (54, 54, 54, 255),
|
||||
"gray22": (56, 56, 56, 255),
|
||||
"gray23": (59, 59, 59, 255),
|
||||
"gray24": (61, 61, 61, 255),
|
||||
"gray25": (64, 64, 64, 255),
|
||||
"gray26": (66, 66, 66, 255),
|
||||
"gray27": (69, 69, 69, 255),
|
||||
"gray28": (71, 71, 71, 255),
|
||||
"gray29": (74, 74, 74, 255),
|
||||
"gray30": (77, 77, 77, 255),
|
||||
"gray31": (79, 79, 79, 255),
|
||||
"gray32": (82, 82, 82, 255),
|
||||
"gray33": (84, 84, 84, 255),
|
||||
"gray34": (87, 87, 87, 255),
|
||||
"gray35": (89, 89, 89, 255),
|
||||
"gray36": (92, 92, 92, 255),
|
||||
"gray37": (94, 94, 94, 255),
|
||||
"gray38": (97, 97, 97, 255),
|
||||
"gray39": (99, 99, 99, 255),
|
||||
"gray40": (102, 102, 102, 255),
|
||||
"gray41": (105, 105, 105, 255),
|
||||
"gray42": (107, 107, 107, 255),
|
||||
"gray43": (110, 110, 110, 255),
|
||||
"gray44": (112, 112, 112, 255),
|
||||
"gray45": (115, 115, 115, 255),
|
||||
"gray46": (117, 117, 117, 255),
|
||||
"gray47": (120, 120, 120, 255),
|
||||
"gray48": (122, 122, 122, 255),
|
||||
"gray49": (125, 125, 125, 255),
|
||||
"gray50": (127, 127, 127, 255),
|
||||
"gray51": (130, 130, 130, 255),
|
||||
"gray52": (133, 133, 133, 255),
|
||||
"gray53": (135, 135, 135, 255),
|
||||
"gray54": (138, 138, 138, 255),
|
||||
"gray55": (140, 140, 140, 255),
|
||||
"gray56": (143, 143, 143, 255),
|
||||
"gray57": (145, 145, 145, 255),
|
||||
"gray58": (148, 148, 148, 255),
|
||||
"gray59": (150, 150, 150, 255),
|
||||
"gray60": (153, 153, 153, 255),
|
||||
"gray61": (156, 156, 156, 255),
|
||||
"gray62": (158, 158, 158, 255),
|
||||
"gray63": (161, 161, 161, 255),
|
||||
"gray64": (163, 163, 163, 255),
|
||||
"gray65": (166, 166, 166, 255),
|
||||
"gray66": (168, 168, 168, 255),
|
||||
"gray67": (171, 171, 171, 255),
|
||||
"gray68": (173, 173, 173, 255),
|
||||
"gray69": (176, 176, 176, 255),
|
||||
"gray70": (179, 179, 179, 255),
|
||||
"gray71": (181, 181, 181, 255),
|
||||
"gray72": (184, 184, 184, 255),
|
||||
"gray73": (186, 186, 186, 255),
|
||||
"gray74": (189, 189, 189, 255),
|
||||
"gray75": (191, 191, 191, 255),
|
||||
"gray76": (194, 194, 194, 255),
|
||||
"gray77": (196, 196, 196, 255),
|
||||
"gray78": (199, 199, 199, 255),
|
||||
"gray79": (201, 201, 201, 255),
|
||||
"gray80": (204, 204, 204, 255),
|
||||
"gray81": (207, 207, 207, 255),
|
||||
"gray82": (209, 209, 209, 255),
|
||||
"gray83": (212, 212, 212, 255),
|
||||
"gray84": (214, 214, 214, 255),
|
||||
"gray85": (217, 217, 217, 255),
|
||||
"gray86": (219, 219, 219, 255),
|
||||
"gray87": (222, 222, 222, 255),
|
||||
"gray88": (224, 224, 224, 255),
|
||||
"gray89": (227, 227, 227, 255),
|
||||
"gray90": (229, 229, 229, 255),
|
||||
"gray91": (232, 232, 232, 255),
|
||||
"gray92": (235, 235, 235, 255),
|
||||
"gray93": (237, 237, 237, 255),
|
||||
"gray94": (240, 240, 240, 255),
|
||||
"gray95": (242, 242, 242, 255),
|
||||
"gray96": (245, 245, 245, 255),
|
||||
"gray97": (247, 247, 247, 255),
|
||||
"gray98": (250, 250, 250, 255),
|
||||
"gray99": (252, 252, 252, 255),
|
||||
"gray100": (255, 255, 255, 255),
|
||||
"green": (0, 255, 0, 255),
|
||||
"green1": (0, 255, 0, 255),
|
||||
"green2": (0, 238, 0, 255),
|
||||
"green3": (0, 205, 0, 255),
|
||||
"green4": (0, 139, 0, 255),
|
||||
"greenyellow": (173, 255, 47, 255),
|
||||
"grey": (190, 190, 190, 255),
|
||||
"grey0": (0, 0, 0, 255),
|
||||
"grey1": (3, 3, 3, 255),
|
||||
"grey2": (5, 5, 5, 255),
|
||||
"grey3": (8, 8, 8, 255),
|
||||
"grey4": (10, 10, 10, 255),
|
||||
"grey5": (13, 13, 13, 255),
|
||||
"grey6": (15, 15, 15, 255),
|
||||
"grey7": (18, 18, 18, 255),
|
||||
"grey8": (20, 20, 20, 255),
|
||||
"grey9": (23, 23, 23, 255),
|
||||
"grey10": (26, 26, 26, 255),
|
||||
"grey11": (28, 28, 28, 255),
|
||||
"grey12": (31, 31, 31, 255),
|
||||
"grey13": (33, 33, 33, 255),
|
||||
"grey14": (36, 36, 36, 255),
|
||||
"grey15": (38, 38, 38, 255),
|
||||
"grey16": (41, 41, 41, 255),
|
||||
"grey17": (43, 43, 43, 255),
|
||||
"grey18": (46, 46, 46, 255),
|
||||
"grey19": (48, 48, 48, 255),
|
||||
"grey20": (51, 51, 51, 255),
|
||||
"grey21": (54, 54, 54, 255),
|
||||
"grey22": (56, 56, 56, 255),
|
||||
"grey23": (59, 59, 59, 255),
|
||||
"grey24": (61, 61, 61, 255),
|
||||
"grey25": (64, 64, 64, 255),
|
||||
"grey26": (66, 66, 66, 255),
|
||||
"grey27": (69, 69, 69, 255),
|
||||
"grey28": (71, 71, 71, 255),
|
||||
"grey29": (74, 74, 74, 255),
|
||||
"grey30": (77, 77, 77, 255),
|
||||
"grey31": (79, 79, 79, 255),
|
||||
"grey32": (82, 82, 82, 255),
|
||||
"grey33": (84, 84, 84, 255),
|
||||
"grey34": (87, 87, 87, 255),
|
||||
"grey35": (89, 89, 89, 255),
|
||||
"grey36": (92, 92, 92, 255),
|
||||
"grey37": (94, 94, 94, 255),
|
||||
"grey38": (97, 97, 97, 255),
|
||||
"grey39": (99, 99, 99, 255),
|
||||
"grey40": (102, 102, 102, 255),
|
||||
"grey41": (105, 105, 105, 255),
|
||||
"grey42": (107, 107, 107, 255),
|
||||
"grey43": (110, 110, 110, 255),
|
||||
"grey44": (112, 112, 112, 255),
|
||||
"grey45": (115, 115, 115, 255),
|
||||
"grey46": (117, 117, 117, 255),
|
||||
"grey47": (120, 120, 120, 255),
|
||||
"grey48": (122, 122, 122, 255),
|
||||
"grey49": (125, 125, 125, 255),
|
||||
"grey50": (127, 127, 127, 255),
|
||||
"grey51": (130, 130, 130, 255),
|
||||
"grey52": (133, 133, 133, 255),
|
||||
"grey53": (135, 135, 135, 255),
|
||||
"grey54": (138, 138, 138, 255),
|
||||
"grey55": (140, 140, 140, 255),
|
||||
"grey56": (143, 143, 143, 255),
|
||||
"grey57": (145, 145, 145, 255),
|
||||
"grey58": (148, 148, 148, 255),
|
||||
"grey59": (150, 150, 150, 255),
|
||||
"grey60": (153, 153, 153, 255),
|
||||
"grey61": (156, 156, 156, 255),
|
||||
"grey62": (158, 158, 158, 255),
|
||||
"grey63": (161, 161, 161, 255),
|
||||
"grey64": (163, 163, 163, 255),
|
||||
"grey65": (166, 166, 166, 255),
|
||||
"grey66": (168, 168, 168, 255),
|
||||
"grey67": (171, 171, 171, 255),
|
||||
"grey68": (173, 173, 173, 255),
|
||||
"grey69": (176, 176, 176, 255),
|
||||
"grey70": (179, 179, 179, 255),
|
||||
"grey71": (181, 181, 181, 255),
|
||||
"grey72": (184, 184, 184, 255),
|
||||
"grey73": (186, 186, 186, 255),
|
||||
"grey74": (189, 189, 189, 255),
|
||||
"grey75": (191, 191, 191, 255),
|
||||
"grey76": (194, 194, 194, 255),
|
||||
"grey77": (196, 196, 196, 255),
|
||||
"grey78": (199, 199, 199, 255),
|
||||
"grey79": (201, 201, 201, 255),
|
||||
"grey80": (204, 204, 204, 255),
|
||||
"grey81": (207, 207, 207, 255),
|
||||
"grey82": (209, 209, 209, 255),
|
||||
"grey83": (212, 212, 212, 255),
|
||||
"grey84": (214, 214, 214, 255),
|
||||
"grey85": (217, 217, 217, 255),
|
||||
"grey86": (219, 219, 219, 255),
|
||||
"grey87": (222, 222, 222, 255),
|
||||
"grey88": (224, 224, 224, 255),
|
||||
"grey89": (227, 227, 227, 255),
|
||||
"grey90": (229, 229, 229, 255),
|
||||
"grey91": (232, 232, 232, 255),
|
||||
"grey92": (235, 235, 235, 255),
|
||||
"grey93": (237, 237, 237, 255),
|
||||
"grey94": (240, 240, 240, 255),
|
||||
"grey95": (242, 242, 242, 255),
|
||||
"grey96": (245, 245, 245, 255),
|
||||
"grey97": (247, 247, 247, 255),
|
||||
"grey98": (250, 250, 250, 255),
|
||||
"grey99": (252, 252, 252, 255),
|
||||
"grey100": (255, 255, 255, 255),
|
||||
"honeydew": (240, 255, 240, 255),
|
||||
"honeydew1": (240, 255, 240, 255),
|
||||
"honeydew2": (224, 238, 224, 255),
|
||||
"honeydew3": (193, 205, 193, 255),
|
||||
"honeydew4": (131, 139, 131, 255),
|
||||
"hotpink": (255, 105, 180, 255),
|
||||
"hotpink1": (255, 110, 180, 255),
|
||||
"hotpink2": (238, 106, 167, 255),
|
||||
"hotpink3": (205, 96, 144, 255),
|
||||
"hotpink4": (139, 58, 98, 255),
|
||||
"indianred": (205, 92, 92, 255),
|
||||
"indianred1": (255, 106, 106, 255),
|
||||
"indianred2": (238, 99, 99, 255),
|
||||
"indianred3": (205, 85, 85, 255),
|
||||
"indianred4": (139, 58, 58, 255),
|
||||
"indigo": (75, 0, 130, 255),
|
||||
"ivory": (255, 255, 240, 255),
|
||||
"ivory1": (255, 255, 240, 255),
|
||||
"ivory2": (238, 238, 224, 255),
|
||||
"ivory3": (205, 205, 193, 255),
|
||||
"ivory4": (139, 139, 131, 255),
|
||||
"khaki": (240, 230, 140, 255),
|
||||
"khaki1": (255, 246, 143, 255),
|
||||
"khaki2": (238, 230, 133, 255),
|
||||
"khaki3": (205, 198, 115, 255),
|
||||
"khaki4": (139, 134, 78, 255),
|
||||
"lavender": (230, 230, 250, 255),
|
||||
"lavenderblush": (255, 240, 245, 255),
|
||||
"lavenderblush1": (255, 240, 245, 255),
|
||||
"lavenderblush2": (238, 224, 229, 255),
|
||||
"lavenderblush3": (205, 193, 197, 255),
|
||||
"lavenderblush4": (139, 131, 134, 255),
|
||||
"lawngreen": (124, 252, 0, 255),
|
||||
"lemonchiffon": (255, 250, 205, 255),
|
||||
"lemonchiffon1": (255, 250, 205, 255),
|
||||
"lemonchiffon2": (238, 233, 191, 255),
|
||||
"lemonchiffon3": (205, 201, 165, 255),
|
||||
"lemonchiffon4": (139, 137, 112, 255),
|
||||
"lightblue": (173, 216, 230, 255),
|
||||
"lightblue1": (191, 239, 255, 255),
|
||||
"lightblue2": (178, 223, 238, 255),
|
||||
"lightblue3": (154, 192, 205, 255),
|
||||
"lightblue4": (104, 131, 139, 255),
|
||||
"lightcoral": (240, 128, 128, 255),
|
||||
"lightcyan": (224, 255, 255, 255),
|
||||
"lightcyan1": (224, 255, 255, 255),
|
||||
"lightcyan2": (209, 238, 238, 255),
|
||||
"lightcyan3": (180, 205, 205, 255),
|
||||
"lightcyan4": (122, 139, 139, 255),
|
||||
"lightgoldenrod": (238, 221, 130, 255),
|
||||
"lightgoldenrod1": (255, 236, 139, 255),
|
||||
"lightgoldenrod2": (238, 220, 130, 255),
|
||||
"lightgoldenrod3": (205, 190, 112, 255),
|
||||
"lightgoldenrod4": (139, 129, 76, 255),
|
||||
"lightgoldenrodyellow": (250, 250, 210, 255),
|
||||
"lightgray": (211, 211, 211, 255),
|
||||
"lightgreen": (144, 238, 144, 255),
|
||||
"lightgrey": (211, 211, 211, 255),
|
||||
"lightpink": (255, 182, 193, 255),
|
||||
"lightpink1": (255, 174, 185, 255),
|
||||
"lightpink2": (238, 162, 173, 255),
|
||||
"lightpink3": (205, 140, 149, 255),
|
||||
"lightpink4": (139, 95, 101, 255),
|
||||
"lightsalmon": (255, 160, 122, 255),
|
||||
"lightsalmon1": (255, 160, 122, 255),
|
||||
"lightsalmon2": (238, 149, 114, 255),
|
||||
"lightsalmon3": (205, 129, 98, 255),
|
||||
"lightsalmon4": (139, 87, 66, 255),
|
||||
"lightseagreen": (32, 178, 170, 255),
|
||||
"lightskyblue": (135, 206, 250, 255),
|
||||
"lightskyblue1": (176, 226, 255, 255),
|
||||
"lightskyblue2": (164, 211, 238, 255),
|
||||
"lightskyblue3": (141, 182, 205, 255),
|
||||
"lightskyblue4": (96, 123, 139, 255),
|
||||
"lightslateblue": (132, 112, 255, 255),
|
||||
"lightslategray": (119, 136, 153, 255),
|
||||
"lightslategrey": (119, 136, 153, 255),
|
||||
"lightsteelblue": (176, 196, 222, 255),
|
||||
"lightsteelblue1": (202, 225, 255, 255),
|
||||
"lightsteelblue2": (188, 210, 238, 255),
|
||||
"lightsteelblue3": (162, 181, 205, 255),
|
||||
"lightsteelblue4": (110, 123, 139, 255),
|
||||
"lightyellow": (255, 255, 224, 255),
|
||||
"lightyellow1": (255, 255, 224, 255),
|
||||
"lightyellow2": (238, 238, 209, 255),
|
||||
"lightyellow3": (205, 205, 180, 255),
|
||||
"lightyellow4": (139, 139, 122, 255),
|
||||
"linen": (250, 240, 230, 255),
|
||||
"lime": (0, 255, 0, 255),
|
||||
"limegreen": (50, 205, 50, 255),
|
||||
"magenta": (255, 0, 255, 255),
|
||||
"magenta1": (255, 0, 255, 255),
|
||||
"magenta2": (238, 0, 238, 255),
|
||||
"magenta3": (205, 0, 205, 255),
|
||||
"magenta4": (139, 0, 139, 255),
|
||||
"maroon": (176, 48, 96, 255),
|
||||
"maroon1": (255, 52, 179, 255),
|
||||
"maroon2": (238, 48, 167, 255),
|
||||
"maroon3": (205, 41, 144, 255),
|
||||
"maroon4": (139, 28, 98, 255),
|
||||
"mediumaquamarine": (102, 205, 170, 255),
|
||||
"mediumblue": (0, 0, 205, 255),
|
||||
"mediumorchid": (186, 85, 211, 255),
|
||||
"mediumorchid1": (224, 102, 255, 255),
|
||||
"mediumorchid2": (209, 95, 238, 255),
|
||||
"mediumorchid3": (180, 82, 205, 255),
|
||||
"mediumorchid4": (122, 55, 139, 255),
|
||||
"mediumpurple": (147, 112, 219, 255),
|
||||
"mediumpurple1": (171, 130, 255, 255),
|
||||
"mediumpurple2": (159, 121, 238, 255),
|
||||
"mediumpurple3": (137, 104, 205, 255),
|
||||
"mediumpurple4": (93, 71, 139, 255),
|
||||
"mediumseagreen": (60, 179, 113, 255),
|
||||
"mediumslateblue": (123, 104, 238, 255),
|
||||
"mediumspringgreen": (0, 250, 154, 255),
|
||||
"mediumturquoise": (72, 209, 204, 255),
|
||||
"mediumvioletred": (199, 21, 133, 255),
|
||||
"midnightblue": (25, 25, 112, 255),
|
||||
"mintcream": (245, 255, 250, 255),
|
||||
"mistyrose": (255, 228, 225, 255),
|
||||
"mistyrose1": (255, 228, 225, 255),
|
||||
"mistyrose2": (238, 213, 210, 255),
|
||||
"mistyrose3": (205, 183, 181, 255),
|
||||
"mistyrose4": (139, 125, 123, 255),
|
||||
"moccasin": (255, 228, 181, 255),
|
||||
"navajowhite": (255, 222, 173, 255),
|
||||
"navajowhite1": (255, 222, 173, 255),
|
||||
"navajowhite2": (238, 207, 161, 255),
|
||||
"navajowhite3": (205, 179, 139, 255),
|
||||
"navajowhite4": (139, 121, 94, 255),
|
||||
"navy": (0, 0, 128, 255),
|
||||
"navyblue": (0, 0, 128, 255),
|
||||
"oldlace": (253, 245, 230, 255),
|
||||
"olive": (128, 128, 0, 255),
|
||||
"olivedrab": (107, 142, 35, 255),
|
||||
"olivedrab1": (192, 255, 62, 255),
|
||||
"olivedrab2": (179, 238, 58, 255),
|
||||
"olivedrab3": (154, 205, 50, 255),
|
||||
"olivedrab4": (105, 139, 34, 255),
|
||||
"orange": (255, 165, 0, 255),
|
||||
"orange1": (255, 165, 0, 255),
|
||||
"orange2": (238, 154, 0, 255),
|
||||
"orange3": (205, 133, 0, 255),
|
||||
"orange4": (139, 90, 0, 255),
|
||||
"orangered": (255, 69, 0, 255),
|
||||
"orangered1": (255, 69, 0, 255),
|
||||
"orangered2": (238, 64, 0, 255),
|
||||
"orangered3": (205, 55, 0, 255),
|
||||
"orangered4": (139, 37, 0, 255),
|
||||
"orchid": (218, 112, 214, 255),
|
||||
"orchid1": (255, 131, 250, 255),
|
||||
"orchid2": (238, 122, 233, 255),
|
||||
"orchid3": (205, 105, 201, 255),
|
||||
"orchid4": (139, 71, 137, 255),
|
||||
"palegreen": (152, 251, 152, 255),
|
||||
"palegreen1": (154, 255, 154, 255),
|
||||
"palegreen2": (144, 238, 144, 255),
|
||||
"palegreen3": (124, 205, 124, 255),
|
||||
"palegreen4": (84, 139, 84, 255),
|
||||
"palegoldenrod": (238, 232, 170, 255),
|
||||
"paleturquoise": (175, 238, 238, 255),
|
||||
"paleturquoise1": (187, 255, 255, 255),
|
||||
"paleturquoise2": (174, 238, 238, 255),
|
||||
"paleturquoise3": (150, 205, 205, 255),
|
||||
"paleturquoise4": (102, 139, 139, 255),
|
||||
"palevioletred": (219, 112, 147, 255),
|
||||
"palevioletred1": (255, 130, 171, 255),
|
||||
"palevioletred2": (238, 121, 159, 255),
|
||||
"palevioletred3": (205, 104, 137, 255),
|
||||
"palevioletred4": (139, 71, 93, 255),
|
||||
"papayawhip": (255, 239, 213, 255),
|
||||
"peachpuff": (255, 218, 185, 255),
|
||||
"peachpuff1": (255, 218, 185, 255),
|
||||
"peachpuff2": (238, 203, 173, 255),
|
||||
"peachpuff3": (205, 175, 149, 255),
|
||||
"peachpuff4": (139, 119, 101, 255),
|
||||
"peru": (205, 133, 63, 255),
|
||||
"pink": (255, 192, 203, 255),
|
||||
"pink1": (255, 181, 197, 255),
|
||||
"pink2": (238, 169, 184, 255),
|
||||
"pink3": (205, 145, 158, 255),
|
||||
"pink4": (139, 99, 108, 255),
|
||||
"plum": (221, 160, 221, 255),
|
||||
"plum1": (255, 187, 255, 255),
|
||||
"plum2": (238, 174, 238, 255),
|
||||
"plum3": (205, 150, 205, 255),
|
||||
"plum4": (139, 102, 139, 255),
|
||||
"powderblue": (176, 224, 230, 255),
|
||||
"purple": (160, 32, 240, 255),
|
||||
"purple1": (155, 48, 255, 255),
|
||||
"purple2": (145, 44, 238, 255),
|
||||
"purple3": (125, 38, 205, 255),
|
||||
"purple4": (85, 26, 139, 255),
|
||||
"red": (255, 0, 0, 255),
|
||||
"red1": (255, 0, 0, 255),
|
||||
"red2": (238, 0, 0, 255),
|
||||
"red3": (205, 0, 0, 255),
|
||||
"red4": (139, 0, 0, 255),
|
||||
"rosybrown": (188, 143, 143, 255),
|
||||
"rosybrown1": (255, 193, 193, 255),
|
||||
"rosybrown2": (238, 180, 180, 255),
|
||||
"rosybrown3": (205, 155, 155, 255),
|
||||
"rosybrown4": (139, 105, 105, 255),
|
||||
"royalblue": (65, 105, 225, 255),
|
||||
"royalblue1": (72, 118, 255, 255),
|
||||
"royalblue2": (67, 110, 238, 255),
|
||||
"royalblue3": (58, 95, 205, 255),
|
||||
"royalblue4": (39, 64, 139, 255),
|
||||
"salmon": (250, 128, 114, 255),
|
||||
"salmon1": (255, 140, 105, 255),
|
||||
"salmon2": (238, 130, 98, 255),
|
||||
"salmon3": (205, 112, 84, 255),
|
||||
"salmon4": (139, 76, 57, 255),
|
||||
"saddlebrown": (139, 69, 19, 255),
|
||||
"sandybrown": (244, 164, 96, 255),
|
||||
"seagreen": (46, 139, 87, 255),
|
||||
"seagreen1": (84, 255, 159, 255),
|
||||
"seagreen2": (78, 238, 148, 255),
|
||||
"seagreen3": (67, 205, 128, 255),
|
||||
"seagreen4": (46, 139, 87, 255),
|
||||
"seashell": (255, 245, 238, 255),
|
||||
"seashell1": (255, 245, 238, 255),
|
||||
"seashell2": (238, 229, 222, 255),
|
||||
"seashell3": (205, 197, 191, 255),
|
||||
"seashell4": (139, 134, 130, 255),
|
||||
"sienna": (160, 82, 45, 255),
|
||||
"sienna1": (255, 130, 71, 255),
|
||||
"sienna2": (238, 121, 66, 255),
|
||||
"sienna3": (205, 104, 57, 255),
|
||||
"sienna4": (139, 71, 38, 255),
|
||||
"silver": (192, 192, 192, 255),
|
||||
"skyblue": (135, 206, 235, 255),
|
||||
"skyblue1": (135, 206, 255, 255),
|
||||
"skyblue2": (126, 192, 238, 255),
|
||||
"skyblue3": (108, 166, 205, 255),
|
||||
"skyblue4": (74, 112, 139, 255),
|
||||
"slateblue": (106, 90, 205, 255),
|
||||
"slateblue1": (131, 111, 255, 255),
|
||||
"slateblue2": (122, 103, 238, 255),
|
||||
"slateblue3": (105, 89, 205, 255),
|
||||
"slateblue4": (71, 60, 139, 255),
|
||||
"slategray": (112, 128, 144, 255),
|
||||
"slategray1": (198, 226, 255, 255),
|
||||
"slategray2": (185, 211, 238, 255),
|
||||
"slategray3": (159, 182, 205, 255),
|
||||
"slategray4": (108, 123, 139, 255),
|
||||
"slategrey": (112, 128, 144, 255),
|
||||
"snow": (255, 250, 250, 255),
|
||||
"snow1": (255, 250, 250, 255),
|
||||
"snow2": (238, 233, 233, 255),
|
||||
"snow3": (205, 201, 201, 255),
|
||||
"snow4": (139, 137, 137, 255),
|
||||
"springgreen": (0, 255, 127, 255),
|
||||
"springgreen1": (0, 255, 127, 255),
|
||||
"springgreen2": (0, 238, 118, 255),
|
||||
"springgreen3": (0, 205, 102, 255),
|
||||
"springgreen4": (0, 139, 69, 255),
|
||||
"steelblue": (70, 130, 180, 255),
|
||||
"steelblue1": (99, 184, 255, 255),
|
||||
"steelblue2": (92, 172, 238, 255),
|
||||
"steelblue3": (79, 148, 205, 255),
|
||||
"steelblue4": (54, 100, 139, 255),
|
||||
"tan": (210, 180, 140, 255),
|
||||
"tan1": (255, 165, 79, 255),
|
||||
"tan2": (238, 154, 73, 255),
|
||||
"tan3": (205, 133, 63, 255),
|
||||
"tan4": (139, 90, 43, 255),
|
||||
"teal": (0, 128, 128, 255),
|
||||
"thistle": (216, 191, 216, 255),
|
||||
"thistle1": (255, 225, 255, 255),
|
||||
"thistle2": (238, 210, 238, 255),
|
||||
"thistle3": (205, 181, 205, 255),
|
||||
"thistle4": (139, 123, 139, 255),
|
||||
"tomato": (255, 99, 71, 255),
|
||||
"tomato1": (255, 99, 71, 255),
|
||||
"tomato2": (238, 92, 66, 255),
|
||||
"tomato3": (205, 79, 57, 255),
|
||||
"tomato4": (139, 54, 38, 255),
|
||||
"turquoise": (64, 224, 208, 255),
|
||||
"turquoise1": (0, 245, 255, 255),
|
||||
"turquoise2": (0, 229, 238, 255),
|
||||
"turquoise3": (0, 197, 205, 255),
|
||||
"turquoise4": (0, 134, 139, 255),
|
||||
"violet": (238, 130, 238, 255),
|
||||
"violetred": (208, 32, 144, 255),
|
||||
"violetred1": (255, 62, 150, 255),
|
||||
"violetred2": (238, 58, 140, 255),
|
||||
"violetred3": (205, 50, 120, 255),
|
||||
"violetred4": (139, 34, 82, 255),
|
||||
"wheat": (245, 222, 179, 255),
|
||||
"wheat1": (255, 231, 186, 255),
|
||||
"wheat2": (238, 216, 174, 255),
|
||||
"wheat3": (205, 186, 150, 255),
|
||||
"wheat4": (139, 126, 102, 255),
|
||||
"white": (255, 255, 255, 255),
|
||||
"whitesmoke": (245, 245, 245, 255),
|
||||
"yellow": (255, 255, 0, 255),
|
||||
"yellow1": (255, 255, 0, 255),
|
||||
"yellow2": (238, 238, 0, 255),
|
||||
"yellow3": (205, 205, 0, 255),
|
||||
"yellow4": (139, 139, 0, 255),
|
||||
"yellowgreen": (154, 205, 50, 255),
|
||||
}
|
||||
@@ -0,0 +1,986 @@
|
||||
# pygame-ce - Python Game Library
|
||||
# Copyright (C) 2000-2003 Pete Shinners
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the Free
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Pete Shinners
|
||||
# pete@shinners.org
|
||||
|
||||
"""Pygame module for cursor resources.
|
||||
|
||||
Pygame offers control over the system hardware cursor. Pygame supports
|
||||
black and white cursors (bitmap cursors), as well as system variant cursors and color cursors.
|
||||
You control the cursor with functions inside :mod:`pygame.mouse`.
|
||||
|
||||
This cursors module contains functions for loading and decoding various
|
||||
cursor formats. These allow you to easily store your cursors in external files
|
||||
or directly as encoded python strings.
|
||||
|
||||
The module includes several standard cursors. The :func:`pygame.mouse.set_cursor()`
|
||||
function takes several arguments. All those arguments have been stored in a
|
||||
single tuple you can call like this:
|
||||
|
||||
::
|
||||
|
||||
>>> pygame.mouse.set_cursor(*pygame.cursors.arrow)
|
||||
|
||||
The following variables can be passed to ``pygame.mouse.set_cursor`` function:
|
||||
|
||||
* ``pygame.cursors.arrow``
|
||||
|
||||
* ``pygame.cursors.diamond``
|
||||
|
||||
* ``pygame.cursors.broken_x``
|
||||
|
||||
* ``pygame.cursors.tri_left``
|
||||
|
||||
* ``pygame.cursors.tri_right``
|
||||
|
||||
* ``pygame.cursors.ball``
|
||||
|
||||
This module also contains a few cursors as formatted strings. You'll need to
|
||||
pass these to ``pygame.cursors.compile()`` function before you can use them.
|
||||
The example call would look like this:
|
||||
|
||||
::
|
||||
|
||||
>>> cursor = pygame.cursors.compile(pygame.cursors.textmarker_strings)
|
||||
>>> pygame.mouse.set_cursor((8, 16), (0, 0), *cursor)
|
||||
|
||||
The following strings can be converted into cursor bitmaps with
|
||||
``pygame.cursors.compile()`` :
|
||||
|
||||
* ``pygame.cursors.thickarrow_strings``
|
||||
|
||||
* ``pygame.cursors.sizer_x_strings``
|
||||
|
||||
* ``pygame.cursors.sizer_y_strings``
|
||||
|
||||
* ``pygame.cursors.sizer_xy_strings``
|
||||
|
||||
* ``pygame.cursors.textmarker_strings``
|
||||
"""
|
||||
|
||||
import pygame
|
||||
|
||||
_cursor_id_table = {
|
||||
pygame.SYSTEM_CURSOR_ARROW: "SYSTEM_CURSOR_ARROW",
|
||||
pygame.SYSTEM_CURSOR_IBEAM: "SYSTEM_CURSOR_IBEAM",
|
||||
pygame.SYSTEM_CURSOR_WAIT: "SYSTEM_CURSOR_WAIT",
|
||||
pygame.SYSTEM_CURSOR_CROSSHAIR: "SYSTEM_CURSOR_CROSSHAIR",
|
||||
pygame.SYSTEM_CURSOR_WAITARROW: "SYSTEM_CURSOR_WAITARROW",
|
||||
pygame.SYSTEM_CURSOR_SIZENWSE: "SYSTEM_CURSOR_SIZENWSE",
|
||||
pygame.SYSTEM_CURSOR_SIZENESW: "SYSTEM_CURSOR_SIZENESW",
|
||||
pygame.SYSTEM_CURSOR_SIZEWE: "SYSTEM_CURSOR_SIZEWE",
|
||||
pygame.SYSTEM_CURSOR_SIZENS: "SYSTEM_CURSOR_SIZENS",
|
||||
pygame.SYSTEM_CURSOR_SIZEALL: "SYSTEM_CURSOR_SIZEALL",
|
||||
pygame.SYSTEM_CURSOR_NO: "SYSTEM_CURSOR_NO",
|
||||
pygame.SYSTEM_CURSOR_HAND: "SYSTEM_CURSOR_HAND",
|
||||
}
|
||||
|
||||
|
||||
class Cursor:
|
||||
"""Pygame object representing a cursor.
|
||||
|
||||
In pygame 2, there are 3 types of cursors you can create to give your
|
||||
game that little bit of extra polish. There's **bitmap** type cursors,
|
||||
which existed in pygame 1.x, and are compiled from a string or load from an xbm file.
|
||||
Then there are **system** type cursors, where you choose a preset that will
|
||||
convey the same meaning but look native across different operating systems.
|
||||
Finally you can create a **color** cursor, which displays a pygame surface as the cursor.
|
||||
|
||||
**Creating a system cursor**
|
||||
|
||||
Choose a constant from this list, pass it into ``pygame.cursors.Cursor(constant)``,
|
||||
and you're good to go. Be advised that not all systems support every system
|
||||
cursor, and you may get a substitution instead. For example, on macOS,
|
||||
WAIT/WAITARROW should show up as an arrow, and SIZENWSE/SIZENESW/SIZEALL
|
||||
should show up as a closed hand. And on Wayland, every SIZE cursor should
|
||||
show up as a hand.
|
||||
|
||||
::
|
||||
|
||||
Pygame Cursor Constant Description
|
||||
--------------------------------------------
|
||||
pygame.SYSTEM_CURSOR_ARROW arrow
|
||||
pygame.SYSTEM_CURSOR_IBEAM i-beam
|
||||
pygame.SYSTEM_CURSOR_WAIT wait
|
||||
pygame.SYSTEM_CURSOR_CROSSHAIR crosshair
|
||||
pygame.SYSTEM_CURSOR_WAITARROW small wait cursor
|
||||
(or wait if not available)
|
||||
pygame.SYSTEM_CURSOR_SIZENWSE double arrow pointing
|
||||
northwest and southeast
|
||||
pygame.SYSTEM_CURSOR_SIZENESW double arrow pointing
|
||||
northeast and southwest
|
||||
pygame.SYSTEM_CURSOR_SIZEWE double arrow pointing
|
||||
west and east
|
||||
pygame.SYSTEM_CURSOR_SIZENS double arrow pointing
|
||||
north and south
|
||||
pygame.SYSTEM_CURSOR_SIZEALL four pointed arrow pointing
|
||||
north, south, east, and west
|
||||
pygame.SYSTEM_CURSOR_NO slashed circle or crossbones
|
||||
pygame.SYSTEM_CURSOR_HAND hand
|
||||
|
||||
**Creating a cursor without passing arguments**
|
||||
|
||||
In addition to the cursor constants available and described above, you can
|
||||
also call ``pygame.cursors.Cursor()``, and your cursor is ready (doing that
|
||||
is the same as calling ``pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_ARROW)``.
|
||||
Doing one of those calls actually creates a system cursor using the default
|
||||
native image.
|
||||
|
||||
**Creating a color cursor**
|
||||
|
||||
To create a color cursor, create a ``Cursor`` from a ``hotspot`` and a ``surface``.
|
||||
``hotspot`` are (x,y) coordinates that determine where in the cursor the exact point is.
|
||||
The hotspot position must be within the bounds of the ``surface``.
|
||||
|
||||
**Creating a bitmap cursor**
|
||||
|
||||
When the mouse cursor is visible, it will be displayed as a black and white
|
||||
bitmap using the given bitmask arrays. The ``size`` is a sequence containing
|
||||
the cursor width and height. ``hotspot`` is a sequence containing the cursor
|
||||
hotspot position.
|
||||
|
||||
A cursor has a width and height, but a mouse position is represented by a
|
||||
set of point coordinates. So the value passed into the cursor ``hotspot``
|
||||
variable helps pygame to actually determine at what exact point the cursor
|
||||
is at.
|
||||
|
||||
``xormasks`` is a sequence of bytes containing the cursor xor data masks.
|
||||
Lastly ``andmasks``, a sequence of bytes containing the cursor bitmask data.
|
||||
To create these variables, we can make use of the
|
||||
:func:`pygame.cursors.compile()` function.
|
||||
|
||||
Width and height must be a multiple of 8, and the mask arrays must be the
|
||||
correct size for the given width and height. Otherwise an exception is raised.
|
||||
|
||||
.. versionaddedold:: 2.0.1
|
||||
"""
|
||||
|
||||
def __init__(self, *args):
|
||||
self.type = "system"
|
||||
"""Get the cursor type.
|
||||
|
||||
The type will be ``"system"``, ``"bitmap"``, or ``"color"``.
|
||||
"""
|
||||
self.data = tuple()
|
||||
"""Get the cursor data.
|
||||
|
||||
Returns the data that was used to create this cursor object, wrapped up in a tuple.
|
||||
"""
|
||||
if len(args) == 0:
|
||||
self.type = "system"
|
||||
self.data = (pygame.SYSTEM_CURSOR_ARROW,)
|
||||
elif len(args) == 1 and args[0] in _cursor_id_table:
|
||||
self.type = "system"
|
||||
self.data = (args[0],)
|
||||
elif len(args) == 1 and isinstance(args[0], Cursor):
|
||||
self.type = args[0].type
|
||||
self.data = args[0].data
|
||||
elif (
|
||||
len(args) == 2 and len(args[0]) == 2 and isinstance(args[1], pygame.Surface)
|
||||
):
|
||||
self.type = "color"
|
||||
self.data = tuple(args)
|
||||
elif len(args) == 4 and len(args[0]) == 2 and len(args[1]) == 2:
|
||||
self.type = "bitmap"
|
||||
# pylint: disable=consider-using-generator
|
||||
# See https://github.com/pygame/pygame/pull/2509 for analysis
|
||||
self.data = tuple(tuple(arg) for arg in args)
|
||||
else:
|
||||
raise TypeError("Arguments must match a cursor specification")
|
||||
|
||||
def __len__(self):
|
||||
return len(self.data)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.data)
|
||||
|
||||
def __getitem__(self, index):
|
||||
return self.data[index]
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, Cursor) and self.data == other.data
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def copy(self):
|
||||
"""Copy the current cursor.
|
||||
|
||||
Returns a new Cursor object with the same data and hotspot as the original.
|
||||
"""
|
||||
return self.__class__(self)
|
||||
|
||||
__copy__ = copy
|
||||
|
||||
def __hash__(self):
|
||||
return hash(tuple([self.type] + list(self.data)))
|
||||
|
||||
def __repr__(self):
|
||||
if self.type == "system":
|
||||
id_string = _cursor_id_table.get(self.data[0], "constant lookup error")
|
||||
return f"<Cursor(type: system, constant: {id_string})>"
|
||||
if self.type == "bitmap":
|
||||
size = f"size: {self.data[0]}"
|
||||
hotspot = f"hotspot: {self.data[1]}"
|
||||
return f"<Cursor(type: bitmap, {size}, {hotspot})>"
|
||||
if self.type == "color":
|
||||
hotspot = f"hotspot: {self.data[0]}"
|
||||
surf = repr(self.data[1])
|
||||
return f"<Cursor(type: color, {hotspot}, surf: {surf})>"
|
||||
raise TypeError("Invalid Cursor")
|
||||
|
||||
|
||||
# Python side of the set_cursor function: C side in mouse.c
|
||||
def set_cursor(*args):
|
||||
"""set_cursor(pygame.cursors.Cursor OR args for a pygame.cursors.Cursor) -> None
|
||||
set the mouse cursor to a new cursor"""
|
||||
cursor = Cursor(*args)
|
||||
pygame.mouse._set_cursor(**{cursor.type: cursor.data})
|
||||
|
||||
|
||||
pygame.mouse.set_cursor = set_cursor
|
||||
del set_cursor # cleanup namespace
|
||||
|
||||
|
||||
# Python side of the get_cursor function: C side in mouse.c
|
||||
def get_cursor():
|
||||
"""get_cursor() -> pygame.cursors.Cursor
|
||||
get the current mouse cursor"""
|
||||
return Cursor(*pygame.mouse._get_cursor())
|
||||
|
||||
|
||||
pygame.mouse.get_cursor = get_cursor
|
||||
del get_cursor # cleanup namespace
|
||||
|
||||
arrow = Cursor(
|
||||
(16, 16),
|
||||
(0, 0),
|
||||
(
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x00,
|
||||
0x60,
|
||||
0x00,
|
||||
0x70,
|
||||
0x00,
|
||||
0x78,
|
||||
0x00,
|
||||
0x7C,
|
||||
0x00,
|
||||
0x7E,
|
||||
0x00,
|
||||
0x7F,
|
||||
0x00,
|
||||
0x7F,
|
||||
0x80,
|
||||
0x7C,
|
||||
0x00,
|
||||
0x6C,
|
||||
0x00,
|
||||
0x46,
|
||||
0x00,
|
||||
0x06,
|
||||
0x00,
|
||||
0x03,
|
||||
0x00,
|
||||
0x03,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
),
|
||||
(
|
||||
0x40,
|
||||
0x00,
|
||||
0xE0,
|
||||
0x00,
|
||||
0xF0,
|
||||
0x00,
|
||||
0xF8,
|
||||
0x00,
|
||||
0xFC,
|
||||
0x00,
|
||||
0xFE,
|
||||
0x00,
|
||||
0xFF,
|
||||
0x00,
|
||||
0xFF,
|
||||
0x80,
|
||||
0xFF,
|
||||
0xC0,
|
||||
0xFF,
|
||||
0x80,
|
||||
0xFE,
|
||||
0x00,
|
||||
0xEF,
|
||||
0x00,
|
||||
0x4F,
|
||||
0x00,
|
||||
0x07,
|
||||
0x80,
|
||||
0x07,
|
||||
0x80,
|
||||
0x03,
|
||||
0x00,
|
||||
),
|
||||
)
|
||||
|
||||
diamond = Cursor(
|
||||
(16, 16),
|
||||
(7, 7),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
3,
|
||||
128,
|
||||
7,
|
||||
192,
|
||||
14,
|
||||
224,
|
||||
28,
|
||||
112,
|
||||
56,
|
||||
56,
|
||||
112,
|
||||
28,
|
||||
56,
|
||||
56,
|
||||
28,
|
||||
112,
|
||||
14,
|
||||
224,
|
||||
7,
|
||||
192,
|
||||
3,
|
||||
128,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
(
|
||||
1,
|
||||
0,
|
||||
3,
|
||||
128,
|
||||
7,
|
||||
192,
|
||||
15,
|
||||
224,
|
||||
31,
|
||||
240,
|
||||
62,
|
||||
248,
|
||||
124,
|
||||
124,
|
||||
248,
|
||||
62,
|
||||
124,
|
||||
124,
|
||||
62,
|
||||
248,
|
||||
31,
|
||||
240,
|
||||
15,
|
||||
224,
|
||||
7,
|
||||
192,
|
||||
3,
|
||||
128,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)
|
||||
|
||||
ball = Cursor(
|
||||
(16, 16),
|
||||
(7, 7),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
192,
|
||||
15,
|
||||
240,
|
||||
24,
|
||||
248,
|
||||
51,
|
||||
252,
|
||||
55,
|
||||
252,
|
||||
127,
|
||||
254,
|
||||
127,
|
||||
254,
|
||||
127,
|
||||
254,
|
||||
127,
|
||||
254,
|
||||
63,
|
||||
252,
|
||||
63,
|
||||
252,
|
||||
31,
|
||||
248,
|
||||
15,
|
||||
240,
|
||||
3,
|
||||
192,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
(
|
||||
3,
|
||||
192,
|
||||
15,
|
||||
240,
|
||||
31,
|
||||
248,
|
||||
63,
|
||||
252,
|
||||
127,
|
||||
254,
|
||||
127,
|
||||
254,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
127,
|
||||
254,
|
||||
127,
|
||||
254,
|
||||
63,
|
||||
252,
|
||||
31,
|
||||
248,
|
||||
15,
|
||||
240,
|
||||
3,
|
||||
192,
|
||||
),
|
||||
)
|
||||
|
||||
broken_x = Cursor(
|
||||
(16, 16),
|
||||
(7, 7),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
96,
|
||||
6,
|
||||
112,
|
||||
14,
|
||||
56,
|
||||
28,
|
||||
28,
|
||||
56,
|
||||
12,
|
||||
48,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
12,
|
||||
48,
|
||||
28,
|
||||
56,
|
||||
56,
|
||||
28,
|
||||
112,
|
||||
14,
|
||||
96,
|
||||
6,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
(
|
||||
224,
|
||||
7,
|
||||
240,
|
||||
15,
|
||||
248,
|
||||
31,
|
||||
124,
|
||||
62,
|
||||
62,
|
||||
124,
|
||||
30,
|
||||
120,
|
||||
14,
|
||||
112,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
14,
|
||||
112,
|
||||
30,
|
||||
120,
|
||||
62,
|
||||
124,
|
||||
124,
|
||||
62,
|
||||
248,
|
||||
31,
|
||||
240,
|
||||
15,
|
||||
224,
|
||||
7,
|
||||
),
|
||||
)
|
||||
|
||||
tri_left = Cursor(
|
||||
(16, 16),
|
||||
(1, 1),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
96,
|
||||
0,
|
||||
120,
|
||||
0,
|
||||
62,
|
||||
0,
|
||||
63,
|
||||
128,
|
||||
31,
|
||||
224,
|
||||
31,
|
||||
248,
|
||||
15,
|
||||
254,
|
||||
15,
|
||||
254,
|
||||
7,
|
||||
128,
|
||||
7,
|
||||
128,
|
||||
3,
|
||||
128,
|
||||
3,
|
||||
128,
|
||||
1,
|
||||
128,
|
||||
1,
|
||||
128,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
(
|
||||
224,
|
||||
0,
|
||||
248,
|
||||
0,
|
||||
254,
|
||||
0,
|
||||
127,
|
||||
128,
|
||||
127,
|
||||
224,
|
||||
63,
|
||||
248,
|
||||
63,
|
||||
254,
|
||||
31,
|
||||
255,
|
||||
31,
|
||||
255,
|
||||
15,
|
||||
254,
|
||||
15,
|
||||
192,
|
||||
7,
|
||||
192,
|
||||
7,
|
||||
192,
|
||||
3,
|
||||
192,
|
||||
3,
|
||||
192,
|
||||
1,
|
||||
128,
|
||||
),
|
||||
)
|
||||
|
||||
tri_right = Cursor(
|
||||
(16, 16),
|
||||
(14, 1),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6,
|
||||
0,
|
||||
30,
|
||||
0,
|
||||
124,
|
||||
1,
|
||||
252,
|
||||
7,
|
||||
248,
|
||||
31,
|
||||
248,
|
||||
127,
|
||||
240,
|
||||
127,
|
||||
240,
|
||||
1,
|
||||
224,
|
||||
1,
|
||||
224,
|
||||
1,
|
||||
192,
|
||||
1,
|
||||
192,
|
||||
1,
|
||||
128,
|
||||
1,
|
||||
128,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
(
|
||||
0,
|
||||
7,
|
||||
0,
|
||||
31,
|
||||
0,
|
||||
127,
|
||||
1,
|
||||
254,
|
||||
7,
|
||||
254,
|
||||
31,
|
||||
252,
|
||||
127,
|
||||
252,
|
||||
255,
|
||||
248,
|
||||
255,
|
||||
248,
|
||||
127,
|
||||
240,
|
||||
3,
|
||||
240,
|
||||
3,
|
||||
224,
|
||||
3,
|
||||
224,
|
||||
3,
|
||||
192,
|
||||
3,
|
||||
192,
|
||||
1,
|
||||
128,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
# Here is an example string resource cursor. To use this:
|
||||
# curs, mask = pygame.cursors.compile_cursor(pygame.cursors.thickarrow_strings, 'X', '.')
|
||||
# pygame.mouse.set_cursor((24, 24), (0, 0), curs, mask)
|
||||
# Be warned, though, that cursors created from compiled strings do not support colors.
|
||||
|
||||
# sized 24x24
|
||||
thickarrow_strings = (
|
||||
"XX ",
|
||||
"XXX ",
|
||||
"XXXX ",
|
||||
"XX.XX ",
|
||||
"XX..XX ",
|
||||
"XX...XX ",
|
||||
"XX....XX ",
|
||||
"XX.....XX ",
|
||||
"XX......XX ",
|
||||
"XX.......XX ",
|
||||
"XX........XX ",
|
||||
"XX........XXX ",
|
||||
"XX......XXXXX ",
|
||||
"XX.XXX..XX ",
|
||||
"XXXX XX..XX ",
|
||||
"XX XX..XX ",
|
||||
" XX..XX ",
|
||||
" XX..XX ",
|
||||
" XX..XX ",
|
||||
" XXXX ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
# sized 24x16
|
||||
sizer_x_strings = (
|
||||
" X X ",
|
||||
" XX XX ",
|
||||
" X.X X.X ",
|
||||
" X..X X..X ",
|
||||
" X...XXXXXXXX...X ",
|
||||
"X................X ",
|
||||
" X...XXXXXXXX...X ",
|
||||
" X..X X..X ",
|
||||
" X.X X.X ",
|
||||
" XX XX ",
|
||||
" X X ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
# sized 16x24
|
||||
sizer_y_strings = (
|
||||
" X ",
|
||||
" X.X ",
|
||||
" X...X ",
|
||||
" X.....X ",
|
||||
" X.......X ",
|
||||
"XXXXX.XXXXX ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
" X.X ",
|
||||
"XXXXX.XXXXX ",
|
||||
" X.......X ",
|
||||
" X.....X ",
|
||||
" X...X ",
|
||||
" X.X ",
|
||||
" X ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
# sized 24x16
|
||||
sizer_xy_strings = (
|
||||
"XXXXXXXX ",
|
||||
"X.....X ",
|
||||
"X....X ",
|
||||
"X...X ",
|
||||
"X..X.X ",
|
||||
"X.X X.X ",
|
||||
"XX X.X X ",
|
||||
"X X.X XX ",
|
||||
" X.XX.X ",
|
||||
" X...X ",
|
||||
" X...X ",
|
||||
" X....X ",
|
||||
" X.....X ",
|
||||
" XXXXXXXX ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
# sized 8x16
|
||||
textmarker_strings = (
|
||||
"ooo ooo ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
" o ",
|
||||
"ooo ooo ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
)
|
||||
|
||||
|
||||
def compile(strings, black="X", white=".", xor="o"):
|
||||
"""Create binary cursor data from simple strings.
|
||||
|
||||
A sequence of strings can be used to create binary cursor data for the
|
||||
system cursor. This returns the binary data in the form of two tuples.
|
||||
Those can be passed as the third and fourth arguments respectively of the
|
||||
:func:`pygame.mouse.set_cursor()` function.
|
||||
|
||||
If you are creating your own cursor strings, you can use any value represent
|
||||
the black and white pixels. Some system allow you to set a special toggle
|
||||
color for the system color, this is also called the xor color. If the system
|
||||
does not support xor cursors, that color will simply be black.
|
||||
|
||||
The height must be divisible by 8. The width of the strings must all be equal
|
||||
and be divisible by 8. If these two conditions are not met, ``ValueError`` is
|
||||
raised.
|
||||
An example set of cursor strings looks like this
|
||||
|
||||
::
|
||||
|
||||
thickarrow_strings = ( #sized 24x24
|
||||
"XX ",
|
||||
"XXX ",
|
||||
"XXXX ",
|
||||
"XX.XX ",
|
||||
"XX..XX ",
|
||||
"XX...XX ",
|
||||
"XX....XX ",
|
||||
"XX.....XX ",
|
||||
"XX......XX ",
|
||||
"XX.......XX ",
|
||||
"XX........XX ",
|
||||
"XX........XXX ",
|
||||
"XX......XXXXX ",
|
||||
"XX.XXX..XX ",
|
||||
"XXXX XX..XX ",
|
||||
"XX XX..XX ",
|
||||
" XX..XX ",
|
||||
" XX..XX ",
|
||||
" XX..XX ",
|
||||
" XXXX ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ")
|
||||
|
||||
"""
|
||||
# first check for consistent lengths
|
||||
size = len(strings[0]), len(strings)
|
||||
if size[0] % 8 or size[1] % 8:
|
||||
raise ValueError(f"cursor string sizes must be divisible by 8 {size}")
|
||||
|
||||
for s in strings[1:]:
|
||||
if len(s) != size[0]:
|
||||
raise ValueError("Cursor strings are inconsistent lengths")
|
||||
|
||||
# create the data arrays.
|
||||
# this could stand a little optimizing
|
||||
maskdata = []
|
||||
filldata = []
|
||||
maskitem = fillitem = 0
|
||||
step = 8
|
||||
for s in strings:
|
||||
for c in s:
|
||||
maskitem = maskitem << 1
|
||||
fillitem = fillitem << 1
|
||||
step = step - 1
|
||||
if c == black:
|
||||
maskitem = maskitem | 1
|
||||
fillitem = fillitem | 1
|
||||
elif c == white:
|
||||
maskitem = maskitem | 1
|
||||
elif c == xor:
|
||||
fillitem = fillitem | 1
|
||||
|
||||
if not step:
|
||||
maskdata.append(maskitem)
|
||||
filldata.append(fillitem)
|
||||
maskitem = fillitem = 0
|
||||
step = 8
|
||||
|
||||
return tuple(filldata), tuple(maskdata)
|
||||
|
||||
|
||||
def load_xbm(curs, mask):
|
||||
"""Load cursor data from an XBM file.
|
||||
|
||||
This loads cursors for a simple subset of ``XBM`` files. ``XBM`` files are
|
||||
traditionally used to store cursors on UNIX systems, they are an ASCII
|
||||
format used to represent simple images.
|
||||
|
||||
Sometimes the black and white color values will be split into two separate
|
||||
``XBM`` files. You can pass a second maskfile argument to load the two
|
||||
images into a single cursor.
|
||||
|
||||
The curs and mask arguments can either be filenames or file-like
|
||||
object with the readlines method.
|
||||
|
||||
The return value cursor_args can be passed directly to the
|
||||
``pygame.mouse.set_cursor()`` function.
|
||||
"""
|
||||
|
||||
def bitswap(num):
|
||||
val = 0
|
||||
for x in range(8):
|
||||
b = num & (1 << x) != 0
|
||||
val = val << 1 | b
|
||||
return val
|
||||
|
||||
if hasattr(curs, "readlines"):
|
||||
curs = curs.readlines()
|
||||
else:
|
||||
with open(curs, encoding="ascii") as cursor_f:
|
||||
curs = cursor_f.readlines()
|
||||
|
||||
if hasattr(mask, "readlines"):
|
||||
mask = mask.readlines()
|
||||
else:
|
||||
with open(mask, encoding="ascii") as mask_f:
|
||||
mask = mask_f.readlines()
|
||||
|
||||
# avoid comments
|
||||
for i, line in enumerate(curs):
|
||||
if line.startswith("#define"):
|
||||
curs = curs[i:]
|
||||
break
|
||||
|
||||
for i, line in enumerate(mask):
|
||||
if line.startswith("#define"):
|
||||
mask = mask[i:]
|
||||
break
|
||||
|
||||
# load width,height
|
||||
width = int(curs[0].split()[-1])
|
||||
height = int(curs[1].split()[-1])
|
||||
# load hotspot position
|
||||
if curs[2].startswith("#define"):
|
||||
hotx = int(curs[2].split()[-1])
|
||||
hoty = int(curs[3].split()[-1])
|
||||
else:
|
||||
hotx = hoty = 0
|
||||
|
||||
info = width, height, hotx, hoty
|
||||
|
||||
possible_starts = ("static char", "static unsigned char")
|
||||
for i, line in enumerate(curs):
|
||||
if line.startswith(possible_starts):
|
||||
break
|
||||
data = " ".join(curs[i + 1 :]).replace("};", "").replace(",", " ")
|
||||
cursdata = tuple(bitswap(int(x, 16)) for x in data.split())
|
||||
for i, line in enumerate(mask):
|
||||
if line.startswith(possible_starts):
|
||||
break
|
||||
data = " ".join(mask[i + 1 :]).replace("};", "").replace(",", " ")
|
||||
maskdata = tuple(bitswap(int(x, 16)) for x in data.split())
|
||||
return info[:2], info[2:], cursdata, maskdata
|
||||
@@ -0,0 +1,89 @@
|
||||
from collections.abc import Iterator
|
||||
from typing import Any, Literal, TypeAlias, overload
|
||||
|
||||
from pygame.surface import Surface
|
||||
from pygame.typing import FileLike, IntPoint, SequenceLike
|
||||
|
||||
_SmallString: TypeAlias = tuple[
|
||||
str, str, str, str, str, str, str, str, str, str, str, str, str, str, str, str
|
||||
]
|
||||
_BigString: TypeAlias = tuple[
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
str,
|
||||
]
|
||||
|
||||
arrow: Cursor
|
||||
diamond: Cursor
|
||||
broken_x: Cursor
|
||||
tri_left: Cursor
|
||||
tri_right: Cursor
|
||||
ball: Cursor
|
||||
thickarrow_strings: _BigString
|
||||
sizer_x_strings: _SmallString
|
||||
sizer_y_strings: _BigString
|
||||
sizer_xy_strings: _SmallString
|
||||
textmarker_strings: _SmallString
|
||||
|
||||
def compile(
|
||||
strings: SequenceLike[str],
|
||||
black: str = "X",
|
||||
white: str = ".",
|
||||
xor: str = "o",
|
||||
) -> tuple[tuple[int, ...], tuple[int, ...]]: ...
|
||||
def load_xbm(
|
||||
curs: FileLike, mask: FileLike
|
||||
) -> tuple[tuple[int, int], tuple[int, int], tuple[int, ...], tuple[int, ...]]: ...
|
||||
|
||||
class Cursor:
|
||||
@overload
|
||||
def __init__(self, constant: int = ...) -> None: ...
|
||||
@overload
|
||||
def __init__(self, cursor: Cursor) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
size: IntPoint,
|
||||
hotspot: IntPoint,
|
||||
xormasks: SequenceLike[int],
|
||||
andmasks: SequenceLike[int],
|
||||
) -> None: ...
|
||||
@overload
|
||||
def __init__(
|
||||
self,
|
||||
hotspot: IntPoint,
|
||||
surface: Surface,
|
||||
) -> None: ...
|
||||
def __iter__(self) -> Iterator[Any]: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __copy__(self) -> Cursor: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def __getitem__(self, index: int) -> int | IntPoint | Surface: ...
|
||||
def copy(self) -> Cursor: ...
|
||||
type: Literal["system", "color", "bitmap"]
|
||||
data: (
|
||||
tuple[int]
|
||||
| tuple[tuple[int, int], tuple[int, int], tuple[int, ...], tuple[int, ...]]
|
||||
| tuple[IntPoint, Surface]
|
||||
)
|
||||
@@ -0,0 +1,869 @@
|
||||
"""Pygame module to control the display window and screen.
|
||||
|
||||
This module offers control over the pygame display. Pygame has a single display
|
||||
Surface that is either contained in a window or runs full screen. Once you
|
||||
create the display you treat it as a regular Surface. Changes are not
|
||||
immediately visible onscreen; you must choose one of the two flipping functions
|
||||
to update the actual display.
|
||||
|
||||
The origin of the display, where x = 0 and y = 0, is the top left of the
|
||||
screen. Both axes increase positively towards the bottom right of the screen.
|
||||
|
||||
The pygame display can actually be initialized in one of several modes. By
|
||||
default, the display is a basic software driven framebuffer. You can request
|
||||
special modules like automatic scaling or OpenGL support. These are
|
||||
controlled by flags passed to ``pygame.display.set_mode()``.
|
||||
|
||||
Pygame can only have a single display active at any time. Creating a new one
|
||||
with ``pygame.display.set_mode()`` will close the previous display. To detect
|
||||
the number and size of attached screens, you can use
|
||||
``pygame.display.get_desktop_sizes`` and then select appropriate window size
|
||||
and display index to pass to ``pygame.display.set_mode()``.
|
||||
|
||||
For backward compatibility ``pygame.display`` allows precise control over
|
||||
the pixel format or display resolutions. This used to be necessary with old
|
||||
graphics cards and CRT screens, but is usually not needed any more. Use the
|
||||
functions ``pygame.display.mode_ok()``, ``pygame.display.list_modes()``, and
|
||||
``pygame.display.Info()`` to query detailed information about the display.
|
||||
|
||||
Once the display Surface is created, the functions from this module affect the
|
||||
single existing display. The Surface becomes invalid if the module is
|
||||
uninitialized. If a new display mode is set, the existing Surface will
|
||||
automatically switch to operate on the new display.
|
||||
|
||||
When the display mode is set, several events are placed on the pygame event
|
||||
queue. ``pygame.QUIT`` is sent when the user has requested the program to
|
||||
shut down. The window will receive ``pygame.ACTIVEEVENT`` events as the display
|
||||
gains and loses input focus. If the display is set to be resizable with the
|
||||
``pygame.RESIZABLE`` flag, ``pygame.VIDEORESIZE`` event(s) will be sent when the
|
||||
user adjusts the window dimensions. Depending on your platform, this may be
|
||||
multiple gradual events or one event at the end (Windows). Hardware displays
|
||||
that draw direct to the screen will get ``pygame.VIDEOEXPOSE`` events when
|
||||
portions of the window must be redrawn.
|
||||
|
||||
A new windowevent API was introduced in pygame 2.0.1. Check event module docs
|
||||
for more information on that
|
||||
|
||||
Some display environments have an option for automatically stretching all
|
||||
windows. When this option is enabled, this automatic stretching distorts the
|
||||
appearance of the pygame window. In the pygame examples directory, there is
|
||||
example code (prevent_display_stretching.py) which shows how to disable this
|
||||
automatic stretching of the pygame display on Microsoft Windows (Vista or newer
|
||||
required).
|
||||
"""
|
||||
|
||||
from collections.abc import Iterable
|
||||
from typing import Literal, overload
|
||||
|
||||
from pygame._sdl2 import Window
|
||||
from pygame.constants import FULLSCREEN
|
||||
from pygame.surface import Surface
|
||||
from pygame.typing import (
|
||||
ColorLike,
|
||||
IntPoint,
|
||||
Point,
|
||||
RectLike,
|
||||
SequenceLike,
|
||||
)
|
||||
from typing_extensions import deprecated # added in 3.13
|
||||
|
||||
class _VidInfo:
|
||||
@property
|
||||
def hw(self) -> int: ...
|
||||
@property
|
||||
def wm(self) -> int: ...
|
||||
@property
|
||||
def video_mem(self) -> int: ...
|
||||
@property
|
||||
def bitsize(self) -> int: ...
|
||||
@property
|
||||
def bytesize(self) -> int: ...
|
||||
@property
|
||||
def masks(self) -> tuple[int, int, int, int]: ...
|
||||
@property
|
||||
def shifts(self) -> tuple[int, int, int, int]: ...
|
||||
@property
|
||||
def losses(self) -> tuple[int, int, int, int]: ...
|
||||
@property
|
||||
def blit_hw(self) -> int: ...
|
||||
@property
|
||||
def blit_hw_CC(self) -> int: ...
|
||||
@property
|
||||
def blit_hw_A(self) -> int: ...
|
||||
@property
|
||||
def blit_sw(self) -> int: ...
|
||||
@property
|
||||
def blit_sw_CC(self) -> int: ...
|
||||
@property
|
||||
def blit_sw_A(self) -> int: ...
|
||||
@property
|
||||
def current_h(self) -> int: ...
|
||||
@property
|
||||
def current_w(self) -> int: ...
|
||||
@property
|
||||
def pixel_format(self) -> str: ...
|
||||
|
||||
def init() -> None:
|
||||
"""Initialize the display module.
|
||||
|
||||
Initializes the pygame display module. The display module cannot do anything
|
||||
until it is initialized. This is usually handled for you automatically when
|
||||
you call the higher level ``pygame.init()``.
|
||||
|
||||
Pygame will select from one of several internal display backends when it is
|
||||
initialized. The display mode will be chosen depending on the platform and
|
||||
permissions of current user. Before the display module is initialized the
|
||||
environment variable ``SDL_VIDEODRIVER`` can be set to control which backend
|
||||
is used. The systems with multiple choices are listed here.
|
||||
|
||||
::
|
||||
|
||||
Windows : windib, directx
|
||||
Unix : x11, dga, fbcon, directfb, ggi, vgl, svgalib, aalib, wayland
|
||||
|
||||
:note: On wayland desktops, pygame-ce may choose to use the X11 video driver to run on Xwayland.
|
||||
This behaviour is determined by the SDL library and might change in the future, so it's suggested
|
||||
to account for this and not rely on the default behavior. The Wayland video driver can be forced
|
||||
by setting the ``SDL_VIDEODRIVER`` environment variable to ``"wayland"``
|
||||
|
||||
On some platforms it is possible to embed the pygame display into an already
|
||||
existing window. To do this, the environment variable ``SDL_WINDOWID`` must
|
||||
be set to a string containing the window id or handle. The environment
|
||||
variable is checked when the pygame display is initialized. Be aware that
|
||||
there can be many strange side effects when running in an embedded display.
|
||||
|
||||
It is harmless to call this more than once, repeated calls have no effect.
|
||||
|
||||
.. versionchanged:: 2.5.0 the manylinux wheels distributed by us now support the ``wayland`` videodriver
|
||||
|
||||
"""
|
||||
|
||||
def quit() -> None:
|
||||
"""Uninitialize the display module.
|
||||
|
||||
This will shut down the entire display module. This means any active
|
||||
displays will be closed. This will also be handled automatically when the
|
||||
program exits.
|
||||
|
||||
It is harmless to call this more than once, repeated calls have no effect.
|
||||
"""
|
||||
|
||||
def get_init() -> bool:
|
||||
"""Returns True if the display module has been initialized.
|
||||
|
||||
Returns True if the :mod:`pygame.display` module is currently initialized.
|
||||
"""
|
||||
|
||||
def set_mode(
|
||||
size: Point = (0, 0),
|
||||
flags: int = 0,
|
||||
depth: int = 0,
|
||||
display: int = 0,
|
||||
vsync: int = 0,
|
||||
) -> Surface:
|
||||
"""Initialize a window or screen for display.
|
||||
|
||||
This will create a window or display output and return a display Surface.
|
||||
The arguments passed in are requests for a display type. The actual created
|
||||
display will be the best possible match supported by the system.
|
||||
|
||||
Note that calling this function implicitly initializes ``pygame.display``, if
|
||||
it was not initialized before.
|
||||
|
||||
The size argument is a pair of numbers representing the width and
|
||||
height. The flags argument is a collection of additional options. The depth
|
||||
argument represents the number of bits to use for color.
|
||||
|
||||
The Surface that gets returned can be drawn to like a regular Surface but
|
||||
changes will eventually be seen on the monitor.
|
||||
|
||||
If no size is passed or is set to ``(0, 0)``, the created Surface will have
|
||||
the same size as the current screen resolution. If only the width or height
|
||||
are set to ``0``, the Surface will have the same width or height as the
|
||||
screen resolution.
|
||||
|
||||
Since pygame 2, the depth argument is ignored, in favour of the best
|
||||
and fastest one. It also raises a deprecation warning since pygame-ce
|
||||
2.4.0 if the passed in depth is not 0 or the one pygame selects.
|
||||
|
||||
When requesting fullscreen display modes, sometimes an exact match for the
|
||||
requested size cannot be made. In these situations pygame will select
|
||||
the closest compatible match. The returned surface will still always match
|
||||
the requested size.
|
||||
|
||||
On high resolution displays(4k, 1080p) and tiny graphics games (640x480)
|
||||
show up very small so that they are unplayable. SCALED scales up the window
|
||||
for you. The game thinks it's a 640x480 window, but really it can be bigger.
|
||||
Mouse events are scaled for you, so your game doesn't need to do it. Note
|
||||
that SCALED is considered an experimental API and may change in future
|
||||
releases.
|
||||
|
||||
The flags argument controls which type of display you want. There are
|
||||
several to choose from, and you can even combine multiple types using the
|
||||
bitwise or operator, (the pipe "|" character). Here are the display
|
||||
flags you will want to choose from:
|
||||
|
||||
::
|
||||
|
||||
pygame.FULLSCREEN create a fullscreen display
|
||||
pygame.DOUBLEBUF only applicable with OPENGL
|
||||
pygame.HWSURFACE (obsolete in pygame 2) hardware accelerated, only in FULLSCREEN
|
||||
pygame.OPENGL create an OpenGL-renderable display
|
||||
pygame.RESIZABLE display window should be sizeable
|
||||
pygame.NOFRAME display window will have no border or controls
|
||||
pygame.SCALED resolution depends on desktop size and scale graphics
|
||||
pygame.SHOWN window is opened in visible mode (default)
|
||||
pygame.HIDDEN window is opened in hidden mode
|
||||
|
||||
|
||||
.. versionaddedold:: 2.0.0 ``SCALED``, ``SHOWN`` and ``HIDDEN``
|
||||
|
||||
.. versionaddedold:: 2.0.0 ``vsync`` parameter
|
||||
|
||||
By setting the ``vsync`` parameter to ``1``, it is possible to get a display
|
||||
with vertical sync at a constant frame rate determined by the monitor and
|
||||
graphics drivers. Subsequent calls to :func:`pygame.display.flip()` or
|
||||
:func:`pygame.display.update()` will block (i.e. *wait*) until the screen
|
||||
has refreshed, in order to prevent "screen tearing"
|
||||
<https://en.wikipedia.org/wiki/Screen_tearing>.
|
||||
|
||||
Be careful when using this feature together with ``pygame.time.Clock`` or
|
||||
:func:`pygame.time.delay()`, as multiple forms of waiting and frame rate
|
||||
limiting may interact to cause skipped frames.
|
||||
|
||||
The request only works when graphics acceleration is available on the
|
||||
system. The exact behaviour depends on the hardware and driver
|
||||
configuration. When ``vsync`` is requested, but unavailable,
|
||||
``set_mode()`` may raise an exception.
|
||||
|
||||
Setting the ``vsync`` parameter to ``-1`` in conjunction with ``OPENGL``
|
||||
will request the OpenGL-specific feature "adaptive vsync" <https://www.khronos.org/opengl/wiki/Swap_Interval#Adaptive_Vsync>.
|
||||
|
||||
Here is an example usage of a call
|
||||
to ``set_mode()`` that may give you a display with vsync:
|
||||
|
||||
::
|
||||
|
||||
flags = pygame.OPENGL | pygame.FULLSCREEN
|
||||
try:
|
||||
window_surface = pygame.display.set_mode((1920, 1080), flags, vsync=1)
|
||||
vsync_success=True
|
||||
except pygame.error:
|
||||
window_surface = pygame.display.set_mode((1920, 1080), flags)
|
||||
vsync_success=False
|
||||
|
||||
.. versionaddedold:: 2.0.0 ``vsync`` parameter
|
||||
|
||||
.. versionchanged:: 2.2.0 passing ``vsync`` can raise an exception
|
||||
|
||||
.. versionchanged:: 2.2.0 explicit request for "adaptive vsync"
|
||||
|
||||
.. versionchanged:: 2.2.0 ``vsync=1`` does not require ``SCALED`` or ``OPENGL``
|
||||
|
||||
.. deprecated:: 2.4.0 The depth argument is ignored, and will be set to the optimal value
|
||||
|
||||
.. versionchanged:: 2.5.0 No longer emits warning when running on xwayland, see :func:`pygame.display.init` for details on running on wayland directly
|
||||
|
||||
Basic example:
|
||||
|
||||
::
|
||||
|
||||
# Open a window on the screen
|
||||
screen_width=700
|
||||
screen_height=400
|
||||
screen=pygame.display.set_mode([screen_width, screen_height])
|
||||
|
||||
The display index ``0`` means the default display is used. If no display
|
||||
index argument is provided, the default display can be overridden with an
|
||||
environment variable.
|
||||
|
||||
|
||||
.. versionchangedold:: 1.9.5 ``display`` argument added
|
||||
|
||||
.. versionchanged:: 2.1.3
|
||||
pygame now ensures that subsequent calls to this function clears the
|
||||
window to black. On older versions, this was an implementation detail
|
||||
on the major platforms this function was tested with.
|
||||
"""
|
||||
|
||||
def get_surface() -> Surface | None:
|
||||
"""Get a reference to the currently set display surface.
|
||||
|
||||
Return a reference to the currently set display Surface. If no display mode
|
||||
has been set this will return None.
|
||||
"""
|
||||
|
||||
def flip() -> None:
|
||||
"""Update the full display Surface to the screen.
|
||||
|
||||
This will update the contents of the entire display.
|
||||
|
||||
When using an ``pygame.OPENGL`` display mode this will perform a gl buffer
|
||||
swap.
|
||||
"""
|
||||
|
||||
@overload
|
||||
def update() -> None: ...
|
||||
@overload
|
||||
def update(rectangle: RectLike | None, /) -> None: ...
|
||||
@overload
|
||||
def update(rectangles: Iterable[RectLike | None], /) -> None: ...
|
||||
@overload
|
||||
def update(x: float, y: float, w: float, h: float, /) -> None: ...
|
||||
@overload
|
||||
def update(xy: Point, wh: Point, /) -> None: ...
|
||||
def update(*args): # type: ignore
|
||||
"""Update all, or a portion, of the display. For non-OpenGL displays.
|
||||
|
||||
For non OpenGL display Surfaces, this function is very similar to
|
||||
``pygame.display.flip()`` with an optional parameter that allows only
|
||||
portions of the display surface to be updated, instead of the entire area.
|
||||
If no argument is passed it updates the entire Surface area like
|
||||
``pygame.display.flip()``.
|
||||
|
||||
.. note:: calling ``display.update(None)`` means no part of the window is
|
||||
updated. Whereas ``display.update()`` means the whole window is
|
||||
updated.
|
||||
|
||||
You can pass the function a single rectangle, or an iterable of rectangles.
|
||||
Generally you do not want to pass an iterable of rectangles as there is a
|
||||
performance cost per rectangle passed to the function. On modern hardware,
|
||||
after a very small number of rectangles passed in, the per-rectangle cost
|
||||
will exceed the saving of updating less pixels. In most applications it is
|
||||
simply more efficient to update the entire display surface at once, it also
|
||||
means you do not need to keep track of a list of rectangles for each call
|
||||
to update.
|
||||
|
||||
If passing an iterable of rectangles it is safe to include None
|
||||
values in the list, which will be skipped.
|
||||
|
||||
This call cannot be used on ``pygame.OPENGL`` displays and will generate an
|
||||
exception.
|
||||
|
||||
.. versionchanged:: 2.5.1 Added support for passing an iterable, previously only sequence was allowed
|
||||
"""
|
||||
|
||||
def get_driver() -> str:
|
||||
"""Get the name of the pygame display backend.
|
||||
|
||||
Pygame chooses one of many available display backends when it is
|
||||
initialized. This returns the internal name used for the display backend.
|
||||
This can be used to provide limited information about what display
|
||||
capabilities might be accelerated. See the ``SDL_VIDEODRIVER`` flags in
|
||||
``pygame.display.init()`` to see some of the common options.
|
||||
"""
|
||||
|
||||
def Info() -> _VidInfo:
|
||||
"""Create a video display information object.
|
||||
|
||||
Creates a simple object containing several attributes to describe the
|
||||
current graphics environment. If this is called before
|
||||
``pygame.display.set_mode()`` some platforms can provide information about
|
||||
the default display mode. This can also be called after setting the display
|
||||
mode to verify specific display options were satisfied. The VidInfo object
|
||||
has several attributes:
|
||||
|
||||
.. code-block:: text
|
||||
|
||||
hw: 1 if the display is hardware accelerated
|
||||
wm: 1 if windowed display modes can be used
|
||||
video_mem: The megabytes of video memory on the display.
|
||||
This is 0 if unknown
|
||||
bitsize: Number of bits used to store each pixel
|
||||
bytesize: Number of bytes used to store each pixel
|
||||
masks: Four values used to pack RGBA values into pixels
|
||||
shifts: Four values used to pack RGBA values into pixels
|
||||
losses: Four values used to pack RGBA values into pixels
|
||||
blit_hw: 1 if hardware Surface blitting is accelerated
|
||||
blit_hw_CC: 1 if hardware Surface colorkey blitting is accelerated
|
||||
blit_hw_A: 1 if hardware Surface pixel alpha blitting is
|
||||
accelerated
|
||||
blit_sw: 1 if software Surface blitting is accelerated
|
||||
blit_sw_CC: 1 if software Surface colorkey blitting is
|
||||
accelerated
|
||||
blit_sw_A: 1 if software Surface pixel alpha blitting is
|
||||
accelerated
|
||||
current_h, current_w: Height and width of the current video
|
||||
mode, or of the desktop mode if called before
|
||||
the display.set_mode is called. They are -1 on error.
|
||||
pixel_format: The pixel format of the display Surface as a string.
|
||||
E.g PIXELFORMAT_RGB888.
|
||||
|
||||
.. versionchanged:: 2.4.0 ``pixel_format`` attribute added.
|
||||
"""
|
||||
|
||||
def get_wm_info() -> dict[str, int]:
|
||||
"""Get information about the current windowing system.
|
||||
|
||||
Creates a dictionary filled with string keys. The strings and values are
|
||||
arbitrarily created by the system. Some systems may have no information and
|
||||
an empty dictionary will be returned. Most platforms will return a "window"
|
||||
key with the value set to the system id for the current display.
|
||||
|
||||
.. versionaddedold:: 1.7.1
|
||||
"""
|
||||
|
||||
def get_desktop_sizes() -> list[tuple[int, int]]:
|
||||
"""Get sizes of active desktops.
|
||||
|
||||
This function returns the sizes of the currently configured
|
||||
virtual desktops as a list of (x, y) tuples of integers.
|
||||
|
||||
The length of the list is not the same as the number of attached monitors,
|
||||
as a desktop can be mirrored across multiple monitors. The desktop sizes
|
||||
do not indicate the maximum monitor resolutions supported by the hardware,
|
||||
but the desktop size configured in the operating system.
|
||||
|
||||
In order to fit windows into the desktop as it is currently configured, and
|
||||
to respect the resolution configured by the operating system in fullscreen
|
||||
mode, this function *should* be used to replace many use cases of
|
||||
``pygame.display.list_modes()`` whenever applicable.
|
||||
|
||||
.. versionaddedold:: 2.0.0
|
||||
"""
|
||||
|
||||
def list_modes(
|
||||
depth: int = 0,
|
||||
flags: int = FULLSCREEN,
|
||||
display: int = 0,
|
||||
) -> list[tuple[int, int]]:
|
||||
"""Get list of available fullscreen modes.
|
||||
|
||||
This function returns a list of possible sizes for a specified color
|
||||
depth. The return value will be an empty list if no display modes are
|
||||
available with the given arguments. A return value of ``-1`` means that
|
||||
any requested size should work (this is likely the case for windowed
|
||||
modes). Mode sizes are sorted from biggest to smallest.
|
||||
|
||||
If depth is ``0``, the current/best color depth for the display is used.
|
||||
The flags defaults to ``pygame.FULLSCREEN``, but you may need to add
|
||||
additional flags for specific fullscreen modes.
|
||||
|
||||
The display index ``0`` means the default display is used.
|
||||
|
||||
Since pygame 2.0, ``pygame.display.get_desktop_sizes()`` has taken over
|
||||
some use cases from ``pygame.display.list_modes()``:
|
||||
|
||||
To find a suitable size for non-fullscreen windows, it is preferable to
|
||||
use ``pygame.display.get_desktop_sizes()`` to get the size of the *current*
|
||||
desktop, and to then choose a smaller window size. This way, the window is
|
||||
guaranteed to fit, even when the monitor is configured to a lower resolution
|
||||
than the maximum supported by the hardware.
|
||||
|
||||
To avoid changing the physical monitor resolution, it is also preferable to
|
||||
use ``pygame.display.get_desktop_sizes()`` to determine the fullscreen
|
||||
resolution. Developers are strongly advised to default to the current
|
||||
physical monitor resolution unless the user explicitly requests a different
|
||||
one (e.g. in an options menu or configuration file).
|
||||
|
||||
.. versionchangedold:: 1.9.5 ``display`` argument added
|
||||
"""
|
||||
|
||||
def mode_ok(
|
||||
size: IntPoint,
|
||||
flags: int = 0,
|
||||
depth: int = 0,
|
||||
display: int = 0,
|
||||
) -> int:
|
||||
"""Pick the best color depth for a display mode.
|
||||
|
||||
This function uses the same arguments as ``pygame.display.set_mode()``. It
|
||||
is used to determine if a requested display mode is available. It will
|
||||
return ``0`` if the display mode cannot be set. Otherwise it will return a
|
||||
pixel depth that best matches the display asked for.
|
||||
|
||||
Usually the depth argument is not passed, but some platforms can support
|
||||
multiple display depths. If passed it will hint to which depth is a better
|
||||
match.
|
||||
|
||||
The function will return ``0`` if the passed display flags cannot be set.
|
||||
|
||||
The display index ``0`` means the default display is used.
|
||||
|
||||
.. versionchangedold:: 1.9.5 ``display`` argument added
|
||||
"""
|
||||
|
||||
def gl_get_attribute(flag: int, /) -> int:
|
||||
"""Get the value for an OpenGL flag for the current display.
|
||||
|
||||
After calling ``pygame.display.set_mode()`` with the ``pygame.OPENGL`` flag,
|
||||
it is a good idea to check the value of any requested OpenGL attributes. See
|
||||
``pygame.display.gl_set_attribute()`` for a list of valid flags.
|
||||
"""
|
||||
|
||||
def gl_set_attribute(flag: int, value: int, /) -> None:
|
||||
"""Request an OpenGL display attribute for the display mode.
|
||||
|
||||
When calling ``pygame.display.set_mode()`` with the ``pygame.OPENGL`` flag,
|
||||
Pygame automatically handles setting the OpenGL attributes like color and
|
||||
double-buffering. OpenGL offers several other attributes you may want control
|
||||
over. Pass one of these attributes as the flag, and its appropriate value.
|
||||
This must be called before ``pygame.display.set_mode()``.
|
||||
|
||||
Many settings are the requested minimum. Creating a window with an OpenGL context
|
||||
will fail if OpenGL cannot provide the requested attribute, but it may for example
|
||||
give you a stencil buffer even if you request none, or it may give you a larger
|
||||
one than requested.
|
||||
|
||||
The ``OPENGL`` flags are
|
||||
|
||||
::
|
||||
|
||||
GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_ACCUM_RED_SIZE,
|
||||
GL_ACCUM_GREEN_SIZE, GL_ACCUM_BLUE_SIZE, GL_ACCUM_ALPHA_SIZE,
|
||||
GL_MULTISAMPLEBUFFERS, GL_MULTISAMPLESAMPLES, GL_STEREO
|
||||
|
||||
:const:`GL_MULTISAMPLEBUFFERS`
|
||||
|
||||
Whether to enable multisampling anti-aliasing.
|
||||
Defaults to 0 (disabled).
|
||||
Set ``GL_MULTISAMPLESAMPLES`` to a value
|
||||
above 0 to control the amount of anti-aliasing.
|
||||
A typical value is 2 or 3.
|
||||
|
||||
:const:`GL_STENCIL_SIZE`
|
||||
|
||||
Minimum bit size of the stencil buffer. Defaults to 0.
|
||||
|
||||
:const:`GL_DEPTH_SIZE`
|
||||
|
||||
Minimum bit size of the depth buffer. Defaults to 16.
|
||||
|
||||
:const:`GL_STEREO`
|
||||
|
||||
1 enables stereo 3D. Defaults to 0.
|
||||
|
||||
:const:`GL_BUFFER_SIZE`
|
||||
|
||||
Minimum bit size of the frame buffer. Defaults to 0.
|
||||
|
||||
.. versionaddedold:: 2.0.0 Additional attributes:
|
||||
|
||||
::
|
||||
|
||||
GL_ACCELERATED_VISUAL,
|
||||
GL_CONTEXT_MAJOR_VERSION, GL_CONTEXT_MINOR_VERSION,
|
||||
GL_CONTEXT_FLAGS, GL_CONTEXT_PROFILE_MASK,
|
||||
GL_SHARE_WITH_CURRENT_CONTEXT,
|
||||
GL_CONTEXT_RELEASE_BEHAVIOR,
|
||||
GL_FRAMEBUFFER_SRGB_CAPABLE
|
||||
|
||||
:const:`GL_CONTEXT_PROFILE_MASK`
|
||||
|
||||
Sets the OpenGL profile to one of these values:
|
||||
|
||||
::
|
||||
|
||||
GL_CONTEXT_PROFILE_CORE disable deprecated features
|
||||
GL_CONTEXT_PROFILE_COMPATIBILITY allow deprecated features
|
||||
GL_CONTEXT_PROFILE_ES allow only the ES feature
|
||||
subset of OpenGL
|
||||
|
||||
:const:`GL_ACCELERATED_VISUAL`
|
||||
|
||||
Set to 1 to require hardware acceleration, or 0 to force software render.
|
||||
By default, both are allowed.
|
||||
"""
|
||||
|
||||
def get_active() -> bool:
|
||||
"""Returns True when the display is active on the screen.
|
||||
|
||||
Returns True when the display Surface is considered actively
|
||||
renderable on the screen and may be visible to the user. This is
|
||||
the default state immediately after ``pygame.display.set_mode()``.
|
||||
This method may return True even if the application is fully hidden
|
||||
behind another application window.
|
||||
|
||||
This will return False if the display Surface has been iconified or
|
||||
minimized (either via ``pygame.display.iconify()`` or via an OS
|
||||
specific method such as the minimize-icon available on most
|
||||
desktops).
|
||||
|
||||
The method can also return False for other reasons without the
|
||||
application being explicitly iconified or minimized by the user. A
|
||||
notable example being if the user has multiple virtual desktops and
|
||||
the display Surface is not on the active virtual desktop.
|
||||
|
||||
.. note:: This function returning True is unrelated to whether the
|
||||
application has input focus. Please see
|
||||
``pygame.key.get_focused()`` and ``pygame.mouse.get_focused()``
|
||||
for APIs related to input focus.
|
||||
"""
|
||||
|
||||
def iconify() -> bool:
|
||||
"""Iconify the display surface.
|
||||
|
||||
Request the window for the display surface be iconified or hidden. Not all
|
||||
systems and displays support an iconified display. The function will return
|
||||
True if successful.
|
||||
|
||||
When the display is iconified ``pygame.display.get_active()`` will return
|
||||
``False``. The event queue should receive an ``ACTIVEEVENT`` event when the
|
||||
window has been iconified. Additionally, the event queue also receives a
|
||||
``WINDOWEVENT_MINIMIZED`` event when the window has been iconified on pygame 2.
|
||||
"""
|
||||
|
||||
def toggle_fullscreen() -> int:
|
||||
"""Switch between fullscreen and windowed displays.
|
||||
|
||||
Switches the display window between windowed and fullscreen modes.
|
||||
Display driver support is not great when using pygame 1, but with
|
||||
pygame 2 it is the most reliable method to switch to and from fullscreen.
|
||||
|
||||
Supported display drivers in pygame 1:
|
||||
|
||||
* x11 (Linux/Unix)
|
||||
* wayland (Linux/Unix)
|
||||
|
||||
Supported display drivers in pygame 2:
|
||||
|
||||
* windows (Windows)
|
||||
* x11 (Linux/Unix)
|
||||
* wayland (Linux/Unix)
|
||||
* cocoa (OSX/Mac)
|
||||
|
||||
.. note:: :func:`toggle_fullscreen` doesn't work on Windows
|
||||
unless the window size is in :func:`pygame.display.list_modes()` or
|
||||
the window is created with the flag ``pygame.SCALED``.
|
||||
See `issue #1221 <https://github.com/pygame-community/pygame-ce/issues/1221>`_.
|
||||
"""
|
||||
|
||||
@deprecated("since 2.1.4. Removed in SDL3")
|
||||
def set_gamma(red: float, green: float = ..., blue: float = ..., /) -> bool:
|
||||
"""Change the hardware gamma ramps.
|
||||
|
||||
DEPRECATED: This functionality will go away in SDL3.
|
||||
|
||||
Set the red, green, and blue gamma values on the display hardware. If the
|
||||
green and blue arguments are not passed, they will both be the same as red.
|
||||
Not all systems and hardware support gamma ramps, if the function succeeds
|
||||
it will return ``True``.
|
||||
|
||||
A gamma value of ``1.0`` creates a linear color table. Lower values will
|
||||
darken the display and higher values will brighten.
|
||||
|
||||
.. deprecated:: 2.1.4
|
||||
"""
|
||||
|
||||
@deprecated("since 2.1.4. Removed in SDL3")
|
||||
def set_gamma_ramp(
|
||||
red: SequenceLike[int], green: SequenceLike[int], blue: SequenceLike[int], /
|
||||
) -> bool:
|
||||
"""Change the hardware gamma ramps with a custom lookup.
|
||||
|
||||
DEPRECATED: This functionality will go away in SDL3.
|
||||
|
||||
Set the red, green, and blue gamma ramps with an explicit lookup table. Each
|
||||
argument should be sequence of 256 integers. The integers should range
|
||||
between ``0`` and ``0xffff``. Not all systems and hardware support gamma
|
||||
ramps, if the function succeeds it will return ``True``.
|
||||
|
||||
.. deprecated:: 2.1.4
|
||||
"""
|
||||
|
||||
def set_icon(surface: Surface, /) -> None:
|
||||
"""Change the system image for the display window.
|
||||
|
||||
Sets the runtime icon the system will use to represent the display window.
|
||||
All windows default to a simple pygame logo for the window icon.
|
||||
|
||||
Note that calling this function implicitly initializes ``pygame.display``, if
|
||||
it was not initialized before.
|
||||
|
||||
You can pass any surface, but most systems want a smaller image around
|
||||
32x32. The image can have colorkey transparency which will be passed to the
|
||||
system.
|
||||
|
||||
Some systems do not allow the window icon to change after it has been shown.
|
||||
This function can be called before ``pygame.display.set_mode()`` to create
|
||||
the icon before the display mode is set.
|
||||
"""
|
||||
|
||||
def set_caption(title: str, icontitle: str | None = None, /) -> None:
|
||||
"""Set the current window caption.
|
||||
|
||||
If the display has a window title, this function will change the name on the
|
||||
window. In pygame 1.x, some systems supported an alternate shorter title to
|
||||
be used for minimized displays, but in pygame 2 ``icontitle`` does nothing.
|
||||
"""
|
||||
|
||||
def get_caption() -> tuple[str, str]:
|
||||
"""Get the current window caption.
|
||||
|
||||
Returns the title and icontitle of the display window. In pygame 2.x
|
||||
these will always be the same value.
|
||||
"""
|
||||
|
||||
def set_palette(palette: SequenceLike[ColorLike], /) -> None:
|
||||
"""Set the display color palette for indexed displays.
|
||||
|
||||
This will change the video display color palette for 8-bit displays. This
|
||||
does not change the palette for the actual display Surface, only the palette
|
||||
that is used to display the Surface. If no palette argument is passed, the
|
||||
system default palette will be restored. The palette is a sequence of
|
||||
``RGB`` triplets.
|
||||
"""
|
||||
|
||||
def get_num_displays() -> int:
|
||||
"""Return the number of displays.
|
||||
|
||||
Returns the number of available displays. This is always 1 if
|
||||
:func:`pygame.get_sdl_version()` returns a major version number below 2.
|
||||
|
||||
.. versionaddedold:: 1.9.5
|
||||
"""
|
||||
|
||||
def get_window_size() -> tuple[int, int]:
|
||||
"""Return the size of the window or screen.
|
||||
|
||||
Returns the size of the window initialized with :func:`pygame.display.set_mode()`.
|
||||
This may differ from the size of the display surface if ``SCALED`` is used.
|
||||
|
||||
.. versionaddedold:: 2.0.0
|
||||
"""
|
||||
|
||||
def get_window_position() -> tuple[int, int]:
|
||||
"""Return the position of the window or screen.
|
||||
|
||||
Returns the position of the window initialized with :func:`pygame.display.set_mode()`.
|
||||
The position will change when the user moves the window or when the
|
||||
position is set manually with :func:`pygame.display.set_window_position()`.
|
||||
Coordinates could be negative or outside the desktop size bounds. The
|
||||
position is relative to the topleft of the primary monitor and the y coordinate
|
||||
ignores the window frame.
|
||||
|
||||
.. versionadded:: 2.5.0
|
||||
"""
|
||||
|
||||
def set_window_position(position: Point) -> None:
|
||||
"""Set the current window position.
|
||||
|
||||
Sets the position of the window initialized with :func:`pygame.display.set_mode()`.
|
||||
This differs from updating environment variables as this function can be
|
||||
called after the display has been initialised. The position is expected to
|
||||
be relative to the topleft of the primary monitor. The y coordinate will
|
||||
ignore the window frame (y = 0 means the frame is hidden). The user will
|
||||
still be able to move the window after this call. See also
|
||||
:func:`pygame.display.get_window_position()`.
|
||||
|
||||
.. note:: This function is not supported on some video drivers (like wayland)
|
||||
and a :exc:`pygame.error` exception may be raised in such cases.
|
||||
|
||||
.. versionadded:: 2.5.0
|
||||
"""
|
||||
|
||||
def get_allow_screensaver() -> bool:
|
||||
"""Return whether the screensaver is allowed to run.
|
||||
|
||||
Return whether screensaver is allowed to run whilst the app is running. Default
|
||||
is ``False``. By default pygame does not allow the screensaver during game
|
||||
play.
|
||||
|
||||
.. note:: Some platforms do not have a screensaver or support
|
||||
disabling the screensaver. Please see
|
||||
:func:`pygame.display.set_allow_screensaver()` for
|
||||
caveats with screensaver support.
|
||||
|
||||
.. versionaddedold:: 2.0.0
|
||||
"""
|
||||
|
||||
def set_allow_screensaver(value: bool = True) -> None:
|
||||
"""Set whether the screensaver may run.
|
||||
|
||||
Change whether screensavers should be allowed whilst the app is running.
|
||||
The default value of the argument to the function is True.
|
||||
By default pygame does not allow the screensaver during game play.
|
||||
|
||||
If the screensaver has been disallowed due to this function, it will automatically
|
||||
be allowed to run when :func:`pygame.quit()` is called.
|
||||
|
||||
It is possible to influence the default value via the environment variable
|
||||
``SDL_HINT_VIDEO_ALLOW_SCREENSAVER``, which can be set to either ``0`` (disable)
|
||||
or ``1`` (enable).
|
||||
|
||||
.. note:: Disabling screensaver is subject to platform support.
|
||||
When platform support is absent, this function will
|
||||
silently appear to work even though the screensaver state
|
||||
is unchanged. The lack of feedback is due to SDL not
|
||||
providing any supported method for determining whether
|
||||
it supports changing the screensaver state.
|
||||
|
||||
.. versionaddedold:: 2.0.0
|
||||
"""
|
||||
|
||||
def is_fullscreen() -> bool:
|
||||
"""Returns True if the pygame window created by pygame.display.set_mode() is in full-screen mode.
|
||||
|
||||
Edge cases:
|
||||
If the window is in windowed mode, but maximized, this will return `False`.
|
||||
If the window is in "borderless fullscreen" mode, this will return `True`.
|
||||
|
||||
.. versionadded:: 2.2.0
|
||||
"""
|
||||
|
||||
def is_vsync() -> bool:
|
||||
"""Returns True if vertical synchronisation for pygame.display.flip() and pygame.display.update() is enabled.
|
||||
|
||||
.. versionadded:: 2.2.0
|
||||
"""
|
||||
|
||||
def get_current_refresh_rate() -> int:
|
||||
"""Returns the screen refresh rate or 0 if unknown.
|
||||
|
||||
The screen refresh rate for the current window. In windowed mode, this
|
||||
should be equal to the refresh rate of the desktop the window is on.
|
||||
|
||||
If no window is open, an exception is raised.
|
||||
|
||||
When a constant refresh rate cannot be determined, 0 is returned.
|
||||
|
||||
.. versionadded:: 2.2.0
|
||||
"""
|
||||
|
||||
def get_desktop_refresh_rates() -> list[int]:
|
||||
"""Returns the screen refresh rates for all displays (in windowed mode).
|
||||
|
||||
If the current window is in full-screen mode, the actual refresh rate for
|
||||
that window can differ.
|
||||
|
||||
This is safe to call when no window is open (i.e. before any calls to
|
||||
:func:`pygame.display.set_mode()`
|
||||
|
||||
When a constant refresh rate cannot be determined, 0 is returned for that
|
||||
desktop.
|
||||
|
||||
.. versionadded:: 2.2.0
|
||||
"""
|
||||
|
||||
def message_box(
|
||||
title: str,
|
||||
message: str | None = None,
|
||||
message_type: Literal["info", "warn", "error"] = "info",
|
||||
parent_window: Window | None = None,
|
||||
buttons: SequenceLike[str] = ("OK",),
|
||||
return_button: int = 0,
|
||||
escape_button: int | None = None,
|
||||
) -> int:
|
||||
"""Create a native GUI message box.
|
||||
|
||||
:param str title: A title string.
|
||||
:param str message: A message string. If this parameter is set to ``None``, the message will be the title.
|
||||
:param str message_type: Set the type of message_box, could be ``"info"``, ``"warn"`` or ``"error"``.
|
||||
:param pygame.Window parent_window: The parent window of the message box.
|
||||
:param tuple buttons: An optional sequence of button name strings to show to the user.
|
||||
:param int return_button: Button index to use if the return key is hit, ``0`` by default.
|
||||
:param int escape_button: Button index to use if the escape key is hit, ``None`` for no button linked by default.
|
||||
|
||||
:return: The index of the button that was pushed.
|
||||
|
||||
This function should be called on the thread that ``set_mode()`` is called.
|
||||
It will block execution of that thread until the user clicks a button or
|
||||
closes the message_box.
|
||||
|
||||
This function may be called at any time, even before ``pygame.init()``.
|
||||
|
||||
Negative values of ``return_button`` and ``escape_button`` are allowed
|
||||
just like standard Python list indexing.
|
||||
|
||||
.. versionadded:: 2.4.0
|
||||
"""
|
||||
@@ -0,0 +1,10 @@
|
||||
# python -m pygame.docs
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
PKG_DIR = Path(__file__).absolute().parent / "generated"
|
||||
|
||||
|
||||
# for test suite to confirm pygame-ce built with local docs
|
||||
def has_local_docs():
|
||||
return PKG_DIR.exists()
|
||||
@@ -0,0 +1,17 @@
|
||||
import platform
|
||||
|
||||
# use relative import here and not absolute, so that `python -m docs` works at
|
||||
# development time
|
||||
from .serve import main as serve
|
||||
from .static import main as static
|
||||
|
||||
|
||||
def main():
|
||||
if platform.system() == "Linux":
|
||||
serve()
|
||||
else:
|
||||
static()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,504 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 42 B |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 52 B |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 9.5 KiB |
@@ -0,0 +1,27 @@
|
||||
pygame C API
|
||||
============
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:glob:
|
||||
|
||||
c_api/slots.rst
|
||||
c_api/base.rst
|
||||
c_api/bufferproxy.rst
|
||||
c_api/color.rst
|
||||
c_api/display.rst
|
||||
c_api/event.rst
|
||||
c_api/freetype.rst
|
||||
c_api/joystick.rst
|
||||
c_api/mixer.rst
|
||||
c_api/rect.rst
|
||||
c_api/rwobject.rst
|
||||
c_api/surface.rst
|
||||
c_api/surflock.rst
|
||||
c_api/version.rst
|
||||
c_api/window.rst
|
||||
|
||||
|
||||
src_c/include/ contains header files for applications
|
||||
that use the pygame C API, while src_c/ contains
|
||||
headers used by pygame internally.
|
||||
@@ -0,0 +1,17 @@
|
||||
File Path Function Arguments
|
||||
============================
|
||||
|
||||
A pygame function or method which takes a file path argument will accept
|
||||
either a Unicode or a byte (8-bit or ASCII character) string.
|
||||
Unicode strings are translated to Python's default filesystem encoding,
|
||||
as returned by sys.getfilesystemencoding(). A Unicode code point
|
||||
above U+FFFF (``\uFFFF``) can be coded directly with a 32-bit escape sequences
|
||||
(``\Uxxxxxxxx``), even for Python interpreters built with an UCS-2
|
||||
(16-bit character) Unicode type. Byte strings are passed
|
||||
to the operating system unchanged.
|
||||
|
||||
Null characters (``\x00``) are not permitted in the path, raising an exception.
|
||||
An exception is also raised if an Unicode file path cannot be encoded.
|
||||
How UTF-16 surrogate codes are handled is Python-interpreter-dependent.
|
||||
Use UTF-32 code points and 32-bit escape sequences instead.
|
||||
The exception types are function-dependent.
|
||||
@@ -0,0 +1,256 @@
|
||||
Pygame-ce Front Page
|
||||
====================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:glob:
|
||||
:hidden:
|
||||
|
||||
ref/*
|
||||
tutorials/en/*
|
||||
tutorials/es/*
|
||||
c_api
|
||||
filepaths
|
||||
logos
|
||||
|
||||
Quick start
|
||||
-----------
|
||||
|
||||
Welcome to pygame-ce! Once you've got pygame-ce installed
|
||||
(:code:`pip install pygame-ce` or :code:`pip3 install pygame-ce` for most
|
||||
people), the next question is how to get a game loop running. Pygame-ce,
|
||||
unlike some other libraries, gives you full control of program
|
||||
execution. That freedom means it is easy to mess up in your initial steps.
|
||||
|
||||
Here is a good example of a basic setup (opens the window, updates the screen, and handles events)--
|
||||
|
||||
.. literalinclude:: ref/code_examples/base_script.py
|
||||
|
||||
Here is a slightly more fleshed out example, which shows you how to move something
|
||||
(a circle in this case) around on screen--
|
||||
|
||||
.. literalinclude:: ref/code_examples/base_script_example.py
|
||||
|
||||
For more in depth reference, check out the :ref:`tutorials-reference-label`
|
||||
section below, or reference the API documentation by module.
|
||||
|
||||
Experimental modules
|
||||
--------------------
|
||||
|
||||
Experimental modules are work in progress, this is why you should refrain from relying on any features
|
||||
provided by these modules, as they are subject to change or removal without prior notice.
|
||||
If you want to test these experimental modules, you might want to understand how you import
|
||||
them, this is how you can do it:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pygame import experimental_module
|
||||
# Or for specific modules like _sdl2.controller
|
||||
from pygame._sdl2 import controller
|
||||
# Or
|
||||
import pygame.experimental_module
|
||||
|
||||
Don't forget to report us any problem with the experimental features on `github`_ so we can easily
|
||||
turn them to stable API in the future ^^.
|
||||
|
||||
**Below is currently the list of experimental modules :**
|
||||
|
||||
:doc:`ref/geometry`
|
||||
Pygame module for the Circle, Line, and Polygon objects.
|
||||
|
||||
:doc:`ref/sdl2_controller`
|
||||
Pygame module to work with controllers.
|
||||
|
||||
:doc:`ref/sdl2_video`
|
||||
Pygame module for porting new SDL video systems.
|
||||
|
||||
.. _github: https://github.com/pygame-community/pygame-ce
|
||||
|
||||
Documents
|
||||
---------
|
||||
|
||||
`Readme`_
|
||||
Basic information about pygame: what it is, who is involved, and where to find it.
|
||||
|
||||
:doc:`filepaths`
|
||||
How pygame handles file system paths.
|
||||
|
||||
:doc:`Pygame Logos <logos>`
|
||||
The logos of Pygame in different resolutions.
|
||||
|
||||
|
||||
`LGPL License`_
|
||||
This is the license pygame is distributed under.
|
||||
It provides for pygame to be distributed with open source and commercial software.
|
||||
Generally, if pygame is not changed, it can be used with any type of program.
|
||||
|
||||
.. _tutorials-reference-label:
|
||||
|
||||
Tutorials
|
||||
---------
|
||||
|
||||
| `Master Python by making 5 games [the new ultimate introduction to pygame] <https://www.youtube.com/watch?v=8OMghdHP-zs>`_
|
||||
| YouTube video by Clear Code.
|
||||
|
||||
| `Pygame in 18 Minutes <https://www.youtube.com/watch?v=blLLtdv4tvo>`_
|
||||
| YouTube video by DaFluffyPotato.
|
||||
|
||||
| `Introduction to Pygame-ce, 2D game programming <https://github.com/adamsralf/pygame_book/blob/main/00%20pygamece.pdf>`_
|
||||
| Book by Ralf Adams.
|
||||
|
||||
:doc:`Newbie Guide <tutorials/en/newbie-guide>`
|
||||
A list of thirteen helpful tips for people to get comfortable using pygame.
|
||||
|
||||
:doc:`Import and Initialize <tutorials/en/import-init>`
|
||||
The beginning steps on importing and initializing pygame.
|
||||
The pygame package is made of several modules.
|
||||
Some modules are not included on all platforms.
|
||||
|
||||
:doc:`How do I move an Image? <tutorials/en/move-it>`
|
||||
A basic tutorial that covers the concepts behind 2D computer animation.
|
||||
Information about drawing and clearing objects to make them appear animated.
|
||||
|
||||
:doc:`Chimp Tutorial, Line by Line <tutorials/en/chimp-explanation>`
|
||||
The pygame examples include a simple program with an interactive fist and a chimpanzee.
|
||||
This was inspired by the annoying flash banner of the early 2000s.
|
||||
This tutorial examines every line of code used in the example.
|
||||
|
||||
:doc:`What is Premultiplied Alpha? <tutorials/en/premultiplied-alpha>`
|
||||
An explanation of alpha compositing and the advantages of using premultiplied alpha.
|
||||
|
||||
:doc:`Sprite Module Introduction <tutorials/en/intro-to-sprites>`
|
||||
Pygame includes a higher level sprite module to help organize games.
|
||||
The sprite module includes several classes that help manage details found in almost all games types.
|
||||
The Sprite classes are a bit more advanced than the regular pygame modules,
|
||||
and need more understanding to be properly used.
|
||||
|
||||
:doc:`Introduction to Pygame <tutorials/en/intro-to-pygame>`
|
||||
An introduction to the basics of pygame.
|
||||
This is written for users of Python and appeared in volume two of the Py magazine.
|
||||
|
||||
:doc:`Surfarray Introduction <tutorials/en/intro-to-surfarray>`
|
||||
Pygame used the NumPy python module to allow efficient per pixel effects on images.
|
||||
Using the surface arrays is an advanced feature that allows custom effects and filters.
|
||||
This also examines some of the simple effects from the pygame example, arraydemo.py.
|
||||
|
||||
:doc:`Camera Module Introduction <tutorials/en/intro-to-camera>`
|
||||
Pygame, as of 1.9, has a camera module that allows you to capture images,
|
||||
watch live streams, and do some basic computer vision.
|
||||
This tutorial covers those use cases.
|
||||
|
||||
:doc:`Making Games Tutorial <tutorials/en/make-games>`
|
||||
A large tutorial that covers the bigger topics needed to create an entire game.
|
||||
|
||||
:doc:`Display Modes <tutorials/en/display-modes>`
|
||||
Getting a display surface for the screen.
|
||||
|
||||
:doc:`Tutorial de Pygame - Ejemplo del Chimpancé, Línea Por Línea <tutorials/es/ChimpanceLineaporLinea>`
|
||||
Los ejemplos de pygame incluyen un sencillo programa con un puño interactivo y un chimpancé.
|
||||
Está inspirado en el molesto banner de flash de principios de la década de 2000.
|
||||
Este tutorial examina cada línea de código utilizada en el ejemplo.
|
||||
|
||||
Reference
|
||||
---------
|
||||
|
||||
:ref:`genindex`
|
||||
A list of all functions, classes, and methods in the pygame package.
|
||||
|
||||
:doc:`ref/bufferproxy`
|
||||
An array protocol view of surface pixels
|
||||
|
||||
:doc:`ref/color`
|
||||
Color representation.
|
||||
|
||||
:doc:`ref/cursors`
|
||||
Loading and compiling cursor images.
|
||||
|
||||
:doc:`ref/display`
|
||||
Configure the display surface.
|
||||
|
||||
:doc:`ref/draw`
|
||||
Drawing simple shapes like lines and ellipses to surfaces.
|
||||
|
||||
:doc:`ref/event`
|
||||
Manage the incoming events from various input devices and the windowing platform.
|
||||
|
||||
:doc:`ref/examples`
|
||||
Various programs demonstrating the use of individual pygame modules.
|
||||
|
||||
:doc:`ref/font`
|
||||
Loading and rendering TrueType fonts.
|
||||
|
||||
:doc:`ref/freetype`
|
||||
Enhanced pygame module for loading and rendering font faces.
|
||||
|
||||
:doc:`ref/gfxdraw`
|
||||
Anti-aliasing draw functions.
|
||||
|
||||
:doc:`ref/image`
|
||||
Loading, saving, and transferring of surfaces.
|
||||
|
||||
:doc:`ref/joystick`
|
||||
Manage the joystick devices.
|
||||
|
||||
:doc:`ref/key`
|
||||
Manage the keyboard device.
|
||||
|
||||
:doc:`ref/locals`
|
||||
Pygame constants.
|
||||
|
||||
:doc:`ref/mixer`
|
||||
Load and play sounds
|
||||
|
||||
:doc:`ref/mouse`
|
||||
Manage the mouse device and display.
|
||||
|
||||
:doc:`ref/music`
|
||||
Play streaming music tracks.
|
||||
|
||||
:doc:`ref/pygame`
|
||||
Top level functions to manage pygame.
|
||||
|
||||
:doc:`ref/pixelarray`
|
||||
Manipulate image pixel data.
|
||||
|
||||
:doc:`ref/rect`
|
||||
Flexible container for a rectangle.
|
||||
|
||||
:doc:`ref/scrap`
|
||||
Native clipboard access.
|
||||
|
||||
:doc:`ref/sndarray`
|
||||
Manipulate sound sample data.
|
||||
|
||||
:doc:`ref/sprite`
|
||||
Higher level objects to represent game images.
|
||||
|
||||
:doc:`ref/surface`
|
||||
Objects for images and the screen.
|
||||
|
||||
:doc:`ref/surfarray`
|
||||
Manipulate image pixel data.
|
||||
|
||||
:doc:`ref/tests`
|
||||
Test pygame.
|
||||
|
||||
:doc:`ref/time`
|
||||
Manage timing and framerate.
|
||||
|
||||
:doc:`ref/transform`
|
||||
Resize and move images.
|
||||
|
||||
:doc:`ref/typing`
|
||||
Provide common typehints
|
||||
|
||||
:doc:`ref/window`
|
||||
Pygame object that handles a window.
|
||||
|
||||
:doc:`pygame C API <c_api>`
|
||||
The C api shared amongst pygame extension modules.
|
||||
|
||||
:ref:`search`
|
||||
Search pygame documents by keyword.
|
||||
|
||||
.. _Readme: https://github.com/pygame-community/pygame-ce#readme
|
||||
|
||||
.. _LGPL License: LGPL.txt
|
||||
@@ -0,0 +1,58 @@
|
||||
*************************************************
|
||||
Pygame CE Logos Page
|
||||
*************************************************
|
||||
|
||||
Pygame CE Logos
|
||||
===============
|
||||
|
||||
These logos are available for use in your own game projects.
|
||||
Please put them up wherever you see fit.
|
||||
|
||||
The pygame-ce logo and its variants were created by Mega-JC and kadir014 on June 30, 2024.
|
||||
|
||||
.. container:: fullwidth
|
||||
|
||||
.. image:: _static/pygame_ce_logo.webp
|
||||
|
||||
| `pygame_ce_logo.svg <_static/pygame_ce_logo.svg>`_
|
||||
| `pygame_ce_logo.webp <_static/pygame_ce_logo.webp>`_ - 1560 x 800
|
||||
|
||||
.. image:: _static/pygame_ce_lofi.webp
|
||||
|
||||
| `pygame_ce_lofi.svg <_static/pygame_ce_lofi.svg>`_
|
||||
| `pygame_ce_lofi.webp <_static/pygame_ce_lofi.webp>`_ - 1560 x 800
|
||||
|
||||
.. image:: _static/pygame_ce_powered.webp
|
||||
|
||||
| `pygame_ce_powered.svg <_static/pygame_ce_powered.svg>`_
|
||||
| `pygame_ce_powered.webp <_static/pygame_ce_powered.webp>`_ - 1560 x 824
|
||||
|
||||
.. image:: _static/pygame_ce_tiny.webp
|
||||
|
||||
| `pygame_ce_tiny.webp <_static/pygame_ce_tiny.webp>`_ - 214 x 110
|
||||
|
||||
.. image:: _static/pygame_ce_powered_lowres.webp
|
||||
|
||||
| `pygame_ce_powered_lowres.webp <_static/pygame_ce_powered_lowres.webp>`_ - 101 x 53
|
||||
|
||||
|
||||
|
||||
Upstream & legacy logos
|
||||
-----------------------
|
||||
|
||||
The pygame logo was originally created
|
||||
by TheCorruptor on July 29, 2001.
|
||||
|
||||
It was upscaled alongside its "LoFi" and "Powered" variants by Mega-JC on
|
||||
August 29, 2021.
|
||||
|
||||
.. container:: fullwidth
|
||||
|
||||
| `upstream_logos.zip <_static/upstream_logos.zip>`_ - 314 KB
|
||||
|
||||
There is a higher resolution layered photoshop image
|
||||
available `here <https://www.pygame.org/ftp/pygame_ce_logo.psd>`_. *(1.3 MB)*
|
||||
|
||||
.. container:: fullwidth
|
||||
|
||||
| `legacy_logos.zip <_static/legacy_logos.zip>`_ - 50.1 KB
|
||||
@@ -0,0 +1,113 @@
|
||||
.. include:: common.txt
|
||||
|
||||
.. default-domain:: py
|
||||
|
||||
:class:`pygame.BufferProxy`
|
||||
===========================
|
||||
|
||||
.. currentmodule:: pygame
|
||||
|
||||
.. class:: BufferProxy
|
||||
|
||||
| :sl:`pygame object to export a surface buffer through an array protocol`
|
||||
| :sg:`BufferProxy(parent) -> BufferProxy`
|
||||
|
||||
:class:`BufferProxy` is a pygame support type, designed as the return value
|
||||
of the :meth:`Surface.get_buffer` and :meth:`Surface.get_view` methods.
|
||||
For all Python versions a :class:`BufferProxy` object exports a C struct
|
||||
and Python level array interface on behalf of its parent object's buffer.
|
||||
A new buffer interface is also exported.
|
||||
In pygame, :class:`BufferProxy` is key to implementing the
|
||||
:mod:`pygame.surfarray` module.
|
||||
|
||||
:class:`BufferProxy` instances can be created directly from Python code,
|
||||
either for a parent that exports an interface, or from a Python ``dict``
|
||||
describing an object's buffer layout. The dict entries are based on the
|
||||
Python level array interface mapping. The following keys are recognized:
|
||||
|
||||
``"shape"`` : tuple
|
||||
The length of each array dimension as a tuple of integers. The
|
||||
length of the tuple is the number of dimensions in the array.
|
||||
|
||||
``"typestr"`` : string
|
||||
The array element type as a length 3 string. The first character
|
||||
gives byteorder, '<' for little-endian, '>' for big-endian, and
|
||||
'\|' for not applicable. The second character is the element type,
|
||||
'i' for signed integer, 'u' for unsigned integer, 'f' for floating
|
||||
point, and 'V' for an chunk of bytes. The third character gives the
|
||||
bytesize of the element, from '1' to '9' bytes. So, for example,
|
||||
"<u4" is an unsigned 4 byte little-endian integer, such as a
|
||||
32 bit pixel on a PC, while "\|V3" would represent a 24 bit pixel,
|
||||
which has no integer equivalent.
|
||||
|
||||
``"data"`` : tuple
|
||||
The physical buffer start address and a read-only flag as a length
|
||||
2 tuple. The address is an integer value, while the read-only flag
|
||||
is a bool—``False`` for writable, ``True`` for read-only.
|
||||
|
||||
``"strides"`` : tuple : (optional)
|
||||
Array stride information as a tuple of integers. It is required
|
||||
only of non C-contiguous arrays. The tuple length must match
|
||||
that of ``"shape"``.
|
||||
|
||||
``"parent"`` : object : (optional)
|
||||
The exporting object. It can be used to keep the parent object
|
||||
alive while its buffer is visible.
|
||||
|
||||
``"before"`` : callable : (optional)
|
||||
Callback invoked when the :class:`BufferProxy` instance
|
||||
exports the buffer. The callback is given one argument, the
|
||||
``"parent"`` object if given, otherwise ``None``.
|
||||
The callback is useful for setting a lock on the parent.
|
||||
|
||||
``"after"`` : callable : (optional)
|
||||
Callback invoked when an exported buffer is released.
|
||||
The callback is passed on argument, the ``"parent"`` object if given,
|
||||
otherwise None. The callback is useful for releasing a lock on the
|
||||
parent.
|
||||
|
||||
The BufferProxy class supports subclassing, instance variables, and weak
|
||||
references.
|
||||
|
||||
.. versionaddedold:: 1.8.0
|
||||
.. versionextendedold:: 1.9.2
|
||||
|
||||
.. attribute:: parent
|
||||
|
||||
| :sl:`Return wrapped exporting object.`
|
||||
| :sg:`parent -> Surface`
|
||||
| :sg:`parent -> parent`
|
||||
|
||||
The :class:`Surface` which returned the :class:`BufferProxy` object or
|
||||
the object passed to a :class:`BufferProxy` call.
|
||||
|
||||
.. attribute:: length
|
||||
|
||||
| :sl:`The size, in bytes, of the exported buffer.`
|
||||
| :sg:`length -> int`
|
||||
|
||||
The number of valid bytes of data exported. For discontinuous data,
|
||||
that is data which is not a single block of memory, the bytes within
|
||||
the gaps are excluded from the count. This property is equivalent to
|
||||
the ``Py_buffer`` C struct ``len`` field.
|
||||
|
||||
.. attribute:: raw
|
||||
|
||||
| :sl:`A copy of the exported buffer as a single block of bytes.`
|
||||
| :sg:`raw -> bytes`
|
||||
|
||||
The buffer data as a ``str``/``bytes`` object.
|
||||
Any gaps in the exported data are removed.
|
||||
|
||||
.. method:: write
|
||||
|
||||
| :sl:`Write raw bytes to object buffer.`
|
||||
| :sg:`write(buffer, offset=0)`
|
||||
|
||||
Overwrite bytes in the parent object's data. The data must be C or F
|
||||
contiguous, otherwise a ValueError is raised. Argument `buffer` is a
|
||||
``str``/``bytes`` object. An optional offset gives a
|
||||
start position, in bytes, within the buffer where overwriting begins.
|
||||
If the offset is negative or greater that or equal to the buffer proxy's
|
||||
:attr:`length` value, an ``IndexException`` is raised.
|
||||
If ``len(buffer) > proxy.length + offset``, a ``ValueError`` is raised.
|
||||
@@ -0,0 +1,246 @@
|
||||
.. include:: common.txt
|
||||
|
||||
:mod:`pygame.camera`
|
||||
====================
|
||||
|
||||
.. module:: pygame.camera
|
||||
:synopsis: pygame module for camera use
|
||||
|
||||
| :sl:`pygame module for camera use`
|
||||
|
||||
Pygame currently supports Linux (V4L2) and Windows (MSMF) cameras natively,
|
||||
with wider platform support available via an integrated OpenCV backend.
|
||||
|
||||
.. versionaddedold:: 2.0.2 Windows native camera support
|
||||
.. versionaddedold:: 2.0.3 New OpenCV backends
|
||||
.. versionchanged:: 2.3.0 Removed deprecated vidcapture backend
|
||||
|
||||
EXPERIMENTAL!: This API may change or disappear in later pygame releases. If
|
||||
you use this, your code will very likely break with the next pygame release.
|
||||
|
||||
The Bayer to ``RGB`` function is based on:
|
||||
|
||||
::
|
||||
|
||||
Sonix SN9C101 based webcam basic I/F routines
|
||||
Copyright (C) 2004 Takafumi Mizuno <taka-qce@ls-a.jp>
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
.. versionaddedold:: 1.9.0
|
||||
|
||||
.. function:: init
|
||||
|
||||
| :sl:`Module init`
|
||||
| :sg:`init(backend = None) -> None`
|
||||
|
||||
This function starts up the camera module, choosing the best webcam backend
|
||||
it can find for your system. This is not guaranteed to succeed, and may even
|
||||
attempt to import third party modules, like `OpenCV`. If you want to
|
||||
override its backend choice, you can call pass the name of the backend you
|
||||
want into this function. More about backends in
|
||||
:func:`get_backends()`.
|
||||
|
||||
.. versionchangedold:: 2.0.3 Option to explicitly select backend
|
||||
|
||||
.. ## pygame.camera.init ##
|
||||
|
||||
.. function:: get_backends
|
||||
|
||||
| :sl:`Get the backends supported on this system`
|
||||
| :sg:`get_backends() -> [str]`
|
||||
|
||||
This function returns every backend it thinks has a possibility of working
|
||||
on your system, in order of priority.
|
||||
|
||||
pygame.camera Backends:
|
||||
::
|
||||
|
||||
Backend OS Description
|
||||
---------------------------------------------------------------------------------
|
||||
_camera (MSMF) Windows Builtin, works on Windows 8+ Python3
|
||||
_camera (V4L2) Linux Builtin
|
||||
OpenCV Any Uses `opencv-python` module, can't enumerate cameras
|
||||
OpenCV-Mac Mac Same as OpenCV, but has camera enumeration
|
||||
|
||||
There are two main differences among backends.
|
||||
|
||||
The _camera backends are built in to pygame itself, and require no third
|
||||
party imports. All the other backends do. For the OpenCV backend,
|
||||
the module will need to be installed on your system.
|
||||
|
||||
The other big difference is "camera enumeration." Some backends don't have
|
||||
a way to list out camera names, or even the number of cameras on the
|
||||
system. In these cases, :func:`list_cameras()` will return
|
||||
something like ``[0]``. If you know you have multiple cameras on the
|
||||
system, these backend ports will pass through a "camera index number"
|
||||
through if you use that as the ``device`` parameter.
|
||||
|
||||
.. versionaddedold:: 2.0.3
|
||||
|
||||
.. ## pygame.camera.get_backends ##
|
||||
|
||||
.. function:: colorspace
|
||||
|
||||
| :sl:`Surface colorspace conversion`
|
||||
| :sg:`colorspace(surface, format, dest_surface = None, /) -> Surface`
|
||||
|
||||
Allows for conversion from "RGB" to a destination colorspace of "HSV" or
|
||||
"YUV". The source and destination surfaces must be the same size and pixel
|
||||
depth. This is useful for computer vision on devices with limited processing
|
||||
power. Capture as small of an image as possible, ``transform.scale()`` it
|
||||
even smaller, and then convert the colorspace to ``YUV`` or ``HSV`` before
|
||||
doing any processing on it.
|
||||
|
||||
.. ## pygame.camera.colorspace ##
|
||||
|
||||
.. function:: list_cameras
|
||||
|
||||
| :sl:`returns a list of available cameras`
|
||||
| :sg:`list_cameras() -> [cameras]`
|
||||
|
||||
Checks the computer for available cameras and returns a list of strings of
|
||||
camera names, ready to be fed into :class:`pygame.camera.Camera`.
|
||||
|
||||
If the camera backend doesn't support webcam enumeration, this will return
|
||||
something like ``[0]``. See :func:`get_backends()` for much more
|
||||
information.
|
||||
|
||||
.. ## pygame.camera.list_cameras ##
|
||||
|
||||
.. class:: Camera
|
||||
|
||||
| :sl:`load a camera`
|
||||
| :sg:`Camera(device, (width, height), format) -> Camera`
|
||||
|
||||
Loads a camera. On Linux, the device is typically something like
|
||||
"/dev/video0". Default width and height are 640 by 480.
|
||||
Format is the desired colorspace of the output.
|
||||
This is useful for computer vision purposes. The default is
|
||||
``RGB``. The following are supported:
|
||||
|
||||
* ``RGB`` - Red, Green, Blue
|
||||
|
||||
* ``YUV`` - Luma, Blue Chrominance, Red Chrominance
|
||||
|
||||
* ``HSV`` - Hue, Saturation, Value
|
||||
|
||||
.. method:: start
|
||||
|
||||
| :sl:`opens, initializes, and starts capturing`
|
||||
| :sg:`start() -> None`
|
||||
|
||||
Opens the camera device, attempts to initialize it, and begins recording
|
||||
images to a buffer. The camera must be started before any of the below
|
||||
functions can be used.
|
||||
|
||||
.. ## Camera.start ##
|
||||
|
||||
.. method:: stop
|
||||
|
||||
| :sl:`stops, uninitializes, and closes the camera`
|
||||
| :sg:`stop() -> None`
|
||||
|
||||
Stops recording, uninitializes the camera, and closes it. Once a camera
|
||||
is stopped, the below functions cannot be used until it is started again.
|
||||
|
||||
.. ## Camera.stop ##
|
||||
|
||||
.. method:: get_controls
|
||||
|
||||
| :sl:`gets current values of user controls`
|
||||
| :sg:`get_controls() -> (hflip = bool, vflip = bool, brightness)`
|
||||
|
||||
If the camera supports it, get_controls will return the current settings
|
||||
for horizontal and vertical image flip as bools and brightness as an int.
|
||||
If unsupported, it will return the default values of (0, 0, 0). Note that
|
||||
the return values here may be different than those returned by
|
||||
set_controls, though these are more likely to be correct.
|
||||
|
||||
.. ## Camera.get_controls ##
|
||||
|
||||
.. method:: set_controls
|
||||
|
||||
| :sl:`changes camera settings if supported by the camera`
|
||||
| :sg:`set_controls(hflip = bool, vflip = bool, brightness) -> (hflip = bool, vflip = bool, brightness)`
|
||||
|
||||
Allows you to change camera settings if the camera supports it. The
|
||||
return values will be the input values if the camera claims it succeeded
|
||||
or the values previously in use if not. Each argument is optional, and
|
||||
the desired one can be chosen by supplying the keyword, like hflip. Note
|
||||
that the actual settings being used by the camera may not be the same as
|
||||
those returned by set_controls. On Windows, :code:`hflip` and :code:`vflip` are
|
||||
implemented by pygame, not by the Camera, so they should always work, but
|
||||
:code:`brightness` is unsupported.
|
||||
|
||||
.. ## Camera.set_controls ##
|
||||
|
||||
.. method:: get_size
|
||||
|
||||
| :sl:`returns the dimensions of the images being recorded`
|
||||
| :sg:`get_size() -> (width, height)`
|
||||
|
||||
Returns the current dimensions of the images being captured by the
|
||||
camera. This will return the actual size, which may be different than the
|
||||
one specified during initialization if the camera did not support that
|
||||
size.
|
||||
|
||||
.. ## Camera.get_size ##
|
||||
|
||||
.. method:: query_image
|
||||
|
||||
| :sl:`checks if a frame is ready`
|
||||
| :sg:`query_image() -> bool`
|
||||
|
||||
If an image is ready to get, it returns true. Otherwise it returns false.
|
||||
Note that some webcams will always return False and will only queue a
|
||||
frame when called with a blocking function like :func:`get_image()`.
|
||||
On Windows (MSMF), and the OpenCV backends, :func:`query_image()`
|
||||
should be reliable, though. This is useful to separate the framerate of
|
||||
the game from that of the camera without having to use threading.
|
||||
|
||||
.. ## Camera.query_image ##
|
||||
|
||||
.. method:: get_image
|
||||
|
||||
| :sl:`captures an image as a Surface`
|
||||
| :sg:`get_image(Surface = None, /) -> Surface`
|
||||
|
||||
Pulls an image off of the buffer as an ``RGB`` Surface. It can optionally
|
||||
reuse an existing Surface to save time. The bit-depth of the surface is
|
||||
24 bits on Linux, 32 bits on Windows, or the same as the optionally
|
||||
supplied Surface.
|
||||
|
||||
.. ## Camera.get_image ##
|
||||
|
||||
.. method:: get_raw
|
||||
|
||||
| :sl:`returns an unmodified image as bytes`
|
||||
| :sg:`get_raw() -> bytes`
|
||||
|
||||
Gets an image from a camera as a string in the native pixelformat of the
|
||||
camera. Useful for integration with other libraries. This returns a
|
||||
bytes object
|
||||
|
||||
.. ## Camera.get_raw ##
|
||||
|
||||
.. ## pygame.camera.Camera ##
|
||||
|
||||
.. ## pygame.camera ##
|
||||
@@ -0,0 +1,9 @@
|
||||
.. include:: common.txt
|
||||
|
||||
:mod:`pygame.Color`
|
||||
===================
|
||||
|
||||
.. currentmodule:: pygame
|
||||
|
||||
.. autopgclass:: Color
|
||||
:members:
|
||||
@@ -0,0 +1,11 @@
|
||||
.. include:: common.txt
|
||||
|
||||
:mod:`pygame.cursors`
|
||||
=====================
|
||||
|
||||
.. autopgmodule:: pygame.cursors
|
||||
:members:
|
||||
|
||||
Example code for creating and settings cursors. (Click the mouse to switch cursor)
|
||||
|
||||
.. literalinclude:: code_examples/cursors_module_example.py
|
||||
@@ -0,0 +1,7 @@
|
||||
.. include:: common.txt
|
||||
|
||||
:mod:`pygame.display`
|
||||
=====================
|
||||
|
||||
.. autopgmodule:: pygame.display
|
||||
:members:
|
||||
@@ -0,0 +1,14 @@
|
||||
.. include:: common.txt
|
||||
|
||||
:mod:`pygame.draw`
|
||||
==================
|
||||
|
||||
.. autopgmodule:: pygame.draw
|
||||
:members:
|
||||
|
||||
.. figure:: code_examples/draw_module_example.png
|
||||
:alt: draw module example
|
||||
|
||||
Example code for draw module.
|
||||
|
||||
.. literalinclude:: code_examples/draw_module_example.py
|
||||
@@ -0,0 +1,524 @@
|
||||
.. include:: common.txt
|
||||
|
||||
:mod:`pygame.event`
|
||||
===================
|
||||
|
||||
.. module:: pygame.event
|
||||
:synopsis: pygame module for interacting with events and queues
|
||||
|
||||
| :sl:`pygame module for interacting with events and queues`
|
||||
|
||||
.. rubric:: Event queue
|
||||
|
||||
Pygame handles all its event messaging through an event queue. The functions in
|
||||
this module help you manage that event queue. The input queue is heavily
|
||||
dependent on the video system (:mod:`pygame.display` or :class:`pygame.Window`).
|
||||
If a window has not been created, the event queue may not work properly.
|
||||
|
||||
The event queue has an upper limit on the number of events it can hold. When
|
||||
the queue becomes full new events are quietly dropped. To prevent lost events,
|
||||
especially input events which signal a quit command, your program must handle
|
||||
events every frame (with :func:`pygame.event.get()`, :func:`pygame.event.pump()`,
|
||||
:func:`pygame.event.wait()`, :func:`pygame.event.peek()` or
|
||||
:func:`pygame.event.clear()`).
|
||||
|
||||
.. note:: Not handling events may cause the system to decide the program is
|
||||
frozen (not responding).
|
||||
|
||||
.. rubric:: Events of input devices
|
||||
|
||||
To get the state of various input devices, you can forego the event queue and
|
||||
access the input devices directly with their appropriate modules:
|
||||
:mod:`pygame.mouse`, :mod:`pygame.key`, and :mod:`pygame.joystick`. However,
|
||||
the event queue still needs to be running internally to enable this; programs
|
||||
still need to use functions like :func:`pygame.event.get()` or
|
||||
:func:`pygame.event.pump()` periodically. Note: Joysticks will not send any
|
||||
events until the device has been initialized.
|
||||
|
||||
.. rubric:: Event objects
|
||||
|
||||
The event queue contains :class:`pygame.event.Event` event objects.
|
||||
There are a variety of ways to access the queued events, from simply
|
||||
checking for the existence of events, to popping them off of the event queue.
|
||||
|
||||
All :class:`pygame.event.Event` instances contain an event type identifier
|
||||
and attributes specific to that event type. The event type identifier is
|
||||
accessible as the :attr:`pygame.event.Event.type` property. An event type's
|
||||
specific attributes can be accessed directly as an attribute on the event
|
||||
object.
|
||||
|
||||
Users can create their own new events (or emulate system events) by
|
||||
instantiating :func:`pygame.event.Event()` themselves, usually paired
|
||||
with :func:`pygame.event.post()`.
|
||||
|
||||
Events support equality and inequality comparisons. Two events are equal if
|
||||
they are the same type and have identical attribute values.
|
||||
|
||||
.. rubric:: Custom events and debugging
|
||||
|
||||
The event type identifier is in between the values of ``NOEVENT`` and
|
||||
``NUMEVENTS``. User defined events should have a value in the inclusive range
|
||||
of ``USEREVENT`` to ``NUMEVENTS - 1``. User defined events should reserve
|
||||
a custom event number with :func:`pygame.event.custom_type()`.
|
||||
|
||||
While debugging and experimenting, you can print an event object for a quick
|
||||
display of its type and members.
|
||||
|
||||
.. rubric:: Event types and attributes
|
||||
|
||||
Events that come from the system will have a guaranteed set of member
|
||||
attributes based on the type. The following are lists of event types with their
|
||||
specific attributes and notes.
|
||||
|
||||
You can also find a list of constants for keyboard keys
|
||||
:ref:`here <key-constants-label>`.
|
||||
|
||||
::
|
||||
|
||||
Event type Attributes/Notes
|
||||
|
||||
QUIT
|
||||
USEREVENT (Starting type of the user defined
|
||||
event types)
|
||||
|
||||
KEYDOWN key, mod, unicode, scancode, window(1)
|
||||
KEYUP key, mod, unicode, scancode, window(1)
|
||||
|
||||
MOUSEMOTION pos, rel, buttons, touch(2), window(1)
|
||||
MOUSEBUTTONUP pos, button, touch(2), clicks(3), window(1)
|
||||
MOUSEBUTTONDOWN pos, button, touch(2), clicks(3), window(1)
|
||||
MOUSEWHEEL which, flipped, x, y, touch(2), precise_x,
|
||||
precise_y, window(1), pos(5)
|
||||
|
||||
JOYAXISMOTION instance_id, axis, value (deprecated: joy)
|
||||
JOYBALLMOTION instance_id, ball, rel (deprecated: joy)
|
||||
JOYHATMOTION instance_id, hat, value (deprecated: joy)
|
||||
JOYBUTTONUP instance_id, button (deprecated: joy)
|
||||
JOYBUTTONDOWN instance_id, button (deprecated: joy)
|
||||
CONTROLLERDEVICEADDED device_index
|
||||
JOYDEVICEADDED device_index
|
||||
CONTROLLERDEVICEREMOVED instance_id
|
||||
JOYDEVICEREMOVED instance_id
|
||||
CONTROLLERDEVICEREMAPPED instance_id
|
||||
|
||||
(Use the window event API instead of legacy events)
|
||||
ACTIVEEVENT gain, state (Legacy event)
|
||||
VIDEORESIZE size, w, h (Legacy event)
|
||||
VIDEOEXPOSE (Legacy event)
|
||||
|
||||
AUDIODEVICEADDED which, iscapture
|
||||
AUDIODEVICEREMOVED which, iscapture
|
||||
|
||||
FINGERMOTION touch_id, finger_id, x, y, dx, dy, window(1)
|
||||
FINGERDOWN touch_id, finger_id, x, y, dx, dy, window(1)
|
||||
FINGERUP touch_id, finger_id, x, y, dx, dy, window(1)
|
||||
MULTIGESTURE touch_id, x, y, pinched, rotated, num_fingers
|
||||
|
||||
TEXTEDITING(4) text, start(4), length(4), window(1)
|
||||
TEXTINPUT(4) text, window(1)
|
||||
|
||||
DROPFILE window(1), file (Path of the file dropped
|
||||
on the window)
|
||||
DROPBEGIN window(1)
|
||||
DROPCOMPLETE window(1)
|
||||
DROPTEXT window(1)
|
||||
|
||||
MIDIIN (Reserved for pygame.midi use)
|
||||
MIDIOUT (Reserved for pygame.midi use)
|
||||
|
||||
KEYMAPCHANGED (Keymap change due to language/keyboard
|
||||
layout change)
|
||||
CLIPBOARDUPDATE (Partially experimental)
|
||||
LOCALECHANGED
|
||||
|
||||
RENDER_TARGETS_RESET
|
||||
RENDER_DEVICE_RESET
|
||||
|
||||
|
|
||||
|
||||
(``1``): if a :class:`pygame.Window` instance exists for the window that the event
|
||||
occurred in, the ``window`` attribute of these events will be that instance,
|
||||
otherwise it will be ``None``.
|
||||
|
||||
(``2``): The ``touch`` attribute of ``MOUSE`` events indicates whether or not the
|
||||
events were generated by a touch input device, and not a real mouse. You might
|
||||
want to ignore such events, if your application already handles ``FINGERMOTION``,
|
||||
``FINGERDOWN`` and ``FINGERUP`` events.
|
||||
|
||||
(``3``): The ``clicks`` attribute of the ``MOUSEBUTTONDOWN`` and ``MOUSEBUTTONUP``
|
||||
events indicate the number of clicks occurring in rapid succession, e.g. ``1``
|
||||
for single-click, ``2`` for double-click, etc. Note that double, triple, or
|
||||
more clicks will still fire mouse events for each individual click, with a
|
||||
progressively increasing ``clicks`` attribute.
|
||||
|
||||
(``4``): The ``start`` attribute of the ``TEXTEDITING`` event is the cursor position,
|
||||
in UTF-8 characters, where the new typing will be inserted into the editing text,
|
||||
while the ``length`` attribute is the number of UTF-8 characters that will be
|
||||
replaced by the new typing.
|
||||
|
||||
These ``TEXT*`` events are useful to implement inputs/languages that require composition,
|
||||
provided by the system's IME (Input Method Editor). The ``TEXTINPUT`` event is only
|
||||
fired when the text is confirmed.
|
||||
|
||||
(``5``): Position information was added to ``MOUSEWHEEL`` events in SDL 2.26.0. If
|
||||
pygame was built on a version lower than that, the ``pos`` attribute is ``None``.
|
||||
|
||||
|
|
||||
|
||||
Here is a list of the new window events.
|
||||
|
||||
All window events have a ``window`` attribute corresponding to the
|
||||
:class:`pygame.Window` that generated them.
|
||||
|
||||
::
|
||||
|
||||
Event type Short description and additional attributes
|
||||
|
||||
WINDOWSHOWN Window became shown
|
||||
WINDOWHIDDEN Window became hidden
|
||||
WINDOWEXPOSED Window got updated by some external event
|
||||
WINDOWMOVED Window got moved (x, y attributes)
|
||||
WINDOWSIZECHANGED Window size has changed (x, y attributes)
|
||||
WINDOWRESIZED Window got resized by the user/window manager
|
||||
(x, y attributes)
|
||||
WINDOWMINIMIZED Window was minimized
|
||||
WINDOWMAXIMIZED Window was maximized
|
||||
WINDOWRESTORED Window was restored
|
||||
WINDOWENTER Mouse entered the window
|
||||
WINDOWLEAVE Mouse left the window
|
||||
WINDOWFOCUSGAINED Window gained focus
|
||||
WINDOWFOCUSLOST Window lost focus
|
||||
WINDOWCLOSE Window was closed
|
||||
WINDOWTAKEFOCUS Window was offered focus
|
||||
WINDOWHITTEST Window has a special hit test
|
||||
WINDOWICCPROFCHANGED Window ICC profile changed
|
||||
(SDL backend >= 2.0.18)
|
||||
WINDOWDISPLAYCHANGED Window moved on a new display (display_index
|
||||
attribute. SDL backend >= 2.0.18)
|
||||
|
||||
|
|
||||
|
||||
On Android, the following events can be generated:
|
||||
|
||||
::
|
||||
|
||||
Event type Short description
|
||||
|
||||
APP_TERMINATING OS is terminating the application
|
||||
APP_LOWMEMORY OS is low on memory (try to free memory)
|
||||
APP_WILLENTERBACKGROUND Application is entering background
|
||||
APP_DIDENTERBACKGROUND Application entered background
|
||||
APP_WILLENTERFOREGROUND Application is entering foreground
|
||||
APP_DIDENTERFOREGROUND Application entered foreground
|
||||
|
||||
|
|
||||
|
||||
.. versionchangedold:: 2.0.0 The ``joy`` attribute was deprecated, ``instance_id`` was added.
|
||||
|
||||
.. versionaddedold:: 2.0.1 Window events and the ``unicode`` attribute for ``KEYUP`` events.
|
||||
|
||||
.. versionaddedold:: 2.0.2 The ``touch`` attribute was added to all the ``MOUSE`` events.
|
||||
|
||||
.. versionadded:: 2.1.3 Android events, ``precise_x`` and ``precise_y`` to ``MOUSEWHEEL`` events,
|
||||
``KEYMAPCHANGED``, ``CLIPBOARDUPDATE``, ``LOCALECHANGED``, ``WINDOWICCPROFCHANGED``,
|
||||
``WINDOWDISPLAYCHANGED``, ``RENDER_TARGETS_RESET``, and ``RENDER_DEVICE_RESET``.
|
||||
|
||||
.. versionadded:: 2.5.7 The ``clicks`` attribute was added to ``MOUSEBUTTONDOWN``
|
||||
and ``MOUSEBUTTONUP`` events.
|
||||
|
||||
.. versionadded:: 2.5.8 The ``pos`` attribute was added to ``MOUSEWHEEL`` events.
|
||||
|
||||
|
|
||||
|
||||
.. function:: pump
|
||||
|
||||
| :sl:`internally process pygame event handlers`
|
||||
| :sg:`pump() -> None`
|
||||
|
||||
For each frame of your game, you will need to make some sort of call to the
|
||||
event queue. This ensures your program can internally interact with the rest
|
||||
of the operating system. If you are not using other event functions in your
|
||||
game, you should call ``pygame.event.pump()`` to allow pygame to handle
|
||||
internal actions.
|
||||
|
||||
This function is not necessary if your program is consistently processing
|
||||
events on the queue through the other :mod:`pygame.event` functions.
|
||||
|
||||
There are important things that must be dealt with internally in the event
|
||||
queue. The main window may need to be repainted or respond to the system. If
|
||||
you fail to make a call to the event queue for too long, the system may
|
||||
decide your program has locked up.
|
||||
|
||||
.. caution::
|
||||
This function should only be called in the thread that initialized :mod:`pygame.display`.
|
||||
|
||||
.. ## pygame.event.pump ##
|
||||
|
||||
.. function:: get
|
||||
|
||||
| :sl:`get events from the queue`
|
||||
| :sg:`get(eventtype=None) -> Eventlist`
|
||||
| :sg:`get(eventtype=None, pump=True) -> Eventlist`
|
||||
| :sg:`get(eventtype=None, pump=True, exclude=None) -> Eventlist`
|
||||
|
||||
This will get all the messages and remove them from the queue. If a type or
|
||||
sequence of types is given only those messages will be removed from the
|
||||
queue and returned.
|
||||
|
||||
If a type or sequence of types is passed in the ``exclude`` argument
|
||||
instead, then all only *other* messages will be removed from the queue. If
|
||||
an ``exclude`` parameter is passed, the ``eventtype`` parameter *must* be
|
||||
None.
|
||||
|
||||
If you are only taking specific events from the queue, be aware that the
|
||||
queue could eventually fill up with the events you are not interested.
|
||||
|
||||
If ``pump`` is ``True`` (the default), then :func:`pygame.event.pump()` will be called.
|
||||
|
||||
.. versionchangedold:: 1.9.5 Added ``pump`` argument
|
||||
.. versionchangedold:: 2.0.2 Added ``exclude`` argument
|
||||
|
||||
.. ## pygame.event.get ##
|
||||
|
||||
.. function:: poll
|
||||
|
||||
| :sl:`get a single event from the queue`
|
||||
| :sg:`poll() -> Event instance`
|
||||
|
||||
Returns a single event from the queue. If the event queue is empty an event
|
||||
of type ``pygame.NOEVENT`` will be returned immediately. The returned event
|
||||
is removed from the queue.
|
||||
|
||||
.. caution::
|
||||
This function should only be called in the thread that initialized :mod:`pygame.display`.
|
||||
|
||||
.. ## pygame.event.poll ##
|
||||
|
||||
.. function:: wait
|
||||
|
||||
| :sl:`wait for a single event from the queue`
|
||||
| :sg:`wait() -> Event instance`
|
||||
| :sg:`wait(timeout) -> Event instance`
|
||||
|
||||
Returns a single event from the queue. If the queue is empty this function
|
||||
will wait until one is created. From pygame 2.0.0, if a ``timeout`` argument
|
||||
is given, the function will return an event of type ``pygame.NOEVENT``
|
||||
if no events enter the queue in ``timeout`` milliseconds. The event is removed
|
||||
from the queue once it has been returned. While the program is waiting it will
|
||||
sleep in an idle state. This is important for programs that want to share the
|
||||
system with other applications.
|
||||
|
||||
.. versionchangedold:: 2.0.0.dev13 Added ``timeout`` argument
|
||||
|
||||
.. caution::
|
||||
This function should only be called in the thread that initialized :mod:`pygame.display`.
|
||||
|
||||
.. ## pygame.event.wait ##
|
||||
|
||||
.. function:: peek
|
||||
|
||||
| :sl:`test if event types are waiting on the queue`
|
||||
| :sg:`peek(eventtype=None) -> bool`
|
||||
| :sg:`peek(eventtype=None, pump=True) -> bool`
|
||||
|
||||
Returns ``True`` if there are any events of the given type waiting on the
|
||||
queue. If a sequence of event types is passed, this will return ``True`` if
|
||||
any of those events are on the queue.
|
||||
|
||||
When ``eventtype`` is not passed or ``None``, this function will return ``True`` if
|
||||
there's any event on the queue, and return ``False`` if the queue is empty.
|
||||
|
||||
If ``pump`` is ``True`` (the default), then :func:`pygame.event.pump()` will be called.
|
||||
|
||||
.. versionchangedold:: 1.9.5 Added ``pump`` argument
|
||||
|
||||
.. versionchanged:: 2.5.3 no longer mistakenly returns an event when ``eventtype`` is None or not passed.
|
||||
|
||||
.. ## pygame.event.peek ##
|
||||
|
||||
.. function:: clear
|
||||
|
||||
| :sl:`remove all events from the queue`
|
||||
| :sg:`clear(eventtype=None) -> None`
|
||||
| :sg:`clear(eventtype=None, pump=True) -> None`
|
||||
|
||||
Removes all events from the queue. If ``eventtype`` is given, removes the given event
|
||||
or sequence of events. This has the same effect as :func:`pygame.event.get()` except ``None``
|
||||
is returned. It can be slightly more efficient when clearing a full event queue.
|
||||
|
||||
If ``pump`` is ``True`` (the default), then :func:`pygame.event.pump()` will be called.
|
||||
|
||||
.. versionchangedold:: 1.9.5 Added ``pump`` argument
|
||||
|
||||
.. ## pygame.event.clear ##
|
||||
|
||||
.. function:: event_name
|
||||
|
||||
| :sl:`get the string name from an event id`
|
||||
| :sg:`event_name(type, /) -> string`
|
||||
|
||||
Returns a string representing the name (in CapWords style) of the given
|
||||
event type.
|
||||
|
||||
"UserEvent" is returned for all values in the user event id range.
|
||||
"Unknown" is returned when the event type does not exist.
|
||||
|
||||
.. ## pygame.event.event_name ##
|
||||
|
||||
.. function:: set_blocked
|
||||
|
||||
| :sl:`control which events are blocked on the queue`
|
||||
| :sg:`set_blocked(type, /) -> None`
|
||||
| :sg:`set_blocked(typelist, /) -> None`
|
||||
| :sg:`set_blocked(None) -> None`
|
||||
|
||||
The given event types are not allowed to appear on the event queue. By
|
||||
default all events can be placed on the queue. It is safe to disable an
|
||||
event type multiple times.
|
||||
|
||||
If ``None`` is passed as the argument, ALL of the event types are blocked
|
||||
from being placed on the queue.
|
||||
|
||||
.. ## pygame.event.set_blocked ##
|
||||
|
||||
.. function:: set_allowed
|
||||
|
||||
| :sl:`control which events are allowed on the queue`
|
||||
| :sg:`set_allowed(type, /) -> None`
|
||||
| :sg:`set_allowed(typelist, /) -> None`
|
||||
| :sg:`set_allowed(None) -> None`
|
||||
|
||||
The given event types are allowed to appear on the event queue. By default,
|
||||
all event types can be placed on the queue. It is safe to enable an event
|
||||
type multiple times.
|
||||
|
||||
If ``None`` is passed as the argument, ALL of the event types are allowed
|
||||
to be placed on the queue.
|
||||
|
||||
.. ## pygame.event.set_allowed ##
|
||||
|
||||
.. function:: get_blocked
|
||||
|
||||
| :sl:`test if a type of event is blocked from the queue`
|
||||
| :sg:`get_blocked(type, /) -> bool`
|
||||
| :sg:`get_blocked(typelist, /) -> bool`
|
||||
|
||||
Returns ``True`` if the given event type is blocked from the queue. If a
|
||||
sequence of event types is passed, this will return ``True`` if any of those
|
||||
event types are blocked.
|
||||
|
||||
.. ## pygame.event.get_blocked ##
|
||||
|
||||
.. function:: set_grab
|
||||
|
||||
| :sl:`control the sharing of input devices with other applications`
|
||||
| :sg:`set_grab(bool, /) -> None`
|
||||
|
||||
When your program runs in a windowed environment, it will share the mouse
|
||||
and keyboard devices with other applications that have focus. If your
|
||||
program sets the event grab to ``True``, it will lock all input into your
|
||||
program.
|
||||
|
||||
It is best to not always grab the input, since it prevents the user from
|
||||
doing other things on their system.
|
||||
|
||||
.. ## pygame.event.set_grab ##
|
||||
|
||||
.. function:: get_grab
|
||||
|
||||
| :sl:`test if the program is sharing input devices`
|
||||
| :sg:`get_grab() -> bool`
|
||||
|
||||
Returns ``True`` when the input events are grabbed for this application.
|
||||
|
||||
.. ## pygame.event.get_grab ##
|
||||
|
||||
.. function:: post
|
||||
|
||||
| :sl:`place a new event on the queue`
|
||||
| :sg:`post(event, /) -> bool`
|
||||
|
||||
Places the given event at the end of the event queue.
|
||||
|
||||
This is usually used for placing custom events on the event queue.
|
||||
Any type of event can be posted, and the events posted can have any attributes.
|
||||
|
||||
When this event is received on the event queue, it will be a shallow copy of
|
||||
the event object posted by this function; the dict attribute of both events
|
||||
will be a reference to the same dict object in memory. Modifications on one
|
||||
dict can affect another, use deepcopy operations on the dict object if you
|
||||
don't want this behaviour.
|
||||
|
||||
This returns a boolean on whether the event was posted or not. Blocked events
|
||||
cannot be posted, and this function returns ``False`` if you try to post them.
|
||||
|
||||
.. versionchangedold:: 2.0.1 returns a boolean, previously returned ``None``
|
||||
|
||||
.. ## pygame.event.post ##
|
||||
|
||||
.. function:: custom_type
|
||||
|
||||
| :sl:`make custom user event type`
|
||||
| :sg:`custom_type() -> int`
|
||||
|
||||
Reserves an event slot for use in a custom event ``userevent`` and returns the integer that the event slot is reserved to.
|
||||
|
||||
If too many events are made a :exc:`pygame.error` is raised.
|
||||
|
||||
.. versionaddedold:: 2.0.0.dev3
|
||||
|
||||
.. ## pygame.event.custom_type ##
|
||||
|
||||
.. class:: Event
|
||||
|
||||
| :sl:`pygame object for representing events`
|
||||
| :sg:`Event(type, dict) -> Event`
|
||||
| :sg:`Event(type, \**attributes) -> Event`
|
||||
|
||||
A pygame object used for representing an event. ``Event`` instances
|
||||
support attribute assignment and deletion.
|
||||
|
||||
When creating the object, the attributes may come from a dictionary
|
||||
argument with string keys or from keyword arguments.
|
||||
|
||||
.. versionchanged:: 2.1.4 This class is also available through the ``pygame.Event``
|
||||
alias.
|
||||
|
||||
.. note::
|
||||
From version 2.1.3 ``EventType`` is an alias for ``Event``. Beforehand,
|
||||
``Event`` was a function that returned ``EventType`` instances. Use of
|
||||
``Event`` is preferred over ``EventType`` wherever it is possible, as
|
||||
the latter could be deprecated in a future version.
|
||||
|
||||
.. attribute:: type
|
||||
|
||||
| :sl:`event type identifier.`
|
||||
| :sg:`type -> int`
|
||||
|
||||
Read-only. The event type identifier. For user created event
|
||||
objects, this is the ``type`` argument passed to
|
||||
:class:`pygame.event.Event()`.
|
||||
|
||||
For example, some predefined event identifiers are ``QUIT`` and
|
||||
``MOUSEMOTION``.
|
||||
|
||||
.. ## pygame.event.Event.type ##
|
||||
|
||||
.. attribute:: __dict__
|
||||
|
||||
| :sl:`event attribute dictionary`
|
||||
| :sg:`__dict__ -> dict`
|
||||
|
||||
Read-only. The event type specific attributes of an event. The
|
||||
``dict`` attribute is a synonym for backward compatibility.
|
||||
|
||||
For example, the attributes of a ``KEYDOWN`` event would be ``unicode``,
|
||||
``key``, and ``mod``
|
||||
|
||||
.. ## pygame.event.Event.__dict__ ##
|
||||
|
||||
.. versionaddedold:: 1.9.2 Mutable attributes.
|
||||
|
||||
.. ## pygame.event.Event ##
|
||||
|
||||
.. ## pygame.event ##
|
||||