| 1 | """Tests for window settings.""" |
| 2 | import pytest |
| 3 | import time |
| 4 | |
| 5 | from tests.base.interactive import InteractiveTestCase |
| 6 | from tests.interactive.window import window_util |
| 7 | |
| 8 | from pyglet.gl import * |
| 9 | from pyglet import image |
| 10 | from pyglet.window import key, Window, ImageMouseCursor |
| 11 | from pyglet.window.event import WindowEventLogger |
| 12 | |
| 13 | |
| 14 | @pytest.mark.requires_user_action |
| 15 | class WINDOW_SET_EXCLUSIVE_KEYBOARD(InteractiveTestCase): |
| 16 | """Test that exclusive keyboard mode can be set. |
| 17 | |
| 18 | Expected behaviour: |
| 19 | One window will be opened. Press 'e' to enable exclusive mode and 'E' |
| 20 | to disable exclusive mode. |
| 21 | |
| 22 | In exclusive mode: |
| 23 | - Pressing system keys, the Expose keys, etc., should have no effect |
| 24 | besides displaying as keyboard events. |
| 25 | - On OS X, the Power switch is not disabled (though this is possible |
| 26 | if desired, see source). |
| 27 | - On OS X, the menu bar and dock will disappear during keyboard |
| 28 | exclusive mode. |
| 29 | - On Windows, only Alt+Tab is disabled. A user can still switch away |
| 30 | using Ctrl+Escape, Alt+Escape, the Windows key or Ctrl+Alt+Del. |
| 31 | - Switching to another application (i.e., with the mouse) should make |
| 32 | these keys work normally again until this application regains focus. |
| 33 | |
| 34 | Close the window or press ESC to end the test. |
| 35 | """ |
| 36 | def on_key_press(self, symbol, modifiers): |
| 37 | print('Pressed %s with modifiers %s' % \ |
| 38 | (key.symbol_string(symbol), key.modifiers_string(modifiers))) |
| 39 | |
| 40 | if symbol == key.E: |
| 41 | exclusive = not (modifiers & key.MOD_SHIFT) |
| 42 | self.w.set_exclusive_keyboard(exclusive) |
| 43 | print('Exclusive keyboard is now %r' % exclusive) |
| 44 | |
| 45 | def on_key_release(self, symbol, modifiers): |
| 46 | print('Released %s with modifiers %s' % \ |
| 47 | (key.symbol_string(symbol), key.modifiers_string(modifiers))) |
| 48 | |
| 49 | def test_set_exclusive_keyboard(self): |
| 50 | self.width, self.height = 200, 200 |
| 51 | self.w = w = Window(self.width, self.height) |
| 52 | try: |
| 53 | w.push_handlers(self) |
| 54 | while not w.has_exit: |
| 55 | w.dispatch_events() |
| 56 | finally: |
| 57 | w.close() |
| 58 | self.user_verify('Pass test?', take_screenshot=False) |
| 59 | |
| 60 | |
| 61 | @pytest.mark.requires_user_action |
| 62 | class WINDOW_SET_EXCLUSIVE_MOUSE(InteractiveTestCase): |
| 63 | """Test that exclusive mouse mode can be set. |
| 64 | |
| 65 | Expected behaviour: |
| 66 | One window will be opened. Press 'e' to enable exclusive mode and 'E' |
| 67 | to disable exclusive mode. |
| 68 | |
| 69 | In exclusive mode: |
| 70 | - the mouse cursor should be invisible |
| 71 | - moving the mouse should generate events with bogus x,y but correct |
| 72 | dx and dy. |
| 73 | - it should not be possible to switch applications with the mouse |
| 74 | - if application loses focus (i.e., with keyboard), the mouse should |
| 75 | operate normally again until focus is returned to the app, in which |
| 76 | case it should hide again. |
| 77 | |
| 78 | Close the window or press ESC to end the test. |
| 79 | """ |
| 80 | def on_key_press(self, symbol, modifiers): |
| 81 | if symbol == key.E: |
| 82 | exclusive = not (modifiers & key.MOD_SHIFT) |
| 83 | self.w.set_exclusive_mouse(exclusive) |
| 84 | print('Exclusive mouse is now %r' % exclusive) |
| 85 | |
| 86 | def on_mouse_motion(self, x, y, dx, dy): |
| 87 | print('on_mousemotion(x=%f, y=%f, dx=%f, dy=%f)' % (x, y, dx, dy)) |
| 88 | |
| 89 | def test_set_exclusive_mouse(self): |
| 90 | self.width, self.height = 200, 200 |
| 91 | self.w = w = Window(self.width, self.height) |
| 92 | try: |
| 93 | w.push_handlers(self) |
| 94 | while not w.has_exit: |
| 95 | w.dispatch_events() |
| 96 | finally: |
| 97 | w.close() |
| 98 | self.user_verify('Pass test?', take_screenshot=False) |
| 99 | |
| 100 | |
| 101 | @pytest.mark.requires_user_action |
| 102 | class WINDOW_SET_FULLSCREEN(InteractiveTestCase): |
| 103 | """Test that window can be set fullscreen and back again. |
| 104 | |
| 105 | Expected behaviour: |
| 106 | One window will be opened. |
| 107 | |
| 108 | - press "f" to enter fullscreen mode. |
| 109 | - press "g" to leave fullscreen mode. |
| 110 | |
| 111 | All events will be printed to the terminal. |
| 112 | |
| 113 | Close the window or press ESC to end the test. |
| 114 | """ |
| 115 | def on_key_press(self, symbol, modifiers): |
| 116 | if symbol == key.F: |
| 117 | print('Setting fullscreen.') |
| 118 | self.w.set_fullscreen(True) |
| 119 | elif symbol == key.G: |
| 120 | print('Leaving fullscreen.') |
| 121 | self.w.set_fullscreen(False) |
| 122 | |
| 123 | def on_expose(self): |
| 124 | glClearColor(1, 0, 0, 1) |
| 125 | glClear(GL_COLOR_BUFFER_BIT) |
| 126 | self.w.flip() |
| 127 | |
| 128 | def test_set_fullscreen(self): |
| 129 | self.w = w = Window(200, 200) |
| 130 | try: |
| 131 | w.push_handlers(self) |
| 132 | w.push_handlers(WindowEventLogger()) |
| 133 | self.on_expose() |
| 134 | while not w.has_exit: |
| 135 | w.dispatch_events() |
| 136 | finally: |
| 137 | w.close() |
| 138 | self.user_verify('Pass test?', take_screenshot=False) |
| 139 | |
| 140 | |
| 141 | @pytest.mark.requires_user_validation |
| 142 | class WINDOW_SET_ICON(InteractiveTestCase): |
| 143 | """Test that window icon can be set. |
| 144 | |
| 145 | Expected behaviour: |
| 146 | One window will be opened. It will have an icon depicting a yellow |
| 147 | "A". |
| 148 | """ |
| 149 | def test_set_icon(self): |
| 150 | self.width, self.height = 200, 200 |
| 151 | self.w = w = Window(self.width, self.height) |
| 152 | try: |
| 153 | w.set_icon(image.load(self.get_test_data_file('images', 'icon1.png'))) |
| 154 | w.dispatch_events() |
| 155 | self.user_verify('Does the window have a yellow A icon?', take_screenshot=False) |
| 156 | finally: |
| 157 | w.close() |
| 158 | |
| 159 | |
| 160 | @pytest.mark.requires_user_validation |
| 161 | class WINDOW_SET_ICON_SIZES(InteractiveTestCase): |
| 162 | """Test that window icon can be set for multiple sizes. |
| 163 | |
| 164 | Expected behaviour: |
| 165 | One window will be opened. The window's icon depends on the icon |
| 166 | size: |
| 167 | |
| 168 | 16x16 icon is a yellow "1" |
| 169 | 32x32 icon is a purple "2" |
| 170 | 48x48 icon is a cyan "3" |
| 171 | 72x72 icon is a red "4" |
| 172 | 128x128 icon is a blue "5" |
| 173 | |
| 174 | For other sizes, the operating system may select the closest match and |
| 175 | scale it (Linux, Windows), or interpolate between two or more images |
| 176 | (Mac OS X). |
| 177 | """ |
| 178 | def test_set_icon_sizes(self): |
| 179 | self.width, self.height = 200, 200 |
| 180 | self.w = w = Window(self.width, self.height) |
| 181 | try: |
| 182 | w.set_icon(image.load(self.get_test_data_file('images', 'icon_size1.png')), |
| 183 | image.load(self.get_test_data_file('images', 'icon_size2.png')), |
| 184 | image.load(self.get_test_data_file('images', 'icon_size3.png')), |
| 185 | image.load(self.get_test_data_file('images', 'icon_size4.png')), |
| 186 | image.load(self.get_test_data_file('images', 'icon_size5.png'))) |
| 187 | w.dispatch_events() |
| 188 | self.user_verify('Does the window have the icon corresponding to the correct size?', take_screenshot=False) |
| 189 | finally: |
| 190 | w.close() |
| 191 | |
| 192 | |
| 193 | @pytest.mark.requires_user_action |
| 194 | class WINDOW_SET_LOCATION(InteractiveTestCase): |
| 195 | """Test that window location can be set. |
| 196 | |
| 197 | Expected behaviour: |
| 198 | One window will be opened. The window's location will be printed |
| 199 | to the terminal. |
| 200 | |
| 201 | - Use the arrow keys to move the window. |
| 202 | |
| 203 | Close the window or press ESC to end the test. |
| 204 | """ |
| 205 | def on_key_press(self, symbol, modifiers): |
| 206 | x, y = self.w.get_location() |
| 207 | if symbol == key.LEFT: |
| 208 | x -= 10 |
| 209 | if symbol == key.RIGHT: |
| 210 | x += 10 |
| 211 | if symbol == key.UP: |
| 212 | y -= 10 |
| 213 | if symbol == key.DOWN: |
| 214 | y += 10 |
| 215 | self.w.set_location(x, y) |
| 216 | print('Window location set to %dx%d.' % (x, y)) |
| 217 | print('Window location now: %dx%d.' % self.w.get_location()) |
| 218 | self.assertSequenceEqual((x, y), self.w.get_location()) |
| 219 | |
| 220 | def test_set_location(self): |
| 221 | self.w = w = Window(200, 200) |
| 222 | try: |
| 223 | w.push_handlers(self) |
| 224 | while not w.has_exit: |
| 225 | w.dispatch_events() |
| 226 | finally: |
| 227 | w.close() |
| 228 | self.user_verify('Pass test?', take_screenshot=False) |
| 229 | |
| 230 | |
| 231 | @pytest.mark.requires_user_action |
| 232 | class WINDOW_SET_MIN_MAX_SIZE(InteractiveTestCase): |
| 233 | """Test that minimum and maximum window size can be set. |
| 234 | |
| 235 | Expected behaviour: |
| 236 | One window will be opened. The window's dimensions will be printed |
| 237 | to the terminal. Initially the window has no minimum or maximum |
| 238 | size (besides any OS-enforced limit). |
| 239 | |
| 240 | - press "n" to set the minimum size to be the current size. |
| 241 | - press "x" to set the maximum size to be the current size. |
| 242 | |
| 243 | You should see a green border inside the window but no red. |
| 244 | |
| 245 | Close the window or press ESC to end the test. |
| 246 | """ |
| 247 | def on_resize(self, width, height): |
| 248 | print('Window size is %dx%d.' % (width, height)) |
| 249 | self.width, self.height = width, height |
| 250 | |
| 251 | def on_key_press(self, symbol, modifiers): |
| 252 | if symbol == key.N: |
| 253 | self.w.set_minimum_size(self.width, self.height) |
| 254 | print('Minimum size set to %dx%d.' % (self.width, self.height)) |
| 255 | elif symbol == key.X: |
| 256 | self.w.set_maximum_size(self.width, self.height) |
| 257 | print('Maximum size set to %dx%d.' % (self.width, self.height)) |
| 258 | |
| 259 | def test_min_max_size(self): |
| 260 | self.width, self.height = 200, 200 |
| 261 | self.w = w = Window(self.width, self.height, resizable=True) |
| 262 | try: |
| 263 | w.push_handlers(self) |
| 264 | while not w.has_exit: |
| 265 | window_util.draw_client_border(w) |
| 266 | w.flip() |
| 267 | w.dispatch_events() |
| 268 | finally: |
| 269 | w.close() |
| 270 | self.user_verify('Pass test?', take_screenshot=False) |
| 271 | |
| 272 | |
| 273 | @pytest.mark.requires_user_action |
| 274 | class WINDOW_SET_MOUSE_CURSOR(InteractiveTestCase): |
| 275 | """Test that image mouse cursor can be set. |
| 276 | |
| 277 | Expected behaviour: |
| 278 | One window will be opened. The mouse cursor in the window will be |
| 279 | a custom cursor. |
| 280 | |
| 281 | Close the window or press ESC to end the test. |
| 282 | """ |
| 283 | def on_mouse_motion(self, x, y, dx, dy): |
| 284 | print('on_mousemotion(x=%f, y=%f, dx=%f, dy=%f)' % (x, y, dx, dy)) |
| 285 | |
| 286 | def test_set_mouse_cursor(self): |
| 287 | self.width, self.height = 200, 200 |
| 288 | self.w = w = Window(self.width, self.height) |
| 289 | try: |
| 290 | img = image.load(self.get_test_data_file('images', 'cursor.png')) |
| 291 | w.set_mouse_cursor(ImageMouseCursor(img, 4, 28)) |
| 292 | w.push_handlers(self) |
| 293 | glClearColor(1, 1, 1, 1) |
| 294 | while not w.has_exit: |
| 295 | glClear(GL_COLOR_BUFFER_BIT) |
| 296 | w.flip() |
| 297 | w.dispatch_events() |
| 298 | finally: |
| 299 | w.close() |
| 300 | self.user_verify('Pass test?', take_screenshot=False) |
| 301 | |
| 302 | |
| 303 | @pytest.mark.requires_user_action |
| 304 | class WINDOW_SET_MOUSE_PLATFORM_CURSOR(InteractiveTestCase): |
| 305 | """Test that mouse cursor can be set to a platform-dependent image. |
| 306 | |
| 307 | Expected behaviour: |
| 308 | One window will be opened. Press the left and right arrow keys to cycle |
| 309 | through the system mouse cursors. The current cursor selected will |
| 310 | be printed to the terminal. |
| 311 | |
| 312 | Note that not all cursors are unique on each platform; for example, |
| 313 | if a platform doesn't define a cursor for a given name, a suitable |
| 314 | replacement (e.g., a plain arrow) will be used instead. |
| 315 | |
| 316 | Close the window or press ESC to end the test. |
| 317 | """ |
| 318 | i = 0 |
| 319 | def on_key_press(self, symbol, modifiers): |
| 320 | names = [ |
| 321 | self.w.CURSOR_DEFAULT, |
| 322 | self.w.CURSOR_CROSSHAIR, |
| 323 | self.w.CURSOR_HAND, |
| 324 | self.w.CURSOR_HELP, |
| 325 | self.w.CURSOR_NO, |
| 326 | self.w.CURSOR_SIZE, |
| 327 | self.w.CURSOR_SIZE_UP, |
| 328 | self.w.CURSOR_SIZE_UP_RIGHT, |
| 329 | self.w.CURSOR_SIZE_RIGHT, |
| 330 | self.w.CURSOR_SIZE_DOWN_RIGHT, |
| 331 | self.w.CURSOR_SIZE_DOWN, |
| 332 | self.w.CURSOR_SIZE_DOWN_LEFT, |
| 333 | self.w.CURSOR_SIZE_LEFT, |
| 334 | self.w.CURSOR_SIZE_UP_LEFT, |
| 335 | self.w.CURSOR_SIZE_UP_DOWN, |
| 336 | self.w.CURSOR_SIZE_LEFT_RIGHT, |
| 337 | self.w.CURSOR_TEXT, |
| 338 | self.w.CURSOR_WAIT, |
| 339 | self.w.CURSOR_WAIT_ARROW, |
| 340 | ] |
| 341 | if symbol == key.ESCAPE: |
| 342 | self.w.on_close() |
| 343 | if symbol == key.RIGHT: |
| 344 | self.i = (self.i + 1) % len(names) |
| 345 | elif symbol == key.LEFT: |
| 346 | self.i = (self.i - 1) % len(names) |
| 347 | cursor = self.w.get_system_mouse_cursor(names[self.i]) |
| 348 | self.w.set_mouse_cursor(cursor) |
| 349 | print('Set cursor to "%s"' % names[self.i]) |
| 350 | |
| 351 | return True |
| 352 | |
| 353 | def test_set_visible(self): |
| 354 | self.width, self.height = 200, 200 |
| 355 | self.w = w = Window(self.width, self.height) |
| 356 | try: |
| 357 | w.push_handlers(self) |
| 358 | while not w.has_exit: |
| 359 | glClear(GL_COLOR_BUFFER_BIT) |
| 360 | w.flip() |
| 361 | w.dispatch_events() |
| 362 | finally: |
| 363 | w.close() |
| 364 | self.user_verify('Pass test?', take_screenshot=False) |
| 365 | |
| 366 | |
| 367 | @pytest.mark.requires_user_action |
| 368 | class WINDOW_SET_MOUSE_VISIBLE(InteractiveTestCase): |
| 369 | """Test that mouse cursor can be made visible and hidden. |
| 370 | |
| 371 | Expected behaviour: |
| 372 | One window will be opened. Press 'v' to hide mouse cursor and 'V' to |
| 373 | show mouse cursor. It should only affect the mouse when within the |
| 374 | client area of the window. |
| 375 | |
| 376 | Close the window or press ESC to end the test. |
| 377 | """ |
| 378 | def on_key_press(self, symbol, modifiers): |
| 379 | if symbol == key.V: |
| 380 | visible = (modifiers & key.MOD_SHIFT) |
| 381 | self.w.set_mouse_visible(visible) |
| 382 | print('Mouse is now %s' % (visible and 'visible' or 'hidden')) |
| 383 | |
| 384 | def on_mouse_motion(self, x, y, dx, dy): |
| 385 | print('on_mousemotion(x=%f, y=%f, dx=%f, dy=%f)' % (x, y, dx, dy)) |
| 386 | |
| 387 | def test_set_visible(self): |
| 388 | self.width, self.height = 200, 200 |
| 389 | self.w = w = Window(self.width, self.height) |
| 390 | try: |
| 391 | w.push_handlers(self) |
| 392 | while not w.has_exit: |
| 393 | w.dispatch_events() |
| 394 | finally: |
| 395 | w.close() |
| 396 | self.user_verify('Pass test?', take_screenshot=False) |
| 397 | |
| 398 | |
| 399 | @pytest.mark.requires_user_action |
| 400 | class WINDOW_SET_SIZE(InteractiveTestCase): |
| 401 | """Test that window size can be set. |
| 402 | |
| 403 | Expected behaviour: |
| 404 | One window will be opened. The window's dimensions will be printed |
| 405 | to the terminal. |
| 406 | |
| 407 | - press "x" to increase the width |
| 408 | - press "X" to decrease the width |
| 409 | - press "y" to increase the height |
| 410 | - press "Y" to decrease the height |
| 411 | |
| 412 | You should see a green border inside the window but no red. |
| 413 | |
| 414 | Close the window or press ESC to end the test. |
| 415 | """ |
| 416 | def on_key_press(self, symbol, modifiers): |
| 417 | delta = 20 |
| 418 | if modifiers & key.MOD_SHIFT: |
| 419 | delta = -delta |
| 420 | if symbol == key.X: |
| 421 | self.width += delta |
| 422 | elif symbol == key.Y: |
| 423 | self.height += delta |
| 424 | self.w.set_size(self.width, self.height) |
| 425 | print('Window size set to %dx%d.' % (self.width, self.height)) |
| 426 | |
| 427 | def test_set_size(self): |
| 428 | self.width, self.height = 200, 200 |
| 429 | self.w = w = Window(self.width, self.height, resizable=True) |
| 430 | try: |
| 431 | w.push_handlers(self) |
| 432 | while not w.has_exit: |
| 433 | window_util.draw_client_border(w) |
| 434 | w.flip() |
| 435 | w.dispatch_events() |
| 436 | finally: |
| 437 | w.close() |
| 438 | self.user_verify('Pass test?', take_screenshot=False) |
| 439 | |
| 440 | |
| 441 | @pytest.mark.requires_user_validation |
| 442 | class WINDOW_SET_VISIBLE(InteractiveTestCase): |
| 443 | """Test that the window can be hidden and shown. |
| 444 | |
| 445 | Expected behaviour: |
| 446 | One window will be opened. It will toggle between |
| 447 | hidden and shown. |
| 448 | """ |
| 449 | def test_set_visible(self): |
| 450 | w = Window(200, 200) |
| 451 | try: |
| 452 | w.push_handlers(WindowEventLogger()) |
| 453 | w.dispatch_events() |
| 454 | self.user_verify('Is the window visible?', take_screenshot=False) |
| 455 | |
| 456 | w.set_visible(False) |
| 457 | w.dispatch_events() |
| 458 | self.user_verify('Is the window no longer visible?', take_screenshot=False) |
| 459 | |
| 460 | w.set_visible(True) |
| 461 | w.dispatch_events() |
| 462 | self.user_verify('Is the window visible again?', take_screenshot=False) |
| 463 | |
| 464 | finally: |
| 465 | w.close() |
| 466 | |
| 467 | |
| 468 | @pytest.mark.requires_user_action |
| 469 | class WINDOW_SET_VSYNC(InteractiveTestCase): |
| 470 | """Test that vsync can be set. |
| 471 | |
| 472 | Expected behaviour: |
| 473 | A window will alternate between red and green fill. |
| 474 | |
| 475 | - Press "v" to toggle vsync on/off. "Tearing" should only be visible |
| 476 | when vsync is off (as indicated at the terminal). |
| 477 | |
| 478 | Not all video drivers support vsync. On Linux, check the output of |
| 479 | `tools/info.py`: |
| 480 | |
| 481 | - If GLX_SGI_video_sync extension is present, should work as expected. |
| 482 | - If GLX_MESA_swap_control extension is present, should work as expected. |
| 483 | - If GLX_SGI_swap_control extension is present, vsync can be enabled, |
| 484 | but once enabled, it cannot be switched off (there will be no error |
| 485 | message). |
| 486 | - If none of these extensions are present, vsync is not supported by |
| 487 | your driver, but no error message or warning will be printed. |
| 488 | |
| 489 | Close the window or press ESC to end the test. |
| 490 | """ |
| 491 | colors = [(1, 0, 0, 1), (0, 1, 0, 1)] |
| 492 | color_index = 0 |
| 493 | |
| 494 | def open_window(self): |
| 495 | return Window(200, 200, vsync=False) |
| 496 | |
| 497 | def on_key_press(self, symbol, modifiers): |
| 498 | if symbol == key.V: |
| 499 | vsync = not self.w1.vsync |
| 500 | self.w1.set_vsync(vsync) |
| 501 | print('vsync is %r' % self.w1.vsync) |
| 502 | |
| 503 | def draw_window(self, window, colour): |
| 504 | window.switch_to() |
| 505 | glClearColor(*colour) |
| 506 | glClear(GL_COLOR_BUFFER_BIT) |
| 507 | window.flip() |
| 508 | |
| 509 | def test_open_window(self): |
| 510 | self.w1 = self.open_window() |
| 511 | try: |
| 512 | self.w1.push_handlers(self) |
| 513 | print('vsync is %r' % self.w1.vsync) |
| 514 | while not self.w1.has_exit: |
| 515 | self.color_index = 1 - self.color_index |
| 516 | self.draw_window(self.w1, self.colors[self.color_index]) |
| 517 | self.w1.dispatch_events() |
| 518 | finally: |
| 519 | self.w1.close() |
| 520 | self.user_verify('Pass test?', take_screenshot=False) |
| 521 | |
| 522 | |
| 523 | @pytest.mark.requires_user_action |
| 524 | class WINDOW_SET_CAPTION(InteractiveTestCase): |
| 525 | """Test that the window caption can be set. |
| 526 | |
| 527 | Expected behaviour: |
| 528 | Two windows will be opened, one with the caption "Window caption 1" |
| 529 | counting up every second; the other with a Unicode string including |
| 530 | some non-ASCII characters. |
| 531 | |
| 532 | Press escape or close either window to finished the test. |
| 533 | """ |
| 534 | def test_caption(self): |
| 535 | try: |
| 536 | w1 = Window(400, 200, resizable=True) |
| 537 | w2 = Window(400, 200, resizable=True) |
| 538 | count = 1 |
| 539 | w1.set_caption('Window caption %d' % count) |
| 540 | w2.set_caption(u'\u00bfHabla espa\u00f1ol?') |
| 541 | last_time = time.time() |
| 542 | while not (w1.has_exit or w2.has_exit): |
| 543 | if time.time() - last_time > 1: |
| 544 | count += 1 |
| 545 | w1.set_caption('Window caption %d' % count) |
| 546 | last_time = time.time() |
| 547 | w1.dispatch_events() |
| 548 | w2.dispatch_events() |
| 549 | finally: |
| 550 | w1.close() |
| 551 | w2.close() |
| 552 | self.user_verify('Pass test?', take_screenshot=False) |
| 553 | |
| 554 | |
| 555 | @pytest.mark.requires_user_action |
| 556 | class WINDOW_FIXED_SET_SIZE(InteractiveTestCase): |
| 557 | """Test that a non-resizable window's size can be set. |
| 558 | |
| 559 | Expected behaviour: |
| 560 | One window will be opened. The window's dimensions will be printed |
| 561 | to the terminal. |
| 562 | |
| 563 | - press "x" to increase the width |
| 564 | - press "X" to decrease the width |
| 565 | - press "y" to increase the height |
| 566 | - press "Y" to decrease the height |
| 567 | |
| 568 | You should see a green border inside the window but no red. |
| 569 | |
| 570 | Close the window or press ESC to end the test. |
| 571 | """ |
| 572 | def on_key_press(self, symbol, modifiers): |
| 573 | delta = 20 |
| 574 | if modifiers & key.MOD_SHIFT: |
| 575 | delta = -delta |
| 576 | if symbol == key.X: |
| 577 | self.width += delta |
| 578 | elif symbol == key.Y: |
| 579 | self.height += delta |
| 580 | self.w.set_size(self.width, self.height) |
| 581 | print('Window size set to %dx%d.' % (self.width, self.height)) |
| 582 | |
| 583 | def test_set_size(self): |
| 584 | self.width, self.height = 200, 200 |
| 585 | self.w = w = Window(self.width, self.height) |
| 586 | try: |
| 587 | w.push_handlers(self) |
| 588 | while not w.has_exit: |
| 589 | window_util.draw_client_border(w) |
| 590 | w.flip() |
| 591 | w.dispatch_events() |
| 592 | finally: |
| 593 | w.close() |
| 594 | self.user_verify('Pass test?', take_screenshot=False) |
| 595 | |
| 596 |