summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2000-09-22 10:05:54 (GMT)
committerTim Peters <tim.peters@gmail.com>2000-09-22 10:05:54 (GMT)
commitf58a7aafea13f9214065bf5d97855cfce154d1c3 (patch)
tree65662afed654a792b562cc28c7c36bb7b6cce930
parent7fa7da861a3287594b2e9d6de5dab7d3cb4b0784 (diff)
downloadcpython-f58a7aafea13f9214065bf5d97855cfce154d1c3.zip
cpython-f58a7aafea13f9214065bf5d97855cfce154d1c3.tar.gz
cpython-f58a7aafea13f9214065bf5d97855cfce154d1c3.tar.bz2
Implemented new os.startfile function, unique to Windows, exposing a
subset of Win32 ShellExecute's functionality. Guido wants this because IDLE's Help -> Docs function currently crashes his machine because of a conflict between his version of Norton AntiVirus (6.10.20) and MS's _popen. Docs for startfile are being mailed to Fred (or just read the docstring -- it tells the whole story). Changed webbrowser.py to use os.startfile instead of os.popen on Windows. Changed IDLE's EditorWindow.py to pass an absolute path for the docs (hardcoding ShellExecute's "directory" arg to "." as used to be done let IDLE work, but made the startfile command exceedingly obscure for other uses -- the MS docs are terrible, of course, & still not sure I understand it). Note that Windows Python must link with shell32.lib now! That's where ShellExecute lives.
-rw-r--r--Lib/webbrowser.py2
-rw-r--r--Modules/posixmodule.c33
-rw-r--r--PCbuild/python20.dsp4
-rw-r--r--Tools/idle/EditorWindow.py5
4 files changed, 39 insertions, 5 deletions
diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index 66cdbff..a8b0e8b 100644
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -183,7 +183,7 @@ register("grail", Grail)
class WindowsDefault:
def open(self, url, new=0):
- self.junk = os.popen("start " + url)
+ os.startfile(url)
def open_new(self, url):
self.open(url)
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e46d68a..71a880f 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5102,6 +5102,38 @@ posix_abort(PyObject *self, PyObject *args)
return NULL;
}
+#ifdef MS_WIN32
+static char win32_startfile__doc__[] = "\
+startfile(filepath) - Start a file with its associated application.\n\
+\n\
+This acts like double-clicking the file in Explorer, or giving the file\n\
+name as an argument to the DOS \"start\" command: the file is opened\n\
+with whatever application (if any) its extension is associated.\n\
+\n\
+startfile returns as soon as the associated application is launched.\n\
+There is no option to wait for the application to close, and no way\n\
+to retrieve the application's exit status.\n\
+\n\
+The filepath is relative to the current directory. If you want to use\n\
+an absolute path, make sure the first character is not a slash (\"/\");\n\
+the underlying Win32 ShellExecute function doesn't work if it is.";
+
+static PyObject *
+win32_startfile(PyObject *self, PyObject *args)
+{
+ char *filepath;
+ HINSTANCE rc;
+ if (!PyArg_ParseTuple(args, "s:startfile", &filepath))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ rc = ShellExecute((HWND)0, NULL, filepath, NULL, NULL, SW_SHOWNORMAL);
+ Py_END_ALLOW_THREADS
+ if (rc <= (HINSTANCE)32)
+ return win32_error("startfile", filepath);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+#endif
static PyMethodDef posix_methods[] = {
{"access", posix_access, METH_VARARGS, posix_access__doc__},
@@ -5205,6 +5237,7 @@ static PyMethodDef posix_methods[] = {
{"popen2", win32_popen2, METH_VARARGS},
{"popen3", win32_popen3, METH_VARARGS},
{"popen4", win32_popen4, METH_VARARGS},
+ {"startfile", win32_startfile, METH_VARARGS, win32_startfile__doc__},
#endif
#endif /* HAVE_POPEN */
#ifdef HAVE_SETUID
diff --git a/PCbuild/python20.dsp b/PCbuild/python20.dsp
index 4ad5c30..f6e2113 100644
--- a/PCbuild/python20.dsp
+++ b/PCbuild/python20.dsp
@@ -57,7 +57,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
-# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib /nologo /base:"0x1e100000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc"
+# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e100000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc"
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "python20 - Win32 Debug"
@@ -88,7 +88,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib /nologo /base:"0x1e100000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python20_d.dll" /pdbtype:sept
+# ADD LINK32 largeint.lib kernel32.lib user32.lib advapi32.lib shell32.lib /nologo /base:"0x1e100000" /subsystem:windows /dll /debug /machine:I386 /nodefaultlib:"libc" /out:"./python20_d.dll" /pdbtype:sept
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "python20 - Win32 Alpha Debug"
diff --git a/Tools/idle/EditorWindow.py b/Tools/idle/EditorWindow.py
index 5feda4b..589b0ab 100644
--- a/Tools/idle/EditorWindow.py
+++ b/Tools/idle/EditorWindow.py
@@ -297,8 +297,9 @@ class EditorWindow:
help_url = "http://www.python.org/doc/current/"
if sys.platform[:3] == "win":
- fn = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
- fn = os.path.join(fn, "Doc", "index.html")
+ fn = os.path.dirname(__file__)
+ fn = os.path.join(fn, "../../Doc/index.html")
+ fn = os.path.normpath(fn)
if os.path.isfile(fn):
help_url = fn
del fn