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

taskbar: show a green mercurial icon during update

Changeset 6c125b90f701

Parent e177b40c0b9d

by Adrian Buehlmann

Changes to 2 files · Browse files at 6c125b90f701 Showing diff from parent e177b40c0b9d Diff from another changeset...

Added image
Change 1 of 8 Show Entire File thgtaskbar.py Stacked
 
33
34
35
36
 
37
 
38
39
40
 
41
42
43
 
47
48
49
 
 
 
50
51
 
52
53
54
 
84
85
86
87
 
88
89
90
 
173
174
175
176
 
177
178
179
 
245
246
247
248
 
249
250
251
252
253
 
254
255
256
 
270
271
272
 
273
274
275
 
284
285
286
287
 
288
289
290
 
291
292
293
294
295
296
 
 
 
 
297
298
299
 
302
303
304
305
 
306
307
308
 
 
 
 
309
310
311
312
313
314
 
33
34
35
 
36
37
38
39
40
 
41
42
43
44
 
48
49
50
51
52
53
54
 
55
56
57
58
 
88
89
90
 
91
92
93
94
 
177
178
179
 
180
181
182
183
 
249
250
251
 
252
253
254
255
256
257
258
259
260
261
 
275
276
277
278
279
280
281
 
290
291
292
 
293
294
295
 
296
297
298
299
300
301
302
303
304
305
306
307
308
309
 
312
313
314
 
315
316
317
 
318
319
320
321
322
 
 
323
324
325
@@ -33,11 +33,12 @@
 SHOWLOG_CMD = 1023  EXIT_CMD = 1025   -def SetIcon(hwnd, name): +def SetIcon(hwnd, name, add=False):   # Try and find a custom icon + print "SetIcon(%s)" % name   hinst = GetModuleHandle(None)   from thgutil.paths import get_tortoise_icon - iconPathName = get_tortoise_icon("hgB.ico") + iconPathName = get_tortoise_icon(name)   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) @@ -47,8 +48,11 @@
    flags = NIF_ICON | NIF_MESSAGE | NIF_TIP   nid = (hwnd, 0, flags, win32con.WM_USER+20, hicon, APP_TITLE) + action = NIM_MODIFY + if add: + action = NIM_ADD   try: - Shell_NotifyIcon(NIM_ADD, nid) + Shell_NotifyIcon(action, nid)   except error:   # This is common when windows is starting, and this code is hit   # before the taskbar has been created. @@ -84,7 +88,7 @@
  self._DoCreateIcons()     def _DoCreateIcons(self): - SetIcon(self.hwnd, "hg.ico") + SetIcon(self.hwnd, "hg.ico", add=True)   # start namepipe server for hg status   self.start_pipe_server()   @@ -173,7 +177,7 @@
    def start_pipe_server(self):   def servepipe(): - self.svc = PipeServer() + self.svc = PipeServer(self.hwnd)   self.svc.SvcDoRun()     self.pipethread = thread2.Thread(target=servepipe) @@ -245,12 +249,13 @@
   requests = Queue.Queue(0)   -def update(args): +def update(args, hwnd):   batch = []   r = args[0]   print "got update request %s (first in batch)" % r   batch.append(r)   print "wait a bit for additional requests..." + SetIcon(hwnd, "hgB.ico")   time.sleep(0.2)   deferred_requests = []   try: @@ -270,6 +275,7 @@
  msg = "processing batch with %i update requests"   print msg % len(batch)   update_batch(batch) + SetIcon(hwnd, "hg.ico")    def remove(args):   path = args[0] @@ -284,16 +290,20 @@
  if notifypaths:   shlib.shell_notify(list(notifypaths))   -def dispatch(req, cmd, args): +def dispatch(req, cmd, args, hwnd):   print "dispatch(%s)" % req   if cmd == 'update': - update(args) + update(args, hwnd)   elif cmd == 'remove':   remove(args)   else:   logger.msg("Error: unknown request '%s'" % req)    class Updater(threading.Thread): + def __init__(self, hwnd): + threading.Thread.__init__(self) + self.hwnd = hwnd +   def run(self):   while True:   req = requests.get() @@ -302,13 +312,14 @@
  if cmd == 'terminate':   logger.msg('Updater thread terminating')   return - dispatch(req, cmd, args) + dispatch(req, cmd, args, self.hwnd)   gc.collect()   -Updater().start() +class PipeServer: + def __init__(self, hwnd): + self.updater = Updater(hwnd) + self.updater.start()   -class PipeServer: - def __init__(self):   # Create an event which we will use to wait on.   # The "service stop" request will set this event.   self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)