FAQ
Hi,

As part of my efforts to write a test tool that copes with GUIs
nicely, I'm trying to establish how I can start a GUI process on
Windows that will not bring up the window. So I try to hide the window
as follows:

info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

proc = subprocess.Popen(..., startupinfo=info)

This works, in a way, but doesn't work recursively. I.e. if the
started process itself starts a window, that second window will not be
hidden. This even applies to dialog boxes within the application. So
instead of a lot of windows popping up I now get a lot of disembodied
dialogs appearing, which is a slight improvement but not much.

Also, certain processes (e.g. tkdiff) seem to ignore the directive to
be hidden altogether.

This is dead easy on UNIX with virtual displays like Xvfb. Can someone
shed any light if it's possible on Windows from python?

Regards,
Geoff Bache

Search Discussions

  • Kyosohma at Aug 27, 2007 at 9:28 pm

    On Aug 27, 3:21 pm, geoffbache wrote:
    Hi,

    As part of my efforts to write a test tool that copes with GUIs
    nicely, I'm trying to establish how I can start a GUI process on
    Windows that will not bring up the window. So I try to hide the window
    as follows:

    info = subprocess.STARTUPINFO()
    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE

    proc = subprocess.Popen(..., startupinfo=info)

    This works, in a way, but doesn't work recursively. I.e. if the
    started process itself starts a window, that second window will not be
    hidden. This even applies to dialog boxes within the application. So
    instead of a lot of windows popping up I now get a lot of disembodied
    dialogs appearing, which is a slight improvement but not much.

    Also, certain processes (e.g. tkdiff) seem to ignore the directive to
    be hidden altogether.

    This is dead easy on UNIX with virtual displays like Xvfb. Can someone
    shed any light if it's possible on Windows from python?

    Regards,
    Geoff Bache
    I'm confused. Why would you create a GUI if you're not going to
    actually display it? Isn't that the point of a GUI? Or are you talking
    about the command window popping up?

    Mike
  • Geoffbache at Aug 28, 2007 at 9:08 am

    On Aug 27, 11:28 pm, kyoso... at gmail.com wrote:
    On Aug 27, 3:21 pm, geoffbache wrote:


    Hi,
    As part of my efforts to write a test tool that copes with GUIs
    nicely, I'm trying to establish how I can start a GUI process on
    Windows that will not bring up the window. So I try to hide the window
    as follows:
    info = subprocess.STARTUPINFO()
    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE
    proc = subprocess.Popen(..., startupinfo=info)
    This works, in a way, but doesn't work recursively. I.e. if the
    started process itself starts a window, that second window will not be
    hidden. This even applies to dialog boxes within the application. So
    instead of a lot of windows popping up I now get a lot of disembodied
    dialogs appearing, which is a slight improvement but not much.
    Also, certain processes (e.g. tkdiff) seem to ignore the directive to
    be hidden altogether.
    This is dead easy on UNIX with virtual displays like Xvfb. Can someone
    shed any light if it's possible on Windows from python?
    Regards,
    Geoff Bache
    I'm confused. Why would you create a GUI if you're not going to
    actually display it? Isn't that the point of a GUI? Or are you talking
    about the command window popping up?

    Mike
    Only in the context of testing it. If I run lots of GUI tests on my
    computer I want
    the tested GUIs to remain hidden so I can still use my computer in the
    meantime...

    Though if you can tell me how to stop the command window popping up on
    Windows
    I'll be grateful for that too (though it wasn't the original
    question).

    Geoff
  • Kyosohma at Aug 28, 2007 at 1:37 pm

    On Aug 28, 4:08 am, geoffbache wrote:
    On Aug 27, 11:28 pm, kyoso... at gmail.com wrote:


    On Aug 27, 3:21 pm, geoffbache wrote:

    Hi,
    As part of my efforts to write a test tool that copes with GUIs
    nicely, I'm trying to establish how I can start a GUI process on
    Windows that will not bring up the window. So I try to hide the window
    as follows:
    info = subprocess.STARTUPINFO()
    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE
    proc = subprocess.Popen(..., startupinfo=info)
    This works, in a way, but doesn't work recursively. I.e. if the
    started process itself starts a window, that second window will not be
    hidden. This even applies to dialog boxes within the application. So
    instead of a lot of windows popping up I now get a lot of disembodied
    dialogs appearing, which is a slight improvement but not much.
    Also, certain processes (e.g. tkdiff) seem to ignore the directive to
    be hidden altogether.
    This is dead easy on UNIX with virtual displays like Xvfb. Can someone
    shed any light if it's possible on Windows from python?
    Regards,
    Geoff Bache
    I'm confused. Why would you create a GUI if you're not going to
    actually display it? Isn't that the point of a GUI? Or are you talking
    about the command window popping up?
    Mike
    Only in the context of testing it. If I run lots of GUI tests on my
    computer I want
    the tested GUIs to remain hidden so I can still use my computer in the
    meantime...

    Though if you can tell me how to stop the command window popping up on
    Windows
    I'll be grateful for that too (though it wasn't the original
    question).

    Geoff
    Which GUI toolkit are you using? Tkinter, wxPython, pyQt? As for
    losing the command window on Windows, the best way that I know of is
    to just change the extension of the python file itself from *.py to
    *.pyw . I'm pretty sure you can suppress command windows if you're
    calling them from the command line using a flag, but I can't recall
    the flag off the top of my head.

    One way to test while still being able to use your computer is to
    install a virtual machine with VMWare or some similar product. I use
    VMWare's free software for testing some of my scripts, but I've heard
    that Microsoft's got a free virtual product that isn't half bad.

    Mike
  • Geoffbache at Aug 28, 2007 at 1:59 pm
    Which GUI toolkit are you using? Tkinter, wxPython, pyQt?
    Primarily PyGTK, but I was hoping it wouldn't matter. I hope to be
    able
    to start the process as indicated in the original post from within my
    test
    tool and instruct the subprocess to be hidden (or minimized? would
    that be easier?),
    irrespective of what it was (it might be a Java GUI or anything for
    all I care...)
    As for
    losing the command window on Windows, the best way that I know of is
    to just change the extension of the python file itself from *.py to
    *.pyw . I'm pretty sure you can suppress command windows if you're
    calling them from the command line using a flag, but I can't recall
    the flag off the top of my head.
    Thanks, that seemed to work.
    One way to test while still being able to use your computer is to
    install a virtual machine with VMWare or some similar product. I use
    VMWare's free software for testing some of my scripts, but I've heard
    that Microsoft's got a free virtual product that isn't half bad.
    OK. If all else fails I might try that. But if there is a solution to
    the original
    problem it would be nice not to have to install VMWare everywhere for
    convenient testing...

    Geoff
  • Kyosohma at Aug 28, 2007 at 2:20 pm

    On Aug 28, 8:59 am, geoffbache wrote:
    Which GUI toolkit are you using? Tkinter, wxPython, pyQt?
    Primarily PyGTK, but I was hoping it wouldn't matter. I hope to be
    able
    to start the process as indicated in the original post from within my
    test
    tool and instruct the subprocess to be hidden (or minimized? would
    that be easier?),
    irrespective of what it was (it might be a Java GUI or anything for
    all I care...)
    As for
    losing the command window on Windows, the best way that I know of is
    to just change the extension of the python file itself from *.py to
    *.pyw . I'm pretty sure you can suppress command windows if you're
    calling them from the command line using a flag, but I can't recall
    the flag off the top of my head.
    Thanks, that seemed to work.
    One way to test while still being able to use your computer is to
    install a virtual machine with VMWare or some similar product. I use
    VMWare's free software for testing some of my scripts, but I've heard
    that Microsoft's got a free virtual product that isn't half bad.
    OK. If all else fails I might try that. But if there is a solution to
    the original
    problem it would be nice not to have to install VMWare everywhere for
    convenient testing...

    Geoff
    I did a quick google and found the following, which probably only
    applies to Windows:

    http://www.tech-recipes.com/windows_tips512.html

    I know that with wxPython, you can tell it to whether or not to show
    the frame. Maybe pyGTK has the same functionality? This link seems to
    suggest that that maybe a valid option, but it doesn't detail how to
    accomplish it:

    http://www.daa.com.au/pipermail/pygtk/2000-August/000300.html

    This might be better: http://linuxgazette.net/issue78/krishnakumar.html

    Looks to me like you could just omit the "show" method. However, I
    have never used that particular toolkit. When you run stuff hidden
    like that, it can be difficult to kill them.

    Mike
  • Geoffbache at Aug 28, 2007 at 5:57 pm
    OK, more background needed. I develop the TextTest tool which is a
    generic test tool that starts tested applications from
    the command line. The idea is that it can handle any system under test
    at all, whatever language it's written in. Preferably
    without requiring a bunch of changes to the tested code before
    starting. I'd like to be able to pass some sort of flag to
    ensure that the system under test *and everything it starts* remain
    hidden.

    I can do as you suggest in my PyGTK GUI, of course, but that's only
    one system under test. A generic solution, if there
    is one, would be much better. I felt like there ought to be one
    because :

    a) It's easy on UNIX and
    b) I managed to hide the system under test fairly easily, just not its
    child windows and dialogs.

    Thanks for the help, anyway, it's another fallback if I can't find a
    solution.
  • Larry Bates at Aug 28, 2007 at 4:18 pm

    geoffbache wrote:
    Hi,

    As part of my efforts to write a test tool that copes with GUIs
    nicely, I'm trying to establish how I can start a GUI process on
    Windows that will not bring up the window. So I try to hide the window
    as follows:

    info = subprocess.STARTUPINFO()
    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE

    proc = subprocess.Popen(..., startupinfo=info)

    This works, in a way, but doesn't work recursively. I.e. if the
    started process itself starts a window, that second window will not be
    hidden. This even applies to dialog boxes within the application. So
    instead of a lot of windows popping up I now get a lot of disembodied
    dialogs appearing, which is a slight improvement but not much.

    Also, certain processes (e.g. tkdiff) seem to ignore the directive to
    be hidden altogether.

    This is dead easy on UNIX with virtual displays like Xvfb. Can someone
    shed any light if it's possible on Windows from python?

    Regards,
    Geoff Bache
    While I'm not entirely sure I understand what you want, I think you can
    accomplish it by using win32CreateProcess instead of subprocess. You can run
    the application minimized or perhaps in a REALLY small window. If you have
    modal dialog boxes, I don't think you can do anything as they don't run in the
    parent windows frame but rather outside (I could be wrong about this).

    -Larry
  • Geoffbache at Aug 28, 2007 at 6:13 pm

    On 28 Aug, 18:18, Larry Bates wrote:
    geoffbache wrote:
    Hi,
    As part of my efforts to write a test tool that copes with GUIs
    nicely, I'm trying to establish how I can start a GUI process on
    Windows that will not bring up the window. So I try to hide the window
    as follows:
    info = subprocess.STARTUPINFO()
    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE
    proc = subprocess.Popen(..., startupinfo=info)
    This works, in a way, but doesn't work recursively. I.e. if the
    started process itself starts a window, that second window will not be
    hidden. This even applies to dialog boxes within the application. So
    instead of a lot of windows popping up I now get a lot of disembodied
    dialogs appearing, which is a slight improvement but not much.
    Also, certain processes (e.g. tkdiff) seem to ignore the directive to
    be hidden altogether.
    This is dead easy on UNIX with virtual displays like Xvfb. Can someone
    shed any light if it's possible on Windows from python?
    Regards,
    Geoff Bache
    While I'm not entirely sure I understand what you want, I think you can
    accomplish it by using win32CreateProcess instead of subprocess. You can run
    the application minimized or perhaps in a REALLY small window. If you have
    modal dialog boxes, I don't think you can do anything as they don't run in the
    parent windows frame but rather outside (I could be wrong about this).

    -Larry
    Hi Larry,

    I don't know if that would help. I've tried running minimized from the
    command line as
    suggested by Mike and that has the same issue (child windows and
    dialogs don't get minimized)
    So the question is moving away from how to technically achieve this in
    Python to whether
    Windows even supports it...

    Geoff
  • Roger Upole at Aug 29, 2007 at 1:21 am

    geoffbache wrote:
    On 28 Aug, 18:18, Larry Bates wrote:
    geoffbache wrote:
    Hi,
    As part of my efforts to write a test tool that copes with GUIs
    nicely, I'm trying to establish how I can start a GUI process on
    Windows that will not bring up the window. So I try to hide the window
    as follows:
    info = subprocess.STARTUPINFO()
    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE
    proc = subprocess.Popen(..., startupinfo=info)
    This works, in a way, but doesn't work recursively. I.e. if the
    started process itself starts a window, that second window will not be
    hidden. This even applies to dialog boxes within the application. So
    instead of a lot of windows popping up I now get a lot of disembodied
    dialogs appearing, which is a slight improvement but not much.
    Also, certain processes (e.g. tkdiff) seem to ignore the directive to
    be hidden altogether.
    This is dead easy on UNIX with virtual displays like Xvfb. Can someone
    shed any light if it's possible on Windows from python?
    Regards,
    Geoff Bache
    While I'm not entirely sure I understand what you want, I think you can
    accomplish it by using win32CreateProcess instead of subprocess. You can run
    the application minimized or perhaps in a REALLY small window. If you have
    modal dialog boxes, I don't think you can do anything as they don't run in the
    parent windows frame but rather outside (I could be wrong about this).

    -Larry
    Hi Larry,

    I don't know if that would help. I've tried running minimized from the
    command line as
    suggested by Mike and that has the same issue (child windows and
    dialogs don't get minimized)
    So the question is moving away from how to technically achieve this in
    Python to whether
    Windows even supports it...

    Geoff
    You might want to look into running the tests on a separate desktop (or possibly
    even a new window station).

    Roger
  • Kyosohma at Aug 29, 2007 at 1:31 pm

    On Aug 28, 1:13 pm, geoffbache wrote:
    On 28 Aug, 18:18, Larry Bates wrote:


    geoffbache wrote:
    Hi,
    As part of my efforts to write a test tool that copes with GUIs
    nicely, I'm trying to establish how I can start a GUI process on
    Windows that will not bring up the window. So I try to hide the window
    as follows:
    info = subprocess.STARTUPINFO()
    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    info.wShowWindow = subprocess.SW_HIDE
    proc = subprocess.Popen(..., startupinfo=info)
    This works, in a way, but doesn't work recursively. I.e. if the
    started process itself starts a window, that second window will not be
    hidden. This even applies to dialog boxes within the application. So
    instead of a lot of windows popping up I now get a lot of disembodied
    dialogs appearing, which is a slight improvement but not much.
    Also, certain processes (e.g. tkdiff) seem to ignore the directive to
    be hidden altogether.
    This is dead easy on UNIX with virtual displays like Xvfb. Can someone
    shed any light if it's possible on Windows from python?
    Regards,
    Geoff Bache
    While I'm not entirely sure I understand what you want, I think you can
    accomplish it by using win32CreateProcess instead of subprocess. You can run
    the application minimized or perhaps in a REALLY small window. If you have
    modal dialog boxes, I don't think you can do anything as they don't run in the
    parent windows frame but rather outside (I could be wrong about this).
    -Larry
    Hi Larry,

    I don't know if that would help. I've tried running minimized from the
    command line as
    suggested by Mike and that has the same issue (child windows and
    dialogs don't get minimized)
    So the question is moving away from how to technically achieve this in
    Python to whether
    Windows even supports it...

    Geoff
    I just discovered Tim Golden's recipe for running processes minimized:
    http://tgolden.sc.sabren.com/python/wmi_cookbook.html#run-process-minimised

    I haven't tested it, but his stuff usually works. However, it may have
    the same issues with modal dialogs that my other suggestion had.

    Mike
  • David at Sep 3, 2007 at 12:55 am

    geoffbache wrote:

    As part of my efforts to write a test tool that copes with GUIs
    This is dead easy on UNIX with virtual displays like Xvfb.
    Can someone shed any light if it's possible on Windows
    Configure the virtual display first:
    http://en.wikipedia.org/wiki/Virtual_desktop

    Alternatively, run the process in a separate gui.
    Terminal Server client is one way to do that.

    [david]

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 27, '07 at 8:21p
activeSep 3, '07 at 12:55a
posts12
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase