aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo
diff options
context:
space:
mode:
authorVladimir Vukicevic <vladimir@pobox.com>2016-07-29 18:56:56 -0400
committerVladimir Vukicevic <vladimir@pobox.com>2016-08-17 09:50:58 -0400
commit0e328715918d509dcaad719d974b85cf7519c285 (patch)
tree3d875a95fc4f0f40d8de61d2e63b60a47b672e32 /python/servo
parent82df8e9399cad363ba2ff1fbe5350327935d8289 (diff)
downloadservo-0e328715918d509dcaad719d974b85cf7519c285.tar.gz
servo-0e328715918d509dcaad719d974b85cf7519c285.zip
Add proper Win32 notification for builds
Diffstat (limited to 'python/servo')
-rw-r--r--python/servo/build_commands.py43
-rw-r--r--python/servo/win32_toast.py45
2 files changed, 69 insertions, 19 deletions
diff --git a/python/servo/build_commands.py b/python/servo/build_commands.py
index 9771a7c9b8a..9ff87249d18 100644
--- a/python/servo/build_commands.py
+++ b/python/servo/build_commands.py
@@ -42,26 +42,31 @@ def notify_linux(title, text):
def notify_win(title, text):
- from ctypes import Structure, windll, POINTER, sizeof
- from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT
+ try:
+ from servo.win32_toast import WindowsToast
+ w = WindowsToast()
+ w.balloon_tip(title, text)
+ except:
+ from ctypes import Structure, windll, POINTER, sizeof
+ from ctypes.wintypes import DWORD, HANDLE, WINFUNCTYPE, BOOL, UINT
- class FLASHWINDOW(Structure):
- _fields_ = [("cbSize", UINT),
- ("hwnd", HANDLE),
- ("dwFlags", DWORD),
- ("uCount", UINT),
- ("dwTimeout", DWORD)]
+ class FLASHWINDOW(Structure):
+ _fields_ = [("cbSize", UINT),
+ ("hwnd", HANDLE),
+ ("dwFlags", DWORD),
+ ("uCount", UINT),
+ ("dwTimeout", DWORD)]
- FlashWindowExProto = WINFUNCTYPE(BOOL, POINTER(FLASHWINDOW))
- FlashWindowEx = FlashWindowExProto(("FlashWindowEx", windll.user32))
- FLASHW_CAPTION = 0x01
- FLASHW_TRAY = 0x02
- FLASHW_TIMERNOFG = 0x0C
+ FlashWindowExProto = WINFUNCTYPE(BOOL, POINTER(FLASHWINDOW))
+ FlashWindowEx = FlashWindowExProto(("FlashWindowEx", windll.user32))
+ FLASHW_CAPTION = 0x01
+ FLASHW_TRAY = 0x02
+ FLASHW_TIMERNOFG = 0x0C
- params = FLASHWINDOW(sizeof(FLASHWINDOW),
- windll.kernel32.GetConsoleWindow(),
- FLASHW_CAPTION | FLASHW_TRAY | FLASHW_TIMERNOFG, 3, 0)
- FlashWindowEx(params)
+ params = FLASHWINDOW(sizeof(FLASHWINDOW),
+ windll.kernel32.GetConsoleWindow(),
+ FLASHW_CAPTION | FLASHW_TRAY | FLASHW_TIMERNOFG, 3, 0)
+ FlashWindowEx(params)
def notify_darwin(title, text):
@@ -100,7 +105,7 @@ def notify(title, text):
platforms = {
"linux": notify_linux,
"linux2": notify_linux,
- "win": notify_win,
+ "win32": notify_win,
"darwin": notify_darwin
}
func = platforms.get(sys.platform)
@@ -256,7 +261,7 @@ class MachCommands(CommandBase):
if "msvc" in host_triple():
call(["editbin", "/nologo", "/subsystem:windows", path.join(servo_exe_dir, "servo.exe")],
verbose=verbose)
-
+
elif sys.platform == "darwin":
# On the Mac, set a lovely icon. This makes it easier to pick out the Servo binary in tools
# like Instruments.app.
diff --git a/python/servo/win32_toast.py b/python/servo/win32_toast.py
new file mode 100644
index 00000000000..22a7ccd917f
--- /dev/null
+++ b/python/servo/win32_toast.py
@@ -0,0 +1,45 @@
+# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution.
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+from win32api import GetModuleHandle
+from win32gui import WNDCLASS, RegisterClass, CreateWindow, UpdateWindow
+from win32gui import DestroyWindow, LoadIcon, NIF_ICON, NIF_MESSAGE, NIF_TIP
+from win32gui import Shell_NotifyIcon, NIM_ADD, NIM_MODIFY, NIF_INFO, NIIF_INFO
+import win32con
+
+
+class WindowsToast:
+ def __init__(self):
+ # Register window class; it's okay to do this multiple times
+ wc = WNDCLASS()
+ wc.lpszClassName = 'ServoTaskbarNotification'
+ wc.lpfnWndProc = {win32con.WM_DESTROY: self.OnDestroy, }
+ self.classAtom = RegisterClass(wc)
+ self.hinst = wc.hInstance = GetModuleHandle(None)
+
+ def OnDestroy(self, hwnd, msg, wparam, lparam):
+ # We don't have to Shell_NotifyIcon to delete it, since
+ # we destroyed
+ pass
+
+ def balloon_tip(self, title, msg):
+ style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
+ hwnd = CreateWindow(self.classAtom, "Taskbar", style, 0, 0,
+ win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
+ 0, 0, self.hinst, None)
+ UpdateWindow(hwnd)
+
+ hicon = LoadIcon(0, win32con.IDI_APPLICATION)
+
+ nid = (hwnd, 0, NIF_ICON | NIF_MESSAGE | NIF_TIP, win32con.WM_USER + 20, hicon, 'Tooltip')
+ Shell_NotifyIcon(NIM_ADD, nid)
+ nid = (hwnd, 0, NIF_INFO, win32con.WM_USER + 20, hicon, 'Balloon Tooltip', msg, 200, title, NIIF_INFO)
+ Shell_NotifyIcon(NIM_MODIFY, nid)
+
+ DestroyWindow(hwnd)