blob: e86b578ce07aadd0aa2142b3a4deb9b8ddb91c0e [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
Neal Norwitz178f9062005-10-04 03:31:01 +000014Under \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
Georg Brandl23929f22006-01-20 21:03:35 +000022a list part contains the string \code{\%s}, then it is
23interpreted as a literal browser command line to be used with the argument URL
24substituted for \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
Neal Norwitz178f9062005-10-04 03:31:01 +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
Neal Norwitz178f9062005-10-04 03:31:01 +000031windows on the display. If remote browsers are not available on \UNIX{},
Georg Brandle8f24432005-10-03 14:16:44 +000032the 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
Neal Norwitz178f9062005-10-04 03:31:01 +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 Brandl23929f22006-01-20 21:03:35 +000055\versionchanged[\var{new} can now be 2]{2.5}
Fred Drakee4dbb862000-07-07 03:36:12 +000056\end{funcdesc}
57
Neal Norwitz178f9062005-10-04 03:31:01 +000058\begin{funcdesc}{open_new}{url}
Fred Drakee4dbb862000-07-07 03:36:12 +000059 Open \var{url} in a new window of the default browser, if possible,
Neal Norwitz178f9062005-10-04 03:31:01 +000060 otherwise, open \var{url} in the only browser window.
Georg Brandle8f24432005-10-03 14:16:44 +000061\end{funcdesc}
62
63\begin{funcdesc}{open_new_tab}{url}
64 Open \var{url} in a new page ("tab") of the default browser, if possible,
Neal Norwitz178f9062005-10-04 03:31:01 +000065 otherwise equivalent to \function{open_new}.
66\versionadded{2.5}
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')}}{}
Georg Brandl23929f22006-01-20 21:03:35 +000099 \lineiii{'skipstone'}{\class{BackgroundBrowser('skipstone')}}{}
100 \lineiii{'kfmclient'}{\class{Konqueror()}}{(1)}
Georg Brandle8f24432005-10-03 14:16:44 +0000101 \lineiii{'konqueror'}{\class{Konqueror()}}{(1)}
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +0000102 \lineiii{'kfm'}{\class{Konqueror()}}{(1)}
Georg Brandl23929f22006-01-20 21:03:35 +0000103 \lineiii{'mosaic'}{\class{BackgroundBrowser('mosaic')}}{}
Georg Brandle8f24432005-10-03 14:16:44 +0000104 \lineiii{'opera'}{\class{Opera()}}{}
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +0000105 \lineiii{'grail'}{\class{Grail()}}{}
Georg Brandl23929f22006-01-20 21:03:35 +0000106 \lineiii{'links'}{\class{GenericBrowser('links')}}{}
Georg Brandle8f24432005-10-03 14:16:44 +0000107 \lineiii{'elinks'}{\class{Elinks('elinks')}}{}
Georg Brandl23929f22006-01-20 21:03:35 +0000108 \lineiii{'lynx'}{\class{GenericBrowser('lynx')}}{}
109 \lineiii{'w3m'}{\class{GenericBrowser('w3m')}}{}
Fred Drakec826ecb2000-07-07 17:08:40 +0000110 \lineiii{'windows-default'}{\class{WindowsDefault}}{(2)}
111 \lineiii{'internet-config'}{\class{InternetConfig}}{(3)}
Georg Brandle8f24432005-10-03 14:16:44 +0000112 \lineiii{'macosx'}{\class{MacOSX('default')}}{(4)}
Fred Drakee4dbb862000-07-07 03:36:12 +0000113\end{tableiii}
114
115\noindent
116Notes:
117
118\begin{description}
119\item[(1)]
Eric S. Raymondf79cb2d2001-01-23 13:49:44 +0000120``Konqueror'' is the file manager for the KDE desktop environment for
Neal Norwitz178f9062005-10-04 03:31:01 +0000121\UNIX{}, and only makes sense to use if KDE is running. Some way of
Fred Drakef6791f32000-10-02 03:42:43 +0000122reliably detecting KDE would be nice; the \envvar{KDEDIR} variable is
Fred Drake21e036c2001-03-26 16:17:21 +0000123not sufficient. Note also that the name ``kfm'' is used even when
124using the \program{konqueror} command with KDE 2 --- the
125implementation selects the best strategy for running Konqueror.
Fred Drakec826ecb2000-07-07 17:08:40 +0000126
127\item[(2)]
Georg Brandle8f24432005-10-03 14:16:44 +0000128Only on Windows platforms.
Fred Drakee4dbb862000-07-07 03:36:12 +0000129
Fred Drakec826ecb2000-07-07 17:08:40 +0000130\item[(3)]
Fred Drakee4dbb862000-07-07 03:36:12 +0000131Only on MacOS platforms; requires the standard MacPython \module{ic}
132module, described in the \citetitle[../mac/module-ic.html]{Macintosh
133Library Modules} manual.
Georg Brandle8f24432005-10-03 14:16:44 +0000134
135\item[(4)]
136Only on MacOS X platform.
Fred Drakee4dbb862000-07-07 03:36:12 +0000137\end{description}
138
139
140\subsection{Browser Controller Objects \label{browser-controllers}}
141
142Browser controllers provide two methods which parallel two of the
143module-level convenience functions:
144
Neal Norwitz178f9062005-10-04 03:31:01 +0000145\begin{funcdesc}{open}{url\optional{, new\optional{, autoraise=1}}}
Georg Brandle8f24432005-10-03 14:16:44 +0000146 Display \var{url} using the browser handled by this controller.
147 If \var{new} is 1, a new browser window is opened if possible.
148 If \var{new} is 2, a new browser page ("tab") is opened if possible.
Fred Drakee4dbb862000-07-07 03:36:12 +0000149\end{funcdesc}
150
Neal Norwitz178f9062005-10-04 03:31:01 +0000151\begin{funcdesc}{open_new}{url}
Fred Drakee4dbb862000-07-07 03:36:12 +0000152 Open \var{url} in a new window of the browser handled by this
153 controller, if possible, otherwise, open \var{url} in the only
Georg Brandle8f24432005-10-03 14:16:44 +0000154 browser window. Alias \function{open_new}.
155\end{funcdesc}
156
157\begin{funcdesc}{open_new_tab}{url}
158 Open \var{url} in a new page ("tab") of the browser handled by this
Neal Norwitz178f9062005-10-04 03:31:01 +0000159 controller, if possible, otherwise equivalent to \function{open_new}.
160\versionadded{2.5}
Fred Drakee4dbb862000-07-07 03:36:12 +0000161\end{funcdesc}