1 /* Document viewing for Python. */
11 #include "intl/gettext/libintl.h"
12 #include "protocol/uri.h"
13 #include "scripting/python/core.h"
14 #include "session/task.h"
15 #include "terminal/tab.h"
16 #include "util/error.h"
18 /* Python interface for viewing a document. */
20 static char python_open_doc
[] =
21 PYTHON_DOCSTRING("open(url, new_tab=False, background=False) -> None\n\
23 View a document in either the current tab or a new tab.\n\
27 url -- A string containing the URL to view.\n\
29 Optional keyword arguments:\n\
31 new_tab -- By default the URL is opened in the current tab. If this\n\
32 argument's value is the boolean True then the URL is instead\n\
33 opened in a new tab.\n\
34 background -- By default a new tab is opened in the foreground. If\n\
35 this argument's value is the boolean True then a new tab is\n\
36 instead opened in the background. This argument is ignored\n\
37 unless new_tab's value is True.\n");
40 python_open(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
43 int new_tab
= 0, background
= 0;
45 static char *kwlist
[] = {"url", "new_tab", "background", NULL
};
48 PyErr_SetString(python_elinks_err
, "No session");
52 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "s|ii:open",
54 &new_tab
, &background
))
59 PyErr_SetString(python_elinks_err
, N_("Internal error"));
63 uri
= get_translated_uri(url
, python_ses
->tab
->term
->cwd
);
65 PyErr_SetString(python_elinks_err
, N_("Bad URL syntax"));
70 open_uri_in_new_tab(python_ses
, uri
, background
, 0);
72 goto_uri(python_ses
, uri
);
80 static PyMethodDef open_methods
[] = {
81 {"open", (PyCFunction
) python_open
,
82 METH_VARARGS
| METH_KEYWORDS
,
89 python_init_open_interface(PyObject
*dict
, PyObject
*name
)
91 return add_python_methods(dict
, name
, open_methods
);