| 1 |
import pytest |
| 2 |
from tests.base.interactive import InteractiveTestCase |
| 3 |
|
| 4 |
from pyglet import window |
| 5 |
from pyglet.window.event import WindowEventLogger |
| 6 |
from pyglet.window import key |
| 7 |
from pyglet.gl import * |
| 8 |
|
| 9 |
from . import window_util |
| 10 |
|
| 11 |
|
| 12 |
@pytest.mark.requires_user_action |
| 13 |
class WINDOW_SET_FULLSCREEN(InteractiveTestCase): |
| 14 |
"""Test that window can be set to and from various fullscreen sizes. |
| 15 |
|
| 16 |
Expected behaviour: |
| 17 |
One window will be opened. Press a number to switch to the corresponding |
| 18 |
fullscreen size; hold control and press a number to switch back |
| 19 |
to the corresponding window size: |
| 20 |
|
| 21 |
0 - Default size |
| 22 |
1 - 320x200 |
| 23 |
2 - 640x480 |
| 24 |
3 - 800x600 |
| 25 |
4 - 1024x768 |
| 26 |
5 - 1280x800 (widescreen) |
| 27 |
6 - 1280x1024 |
| 28 |
|
| 29 |
In all cases the window bounds will be indicated by a green rectangle |
| 30 |
which should be completely visible. |
| 31 |
|
| 32 |
All events will be printed to the terminal. |
| 33 |
|
| 34 |
Press ESC to end the test. |
| 35 |
""" |
| 36 |
def on_key_press(self, symbol, modifiers): |
| 37 |
fullscreen = not modifiers & key.MOD_CTRL |
| 38 |
doing = fullscreen and 'Setting' or 'Restoring from' |
| 39 |
if symbol == key._0: |
| 40 |
print('%s default size' % doing) |
| 41 |
self.w.set_fullscreen(fullscreen) |
| 42 |
return |
| 43 |
elif symbol == key._1: |
| 44 |
width, height = 320, 200 |
| 45 |
elif symbol == key._2: |
| 46 |
width, height = 640, 480 |
| 47 |
elif symbol == key._3: |
| 48 |
width, height = 800, 600 |
| 49 |
elif symbol == key._4: |
| 50 |
width, height = 1024, 768 |
| 51 |
elif symbol == key._5: |
| 52 |
width, height = 1280, 800 |
| 53 |
elif symbol == key._6: |
| 54 |
width, height = 1280, 1024 |
| 55 |
else: |
| 56 |
return |
| 57 |
print('%s width=%d, height=%d' % (doing, width, height)) |
| 58 |
self.w.set_fullscreen(fullscreen, width=width, height=height) |
| 59 |
|
| 60 |
def on_expose(self): |
| 61 |
glClearColor(1, 0, 0, 1) |
| 62 |
glClear(GL_COLOR_BUFFER_BIT) |
| 63 |
window_util.draw_client_border(self.w) |
| 64 |
self.w.flip() |
| 65 |
|
| 66 |
def test_set_fullscreen(self): |
| 67 |
self.w = w = window.Window(200, 200) |
| 68 |
try: |
| 69 |
w.push_handlers(self) |
| 70 |
w.push_handlers(WindowEventLogger()) |
| 71 |
self.on_expose() |
| 72 |
while not w.has_exit: |
| 73 |
w.dispatch_events() |
| 74 |
finally: |
| 75 |
w.close() |
| 76 |
self.user_verify('Pass test?', take_screenshot=False) |
| 77 |
|
| 78 |
|
| 79 |
@pytest.mark.requires_user_action |
| 80 |
class WINDOW_INITIAL_FULLSCREEN(InteractiveTestCase): |
| 81 |
"""Test that a window can be opened fullscreen. |
| 82 |
|
| 83 |
Expected behaviour: |
| 84 |
A fullscreen window will be created, with a flat purple colour. |
| 85 |
|
| 86 |
- Press 'g' to leave fullscreen mode and create a window. |
| 87 |
- Press 'f' to re-enter fullscreen mode. |
| 88 |
- All events will be printed to the console. Ensure that mouse, |
| 89 |
keyboard and activation/deactivation events are all correct. |
| 90 |
|
| 91 |
Close either window or press ESC to end the test. |
| 92 |
""" |
| 93 |
def on_key_press(self, symbol, modifiers): |
| 94 |
if symbol == key.F: |
| 95 |
print('Setting fullscreen.') |
| 96 |
self.w.set_fullscreen(True) |
| 97 |
elif symbol == key.G: |
| 98 |
print('Leaving fullscreen.') |
| 99 |
self.w.set_fullscreen(False) |
| 100 |
|
| 101 |
def on_expose(self): |
| 102 |
glClearColor(1, 0, 1, 1) |
| 103 |
glClear(GL_COLOR_BUFFER_BIT) |
| 104 |
self.w.flip() |
| 105 |
|
| 106 |
def test_initial_fullscreen(self): |
| 107 |
self.w = window.Window(fullscreen=True) |
| 108 |
try: |
| 109 |
self.w.push_handlers(self) |
| 110 |
self.w.push_handlers(WindowEventLogger()) |
| 111 |
self.on_expose() |
| 112 |
while not self.w.has_exit: |
| 113 |
self.w.dispatch_events() |
| 114 |
finally: |
| 115 |
self.w.close() |
| 116 |
self.user_verify('Pass test?', take_screenshot=False) |
| 117 |
|
| 118 |
|
| 119 |
@pytest.mark.requires_user_validation |
| 120 |
class MULTIPLE_SCREEN(InteractiveTestCase): |
| 121 |
"""Test that screens can be selected for fullscreen. |
| 122 |
|
| 123 |
Expected behaviour: |
| 124 |
One window will be created fullscreen on the primary screen. When you |
| 125 |
close this window, another will open on the next screen, and so |
| 126 |
on until all screens have been tested. |
| 127 |
|
| 128 |
Each screen will be filled with a different color: |
| 129 |
- Screen 0: Red |
| 130 |
- Screen 1: Green |
| 131 |
- Screen 2: Blue |
| 132 |
- Screen 3: Purple |
| 133 |
|
| 134 |
The test will end when all screens have been tested. |
| 135 |
""" |
| 136 |
colours = [ |
| 137 |
(1, 0, 0, 1), |
| 138 |
(0, 1, 0, 1), |
| 139 |
(0, 0, 1, 1), |
| 140 |
(1, 0, 1, 1)] |
| 141 |
colour_names = ('red', 'green', 'blue', 'purple') |
| 142 |
|
| 143 |
def open_next_window(self): |
| 144 |
screen = self.screens[self.index] |
| 145 |
self.w = window.Window(screen=screen, fullscreen=True) |
| 146 |
|
| 147 |
def on_expose(self): |
| 148 |
self.w.switch_to() |
| 149 |
glClearColor(*self.colours[self.index]) |
| 150 |
glClear(GL_COLOR_BUFFER_BIT) |
| 151 |
self.w.flip() |
| 152 |
|
| 153 |
def test_multiple_screen(self): |
| 154 |
display = window.get_platform().get_default_display() |
| 155 |
self.screens = display.get_screens() |
| 156 |
for i in range(len(self.screens)): |
| 157 |
self.index = i |
| 158 |
self.open_next_window() |
| 159 |
try: |
| 160 |
self.on_expose() |
| 161 |
self.w.dispatch_events() |
| 162 |
self.user_verify('Do you see a {} full screen window on screen {}?'.format( |
| 163 |
self.colour_names[i], i+1)) |
| 164 |
finally: |
| 165 |
self.w.close() |
| 166 |
|