Rev 1718 | Rev 1752 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
82 | Franz | 1 | /*************************************************************************** |
2 | scriptplugin.cpp - description |
||
3 | ------------------- |
||
4 | begin : Thu Oct 3 08:00:00 CEST 2002 |
||
5 | copyright : (C) 2002 by Franz Schmid |
||
6 | email : Franz.Schmid@altmuehlnet.de |
||
7 | ***************************************************************************/ |
||
8 | |||
9 | /*************************************************************************** |
||
10 | * * |
||
11 | * This program is free software; you can redistribute it and/or modify * |
||
12 | * it under the terms of the GNU General Public License as published by * |
||
13 | * the Free Software Foundation; either version 2 of the License, or * |
||
14 | * (at your option) any later version. * |
||
15 | * * |
||
16 | ***************************************************************************/ |
||
792 | subik | 17 | |
18 | // include cmdvar.h first, as it pulls in <Python.h> |
||
19 | #include "cmdvar.h" |
||
20 | |||
103 | Franz | 21 | #include "cmddialog.h" |
22 | #include "cmddoc.h" |
||
23 | #include "cmdpage.h" |
||
24 | #include "cmdobj.h" |
||
25 | #include "cmdgetprop.h" |
||
26 | #include "cmdsetprop.h" |
||
27 | #include "cmdtext.h" |
||
28 | #include "cmdmani.h" |
||
29 | #include "cmdcolor.h" |
||
30 | #include "cmdmisc.h" |
||
1425 | subik | 31 | #include "cmdgetsetprop.h" |
82 | Franz | 32 | #include "scriptplugin.h" |
103 | Franz | 33 | #include "cmdutil.h" |
411 | Franz | 34 | #include "objprinter.h" |
418 | Franz | 35 | #include "objpdffile.h" |
1407 | subik | 36 | #include "objimageexport.h" |
203 | Franz | 37 | #include "guiapp.h" |
1718 | craig | 38 | #include "scriptercore.h" |
39 | |||
82 | Franz | 40 | #include "customfdialog.h" |
41 | #include "helpbrowser.h" |
||
265 | Franz | 42 | #include "mpalette.h" |
1525 | cbradney | 43 | #include "seiten.h" |
44 | #include "layers.h" |
||
1414 | fschmid | 45 | #include "tree.h" |
1269 | cbradney | 46 | #include "menumanager.h" |
47 | #include "scraction.h" |
||
1693 | craig | 48 | #include "scpaths.h" |
128 | Franz | 49 | |
1269 | cbradney | 50 | |
661 | fschmid | 51 | #ifdef _MSC_VER |
52 | #if (_MSC_VER >= 1200) |
||
53 | #include "win-config.h" |
||
54 | #endif |
||
128 | Franz | 55 | #else |
56 | #include "config.h" |
||
57 | #endif |
||
58 | |||
1425 | subik | 59 | #include <qapplication.h> |
82 | Franz | 60 | #include <qmessagebox.h> |
61 | #include <qtextcodec.h> |
||
62 | #include <qdom.h> |
||
63 | #include <qtextstream.h> |
||
64 | #include <cstdlib> |
||
65 | |||
853 | subik | 66 | #include <iostream> |
67 | |||
647 | fschmid | 68 | // Exceptions; visible from cmdvar.h, set up in initscribus() |
69 | PyObject* ScribusException; |
||
70 | PyObject* NoDocOpenError; |
||
853 | subik | 71 | PyObject* WrongFrameTypeError; |
72 | PyObject* NoValidObjectError; |
||
899 | cbradney | 73 | PyObject* NotFoundError; |
74 | PyObject* NameExistsError; |
||
647 | fschmid | 75 | |
1425 | subik | 76 | // Other extern variables defined in cmdvar.h |
77 | PyObject* wrappedMainWindow; |
||
78 | PyObject* wrappedQApp; |
||
1718 | craig | 79 | ScripterCore* scripterCore; |
1425 | subik | 80 | |
1718 | craig | 81 | // Variables used to pass data between the interpreter and |
82 | // Scribus by the console. |
||
83 | QString RetString; |
||
84 | QString InValue; |
||
85 | int RetVal; |
||
86 | |||
1552 | subik | 87 | QString name() |
82 | Franz | 88 | { |
308 | Franz | 89 | return QObject::tr("S&cripter Manual..."); |
82 | Franz | 90 | } |
91 | |||
1552 | subik | 92 | PluginManager::PluginType type() |
82 | Franz | 93 | { |
1552 | subik | 94 | return PluginManager::Persistent; |
82 | Franz | 95 | } |
96 | |||
660 | fschmid | 97 | int ID() |
98 | { |
||
99 | return 8; |
||
100 | } |
||
101 | |||
1269 | cbradney | 102 | QString actionName() |
103 | { |
||
104 | return "Scripter"; |
||
105 | } |
||
106 | |||
107 | QString actionKeySequence() |
||
108 | { |
||
109 | return ""; |
||
110 | } |
||
111 | |||
112 | QString actionMenu() |
||
113 | { |
||
114 | return "Help"; |
||
115 | } |
||
116 | |||
117 | QString actionMenuAfterName() |
||
118 | { |
||
119 | return "Manual"; |
||
120 | } |
||
121 | |||
122 | bool actionEnabledOnStartup() |
||
123 | { |
||
124 | return true; |
||
125 | } |
||
126 | |||
1552 | subik | 127 | void initPlug(QWidget *d, ScribusApp *plug) |
82 | Franz | 128 | { |
129 | QString cm; |
||
130 | Py_Initialize(); |
||
899 | cbradney | 131 | if (PyUnicode_SetDefaultEncoding("utf-8")) |
132 | { |
||
133 | qDebug("Failed to set default encoding to utf-8.\n"); |
||
134 | PyErr_Clear(); |
||
135 | } |
||
82 | Franz | 136 | Carrier = plug; |
137 | RetVal = 0; |
||
1269 | cbradney | 138 | |
1718 | craig | 139 | scripterCore = new ScripterCore(d); |
1747 | craig | 140 | initscribus(Carrier); |
1269 | cbradney | 141 | } |
142 | |||
1552 | subik | 143 | void cleanUpPlug() |
1269 | cbradney | 144 | { |
1718 | craig | 145 | if (scripterCore) |
146 | delete scripterCore; |
||
1269 | cbradney | 147 | Py_Finalize(); |
148 | } |
||
149 | |||
1718 | craig | 150 | void run(QWidget* /*d*/, ScribusApp* /*plug*/) |
1269 | cbradney | 151 | { |
1693 | craig | 152 | QString pfad = ScPaths::instance().docDir(); |
1269 | cbradney | 153 | QString pfad2; |
154 | pfad2 = QDir::convertSeparators(pfad + "en/Scripter/index.html"); |
||
155 | HelpBrowser *dia = new HelpBrowser(0, QObject::tr("Online Reference"), Carrier->getGuiLanguage(), "scripter"); |
||
156 | dia->show(); |
||
157 | } |
||
158 | |||
159 | |||
82 | Franz | 160 | /****************************************************************************************/ |
161 | /* */ |
||
650 | fschmid | 162 | /* Definitions of the Python commands */ |
82 | Franz | 163 | /* */ |
164 | /****************************************************************************************/ |
||
165 | |||
1718 | craig | 166 | static PyObject *scribus_retval(PyObject* /*self*/, PyObject* args) |
82 | Franz | 167 | { |
899 | cbradney | 168 | char *Name = NULL; |
169 | int retV = 0; |
||
934 | subik | 170 | if (!PyArg_ParseTuple(args, (char*)"si", &Name, &retV)) |
82 | Franz | 171 | return NULL; |
899 | cbradney | 172 | // Because sysdefaultencoding is not utf-8, Python is returning utf-8 encoded |
173 | // 8-bit char* strings. Make sure Qt understands that the input is utf-8 not |
||
174 | // the default local encoding (usually latin-1) by using QString::fromUtf8() |
||
175 | RetString = QString::fromUtf8(Name); |
||
82 | Franz | 176 | RetVal = retV; |
177 | return PyInt_FromLong(0L); |
||
178 | } |
||
179 | |||
1718 | craig | 180 | static PyObject *scribus_getval(PyObject* /*self*/) |
82 | Franz | 181 | { |
899 | cbradney | 182 | return PyString_FromString(InValue.utf8().data()); |
82 | Franz | 183 | } |
184 | |||
853 | subik | 185 | /*! |
186 | * Translate a docstring. Small helper function for use with the |
||
187 | * PyMethodDef struct. |
||
188 | */ |
||
189 | char* tr(const char* docstringConstant) |
||
190 | { |
||
899 | cbradney | 191 | // Alas, there's a lot of wasteful string copying going on |
192 | // here. |
||
193 | QString translated = QObject::tr(docstringConstant, "scripter docstring"); |
||
194 | /* |
||
195 | * Python doesn't support 'unicode' object docstrings in the PyMethodDef, |
||
196 | * and has no way to specify what encoding docstrings are in. The passed C |
||
197 | * strings passed are made into 'str' objects as-is. These are interpreted |
||
198 | * as being in the Python sysdefaultencoding, usually 'ascii', when used. |
||
199 | * We now set systemdefaultencoding to 'utf-8' ... so we're going to pass |
||
200 | * Python an 8-bit utf-8 encoded string in a char* . With |
||
201 | * sysdefaultencoding set correctly, Python will interpret it correctly and |
||
202 | * we'll have our unicode docstrings. It's not as ugly a hack as it sounds, |
||
203 | * you just have to remember that C and Python strings can both be |
||
204 | * considered 8-bit strings of binary data that can be later interpreted as |
||
205 | * a text string in a particular text encoding. |
||
206 | */ |
||
207 | //QCString utfTranslated = translated.utf8(); |
||
1559 | craig | 208 | QCString trch = translated.utf8(); |
209 | char* utfstr = strdup(trch.data()); |
||
210 | if (!utfstr) |
||
211 | // Complain, but then return NULL anyway. Python will treat NULL as |
||
212 | // "no value" so that's fine. |
||
213 | qDebug("scriptplugin.cpp:tr() - strdup() failure"); |
||
214 | return utfstr; |
||
853 | subik | 215 | } |
216 | |||
899 | cbradney | 217 | /* Now we're using the more pythonic convention for names: |
218 | * class - ClassName |
||
219 | * procedure/function/method - procedureName |
||
220 | * etc. */ |
||
853 | subik | 221 | PyMethodDef scribus_methods[] = { |
421 | Franz | 222 | // 2004/10/03 pv - aliases with common Python syntax - ClassName methodName |
655 | fschmid | 223 | // 2004-11-06 cr - move aliasing to dynamically generated wrapper functions, sort methoddef |
934 | subik | 224 | {const_cast<char*>("changeColor"), scribus_setcolor, METH_VARARGS, tr(scribus_setcolor__doc__)}, |
225 | {const_cast<char*>("closeDoc"), (PyCFunction)scribus_closedoc, METH_NOARGS, tr(scribus_closedoc__doc__)}, |
||
226 | {const_cast<char*>("createBezierLine"), scribus_bezierline, METH_VARARGS, tr(scribus_bezierline__doc__)}, |
||
227 | {const_cast<char*>("createEllipse"), scribus_newellipse, METH_VARARGS, tr(scribus_newellipse__doc__)}, |
||
228 | {const_cast<char*>("createImage"), scribus_newimage, METH_VARARGS, tr(scribus_newimage__doc__)}, |
||
229 | {const_cast<char*>("createLayer"), scribus_createlayer, METH_VARARGS, tr(scribus_createlayer__doc__)}, |
||
230 | {const_cast<char*>("createLine"), scribus_newline, METH_VARARGS, tr(scribus_newline__doc__)}, |
||
231 | {const_cast<char*>("createPathText"), scribus_pathtext, METH_VARARGS, tr(scribus_pathtext__doc__)}, |
||
232 | {const_cast<char*>("createPolygon"), scribus_polygon, METH_VARARGS, tr(scribus_polygon__doc__)}, |
||
233 | {const_cast<char*>("createPolyLine"), scribus_polyline, METH_VARARGS, tr(scribus_polyline__doc__)}, |
||
234 | {const_cast<char*>("createRect"), scribus_newrect, METH_VARARGS, tr(scribus_newrect__doc__)}, |
||
235 | {const_cast<char*>("createText"), scribus_newtext, METH_VARARGS, tr(scribus_newtext__doc__)}, |
||
236 | {const_cast<char*>("currentPage"), (PyCFunction)scribus_actualpage, METH_NOARGS, tr(scribus_actualpage__doc__)}, |
||
237 | {const_cast<char*>("defineColor"), scribus_newcolor, METH_VARARGS, tr(scribus_newcolor__doc__)}, |
||
238 | {const_cast<char*>("deleteColor"), scribus_delcolor, METH_VARARGS, tr(scribus_delcolor__doc__)}, |
||
239 | {const_cast<char*>("deleteLayer"), scribus_removelayer, METH_VARARGS, tr(scribus_removelayer__doc__)}, |
||
240 | {const_cast<char*>("deleteObject"), scribus_deleteobj, METH_VARARGS, tr(scribus_deleteobj__doc__)}, |
||
241 | {const_cast<char*>("deletePage"), scribus_deletepage, METH_VARARGS, tr(scribus_deletepage__doc__)}, |
||
242 | {const_cast<char*>("deleteText"), scribus_deletetext, METH_VARARGS, tr(scribus_deletetext__doc__)}, |
||
243 | {const_cast<char*>("deselectAll"), (PyCFunction)scribus_deselect, METH_NOARGS, tr(scribus_deselect__doc__)}, |
||
244 | {const_cast<char*>("docChanged"), scribus_docchanged, METH_VARARGS, tr(scribus_docchanged__doc__)}, |
||
245 | {const_cast<char*>("fileDialog"), (PyCFunction)scribus_filedia, METH_VARARGS|METH_KEYWORDS, tr(scribus_filedia__doc__)}, |
||
246 | {const_cast<char*>("getActiveLayer"), (PyCFunction)scribus_getactlayer, METH_NOARGS, tr(scribus_getactlayer__doc__)}, |
||
247 | {const_cast<char*>("getAllObjects"), scribus_getallobj, METH_VARARGS, tr(scribus_getallobj__doc__)}, |
||
248 | {const_cast<char*>("getAllStyles"), (PyCFunction)scribus_getstylenames, METH_NOARGS, tr(scribus_getstylenames__doc__)}, |
||
249 | {const_cast<char*>("getAllText"), scribus_gettext, METH_VARARGS, tr(scribus_gettext__doc__)}, |
||
250 | {const_cast<char*>("getColorNames"), (PyCFunction)scribus_colornames, METH_NOARGS, tr(scribus_colornames__doc__)}, |
||
251 | {const_cast<char*>("getColor"), scribus_getcolor, METH_VARARGS, tr(scribus_getcolor__doc__)}, |
||
1517 | craig | 252 | {const_cast<char*>("getColorAsRGB"), scribus_getcolorasrgb, METH_VARARGS, tr(scribus_getcolorasrgb__doc__)}, |
934 | subik | 253 | {const_cast<char*>("getColumnGap"), scribus_getcolumngap, METH_VARARGS, tr(scribus_getcolumngap__doc__)}, |
254 | {const_cast<char*>("getColumns"), scribus_getcolumns, METH_VARARGS, tr(scribus_getcolumns__doc__)}, |
||
255 | {const_cast<char*>("getCornerRadius"), scribus_getcornerrad, METH_VARARGS, tr(scribus_getcornerrad__doc__)}, |
||
256 | {const_cast<char*>("getFillColor"), scribus_getfillcolor, METH_VARARGS, tr(scribus_getfillcolor__doc__)}, |
||
257 | {const_cast<char*>("getFillShade"), scribus_getfillshade, METH_VARARGS, tr(scribus_getfillshade__doc__)}, |
||
258 | {const_cast<char*>("getFontNames"), (PyCFunction)scribus_fontnames, METH_NOARGS, tr(scribus_fontnames__doc__)}, |
||
259 | {const_cast<char*>("getFont"), scribus_getfont, METH_VARARGS, tr(scribus_getfont__doc__)}, |
||
260 | {const_cast<char*>("getFontSize"), scribus_getfontsize, METH_VARARGS, tr(scribus_getfontsize__doc__)}, |
||
261 | {const_cast<char*>("getGuiLanguage"), (PyCFunction)scribus_getlanguage, METH_NOARGS, tr(scribus_getlanguage__doc__)}, |
||
262 | {const_cast<char*>("getHGuides"), (PyCFunction)scribus_getHguides, METH_NOARGS, tr(scribus_getHguides__doc__)}, |
||
263 | {const_cast<char*>("getImageFile"), scribus_getimgname, METH_VARARGS, tr(scribus_getimgname__doc__)}, |
||
264 | {const_cast<char*>("getImageScale"), scribus_getimgscale, METH_VARARGS, tr(scribus_getimgscale__doc__)}, |
||
265 | {const_cast<char*>("getLayers"), (PyCFunction)scribus_getlayers, METH_NOARGS, tr(scribus_getlayers__doc__)}, |
||
266 | {const_cast<char*>("getLineCap"), scribus_getlineend, METH_VARARGS, tr(scribus_getlineend__doc__)}, |
||
267 | {const_cast<char*>("getLineColor"), scribus_getlinecolor, METH_VARARGS, tr(scribus_getlinecolor__doc__)}, |
||
268 | {const_cast<char*>("getLineJoin"), scribus_getlinejoin, METH_VARARGS, tr(scribus_getlinejoin__doc__)}, |
||
269 | {const_cast<char*>("getLineShade"), scribus_getlineshade, METH_VARARGS, tr(scribus_getlineshade__doc__)}, |
||
270 | {const_cast<char*>("getLineSpacing"), scribus_getlinespace, METH_VARARGS, tr(scribus_getlinespace__doc__)}, |
||
271 | {const_cast<char*>("getLineStyle"), scribus_getlinestyle, METH_VARARGS, tr(scribus_getlinestyle__doc__)}, |
||
272 | {const_cast<char*>("getLineWidth"), scribus_getlinewidth, METH_VARARGS, tr(scribus_getlinewidth__doc__)}, |
||
273 | {const_cast<char*>("getPageItems"), (PyCFunction)scribus_getpageitems, METH_NOARGS, tr(scribus_getpageitems__doc__)}, |
||
274 | {const_cast<char*>("getPageMargins"), (PyCFunction)scribus_getpagemargins, METH_NOARGS, tr(scribus_getpagemargins__doc__)}, |
||
275 | {const_cast<char*>("getPageSize"), (PyCFunction)scribus_pagedimension, METH_NOARGS, tr(scribus_pagedimension__doc__)}, // just an alias to PageDimension() |
||
276 | {const_cast<char*>("getPosition"), scribus_getposi, METH_VARARGS, tr(scribus_getposi__doc__)}, |
||
277 | {const_cast<char*>("getRotation"), scribus_getrotation, METH_VARARGS, tr(scribus_getrotation__doc__)}, |
||
278 | {const_cast<char*>("getSelectedObject"), scribus_getselobjnam, METH_VARARGS, tr(scribus_getselobjnam__doc__)}, |
||
279 | {const_cast<char*>("getSize"), scribus_getsize, METH_VARARGS, tr(scribus_getsize__doc__)}, |
||
280 | {const_cast<char*>("getTextColor"), scribus_getlinecolor, METH_VARARGS, tr(scribus_getlinecolor__doc__)}, |
||
281 | {const_cast<char*>("getTextLength"), scribus_gettextsize, METH_VARARGS, tr(scribus_gettextsize__doc__)}, |
||
282 | {const_cast<char*>("getText"), scribus_getframetext, METH_VARARGS, tr(scribus_getframetext__doc__)}, |
||
283 | {const_cast<char*>("getTextShade"), scribus_getlineshade, METH_VARARGS, tr(scribus_getlineshade__doc__)}, |
||
284 | {const_cast<char*>("getUnit"), (PyCFunction)scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)}, |
||
285 | {const_cast<char*>("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)}, |
||
286 | {const_cast<char*>("getXFontNames"), (PyCFunction)scribus_xfontnames, METH_NOARGS, tr(scribus_xfontnames__doc__)}, |
||
287 | {const_cast<char*>("gotoPage"), scribus_gotopage, METH_VARARGS, tr(scribus_gotopage__doc__)}, |
||
288 | {const_cast<char*>("groupObjects"), scribus_groupobj, METH_VARARGS, tr(scribus_groupobj__doc__)}, |
||
289 | {const_cast<char*>("haveDoc"), (PyCFunction)scribus_havedoc, METH_NOARGS, tr(scribus_havedoc__doc__)}, |
||
290 | {const_cast<char*>("insertText"), scribus_inserttext, METH_VARARGS, tr(scribus_inserttext__doc__)}, |
||
291 | {const_cast<char*>("isLayerPrintable"), scribus_glayerprint, METH_VARARGS, tr(scribus_glayerprint__doc__)}, |
||
292 | {const_cast<char*>("isLayerVisible"), scribus_glayervisib, METH_VARARGS, tr(scribus_glayervisib__doc__)}, |
||
293 | {const_cast<char*>("isLocked"), scribus_islocked, METH_VARARGS, tr(scribus_islocked__doc__)}, |
||
294 | {const_cast<char*>("linkTextFrames"), scribus_linktextframes, METH_VARARGS, tr(scribus_linktextframes__doc__)}, |
||
295 | {const_cast<char*>("loadImage"), scribus_loadimage, METH_VARARGS, tr(scribus_loadimage__doc__)}, |
||
296 | {const_cast<char*>("loadStylesFromFile"), scribus_loadstylesfromfile, METH_VARARGS, tr(scribus_loadstylesfromfile__doc__)}, |
||
297 | {const_cast<char*>("lockObject"), scribus_lockobject, METH_VARARGS, tr(scribus_lockobject__doc__)}, |
||
298 | {const_cast<char*>("messagebarText"), scribus_messagebartext, METH_VARARGS, tr(scribus_messagebartext__doc__)}, |
||
299 | {const_cast<char*>("messageBox"), (PyCFunction)scribus_messdia, METH_VARARGS|METH_KEYWORDS, tr(scribus_messdia__doc__)}, |
||
300 | {const_cast<char*>("moveObjectAbs"), scribus_moveobjabs, METH_VARARGS, tr(scribus_moveobjabs__doc__)}, |
||
301 | {const_cast<char*>("moveObject"), scribus_moveobjrel, METH_VARARGS, tr(scribus_moveobjrel__doc__)}, |
||
302 | {const_cast<char*>("newDocDialog"), (PyCFunction)scribus_newdocdia, METH_NOARGS, tr(scribus_newdocdia__doc__)}, |
||
303 | {const_cast<char*>("newDoc"), scribus_newdoc, METH_VARARGS, tr(scribus_newdoc__doc__)}, |
||
304 | {const_cast<char*>("newPage"), scribus_newpage, METH_VARARGS, tr(scribus_newpage__doc__)}, |
||
305 | {const_cast<char*>("objectExists"),scribus_objectexists, METH_VARARGS, tr(scribus_objectexists__doc__)}, |
||
306 | {const_cast<char*>("openDoc"), scribus_opendoc, METH_VARARGS, tr(scribus_opendoc__doc__)}, |
||
307 | {const_cast<char*>("pageCount"), (PyCFunction)scribus_pagecount, METH_NOARGS, tr(scribus_pagecount__doc__)}, |
||
308 | {const_cast<char*>("pageDimension"), (PyCFunction)scribus_pagedimension, METH_NOARGS, tr(scribus_pagedimension__doc__)}, |
||
309 | {const_cast<char*>("progressReset"), (PyCFunction)scribus_progressreset, METH_NOARGS, tr(scribus_progressreset__doc__)}, |
||
310 | {const_cast<char*>("progressSet"), scribus_progresssetprogress, METH_VARARGS, tr(scribus_progresssetprogress__doc__)}, |
||
311 | {const_cast<char*>("progressTotal"), scribus_progresssettotalsteps, METH_VARARGS, tr(scribus_progresssettotalsteps__doc__)}, |
||
312 | {const_cast<char*>("redrawAll"), (PyCFunction)scribus_redraw, METH_NOARGS, tr(scribus_redraw__doc__)}, |
||
1514 | craig | 313 | {const_cast<char*>("renderFont"), (PyCFunction)scribus_renderfont, METH_KEYWORDS, tr(scribus_renderfont__doc__)}, |
934 | subik | 314 | {const_cast<char*>("replaceColor"), scribus_replcolor, METH_VARARGS, tr(scribus_replcolor__doc__)}, |
315 | {const_cast<char*>("rotateObjectAbs"), scribus_rotobjabs, METH_VARARGS, tr(scribus_rotobjabs__doc__)}, |
||
316 | {const_cast<char*>("rotateObject"), scribus_rotobjrel, METH_VARARGS, tr(scribus_rotobjrel__doc__)}, |
||
317 | {const_cast<char*>("saveDocAs"), scribus_savedocas, METH_VARARGS, tr(scribus_savedocas__doc__)}, |
||
318 | {const_cast<char*>("saveDoc"), (PyCFunction)scribus_savedoc, METH_NOARGS, tr(scribus_savedoc__doc__)}, |
||
319 | {const_cast<char*>("savePageAsEPS"), scribus_savepageeps, METH_VARARGS, tr(scribus_savepageeps__doc__)}, |
||
320 | {const_cast<char*>("scaleGroup"), scribus_scalegroup, METH_VARARGS, tr(scribus_scalegroup__doc__)}, |
||
321 | {const_cast<char*>("scaleImage"), scribus_scaleimage, METH_VARARGS, tr(scribus_scaleimage__doc__)}, |
||
322 | {const_cast<char*>("selectionCount"), (PyCFunction)scribus_selcount, METH_NOARGS, tr(scribus_selcount__doc__)}, |
||
323 | {const_cast<char*>("selectObject"), scribus_selectobj, METH_VARARGS, tr(scribus_selectobj__doc__)}, |
||
324 | {const_cast<char*>("selectText"), scribus_selecttext, METH_VARARGS, tr(scribus_selecttext__doc__)}, |
||
325 | {const_cast<char*>("sentToLayer"), scribus_senttolayer, METH_VARARGS, tr(scribus_senttolayer__doc__)}, |
||
326 | {const_cast<char*>("setActiveLayer"), scribus_setactlayer, METH_VARARGS, tr(scribus_setactlayer__doc__)}, |
||
1534 | subik | 327 | {const_cast<char*>("setPDFBookmark"), scribus_setpdfbookmark, METH_VARARGS, tr(scribus_setpdfbookmark__doc__)}, |
328 | {const_cast<char*>("isPDFBookmark"), scribus_ispdfbookmark, METH_VARARGS, tr(scribus_ispdfbookmark__doc__)}, |
||
934 | subik | 329 | {const_cast<char*>("setColumnGap"), scribus_setcolumngap, METH_VARARGS, tr(scribus_setcolumngap__doc__)}, |
330 | {const_cast<char*>("setColumns"), scribus_setcolumns, METH_VARARGS, tr(scribus_setcolumns__doc__)}, |
||
331 | {const_cast<char*>("setCornerRadius"), scribus_setcornerrad, METH_VARARGS, tr(scribus_setcornerrad__doc__)}, |
||
332 | {const_cast<char*>("setCursor"), scribus_setcursor, METH_VARARGS, tr(scribus_setcursor__doc__)}, |
||
333 | {const_cast<char*>("setDocType"), scribus_setdoctype, METH_VARARGS, tr(scribus_setdoctype__doc__)}, |
||
334 | {const_cast<char*>("setFillColor"), scribus_setfillcolor, METH_VARARGS, tr(scribus_setfillcolor__doc__)}, |
||
335 | {const_cast<char*>("setFillShade"), scribus_setfillshade, METH_VARARGS, tr(scribus_setfillshade__doc__)}, |
||
336 | {const_cast<char*>("setFont"), scribus_setfont, METH_VARARGS, tr(scribus_setfont__doc__)}, |
||
337 | {const_cast<char*>("setFontSize"), scribus_setfontsize, METH_VARARGS, tr(scribus_setfontsize__doc__)}, |
||
338 | {const_cast<char*>("setGradientFill"), scribus_setgradfill, METH_VARARGS, tr(scribus_setgradfill__doc__)}, |
||
339 | {const_cast<char*>("setHGuides"), scribus_setHguides, METH_VARARGS, tr(scribus_setHguides__doc__)}, |
||
340 | {const_cast<char*>("setInfo"), scribus_setinfo, METH_VARARGS, tr(scribus_setinfo__doc__)}, |
||
341 | {const_cast<char*>("setLayerPrintable"), scribus_layerprint, METH_VARARGS, tr(scribus_layerprint__doc__)}, |
||
342 | {const_cast<char*>("setLayerVisible"), scribus_layervisible, METH_VARARGS, tr(scribus_layervisible__doc__)}, |
||
343 | {const_cast<char*>("setLineCap"), scribus_setlineend, METH_VARARGS, tr(scribus_setlineend__doc__)}, |
||
344 | {const_cast<char*>("setLineColor"), scribus_setlinecolor, METH_VARARGS, tr(scribus_setlinecolor__doc__)}, |
||
345 | {const_cast<char*>("setLineJoin"), scribus_setlinejoin, METH_VARARGS, tr(scribus_setlinejoin__doc__)}, |
||
346 | {const_cast<char*>("setLineShade"), scribus_setlineshade, METH_VARARGS, tr(scribus_setlineshade__doc__)}, |
||
347 | {const_cast<char*>("setLineSpacing"), scribus_setlinespace, METH_VARARGS, tr(scribus_setlinespace__doc__)}, |
||
348 | {const_cast<char*>("setLineStyle"), scribus_setlinestyle, METH_VARARGS, tr(scribus_setlinestyle__doc__)}, |
||
349 | {const_cast<char*>("setLineWidth"), scribus_setlinewidth, METH_VARARGS, tr(scribus_setlinewidth__doc__)}, |
||
350 | {const_cast<char*>("setMargins"), scribus_setmargins, METH_VARARGS, tr(scribus_setmargins__doc__)}, |
||
351 | {const_cast<char*>("setMultiLine"), scribus_setmultiline, METH_VARARGS, tr(scribus_setmultiline__doc__)}, |
||
733 | subik | 352 | // duplicity? {"setMultiLine", scribus_setmultiline, METH_VARARGS, "TODO: docstring"}, |
934 | subik | 353 | {const_cast<char*>("setRedraw"), scribus_setredraw, METH_VARARGS, tr(scribus_setredraw__doc__)}, |
733 | subik | 354 | // missing? {"setSelectedObject", scribus_setselobjnam, METH_VARARGS, "Returns the Name of the selecteted Object. \"nr\" if given indicates the Number of the selected Object, e.g. 0 means the first selected Object, 1 means the second selected Object and so on."}, |
1381 | cbradney | 355 | {const_cast<char*>("setScaleImageToFrame"), (PyCFunction)scribus_setscaleimagetoframe, METH_KEYWORDS, tr(scribus_setscaleimagetoframe__doc__)}, |
934 | subik | 356 | {const_cast<char*>("setStyle"), scribus_setstyle, METH_VARARGS, tr(scribus_setstyle__doc__)}, |
357 | {const_cast<char*>("setTextAlignment"), scribus_setalign, METH_VARARGS, tr(scribus_setalign__doc__)}, |
||
358 | {const_cast<char*>("setTextColor"), scribus_settextfill, METH_VARARGS, tr(scribus_settextfill__doc__)}, |
||
359 | {const_cast<char*>("setText"), scribus_setboxtext, METH_VARARGS, tr(scribus_setboxtext__doc__)}, |
||
360 | {const_cast<char*>("setTextShade"), scribus_settextshade, METH_VARARGS, tr(scribus_settextshade__doc__)}, |
||
361 | {const_cast<char*>("setTextStroke"), scribus_settextstroke, METH_VARARGS, tr(scribus_settextstroke__doc__)}, |
||
362 | {const_cast<char*>("setUnit"), scribus_setunit, METH_VARARGS, tr(scribus_setunit__doc__)}, |
||
363 | {const_cast<char*>("setVGuides"), scribus_setVguides, METH_VARARGS, tr(scribus_setVguides__doc__)}, |
||
364 | {const_cast<char*>("sizeObject"), scribus_sizeobjabs, METH_VARARGS, tr(scribus_sizeobjabs__doc__)}, |
||
365 | {const_cast<char*>("statusMessage"), scribus_messagebartext, METH_VARARGS, tr(scribus_messagebartext__doc__)}, |
||
366 | {const_cast<char*>("textFlowsAroundFrame"), scribus_textflow, METH_VARARGS, tr(scribus_textflow__doc__)}, |
||
367 | {const_cast<char*>("traceText"), scribus_tracetext, METH_VARARGS, tr(scribus_tracetext__doc__)}, |
||
368 | {const_cast<char*>("unGroupObject"), scribus_ungroupobj, METH_VARARGS, tr(scribus_ungroupobj__doc__)}, |
||
369 | {const_cast<char*>("unlinkTextFrames"), scribus_unlinktextframes, METH_VARARGS, tr(scribus_unlinktextframes__doc__)}, |
||
370 | {const_cast<char*>("valueDialog"), scribus_valdialog, METH_VARARGS, tr(scribus_valdialog__doc__)}, |
||
1607 | subik | 371 | {const_cast<char*>("textOverflows"), (PyCFunction)scribus_istextoverflowing, METH_KEYWORDS, tr(scribus_istextoverflowing__doc__)}, |
1425 | subik | 372 | // Property magic |
373 | {const_cast<char*>("getPropertyCType"), (PyCFunction)scribus_propertyctype, METH_KEYWORDS, tr(scribus_propertyctype__doc__)}, |
||
374 | {const_cast<char*>("getPropertyNames"), (PyCFunction)scribus_getpropertynames, METH_KEYWORDS, tr(scribus_getpropertynames__doc__)}, |
||
375 | {const_cast<char*>("getProperty"), (PyCFunction)scribus_getproperty, METH_KEYWORDS, tr(scribus_getproperty__doc__)}, |
||
376 | {const_cast<char*>("setProperty"), (PyCFunction)scribus_setproperty, METH_KEYWORDS, tr(scribus_setproperty__doc__)}, |
||
377 | {const_cast<char*>("getChildren"), (PyCFunction)scribus_getchildren, METH_KEYWORDS, tr(scribus_getchildren__doc__)}, |
||
378 | {const_cast<char*>("getChild"), (PyCFunction)scribus_getchild, METH_KEYWORDS, tr(scribus_getchild__doc__)}, |
||
379 | // Internal methods - Not for public use |
||
934 | subik | 380 | {const_cast<char*>("retval"), scribus_retval, METH_VARARGS, const_cast<char*>("Scribus internal.")}, |
381 | {const_cast<char*>("getval"), (PyCFunction)scribus_getval, METH_NOARGS, const_cast<char*>("Scribus internal.")}, |
||
1043 | subik | 382 | {NULL, (PyCFunction)(0), 0, NULL} /* sentinel */ |
82 | Franz | 383 | }; |
384 | |||
385 | void initscribus(ScribusApp *pl) |
||
386 | { |
||
1747 | craig | 387 | if (!scripterCore) |
388 | { |
||
389 | qWarning("scriptplugin: Tried to init scribus module, but no scripter core. Aborting."); |
||
390 | return; |
||
391 | } |
||
82 | Franz | 392 | PyObject *m, *d; |
934 | subik | 393 | PyImport_AddModule((char*)"scribus"); |
411 | Franz | 394 | PyType_Ready(&Printer_Type); |
418 | Franz | 395 | PyType_Ready(&PDFfile_Type); |
1407 | subik | 396 | PyType_Ready(&ImageExport_Type); |
934 | subik | 397 | m = Py_InitModule((char*)"scribus", scribus_methods); |
411 | Franz | 398 | Py_INCREF(&Printer_Type); |
934 | subik | 399 | PyModule_AddObject(m, (char*)"Printer", (PyObject *) &Printer_Type); |
418 | Franz | 400 | Py_INCREF(&PDFfile_Type); |
934 | subik | 401 | PyModule_AddObject(m, (char*)"PDFfile", (PyObject *) &PDFfile_Type); |
1407 | subik | 402 | Py_INCREF(&ImageExport_Type); |
403 | PyModule_AddObject(m, (char*)"ImageExport", (PyObject *) &ImageExport_Type); |
||
82 | Franz | 404 | d = PyModule_GetDict(m); |
647 | fschmid | 405 | |
406 | // Set up the module exceptions |
||
407 | // common exc. |
||
934 | subik | 408 | ScribusException = PyErr_NewException((char*)"scribus.ScribusException", NULL, NULL); |
647 | fschmid | 409 | Py_INCREF(ScribusException); |
934 | subik | 410 | PyModule_AddObject(m, (char*)"ScribusException", ScribusException); |
647 | fschmid | 411 | // no doc open |
934 | subik | 412 | NoDocOpenError = PyErr_NewException((char*)"scribus.NoDocOpenError", ScribusException, NULL); |
647 | fschmid | 413 | Py_INCREF(NoDocOpenError); |
934 | subik | 414 | PyModule_AddObject(m, (char*)"NoDocOpenError", NoDocOpenError); |
853 | subik | 415 | // wrong type of frame for operation |
416 | WrongFrameTypeError = PyErr_NewException((char*)"scribus.WrongFrameTypeError", ScribusException, NULL); |
||
417 | Py_INCREF(WrongFrameTypeError); |
||
418 | PyModule_AddObject(m, (char*)"WrongFrameTypeError", WrongFrameTypeError); |
||
419 | // Couldn't find named object, or no named object and no selection |
||
420 | NoValidObjectError = PyErr_NewException((char*)"scribus.NoValidObjectError", ScribusException, NULL); |
||
421 | Py_INCREF(NoValidObjectError); |
||
422 | PyModule_AddObject(m, (char*)"NoValidObjectError", NoValidObjectError); |
||
899 | cbradney | 423 | // Couldn't find the specified resource - font, color, etc. |
424 | NotFoundError = PyErr_NewException((char*)"scribus.NotFoundError", ScribusException, NULL); |
||
425 | Py_INCREF(NotFoundError); |
||
426 | PyModule_AddObject(m, (char*)"NotFoundError", NotFoundError); |
||
427 | // Tried to create an object with the same name as one that already exists |
||
428 | NameExistsError = PyErr_NewException((char*)"scribus.NameExistsError", ScribusException, NULL); |
||
429 | Py_INCREF(NameExistsError); |
||
430 | PyModule_AddObject(m, (char*)"NameExistsError", NameExistsError); |
||
647 | fschmid | 431 | // Done with exception setup |
432 | |||
421 | Franz | 433 | // CONSTANTS |
934 | subik | 434 | PyDict_SetItemString(d, const_cast<char*>("UNIT_POINTS"), Py_BuildValue(const_cast<char*>("i"), 0)); |
435 | PyDict_SetItemString(d, const_cast<char*>("UNIT_MILLIMETERS"), Py_BuildValue(const_cast<char*>("i"), 1)); |
||
436 | PyDict_SetItemString(d, const_cast<char*>("UNIT_INCHES"), Py_BuildValue(const_cast<char*>("i"), 2)); |
||
437 | PyDict_SetItemString(d, const_cast<char*>("UNIT_PICAS"), Py_BuildValue(const_cast<char*>("i"), 3)); |
||
438 | PyDict_SetItemString(d, const_cast<char*>("PORTRAIT"), Py_BuildValue(const_cast<char*>("i"), 0)); |
||
439 | PyDict_SetItemString(d, const_cast<char*>("LANDSCAPE"), Py_BuildValue(const_cast<char*>("i"), 1)); |
||
440 | PyDict_SetItemString(d, const_cast<char*>("NOFACINGPAGES"), Py_BuildValue(const_cast<char*>("i"), 0)); |
||
441 | PyDict_SetItemString(d, const_cast<char*>("FACINGPAGES"), Py_BuildValue(const_cast<char*>("i"), 1)); |
||
442 | PyDict_SetItemString(d, const_cast<char*>("FIRSTPAGERIGHT"), Py_BuildValue(const_cast<char*>("i"), 0)); |
||
443 | PyDict_SetItemString(d, const_cast<char*>("FIRSTPAGELEFT"), Py_BuildValue(const_cast<char*>("i"), 1)); |
||
444 | PyDict_SetItemString(d, const_cast<char*>("ALIGN_LEFT"), Py_BuildValue(const_cast<char*>("i"), 0)); |
||
445 | PyDict_SetItemString(d, const_cast<char*>("ALIGN_RIGHT"), Py_BuildValue(const_cast<char*>("i"), 2)); |
||
446 | PyDict_SetItemString(d, const_cast<char*>("ALIGN_CENTERED"), Py_BuildValue(const_cast<char*>("i"), 1)); |
||
447 | PyDict_SetItemString(d, const_cast<char*>("ALIGN_BLOCK"), Py_BuildValue(const_cast<char*>("i"), 4)); |
||
448 | PyDict_SetItemString(d, const_cast<char*>("ALIGN_FORCED"), Py_BuildValue(const_cast<char*>("i"), 4)); |
||
449 | PyDict_SetItemString(d, const_cast<char*>("FILL_NOG"), Py_BuildValue(const_cast<char*>("i"), 0)); |
||
450 | PyDict_SetItemString(d, const_cast<char*>("FILL_HORIZONTALG"), Py_BuildValue(const_cast<char*>("i"), 1)); |
||
451 | PyDict_SetItemString(d, const_cast<char*>("FILL_VERTICALG"), Py_BuildValue(const_cast<char*>("i"), 2)); |
||
452 | PyDict_SetItemString(d, const_cast<char*>("FILL_DIAGONALG"), Py_BuildValue(const_cast<char*>("i"), 3)); |
||
453 | PyDict_SetItemString(d, const_cast<char*>("FILL_CROSSDIAGONALG"), Py_BuildValue(const_cast<char*>("i"), 4)); |
||
454 | PyDict_SetItemString(d, const_cast<char*>("FILL_RADIALG"), Py_BuildValue(const_cast<char*>("i"), 5)); |
||
455 | PyDict_SetItemString(d, const_cast<char*>("LINE_SOLID"), Py_BuildValue(const_cast<char*>("i"), Qt::SolidLine)); |
||
456 | PyDict_SetItemString(d, const_cast<char*>("LINE_DASH"), Py_BuildValue(const_cast<char*>("i"), Qt::DashLine)); |
||
457 | PyDict_SetItemString(d, const_cast<char*>("LINE_DOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DotLine)); |
||
458 | PyDict_SetItemString(d, const_cast<char*>("LINE_DASHDOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DashDotLine)); |
||
459 | PyDict_SetItemString(d, const_cast<char*>("LINE_DASHDOTDOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DashDotDotLine)); |
||
460 | PyDict_SetItemString(d, const_cast<char*>("JOIN_MITTER"), Py_BuildValue(const_cast<char*>("i"), Qt::MiterJoin)); |
||
461 | PyDict_SetItemString(d, const_cast<char*>("JOIN_BEVEL"), Py_BuildValue(const_cast<char*>("i"), Qt::BevelJoin)); |
||
462 | PyDict_SetItemString(d, const_cast<char*>("JOIN_ROUND"), Py_BuildValue(const_cast<char*>("i"), Qt::RoundJoin)); |
||
463 | PyDict_SetItemString(d, const_cast<char*>("CAP_FLAT"), Py_BuildValue(const_cast<char*>("i"), Qt::FlatCap)); |
||
464 | PyDict_SetItemString(d, const_cast<char*>("CAP_SQUARE"), Py_BuildValue(const_cast<char*>("i"), Qt::SquareCap)); |
||
465 | PyDict_SetItemString(d, const_cast<char*>("CAP_ROUND"), Py_BuildValue(const_cast<char*>("i"), Qt::RoundCap)); |
||
466 | PyDict_SetItemString(d, const_cast<char*>("BUTTON_NONE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::NoButton)); |
||
467 | PyDict_SetItemString(d, const_cast<char*>("BUTTON_OK"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Ok)); |
||
468 | PyDict_SetItemString(d, const_cast<char*>("BUTTON_CANCEL"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Cancel)); |
||
469 | PyDict_SetItemString(d, const_cast<char*>("BUTTON_YES"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Yes)); |
||
470 | PyDict_SetItemString(d, const_cast<char*>("BUTTON_NO"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::No)); |
||
471 | PyDict_SetItemString(d, const_cast<char*>("BUTTON_ABORT"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Abort)); |
||
472 | PyDict_SetItemString(d, const_cast<char*>("BUTTON_RETRY"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Retry)); |
||
473 | PyDict_SetItemString(d, const_cast<char*>("BUTTON_IGNORE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Ignore)); |
||
474 | PyDict_SetItemString(d, const_cast<char*>("ICON_NONE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::NoIcon)); |
||
475 | PyDict_SetItemString(d, const_cast<char*>("ICON_INFORMATION"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Information)); |
||
476 | PyDict_SetItemString(d, const_cast<char*>("ICON_WARNING"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Warning)); |
||
477 | PyDict_SetItemString(d, const_cast<char*>("ICON_CRITICAL"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Critical)); |
||
478 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A0"), Py_BuildValue(const_cast<char*>("(ff)"), 2380.0, 3368.0)); |
||
479 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A1"), Py_BuildValue(const_cast<char*>("(ff)"), 1684.0, 2380.0)); |
||
480 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A2"), Py_BuildValue(const_cast<char*>("(ff)"), 1190.0, 1684.0)); |
||
481 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A3"), Py_BuildValue(const_cast<char*>("(ff)"), 842.0, 1190.0)); |
||
482 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A4"), Py_BuildValue(const_cast<char*>("(ff)"), 595.0, 842.0)); |
||
483 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A5"), Py_BuildValue(const_cast<char*>("(ff)"), 421.0, 595.0)); |
||
484 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A6"), Py_BuildValue(const_cast<char*>("(ff)"), 297.0, 421.0)); |
||
485 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A7"), Py_BuildValue(const_cast<char*>("(ff)"), 210.0, 297.0)); |
||
486 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A8"), Py_BuildValue(const_cast<char*>("(ff)"), 148.0, 210.0)); |
||
487 | PyDict_SetItemString(d, const_cast<char*>("PAPER_A9"), Py_BuildValue(const_cast<char*>("(ff)"), 105.0, 148.0)); |
||
488 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B0"), Py_BuildValue(const_cast<char*>("(ff)"), 2836.0, 4008.0)); |
||
489 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B1"), Py_BuildValue(const_cast<char*>("(ff)"), 2004.0, 2836.0)); |
||
490 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B2"), Py_BuildValue(const_cast<char*>("(ff)"), 1418.0, 2004.0)); |
||
491 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B3"), Py_BuildValue(const_cast<char*>("(ff)"), 1002.0, 1418.0)); |
||
492 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B4"), Py_BuildValue(const_cast<char*>("(ff)"), 709.0, 1002.0)); |
||
493 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B5"), Py_BuildValue(const_cast<char*>("(ff)"), 501.0, 709.0)); |
||
494 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B6"), Py_BuildValue(const_cast<char*>("(ff)"), 355.0, 501.0)); |
||
495 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B7"), Py_BuildValue(const_cast<char*>("(ff)"), 250.0, 355.0)); |
||
496 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B8"), Py_BuildValue(const_cast<char*>("(ff)"), 178.0, 250.0)); |
||
497 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B9"), Py_BuildValue(const_cast<char*>("(ff)"), 125.0, 178.0)); |
||
498 | PyDict_SetItemString(d, const_cast<char*>("PAPER_B10"), Py_BuildValue(const_cast<char*>("(ff)"), 89.0, 125.0)); |
||
499 | PyDict_SetItemString(d, const_cast<char*>("PAPER_C5E"), Py_BuildValue(const_cast<char*>("(ff)"), 462.0, 649.0)); |
||
500 | PyDict_SetItemString(d, const_cast<char*>("PAPER_COMM10E"), Py_BuildValue(const_cast<char*>("(ff)"), 298.0, 683.0)); |
||
501 | PyDict_SetItemString(d, const_cast<char*>("PAPER_DLE"), Py_BuildValue(const_cast<char*>("(ff)"), 312.0, 624.0)); |
||
502 | PyDict_SetItemString(d, const_cast<char*>("PAPER_EXECUTIVE"), Py_BuildValue(const_cast<char*>("(ff)"), 542.0, 720.0)); |
||
503 | PyDict_SetItemString(d, const_cast<char*>("PAPER_FOLIO"), Py_BuildValue(const_cast<char*>("(ff)"), 595.0, 935.0)); |
||
504 | PyDict_SetItemString(d, const_cast<char*>("PAPER_LEDGER"), Py_BuildValue(const_cast<char*>("(ff)"), 1224.0, 792.0)); |
||
505 | PyDict_SetItemString(d, const_cast<char*>("PAPER_LEGAL"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 1008.0)); |
||
506 | PyDict_SetItemString(d, const_cast<char*>("PAPER_LETTER"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 792.0)); |
||
507 | PyDict_SetItemString(d, const_cast<char*>("PAPER_TABLOID"), Py_BuildValue(const_cast<char*>("(ff)"), 792.0, 1224.0)); |
||
733 | subik | 508 | |
1043 | subik | 509 | // Export the Scribus version into the module namespace so scripts know what they're running in |
510 | PyDict_SetItemString(d, const_cast<char*>("scribus_version"), PyString_FromString(const_cast<char*>(VERSION))); |
||
511 | // Now build a version tuple like that provided by Python in sys.version_info |
||
512 | // The tuple is of the form (major, minor, patchlevel, extraversion, reserved) |
||
513 | QRegExp version_re("(\\d+)\\.(\\d+)\\.(\\d+)(.*)"); |
||
514 | int pos = version_re.search(QString(VERSION)); |
||
515 | // We ignore errors, causing the scribus_version_info attribute to simply not be created. |
||
516 | // This will make acceses raise AttrbuteError. |
||
517 | if (pos > -1) |
||
518 | { |
||
519 | int majorVersion = version_re.cap(1).toInt(); |
||
520 | int minorVersion = version_re.cap(2).toInt(); |
||
521 | int patchVersion = version_re.cap(3).toInt(); |
||
522 | QString extraVersion = version_re.cap(4); |
||
523 | PyObject* versionTuple = Py_BuildValue(const_cast<char*>("(iiisi)"),\ |
||
524 | majorVersion, minorVersion, patchVersion, (const char*)extraVersion.utf8(), 0); |
||
525 | if (versionTuple != NULL) |
||
526 | PyDict_SetItemString(d, const_cast<char*>("scribus_version_info"), versionTuple); |
||
527 | else |
||
528 | qDebug("Failed to build version tuple for version string '%s' in scripter", VERSION); |
||
529 | } |
||
530 | else |
||
531 | qDebug("Couldn't parse version string '%s' in scripter", VERSION); |
||
532 | |||
82 | Franz | 533 | Carrier = pl; |
655 | fschmid | 534 | // Function aliases for compatibility |
535 | // We need to import the __builtins__, warnings and exceptions modules to be able to run |
||
536 | // the generated Python functions from inside the `scribus' module's context. |
||
537 | // This code makes it possible to extend the `scribus' module by running Python code |
||
538 | // from C in other ways too. |
||
934 | subik | 539 | PyObject* builtinModule = PyImport_ImportModuleEx(const_cast<char*>("__builtin__"), |
540 | d, d, Py_BuildValue(const_cast<char*>("[]"))); |
||
655 | fschmid | 541 | if (builtinModule == NULL) |
542 | { |
||
543 | qDebug("Failed to import __builtin__ module. Something is probably broken with your Python."); |
||
544 | return; |
||
545 | } |
||
934 | subik | 546 | PyDict_SetItemString(d, const_cast<char*>("__builtin__"), builtinModule); |
547 | PyObject* exceptionsModule = PyImport_ImportModuleEx(const_cast<char*>("exceptions"), |
||
548 | d, d, Py_BuildValue(const_cast<char*>("[]"))); |
||
655 | fschmid | 549 | if (exceptionsModule == NULL) |
550 | { |
||
551 | qDebug("Failed to import exceptions module. Something is probably broken with your Python."); |
||
552 | return; |
||
553 | } |
||
934 | subik | 554 | PyDict_SetItemString(d, const_cast<char*>("exceptions"), exceptionsModule); |
555 | PyObject* warningsModule = PyImport_ImportModuleEx(const_cast<char*>("warnings"), |
||
556 | d, d, Py_BuildValue(const_cast<char*>("[]"))); |
||
655 | fschmid | 557 | if (warningsModule == NULL) |
558 | { |
||
559 | qDebug("Failed to import warnings module. Something is probably broken with your Python."); |
||
560 | return; |
||
561 | } |
||
934 | subik | 562 | PyDict_SetItemString(d, const_cast<char*>("warnings"), warningsModule); |
853 | subik | 563 | // Create the module-level docstring. This can be a proper unicode string, unlike |
564 | // the others, because we can just create a Unicode object and insert it in our |
||
565 | // module dictionary. |
||
566 | QString docstring = QObject::tr("Scribus Python interface module\n\ |
||
1345 | subik | 567 | \n\ |
568 | This module is the Python interface for Scribus. It provides functions\n\ |
||
569 | to control scribus and to manipulate objects on the canvas. Each\n\ |
||
570 | function is documented individually below.\n\ |
||
571 | \n\ |
||
572 | A few things are common across most of the interface.\n\ |
||
573 | \n\ |
||
574 | Most functions operate on frames. Frames are identified by their name,\n\ |
||
575 | a string - they are not real Python objects. Many functions take an\n\ |
||
576 | optional (non-keyword) parameter, a frame name.\n\ |
||
577 | Many exceptions are also common across most functions. These are\n\ |
||
578 | not currently documented in the docstring for each function.\n\ |
||
1559 | craig | 579 | - Many functions will raise a NoDocOpenError if you try to use them\n\ |
1345 | subik | 580 | without a document to operate on.\n\ |
1559 | craig | 581 | - If you do not pass a frame name to a function that requires one,\n\ |
582 | the function will use the currently selected frame, if any, or\n\ |
||
583 | raise a NoValidObjectError if it can't find anything to operate\n\ |
||
1345 | subik | 584 | on.\n\ |
585 | - Many functions will raise WrongFrameTypeError if you try to use them\n\ |
||
586 | on a frame type that they do not make sense with. For example, setting\n\ |
||
1525 | cbradney | 587 | the text color on a graphics frame doesn't make sense, and will result\n\ |
1345 | subik | 588 | in this exception being raised.\n\ |
589 | - Errors resulting from calls to the underlying Python API will be\n\ |
||
590 | passed through unaltered. As such, the list of exceptions thrown by\n\ |
||
591 | any function as provided here and in its docstring is incomplete.\n\ |
||
592 | \n\ |
||
593 | Details of what exceptions each function may throw are provided on the\n\ |
||
1559 | craig | 594 | function's documentation, though as with most Python code this list\n\ |
595 | is not exhaustive due to exceptions from called functions.\n\ |
||
596 | "); |
||
853 | subik | 597 | |
1559 | craig | 598 | PyObject* docStr = PyString_FromString(docstring.utf8().data()); |
599 | if (!docStr) |
||
600 | qDebug("Failed to create module-level docstring (couldn't make str)"); |
||
853 | subik | 601 | else |
1559 | craig | 602 | { |
603 | PyObject* uniDocStr = PyUnicode_FromEncodedObject(docStr, "utf-8", NULL); |
||
604 | Py_DECREF(docStr); |
||
605 | docStr = NULL; |
||
606 | if (!uniDocStr) |
||
607 | qDebug("Failed to create module-level docstring object (couldn't make unicode)"); |
||
608 | else |
||
609 | PyDict_SetItemString(d, const_cast<char*>("__doc__"), uniDocStr); |
||
610 | Py_DECREF(uniDocStr); |
||
611 | uniDocStr = NULL; |
||
612 | } |
||
1425 | subik | 613 | |
614 | // Wrap up pointers to the the QApp and main window and push them out |
||
615 | // to Python. |
||
616 | wrappedQApp = wrapQObject(qApp); |
||
617 | if (!wrappedQApp) |
||
618 | { |
||
619 | qDebug("Failed to wrap up QApp"); |
||
620 | PyErr_Print(); |
||
621 | } |
||
622 | // Push it into the module dict, stealing a ref in the process |
||
623 | PyDict_SetItemString(d, const_cast<char*>("qApp"), wrappedQApp); |
||
624 | Py_DECREF(wrappedQApp); |
||
625 | wrappedQApp = NULL; |
||
626 | |||
627 | wrappedMainWindow = wrapQObject(Carrier); |
||
628 | if (!wrappedMainWindow) |
||
629 | { |
||
630 | qDebug("Failed to wrap up Carrier"); |
||
631 | PyErr_Print(); |
||
632 | } |
||
633 | // Push it into the module dict, stealing a ref in the process |
||
634 | PyDict_SetItemString(d, const_cast<char*>("mainWindow"), wrappedMainWindow); |
||
635 | Py_DECREF(wrappedMainWindow); |
||
636 | wrappedMainWindow = NULL; |
||
82 | Franz | 637 | } |
638 |