code stringlengths 1 1.72M | language stringclasses 1 value |
|---|---|
#!/usr/bin/env python
'''
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import os
import shutil
import sys
# Bump pyglet/__init__.py version as well.
VERSION = '1.2alpha1'
long_description = '''pyglet provides an object-oriented programming
interface for developing games and other visually-rich applications
for Windows, Mac OS X and Linux.'''
setup_info = dict(
# Metadata
name='pyglet',
version=VERSION,
author='Alex Holkner',
author_email='Alex.Holkner@gmail.com',
url='http://www.pyglet.org/',
download_url='http://pypi.python.org/pypi/pyglet',
description='Cross-platform windowing and multimedia library',
long_description=long_description,
license='BSD',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: MacOS X',
'Environment :: Win32 (MS Windows)',
'Environment :: X11 Applications',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows', # XP
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Topic :: Games/Entertainment',
'Topic :: Software Development :: Libraries :: Python Modules',
],
# Package info
packages=[
'pyglet',
'pyglet.app',
'pyglet.canvas',
'pyglet.font',
'pyglet.gl',
'pyglet.graphics',
'pyglet.image',
'pyglet.image.codecs',
'pyglet.input',
'pyglet.libs',
'pyglet.libs.darwin',
'pyglet.libs.darwin.cocoapy',
'pyglet.libs.win32',
'pyglet.libs.x11',
'pyglet.media',
'pyglet.media.drivers',
'pyglet.media.drivers.directsound',
'pyglet.media.drivers.openal',
'pyglet.media.drivers.pulse',
'pyglet.text',
'pyglet.text.formats',
'pyglet.window',
'pyglet.window.carbon',
'pyglet.window.cocoa',
'pyglet.window.win32',
'pyglet.window.xlib',
],
)
setuptools_info = dict(
zip_safe=True,
)
if 'bdist_egg' in sys.argv or 'develop' in sys.argv:
from setuptools import setup
_have_setuptools = True
# Don't walk SVN tree for default manifest
from setuptools.command import egg_info
from setuptools.command import sdist
egg_info.walk_revctrl = lambda: []
sdist.walk_revctrl = lambda: []
# Insert additional command-line arguments into install_lib when
# bdist_egg calls it, to compile byte-code with optimizations.
# This is a dirty hack.
from setuptools.command import bdist_egg
old_call_command = bdist_egg.bdist_egg.call_command
def call_command(self, *args, **kwargs):
if args[0] == 'install_lib':
kwargs['optimize'] = 2
kwargs['compile'] = False
cmd = old_call_command(self, *args, **kwargs)
return cmd
bdist_egg.bdist_egg.call_command = call_command
elif 'bdist_mpkg' in sys.argv:
from setuptools import setup
_have_setuptools = True
from bdist_mpkg_pyglet import plists, pkg, cmd_bdist_mpkg, tools
# Check for ctypes if installing into Python 2.4
def ctypes_requirement(pkgname, prefix):
prefix = os.path.join(prefix, 'ctypes')
title = '%s requires ctypes 1.0 or later to install with Python 2.4' \
% pkgname
kw = dict(
LabelKey='ctypes',
TitleKey=title,
MessageKey=title,
)
return plists.path_requirement(prefix, **kw)
# Subclass bdist_mpkg
class pyglet_bdist_mpkg(cmd_bdist_mpkg.bdist_mpkg):
# Don't include platform or python version in mpkg name (aesthetics)
def finalize_package_data(self):
cmd_bdist_mpkg.bdist_mpkg.finalize_package_data(self)
self.metapackagename = '-'.join([self.get_name(),
self.get_version()]) + '.mpkg'
self.pseudoinstall_root = self.get_pseudoinstall_root()
self.packagesdir = os.path.join(
self.get_metapackage(),
self.component_directory
)
def get_metapackage_info(self):
info = dict(cmd_bdist_mpkg.bdist_mpkg.get_metapackage_info(self))
info.update(dict(
# Set background image alignment
IFPkgFlagBackgroundScaling='none',
IFPkgFlagBackgroundAlignment='topleft',
# Remove specific Python version requirement from metapackage,
# is per-package now.
IFRequirementDicts=[],
))
return info
# Override how packages are made. purelib forces creation of a
# separate package for each required python version, all symlinked to
# the same Archive.bom.
def make_scheme_package(self, scheme):
assert scheme == 'purelib'
# Make AVbin package
pkgname = 'AVbin'
pkgfile = pkgname + '.pkg'
self.packages.append((pkgfile, self.get_scheme_status(scheme)))
pkgdir = os.path.join(self.packagesdir, pkgfile)
self.mkpath(pkgdir)
version = self.get_scheme_version(scheme)
info = dict(self.get_scheme_info(scheme))
description = 'AVbin audio and video support (recommended)'
files = list(tools.walk_files('build/avbin'))
common = 'build/avbin'
prefix = '/usr/local/lib'
pkg.make_package(self,
pkgname, version,
files, common, prefix,
pkgdir,
info, description)
# pyglet packages
files, common, prefix = self.get_scheme_root(scheme)
def add_package(python_dir, package_dir,
pyver, pkgname, description):
scheme_prefix = package_dir
pkgfile = pkgname + '.pkg'
self.packages.append((pkgfile, self.get_scheme_status(scheme)))
pkgdir = os.path.join(self.packagesdir, pkgfile)
self.mkpath(pkgdir)
version = self.get_scheme_version(scheme)
requirements = [
plists.python_requirement(self.get_name(),
prefix=python_dir,
version=pyver)]
if pyver == '2.4':
requirements.append(ctypes_requirement(self.get_name(),
prefix=scheme_prefix))
info = dict(self.get_scheme_info(scheme))
info.update(dict(
IFRequirementDicts=requirements,
))
pkg.make_package(self,
pkgname, version,
files, common, scheme_prefix,
pkgdir,
info,
description,
)
# Move the archive up to the metapackage and symlink to it
pkgfile = os.path.join(pkgdir, 'Contents/Archive.pax.gz')
shutil.move(pkgfile,
os.path.join(pkgdir, '../../Archive.pax.gz'))
os.symlink('../../../Archive.pax.gz', pkgfile)
pkgfile = os.path.join(pkgdir, 'Contents/Archive.bom')
shutil.move(pkgfile,
os.path.join(pkgdir, '../../Archive.bom'))
os.symlink('../../../Archive.bom', pkgfile)
self.scheme_hook(scheme, pkgname, version, files, common,
prefix, pkgdir)
add_package(
'/System/Library/Frameworks/Python.framework/Versions/2.5',
'/Library/Python/2.5/site-packages',
'2.5', 'pyglet-syspy2.5',
'pyglet for Python 2.5 in /System/Library')
add_package(
'/System/Library/Frameworks/Python.framework/Versions/2.6',
'/Library/Python/2.6/site-packages',
'2.6', 'pyglet-syspy2.6',
'pyglet for Python 2.6 in /System/Library')
add_package(
'/Library/Frameworks/Python.framework/Versions/2.4',
'/Library/Frameworks/Python.framework/Versions/2.4' \
'/lib/python2.4/site-packages',
'2.4', 'pyglet-py2.4',
'pyglet for Python 2.4 in /Library')
add_package(
'/Library/Frameworks/Python.framework/Versions/2.5',
'/Library/Frameworks/Python.framework/Versions/2.5' \
'/lib/python2.5/site-packages',
'2.5', 'pyglet-py2.5',
'pyglet for Python 2.5 in /Library')
add_package(
'/Library/Frameworks/Python.framework/Versions/2.6',
'/Library/Frameworks/Python.framework/Versions/2.6' \
'/lib/python2.6/site-packages',
'2.6', 'pyglet-py2.6',
'pyglet for Python 2.6 in /Library')
add_package(
'/opt/local/',
'/opt/local/lib/python2.4/site-packages',
'2.4', 'pyglet-macports-py2.4',
'pyglet for MacPorts Python 2.4 in /opt/local')
add_package(
'/opt/local/',
'/opt/local/lib/python2.5/site-packages',
'2.5', 'pyglet-macports-py2.5',
'pyglet for MacPorts Python 2.5 in /opt/local')
add_package(
'/opt/local/',
'/opt/local/Library/Frameworks/Python.framework/Versions/2.6' \
'/lib/python2.6/site-packages',
'2.6', 'pyglet-macports-py2.6',
'pyglet for MacPorts Python 2.6 in /opt/local')
# Don't build to an absolute path, assume within site-packages (makes
# it easier to symlink the same archive for all packages)
def get_scheme_install_prefix(self, scheme):
return scheme
# Don't byte compile (waste of space, try to do it in postflight TODO).
def byte_compile(self):
pass
setuptools_info.update(dict(
cmdclass={'bdist_mpkg': pyglet_bdist_mpkg,}
))
else:
from distutils.core import setup
_have_setuptools = False
if _have_setuptools:
# Additional dict values for setuptools
setup_info.update(setuptools_info)
install_requires = []
if sys.version_info < (2, 5, 0):
install_requires.append('ctypes')
setup_info.update(dict(
install_requires=install_requires,
))
if sys.version_info >= (3,):
# Automatically run 2to3 when using Python 3
if _have_setuptools:
setup_info["use_2to3"] = True
else:
from distutils.command.build_py import build_py_2to3
setup_info["cmdclass"] = {"build_py" : build_py_2to3}
setup(**setup_info)
| Python |
#!/usr/bin/python
# $Id:$
import os
import sys
import unittest
from pyglet.gl import *
from pyglet import image
from pyglet import resource
from pyglet import window
__noninteractive = True
# Test image is laid out
# M R
# B G
# In this test the image is sampled at four points from top-right clockwise:
# R G B M (red, green, blue, magenta)
class TestCase(unittest.TestCase):
def setUp(self):
self.w = window.Window(width=10, height=10)
self.w.dispatch_events()
resource.path.append('@' + __name__)
resource.reindex()
def tearDown(self):
self.w.close()
def check(self, img, colors):
glClear(GL_COLOR_BUFFER_BIT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
img.blit(img.anchor_x, img.anchor_y)
buffer = image.get_buffer_manager().get_color_buffer().get_image_data()
bytes = buffer.get_data('RGBA', buffer.width * 4)
def sample(x, y):
i = y * buffer.pitch + x * len(buffer.format)
r, g, b, _ = bytes[i:i+len(buffer.format)]
if type(r) is str:
r, g, b = map(ord, (r, g, b))
return {
(255, 0, 0): 'r',
(0, 255, 0): 'g',
(0, 0, 255): 'b',
(255, 0, 255): 'm'}.get((r, g, b), 'x')
samples = ''.join([
sample(3, 3), sample(3, 0), sample(0, 0), sample(0, 3)])
self.assertTrue(samples == colors, samples)
def test0(self):
self.check(resource.image('rgbm.png'), 'rgbm')
def test2(self):
self.check(resource.image('rgbm.png', flip_x=True), 'mbgr')
def test3(self):
self.check(resource.image('rgbm.png', flip_y=True), 'grmb')
def test4(self):
self.check(resource.image('rgbm.png', flip_x=True, flip_y=True), 'bmrg')
def test5(self):
self.check(resource.image('rgbm.png', rotate=90), 'mrgb')
def test5a(self):
self.check(resource.image('rgbm.png', rotate=-270), 'mrgb')
def test6(self):
self.check(resource.image('rgbm.png', rotate=180), 'bmrg')
def test6a(self):
self.check(resource.image('rgbm.png', rotate=-180), 'bmrg')
def test7(self):
self.check(resource.image('rgbm.png', rotate=270), 'gbmr')
def test7a(self):
self.check(resource.image('rgbm.png', rotate=-90), 'gbmr')
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/python
# $Id:$
import os
import sys
import unittest
from pyglet.gl import *
from pyglet import image
from pyglet import resource
from pyglet import window
__noninteractive = True
# Test image is laid out
# M R
# B G
# In this test the image is sampled at four points from top-right clockwise:
# R G B M (red, green, blue, magenta)
class TestCase(unittest.TestCase):
def setUp(self):
self.w = window.Window(width=10, height=10)
self.w.dispatch_events()
resource.path.append('@' + __name__)
resource.reindex()
def tearDown(self):
self.w.close()
def check(self, img, colors):
glClear(GL_COLOR_BUFFER_BIT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
img.blit(img.anchor_x, img.anchor_y)
buffer = image.get_buffer_manager().get_color_buffer().get_image_data()
bytes = buffer.get_data('RGBA', buffer.width * 4)
def sample(x, y):
i = y * buffer.pitch + x * len(buffer.format)
r, g, b, _ = bytes[i:i+len(buffer.format)]
if type(r) is str:
r, g, b = map(ord, (r, g, b))
return {
(255, 0, 0): 'r',
(0, 255, 0): 'g',
(0, 0, 255): 'b',
(255, 0, 255): 'm'}.get((r, g, b), 'x')
samples = ''.join([
sample(3, 3), sample(3, 0), sample(0, 0), sample(0, 3)])
self.assertTrue(samples == colors, samples)
def test0(self):
self.check(resource.image('rgbm.png'), 'rgbm')
def test2(self):
self.check(resource.image('rgbm.png', flip_x=True), 'mbgr')
def test3(self):
self.check(resource.image('rgbm.png', flip_y=True), 'grmb')
def test4(self):
self.check(resource.image('rgbm.png', flip_x=True, flip_y=True), 'bmrg')
def test5(self):
self.check(resource.image('rgbm.png', rotate=90), 'mrgb')
def test5a(self):
self.check(resource.image('rgbm.png', rotate=-270), 'mrgb')
def test6(self):
self.check(resource.image('rgbm.png', rotate=180), 'bmrg')
def test6a(self):
self.check(resource.image('rgbm.png', rotate=-180), 'bmrg')
def test7(self):
self.check(resource.image('rgbm.png', rotate=270), 'gbmr')
def test7a(self):
self.check(resource.image('rgbm.png', rotate=-90), 'gbmr')
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
__noninteractive = True
'''
Layout:
. (script home)
file.txt F1
dir1/
file.txt F2
dir1/
file.txt F3
res.zip/
file.txt F7
dir1/
file.txt F8
dir1/
file.txt F9
dir2/
file.txt F6
'''
import os
import sys
import unittest
from pyglet import resource
from pyglet.compat import asbytes
class TestCase(unittest.TestCase):
def setUp(self):
self.script_home = os.path.dirname(__file__)
def check(self, path, result):
self.check_file(path, 'file.txt', result)
def check_file(self, path, file, result):
loader = resource.Loader(path, script_home=self.script_home)
self.assertTrue(loader.file(file).read() == asbytes('%s\n' % result))
def checkFail(self, path):
loader = resource.Loader(path, script_home=self.script_home)
self.assertRaises(resource.ResourceNotFoundException,
loader.file, 'file.txt')
def test1(self):
self.check(None, 'F1')
def test2(self):
self.check('', 'F1')
def test2a(self):
self.check('.', 'F1')
def test2b(self):
self.checkFail(())
def test2c(self):
self.checkFail('foo')
def test2d(self):
self.checkFail(['foo'])
def test2e(self):
self.check(['foo', '.'], 'F1')
def test3(self):
self.check(['.', 'dir1'], 'F1')
def test4(self):
self.check(['dir1'], 'F2')
def test5(self):
self.check(['dir1', '.'], 'F2')
def test6(self):
self.check(['dir1/dir1'], 'F3')
def test7(self):
self.check(['dir1', 'dir1/dir1'], 'F2')
def test8(self):
self.check(['dir1/dir1', 'dir1'], 'F3')
def test9(self):
self.check('dir1/res.zip', 'F7')
def test9a(self):
self.check('dir1/res.zip/', 'F7')
def test10(self):
self.check('dir1/res.zip/dir1', 'F8')
def test10a(self):
self.check('dir1/res.zip/dir1/', 'F8')
def test11(self):
self.check(['dir1/res.zip/dir1', 'dir1/res.zip'], 'F8')
def test12(self):
self.check(['dir1/res.zip', 'dir1/res.zip/dir1'], 'F7')
def test12a(self):
self.check(['dir1/res.zip', 'dir1/res.zip/dir1/dir1'], 'F7')
def test12b(self):
self.check(['dir1/res.zip/dir1/dir1/', 'dir1/res.zip/dir1'], 'F9')
def test12c(self):
self.check(['dir1/res.zip/dir1/dir1', 'dir1/res.zip/dir1'], 'F9')
def test13(self):
self.check(['dir1', 'dir2'], 'F2')
def test14(self):
self.check(['dir2', 'dir1'], 'F6')
# path tests
def test15(self):
self.check_file([''], 'dir1/file.txt', 'F2')
def test15a(self):
self.check_file([''], 'dir1/dir1/file.txt', 'F3')
def test15b(self):
self.check_file(['dir1'], 'dir1/file.txt', 'F3')
def test15c(self):
self.check_file([''], 'dir2/file.txt', 'F6')
def test15d(self):
self.check_file(['.'], 'dir2/file.txt', 'F6')
# zip path tests
def test16(self):
self.check_file(['dir1/res.zip'], 'dir1/file.txt', 'F8')
def test16a(self):
self.check_file(['dir1/res.zip/'], 'dir1/file.txt', 'F8')
def test16a(self):
self.check_file(['dir1/res.zip/'], 'dir1/dir1/file.txt', 'F9')
def test16b(self):
self.check_file(['dir1/res.zip/dir1'], 'dir1/file.txt', 'F9')
def test16c(self):
self.check_file(['dir1/res.zip/dir1/'], 'dir1/file.txt', 'F9')
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
__noninteractive = True
'''
Layout:
. (script home)
file.txt F1
dir1/
file.txt F2
dir1/
file.txt F3
res.zip/
file.txt F7
dir1/
file.txt F8
dir1/
file.txt F9
dir2/
file.txt F6
'''
import os
import sys
import unittest
from pyglet import resource
from pyglet.compat import asbytes
class TestCase(unittest.TestCase):
def setUp(self):
self.script_home = os.path.dirname(__file__)
def check(self, path, result):
self.check_file(path, 'file.txt', result)
def check_file(self, path, file, result):
loader = resource.Loader(path, script_home=self.script_home)
self.assertTrue(loader.file(file).read() == asbytes('%s\n' % result))
def checkFail(self, path):
loader = resource.Loader(path, script_home=self.script_home)
self.assertRaises(resource.ResourceNotFoundException,
loader.file, 'file.txt')
def test1(self):
self.check(None, 'F1')
def test2(self):
self.check('', 'F1')
def test2a(self):
self.check('.', 'F1')
def test2b(self):
self.checkFail(())
def test2c(self):
self.checkFail('foo')
def test2d(self):
self.checkFail(['foo'])
def test2e(self):
self.check(['foo', '.'], 'F1')
def test3(self):
self.check(['.', 'dir1'], 'F1')
def test4(self):
self.check(['dir1'], 'F2')
def test5(self):
self.check(['dir1', '.'], 'F2')
def test6(self):
self.check(['dir1/dir1'], 'F3')
def test7(self):
self.check(['dir1', 'dir1/dir1'], 'F2')
def test8(self):
self.check(['dir1/dir1', 'dir1'], 'F3')
def test9(self):
self.check('dir1/res.zip', 'F7')
def test9a(self):
self.check('dir1/res.zip/', 'F7')
def test10(self):
self.check('dir1/res.zip/dir1', 'F8')
def test10a(self):
self.check('dir1/res.zip/dir1/', 'F8')
def test11(self):
self.check(['dir1/res.zip/dir1', 'dir1/res.zip'], 'F8')
def test12(self):
self.check(['dir1/res.zip', 'dir1/res.zip/dir1'], 'F7')
def test12a(self):
self.check(['dir1/res.zip', 'dir1/res.zip/dir1/dir1'], 'F7')
def test12b(self):
self.check(['dir1/res.zip/dir1/dir1/', 'dir1/res.zip/dir1'], 'F9')
def test12c(self):
self.check(['dir1/res.zip/dir1/dir1', 'dir1/res.zip/dir1'], 'F9')
def test13(self):
self.check(['dir1', 'dir2'], 'F2')
def test14(self):
self.check(['dir2', 'dir1'], 'F6')
# path tests
def test15(self):
self.check_file([''], 'dir1/file.txt', 'F2')
def test15a(self):
self.check_file([''], 'dir1/dir1/file.txt', 'F3')
def test15b(self):
self.check_file(['dir1'], 'dir1/file.txt', 'F3')
def test15c(self):
self.check_file([''], 'dir2/file.txt', 'F6')
def test15d(self):
self.check_file(['.'], 'dir2/file.txt', 'F6')
# zip path tests
def test16(self):
self.check_file(['dir1/res.zip'], 'dir1/file.txt', 'F8')
def test16a(self):
self.check_file(['dir1/res.zip/'], 'dir1/file.txt', 'F8')
def test16a(self):
self.check_file(['dir1/res.zip/'], 'dir1/dir1/file.txt', 'F9')
def test16b(self):
self.check_file(['dir1/res.zip/dir1'], 'dir1/file.txt', 'F9')
def test16c(self):
self.check_file(['dir1/res.zip/dir1/'], 'dir1/file.txt', 'F9')
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that rendering of bullet glyphs works.
You should see 5 bullet glyphs rendered in the bottom-left of the window.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import font
import base_text
class TEST_HALIGN(base_text.TextTestBase):
font_name = ''
font_size = 60
text = u'\u2022'*5
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that text will not wrap when its width is set to its calculated
width.
You should be able to clearly see "TEST TEST" on a single line (not two)
and "SPAM SPAM SPAM" over two lines, not three.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import base_text
from pyglet import font
class TEST_WRAP_INVARIANT(base_text.TextTestBase):
font_name = ''
text = 'TEST TEST'
def render(self):
fnt = font.load('', 16)
self.label1 = font.Text(fnt, 'TEST TEST', 10, 150)
self.label1.width = self.label1.width
self.label2 = font.Text(fnt, 'SPAM SPAM\nSPAM', 10, 50)
self.label2.width = self.label2.width
def draw(self):
self.label1.draw()
self.label2.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a font likely to be installed on the computer can be
loaded and displayed correctly.
One window will open, it should show "Quickly brown fox" at 24pt using:
* "Helvetica" on Mac OS X
* "Arial" on Windows
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import sys
import base_text
if sys.platform == 'darwin':
font_name = 'Helvetica'
elif sys.platform in ('win32', 'cygwin'):
font_name = 'Arial'
else:
font_name = 'Arial'
class TEST_SYSTEM(base_text.TextTestBase):
font_name = font_name
font_size = 24
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Base class for text tests.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import sys
from pyglet.gl import *
from pyglet import font
from pyglet.window import *
from pyglet.window.event import *
from tests.regression import ImageRegressionTestCase
class TextTestBase(ImageRegressionTestCase):
font_name = ''
font_size = 24
text = 'Quickly brown fox'
window_size = 200, 200
def on_expose(self):
glClearColor(0.5, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
self.draw()
self.window.flip()
if self.capture_regression_image():
self.window.exit_handler.has_exit = True
def render(self):
fnt = font.load(self.font_name, self.font_size)
self.label = font.Text(fnt, self.text, 10, 10)
def draw(self):
self.label.draw()
def test_main(self):
width, height = self.window_size
self.window = w = Window(width, height, visible=False, resizable=True)
w.push_handlers(self)
self.render()
w.set_visible()
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font.Text alignment works with multiple lines.
Three labels will be rendered at the top-left, center and bottom-right of the
window. Resize the window to ensure the alignment is as specified.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import font
import base_text
class TEST_ALIGN_MULTILINE(base_text.TextTestBase):
font_name = ''
window_size = 400, 500
def render(self):
fnt = font.load(self.font_name, self.font_size)
w = self.window.width
h = self.window.height
self.labels = [
font.Text(fnt,
'This text is top-left aligned with several lines.',
0, h, width=w,
halign='left', valign='top'),
font.Text(fnt,
'This text is centered in the middle.',
0, h//2, width=w,
halign='center', valign='center'),
font.Text(fnt,
'This text is aligned to the bottom-right of the window.',
0, 0, width=w,
halign='right', valign='bottom'),
]
def on_resize(self, width, height):
for label in self.labels:
label.width = width
self.labels[0].y = height
self.labels[1].y = height // 2
def draw(self):
for label in self.labels:
label.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that text will not wrap when its width is set to its calculated
width.
You should be able to clearly see "TEST TEST" on a single line (not two)
and "SPAM SPAM SPAM" over two lines, not three.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import base_text
from pyglet import font
class TEST_WRAP_INVARIANT(base_text.TextTestBase):
font_name = ''
text = 'TEST TEST'
def render(self):
fnt = font.load('', 24)
self.label1 = font.Text(fnt, 'TEST TEST', 10, 150)
self.label1.width = self.label1.width + 1
self.label2 = font.Text(fnt, 'SPAM SPAM\nSPAM', 10, 50)
self.label2.width = self.label2.width + 1
def draw(self):
self.label1.draw()
self.label2.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that the horizontal font metrics are calculated correctly.
Some text in various fonts will be displayed. Green vertical lines mark
the left edge of the text. Blue vertical lines mark the right edge of the
text.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import os
import unittest
from pyglet.gl import *
from pyglet import font
import base_text
base_path = os.path.dirname(__file__)
class TEST_HORIZONTAL_METRICS(base_text.TextTestBase):
window_size = 400, 250
def render(self):
font.add_file(os.path.join(base_path, 'action_man.ttf'))
fnt1 = font.load('Action Man', 16)
fnt2 = font.load('Arial', 16)
fnt3 = font.load('Times New Roman', 16)
h = fnt3.ascent - fnt3.descent + 10
self.texts = [
font.Text(fnt1, 'Action Man', 10, h * 1),
font.Text(fnt1, 'Action Man longer test with more words', 10, h*2),
font.Text(fnt2, 'Arial', 10, h * 3),
font.Text(fnt2, 'Arial longer test with more words', 10, h*4),
font.Text(fnt3, 'Times New Roman', 10, h * 5),
font.Text(fnt3, 'Times New Roman longer test with more words',
10, h*6),
]
def draw(self):
glPushAttrib(GL_CURRENT_BIT)
for text in self.texts:
text.draw()
glBegin(GL_LINES)
glColor3f(0, 1, 0)
glVertex2f(text.x, text.y + text.font.descent)
glVertex2f(text.x, text.y + text.font.ascent)
glColor3f(0, 0, 1)
glVertex2f(text.x + text.width, text.y + text.font.descent)
glVertex2f(text.x + text.width, text.y + text.font.ascent)
glEnd()
glPopAttrib()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font colour is applied correctly. Default font should
appear blue.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
import base_text
from pyglet import font
class TEST_COLOR(base_text.TextTestBase):
def render(self):
fnt = font.load(self.font_name, self.font_size)
self.label = font.Text(fnt, self.text, 10, 10, color=(0, 0, 1, 1))
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that text will not wrap when its width is set to its calculated
width.
You should be able to clearly see "TEST TEST" on a single line (not two)
and "SPAM SPAM SPAM" over two lines, not three.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import base_text
from pyglet import font
class TEST_WRAP_INVARIANT(base_text.TextTestBase):
font_name = ''
text = 'TEST TEST'
def render(self):
fnt = font.load('', 24)
self.label1 = font.Text(fnt, 'TEST TEST', 10, 150)
self.label1.width = self.label1.width + 1
self.label2 = font.Text(fnt, 'SPAM SPAM\nSPAM', 10, 50)
self.label2.width = self.label2.width + 1
def draw(self):
self.label1.draw()
self.label2.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that the horizontal font metrics are calculated correctly.
Some text in various fonts will be displayed. Green vertical lines mark
the left edge of the text. Blue vertical lines mark the right edge of the
text.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import os
import unittest
from pyglet.gl import *
from pyglet import font
import base_text
base_path = os.path.dirname(__file__)
class TEST_HORIZONTAL_METRICS(base_text.TextTestBase):
window_size = 400, 250
def render(self):
font.add_file(os.path.join(base_path, 'action_man.ttf'))
fnt1 = font.load('Action Man', 16)
fnt2 = font.load('Arial', 16)
fnt3 = font.load('Times New Roman', 16)
h = fnt3.ascent - fnt3.descent + 10
self.texts = [
font.Text(fnt1, 'Action Man', 10, h * 1),
font.Text(fnt1, 'Action Man longer test with more words', 10, h*2),
font.Text(fnt2, 'Arial', 10, h * 3),
font.Text(fnt2, 'Arial longer test with more words', 10, h*4),
font.Text(fnt3, 'Times New Roman', 10, h * 5),
font.Text(fnt3, 'Times New Roman longer test with more words',
10, h*6),
]
def draw(self):
glPushAttrib(GL_CURRENT_BIT)
for text in self.texts:
text.draw()
glBegin(GL_LINES)
glColor3f(0, 1, 0)
glVertex2f(text.x, text.y + text.font.descent)
glVertex2f(text.x, text.y + text.font.ascent)
glColor3f(0, 0, 1)
glVertex2f(text.x + text.width, text.y + text.font.descent)
glVertex2f(text.x + text.width, text.y + text.font.ascent)
glEnd()
glPopAttrib()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a font distributed with the application can be displayed.
Four lines of text should be displayed, each in a different variant
(bold/italic/regular) of Action Man at 24pt. The Action Man fonts are
included in the test directory (tests/font) as action_man*.ttf.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import os
import unittest
from pyglet import font
import base_text
base_path = os.path.dirname(__file__)
class TEST_ADD_FONT(base_text.TextTestBase):
font_name = 'Action Man'
def render(self):
font.add_file(os.path.join(base_path, 'action_man.ttf'))
font.add_file(os.path.join(base_path, 'action_man_bold.ttf'))
font.add_file(os.path.join(base_path, 'action_man_italic.ttf'))
font.add_file(os.path.join(base_path, 'action_man_bold_italic.ttf'))
fnt = font.load('Action Man', self.font_size)
fnt_b = font.load('Action Man', self.font_size, bold=True)
fnt_i = font.load('Action Man', self.font_size, italic=True)
fnt_bi = font.load('Action Man', self.font_size, bold=True, italic=True)
h = fnt.ascent - fnt.descent
self.labels = [
font.Text(fnt, 'Action Man', 10, 10 + 3 * h),
font.Text(fnt_i, 'Action Man Italic', 10, 10 + 2 * h),
font.Text(fnt_b, 'Action Man Bold', 10, 10 + h),
font.Text(fnt_bi, 'Action Man Bold Italic', 10, 10)
]
def draw(self):
for label in self.labels:
label.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a specific DPI can be set to render the text with.
Some text in Action Man font will be displayed. A green box should exactly
bound the top and bottom of the text.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import os
import unittest
from pyglet.gl import *
from pyglet import font
import base_text
base_path = os.path.dirname(__file__)
class TEST_ADD_FONT(base_text.TextTestBase):
font_name = 'Action Man'
def render(self):
font.add_file(os.path.join(base_path, 'action_man.ttf'))
# Hard-code 16-pt at 100 DPI, and hard-code the pixel coordinates
# we see that font at when DPI-specified rendering is correct.
fnt = font.load('Action Man', 16, dpi=120)
self.text = font.Text(fnt, 'The DPI is 120', 10, 10)
def draw(self):
self.text.draw()
x1 = self.text.x
x2 = self.text.x + self.text.width
y1 = 9
y2 = 27
glPushAttrib(GL_CURRENT_BIT)
glColor3f(0, 1, 0)
glBegin(GL_LINE_LOOP)
glVertex2f(x1, y1)
glVertex2f(x2, y1)
glVertex2f(x2, y2)
glVertex2f(x1, y2)
glEnd()
glPopAttrib()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font.Text horizontal alignment works.
Three labels will be rendered aligned left, center and right.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import font
import base_text
class TEST_HALIGN(base_text.TextTestBase):
font_name = ''
def render(self):
fnt = font.load('', self.font_size)
h = fnt.ascent - fnt.descent
w = self.window.width
self.labels = [
font.Text(fnt, 'LEFT', 0, 10 + 3 * h, width=w, halign='left'),
font.Text(fnt, 'CENTER', 0, 10 + 2 * h, width=w, halign='center'),
font.Text(fnt, 'RIGHT', 0, 10 + h, width=w, halign='right'),
]
def on_resize(self, width, height):
for label in self.labels:
label.width = width
def draw(self):
for label in self.labels:
label.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font.Text vertical alignment works.
Four labels will be aligned top, center, baseline and bottom.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import gl
from pyglet import font
import base_text
class TEST_VALIGN(base_text.TextTestBase):
font_name = ''
window_size = 600, 200
def render(self):
fnt = font.load('', self.font_size)
h = fnt.ascent - fnt.descent
w = self.window.width
self.labels = []
x = 0
for align in 'top center baseline bottom'.split():
label = align.upper() + 'y'
self.labels.append(font.Text(fnt, label, x, 50, valign=align))
x += self.labels[-1].width
def draw(self):
gl.glColor3f(1, 1, 1)
gl.glBegin(gl.GL_LINES)
gl.glVertex2f(0, 50)
gl.glVertex2f(self.window.width, 50)
gl.glEnd()
for label in self.labels:
label.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font colour is applied correctly. Default font should
appear blue.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
import base_text
from pyglet import font
class TEST_COLOR(base_text.TextTestBase):
def render(self):
fnt = font.load(self.font_name, self.font_size)
self.label = font.Text(fnt, self.text, 10, 10, color=(0, 0, 1, 1))
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that rendering of bullet glyphs works.
You should see 5 bullet glyphs rendered in the bottom-left of the window.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import font
import base_text
class TEST_HALIGN(base_text.TextTestBase):
font_name = ''
font_size = 60
text = u'\u2022'*5
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Base class for text tests.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import sys
from pyglet.gl import *
from pyglet import font
from pyglet.window import *
from pyglet.window.event import *
from tests.regression import ImageRegressionTestCase
class TextTestBase(ImageRegressionTestCase):
font_name = ''
font_size = 24
text = 'Quickly brown fox'
window_size = 200, 200
def on_expose(self):
glClearColor(0.5, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
self.draw()
self.window.flip()
if self.capture_regression_image():
self.window.exit_handler.has_exit = True
def render(self):
fnt = font.load(self.font_name, self.font_size)
self.label = font.Text(fnt, self.text, 10, 10)
def draw(self):
self.label.draw()
def test_main(self):
width, height = self.window_size
self.window = w = Window(width, height, visible=False, resizable=True)
w.push_handlers(self)
self.render()
w.set_visible()
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that text will not wrap when its width is set to its calculated
width.
You should be able to clearly see "TEST TEST" on a single line (not two)
and "SPAM SPAM SPAM" over two lines, not three.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import base_text
from pyglet import font
class TEST_WRAP_INVARIANT(base_text.TextTestBase):
font_name = ''
text = 'TEST TEST'
def render(self):
fnt = font.load('', 16)
self.label1 = font.Text(fnt, 'TEST TEST', 10, 150)
self.label1.width = self.label1.width
self.label2 = font.Text(fnt, 'SPAM SPAM\nSPAM', 10, 50)
self.label2.width = self.label2.width
def draw(self):
self.label1.draw()
self.label2.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a font with no name given still renders using some sort
of default system font.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import base_text
class TEST_DEFAULT(base_text.TextTestBase):
font_name = ''
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font colour is applied correctly. Default font should
appear at 0.1 opacity (faint white)
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
import base_text
from pyglet import font
class TEST_COLOR_BLEND(base_text.TextTestBase):
def render(self):
fnt = font.load(self.font_name, self.font_size)
self.label = font.Text(fnt, self.text, 10, 10, color=(1, 1, 1, 0.1))
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a font likely to be installed on the computer can be
loaded and displayed correctly.
One window will open, it should show "Quickly brown fox" at 24pt using:
* "Helvetica" on Mac OS X
* "Arial" on Windows
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import sys
import base_text
if sys.platform == 'darwin':
font_name = 'Helvetica'
elif sys.platform in ('win32', 'cygwin'):
font_name = 'Arial'
else:
font_name = 'Arial'
class TEST_SYSTEM(base_text.TextTestBase):
font_name = font_name
font_size = 24
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font.Text alignment works with multiple lines.
Three labels will be rendered at the top-left, center and bottom-right of the
window. Resize the window to ensure the alignment is as specified.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import font
import base_text
class TEST_ALIGN_MULTILINE(base_text.TextTestBase):
font_name = ''
window_size = 400, 500
def render(self):
fnt = font.load(self.font_name, self.font_size)
w = self.window.width
h = self.window.height
self.labels = [
font.Text(fnt,
'This text is top-left aligned with several lines.',
0, h, width=w,
halign='left', valign='top'),
font.Text(fnt,
'This text is centered in the middle.',
0, h//2, width=w,
halign='center', valign='center'),
font.Text(fnt,
'This text is aligned to the bottom-right of the window.',
0, 0, width=w,
halign='right', valign='bottom'),
]
def on_resize(self, width, height):
for label in self.labels:
label.width = width
self.labels[0].y = height
self.labels[1].y = height // 2
def draw(self):
for label in self.labels:
label.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a font with no name given still renders using some sort
of default system font.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import base_text
class TEST_DEFAULT(base_text.TextTestBase):
font_name = ''
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font.Text vertical alignment works.
Four labels will be aligned top, center, baseline and bottom.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import gl
from pyglet import font
import base_text
class TEST_VALIGN(base_text.TextTestBase):
font_name = ''
window_size = 600, 200
def render(self):
fnt = font.load('', self.font_size)
h = fnt.ascent - fnt.descent
w = self.window.width
self.labels = []
x = 0
for align in 'top center baseline bottom'.split():
label = align.upper() + 'y'
self.labels.append(font.Text(fnt, label, x, 50, valign=align))
x += self.labels[-1].width
def draw(self):
gl.glColor3f(1, 1, 1)
gl.glBegin(gl.GL_LINES)
gl.glVertex2f(0, 50)
gl.glVertex2f(self.window.width, 50)
gl.glEnd()
for label in self.labels:
label.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a specific DPI can be set to render the text with.
Some text in Action Man font will be displayed. A green box should exactly
bound the top and bottom of the text.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import os
import unittest
from pyglet.gl import *
from pyglet import font
import base_text
base_path = os.path.dirname(__file__)
class TEST_ADD_FONT(base_text.TextTestBase):
font_name = 'Action Man'
def render(self):
font.add_file(os.path.join(base_path, 'action_man.ttf'))
# Hard-code 16-pt at 100 DPI, and hard-code the pixel coordinates
# we see that font at when DPI-specified rendering is correct.
fnt = font.load('Action Man', 16, dpi=120)
self.text = font.Text(fnt, 'The DPI is 120', 10, 10)
def draw(self):
self.text.draw()
x1 = self.text.x
x2 = self.text.x + self.text.width
y1 = 9
y2 = 27
glPushAttrib(GL_CURRENT_BIT)
glColor3f(0, 1, 0)
glBegin(GL_LINE_LOOP)
glVertex2f(x1, y1)
glVertex2f(x2, y1)
glVertex2f(x2, y2)
glVertex2f(x1, y2)
glEnd()
glPopAttrib()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font colour is applied correctly. Default font should
appear at 0.1 opacity (faint white)
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
import base_text
from pyglet import font
class TEST_COLOR_BLEND(base_text.TextTestBase):
def render(self):
fnt = font.load(self.font_name, self.font_size)
self.label = font.Text(fnt, self.text, 10, 10, color=(1, 1, 1, 0.1))
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that font.Text horizontal alignment works.
Three labels will be rendered aligned left, center and right.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import font
import base_text
class TEST_HALIGN(base_text.TextTestBase):
font_name = ''
def render(self):
fnt = font.load('', self.font_size)
h = fnt.ascent - fnt.descent
w = self.window.width
self.labels = [
font.Text(fnt, 'LEFT', 0, 10 + 3 * h, width=w, halign='left'),
font.Text(fnt, 'CENTER', 0, 10 + 2 * h, width=w, halign='center'),
font.Text(fnt, 'RIGHT', 0, 10 + h, width=w, halign='right'),
]
def on_resize(self, width, height):
for label in self.labels:
label.width = width
def draw(self):
for label in self.labels:
label.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a font distributed with the application can be displayed.
Four lines of text should be displayed, each in a different variant
(bold/italic/regular) of Action Man at 24pt. The Action Man fonts are
included in the test directory (tests/font) as action_man*.ttf.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import os
import unittest
from pyglet import font
import base_text
base_path = os.path.dirname(__file__)
class TEST_ADD_FONT(base_text.TextTestBase):
font_name = 'Action Man'
def render(self):
font.add_file(os.path.join(base_path, 'action_man.ttf'))
font.add_file(os.path.join(base_path, 'action_man_bold.ttf'))
font.add_file(os.path.join(base_path, 'action_man_italic.ttf'))
font.add_file(os.path.join(base_path, 'action_man_bold_italic.ttf'))
fnt = font.load('Action Man', self.font_size)
fnt_b = font.load('Action Man', self.font_size, bold=True)
fnt_i = font.load('Action Man', self.font_size, italic=True)
fnt_bi = font.load('Action Man', self.font_size, bold=True, italic=True)
h = fnt.ascent - fnt.descent
self.labels = [
font.Text(fnt, 'Action Man', 10, 10 + 3 * h),
font.Text(fnt_i, 'Action Man Italic', 10, 10 + 2 * h),
font.Text(fnt_b, 'Action Man Bold', 10, 10 + h),
font.Text(fnt_bi, 'Action Man Bold Italic', 10, 10)
]
def draw(self):
for label in self.labels:
label.draw()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/python
'''Test that the event loop can do timing.
The test will display a series of intervals, iterations and sleep times.
It should then display an incrementing number up to 2x the number of
iterations, at a rate determined by the interval.
'''
import sys
import unittest
import pyglet
__noninteractive = True
if sys.platform in ('win32', 'cygwin'):
from time import clock as time
else:
from time import time
from time import sleep
class EVENT_LOOP(unittest.TestCase):
def t_scheduled(self, interval, iterations, sleep_time=0):
print 'Test interval=%s, iterations=%s, sleep=%s' % (interval,
iterations, sleep_time)
warmup_iterations = iterations
self.last_t = 0.
self.timer_count = 0
def f(dt):
sys.stdout.write('%s\r' % self.timer_count)
sys.stdout.flush()
t = time()
self.timer_count += 1
tc = self.timer_count
if tc > warmup_iterations:
self.assertAlmostEqual(dt, interval, places=2)
self.assertAlmostEqual(t - self.last_t, interval, places=2)
self.last_t = t
if self.timer_count > iterations + warmup_iterations:
pyglet.app.exit()
if sleep_time:
sleep(sleep_time)
pyglet.clock.schedule_interval(f, interval)
try:
pyglet.app.run()
finally:
pyglet.clock.unschedule(f)
print
def test_1_5(self):
self.t_scheduled(1, 5, 0)
def test_1_5_d5(self):
self.t_scheduled(1, 5, 0.5)
def test_d1_50(self):
self.t_scheduled(.1, 50)
def test_d1_50_d05(self):
self.t_scheduled(.1, 50, 0.05)
def test_d05_50(self):
self.t_scheduled(.05, 50)
def test_d05_50_d03(self):
self.t_scheduled(.05, 50, 0.03)
def test_d02_50(self):
self.t_scheduled(.02, 50)
def test_d01_50(self):
self.t_scheduled(.01, 50)
if __name__ == '__main__':
if pyglet.version != '1.2dev':
print 'Wrong version of pyglet imported; please check your PYTHONPATH'
else:
unittest.main()
| Python |
#!/usr/bin/python
'''Test that the event loop can do timing.
The test will display a series of intervals, iterations and sleep times.
It should then display an incrementing number up to 2x the number of
iterations, at a rate determined by the interval.
'''
import sys
import unittest
import pyglet
__noninteractive = True
if sys.platform in ('win32', 'cygwin'):
from time import clock as time
else:
from time import time
from time import sleep
class EVENT_LOOP(unittest.TestCase):
def t_scheduled(self, interval, iterations, sleep_time=0):
print 'Test interval=%s, iterations=%s, sleep=%s' % (interval,
iterations, sleep_time)
warmup_iterations = iterations
self.last_t = 0.
self.timer_count = 0
def f(dt):
sys.stdout.write('%s\r' % self.timer_count)
sys.stdout.flush()
t = time()
self.timer_count += 1
tc = self.timer_count
if tc > warmup_iterations:
self.assertAlmostEqual(dt, interval, places=2)
self.assertAlmostEqual(t - self.last_t, interval, places=2)
self.last_t = t
if self.timer_count > iterations + warmup_iterations:
pyglet.app.exit()
if sleep_time:
sleep(sleep_time)
pyglet.clock.schedule_interval(f, interval)
try:
pyglet.app.run()
finally:
pyglet.clock.unschedule(f)
print
def test_1_5(self):
self.t_scheduled(1, 5, 0)
def test_1_5_d5(self):
self.t_scheduled(1, 5, 0.5)
def test_d1_50(self):
self.t_scheduled(.1, 50)
def test_d1_50_d05(self):
self.t_scheduled(.1, 50, 0.05)
def test_d05_50(self):
self.t_scheduled(.05, 50)
def test_d05_50_d03(self):
self.t_scheduled(.05, 50, 0.03)
def test_d02_50(self):
self.t_scheduled(.02, 50)
def test_d01_50(self):
self.t_scheduled(.01, 50)
if __name__ == '__main__':
if pyglet.version != '1.2dev':
print 'Wrong version of pyglet imported; please check your PYTHONPATH'
else:
unittest.main()
| Python |
#!/usr/bin/env python
'''
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
from pyglet.image import get_buffer_manager
class ImageRegressionTestCase(unittest.TestCase):
_enable_regression_image = False
_enable_interactive = True
_captured_image = None
def capture_regression_image(self):
if not self._enable_regression_image:
return False
self._captured_image = \
get_buffer_manager().get_color_buffer().image_data
return not self._enable_interactive
| Python |
#!/usr/bin/env python
'''
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
from pyglet.image import get_buffer_manager
class ImageRegressionTestCase(unittest.TestCase):
_enable_regression_image = False
_enable_interactive = True
_captured_image = None
def capture_regression_image(self):
if not self._enable_regression_image:
return False
self._captured_image = \
get_buffer_manager().get_color_buffer().image_data
return not self._enable_interactive
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear a tone at 440Hz (A above middle C) for 1.0 seconds. The test
will exit immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source1 = procedural.Sine(0.5)
source2 = procedural.Sine(0.5)
player = media.Player()
player.queue(source1)
player.queue(source2)
player.play()
while player.source:
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.5 seconds. The test will exit
immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
player = media.Player()
player.pause()
player.queue(source)
while player.source:
player.dispatch_events()
player.play()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.5 seconds. The test will exit
immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
player = media.Player()
player.queue(source)
player.play()
while player.source:
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.5 seconds. The test will exit
immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
player = media.Player()
player.play()
player.queue(source)
while player.source:
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.5 seconds. The test will exit
immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
player = media.Player()
player.pause()
player.queue(source)
while player.source:
player.dispatch_events()
player.play()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.25 seconds, then a 0.5 second pause
then another 0.25 seconds of noise. The test will exit immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
import time
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
player = media.Player()
player.queue(source)
player.play()
start_time = time.time()
stage = 0
while player.source:
if stage == 0 and time.time() - start_time > 0.25:
player.pause()
stage = 1
if stage == 1 and time.time() - start_time > 0.75:
player.play()
stage = 2
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.5 seconds. The test will exit
immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
source = media.StaticSource(source)
source = media.StaticSource(source)
player = media.Player()
player.queue(source)
player.play()
while player.source:
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.5 seconds. The test will exit
immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
player = media.Player()
player.queue(source)
player.play()
while player.source:
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear a tone at 440Hz (A above middle C) for 1.0 seconds. The test
will exit immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source1 = procedural.Sine(0.5)
source2 = procedural.Sine(0.5)
player = media.Player()
player.queue(source1)
player.queue(source2)
player.play()
while player.source:
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.5 seconds. The test will exit
immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
player = media.Player()
player.play()
player.queue(source)
while player.source:
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.5 seconds. The test will exit
immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
source = media.StaticSource(source)
source = media.StaticSource(source)
player = media.Player()
player.queue(source)
player.play()
while player.source:
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that audio playback works.
You should hear white noise (static) for 0.25 seconds, then a 0.5 second pause
then another 0.25 seconds of noise. The test will exit immediately after.
You may want to turn down the volume of your speakers.
'''
import unittest
import time
from pyglet import media
from pyglet.media import procedural
class TEST_CASE(unittest.TestCase):
def test_method(self):
source = procedural.WhiteNoise(0.5)
player = media.Player()
player.queue(source)
player.play()
start_time = time.time()
stage = 0
while player.source:
if stage == 0 and time.time() - start_time > 0.25:
player.pause()
stage = 1
if stage == 1 and time.time() - start_time > 0.75:
player.play()
stage = 2
player.dispatch_events()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window size can be set.
Expected behaviour:
One window will be opened. The window's dimensions will be printed
to the terminal.
- press "x" to increase the width
- press "X" to decrease the width
- press "y" to increase the height
- press "Y" to decrease the height
You should see a green border inside the window but no red.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
import window_util
class WINDOW_SET_SIZE(unittest.TestCase):
def on_key_press(self, symbol, modifiers):
delta = 20
if modifiers & key.MOD_SHIFT:
delta = -delta
if symbol == key.X:
self.width += delta
elif symbol == key.Y:
self.height += delta
self.w.set_size(self.width, self.height)
print 'Window size set to %dx%d.' % (self.width, self.height)
def test_set_size(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height, resizable=True)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
window_util.draw_client_border(w)
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that exclusive mouse mode can be set.
Expected behaviour:
One window will be opened. Press 'e' to enable exclusive mode and 'E'
to disable exclusive mode.
In exclusive mode:
- the mouse cursor should be invisible
- moving the mouse should generate events with bogus x,y but correct
dx and dy.
- it should not be possible to switch applications with the mouse
- if application loses focus (i.e., with keyboard), the mouse should
operate normally again until focus is returned to the app, in which
case it should hide again.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
class WINDOW_SET_EXCLUSIVE_MOUSE(unittest.TestCase):
def on_key_press(self, symbol, modifiers):
if symbol == key.E:
exclusive = not (modifiers & key.MOD_SHIFT)
self.w.set_exclusive_mouse(exclusive)
print 'Exclusive mouse is now %r' % exclusive
def on_mouse_motion(self, x, y, dx, dy):
print 'on_mousemotion(x=%f, y=%f, dx=%f, dy=%f)' % (x, y, dx, dy)
def test_set_exclusive_mouse(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window style can be dialog.
Expected behaviour:
One dialog-styled window will be opened.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import window
from pyglet.window import key
class TEST_WINDOW_STYLE_DIALOG(unittest.TestCase):
def test_style_dialog(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height,
style=window.Window.WINDOW_STYLE_DIALOG)
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/python
# $Id:$
import unittest
from pyglet import window
import base_event_sequence
__noninteractive = True
class TEST_CLASS(base_event_sequence.BaseEventSequence):
last_sequence = 3
def on_resize(self, width, height):
self.check_sequence(1, 'on_resize')
def on_show(self):
self.check_sequence(2, 'on_show')
def on_expose(self):
self.check_sequence(3, 'on_expose')
def test_method(self):
win = window.Window(visible=False)
win.dispatch_events()
win.push_handlers(self)
win.set_visible(True)
self.check_sequence(0, 'begin')
while not win.has_exit and not self.finished:
win.dispatch_events()
self.check_timeout()
win.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that screens can be selected for fullscreen.
Expected behaviour:
One window will be created fullscreen on the primary screen. When you
close this window, another will open on the next screen, and so
on until all screens have been tested.
Each screen will be filled with a different color:
- Screen 0: Red
- Screen 1: Green
- Screen 2: Blue
- Screen 3: Purple
The test will end when all screens have been tested.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.gl import *
colours = [
(1, 0, 0, 1),
(0, 1, 0, 1),
(0, 0, 1, 1),
(1, 0, 1, 1)]
class MULTIPLE_SCREEN(unittest.TestCase):
def open_next_window(self):
screen = self.screens[self.index]
self.w = window.Window(screen=screen, fullscreen=True)
def on_expose(self):
self.w.switch_to()
glClearColor(*colours[self.index])
glClear(GL_COLOR_BUFFER_BIT)
self.w.flip()
def test_multiple_screen(self):
display = window.get_platform().get_default_display()
self.screens = display.get_screens()
for i in range(len(self.screens)):
self.index = i
self.open_next_window()
self.on_expose()
while not self.w.has_exit:
self.w.dispatch_events()
self.w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that minimum and maximum window size can be set.
Expected behaviour:
One window will be opened. The window's dimensions will be printed
to the terminal. Initially the window has no minimum or maximum
size (besides any OS-enforced limit).
- press "n" to set the minimum size to be the current size.
- press "x" to set the maximum size to be the current size.
You should see a green border inside the window but no red.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
import window_util
class WINDOW_SET_MIN_MAX_SIZE(unittest.TestCase):
def on_resize(self, width, height):
print 'Window size is %dx%d.' % (width, height)
self.width, self.height = width, height
def on_key_press(self, symbol, modifiers):
if symbol == key.N:
self.w.set_minimum_size(self.width, self.height)
print 'Minimum size set to %dx%d.' % (self.width, self.height)
elif symbol == key.X:
self.w.set_maximum_size(self.width, self.height)
print 'Maximum size set to %dx%d.' % (self.width, self.height)
def test_min_max_size(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height, resizable=True)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
window_util.draw_client_border(w)
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
# $Id: $
import unittest
from pyglet import window
import base_event_sequence
__noninteractive = True
class TEST_CLASS(base_event_sequence.BaseEventSequence):
last_sequence = 2
def on_resize(self, width, height):
self.check_sequence(1, 'on_resize')
def on_expose(self):
self.check_sequence(2, 'on_expose')
def test_method(self):
win = window.Window()
win.dispatch_events()
win.push_handlers(self)
win.set_fullscreen()
self.check_sequence(0, 'begin')
while not win.has_exit and not self.finished:
win.dispatch_events()
self.check_timeout()
win.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window icon can be set for multiple sizes.
Expected behaviour:
One window will be opened. The window's icon depends on the icon
size:
16x16 icon is a yellow "1"
32x32 icon is a purple "2"
48x48 icon is a cyan "3"
72x72 icon is a red "4"
128x128 icon is a blue "5"
For other sizes, the operating system may select the closest match and
scale it (Linux, Windows), or interpolate between two or more images
(Mac OS X).
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import image
from pyglet import window
from pyglet.window import key
import window_util
from os.path import join, dirname
icon_file1 = join(dirname(__file__), 'icon_size1.png')
icon_file2 = join(dirname(__file__), 'icon_size2.png')
icon_file3 = join(dirname(__file__), 'icon_size3.png')
icon_file4 = join(dirname(__file__), 'icon_size4.png')
icon_file5 = join(dirname(__file__), 'icon_size5.png')
class WINDOW_SET_ICON_SIZES(unittest.TestCase):
def test_set_icon_sizes(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height)
w.set_icon(image.load(icon_file1),
image.load(icon_file2),
image.load(icon_file3),
image.load(icon_file4),
image.load(icon_file5))
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
# $Id: $
import unittest
from pyglet import window
import base_event_sequence
__noninteractive = True
class TEST_CLASS(base_event_sequence.BaseEventSequence):
last_sequence = 3
def on_resize(self, width, height):
self.check_sequence(1, 'on_resize')
def on_show(self):
self.check_sequence(2, 'on_show')
def on_expose(self):
self.check_sequence(3, 'on_expose')
def test_method(self):
win = window.Window(fullscreen=True)
win.push_handlers(self)
self.check_sequence(0, 'begin')
while not win.has_exit and not self.finished:
win.dispatch_events()
self.check_timeout()
win.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that mouse drag event works correctly.
Expected behaviour:
One window will be opened. Click and drag with the mouse and ensure
that buttons, coordinates and modifiers are reported correctly. Events
should be generated even when the drag leaves the window.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
from pyglet import window
from pyglet.window.event import WindowEventLogger
class EVENT_MOUSE_DRAG(unittest.TestCase):
def test_mouse_drag(self):
w = window.Window(200, 200)
w.push_handlers(WindowEventLogger())
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that the window can be hidden and shown.
Expected behaviour:
One window will be opened. Every 5 seconds it will toggle between
hidden and shown.
Press escape or close the window to finish the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import time
import unittest
from pyglet import window
from pyglet.window.event import WindowEventLogger
class WINDOW_SET_VISIBLE(unittest.TestCase):
def test_set_visible(self):
w = window.Window(200, 200)
w.push_handlers(WindowEventLogger())
last_time = time.time()
visible = True
while not w.has_exit:
if time.time() - last_time > 5:
visible = not visible
w.set_visible(visible)
last_time = time.time()
print 'Set visibility to %r.' % visible
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a window can be opened.
Expected behaviour:
One small window will be opened coloured purple.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
from pyglet import window
from pyglet.gl import *
class WINDOW_OPEN(unittest.TestCase):
def open_window(self):
return window.Window(200, 200)
def draw_window(self, window, colour):
window.switch_to()
glClearColor(*colour)
glClear(GL_COLOR_BUFFER_BIT)
window.flip()
def test_open_window(self):
w1 = self.open_window()
while not w1.has_exit:
self.draw_window(w1, (1, 0, 1, 1))
w1.dispatch_events()
w1.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that close event works correctly.
Expected behaviour:
One window will be opened. Click the close button and ensure the
event is printed to the terminal. The window should not close
when you do this.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet import event
w = None
class EVENT_CLOSE(unittest.TestCase):
def on_close(self):
print 'Window close event.'
return event.EVENT_HANDLED
def on_key_press(self, symbol, mods):
if symbol == window.key.ESCAPE:
global w
super(window.Window, w).on_close()
def test_close(self):
global w
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window expose event works correctly.
Expected behaviour:
One window will be opened. Uncovering the window from other windows
or the edge of the screen should produce the expose event.
Note that on OS X and other compositing window managers this event
is equivalent to EVENT_SHOW.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
class EVENT_EXPOSE(unittest.TestCase):
def on_expose(self):
print 'Window exposed.'
def test_expose(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window location can be set.
Expected behaviour:
One window will be opened. The window's location will be printed
to the terminal.
- Use the arrow keys to move the window.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
class WINDOW_SET_SIZE(unittest.TestCase):
def on_key_press(self, symbol, modifiers):
x, y = self.w.get_location()
if symbol == key.LEFT:
x -= 10
if symbol == key.RIGHT:
x += 10
if symbol == key.UP:
y -= 10
if symbol == key.DOWN:
y += 10
self.w.set_location(x, y)
print 'Window location set to %dx%d.' % (x, y)
def test_set_size(self):
self.w = w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window style can be borderless.
Expected behaviour:
One borderless window will be opened.
Mouse click in the window to close it and end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import window
from pyglet.window import key
class WINDOW_TEST_STYLE_BORDERLESS(unittest.TestCase):
def test_style_borderless(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height,
style=window.Window.WINDOW_STYLE_BORDERLESS)
@w.event
def on_mouse_press(*args): w.has_exit = True
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that mouse scroll event works correctly.
Expected behaviour:
One window will be opened. Move the scroll wheel and check that events
are printed to console. Positive values are associated with scrolling
up.
Scrolling can also be side-to-side, for example with an Apple Mighty
Mouse.
The actual scroll value is dependent on your operating system
user preferences.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
class EVENT_MOUSE_SCROLL(unittest.TestCase):
def on_mouse_scroll(self, x, y, dx, dy):
print 'Mouse scrolled (%f, %f) (x=%f, y=%f)' % (dx, dy, x, y)
def test_mouse_scroll(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
# $Id: $
import unittest
from pyglet import window
import base_event_sequence
__noninteractive = True
class TEST_CLASS(base_event_sequence.BaseEventSequence):
last_sequence = 3
def on_resize(self, width, height):
self.check_sequence(1, 'on_resize')
def on_show(self):
self.check_sequence(2, 'on_show')
def on_expose(self):
self.check_sequence(3, 'on_expose')
def test_method(self):
win = window.Window()
win.push_handlers(self)
self.check_sequence(0, 'begin')
while not win.has_exit and not self.finished:
win.dispatch_events()
self.check_timeout()
win.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window.event import WindowEventLogger
from pyglet.window import key
from pyglet.gl import *
import window_util
class WINDOW_SET_FULLSCREEN(unittest.TestCase):
def on_text(self, text):
text = text[:1]
i = ord(text) - ord('a')
if 0 <= i < len(self.modes):
print 'Switching to %s' % self.modes[i]
self.w.screen.set_mode(self.modes[i])
def on_expose(self):
glClearColor(1, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)
window_util.draw_client_border(self.w)
self.w.flip()
def test_set_fullscreen(self):
self.w = w = window.Window(200, 200)
self.modes = w.screen.get_modes()
print 'Press a letter to switch to the corresponding mode:'
for i, mode in enumerate(self.modes):
print '%s: %s' % (chr(i + ord('a')), mode)
w.push_handlers(self)
#w.push_handlers(WindowEventLogger())
self.on_expose()
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that mouse button events work correctly.
Expected behaviour:
One window will be opened. Click within this window and check the console
output for mouse events.
- Buttons 1, 2, 4 correspond to left, middle, right, respectively.
- No events for scroll wheel
- Modifiers are correct
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
class EVENT_BUTTON(unittest.TestCase):
def on_mouse_press(self, x, y, button, modifiers):
print 'Mouse button %d pressed at %f,%f with %s' % \
(button, x, y, key.modifiers_string(modifiers))
def on_mouse_release(self, x, y, button, modifiers):
print 'Mouse button %d released at %f,%f with %s' % \
(button, x, y, key.modifiers_string(modifiers))
def test_button(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window style can be borderless.
Expected behaviour:
One borderless window will be opened.
Mouse click in the window to close it and end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import window
from pyglet.window import key
class WINDOW_TEST_STYLE_BORDERLESS(unittest.TestCase):
def test_style_borderless(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height,
style=window.Window.WINDOW_STYLE_BORDERLESS)
@w.event
def on_mouse_press(*args): w.has_exit = True
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that close event works correctly.
Expected behaviour:
One window will be opened. Click the close button and ensure the
event is printed to the terminal. The window should not close
when you do this.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet import event
w = None
class EVENT_CLOSE(unittest.TestCase):
def on_close(self):
print 'Window close event.'
return event.EVENT_HANDLED
def on_key_press(self, symbol, mods):
if symbol == window.key.ESCAPE:
global w
super(window.Window, w).on_close()
def test_close(self):
global w
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window can be resized.
Expected behaviour:
One window will be opened. It should be resizable by the user.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import window
from pyglet.window import key
import window_util
class WINDOW_RESIZABLE(unittest.TestCase):
def test_resizable(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height, resizable=True)
glClearColor(1, 1, 1, 1)
while not w.has_exit:
w.dispatch_events()
window_util.draw_client_border(w)
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window icon can be set for multiple sizes.
Expected behaviour:
One window will be opened. The window's icon depends on the icon
size:
16x16 icon is a yellow "1"
32x32 icon is a purple "2"
48x48 icon is a cyan "3"
72x72 icon is a red "4"
128x128 icon is a blue "5"
For other sizes, the operating system may select the closest match and
scale it (Linux, Windows), or interpolate between two or more images
(Mac OS X).
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import image
from pyglet import window
from pyglet.window import key
import window_util
from os.path import join, dirname
icon_file1 = join(dirname(__file__), 'icon_size1.png')
icon_file2 = join(dirname(__file__), 'icon_size2.png')
icon_file3 = join(dirname(__file__), 'icon_size3.png')
icon_file4 = join(dirname(__file__), 'icon_size4.png')
icon_file5 = join(dirname(__file__), 'icon_size5.png')
class WINDOW_SET_ICON_SIZES(unittest.TestCase):
def test_set_icon_sizes(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height)
w.set_icon(image.load(icon_file1),
image.load(icon_file2),
image.load(icon_file3),
image.load(icon_file4),
image.load(icon_file5))
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that the window can be activated (focus set).
Expected behaviour:
One window will be opened. Every 5 seconds it will be activated;
it should be come to the front and accept keyboard input (this will
be shown on the terminal).
On Windows XP, the taskbar icon may flash (indicating the application
requires attention) rather than moving the window to the foreground. This
is the correct behaviour.
Press escape or close the window to finished the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import time
import unittest
from pyglet import window
from pyglet.window.event import WindowEventLogger
class WINDOW_ACTVATE(unittest.TestCase):
def test_activate(self):
w = window.Window(200, 200)
w.push_handlers(WindowEventLogger())
last_time = time.time()
while not w.has_exit:
if time.time() - last_time > 5:
w.activate()
last_time = time.time()
print 'Activated window.'
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a window can be opened fullscreen.
Expected behaviour:
A fullscreen window will be created, with a flat purple colour.
- Press 'g' to leave fullscreen mode and create a window.
- Press 'f' to re-enter fullscreen mode.
- All events will be printed to the console. Ensure that mouse,
keyboard and activation/deactivation events are all correct.
Close either window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
import pyglet.window
from pyglet import window
from pyglet.window.event import WindowEventLogger
from pyglet.window import key
from pyglet.gl import *
class WINDOW_INITIAL_FULLSCREEN(unittest.TestCase):
def on_key_press(self, symbol, modifiers):
if symbol == key.F:
print 'Setting fullscreen.'
self.w.set_fullscreen(True)
elif symbol == key.G:
print 'Leaving fullscreen.'
self.w.set_fullscreen(False)
def on_expose(self):
glClearColor(1, 0, 1, 1)
glClear(GL_COLOR_BUFFER_BIT)
self.w.flip()
def test_initial_fullscreen(self):
self.w = window.Window(fullscreen=True)
self.w.push_handlers(self)
self.w.push_handlers(WindowEventLogger())
self.on_expose()
while not self.w.has_exit:
self.w.dispatch_events()
self.w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that screens can be selected for fullscreen.
Expected behaviour:
One window will be created fullscreen on the primary screen. When you
close this window, another will open on the next screen, and so
on until all screens have been tested.
Each screen will be filled with a different color:
- Screen 0: Red
- Screen 1: Green
- Screen 2: Blue
- Screen 3: Purple
The test will end when all screens have been tested.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.gl import *
colours = [
(1, 0, 0, 1),
(0, 1, 0, 1),
(0, 0, 1, 1),
(1, 0, 1, 1)]
class MULTIPLE_SCREEN(unittest.TestCase):
def open_next_window(self):
screen = self.screens[self.index]
self.w = window.Window(screen=screen, fullscreen=True)
def on_expose(self):
self.w.switch_to()
glClearColor(*colours[self.index])
glClear(GL_COLOR_BUFFER_BIT)
self.w.flip()
def test_multiple_screen(self):
display = window.get_platform().get_default_display()
self.screens = display.get_screens()
for i in range(len(self.screens)):
self.index = i
self.open_next_window()
self.on_expose()
while not self.w.has_exit:
self.w.dispatch_events()
self.w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a window can be opened.
Expected behaviour:
One small window will be opened coloured purple.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
from pyglet import window
from pyglet.gl import *
class WINDOW_OPEN(unittest.TestCase):
def open_window(self):
return window.Window(200, 200)
def draw_window(self, window, colour):
window.switch_to()
glClearColor(*colour)
glClear(GL_COLOR_BUFFER_BIT)
window.flip()
def test_open_window(self):
w1 = self.open_window()
while not w1.has_exit:
self.draw_window(w1, (1, 0, 1, 1))
w1.dispatch_events()
w1.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that image mouse cursor can be set.
Expected behaviour:
One window will be opened. The mouse cursor in the window will be
a custom cursor.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
from pyglet.gl import *
from pyglet import image
from pyglet import window
from os.path import join, dirname
cursor_file = join(dirname(__file__), 'cursor.png')
class WINDOW_SET_MOUSE_CURSOR(unittest.TestCase):
def on_mouse_motion(self, x, y, dx, dy):
print 'on_mousemotion(x=%f, y=%f, dx=%f, dy=%f)' % (x, y, dx, dy)
def test_set_mouse_cursor(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height)
img = image.load(cursor_file)
w.set_mouse_cursor(window.ImageMouseCursor(img, 4, 28))
w.push_handlers(self)
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window location can be set.
Expected behaviour:
One window will be opened. The window's location will be printed
to the terminal.
- Use the arrow keys to move the window.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
class WINDOW_SET_SIZE(unittest.TestCase):
def on_key_press(self, symbol, modifiers):
x, y = self.w.get_location()
if symbol == key.LEFT:
x -= 10
if symbol == key.RIGHT:
x += 10
if symbol == key.UP:
y -= 10
if symbol == key.DOWN:
y += 10
self.w.set_location(x, y)
print 'Window location set to %dx%d.' % (x, y)
def test_set_size(self):
self.w = w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/python
# $Id:$
from pyglet.gl import *
def draw_client_border(window):
glClearColor(0, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, window.width, 0, window.height, -1, 1)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def rect(x1, y1, x2, y2):
glBegin(GL_LINE_LOOP)
glVertex2f(x1, y1)
glVertex2f(x2, y1)
glVertex2f(x2, y2)
glVertex2f(x1, y2)
glEnd()
glColor3f(1, 0, 0)
rect(-2, -2, window.width + 2, window.height + 2)
glColor3f(0, 1, 0)
rect(1, 1, window.width - 2, window.height - 2)
| Python |
#!/usr/bin/env python
'''Test that vsync can be set.
Expected behaviour:
A window will alternate between red and green fill.
- Press "v" to toggle vsync on/off. "Tearing" should only be visible
when vsync is off (as indicated at the terminal).
Not all video drivers support vsync. On Linux, check the output of
`tools/info.py`:
- If GLX_SGI_video_sync extension is present, should work as expected.
- If GLX_MESA_swap_control extension is present, should work as expected.
- If GLX_SGI_swap_control extension is present, vsync can be enabled,
but once enabled, it cannot be switched off (there will be no error
message).
- If none of these extensions are present, vsync is not supported by
your driver, but no error message or warning will be printed.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import unittest
from pyglet import window
from pyglet.window import key
from pyglet.gl import *
class WINDOW_SET_VSYNC(unittest.TestCase):
colors = [(1, 0, 0, 1), (0, 1, 0, 1)]
color_index = 0
def open_window(self):
return window.Window(200, 200, vsync=False)
def on_key_press(self, symbol, modifiers):
if symbol == key.V:
vsync = not self.w1.vsync
self.w1.set_vsync(vsync)
print 'vsync is %r' % self.w1.vsync
def draw_window(self, window, colour):
window.switch_to()
glClearColor(*colour)
glClear(GL_COLOR_BUFFER_BIT)
window.flip()
def test_open_window(self):
self.w1 = self.open_window()
self.w1.push_handlers(self)
print 'vsync is %r' % self.w1.vsync
while not self.w1.has_exit:
self.color_index = 1 - self.color_index
self.draw_window(self.w1, self.colors[self.color_index])
self.w1.dispatch_events()
self.w1.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that text events work correctly.
Expected behaviour:
One window will be opened. Type into this window and check the console
output for text events.
- Repeated when keys are held down
- Motion events (e.g., arrow keys, HOME/END, etc) are reported
- Select events (motion + SHIFT) are reported
- Non-keyboard text entry is used (e.g., pen or international palette).
- Combining characters do not generate events, but the modified
character is sent.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
class EVENT_KEYPRESS(unittest.TestCase):
def on_text(self, text):
print 'Typed %r' % text
def on_text_motion(self, motion):
print 'Motion %s' % key.motion_string(motion)
def on_text_motion_select(self, motion):
print 'Select %s' % key.motion_string(motion)
def test_text(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
# $Id: $
import unittest
from pyglet import window
import base_event_sequence
__noninteractive = True
class TEST_CLASS(base_event_sequence.BaseEventSequence):
last_sequence = 2
def on_resize(self, width, height):
self.check_sequence(1, 'on_resize')
def on_expose(self):
self.check_sequence(2, 'on_expose')
def test_method(self):
win = window.Window()
win.dispatch_events()
win.push_handlers(self)
win.set_fullscreen()
self.check_sequence(0, 'begin')
while not win.has_exit and not self.finished:
win.dispatch_events()
self.check_timeout()
win.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that exclusive keyboard mode can be set.
Expected behaviour:
One window will be opened. Press 'e' to enable exclusive mode and 'E'
to disable exclusive mode.
In exclusive mode:
- Pressing system keys, the Expose keys, etc., should have no effect
besides displaying as keyboard events.
- On OS X, the Power switch is not disabled (though this is possible
if desired, see source).
- On OS X, the menu bar and dock will disappear during keyboard
exclusive mode.
- On Windows, only Alt+Tab is disabled. A user can still switch away
using Ctrl+Escape, Alt+Escape, the Windows key or Ctrl+Alt+Del.
- Switching to another application (i.e., with the mouse) should make
these keys work normally again until this application regains focus.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
class WINDOW_SET_EXCLUSIVE_KEYBOARD(unittest.TestCase):
def on_key_press(self, symbol, modifiers):
print 'Pressed %s with modifiers %s' % \
(key.symbol_string(symbol), key.modifiers_string(modifiers))
if symbol == key.E:
exclusive = not (modifiers & key.MOD_SHIFT)
self.w.set_exclusive_keyboard(exclusive)
print 'Exclusive keyboard is now %r' % exclusive
def on_key_release(self, symbol, modifiers):
print 'Released %s with modifiers %s' % \
(key.symbol_string(symbol), key.modifiers_string(modifiers))
def test_set_exclusive_keyboard(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window style can be dialog.
Expected behaviour:
One dialog-styled window will be opened.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import window
from pyglet.window import key
class TEST_WINDOW_STYLE_DIALOG(unittest.TestCase):
def test_style_dialog(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height,
style=window.Window.WINDOW_STYLE_DIALOG)
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that resize event works correctly.
Expected behaviour:
One window will be opened. Resize the window and ensure that the
dimensions printed to the terminal are correct. You should see
a green border inside the window but no red.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
import window_util
class EVENT_RESIZE(unittest.TestCase):
def on_resize(self, width, height):
print 'Window resized to %dx%d.' % (width, height)
def test_resize(self):
w = window.Window(200, 200, resizable=True)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
window_util.draw_client_border(w)
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that show and hide events work correctly.
Expected behaviour:
One window will be opened. There should be one shown event printed
initially. Minimizing and restoring the window should produce hidden
and shown events, respectively.
On OS X the events should also be fired when the window is hidden
and shown (using Command+H or the dock context menu).
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
class EVENT_SHOW_HIDE(unittest.TestCase):
def on_show(self):
print 'Window shown.'
def on_hide(self):
print 'Window hidden.'
def test_show_hide(self):
w = window.Window(200, 200, visible=False)
w.push_handlers(self)
w.set_visible()
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that mouse button events work correctly.
Expected behaviour:
One window will be opened. Click within this window and check the console
output for mouse events.
- Buttons 1, 2, 4 correspond to left, middle, right, respectively.
- No events for scroll wheel
- Modifiers are correct
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
class EVENT_BUTTON(unittest.TestCase):
def on_mouse_press(self, x, y, button, modifiers):
print 'Mouse button %d pressed at %f,%f with %s' % \
(button, x, y, key.modifiers_string(modifiers))
def on_mouse_release(self, x, y, button, modifiers):
print 'Mouse button %d released at %f,%f with %s' % \
(button, x, y, key.modifiers_string(modifiers))
def test_button(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window icon can be set.
Expected behaviour:
One window will be opened. It will have an icon depicting a yellow
"A".
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import image
from pyglet import window
from pyglet.window import key
from os.path import join, dirname
icon_file = join(dirname(__file__), 'icon1.png')
class WINDOW_SET_ICON(unittest.TestCase):
def test_set_icon(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height)
w.set_icon(image.load(icon_file))
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that multiple windows can be opened.
Expected behaviour:
Two small windows will be opened, one coloured yellow and the other
purple.
Close either window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.gl import *
class MULTIPLE_WINDOW_OPEN(unittest.TestCase):
def open_window(self):
return window.Window(200, 200)
def draw_window(self, window, colour):
window.switch_to()
glClearColor(*colour)
glClear(GL_COLOR_BUFFER_BIT)
window.flip()
def test_open_window(self):
w1 = self.open_window()
w2 = self.open_window()
while not (w1.has_exit or w2.has_exit):
self.draw_window(w1, (1, 0, 1, 1))
self.draw_window(w2, (1, 1, 0, 1))
w1.dispatch_events()
w2.dispatch_events()
w1.close()
w2.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that key press and release events work correctly.
Expected behaviour:
One window will be opened. Type into this window and check the console
output for key press and release events. Check that the correct
key symbol and modifiers are reported.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
class EVENT_KEYPRESS(unittest.TestCase):
def on_key_press(self, symbol, modifiers):
print 'Pressed %s with modifiers %s' % \
(key.symbol_string(symbol), key.modifiers_string(modifiers))
def on_key_release(self, symbol, modifiers):
print 'Released %s with modifiers %s' % \
(key.symbol_string(symbol), key.modifiers_string(modifiers))
def test_keypress(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window move event works correctly.
Expected behaviour:
One window will be opened. Move the window and ensure that the
location printed to the terminal is correct.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
class EVENT_MOVE(unittest.TestCase):
def on_move(self, x, y):
print 'Window moved to %dx%d.' % (x, y)
def test_move(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that a window can have multisample.
A window will be opened containing two rotating squares. Initially,
there will be no multisampling (the edges will look "jaggy"). Press:
* M to toggle multisampling on/off
* S to increase samples (2, 4, 6, 8, 10, ...)
* Shift+S to decrease samples
Each time sample_buffers or samples is modified, the window will be recreated.
Watch the console for success and failure messages. If the multisample
options are not supported, a "Failure" message will be printed and the window
will be left as-is.
Press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_OPEN.py 750 2007-03-17 01:16:12Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import window
from pyglet import clock
from pyglet.window import key
class WINDOW_MULTISAMPLE(unittest.TestCase):
win = None
width = 640
height = 480
soft_multisample = True
multisample = False
samples = 2
def set_window(self):
oldwindow = self.win
try:
if self.multisample:
print 'Attempting samples=%d...' % self.samples,
config = Config(sample_buffers=1,
samples=self.samples,
double_buffer=True)
else:
print 'Disabling multisample...',
config = Config(double_buffer=True)
self.win = window.Window(self.width, self.height,
vsync=True,
config=config)
self.win.switch_to()
self.win.push_handlers(self.on_key_press)
if self.multisample:
if self.soft_multisample:
glEnable(GL_MULTISAMPLE_ARB)
else:
glDisable(GL_MULTISAMPLE_ARB)
if oldwindow:
oldwindow.close()
print 'Success.'
except window.NoSuchConfigException:
print 'Failed.'
def on_key_press(self, symbol, modifiers):
mod = 1
if modifiers & key.MOD_SHIFT:
mod = -1
if symbol == key.M:
self.multisample = not self.multisample
self.set_window()
if symbol == key.S:
self.samples += 2 * mod
self.samples = max(2, self.samples)
self.set_window()
# Another test: try enabling/disabling GL_MULTISAMPLE_ARB...
# seems to have no effect if samples > 4.
if symbol == key.N:
self.soft_multisample = not self.soft_multisample
if self.soft_multisample:
print 'Enabling GL_MULTISAMPLE_ARB'
glEnable(GL_MULTISAMPLE_ARB)
else:
print 'Disabling GL_MULTISAMPLE_ARB'
glDisable(GL_MULTISAMPLE_ARB)
def render(self):
self.win.switch_to()
size = self.height / 4
glClear(GL_COLOR_BUFFER_BIT)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glLoadIdentity()
glTranslatef(self.width/2, self.height/2, 0)
glRotatef(self.angle, 0, 0, 1)
glColor3f(1, 0, 0)
glBegin(GL_QUADS)
glVertex2f(-size, -size)
glVertex2f(size, -size)
glVertex2f(size, size)
glVertex2f(-size, size)
glEnd()
glRotatef(-self.angle * 2, 0, 0, 1)
glColor4f(0, 1, 0, 0.5)
glBegin(GL_QUADS)
glVertex2f(-size, -size)
glVertex2f(size, -size)
glVertex2f(size, size)
glVertex2f(-size, size)
glEnd()
def test_multisample(self):
self.set_window()
self.angle = 0
clock.set_fps_limit(30)
while not self.win.has_exit:
dt = clock.tick()
self.angle += dt
self.win.dispatch_events()
self.render()
self.win.flip()
self.win.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that window style can be tool.
Expected behaviour:
One tool-styled window will be opened.
Close the window to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: WINDOW_SET_MOUSE_CURSOR.py 717 2007-03-03 07:04:10Z Alex.Holkner $'
import unittest
from pyglet.gl import *
from pyglet import window
class TEST_WINDOW_STYLE_TOOL(unittest.TestCase):
def test_style_tool(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height,
style=window.Window.WINDOW_STYLE_TOOL)
glClearColor(1, 1, 1, 1)
while not w.has_exit:
glClear(GL_COLOR_BUFFER_BIT)
w.dispatch_events()
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
# $Id: $
import unittest
from pyglet import window
import base_event_sequence
__noninteractive = True
class TEST_CLASS(base_event_sequence.BaseEventSequence):
last_sequence = 2
def on_resize(self, width, height):
self.check_sequence(1, 'on_resize')
def on_expose(self):
self.check_sequence(2, 'on_expose')
def test_method(self):
win = window.Window(fullscreen=True)
win.dispatch_events()
win.push_handlers(self)
win.set_fullscreen(False)
self.check_sequence(0, 'begin')
while not win.has_exit and not self.finished:
win.dispatch_events()
self.check_timeout()
win.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that the window caption can be set.
Expected behaviour:
Two windows will be opened, one with the caption "Window caption 1"
counting up every second; the other with a Unicode string including
some non-ASCII characters.
Press escape or close either window to finished the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import time
import unittest
from pyglet import window
class WINDOW_CAPTION(unittest.TestCase):
def test_caption(self):
w1 = window.Window(400, 200, resizable=True)
w2 = window.Window(400, 200, resizable=True)
count = 1
w1.set_caption('Window caption %d' % count)
w2.set_caption(u'\u00bfHabla espa\u00f1ol?')
last_time = time.time()
while not (w1.has_exit or w2.has_exit):
if time.time() - last_time > 1:
count += 1
w1.set_caption('Window caption %d' % count)
last_time = time.time()
w1.dispatch_events()
w2.dispatch_events()
w1.close()
w2.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that the window can be hidden and shown.
Expected behaviour:
One window will be opened. Every 5 seconds it will toggle between
hidden and shown.
Press escape or close the window to finish the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import time
import unittest
from pyglet import window
from pyglet.window.event import WindowEventLogger
class WINDOW_SET_VISIBLE(unittest.TestCase):
def test_set_visible(self):
w = window.Window(200, 200)
w.push_handlers(WindowEventLogger())
last_time = time.time()
visible = True
while not w.has_exit:
if time.time() - last_time > 5:
visible = not visible
w.set_visible(visible)
last_time = time.time()
print 'Set visibility to %r.' % visible
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that mouse scroll event works correctly.
Expected behaviour:
One window will be opened. Move the scroll wheel and check that events
are printed to console. Positive values are associated with scrolling
up.
Scrolling can also be side-to-side, for example with an Apple Mighty
Mouse.
The actual scroll value is dependent on your operating system
user preferences.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
class EVENT_MOUSE_SCROLL(unittest.TestCase):
def on_mouse_scroll(self, x, y, dx, dy):
print 'Mouse scrolled (%f, %f) (x=%f, y=%f)' % (dx, dy, x, y)
def test_mouse_scroll(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that minimum and maximum window size can be set.
Expected behaviour:
One window will be opened. The window's dimensions will be printed
to the terminal. Initially the window has no minimum or maximum
size (besides any OS-enforced limit).
- press "n" to set the minimum size to be the current size.
- press "x" to set the maximum size to be the current size.
You should see a green border inside the window but no red.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
from pyglet.window import key
import window_util
class WINDOW_SET_MIN_MAX_SIZE(unittest.TestCase):
def on_resize(self, width, height):
print 'Window size is %dx%d.' % (width, height)
self.width, self.height = width, height
def on_key_press(self, symbol, modifiers):
if symbol == key.N:
self.w.set_minimum_size(self.width, self.height)
print 'Minimum size set to %dx%d.' % (self.width, self.height)
elif symbol == key.X:
self.w.set_maximum_size(self.width, self.height)
print 'Maximum size set to %dx%d.' % (self.width, self.height)
def test_min_max_size(self):
self.width, self.height = 200, 200
self.w = w = window.Window(self.width, self.height, resizable=True)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
window_util.draw_client_border(w)
w.flip()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
#!/usr/bin/env python
'''Test that mouse enter and leave events work correctly.
Expected behaviour:
One window will be opened. Move the mouse in and out of this window
and ensure the events displayed are correct.
Close the window or press ESC to end the test.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: $'
import unittest
from pyglet import window
class EVENT_MOUSE_ENTER_LEAVE(unittest.TestCase):
def on_mouse_enter(self, x, y):
print 'Entered at %f, %f' % (x, y)
def on_mouse_leave(self, x, y):
print 'Left at %f, %f' % (x, y)
def test_motion(self):
w = window.Window(200, 200)
w.push_handlers(self)
while not w.has_exit:
w.dispatch_events()
w.close()
if __name__ == '__main__':
unittest.main()
| Python |
Subsets and Splits
SQL Console for ajibawa-2023/Python-Code-Large
Provides a useful breakdown of language distribution in the training data, showing which languages have the most samples and helping identify potential imbalances across different language groups.