Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Functions | Variables
scriptplugin.cpp File Reference
#include "cmdvar.h"
#include "cmddialog.h"
#include "cmddoc.h"
#include "cmdpage.h"
#include "cmdobj.h"
#include "cmdgetprop.h"
#include "cmdsetprop.h"
#include "cmdtext.h"
#include "cmdmani.h"
#include "cmdcolor.h"
#include "cmdmisc.h"
#include "cmdgetsetprop.h"
#include "scriptplugin.h"
#include "scriptplugin.moc"
#include "cmdutil.h"
#include "objprinter.h"
#include "objpdffile.h"
#include "objimageexport.h"
#include "guiapp.h"
#include "svgimport.h"
#include "scriptercore.h"
#include "scribuscore.h"
#include "customfdialog.h"
#include "helpbrowser.h"
#include "mpalette.h"
#include "menumanager.h"
#include "scpaths.h"
#include "units.h"
#include "scribusstructs.h"
#include "scconfig.h"
#include "scripterprefsgui.h"
#include <qapplication.h>
#include <qmessagebox.h>
#include <qtextcodec.h>
#include <qdom.h>
#include <qregexp.h>
#include <qtextstream.h>
#include <qpixmap.h>
#include <qwidget.h>
#include <qstring.h>
#include <cstdlib>
#include <iostream>

Go to the source code of this file.

Functions

QPixmap SCRIBUS_API loadIcon (QString nam)
int scriptplugin_getPluginAPIVersion ()
ScPlugin * scriptplugin_getPlugin ()
void scriptplugin_freePlugin (ScPlugin *plugin)
static PyObject * scribus_retval (PyObject *, PyObject *args)
static PyObject * scribus_getval (PyObject *)
char * tr (const char *docstringConstant)
 Translate a docstring.
void initscribus_failed (const char *fileName, int lineNo)
void initscribus (ScribusMainWindow *pl)
 Initialize the 'scribus' Python module in the currently active interpreter.
void scriptplugindocwarnings ()
 HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV.

Variables

PyObject * ScribusException
 Common scribus Exception.
PyObject * NoDocOpenError
 Exception raised when no document opened - see checkHaveDocument() in cmdutil.cpp.
PyObject * WrongFrameTypeError
 Exception raised when an operation is performed on a frame type that doesn't support it.
PyObject * NoValidObjectError
 Exception raised by GetUniqueItem when it can't find a valid frame or a suitable selection to use.
PyObject * NotFoundError
 A general exception for when objects such as colors and fonts cannot be found.
PyObject * NameExistsError
 Exception raised when the user tries to create an object with the same name as one that already exists.
PyObject * wrappedMainWindow
 A PyCObject containing a pointer to the main window ('Carrier')
PyObject * wrappedQApp
 A PyCObject containing a pointer to qApp.
ScripterCorescripterCore
 A pointer to the ScripterCore instance.
PyMethodDef scribus_methods []

Function Documentation

void initscribus ( ScribusMainWindow *  pl)

Initialize the 'scribus' Python module in the currently active interpreter.

Definition at line 486 of file scriptplugin.cpp.

{
       if (!scripterCore)
       {
              qWarning("scriptplugin: Tried to init scribus module, but no scripter core. Aborting.");
              return;
       }
       PyObject *m, *d;
       PyImport_AddModule((char*)"scribus");
       PyType_Ready(&Printer_Type);
       PyType_Ready(&PDFfile_Type);
       PyType_Ready(&ImageExport_Type);
       m = Py_InitModule((char*)"scribus", scribus_methods);
       Py_INCREF(&Printer_Type);
       PyModule_AddObject(m, (char*)"Printer", (PyObject *) &Printer_Type);
       Py_INCREF(&PDFfile_Type);
       PyModule_AddObject(m, (char*)"PDFfile", (PyObject *) &PDFfile_Type);
       Py_INCREF(&ImageExport_Type);
       PyModule_AddObject(m, (char*)"ImageExport", (PyObject *) &ImageExport_Type);
       d = PyModule_GetDict(m);

       // Set up the module exceptions
       // common exc.
       ScribusException = PyErr_NewException((char*)"scribus.ScribusException", NULL, NULL);
       Py_INCREF(ScribusException);
       PyModule_AddObject(m, (char*)"ScribusException", ScribusException);
       // no doc open
       NoDocOpenError = PyErr_NewException((char*)"scribus.NoDocOpenError", ScribusException, NULL);
       Py_INCREF(NoDocOpenError);
       PyModule_AddObject(m, (char*)"NoDocOpenError", NoDocOpenError);
       // wrong type of frame for operation
       WrongFrameTypeError = PyErr_NewException((char*)"scribus.WrongFrameTypeError", ScribusException, NULL);
       Py_INCREF(WrongFrameTypeError);
       PyModule_AddObject(m, (char*)"WrongFrameTypeError", WrongFrameTypeError);
       // Couldn't find named object, or no named object and no selection
       NoValidObjectError = PyErr_NewException((char*)"scribus.NoValidObjectError", ScribusException, NULL);
       Py_INCREF(NoValidObjectError);
       PyModule_AddObject(m, (char*)"NoValidObjectError", NoValidObjectError);
       // Couldn't find the specified resource - font, color, etc.
       NotFoundError = PyErr_NewException((char*)"scribus.NotFoundError", ScribusException, NULL);
       Py_INCREF(NotFoundError);
       PyModule_AddObject(m, (char*)"NotFoundError", NotFoundError);
       // Tried to create an object with the same name as one that already exists
       NameExistsError = PyErr_NewException((char*)"scribus.NameExistsError", ScribusException, NULL);
       Py_INCREF(NameExistsError);
       PyModule_AddObject(m, (char*)"NameExistsError", NameExistsError);
       // Done with exception setup

       // CONSTANTS
       PyDict_SetItemString(d, const_cast<char*>("UNIT_POINTS"), PyInt_FromLong(unitIndexFromString("pt")));
       PyDict_SetItemString(d, const_cast<char*>("UNIT_MILLIMETERS"), PyInt_FromLong(unitIndexFromString("mm")));
       PyDict_SetItemString(d, const_cast<char*>("UNIT_INCHES"), PyInt_FromLong(unitIndexFromString("in")));
       PyDict_SetItemString(d, const_cast<char*>("UNIT_PICAS"), PyInt_FromLong(unitIndexFromString("p")));
       PyDict_SetItemString(d, const_cast<char*>("UNIT_CENTIMETRES"), PyInt_FromLong(unitIndexFromString("cm")));
       PyDict_SetItemString(d, const_cast<char*>("UNIT_CICERO"), PyInt_FromLong(unitIndexFromString("c")));
       PyDict_SetItemString(d, const_cast<char*>("PORTRAIT"), Py_BuildValue(const_cast<char*>("i"), portraitPage));
       PyDict_SetItemString(d, const_cast<char*>("LANDSCAPE"), Py_BuildValue(const_cast<char*>("i"), landscapePage));
       PyDict_SetItemString(d, const_cast<char*>("NOFACINGPAGES"), Py_BuildValue(const_cast<char*>("i"), 0));
       PyDict_SetItemString(d, const_cast<char*>("FACINGPAGES"),  Py_BuildValue(const_cast<char*>("i"), 1));
       PyDict_SetItemString(d, const_cast<char*>("FIRSTPAGERIGHT"), Py_BuildValue(const_cast<char*>("i"), 1));
       PyDict_SetItemString(d, const_cast<char*>("FIRSTPAGELEFT"), Py_BuildValue(const_cast<char*>("i"), 0));
       PyDict_SetItemString(d, const_cast<char*>("ALIGN_LEFT"), Py_BuildValue(const_cast<char*>("i"), 0));
       PyDict_SetItemString(d, const_cast<char*>("ALIGN_RIGHT"), Py_BuildValue(const_cast<char*>("i"), 2));
       PyDict_SetItemString(d, const_cast<char*>("ALIGN_CENTERED"), Py_BuildValue(const_cast<char*>("i"), 1));
       PyDict_SetItemString(d, const_cast<char*>("ALIGN_BLOCK"), Py_BuildValue(const_cast<char*>("i"), 4));
       PyDict_SetItemString(d, const_cast<char*>("ALIGN_FORCED"), Py_BuildValue(const_cast<char*>("i"), 4));
       PyDict_SetItemString(d, const_cast<char*>("FILL_NOG"), Py_BuildValue(const_cast<char*>("i"), 0));
       PyDict_SetItemString(d, const_cast<char*>("FILL_HORIZONTALG"), Py_BuildValue(const_cast<char*>("i"), 1));
       PyDict_SetItemString(d, const_cast<char*>("FILL_VERTICALG"), Py_BuildValue(const_cast<char*>("i"), 2));
       PyDict_SetItemString(d, const_cast<char*>("FILL_DIAGONALG"), Py_BuildValue(const_cast<char*>("i"), 3));
       PyDict_SetItemString(d, const_cast<char*>("FILL_CROSSDIAGONALG"), Py_BuildValue(const_cast<char*>("i"), 4));
       PyDict_SetItemString(d, const_cast<char*>("FILL_RADIALG"), Py_BuildValue(const_cast<char*>("i"), 5));
       PyDict_SetItemString(d, const_cast<char*>("LINE_SOLID"), Py_BuildValue(const_cast<char*>("i"), Qt::SolidLine));
       PyDict_SetItemString(d, const_cast<char*>("LINE_DASH"), Py_BuildValue(const_cast<char*>("i"), Qt::DashLine));
       PyDict_SetItemString(d, const_cast<char*>("LINE_DOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DotLine));
       PyDict_SetItemString(d, const_cast<char*>("LINE_DASHDOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DashDotLine));
       PyDict_SetItemString(d, const_cast<char*>("LINE_DASHDOTDOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DashDotDotLine));
       PyDict_SetItemString(d, const_cast<char*>("JOIN_MITTER"), Py_BuildValue(const_cast<char*>("i"), Qt::MiterJoin));
       PyDict_SetItemString(d, const_cast<char*>("JOIN_BEVEL"), Py_BuildValue(const_cast<char*>("i"), Qt::BevelJoin));
       PyDict_SetItemString(d, const_cast<char*>("JOIN_ROUND"), Py_BuildValue(const_cast<char*>("i"), Qt::RoundJoin));
       PyDict_SetItemString(d, const_cast<char*>("CAP_FLAT"), Py_BuildValue(const_cast<char*>("i"), Qt::FlatCap));
       PyDict_SetItemString(d, const_cast<char*>("CAP_SQUARE"), Py_BuildValue(const_cast<char*>("i"), Qt::SquareCap));
       PyDict_SetItemString(d, const_cast<char*>("CAP_ROUND"), Py_BuildValue(const_cast<char*>("i"), Qt::RoundCap));
       PyDict_SetItemString(d, const_cast<char*>("BUTTON_NONE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::NoButton));
       PyDict_SetItemString(d, const_cast<char*>("BUTTON_OK"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Ok));
       PyDict_SetItemString(d, const_cast<char*>("BUTTON_CANCEL"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Cancel));
       PyDict_SetItemString(d, const_cast<char*>("BUTTON_YES"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Yes));
       PyDict_SetItemString(d, const_cast<char*>("BUTTON_NO"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::No));
       PyDict_SetItemString(d, const_cast<char*>("BUTTON_ABORT"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Abort));
       PyDict_SetItemString(d, const_cast<char*>("BUTTON_RETRY"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Retry));
       PyDict_SetItemString(d, const_cast<char*>("BUTTON_IGNORE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Ignore));
       PyDict_SetItemString(d, const_cast<char*>("ICON_NONE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::NoIcon));
       PyDict_SetItemString(d, const_cast<char*>("ICON_INFORMATION"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Information));
       PyDict_SetItemString(d, const_cast<char*>("ICON_WARNING"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Warning));
       PyDict_SetItemString(d, const_cast<char*>("ICON_CRITICAL"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Critical));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A0"), Py_BuildValue(const_cast<char*>("(ff)"), 2380.0, 3368.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A1"), Py_BuildValue(const_cast<char*>("(ff)"), 1684.0, 2380.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A2"), Py_BuildValue(const_cast<char*>("(ff)"), 1190.0, 1684.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A3"), Py_BuildValue(const_cast<char*>("(ff)"), 842.0, 1190.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A4"), Py_BuildValue(const_cast<char*>("(ff)"), 595.0, 842.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A5"), Py_BuildValue(const_cast<char*>("(ff)"), 421.0, 595.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A6"), Py_BuildValue(const_cast<char*>("(ff)"), 297.0, 421.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A7"), Py_BuildValue(const_cast<char*>("(ff)"), 210.0, 297.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A8"), Py_BuildValue(const_cast<char*>("(ff)"), 148.0, 210.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_A9"), Py_BuildValue(const_cast<char*>("(ff)"), 105.0, 148.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B0"), Py_BuildValue(const_cast<char*>("(ff)"), 2836.0, 4008.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B1"), Py_BuildValue(const_cast<char*>("(ff)"), 2004.0, 2836.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B2"), Py_BuildValue(const_cast<char*>("(ff)"), 1418.0, 2004.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B3"), Py_BuildValue(const_cast<char*>("(ff)"), 1002.0, 1418.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B4"), Py_BuildValue(const_cast<char*>("(ff)"), 709.0, 1002.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B5"), Py_BuildValue(const_cast<char*>("(ff)"), 501.0, 709.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B6"), Py_BuildValue(const_cast<char*>("(ff)"), 355.0, 501.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B7"), Py_BuildValue(const_cast<char*>("(ff)"), 250.0, 355.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B8"), Py_BuildValue(const_cast<char*>("(ff)"), 178.0, 250.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B9"), Py_BuildValue(const_cast<char*>("(ff)"), 125.0, 178.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_B10"), Py_BuildValue(const_cast<char*>("(ff)"), 89.0, 125.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_C5E"), Py_BuildValue(const_cast<char*>("(ff)"), 462.0, 649.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_COMM10E"), Py_BuildValue(const_cast<char*>("(ff)"), 298.0, 683.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_DLE"),  Py_BuildValue(const_cast<char*>("(ff)"), 312.0, 624.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_EXECUTIVE"), Py_BuildValue(const_cast<char*>("(ff)"), 542.0, 720.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_FOLIO"), Py_BuildValue(const_cast<char*>("(ff)"), 595.0, 935.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_LEDGER"), Py_BuildValue(const_cast<char*>("(ff)"), 1224.0, 792.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_LEGAL"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 1008.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_LETTER"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 792.0));
       PyDict_SetItemString(d, const_cast<char*>("PAPER_TABLOID"), Py_BuildValue(const_cast<char*>("(ff)"), 792.0, 1224.0));
       PyDict_SetItemString(d, const_cast<char*>("NORMAL"), Py_BuildValue(const_cast<char*>("i"), 0));
       PyDict_SetItemString(d, const_cast<char*>("DARKEN"), Py_BuildValue(const_cast<char*>("i"), 1));
       PyDict_SetItemString(d, const_cast<char*>("LIGHTEN"), Py_BuildValue(const_cast<char*>("i"), 2));
       PyDict_SetItemString(d, const_cast<char*>("MULTIPLY"), Py_BuildValue(const_cast<char*>("i"), 3));
       PyDict_SetItemString(d, const_cast<char*>("SCREEN"), Py_BuildValue(const_cast<char*>("i"), 4));
       PyDict_SetItemString(d, const_cast<char*>("OVERLAY"), Py_BuildValue(const_cast<char*>("i"), 5));
       PyDict_SetItemString(d, const_cast<char*>("HARD_LIGHT"), Py_BuildValue(const_cast<char*>("i"), 6));
       PyDict_SetItemString(d, const_cast<char*>("SOFT_LIGHT"), Py_BuildValue(const_cast<char*>("i"), 7));
       PyDict_SetItemString(d, const_cast<char*>("DIFFERENCE"), Py_BuildValue(const_cast<char*>("i"), 8));
       PyDict_SetItemString(d, const_cast<char*>("EXCLUSION"), Py_BuildValue(const_cast<char*>("i"), 9));
       PyDict_SetItemString(d, const_cast<char*>("COLOR_DODGE"), Py_BuildValue(const_cast<char*>("i"), 10));
       PyDict_SetItemString(d, const_cast<char*>("COLOR_BURN"), Py_BuildValue(const_cast<char*>("i"), 11));
       PyDict_SetItemString(d, const_cast<char*>("HUE"), Py_BuildValue(const_cast<char*>("i"), 12));
       PyDict_SetItemString(d, const_cast<char*>("SATURATION"), Py_BuildValue(const_cast<char*>("i"), 13));
       PyDict_SetItemString(d, const_cast<char*>("COLOR"), Py_BuildValue(const_cast<char*>("i"), 14));
       PyDict_SetItemString(d, const_cast<char*>("LUMINOSITY"), Py_BuildValue(const_cast<char*>("i"), 15));
       // preset page layouts
       PyDict_SetItemString(d, const_cast<char*>("PAGE_1"), Py_BuildValue(const_cast<char*>("i"), 0));
       PyDict_SetItemString(d, const_cast<char*>("PAGE_2"), Py_BuildValue(const_cast<char*>("i"), 1));
       PyDict_SetItemString(d, const_cast<char*>("PAGE_3"), Py_BuildValue(const_cast<char*>("i"), 2));
       PyDict_SetItemString(d, const_cast<char*>("PAGE_4"), Py_BuildValue(const_cast<char*>("i"), 3));

       // Measurement units understood by Scribus's units.cpp functions are exported as constant conversion
       // factors to be used from Python.
       for (int i = 0; i <= unitGetMaxIndex(); ++i)
       {
              PyObject* value = PyFloat_FromDouble(unitGetRatioFromIndex(i));
              if (!value)
              {
                     initscribus_failed(__FILE__, __LINE__);
                     return;
              }
              // `in' is a reserved word in Python so we must replace it
              PyObject* name;
              if (unitGetStrFromIndex(i) == "in")
                     name = PyString_FromString("inch");
              else
                     name = PyString_FromString(unitGetStrFromIndex(i).ascii());
              if (!name)
              {
                     initscribus_failed(__FILE__, __LINE__);
                     return;
              }
              if (PyDict_SetItem(d, name, value))
              {
                     initscribus_failed(__FILE__, __LINE__);
                     return;
              }
       }

       // Export the Scribus version into the module namespace so scripts know what they're running in
       PyDict_SetItemString(d, const_cast<char*>("scribus_version"), PyString_FromString(const_cast<char*>(VERSION)));
       // Now build a version tuple like that provided by Python in sys.version_info
       // The tuple is of the form (major, minor, patchlevel, extraversion, reserved)
       QRegExp version_re("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
       int pos = version_re.search(QString(VERSION));
       // We ignore errors, causing the scribus_version_info attribute to simply not be created.
       // This will make acceses raise AttrbuteError.
       if (pos > -1)
       {
              int majorVersion = version_re.cap(1).toInt();
              int minorVersion = version_re.cap(2).toInt();
              int patchVersion = version_re.cap(3).toInt();
              QString extraVersion = version_re.cap(4);
              PyObject* versionTuple = Py_BuildValue(const_cast<char*>("(iiisi)"),\
                            majorVersion, minorVersion, patchVersion, (const char*)extraVersion.utf8(), 0);
              if (versionTuple != NULL)
                     PyDict_SetItemString(d, const_cast<char*>("scribus_version_info"), versionTuple);
              else
                     qDebug("Failed to build version tuple for version string '%s' in scripter", VERSION);
       }
       else
              qDebug("Couldn't parse version string '%s' in scripter", VERSION);

//     ScMW = pl;
       // Function aliases for compatibility
       // We need to import the __builtins__, warnings and exceptions modules to be able to run
       // the generated Python functions from inside the `scribus' module's context.
       // This code makes it possible to extend the `scribus' module by running Python code
       // from C in other ways too.
       PyObject* builtinModule = PyImport_ImportModuleEx(const_cast<char*>("__builtin__"),
                     d, d, Py_BuildValue(const_cast<char*>("[]")));
       if (builtinModule == NULL)
       {
              qDebug("Failed to import __builtin__ module. Something is probably broken with your Python.");
              return;
       }
       PyDict_SetItemString(d, const_cast<char*>("__builtin__"), builtinModule);
       PyObject* exceptionsModule = PyImport_ImportModuleEx(const_cast<char*>("exceptions"),
                     d, d, Py_BuildValue(const_cast<char*>("[]")));
       if (exceptionsModule == NULL)
       {
              qDebug("Failed to import exceptions module. Something is probably broken with your Python.");
              return;
       }
       PyDict_SetItemString(d, const_cast<char*>("exceptions"), exceptionsModule);
       PyObject* warningsModule = PyImport_ImportModuleEx(const_cast<char*>("warnings"),
                     d, d, Py_BuildValue(const_cast<char*>("[]")));
       if (warningsModule == NULL)
       {
              qDebug("Failed to import warnings module. Something is probably broken with your Python.");
              return;
       }
       PyDict_SetItemString(d, const_cast<char*>("warnings"), warningsModule);
       // Create the module-level docstring. This can be a proper unicode string, unlike
       // the others, because we can just create a Unicode object and insert it in our
       // module dictionary.
       QString docstring = QObject::tr("Scribus Python interface module\n\
\n\
This module is the Python interface for Scribus. It provides functions\n\
to control scribus and to manipulate objects on the canvas. Each\n\
function is documented individually below.\n\
\n\
A few things are common across most of the interface.\n\
\n\
Most functions operate on frames. Frames are identified by their name,\n\
a string - they are not real Python objects. Many functions take an\n\
optional (non-keyword) parameter, a frame name.\n\
Many exceptions are also common across most functions. These are\n\
not currently documented in the docstring for each function.\n\
- Many functions will raise a NoDocOpenError if you try to use them\n\
without a document to operate on.\n\
- If you do not pass a frame name to a function that requires one,\n\
the function will use the currently selected frame, if any, or\n\
raise a NoValidObjectError if it can't find anything to operate\n\
on.\n\
- Many functions will raise WrongFrameTypeError if you try to use them\n\
on a frame type that they do not make sense with. For example, setting\n\
the text color on a graphics frame doesn't make sense, and will result\n\
in this exception being raised.\n\
- Errors resulting from calls to the underlying Python API will be\n\
passed through unaltered. As such, the list of exceptions thrown by\n\
any function as provided here and in its docstring is incomplete.\n\
\n\
Details of what exceptions each function may throw are provided on the\n\
function's documentation, though as with most Python code this list\n\
is not exhaustive due to exceptions from called functions.\n\
");

       PyObject* docStr = PyString_FromString(docstring.utf8().data());
       if (!docStr)
              qDebug("Failed to create module-level docstring (couldn't make str)");
       else
       {
              PyObject* uniDocStr = PyUnicode_FromEncodedObject(docStr, "utf-8", NULL);
              Py_DECREF(docStr);
              docStr = NULL;
              if (!uniDocStr)
                     qDebug("Failed to create module-level docstring object (couldn't make unicode)");
              else
                     PyDict_SetItemString(d, const_cast<char*>("__doc__"), uniDocStr);
              Py_DECREF(uniDocStr);
              uniDocStr = NULL;
       }

       // Wrap up pointers to the the QApp and main window and push them out
       // to Python.
       wrappedQApp = wrapQObject(qApp);
       if (!wrappedQApp)
       {
              qDebug("Failed to wrap up QApp");
              PyErr_Print();
       }
       // Push it into the module dict, stealing a ref in the process
       PyDict_SetItemString(d, const_cast<char*>("qApp"), wrappedQApp);
       Py_DECREF(wrappedQApp);
       wrappedQApp = NULL;

       wrappedMainWindow = wrapQObject(pl);
       if (!wrappedMainWindow)
       {
              qDebug("Failed to wrap up ScMW");
              PyErr_Print();
       }
       // Push it into the module dict, stealing a ref in the process
       PyDict_SetItemString(d, const_cast<char*>("mainWindow"), wrappedMainWindow);
       Py_DECREF(wrappedMainWindow);
       wrappedMainWindow = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void initscribus_failed ( const char *  fileName,
int  lineNo 
)

Definition at line 478 of file scriptplugin.cpp.

{
       qDebug("Scripter setup failed (%s:%i)", fileName, lineNo);
       if (PyErr_Occurred())
              PyErr_Print();
       return;
}

Here is the caller graph for this function:

QPixmap SCRIBUS_API loadIcon ( QString  nam)

Definition at line 224 of file util.cpp.

{
       static ScPixmapCache<QString> pxCache;
       if (pxCache.contains(nam))
              return *pxCache[nam];

       QString iconFilePath(QString("%1%2").arg(ScPaths::instance().iconDir()).arg(nam));
       QPixmap *pm = new QPixmap();
       
       if (!QFile::exists(iconFilePath))
              qWarning("Unable to load icon %s: File not found", iconFilePath.ascii());
       else
       {
              pm->load(iconFilePath);
              if (pm->isNull())
                     qWarning("Unable to load icon %s: Got null pixmap", iconFilePath.ascii());
       }
       pxCache.insert(nam, pm);
       return *pm;
}
static PyObject* scribus_getval ( PyObject *  ) [static]

Definition at line 236 of file scriptplugin.cpp.

{
       return PyString_FromString(scripterCore->inValue.utf8().data());
}
static PyObject* scribus_retval ( PyObject *  ,
PyObject *  args 
) [static]

Definition at line 222 of file scriptplugin.cpp.

{
       char *Name = NULL;
       if (!PyArg_ParseTuple(args, (char*)"s", &Name))
              return NULL;
       // Because sysdefaultencoding is not utf-8, Python is returning utf-8 encoded
       // 8-bit char* strings. Make sure Qt understands that the input is utf-8 not
       // the default local encoding (usually latin-1) by using QString::fromUtf8()
       /*RetString = QString::fromUtf8(Name);
       RetVal = retV;*/
       scripterCore->returnString = QString::fromUtf8(Name);
       return PyInt_FromLong(0L);
}
void scriptplugin_freePlugin ( ScPlugin *  plugin)

Definition at line 106 of file scriptplugin.cpp.

{
       ScriptPlugin* plug = dynamic_cast<ScriptPlugin*>(plugin);
       Q_ASSERT(plug);
       delete plug;
}
ScPlugin* scriptplugin_getPlugin ( )

Definition at line 98 of file scriptplugin.cpp.

{
       scripterCore=0;
       ScriptPlugin* plug = new ScriptPlugin();
       Q_CHECK_PTR(plug);
       return plug;
}

Definition at line 93 of file scriptplugin.cpp.

{
       return PLUGIN_API_VERSION;
}

HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV.

Definition at line 794 of file scriptplugin.cpp.

{
    QStringList s;
    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__;
}
char* tr ( const char *  docstringConstant)

Translate a docstring.

Small helper function for use with the PyMethodDef struct.

Definition at line 244 of file scriptplugin.cpp.

{
       // Alas, there's a lot of wasteful string copying going on
       // here.
       QString translated = QObject::tr(docstringConstant, "scripter docstring");
       // pv - hack for ugly formating in console removing
       translated.replace("\n\n", "<P>");
       translated.replace('\n', " ");
       translated.replace("<P>", "\n\n");
       /*
        * Python doesn't support 'unicode' object docstrings in the PyMethodDef,
        * and has no way to specify what encoding docstrings are in. The passed C
        * strings passed are made into 'str' objects as-is. These are interpreted
        * as being in the Python sysdefaultencoding, usually 'ascii', when used.
        * We now set systemdefaultencoding to 'utf-8' ...  so we're going to pass
        * Python an 8-bit utf-8 encoded string in a char* .  With
        * sysdefaultencoding set correctly, Python will interpret it correctly and
        * we'll have our unicode docstrings. It's not as ugly a hack as it sounds,
        * you just have to remember that C and Python strings can both be
        * considered 8-bit strings of binary data that can be later interpreted as
        * a text string in a particular text encoding.
        */
       //QCString utfTranslated = translated.utf8();
       QCString trch = translated.utf8();
       char* utfstr = strdup(trch.data());
       if (!utfstr)
              // Complain, but then return NULL anyway. Python will treat NULL as
              // "no value" so that's fine.
              qDebug("scriptplugin.cpp:tr() - strdup() failure");
       return utfstr;
}

Variable Documentation

PyObject* NameExistsError

Exception raised when the user tries to create an object with the same name as one that already exists.

Definition at line 85 of file scriptplugin.cpp.

PyObject* NoDocOpenError

Exception raised when no document opened - see checkHaveDocument() in cmdutil.cpp.

Definition at line 81 of file scriptplugin.cpp.

PyObject* NotFoundError

A general exception for when objects such as colors and fonts cannot be found.

Definition at line 84 of file scriptplugin.cpp.

PyObject* NoValidObjectError

Exception raised by GetUniqueItem when it can't find a valid frame or a suitable selection to use.

Definition at line 83 of file scriptplugin.cpp.

PyMethodDef scribus_methods[]

Definition at line 280 of file scriptplugin.cpp.

PyObject* ScribusException

Common scribus Exception.

Definition at line 80 of file scriptplugin.cpp.

A pointer to the ScripterCore instance.

Definition at line 90 of file scriptplugin.cpp.

PyObject* wrappedMainWindow

A PyCObject containing a pointer to the main window ('Carrier')

Definition at line 88 of file scriptplugin.cpp.

PyObject* wrappedQApp

A PyCObject containing a pointer to qApp.

Definition at line 89 of file scriptplugin.cpp.

Exception raised when an operation is performed on a frame type that doesn't support it.

Definition at line 82 of file scriptplugin.cpp.