PyQt calling an external app?

G

gregarican

What's the easiest and cleanest way of having PyQt bring up an external
application? In this case I am looking to launch Internet Explorer and
bring up a specific URL. I don't care about tracking the IE process'
activity and don't want PyQt to wait until the browser is closed. I
tried the following code from within a PyQt app:

import os

url = 'http://server.domain.com/page.html'
os.system('start %s' % url)

When I use this the PyQt app freezes up and only when I forcefully
close it does the browser window pop up. Then I looked into QThreads
and some other choices. Here's my latest attempt, using win32process:

import win32process

url='http://server.domain.com/page.html'
cmd_line = 'start %s' % url
win32process.CreateProcess(None, cmd_line, None, None,
1,win32process.CREATE_NEW_CONSOLE, None, None,
win32process.STARTUPINFO())

When I try this I get a message stating 'The system cannot find the
file specified' when the cmd_line is being interpreted. I am using
Python 2.3.5 on Windows 2000 Professional, with Qt 2.3.0 and PyQt 3.13.
Do I have to go to the lengths of implementing a QThread just to spawn
an external program I don't care about tracking?
 
P

Paul Boddie

[os.system using the start command on Windows]
When I use this the PyQt app freezes up and only when I forcefully
close it does the browser window pop up.

What does os.startfile do when invoked with the URL? My impression was
that the startfile function - available only on Windows - doesn't wait
for the command to finish, but I don't run Windows and can't test this.
Any feedback would be appreciated, though, since it's part of the
desktop module I proposed a while back:

http://www.python.org/pypi/desktop

Paul
 
G

gregarican

Paul said:
What does os.startfile do when invoked with the URL? My impression was
that the startfile function - available only on Windows - doesn't wait
for the command to finish, but I don't run Windows and can't test this.
Any feedback would be appreciated, though, since it's part of the
desktop module I proposed a while back:

http://www.python.org/pypi/desktop


Paul

Thanks! That worked perfectly. Sorry for all of the n00b questions, as
I'm only about a week or two into learning Python. I had about 1+ year
of experience coding in Ruby and am trying to translate a Qt app I
wrote in Ruby into Python. So there are some differences in each
language's Qt implementation. So far I am very impressed with Python's
maturity in terms of language consistency and available libraries. Plus
everyone is very responsive within the community.

Thanks again!
 
G

Giovanni Bajo

gregarican said:
What's the easiest and cleanest way of having PyQt bring up an
external application?

You can also go the Qt way and use QProcess. This also gives you cross-platform
communication and process killing capabilities which are pretty hard to obtain
(see the mess in Python with popen[1234]/subprocess). You also get nice signals
from the process which interact well in a Qt environment.
 
G

gregarican

Giovanni said:
You can also go the Qt way and use QProcess. This also gives you cross-platform
communication and process killing capabilities which are pretty hard to obtain
(see the mess in Python with popen[1234]/subprocess). You also get nice signals
from the process which interact well in a Qt environment.

Good point. I don't think that this particular class is available with
Qt 2.3.0, which is what I am using for my Sharp Zaurus and Win32
implementations of this app. Once I move up to the world of Qt 4 I will
definitely look into this as an option for certain things. My next
quest will be rewriting this app (again) so that it will run on Windows
Mobile PDA's using Python and Tkinter for the GUI. Since all of the
data pushes/pulls relies on XMLRPC it shouldn't be too daunting. Just
need to present the data nicely :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top