blob: 42c76912b039919dd7d36cd08cab8b5947b8c164 [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
Georg Brandle8f24432005-10-03 14:16:44 +00009The \module{webbrowser} module provides a high-level interface to
10allow displaying Web-based documents to users. Under most
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000011circumstances, simply calling the \function{open()} function from this
12module will do the right thing.
Fred Drakee4dbb862000-07-07 03:36:12 +000013
14Under \UNIX, graphical browsers are preferred under X11, but text-mode
Fred Drakef6791f32000-10-02 03:42:43 +000015browsers will be used if graphical browsers are not available or an X11
Fred Drakee4dbb862000-07-07 03:36:12 +000016display isn't available. If text-mode browsers are used, the calling
17process will block until the user exits the browser.
18
Georg Brandle8f24432005-10-03 14:16:44 +000019If the environment variable \envvar{BROWSER} exists, it
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000020is interpreted to override the platform default list of browsers, as a
Georg Brandle8f24432005-10-03 14:16:44 +000021os.pathsep-separated list of browsers to try in order. When the value of
Eric S. Raymondf7f18512001-01-23 13:16:32 +000022a list part contains the string \code{\%s}, then it is interpreted as
23a literal browser command line to be used with the argument URL
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000024substituted for the \code{\%s}; if the part does not contain
Eric S. Raymondf7f18512001-01-23 13:16:32 +000025\code{\%s}, it is simply interpreted as the name of the browser to
26launch.
27
Georg Brandle8f24432005-10-03 14:16:44 +000028For non-\UNIX{} platforms, or when a remote browser is available on
Fred Drakee4dbb862000-07-07 03:36:12 +000029\UNIX, the controlling process will not wait for the user to finish
Georg Brandle8f24432005-10-03 14:16:44 +000030with the browser, but allow the remote browser to maintain its own
31windows on the display. If remote browsers are not available on \UNIX,
32the controlling process will launch a new browser and wait.
33
34The script \program{webbrowser} can be used as a command-line interface
35for the module. It accepts an URL as the argument. It accepts the following
36optional parameters: \programopt{-n} opens the URL in a new browser window,
37if possible; \programopt{-t} opens the URL in a new browser page ("tab"). The
38options are, naturally, mutually exclusive.
Fred Drakee4dbb862000-07-07 03:36:12 +000039
40The following exception is defined:
41
42\begin{excdesc}{Error}
43 Exception raised when a browser control error occurs.
44\end{excdesc}
45
46The following functions are defined:
47
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000048\begin{funcdesc}{open}{url\optional{, new=0}\optional{, autoraise=1}}
Georg Brandle8f24432005-10-03 14:16:44 +000049 Display \var{url} using the default browser. If \var{new} is 0, the
50 \var{url} is opened in the same browser window. If \var{new} is 1,
51 a new browser window is opened if possible. If \var{new} is 2,
52 a new browser page ("tab") is opened if possible. If \var{autoraise} is
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000053 true, the window is raised if possible (note that under many window
54 managers this will occur regardless of the setting of this variable).
Georg Brandle8f24432005-10-03 14:16:44 +000055
Fred Drakee4dbb862000-07-07 03:36:12 +000056\end{funcdesc}
57
Georg Brandle8f24432005-10-03 14:16:44 +000058\begin{funcdesc}{open_new_win}{url}
Fred Drakee4dbb862000-07-07 03:36:12 +000059 Open \var{url} in a new window of the default browser, if possible,
Georg Brandle8f24432005-10-03 14:16:44 +000060 otherwise, open \var{url} in the only browser window. Alias
61 \function{open_new}.
62\end{funcdesc}
63
64\begin{funcdesc}{open_new_tab}{url}
65 Open \var{url} in a new page ("tab") of the default browser, if possible,
66 otherwise equivalent to \function{open_new_win}.
Fred Drakee4dbb862000-07-07 03:36:12 +000067\end{funcdesc}
68
69\begin{funcdesc}{get}{\optional{name}}
Eric S. Raymondf7f18512001-01-23 13:16:32 +000070 Return a controller object for the browser type \var{name}. If
71 \var{name} is empty, return a controller for a default browser
Eric S. Raymondaeb55322001-01-23 13:22:28 +000072 appropriate to the caller's environment.
Fred Drakee4dbb862000-07-07 03:36:12 +000073\end{funcdesc}
74
Fred Drake246f65f2000-10-23 15:41:13 +000075\begin{funcdesc}{register}{name, constructor\optional{, instance}}
Fred Drakee4dbb862000-07-07 03:36:12 +000076 Register the browser type \var{name}. Once a browser type is
77 registered, the \function{get()} function can return a controller
78 for that browser type. If \var{instance} is not provided, or is
79 \code{None}, \var{constructor} will be called without parameters to
80 create an instance when needed. If \var{instance} is provided,
81 \var{constructor} will never be called, and may be \code{None}.
Eric S. Raymondf7f18512001-01-23 13:16:32 +000082
83 This entry point is only useful if you plan to either set the
84 \envvar{BROWSER} variable or call \function{get} with a nonempty
Georg Brandle8f24432005-10-03 14:16:44 +000085 argument matching the name of a handler you declare.
Fred Drakee4dbb862000-07-07 03:36:12 +000086\end{funcdesc}
87
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +000088A number of browser types are predefined. This table gives the type
89names that may be passed to the \function{get()} function and the
90corresponding instantiations for the controller classes, all defined
91in this module.
Fred Drakee4dbb862000-07-07 03:36:12 +000092
93\begin{tableiii}{l|l|c}{code}{Type Name}{Class Name}{Notes}
Georg Brandle8f24432005-10-03 14:16:44 +000094 \lineiii{'mozilla'}{\class{Mozilla('mozilla')}}{}
95 \lineiii{'firefox'}{\class{Mozilla('mozilla')}}{}
96 \lineiii{'netscape'}{\class{Mozilla('netscape')}}{}
97 \lineiii{'galeon'}{\class{Galeon('galeon')}}{}
98 \lineiii{'epiphany'}{\class{Galeon('epiphany')}}{}
99 \lineiii{'skipstone'}{\class{GenericBrowser('skipstone \%s \&')}}{}
100 \lineiii{'konqueror'}{\class{Konqueror()}}{(1)}
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +0000101 \lineiii{'kfm'}{\class{Konqueror()}}{(1)}
Georg Brandle8f24432005-10-03 14:16:44 +0000102 \lineiii{'mosaic'}{\class{GenericBrowser('mosaic \%s \&')}}{}
103 \lineiii{'opera'}{\class{Opera()}}{}
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +0000104 \lineiii{'grail'}{\class{Grail()}}{}
105 \lineiii{'links'}{\class{GenericBrowser('links \%s')}}{}
Georg Brandle8f24432005-10-03 14:16:44 +0000106 \lineiii{'elinks'}{\class{Elinks('elinks')}}{}
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +0000107 \lineiii{'lynx'}{\class{GenericBrowser('lynx \%s')}}{}
108 \lineiii{'w3m'}{\class{GenericBrowser('w3m \%s')}}{}
Fred Drakec826ecb2000-07-07 17:08:40 +0000109 \lineiii{'windows-default'}{\class{WindowsDefault}}{(2)}
110 \lineiii{'internet-config'}{\class{InternetConfig}}{(3)}
Georg Brandle8f24432005-10-03 14:16:44 +0000111 \lineiii{'macosx'}{\class{MacOSX('default')}}{(4)}
Fred Drakee4dbb862000-07-07 03:36:12 +0000112\end{tableiii}
113
114\noindent
115Notes:
116
117\begin{description}
118\item[(1)]
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +0000119``Konqueror'' is the file manager for the KDE desktop environment for
Fred Drakef6791f32000-10-02 03:42:43 +0000120UNIX, and only makes sense to use if KDE is running. Some way of
121reliably detecting KDE would be nice; the \envvar{KDEDIR} variable is
Fred Drake21e036c2001-03-26 16:17:21 +0000122not sufficient. Note also that the name ``kfm'' is used even when
123using the \program{konqueror} command with KDE 2 --- the
124implementation selects the best strategy for running Konqueror.
Fred Drakec826ecb2000-07-07 17:08:40 +0000125
126\item[(2)]
Georg Brandle8f24432005-10-03 14:16:44 +0000127Only on Windows platforms.
Fred Drakee4dbb862000-07-07 03:36:12 +0000128
Fred Drakec826ecb2000-07-07 17:08:40 +0000129\item[(3)]
Fred Drakee4dbb862000-07-07 03:36:12 +0000130Only on MacOS platforms; requires the standard MacPython \module{ic}
131module, described in the \citetitle[../mac/module-ic.html]{Macintosh
132Library Modules} manual.
Georg Brandle8f24432005-10-03 14:16:44 +0000133
134\item[(4)]
135Only on MacOS X platform.
Fred Drakee4dbb862000-07-07 03:36:12 +0000136\end{description}
137
138
139\subsection{Browser Controller Objects \label{browser-controllers}}
140
141Browser controllers provide two methods which parallel two of the
142module-level convenience functions:
143
144\begin{funcdesc}{open}{url\optional{, new}}
Georg Brandle8f24432005-10-03 14:16:44 +0000145 Display \var{url} using the browser handled by this controller.
146 If \var{new} is 1, a new browser window is opened if possible.
147 If \var{new} is 2, a new browser page ("tab") is opened if possible.
Fred Drakee4dbb862000-07-07 03:36:12 +0000148\end{funcdesc}
149
Georg Brandle8f24432005-10-03 14:16:44 +0000150\begin{funcdesc}{open_new_win}{url}
Fred Drakee4dbb862000-07-07 03:36:12 +0000151 Open \var{url} in a new window of the browser handled by this
152 controller, if possible, otherwise, open \var{url} in the only
Georg Brandle8f24432005-10-03 14:16:44 +0000153 browser window. Alias \function{open_new}.
154\end{funcdesc}
155
156\begin{funcdesc}{open_new_tab}{url}
157 Open \var{url} in a new page ("tab") of the browser handled by this
158 controller, if possible, otherwise equivalent to \function{open_new_win}.
Fred Drakee4dbb862000-07-07 03:36:12 +0000159\end{funcdesc}