Changeset 6c125b90f701…
Parent e177b40c0b9d…
by
Changes to 2 files · Browse files at 6c125b90f701 Showing diff from parent e177b40c0b9d Diff from another changeset...
|
|
@@ -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)
|
Loading...