Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

taskbar: extract SetIcon

Changeset e177b40c0b9d

Parent 8f20f4f51c09

by Adrian Buehlmann

Changes to one file · Browse files at e177b40c0b9d Showing diff from parent 8f20f4f51c09 Diff from another changeset...

Change 1 of 2 Show Entire File thgtaskbar.py Stacked
 
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
 
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
86
87
88
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
84
85
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
88
89
90
@@ -33,6 +33,29 @@
 SHOWLOG_CMD = 1023  EXIT_CMD = 1025   +def SetIcon(hwnd, name): + # Try and find a custom icon + hinst = GetModuleHandle(None) + from thgutil.paths import get_tortoise_icon + iconPathName = get_tortoise_icon("hgB.ico") + if iconPathName and os.path.isfile(iconPathName): + icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE + hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags) + else: + print "Can't find a Python icon file - using default" + hicon = LoadIcon(0, win32con.IDI_APPLICATION) + + flags = NIF_ICON | NIF_MESSAGE | NIF_TIP + nid = (hwnd, 0, flags, win32con.WM_USER+20, hicon, APP_TITLE) + try: + Shell_NotifyIcon(NIM_ADD, nid) + except error: + # This is common when windows is starting, and this code is hit + # before the taskbar has been created. + print "Failed to add the taskbar icon - is explorer running?" + # but keep running anyway - when explorer starts, we get the + # TaskbarCreated message. +  class MainWindow:   def __init__(self):   msg_TaskbarRestart = RegisterWindowMessage("TaskbarCreated"); @@ -61,28 +84,7 @@
  self._DoCreateIcons()     def _DoCreateIcons(self): - # Try and find a custom icon - hinst = GetModuleHandle(None) - from thgutil.paths import get_tortoise_icon - iconPathName = get_tortoise_icon("hg.ico") - if iconPathName and os.path.isfile(iconPathName): - icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE - hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags) - else: - print "Can't find a Python icon file - using default" - hicon = LoadIcon(0, win32con.IDI_APPLICATION) - - flags = NIF_ICON | NIF_MESSAGE | NIF_TIP - nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, APP_TITLE) - try: - Shell_NotifyIcon(NIM_ADD, nid) - except error: - # This is common when windows is starting, and this code is hit - # before the taskbar has been created. - print "Failed to add the taskbar icon - is explorer running?" - # but keep running anyway - when explorer starts, we get the - # TaskbarCreated message. - + SetIcon(self.hwnd, "hg.ico")   # start namepipe server for hg status   self.start_pipe_server()