blob: 58dd604015003c20bf39ac772012dfa525a2c288 [file] [log] [blame]
Fred Drakee4dbb862000-07-07 03:36:12 +00001\section{\module{webbrowser} ---
2 Convenient Web-browser controller}
3
4\declaremodule{standard}{webbrowser}
5\modulesynopsis{Easy-to-use controller for Web browsers.}
6\moduleauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
7\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
8
9The \module{webbrowser} module provides a very high-level interface to
10allow displaying Web-based documents to users. The controller objects
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000011are easy to use and are platform-independent. Under most
12circumstances, simply calling the \function{open()} function from this
13module will do the right thing.
Fred Drakee4dbb862000-07-07 03:36:12 +000014
15Under \UNIX, graphical browsers are preferred under X11, but text-mode
Fred Drakef6791f32000-10-02 03:42:43 +000016browsers will be used if graphical browsers are not available or an X11
Fred Drakee4dbb862000-07-07 03:36:12 +000017display isn't available. If text-mode browsers are used, the calling
18process will block until the user exits the browser.
19
Eric S. Raymondf7f18512001-01-23 13:16:32 +000020Under \UNIX, if the environment variable \envvar{BROWSER} exists, it
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000021is interpreted to override the platform default list of browsers, as a
Eric S. Raymondf7f18512001-01-23 13:16:32 +000022colon-separated list of browsers to try in order. When the value of
23a list part contains the string \code{\%s}, then it is interpreted as
24a literal browser command line to be used with the argument URL
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000025substituted for the \code{\%s}; if the part does not contain
Eric S. Raymondf7f18512001-01-23 13:16:32 +000026\code{\%s}, it is simply interpreted as the name of the browser to
27launch.
28
Fred Drakee4dbb862000-07-07 03:36:12 +000029For non-\UNIX{} platforms, or when X11 browsers are available on
30\UNIX, the controlling process will not wait for the user to finish
31with the browser, but allow the browser to maintain its own window on
32the display.
33
34The following exception is defined:
35
36\begin{excdesc}{Error}
37 Exception raised when a browser control error occurs.
38\end{excdesc}
39
40The following functions are defined:
41
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000042\begin{funcdesc}{open}{url\optional{, new=0}\optional{, autoraise=1}}
Fred Drakee4dbb862000-07-07 03:36:12 +000043 Display \var{url} using the default browser. If \var{new} is true,
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000044 a new browser window is opened if possible. If \var{autoraise} is
45 true, the window is raised if possible (note that under many window
46 managers this will occur regardless of the setting of this variable).
Fred Drakee4dbb862000-07-07 03:36:12 +000047\end{funcdesc}
48
49\begin{funcdesc}{open_new}{url}
50 Open \var{url} in a new window of the default browser, if possible,
Eric S. Raymondf7f18512001-01-23 13:16:32 +000051 otherwise, open \var{url} in the only browser window. (This entry
52 point is deprecated and may be removed in 2.1.)
Fred Drakee4dbb862000-07-07 03:36:12 +000053\end{funcdesc}
54
55\begin{funcdesc}{get}{\optional{name}}
Eric S. Raymondf7f18512001-01-23 13:16:32 +000056 Return a controller object for the browser type \var{name}. If
57 \var{name} is empty, return a controller for a default browser
Eric S. Raymondaeb55322001-01-23 13:22:28 +000058 appropriate to the caller's environment.
Fred Drakee4dbb862000-07-07 03:36:12 +000059\end{funcdesc}
60
Fred Drake246f65f2000-10-23 15:41:13 +000061\begin{funcdesc}{register}{name, constructor\optional{, instance}}
Fred Drakee4dbb862000-07-07 03:36:12 +000062 Register the browser type \var{name}. Once a browser type is
63 registered, the \function{get()} function can return a controller
64 for that browser type. If \var{instance} is not provided, or is
65 \code{None}, \var{constructor} will be called without parameters to
66 create an instance when needed. If \var{instance} is provided,
67 \var{constructor} will never be called, and may be \code{None}.
Eric S. Raymondf7f18512001-01-23 13:16:32 +000068
69 This entry point is only useful if you plan to either set the
70 \envvar{BROWSER} variable or call \function{get} with a nonempty
71 argument matching the name of a handler you declare.
Fred Drakee4dbb862000-07-07 03:36:12 +000072\end{funcdesc}
73
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000074A number of browser types are predefined. This table gives the type
75names that may be passed to the \function{get()} function and the
76corresponding instantiations for the controller classes, all defined
77in this module.
Fred Drakee4dbb862000-07-07 03:36:12 +000078
79\begin{tableiii}{l|l|c}{code}{Type Name}{Class Name}{Notes}
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000080 \lineiii{'mozilla'}{\class{Netscape('mozilla')}}{}
81 \lineiii{'netscape'}{\class{Netscape('netscape')}}{}
82 \lineiii{'mosaic'}{\class{GenericBrowser('mosaic \%s &')}}{}
83 \lineiii{'kfm'}{\class{Konqueror()}}{(1)}
84 \lineiii{'grail'}{\class{Grail()}}{}
85 \lineiii{'links'}{\class{GenericBrowser('links \%s')}}{}
86 \lineiii{'lynx'}{\class{GenericBrowser('lynx \%s')}}{}
87 \lineiii{'w3m'}{\class{GenericBrowser('w3m \%s')}}{}
Fred Drakec826ecb2000-07-07 17:08:40 +000088 \lineiii{'windows-default'}{\class{WindowsDefault}}{(2)}
89 \lineiii{'internet-config'}{\class{InternetConfig}}{(3)}
Fred Drakee4dbb862000-07-07 03:36:12 +000090\end{tableiii}
91
92\noindent
93Notes:
94
95\begin{description}
96\item[(1)]
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000097``Konqueror'' is the file manager for the KDE desktop environment for
Fred Drakef6791f32000-10-02 03:42:43 +000098UNIX, and only makes sense to use if KDE is running. Some way of
99reliably detecting KDE would be nice; the \envvar{KDEDIR} variable is
100not sufficient.
Fred Drakec826ecb2000-07-07 17:08:40 +0000101
102\item[(2)]
Fred Drakee4dbb862000-07-07 03:36:12 +0000103Only on Windows platforms; requires the common
104extension modules \module{win32api} and \module{win32con}.
105
Fred Drakec826ecb2000-07-07 17:08:40 +0000106\item[(3)]
Fred Drakee4dbb862000-07-07 03:36:12 +0000107Only on MacOS platforms; requires the standard MacPython \module{ic}
108module, described in the \citetitle[../mac/module-ic.html]{Macintosh
109Library Modules} manual.
110\end{description}
111
112
113\subsection{Browser Controller Objects \label{browser-controllers}}
114
115Browser controllers provide two methods which parallel two of the
116module-level convenience functions:
117
118\begin{funcdesc}{open}{url\optional{, new}}
119 Display \var{url} using the browser handled by this controller. If
120 \var{new} is true, a new browser window is opened if possible.
121\end{funcdesc}
122
123\begin{funcdesc}{open_new}{url}
124 Open \var{url} in a new window of the browser handled by this
125 controller, if possible, otherwise, open \var{url} in the only
Eric S. Raymondf7f18512001-01-23 13:16:32 +0000126 browser window. (This method is deprecated and may be removed in
127 2.1.)
Fred Drakee4dbb862000-07-07 03:36:12 +0000128\end{funcdesc}