changeset 10240:3af4b39afe2a

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.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 10 Jan 2010 18:13:34 +0100
parents 8e4be44a676f
children 4b2a086bee31
files mercurial/cmdutil.py mercurial/util.py mercurial/win32.py
diffstat 3 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)