|
2 | 2 | # Licensed under the Apache License, Version 2.0 |
3 | 3 |
|
4 | 4 | import sys |
5 | | -import time |
6 | 5 |
|
7 | 6 | from colcon_core.logging import colcon_logger |
8 | 7 | from colcon_core.plugin_system import satisfies_version |
@@ -47,6 +46,12 @@ def __init__(self, title, message, icon_path=None): # noqa: D107 |
47 | 46 | logger.debug( |
48 | 47 | 'Failed to import win32gui: {e}'.format_map(locals())) |
49 | 48 | return |
| 49 | + try: |
| 50 | + import win32.timer |
| 51 | + except ImportError as e: # noqa: F841 |
| 52 | + logger.debug( |
| 53 | + 'Failed to import win32.timer: {e}'.format_map(locals())) |
| 54 | + return |
50 | 55 |
|
51 | 56 | wc, class_atom = NotificationWindow._create_window_class() |
52 | 57 |
|
@@ -82,14 +87,16 @@ def __init__(self, title, message, icon_path=None): # noqa: D107 |
82 | 87 | win32gui.NIM_MODIFY, ( |
83 | 88 | hwnd, 0, win32gui.NIF_INFO, win32con.WM_USER + 20, hicon, |
84 | 89 | 'Balloon tooltip', message, 200, title)) |
| 90 | + # wait a while before destroying the window |
| 91 | + timer_id = win32.timer.set_timer( |
| 92 | + 5000, lambda *_: win32gui.DestroyWindow(hwnd)) |
85 | 93 | except Exception as e: # noqa: F841 |
86 | 94 | logger.debug( |
87 | 95 | 'Failed to show the notification: {e}'.format_map(locals())) |
88 | | - else: |
89 | | - # wait a while before destroying the window |
90 | | - time.sleep(5) |
91 | | - finally: |
92 | 96 | win32gui.DestroyWindow(hwnd) |
| 97 | + else: |
| 98 | + win32gui.PumpMessages() |
| 99 | + win32.timer.kill_timer(timer_id) |
93 | 100 |
|
94 | 101 | _wc = None |
95 | 102 | _class_atom = None |
|
0 commit comments