Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scriptplugin.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           scriptplugin.cpp  -  description
00009                              -------------------
00010     begin                : Thu Oct 3 08:00:00 CEST 2002
00011     copyright            : (C) 2002 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 // include cmdvar.h first, as it pulls in <Python.h>
00025 #include "cmdvar.h"
00026 
00027 #include "cmddialog.h"
00028 #include "cmddoc.h"
00029 #include "cmdpage.h"
00030 #include "cmdobj.h"
00031 #include "cmdgetprop.h"
00032 #include "cmdsetprop.h"
00033 #include "cmdtext.h"
00034 #include "cmdmani.h"
00035 #include "cmdcolor.h"
00036 #include "cmdmisc.h"
00037 #include "cmdgetsetprop.h"
00038 #include "scriptplugin.h"
00039 #include "scriptplugin.moc"
00040 #include "cmdutil.h"
00041 #include "objprinter.h"
00042 #include "objpdffile.h"
00043 #include "objimageexport.h"
00044 #include "guiapp.h"
00045 #include "svgimport.h"
00046 #include "scriptercore.h"
00047 #include "scribuscore.h"
00048 #include "customfdialog.h"
00049 #include "helpbrowser.h"
00050 #include "mpalette.h"
00051 //#include "seiten.h"
00052 //#include "layers.h"
00053 //#include "tree.h"
00054 #include "menumanager.h"
00055 #include "scpaths.h"
00056 #include "units.h"
00057 #include "scribusstructs.h"
00058 #include "scconfig.h"
00059 #include "scripterprefsgui.h"
00060 
00061 #include <qapplication.h>
00062 #include <qmessagebox.h>
00063 #include <qtextcodec.h>
00064 #include <qdom.h>
00065 #include <qregexp.h>
00066 #include <qtextstream.h>
00067 #include <qpixmap.h>
00068 #include <qwidget.h>
00069 #include <qstring.h>
00070 #include <cstdlib>
00071 #include <iostream>
00072 
00073 extern QPixmap SCRIBUS_API loadIcon(QString nam);
00074 
00075 #ifdef HAVE_SCRIPTER2
00076 extern void scripter2_init();
00077 #endif
00078 
00079 // Exceptions; visible from cmdvar.h, set up in initscribus()
00080 PyObject* ScribusException;
00081 PyObject* NoDocOpenError;
00082 PyObject* WrongFrameTypeError;
00083 PyObject* NoValidObjectError;
00084 PyObject* NotFoundError;
00085 PyObject* NameExistsError;
00086 
00087 // Other extern variables defined in cmdvar.h
00088 PyObject* wrappedMainWindow;
00089 PyObject* wrappedQApp;
00090 ScripterCore* scripterCore;
00091 
00092 
00093 int scriptplugin_getPluginAPIVersion()
00094 {
00095        return PLUGIN_API_VERSION;
00096 }
00097 
00098 ScPlugin* scriptplugin_getPlugin()
00099 {
00100        scripterCore=0;
00101        ScriptPlugin* plug = new ScriptPlugin();
00102        Q_CHECK_PTR(plug);
00103        return plug;
00104 }
00105 
00106 void scriptplugin_freePlugin(ScPlugin* plugin)
00107 {
00108        ScriptPlugin* plug = dynamic_cast<ScriptPlugin*>(plugin);
00109        Q_ASSERT(plug);
00110        delete plug;
00111 }
00112 
00113 ScriptPlugin::ScriptPlugin() : ScPersistentPlugin()
00114 {
00115        // Set action info in languageChange, so we only have to do
00116        // it in one place.
00117        languageChange();
00118 }
00119 
00120 ScriptPlugin::~ScriptPlugin() {};
00121 
00122 void ScriptPlugin::languageChange()
00123 {
00124        if (scripterCore)
00125               scripterCore->languageChange();
00126 }
00127 
00128 void ScriptPlugin::addToMainWindowMenu(ScribusMainWindow* mw)
00129 {
00130        if (scripterCore)
00131               scripterCore->addToMainWindowMenu(mw);
00132 }
00133 
00134 const QString ScriptPlugin::fullTrName() const
00135 {
00136        return QObject::tr("Scripter");
00137 }
00138 
00139 const ScActionPlugin::AboutData* ScriptPlugin::getAboutData() const
00140 {
00141        AboutData* about = new AboutData;
00142        Q_CHECK_PTR(about);
00143        about->authors = QString::fromUtf8(
00144                      "Petr Van\xc4\x9bk <petr@scribus.info>, "
00145                      "Franz Schmid <franz@scribus.info>, "
00146                      "Craig Ringer <craig@scribus.info>");
00147        about->shortDescription = tr("Embedded Python scripting support.");
00148        // about->description = tr("Write me!")
00149        // about->version
00150        // about->releaseDate
00151        // about->copyright
00152        // about->license
00153        return about;
00154 }
00155 
00156 void ScriptPlugin::deleteAboutData(const AboutData* about) const
00157 {
00158        Q_ASSERT(about);
00159        delete about;
00160 }
00161 
00162 bool ScriptPlugin::initPlugin()
00163 {
00164        QString cm;
00165        Py_Initialize();
00166        if (PyUnicode_SetDefaultEncoding("utf-8"))
00167        {
00168               qDebug("Failed to set default encoding to utf-8.\n");
00169               PyErr_Clear();
00170        }
00171 
00172        scripterCore = new ScripterCore(ScCore->primaryMainWindow());
00173        Q_CHECK_PTR(scripterCore);
00174        initscribus(ScCore->primaryMainWindow());
00175 #ifdef HAVE_SCRIPTER2
00176        scripter2_init();
00177 #endif
00178        scripterCore->setupMainInterpreter();
00179        scripterCore->initExtensionScripts();
00180        scripterCore->runStartupScript();
00181        return true;
00182 }
00183 
00184 bool ScriptPlugin::cleanupPlugin()
00185 {
00186        if (scripterCore)
00187               delete scripterCore;
00188        Py_Finalize();
00189        return true;
00190 }
00191 
00192 bool ScriptPlugin::newPrefsPanelWidget(QWidget* parent,
00193                                                                   PrefsPanel*& panel,
00194                                                                   QString& caption,
00195                                                                   QPixmap& icon)
00196 {
00197        panel = new ScripterPrefsGui(parent);
00198        Q_CHECK_PTR(panel);
00199        caption = tr("Scripter");
00200        icon = loadIcon("python.png");
00201        return true;
00202 }
00203 
00204 /*  TEMPORARILY DISABLED
00205 void run()
00206 {
00207        QString pfad = ScPaths::instance().docDir();
00208        QString pfad2;
00209        pfad2 = QDir::convertSeparators(pfad + "en/Scripter/index.html");
00210        HelpBrowser *dia = new HelpBrowser(0, QObject::tr("Online Reference"), ScCore->primaryMainWindow()->getGuiLanguage(), "scripter");
00211        dia->show();
00212 }
00213 */
00214 
00215 
00216 /****************************************************************************************/
00217 /*                                                                                      */
00218 /*   Definitions of the Python commands                                                 */
00219 /*                                                                                      */
00220 /****************************************************************************************/
00221 
00222 static PyObject *scribus_retval(PyObject* /*self*/, PyObject* args)
00223 {
00224        char *Name = NULL;
00225        if (!PyArg_ParseTuple(args, (char*)"s", &Name))
00226               return NULL;
00227        // Because sysdefaultencoding is not utf-8, Python is returning utf-8 encoded
00228        // 8-bit char* strings. Make sure Qt understands that the input is utf-8 not
00229        // the default local encoding (usually latin-1) by using QString::fromUtf8()
00230        /*RetString = QString::fromUtf8(Name);
00231        RetVal = retV;*/
00232        scripterCore->returnString = QString::fromUtf8(Name);
00233        return PyInt_FromLong(0L);
00234 }
00235 
00236 static PyObject *scribus_getval(PyObject* /*self*/)
00237 {
00238        return PyString_FromString(scripterCore->inValue.utf8().data());
00239 }
00240 
00244 char* tr(const char* docstringConstant)
00245 {
00246        // Alas, there's a lot of wasteful string copying going on
00247        // here.
00248        QString translated = QObject::tr(docstringConstant, "scripter docstring");
00249        // pv - hack for ugly formating in console removing
00250        translated.replace("\n\n", "<P>");
00251        translated.replace('\n', " ");
00252        translated.replace("<P>", "\n\n");
00253        /*
00254         * Python doesn't support 'unicode' object docstrings in the PyMethodDef,
00255         * and has no way to specify what encoding docstrings are in. The passed C
00256         * strings passed are made into 'str' objects as-is. These are interpreted
00257         * as being in the Python sysdefaultencoding, usually 'ascii', when used.
00258         * We now set systemdefaultencoding to 'utf-8' ...  so we're going to pass
00259         * Python an 8-bit utf-8 encoded string in a char* .  With
00260         * sysdefaultencoding set correctly, Python will interpret it correctly and
00261         * we'll have our unicode docstrings. It's not as ugly a hack as it sounds,
00262         * you just have to remember that C and Python strings can both be
00263         * considered 8-bit strings of binary data that can be later interpreted as
00264         * a text string in a particular text encoding.
00265         */
00266        //QCString utfTranslated = translated.utf8();
00267        QCString trch = translated.utf8();
00268        char* utfstr = strdup(trch.data());
00269        if (!utfstr)
00270               // Complain, but then return NULL anyway. Python will treat NULL as
00271               // "no value" so that's fine.
00272               qDebug("scriptplugin.cpp:tr() - strdup() failure");
00273        return utfstr;
00274 }
00275 
00276 /* Now we're using the more pythonic convention for names:
00277  * class - ClassName
00278  * procedure/function/method - procedureName
00279  * etc. */
00280 PyMethodDef scribus_methods[] = {
00281        // 2004/10/03 pv - aliases with common Python syntax - ClassName methodName
00282        // 2004-11-06 cr - move aliasing to dynamically generated wrapper functions, sort methoddef
00283        {const_cast<char*>("changeColor"), scribus_setcolor, METH_VARARGS, tr(scribus_setcolor__doc__)},
00284        {const_cast<char*>("closeDoc"), (PyCFunction)scribus_closedoc, METH_NOARGS, tr(scribus_closedoc__doc__)},
00285        {const_cast<char*>("closeMasterPage"), (PyCFunction)scribus_closemasterpage, METH_NOARGS, tr(scribus_closemasterpage__doc__)},
00286        {const_cast<char*>("createBezierLine"), scribus_bezierline, METH_VARARGS, tr(scribus_bezierline__doc__)},
00287        {const_cast<char*>("createEllipse"), scribus_newellipse, METH_VARARGS, tr(scribus_newellipse__doc__)},
00288        {const_cast<char*>("createImage"), scribus_newimage, METH_VARARGS, tr(scribus_newimage__doc__)},
00289        {const_cast<char*>("createLayer"), scribus_createlayer, METH_VARARGS, tr(scribus_createlayer__doc__)},
00290        {const_cast<char*>("createLine"), scribus_newline, METH_VARARGS, tr(scribus_newline__doc__)},
00291        {const_cast<char*>("createMasterPage"), scribus_createmasterpage, METH_VARARGS, tr(scribus_createmasterpage__doc__)},
00292        {const_cast<char*>("createPathText"), scribus_pathtext, METH_VARARGS, tr(scribus_pathtext__doc__)},
00293        {const_cast<char*>("createPolygon"), scribus_polygon, METH_VARARGS, tr(scribus_polygon__doc__)},
00294        {const_cast<char*>("createPolyLine"), scribus_polyline, METH_VARARGS, tr(scribus_polyline__doc__)},
00295        {const_cast<char*>("createRect"), scribus_newrect, METH_VARARGS, tr(scribus_newrect__doc__)},
00296        {const_cast<char*>("createText"), scribus_newtext, METH_VARARGS, tr(scribus_newtext__doc__)},
00297        {const_cast<char*>("currentPage"), (PyCFunction)scribus_actualpage, METH_NOARGS, tr(scribus_actualpage__doc__)},
00298        {const_cast<char*>("defineColor"), scribus_newcolor, METH_VARARGS, tr(scribus_newcolor__doc__)},
00299        {const_cast<char*>("deleteColor"), scribus_delcolor, METH_VARARGS, tr(scribus_delcolor__doc__)},
00300        {const_cast<char*>("deleteLayer"), scribus_removelayer, METH_VARARGS, tr(scribus_removelayer__doc__)},
00301        {const_cast<char*>("deleteMasterPage"), scribus_deletemasterpage, METH_VARARGS, tr(scribus_deletemasterpage__doc__)},
00302        {const_cast<char*>("deleteObject"), scribus_deleteobj, METH_VARARGS, tr(scribus_deleteobj__doc__)},
00303        {const_cast<char*>("deletePage"), scribus_deletepage, METH_VARARGS, tr(scribus_deletepage__doc__)},
00304        {const_cast<char*>("deleteText"), scribus_deletetext, METH_VARARGS, tr(scribus_deletetext__doc__)},
00305        {const_cast<char*>("deselectAll"), (PyCFunction)scribus_deselect, METH_NOARGS, tr(scribus_deselect__doc__)},
00306        {const_cast<char*>("docChanged"), scribus_docchanged, METH_VARARGS, tr(scribus_docchanged__doc__)},
00307        {const_cast<char*>("editMasterPage"), scribus_editmasterpage, METH_VARARGS, tr(scribus_editmasterpage__doc__)},
00308        {const_cast<char*>("fileDialog"), (PyCFunction)scribus_filedia, METH_VARARGS|METH_KEYWORDS, tr(scribus_filedia__doc__)},
00309        {const_cast<char*>("getActiveLayer"), (PyCFunction)scribus_getactlayer, METH_NOARGS, tr(scribus_getactlayer__doc__)},
00310        {const_cast<char*>("getAllObjects"), scribus_getallobj, METH_VARARGS, tr(scribus_getallobj__doc__)},
00311        {const_cast<char*>("getAllStyles"), (PyCFunction)scribus_getstylenames, METH_NOARGS, tr(scribus_getstylenames__doc__)},
00312        {const_cast<char*>("getAllText"), scribus_gettext, METH_VARARGS, tr(scribus_gettext__doc__)},
00313        {const_cast<char*>("getColorNames"), (PyCFunction)scribus_colornames, METH_NOARGS, tr(scribus_colornames__doc__)},
00314        {const_cast<char*>("getColor"), scribus_getcolor, METH_VARARGS, tr(scribus_getcolor__doc__)},
00315        {const_cast<char*>("getColorAsRGB"), scribus_getcolorasrgb, METH_VARARGS, tr(scribus_getcolorasrgb__doc__)},
00316        {const_cast<char*>("getColumnGap"), scribus_getcolumngap, METH_VARARGS, tr(scribus_getcolumngap__doc__)},
00317        {const_cast<char*>("getColumns"), scribus_getcolumns, METH_VARARGS, tr(scribus_getcolumns__doc__)},
00318        {const_cast<char*>("getCornerRadius"), scribus_getcornerrad, METH_VARARGS, tr(scribus_getcornerrad__doc__)},
00319        {const_cast<char*>("getFillColor"), scribus_getfillcolor, METH_VARARGS, tr(scribus_getfillcolor__doc__)},
00320        {const_cast<char*>("getFillShade"), scribus_getfillshade, METH_VARARGS, tr(scribus_getfillshade__doc__)},
00321        {const_cast<char*>("getFillBlendmode"), scribus_getfillblend, METH_VARARGS, tr(scribus_getfillblend__doc__)},
00322        {const_cast<char*>("getFillTransparency"), scribus_getfilltrans, METH_VARARGS, tr(scribus_getfilltrans__doc__)},
00323        {const_cast<char*>("getLineBlendmode"), scribus_getlineblend, METH_VARARGS, tr(scribus_getlineblend__doc__)},
00324        {const_cast<char*>("getLineTransparency"), scribus_getlinetrans, METH_VARARGS, tr(scribus_getlinetrans__doc__)},
00325        {const_cast<char*>("getFontNames"), (PyCFunction)scribus_fontnames, METH_NOARGS, tr(scribus_fontnames__doc__)},
00326        {const_cast<char*>("getFont"), scribus_getfont, METH_VARARGS, tr(scribus_getfont__doc__)},
00327        {const_cast<char*>("getFontSize"), scribus_getfontsize, METH_VARARGS, tr(scribus_getfontsize__doc__)},
00328        {const_cast<char*>("getGuiLanguage"), (PyCFunction)scribus_getlanguage, METH_NOARGS, tr(scribus_getlanguage__doc__)},
00329        {const_cast<char*>("getHGuides"), (PyCFunction)scribus_getHguides, METH_NOARGS, tr(scribus_getHguides__doc__)},
00330        {const_cast<char*>("getImageFile"), scribus_getimgname, METH_VARARGS, tr(scribus_getimgname__doc__)},
00331        {const_cast<char*>("getImageScale"), scribus_getimgscale, METH_VARARGS, tr(scribus_getimgscale__doc__)},
00332        {const_cast<char*>("getLayers"), (PyCFunction)scribus_getlayers, METH_NOARGS, tr(scribus_getlayers__doc__)},
00333        {const_cast<char*>("getLayerBlendmode"), scribus_glayerblend, METH_VARARGS, tr(scribus_glayerblend__doc__)},
00334        {const_cast<char*>("getLayerTransparency"), scribus_glayertrans, METH_VARARGS, tr(scribus_glayertrans__doc__)},
00335        {const_cast<char*>("getLineCap"), scribus_getlineend, METH_VARARGS, tr(scribus_getlineend__doc__)},
00336        {const_cast<char*>("getLineColor"), scribus_getlinecolor, METH_VARARGS, tr(scribus_getlinecolor__doc__)},
00337        {const_cast<char*>("getLineJoin"), scribus_getlinejoin, METH_VARARGS, tr(scribus_getlinejoin__doc__)},
00338        {const_cast<char*>("getLineShade"), scribus_getlineshade, METH_VARARGS, tr(scribus_getlineshade__doc__)},
00339        {const_cast<char*>("getLineSpacing"), scribus_getlinespace, METH_VARARGS, tr(scribus_getlinespace__doc__)},
00340        {const_cast<char*>("getLineStyle"), scribus_getlinestyle, METH_VARARGS, tr(scribus_getlinestyle__doc__)},
00341        {const_cast<char*>("getLineWidth"), scribus_getlinewidth, METH_VARARGS, tr(scribus_getlinewidth__doc__)},
00342        {const_cast<char*>("getPageItems"), (PyCFunction)scribus_getpageitems, METH_NOARGS, tr(scribus_getpageitems__doc__)},
00343        {const_cast<char*>("getPageMargins"), (PyCFunction)scribus_getpagemargins, METH_NOARGS, tr(scribus_getpagemargins__doc__)},
00344        {const_cast<char*>("getPageType"), (PyCFunction)scribus_pageposition, METH_VARARGS, tr(scribus_pageposition__doc__)},
00345        {const_cast<char*>("getPageSize"), (PyCFunction)scribus_pagedimension, METH_NOARGS, tr(scribus_pagedimension__doc__)}, // just an alias to PageDimension()
00346        {const_cast<char*>("getPosition"), scribus_getposi, METH_VARARGS, tr(scribus_getposi__doc__)},
00347        {const_cast<char*>("getRotation"), scribus_getrotation, METH_VARARGS, tr(scribus_getrotation__doc__)},
00348        {const_cast<char*>("getSelectedObject"), scribus_getselobjnam, METH_VARARGS, tr(scribus_getselobjnam__doc__)},
00349        {const_cast<char*>("getSize"), scribus_getsize, METH_VARARGS, tr(scribus_getsize__doc__)},
00350        {const_cast<char*>("getTextColor"), scribus_getlinecolor, METH_VARARGS, tr(scribus_getlinecolor__doc__)},
00351        {const_cast<char*>("getTextLength"), scribus_gettextsize, METH_VARARGS, tr(scribus_gettextsize__doc__)},
00352        {const_cast<char*>("getTextLines"), scribus_gettextlines, METH_VARARGS, tr(scribus_gettextlines__doc__)},
00353        {const_cast<char*>("getText"), scribus_getframetext, METH_VARARGS, tr(scribus_getframetext__doc__)},
00354        {const_cast<char*>("getTextShade"), scribus_getlineshade, METH_VARARGS, tr(scribus_getlineshade__doc__)},
00355        {const_cast<char*>("getUnit"), (PyCFunction)scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)},
00356        {const_cast<char*>("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)},
00357        {const_cast<char*>("getXFontNames"), (PyCFunction)scribus_xfontnames, METH_NOARGS, tr(scribus_xfontnames__doc__)},
00358        {const_cast<char*>("gotoPage"), scribus_gotopage, METH_VARARGS, tr(scribus_gotopage__doc__)},
00359        {const_cast<char*>("groupObjects"), scribus_groupobj, METH_VARARGS, tr(scribus_groupobj__doc__)},
00360        {const_cast<char*>("haveDoc"), (PyCFunction)scribus_havedoc, METH_NOARGS, tr(scribus_havedoc__doc__)},
00361        {const_cast<char*>("placeSVG"), scribus_placesvg, METH_VARARGS, tr(scribus_placesvg__doc__)},
00362        {const_cast<char*>("placeEPS"), scribus_placeeps, METH_VARARGS, tr(scribus_placeeps__doc__)},
00363        {const_cast<char*>("placeSXD"), scribus_placesxd, METH_VARARGS, tr(scribus_placesxd__doc__)},
00364        {const_cast<char*>("placeODG"), scribus_placeodg, METH_VARARGS, tr(scribus_placeodg__doc__)},
00365        {const_cast<char*>("insertText"), scribus_inserttext, METH_VARARGS, tr(scribus_inserttext__doc__)},
00366        {const_cast<char*>("isLayerPrintable"), scribus_glayerprint, METH_VARARGS, tr(scribus_glayerprint__doc__)},
00367        {const_cast<char*>("isLayerVisible"), scribus_glayervisib, METH_VARARGS, tr(scribus_glayervisib__doc__)},
00368        {const_cast<char*>("isLayerLocked"), scribus_glayerlock, METH_VARARGS, tr(scribus_glayerlock__doc__)},
00369        {const_cast<char*>("isLayerOutlined"), scribus_glayeroutline, METH_VARARGS, tr(scribus_glayeroutline__doc__)},
00370        {const_cast<char*>("isLayerFlow"), scribus_glayerflow, METH_VARARGS, tr(scribus_glayerflow__doc__)},
00371        {const_cast<char*>("isLocked"), scribus_islocked, METH_VARARGS, tr(scribus_islocked__doc__)},
00372        {const_cast<char*>("linkTextFrames"), scribus_linktextframes, METH_VARARGS, tr(scribus_linktextframes__doc__)},
00373        {const_cast<char*>("loadImage"), scribus_loadimage, METH_VARARGS, tr(scribus_loadimage__doc__)},
00374        {const_cast<char*>("loadStylesFromFile"), scribus_loadstylesfromfile, METH_VARARGS, tr(scribus_loadstylesfromfile__doc__)},
00375        {const_cast<char*>("lockObject"), scribus_lockobject, METH_VARARGS, tr(scribus_lockobject__doc__)},
00376        {const_cast<char*>("masterPageNames"), (PyCFunction)scribus_masterpagenames, METH_NOARGS, tr(scribus_masterpagenames__doc__)},
00377        {const_cast<char*>("messagebarText"), scribus_messagebartext, METH_VARARGS, tr(scribus_messagebartext__doc__)},
00378        {const_cast<char*>("messageBox"), (PyCFunction)scribus_messdia, METH_VARARGS|METH_KEYWORDS, tr(scribus_messdia__doc__)},
00379        {const_cast<char*>("moveObjectAbs"), scribus_moveobjabs, METH_VARARGS, tr(scribus_moveobjabs__doc__)},
00380        {const_cast<char*>("moveObject"), scribus_moveobjrel, METH_VARARGS, tr(scribus_moveobjrel__doc__)},
00381        {const_cast<char*>("newDocDialog"), (PyCFunction)scribus_newdocdia, METH_NOARGS, tr(scribus_newdocdia__doc__)},
00382        {const_cast<char*>("newDoc"), scribus_newdoc, METH_VARARGS, tr(scribus_newdoc__doc__)},
00383        {const_cast<char*>("newDocument"), scribus_newdocument, METH_VARARGS, tr(scribus_newdocument__doc__)},
00384        {const_cast<char*>("newPage"), scribus_newpage, METH_VARARGS, tr(scribus_newpage__doc__)},
00385        {const_cast<char*>("newStyleDialog"), scribus_newstyledialog, METH_NOARGS, tr(scribus_newstyledialog__doc__)},
00386        {const_cast<char*>("objectExists"),scribus_objectexists, METH_VARARGS, tr(scribus_objectexists__doc__)},
00387        {const_cast<char*>("openDoc"), scribus_opendoc, METH_VARARGS, tr(scribus_opendoc__doc__)},
00388        {const_cast<char*>("pageCount"), (PyCFunction)scribus_pagecount, METH_NOARGS, tr(scribus_pagecount__doc__)},
00389        {const_cast<char*>("pageDimension"), (PyCFunction)scribus_pagedimension, METH_NOARGS, "Obsolete function. Don't use it."},
00390        {const_cast<char*>("progressReset"), (PyCFunction)scribus_progressreset, METH_NOARGS, tr(scribus_progressreset__doc__)},
00391        {const_cast<char*>("progressSet"), scribus_progresssetprogress, METH_VARARGS, tr(scribus_progresssetprogress__doc__)},
00392        {const_cast<char*>("progressTotal"), scribus_progresssettotalsteps, METH_VARARGS, tr(scribus_progresssettotalsteps__doc__)},
00393        {const_cast<char*>("redrawAll"), (PyCFunction)scribus_redraw, METH_NOARGS, tr(scribus_redraw__doc__)},
00394        {const_cast<char*>("renderFont"), (PyCFunction)scribus_renderfont, METH_KEYWORDS, tr(scribus_renderfont__doc__)},
00395        {const_cast<char*>("replaceColor"), scribus_replcolor, METH_VARARGS, tr(scribus_replcolor__doc__)},
00396        {const_cast<char*>("rotateObjectAbs"), scribus_rotobjabs, METH_VARARGS, tr(scribus_rotobjabs__doc__)},
00397        {const_cast<char*>("rotateObject"), scribus_rotobjrel, METH_VARARGS, tr(scribus_rotobjrel__doc__)},
00398        {const_cast<char*>("saveDocAs"), scribus_savedocas, METH_VARARGS, tr(scribus_savedocas__doc__)},
00399        {const_cast<char*>("saveDoc"), (PyCFunction)scribus_savedoc, METH_NOARGS, tr(scribus_savedoc__doc__)},
00400        {const_cast<char*>("savePageAsEPS"), scribus_savepageeps, METH_VARARGS, tr(scribus_savepageeps__doc__)},
00401        {const_cast<char*>("scaleGroup"), scribus_scalegroup, METH_VARARGS, tr(scribus_scalegroup__doc__)},
00402        {const_cast<char*>("scaleImage"), scribus_scaleimage, METH_VARARGS, tr(scribus_scaleimage__doc__)},
00403        {const_cast<char*>("selectionCount"), (PyCFunction)scribus_selcount, METH_NOARGS, tr(scribus_selcount__doc__)},
00404        {const_cast<char*>("selectObject"), scribus_selectobj, METH_VARARGS, tr(scribus_selectobj__doc__)},
00405        {const_cast<char*>("selectText"), scribus_selecttext, METH_VARARGS, tr(scribus_selecttext__doc__)},
00406        {const_cast<char*>("sentToLayer"), scribus_senttolayer, METH_VARARGS, tr(scribus_senttolayer__doc__)},
00407        {const_cast<char*>("setActiveLayer"), scribus_setactlayer, METH_VARARGS, tr(scribus_setactlayer__doc__)},
00408        {const_cast<char*>("setPDFBookmark"), scribus_setpdfbookmark, METH_VARARGS, tr(scribus_setpdfbookmark__doc__)},
00409        {const_cast<char*>("isPDFBookmark"), scribus_ispdfbookmark, METH_VARARGS, tr(scribus_ispdfbookmark__doc__)},
00410        {const_cast<char*>("setColumnGap"), scribus_setcolumngap, METH_VARARGS, tr(scribus_setcolumngap__doc__)},
00411        {const_cast<char*>("setColumns"), scribus_setcolumns, METH_VARARGS, tr(scribus_setcolumns__doc__)},
00412        {const_cast<char*>("setCornerRadius"), scribus_setcornerrad, METH_VARARGS, tr(scribus_setcornerrad__doc__)},
00413        {const_cast<char*>("setCursor"), scribus_setcursor, METH_VARARGS, tr(scribus_setcursor__doc__)},
00414        {const_cast<char*>("setDocType"), scribus_setdoctype, METH_VARARGS, tr(scribus_setdoctype__doc__)},
00415        {const_cast<char*>("setFillColor"), scribus_setfillcolor, METH_VARARGS, tr(scribus_setfillcolor__doc__)},
00416        {const_cast<char*>("setFillTransparency"), scribus_setfilltrans, METH_VARARGS, tr(scribus_setfilltrans__doc__)},
00417        {const_cast<char*>("setFillBlendmode"), scribus_setfillblend, METH_VARARGS, tr(scribus_setfillblend__doc__)},
00418        {const_cast<char*>("setFillShade"), scribus_setfillshade, METH_VARARGS, tr(scribus_setfillshade__doc__)},
00419        {const_cast<char*>("setFont"), scribus_setfont, METH_VARARGS, tr(scribus_setfont__doc__)},
00420        {const_cast<char*>("setFontSize"), scribus_setfontsize, METH_VARARGS, tr(scribus_setfontsize__doc__)},
00421        {const_cast<char*>("setGradientFill"), scribus_setgradfill, METH_VARARGS, tr(scribus_setgradfill__doc__)},
00422        {const_cast<char*>("setHGuides"), scribus_setHguides, METH_VARARGS, tr(scribus_setHguides__doc__)},
00423        {const_cast<char*>("setInfo"), scribus_setinfo, METH_VARARGS, tr(scribus_setinfo__doc__)},
00424        {const_cast<char*>("setLayerPrintable"), scribus_layerprint, METH_VARARGS, tr(scribus_layerprint__doc__)},
00425        {const_cast<char*>("setLayerVisible"), scribus_layervisible, METH_VARARGS, tr(scribus_layervisible__doc__)},
00426        {const_cast<char*>("setLayerLocked"), scribus_layerlock, METH_VARARGS, tr(scribus_layerlock__doc__)},
00427        {const_cast<char*>("setLayerOutlined"), scribus_layeroutline, METH_VARARGS, tr(scribus_layeroutline__doc__)},
00428        {const_cast<char*>("setLayerFlow"), scribus_layerflow, METH_VARARGS, tr(scribus_layerflow__doc__)},
00429        {const_cast<char*>("setLayerBlendmode"), scribus_layerblend, METH_VARARGS, tr(scribus_layerblend__doc__)},
00430        {const_cast<char*>("setLayerTransparency"), scribus_layertrans, METH_VARARGS, tr(scribus_layertrans__doc__)},
00431        {const_cast<char*>("setLineCap"), scribus_setlineend, METH_VARARGS, tr(scribus_setlineend__doc__)},
00432        {const_cast<char*>("setLineColor"), scribus_setlinecolor, METH_VARARGS, tr(scribus_setlinecolor__doc__)},
00433        {const_cast<char*>("setLineTransparency"), scribus_setlinetrans, METH_VARARGS, tr(scribus_setlinetrans__doc__)},
00434        {const_cast<char*>("setLineBlendmode"), scribus_setlineblend, METH_VARARGS, tr(scribus_setlineblend__doc__)},
00435        {const_cast<char*>("setLineJoin"), scribus_setlinejoin, METH_VARARGS, tr(scribus_setlinejoin__doc__)},
00436        {const_cast<char*>("setLineShade"), scribus_setlineshade, METH_VARARGS, tr(scribus_setlineshade__doc__)},
00437        {const_cast<char*>("setLineSpacing"), scribus_setlinespace, METH_VARARGS, tr(scribus_setlinespace__doc__)},
00438        {const_cast<char*>("setLineStyle"), scribus_setlinestyle, METH_VARARGS, tr(scribus_setlinestyle__doc__)},
00439        {const_cast<char*>("setLineWidth"), scribus_setlinewidth, METH_VARARGS, tr(scribus_setlinewidth__doc__)},
00440        {const_cast<char*>("setMargins"), scribus_setmargins, METH_VARARGS, tr(scribus_setmargins__doc__)},
00441        {const_cast<char*>("setMultiLine"), scribus_setmultiline, METH_VARARGS, tr(scribus_setmultiline__doc__)},
00442        // duplicity? {"setMultiLine", scribus_setmultiline, METH_VARARGS, "TODO: docstring"},
00443        {const_cast<char*>("setRedraw"), scribus_setredraw, METH_VARARGS, tr(scribus_setredraw__doc__)},
00444        // 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."},
00445        {const_cast<char*>("setScaleImageToFrame"), (PyCFunction)scribus_setscaleimagetoframe, METH_KEYWORDS, tr(scribus_setscaleimagetoframe__doc__)},
00446        {const_cast<char*>("setStyle"), scribus_setstyle, METH_VARARGS, tr(scribus_setstyle__doc__)},
00447        {const_cast<char*>("setTextAlignment"), scribus_setalign, METH_VARARGS, tr(scribus_setalign__doc__)},
00448        {const_cast<char*>("setTextColor"), scribus_settextfill, METH_VARARGS, tr(scribus_settextfill__doc__)},
00449        {const_cast<char*>("setText"), scribus_setboxtext, METH_VARARGS, tr(scribus_setboxtext__doc__)},
00450        {const_cast<char*>("setTextShade"), scribus_settextshade, METH_VARARGS, tr(scribus_settextshade__doc__)},
00451        {const_cast<char*>("setTextStroke"), scribus_settextstroke, METH_VARARGS, tr(scribus_settextstroke__doc__)},
00452        {const_cast<char*>("setUnit"), scribus_setunit, METH_VARARGS, tr(scribus_setunit__doc__)},
00453        {const_cast<char*>("setVGuides"), scribus_setVguides, METH_VARARGS, tr(scribus_setVguides__doc__)},
00454        {const_cast<char*>("sizeObject"), scribus_sizeobjabs, METH_VARARGS, tr(scribus_sizeobjabs__doc__)},
00455        {const_cast<char*>("statusMessage"), scribus_messagebartext, METH_VARARGS, tr(scribus_messagebartext__doc__)},
00456        {const_cast<char*>("textFlowMode"), scribus_textflow, METH_VARARGS, tr(scribus_textflow__doc__)},
00457        {const_cast<char*>("traceText"), scribus_tracetext, METH_VARARGS, tr(scribus_tracetext__doc__)},
00458        {const_cast<char*>("unGroupObject"), scribus_ungroupobj, METH_VARARGS, tr(scribus_ungroupobj__doc__)},
00459        {const_cast<char*>("unlinkTextFrames"), scribus_unlinktextframes, METH_VARARGS, tr(scribus_unlinktextframes__doc__)},
00460        {const_cast<char*>("valueDialog"), scribus_valdialog, METH_VARARGS, tr(scribus_valdialog__doc__)},
00461        {const_cast<char*>("textOverflows"), (PyCFunction)scribus_istextoverflowing, METH_KEYWORDS, tr(scribus_istextoverflowing__doc__)},
00462        {const_cast<char*>("zoomDocument"), scribus_zoomdocument, METH_VARARGS, tr(scribus_zoomdocument__doc__)},
00463        // Property magic
00464        {const_cast<char*>("getPropertyCType"), (PyCFunction)scribus_propertyctype, METH_KEYWORDS, tr(scribus_propertyctype__doc__)},
00465        {const_cast<char*>("getPropertyNames"), (PyCFunction)scribus_getpropertynames, METH_KEYWORDS, tr(scribus_getpropertynames__doc__)},
00466        {const_cast<char*>("getProperty"), (PyCFunction)scribus_getproperty, METH_KEYWORDS, tr(scribus_getproperty__doc__)},
00467        {const_cast<char*>("setProperty"), (PyCFunction)scribus_setproperty, METH_KEYWORDS, tr(scribus_setproperty__doc__)},
00468        {const_cast<char*>("getChildren"), (PyCFunction)scribus_getchildren, METH_KEYWORDS, tr(scribus_getchildren__doc__)},
00469        {const_cast<char*>("getChild"), (PyCFunction)scribus_getchild, METH_KEYWORDS, tr(scribus_getchild__doc__)},
00470        // by Christian Hausknecht
00471        {const_cast<char*>("duplicateObject"), scribus_duplicateobject, METH_VARARGS, tr(scribus_duplicateobject__doc__)},
00472        // Internal methods - Not for public use
00473        {const_cast<char*>("retval"), (PyCFunction)scribus_retval, METH_VARARGS, const_cast<char*>("Scribus internal.")},
00474        {const_cast<char*>("getval"), (PyCFunction)scribus_getval, METH_NOARGS, const_cast<char*>("Scribus internal.")},
00475        {NULL, (PyCFunction)(0), 0, NULL} /* sentinel */
00476 };
00477 
00478 void initscribus_failed(const char* fileName, int lineNo)
00479 {
00480        qDebug("Scripter setup failed (%s:%i)", fileName, lineNo);
00481        if (PyErr_Occurred())
00482               PyErr_Print();
00483        return;
00484 }
00485 
00486 void initscribus(ScribusMainWindow *pl)
00487 {
00488        if (!scripterCore)
00489        {
00490               qWarning("scriptplugin: Tried to init scribus module, but no scripter core. Aborting.");
00491               return;
00492        }
00493        PyObject *m, *d;
00494        PyImport_AddModule((char*)"scribus");
00495        PyType_Ready(&Printer_Type);
00496        PyType_Ready(&PDFfile_Type);
00497        PyType_Ready(&ImageExport_Type);
00498        m = Py_InitModule((char*)"scribus", scribus_methods);
00499        Py_INCREF(&Printer_Type);
00500        PyModule_AddObject(m, (char*)"Printer", (PyObject *) &Printer_Type);
00501        Py_INCREF(&PDFfile_Type);
00502        PyModule_AddObject(m, (char*)"PDFfile", (PyObject *) &PDFfile_Type);
00503        Py_INCREF(&ImageExport_Type);
00504        PyModule_AddObject(m, (char*)"ImageExport", (PyObject *) &ImageExport_Type);
00505        d = PyModule_GetDict(m);
00506 
00507        // Set up the module exceptions
00508        // common exc.
00509        ScribusException = PyErr_NewException((char*)"scribus.ScribusException", NULL, NULL);
00510        Py_INCREF(ScribusException);
00511        PyModule_AddObject(m, (char*)"ScribusException", ScribusException);
00512        // no doc open
00513        NoDocOpenError = PyErr_NewException((char*)"scribus.NoDocOpenError", ScribusException, NULL);
00514        Py_INCREF(NoDocOpenError);
00515        PyModule_AddObject(m, (char*)"NoDocOpenError", NoDocOpenError);
00516        // wrong type of frame for operation
00517        WrongFrameTypeError = PyErr_NewException((char*)"scribus.WrongFrameTypeError", ScribusException, NULL);
00518        Py_INCREF(WrongFrameTypeError);
00519        PyModule_AddObject(m, (char*)"WrongFrameTypeError", WrongFrameTypeError);
00520        // Couldn't find named object, or no named object and no selection
00521        NoValidObjectError = PyErr_NewException((char*)"scribus.NoValidObjectError", ScribusException, NULL);
00522        Py_INCREF(NoValidObjectError);
00523        PyModule_AddObject(m, (char*)"NoValidObjectError", NoValidObjectError);
00524        // Couldn't find the specified resource - font, color, etc.
00525        NotFoundError = PyErr_NewException((char*)"scribus.NotFoundError", ScribusException, NULL);
00526        Py_INCREF(NotFoundError);
00527        PyModule_AddObject(m, (char*)"NotFoundError", NotFoundError);
00528        // Tried to create an object with the same name as one that already exists
00529        NameExistsError = PyErr_NewException((char*)"scribus.NameExistsError", ScribusException, NULL);
00530        Py_INCREF(NameExistsError);
00531        PyModule_AddObject(m, (char*)"NameExistsError", NameExistsError);
00532        // Done with exception setup
00533 
00534        // CONSTANTS
00535        PyDict_SetItemString(d, const_cast<char*>("UNIT_POINTS"), PyInt_FromLong(unitIndexFromString("pt")));
00536        PyDict_SetItemString(d, const_cast<char*>("UNIT_MILLIMETERS"), PyInt_FromLong(unitIndexFromString("mm")));
00537        PyDict_SetItemString(d, const_cast<char*>("UNIT_INCHES"), PyInt_FromLong(unitIndexFromString("in")));
00538        PyDict_SetItemString(d, const_cast<char*>("UNIT_PICAS"), PyInt_FromLong(unitIndexFromString("p")));
00539        PyDict_SetItemString(d, const_cast<char*>("UNIT_CENTIMETRES"), PyInt_FromLong(unitIndexFromString("cm")));
00540        PyDict_SetItemString(d, const_cast<char*>("UNIT_CICERO"), PyInt_FromLong(unitIndexFromString("c")));
00541        PyDict_SetItemString(d, const_cast<char*>("PORTRAIT"), Py_BuildValue(const_cast<char*>("i"), portraitPage));
00542        PyDict_SetItemString(d, const_cast<char*>("LANDSCAPE"), Py_BuildValue(const_cast<char*>("i"), landscapePage));
00543        PyDict_SetItemString(d, const_cast<char*>("NOFACINGPAGES"), Py_BuildValue(const_cast<char*>("i"), 0));
00544        PyDict_SetItemString(d, const_cast<char*>("FACINGPAGES"),  Py_BuildValue(const_cast<char*>("i"), 1));
00545        PyDict_SetItemString(d, const_cast<char*>("FIRSTPAGERIGHT"), Py_BuildValue(const_cast<char*>("i"), 1));
00546        PyDict_SetItemString(d, const_cast<char*>("FIRSTPAGELEFT"), Py_BuildValue(const_cast<char*>("i"), 0));
00547        PyDict_SetItemString(d, const_cast<char*>("ALIGN_LEFT"), Py_BuildValue(const_cast<char*>("i"), 0));
00548        PyDict_SetItemString(d, const_cast<char*>("ALIGN_RIGHT"), Py_BuildValue(const_cast<char*>("i"), 2));
00549        PyDict_SetItemString(d, const_cast<char*>("ALIGN_CENTERED"), Py_BuildValue(const_cast<char*>("i"), 1));
00550        PyDict_SetItemString(d, const_cast<char*>("ALIGN_BLOCK"), Py_BuildValue(const_cast<char*>("i"), 4));
00551        PyDict_SetItemString(d, const_cast<char*>("ALIGN_FORCED"), Py_BuildValue(const_cast<char*>("i"), 4));
00552        PyDict_SetItemString(d, const_cast<char*>("FILL_NOG"), Py_BuildValue(const_cast<char*>("i"), 0));
00553        PyDict_SetItemString(d, const_cast<char*>("FILL_HORIZONTALG"), Py_BuildValue(const_cast<char*>("i"), 1));
00554        PyDict_SetItemString(d, const_cast<char*>("FILL_VERTICALG"), Py_BuildValue(const_cast<char*>("i"), 2));
00555        PyDict_SetItemString(d, const_cast<char*>("FILL_DIAGONALG"), Py_BuildValue(const_cast<char*>("i"), 3));
00556        PyDict_SetItemString(d, const_cast<char*>("FILL_CROSSDIAGONALG"), Py_BuildValue(const_cast<char*>("i"), 4));
00557        PyDict_SetItemString(d, const_cast<char*>("FILL_RADIALG"), Py_BuildValue(const_cast<char*>("i"), 5));
00558        PyDict_SetItemString(d, const_cast<char*>("LINE_SOLID"), Py_BuildValue(const_cast<char*>("i"), Qt::SolidLine));
00559        PyDict_SetItemString(d, const_cast<char*>("LINE_DASH"), Py_BuildValue(const_cast<char*>("i"), Qt::DashLine));
00560        PyDict_SetItemString(d, const_cast<char*>("LINE_DOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DotLine));
00561        PyDict_SetItemString(d, const_cast<char*>("LINE_DASHDOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DashDotLine));
00562        PyDict_SetItemString(d, const_cast<char*>("LINE_DASHDOTDOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DashDotDotLine));
00563        PyDict_SetItemString(d, const_cast<char*>("JOIN_MITTER"), Py_BuildValue(const_cast<char*>("i"), Qt::MiterJoin));
00564        PyDict_SetItemString(d, const_cast<char*>("JOIN_BEVEL"), Py_BuildValue(const_cast<char*>("i"), Qt::BevelJoin));
00565        PyDict_SetItemString(d, const_cast<char*>("JOIN_ROUND"), Py_BuildValue(const_cast<char*>("i"), Qt::RoundJoin));
00566        PyDict_SetItemString(d, const_cast<char*>("CAP_FLAT"), Py_BuildValue(const_cast<char*>("i"), Qt::FlatCap));
00567        PyDict_SetItemString(d, const_cast<char*>("CAP_SQUARE"), Py_BuildValue(const_cast<char*>("i"), Qt::SquareCap));
00568        PyDict_SetItemString(d, const_cast<char*>("CAP_ROUND"), Py_BuildValue(const_cast<char*>("i"), Qt::RoundCap));
00569        PyDict_SetItemString(d, const_cast<char*>("BUTTON_NONE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::NoButton));
00570        PyDict_SetItemString(d, const_cast<char*>("BUTTON_OK"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Ok));
00571        PyDict_SetItemString(d, const_cast<char*>("BUTTON_CANCEL"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Cancel));
00572        PyDict_SetItemString(d, const_cast<char*>("BUTTON_YES"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Yes));
00573        PyDict_SetItemString(d, const_cast<char*>("BUTTON_NO"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::No));
00574        PyDict_SetItemString(d, const_cast<char*>("BUTTON_ABORT"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Abort));
00575        PyDict_SetItemString(d, const_cast<char*>("BUTTON_RETRY"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Retry));
00576        PyDict_SetItemString(d, const_cast<char*>("BUTTON_IGNORE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Ignore));
00577        PyDict_SetItemString(d, const_cast<char*>("ICON_NONE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::NoIcon));
00578        PyDict_SetItemString(d, const_cast<char*>("ICON_INFORMATION"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Information));
00579        PyDict_SetItemString(d, const_cast<char*>("ICON_WARNING"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Warning));
00580        PyDict_SetItemString(d, const_cast<char*>("ICON_CRITICAL"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Critical));
00581        PyDict_SetItemString(d, const_cast<char*>("PAPER_A0"), Py_BuildValue(const_cast<char*>("(ff)"), 2380.0, 3368.0));
00582        PyDict_SetItemString(d, const_cast<char*>("PAPER_A1"), Py_BuildValue(const_cast<char*>("(ff)"), 1684.0, 2380.0));
00583        PyDict_SetItemString(d, const_cast<char*>("PAPER_A2"), Py_BuildValue(const_cast<char*>("(ff)"), 1190.0, 1684.0));
00584        PyDict_SetItemString(d, const_cast<char*>("PAPER_A3"), Py_BuildValue(const_cast<char*>("(ff)"), 842.0, 1190.0));
00585        PyDict_SetItemString(d, const_cast<char*>("PAPER_A4"), Py_BuildValue(const_cast<char*>("(ff)"), 595.0, 842.0));
00586        PyDict_SetItemString(d, const_cast<char*>("PAPER_A5"), Py_BuildValue(const_cast<char*>("(ff)"), 421.0, 595.0));
00587        PyDict_SetItemString(d, const_cast<char*>("PAPER_A6"), Py_BuildValue(const_cast<char*>("(ff)"), 297.0, 421.0));
00588        PyDict_SetItemString(d, const_cast<char*>("PAPER_A7"), Py_BuildValue(const_cast<char*>("(ff)"), 210.0, 297.0));
00589        PyDict_SetItemString(d, const_cast<char*>("PAPER_A8"), Py_BuildValue(const_cast<char*>("(ff)"), 148.0, 210.0));
00590        PyDict_SetItemString(d, const_cast<char*>("PAPER_A9"), Py_BuildValue(const_cast<char*>("(ff)"), 105.0, 148.0));
00591        PyDict_SetItemString(d, const_cast<char*>("PAPER_B0"), Py_BuildValue(const_cast<char*>("(ff)"), 2836.0, 4008.0));
00592        PyDict_SetItemString(d, const_cast<char*>("PAPER_B1"), Py_BuildValue(const_cast<char*>("(ff)"), 2004.0, 2836.0));
00593        PyDict_SetItemString(d, const_cast<char*>("PAPER_B2"), Py_BuildValue(const_cast<char*>("(ff)"), 1418.0, 2004.0));
00594        PyDict_SetItemString(d, const_cast<char*>("PAPER_B3"), Py_BuildValue(const_cast<char*>("(ff)"), 1002.0, 1418.0));
00595        PyDict_SetItemString(d, const_cast<char*>("PAPER_B4"), Py_BuildValue(const_cast<char*>("(ff)"), 709.0, 1002.0));
00596        PyDict_SetItemString(d, const_cast<char*>("PAPER_B5"), Py_BuildValue(const_cast<char*>("(ff)"), 501.0, 709.0));
00597        PyDict_SetItemString(d, const_cast<char*>("PAPER_B6"), Py_BuildValue(const_cast<char*>("(ff)"), 355.0, 501.0));
00598        PyDict_SetItemString(d, const_cast<char*>("PAPER_B7"), Py_BuildValue(const_cast<char*>("(ff)"), 250.0, 355.0));
00599        PyDict_SetItemString(d, const_cast<char*>("PAPER_B8"), Py_BuildValue(const_cast<char*>("(ff)"), 178.0, 250.0));
00600        PyDict_SetItemString(d, const_cast<char*>("PAPER_B9"), Py_BuildValue(const_cast<char*>("(ff)"), 125.0, 178.0));
00601        PyDict_SetItemString(d, const_cast<char*>("PAPER_B10"), Py_BuildValue(const_cast<char*>("(ff)"), 89.0, 125.0));
00602        PyDict_SetItemString(d, const_cast<char*>("PAPER_C5E"), Py_BuildValue(const_cast<char*>("(ff)"), 462.0, 649.0));
00603        PyDict_SetItemString(d, const_cast<char*>("PAPER_COMM10E"), Py_BuildValue(const_cast<char*>("(ff)"), 298.0, 683.0));
00604        PyDict_SetItemString(d, const_cast<char*>("PAPER_DLE"),  Py_BuildValue(const_cast<char*>("(ff)"), 312.0, 624.0));
00605        PyDict_SetItemString(d, const_cast<char*>("PAPER_EXECUTIVE"), Py_BuildValue(const_cast<char*>("(ff)"), 542.0, 720.0));
00606        PyDict_SetItemString(d, const_cast<char*>("PAPER_FOLIO"), Py_BuildValue(const_cast<char*>("(ff)"), 595.0, 935.0));
00607        PyDict_SetItemString(d, const_cast<char*>("PAPER_LEDGER"), Py_BuildValue(const_cast<char*>("(ff)"), 1224.0, 792.0));
00608        PyDict_SetItemString(d, const_cast<char*>("PAPER_LEGAL"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 1008.0));
00609        PyDict_SetItemString(d, const_cast<char*>("PAPER_LETTER"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 792.0));
00610        PyDict_SetItemString(d, const_cast<char*>("PAPER_TABLOID"), Py_BuildValue(const_cast<char*>("(ff)"), 792.0, 1224.0));
00611        PyDict_SetItemString(d, const_cast<char*>("NORMAL"), Py_BuildValue(const_cast<char*>("i"), 0));
00612        PyDict_SetItemString(d, const_cast<char*>("DARKEN"), Py_BuildValue(const_cast<char*>("i"), 1));
00613        PyDict_SetItemString(d, const_cast<char*>("LIGHTEN"), Py_BuildValue(const_cast<char*>("i"), 2));
00614        PyDict_SetItemString(d, const_cast<char*>("MULTIPLY"), Py_BuildValue(const_cast<char*>("i"), 3));
00615        PyDict_SetItemString(d, const_cast<char*>("SCREEN"), Py_BuildValue(const_cast<char*>("i"), 4));
00616        PyDict_SetItemString(d, const_cast<char*>("OVERLAY"), Py_BuildValue(const_cast<char*>("i"), 5));
00617        PyDict_SetItemString(d, const_cast<char*>("HARD_LIGHT"), Py_BuildValue(const_cast<char*>("i"), 6));
00618        PyDict_SetItemString(d, const_cast<char*>("SOFT_LIGHT"), Py_BuildValue(const_cast<char*>("i"), 7));
00619        PyDict_SetItemString(d, const_cast<char*>("DIFFERENCE"), Py_BuildValue(const_cast<char*>("i"), 8));
00620        PyDict_SetItemString(d, const_cast<char*>("EXCLUSION"), Py_BuildValue(const_cast<char*>("i"), 9));
00621        PyDict_SetItemString(d, const_cast<char*>("COLOR_DODGE"), Py_BuildValue(const_cast<char*>("i"), 10));
00622        PyDict_SetItemString(d, const_cast<char*>("COLOR_BURN"), Py_BuildValue(const_cast<char*>("i"), 11));
00623        PyDict_SetItemString(d, const_cast<char*>("HUE"), Py_BuildValue(const_cast<char*>("i"), 12));
00624        PyDict_SetItemString(d, const_cast<char*>("SATURATION"), Py_BuildValue(const_cast<char*>("i"), 13));
00625        PyDict_SetItemString(d, const_cast<char*>("COLOR"), Py_BuildValue(const_cast<char*>("i"), 14));
00626        PyDict_SetItemString(d, const_cast<char*>("LUMINOSITY"), Py_BuildValue(const_cast<char*>("i"), 15));
00627        // preset page layouts
00628        PyDict_SetItemString(d, const_cast<char*>("PAGE_1"), Py_BuildValue(const_cast<char*>("i"), 0));
00629        PyDict_SetItemString(d, const_cast<char*>("PAGE_2"), Py_BuildValue(const_cast<char*>("i"), 1));
00630        PyDict_SetItemString(d, const_cast<char*>("PAGE_3"), Py_BuildValue(const_cast<char*>("i"), 2));
00631        PyDict_SetItemString(d, const_cast<char*>("PAGE_4"), Py_BuildValue(const_cast<char*>("i"), 3));
00632 
00633        // Measurement units understood by Scribus's units.cpp functions are exported as constant conversion
00634        // factors to be used from Python.
00635        for (int i = 0; i <= unitGetMaxIndex(); ++i)
00636        {
00637               PyObject* value = PyFloat_FromDouble(unitGetRatioFromIndex(i));
00638               if (!value)
00639               {
00640                      initscribus_failed(__FILE__, __LINE__);
00641                      return;
00642               }
00643               // `in' is a reserved word in Python so we must replace it
00644               PyObject* name;
00645               if (unitGetStrFromIndex(i) == "in")
00646                      name = PyString_FromString("inch");
00647               else
00648                      name = PyString_FromString(unitGetStrFromIndex(i).ascii());
00649               if (!name)
00650               {
00651                      initscribus_failed(__FILE__, __LINE__);
00652                      return;
00653               }
00654               if (PyDict_SetItem(d, name, value))
00655               {
00656                      initscribus_failed(__FILE__, __LINE__);
00657                      return;
00658               }
00659        }
00660 
00661        // Export the Scribus version into the module namespace so scripts know what they're running in
00662        PyDict_SetItemString(d, const_cast<char*>("scribus_version"), PyString_FromString(const_cast<char*>(VERSION)));
00663        // Now build a version tuple like that provided by Python in sys.version_info
00664        // The tuple is of the form (major, minor, patchlevel, extraversion, reserved)
00665        QRegExp version_re("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
00666        int pos = version_re.search(QString(VERSION));
00667        // We ignore errors, causing the scribus_version_info attribute to simply not be created.
00668        // This will make acceses raise AttrbuteError.
00669        if (pos > -1)
00670        {
00671               int majorVersion = version_re.cap(1).toInt();
00672               int minorVersion = version_re.cap(2).toInt();
00673               int patchVersion = version_re.cap(3).toInt();
00674               QString extraVersion = version_re.cap(4);
00675               PyObject* versionTuple = Py_BuildValue(const_cast<char*>("(iiisi)"),\
00676                             majorVersion, minorVersion, patchVersion, (const char*)extraVersion.utf8(), 0);
00677               if (versionTuple != NULL)
00678                      PyDict_SetItemString(d, const_cast<char*>("scribus_version_info"), versionTuple);
00679               else
00680                      qDebug("Failed to build version tuple for version string '%s' in scripter", VERSION);
00681        }
00682        else
00683               qDebug("Couldn't parse version string '%s' in scripter", VERSION);
00684 
00685 //     ScMW = pl;
00686        // Function aliases for compatibility
00687        // We need to import the __builtins__, warnings and exceptions modules to be able to run
00688        // the generated Python functions from inside the `scribus' module's context.
00689        // This code makes it possible to extend the `scribus' module by running Python code
00690        // from C in other ways too.
00691        PyObject* builtinModule = PyImport_ImportModuleEx(const_cast<char*>("__builtin__"),
00692                      d, d, Py_BuildValue(const_cast<char*>("[]")));
00693        if (builtinModule == NULL)
00694        {
00695               qDebug("Failed to import __builtin__ module. Something is probably broken with your Python.");
00696               return;
00697        }
00698        PyDict_SetItemString(d, const_cast<char*>("__builtin__"), builtinModule);
00699        PyObject* exceptionsModule = PyImport_ImportModuleEx(const_cast<char*>("exceptions"),
00700                      d, d, Py_BuildValue(const_cast<char*>("[]")));
00701        if (exceptionsModule == NULL)
00702        {
00703               qDebug("Failed to import exceptions module. Something is probably broken with your Python.");
00704               return;
00705        }
00706        PyDict_SetItemString(d, const_cast<char*>("exceptions"), exceptionsModule);
00707        PyObject* warningsModule = PyImport_ImportModuleEx(const_cast<char*>("warnings"),
00708                      d, d, Py_BuildValue(const_cast<char*>("[]")));
00709        if (warningsModule == NULL)
00710        {
00711               qDebug("Failed to import warnings module. Something is probably broken with your Python.");
00712               return;
00713        }
00714        PyDict_SetItemString(d, const_cast<char*>("warnings"), warningsModule);
00715        // Create the module-level docstring. This can be a proper unicode string, unlike
00716        // the others, because we can just create a Unicode object and insert it in our
00717        // module dictionary.
00718        QString docstring = QObject::tr("Scribus Python interface module\n\
00719 \n\
00720 This module is the Python interface for Scribus. It provides functions\n\
00721 to control scribus and to manipulate objects on the canvas. Each\n\
00722 function is documented individually below.\n\
00723 \n\
00724 A few things are common across most of the interface.\n\
00725 \n\
00726 Most functions operate on frames. Frames are identified by their name,\n\
00727 a string - they are not real Python objects. Many functions take an\n\
00728 optional (non-keyword) parameter, a frame name.\n\
00729 Many exceptions are also common across most functions. These are\n\
00730 not currently documented in the docstring for each function.\n\
00731 - Many functions will raise a NoDocOpenError if you try to use them\n\
00732 without a document to operate on.\n\
00733 - If you do not pass a frame name to a function that requires one,\n\
00734 the function will use the currently selected frame, if any, or\n\
00735 raise a NoValidObjectError if it can't find anything to operate\n\
00736 on.\n\
00737 - Many functions will raise WrongFrameTypeError if you try to use them\n\
00738 on a frame type that they do not make sense with. For example, setting\n\
00739 the text color on a graphics frame doesn't make sense, and will result\n\
00740 in this exception being raised.\n\
00741 - Errors resulting from calls to the underlying Python API will be\n\
00742 passed through unaltered. As such, the list of exceptions thrown by\n\
00743 any function as provided here and in its docstring is incomplete.\n\
00744 \n\
00745 Details of what exceptions each function may throw are provided on the\n\
00746 function's documentation, though as with most Python code this list\n\
00747 is not exhaustive due to exceptions from called functions.\n\
00748 ");
00749 
00750        PyObject* docStr = PyString_FromString(docstring.utf8().data());
00751        if (!docStr)
00752               qDebug("Failed to create module-level docstring (couldn't make str)");
00753        else
00754        {
00755               PyObject* uniDocStr = PyUnicode_FromEncodedObject(docStr, "utf-8", NULL);
00756               Py_DECREF(docStr);
00757               docStr = NULL;
00758               if (!uniDocStr)
00759                      qDebug("Failed to create module-level docstring object (couldn't make unicode)");
00760               else
00761                      PyDict_SetItemString(d, const_cast<char*>("__doc__"), uniDocStr);
00762               Py_DECREF(uniDocStr);
00763               uniDocStr = NULL;
00764        }
00765 
00766        // Wrap up pointers to the the QApp and main window and push them out
00767        // to Python.
00768        wrappedQApp = wrapQObject(qApp);
00769        if (!wrappedQApp)
00770        {
00771               qDebug("Failed to wrap up QApp");
00772               PyErr_Print();
00773        }
00774        // Push it into the module dict, stealing a ref in the process
00775        PyDict_SetItemString(d, const_cast<char*>("qApp"), wrappedQApp);
00776        Py_DECREF(wrappedQApp);
00777        wrappedQApp = NULL;
00778 
00779        wrappedMainWindow = wrapQObject(pl);
00780        if (!wrappedMainWindow)
00781        {
00782               qDebug("Failed to wrap up ScMW");
00783               PyErr_Print();
00784        }
00785        // Push it into the module dict, stealing a ref in the process
00786        PyDict_SetItemString(d, const_cast<char*>("mainWindow"), wrappedMainWindow);
00787        Py_DECREF(wrappedMainWindow);
00788        wrappedMainWindow = NULL;
00789 }
00790 
00794 void scriptplugindocwarnings()
00795 {
00796     QStringList s;
00797     s <<printer__doc__<<pdffile__doc__<<imgexp__doc__<<imgexp_dpi__doc__<<imgexp_scale__doc__ <<imgexp_quality__doc__<<imgexp_filename__doc__<<imgexp_type__doc__<<imgexp_alltypes__doc__ << imgexp_save__doc__ << imgexp_saveas__doc__;
00798 }