cmdutil: hide child window created by win32 spawndetached()
authorPatrick Mezard <pmezard@gmail.com>
Sun, 10 Jan 2010 18:13:34 +0100
changeset 10240 3af4b39afe2a
parent 10239 8e4be44a676f
child 10241 4b2a086bee31
cmdutil: hide child window created by win32 spawndetached() Hiding the child process window is not strictly necessary but it avoids opening an empty shell window when running hg serve as well as a task in the task bar. The window is hidden after the process is already started causing a single flicker.
mercurial/cmdutil.py
mercurial/util.py
mercurial/win32.py
--- a/mercurial/cmdutil.py	Wed Jan 06 21:11:58 2010 +0100
+++ b/mercurial/cmdutil.py	Sun Jan 10 18:13:34 2010 +0100
@@ -613,6 +613,7 @@
         except AttributeError:
             pass
         os.unlink(lockpath)
+        util.hidewindow()
         sys.stdout.flush()
         sys.stderr.flush()
 
--- a/mercurial/util.py	Wed Jan 06 21:11:58 2010 +0100
+++ b/mercurial/util.py	Sun Jan 10 18:13:34 2010 +0100
@@ -529,6 +529,14 @@
 def lookup_reg(key, name=None, scope=None):
     return None
 
+def hidewindow():
+    """Hide current shell window.
+
+    Used to hide the window opened when starting asynchronous
+    child process under Windows, unneeded on other systems.
+    """
+    pass
+
 if os.name == 'nt':
     from windows import *
 else:
--- a/mercurial/win32.py	Wed Jan 06 21:11:58 2010 +0100
+++ b/mercurial/win32.py	Sun Jan 10 18:13:34 2010 +0100
@@ -16,7 +16,7 @@
 import win32api
 
 import errno, os, sys, pywintypes, win32con, win32file, win32process
-import winerror
+import winerror, win32gui
 import osutil, encoding
 from win32com.shell import shell, shellcon
 
@@ -172,3 +172,12 @@
         win32process.ExitProcess(1)
     win32api.SetConsoleCtrlHandler(handler)
 
+def hidewindow():
+    def callback(*args, **kwargs):
+        hwnd, pid = args
+        wpid = win32process.GetWindowThreadProcessId(hwnd)[1]
+        if pid == wpid:
+            win32gui.ShowWindow(hwnd, win32con.SW_HIDE)
+
+    pid =  win32process.GetCurrentProcessId()
+    win32gui.EnumWindows(callback, pid)