Subversion Repositories Scribus

Rev

Rev 1384 | 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
 ***************************************************************************/
791 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"
82 Franz 31
#include "scriptplugin.h"
32
#include "scriptplugin.moc"
103 Franz 33
#include "cmdutil.h"
411 Franz 34
#include "objprinter.h"
418 Franz 35
#include "objpdffile.h"
1384 cbradney 36
#include "macro.h"
37
#include "macromanager.h"
38
#include "extmacro.h"
39
#include "scripterprefs.h"
203 Franz 40
#include "guiapp.h"
82 Franz 41
#include "customfdialog.h"
42
#include "helpbrowser.h"
265 Franz 43
#include "mpalette.h"
128 Franz 44
 
612 cbradney 45
#ifdef _MSC_VER
46
 #if (_MSC_VER >= 1200)
47
  #include "win-config.h"
48
 #endif
128 Franz 49
#else
50
 #include "config.h"
51
#endif
52
 
82 Franz 53
#include <qmessagebox.h>
54
#include <qtextcodec.h>
55
#include <qdom.h>
56
#include <qtextstream.h>
57
#include <cstdlib>
58
 
474 subik 59
// Exceptions; visible from cmdvar.h, set up in initscribus()
60
PyObject* ScribusException;
61
PyObject* NoDocOpenError;
852 subik 62
PyObject* WrongFrameTypeError;
63
PyObject* NoValidObjectError;
857 cbradney 64
PyObject* NotFoundError;
65
PyObject* NameExistsError;
1384 cbradney 66
PyObject* AccessDeniedError;
474 subik 67
 
82 Franz 68
QString Name()
69
{
308 Franz 70
        return QObject::tr("S&cripter Manual...");
82 Franz 71
}
72
 
73
int Type()
74
{
75
        return 4;
76
}
77
 
585 fschmid 78
int ID()
79
{
80
        return 8;
81
}
82
 
82 Franz 83
void InitPlug(QWidget *d, ScribusApp *plug)
84
{
1384 cbradney 85
        // push the QApplication instance we've been passed into the Carrier global
86
        Carrier = plug;
87
        // init Python
82 Franz 88
        QString cm;
89
        Py_Initialize();
857 cbradney 90
        if (PyUnicode_SetDefaultEncoding("utf-8"))
91
        {
92
                qDebug("Failed to set default encoding to utf-8.\n");
93
                PyErr_Clear();
94
        }
82 Franz 95
        RetVal = 0;
1384 cbradney 96
        // Init the class that manages the scripter and its gui
82 Franz 97
        Tes = new MenuTest(d);
98
        men = new QPopupMenu();
99
        Tes->rmen = new QPopupMenu();
222 Franz 100
        Tes->smen = new QPopupMenu();
82 Franz 101
        Tes->SavedRecentScripts.clear();
1384 cbradney 102
        // init prefs variables
103
        Tes->enableExtPython = false;
104
        Tes->importAllNames = true;
105
        Tes->legacyAliases = true;
106
        Tes->startupScriptEnable = false;
107
        Tes->useDummyStdin = true;
108
        Tes->startupScript = QString();
109
        // now load the prefs
82 Franz 110
        Tes->ReadPlugPrefs();
870 cbradney 111
        QString pfad = SCRIPTSDIR;
282 Franz 112
        QString pfad2;
870 cbradney 113
        pfad2 = QDir::convertSeparators(pfad);
222 Franz 114
        QDir ds(pfad2, "*.py", QDir::Name, QDir::Files | QDir::NoSymLinks);
115
        if ((ds.exists()) && (ds.count() != 0))
116
        {
117
                for (uint dc = 0; dc < ds.count(); ++dc)
118
                {
119
                        QFileInfo fs(ds[dc]);
120
                        Tes->smen->insertItem(fs.baseName(true));
121
                }
122
        }
82 Franz 123
        Tes->RecentScripts.clear();
124
        if (Tes->SavedRecentScripts.count() != 0)
282 Franz 125
        {
82 Franz 126
                uint max = QMIN(Carrier->Prefs.RecentDCount, Tes->SavedRecentScripts.count());
87 Franz 127
                for (uint m = 0; m < max; ++m)
282 Franz 128
                {
82 Franz 129
                        QFileInfo fd(Tes->SavedRecentScripts[m]);
130
                        if (fd.exists())
282 Franz 131
                        {
82 Franz 132
                                Tes->RecentScripts.append(Tes->SavedRecentScripts[m]);
133
                                Tes->rmen->insertItem(Tes->SavedRecentScripts[m]);
134
                        }
135
                }
282 Franz 136
        }
1384 cbradney 137
        int id = -1;
82 Franz 138
        Tes->pcon = new PConsole(d);
308 Franz 139
        Tes->smenid = men->insertItem(QObject::tr("&Scribus Scripts"), Tes->smen);
1384 cbradney 140
        id = men->insertItem(QObject::tr("&Execute Script..."), Tes, SLOT(slotTest()));
141
        men->setWhatsThis(id, QObject::tr("Run a Python script from a file.","scripter"));
142
        id = men->insertItem(QObject::tr("&Load Extension Script..."), Tes, SLOT(loadScript()));
143
        men->setWhatsThis(id, QObject::tr("Load a Python script as an extension. "
144
                          "Used for loading macros and for advanced Python scripts that "
145
                          "extend the Scribus user interface.","scripter"));
308 Franz 146
        Tes->rmenid = men->insertItem(QObject::tr("&Recent Scripts"), Tes->rmen);
222 Franz 147
        men->insertSeparator();
1384 cbradney 148
        id = Tes->cons = men->insertItem(QObject::tr("Show &Console"), Tes, SLOT(slotInteractiveScript()));
149
        men->setWhatsThis(id, QObject::tr("Display an interactive Python console where you can write and "
150
                                          "run Python programs that use the Scripter tools.","scripter"));
538 subik 151
        Tes->about = men->insertItem(QObject::tr("&About Script..."), Tes, SLOT(aboutScript()));
238 Franz 152
        plug->menuBar()->insertItem(QObject::tr("S&cript"), men, -1, plug->menuBar()->count() - 2);
82 Franz 153
        QObject::connect(Tes->pcon->OutWin, SIGNAL(returnPressed()), Tes, SLOT(slotExecute()));
154
        QObject::connect(Tes->pcon, SIGNAL(Schliessen()), Tes, SLOT(slotInteractiveScript()));
155
        QObject::connect(Tes->rmen, SIGNAL(activated(int)), Tes, SLOT(RecentScript(int)));
222 Franz 156
        QObject::connect(Tes->smen, SIGNAL(activated(int)), Tes, SLOT(StdScript(int)));
1384 cbradney 157
        men->insertSeparator();
158
        id = men->insertItem(QObject::tr("Scripter &Settings","script menu"), Tes, SLOT(preferencesDialog()));
159
        // Now init the scribus module in the main interpreter
160
        initscribus(Carrier);
161
        // If Python extensions are enabled, load the macro manager.
162
        if (Tes->enableExtPython)
163
                MacroManager::instance();
164
        // and run the start-up script, if any
165
        if (Tes->enableExtPython && Tes->startupScriptEnable)
166
        {
167
                if (QFile::exists(Tes->startupScript))
168
                {
169
                        // run the script in the main interpreter. The user will be informed
170
                        // with a dialog if something has gone wrong.
171
                        Tes->slotRunScriptFile(Tes->startupScript, true);
172
                }
173
                else
174
                        qDebug("Startup script enabled, but couln't find script %s.", (const char*)(Tes->startupScript.utf8()) );
175
        }
82 Franz 176
}
177
 
178
void CleanUpPlug()
179
{
1384 cbradney 180
        MacroManager::deleteInstance();
82 Franz 181
        Py_Finalize();
182
        Tes->SavePlugPrefs();
1384 cbradney 183
        delete(Tes);
82 Franz 184
}
185
 
186
void Run(QWidget *d, ScribusApp *plug)
187
{
870 cbradney 188
        QString pfad = DOCDIR;
282 Franz 189
        QString pfad2;
870 cbradney 190
        pfad2 = QDir::convertSeparators(pfad + "en/Scripter/index.html");
666 fschmid 191
        HelpBrowser *dia = new HelpBrowser(d, QObject::tr("Online Reference"), plug->GuiLanguage, "scripter");
82 Franz 192
        dia->show();
193
}
194
 
222 Franz 195
 
196
void MenuTest::FinishScriptRun()
197
{
198
        if (Carrier->HaveDoc)
282 Franz 199
        {
222 Franz 200
                Carrier->Mpal->SetDoc(Carrier->doc);
201
                Carrier->Mpal->updateCList();
202
                Carrier->Mpal->Spal->SetFormats(Carrier->doc);
203
                Carrier->Mpal->SetLineFormats(Carrier->doc);
204
                Carrier->Mpal->Cpal->SetColors(Carrier->doc->PageColors);
205
                Carrier->Lpal->setLayers(&Carrier->doc->Layers, &Carrier->doc->ActiveLayer);
206
                Carrier->Tpal->BuildTree(Carrier->view);
207
                Carrier->Sepal->SetView(Carrier->view);
208
                Carrier->Sepal->Rebuild();
209
                if (Carrier->doc->ActPage->SelItem.count() != 0)
210
                        Carrier->HaveNewSel(Carrier->doc->ActPage->SelItem.at(0)->PType);
211
                else
212
                        Carrier->HaveNewSel(-1);
213
                Carrier->view->DrawNew();
282 Franz 214
        }
222 Franz 215
}
216
 
82 Franz 217
void MenuTest::slotTest()
218
{
219
        QString fileName;
91 Franz 220
        QString CurDirP = QDir::currentDirPath();
415 Franz 221
        QString scriptDir = Carrier->Prefs.ScriptDir;
222
        if (scriptDir == "")
223
                scriptDir = CurDirP;
224
        CustomFDialog diaf((QWidget*)parent(), scriptDir, QObject::tr("Open"), QObject::tr("Python Scripts (*.py);; All Files (*)"));
82 Franz 225
        if (diaf.exec())
282 Franz 226
        {
82 Franz 227
                fileName = diaf.selectedFile();
228
                slotRunScriptFile(fileName);
229
                rmen->clear();
230
                if (RecentScripts.findIndex(fileName) == -1)
231
                        RecentScripts.prepend(fileName);
232
                else
282 Franz 233
                {
82 Franz 234
                        RecentScripts.remove(fileName);
235
                        RecentScripts.prepend(fileName);
282 Franz 236
                }
82 Franz 237
                uint max = QMIN(Carrier->Prefs.RecentDCount, RecentScripts.count());
238
                for (uint m = 0; m < max; m++)
282 Franz 239
                {
82 Franz 240
                        rmen->insertItem(RecentScripts[m]);
241
                }
282 Franz 242
        }
91 Franz 243
        QDir::setCurrent(CurDirP);
222 Franz 244
        FinishScriptRun();
82 Franz 245
}
246
 
222 Franz 247
void MenuTest::StdScript(int id)
248
{
870 cbradney 249
        QString pfad = SCRIPTSDIR;
282 Franz 250
        QString pfad2;
870 cbradney 251
        pfad2 = QDir::convertSeparators(pfad);
222 Franz 252
        QString fn = pfad2+smen->text(id)+".py";
253
        QFileInfo fd(fn);
254
        if (!fd.exists())
255
                return;
256
        slotRunScriptFile(fn);
257
        FinishScriptRun();
258
}
259
 
82 Franz 260
void MenuTest::RecentScript(int id)
261
{
262
        QString fn = rmen->text(id);
263
        QFileInfo fd(fn);
264
        if (!fd.exists())
282 Franz 265
        {
82 Franz 266
                RecentScripts.remove(fn);
267
                rmen->clear();
268
                uint max = QMIN(Carrier->Prefs.RecentDCount, RecentScripts.count());
269
                for (uint m = 0; m < max; m++)
282 Franz 270
                {
82 Franz 271
                        rmen->insertItem(RecentScripts[m]);
282 Franz 272
                }
82 Franz 273
                return;
282 Franz 274
        }
82 Franz 275
        slotRunScriptFile(fn);
222 Franz 276
        FinishScriptRun();
82 Franz 277
}
278
 
1384 cbradney 279
void MenuTest::slotRunScriptFile(QString fileName, bool inMainInterpreter)
82 Franz 280
{
281
        char* comm[1];
1384 cbradney 282
        PyThreadState *stateo, *state;
82 Franz 283
        QFileInfo fi(fileName);
284
        QCString na = fi.fileName().latin1();
1384 cbradney 285
        // Set up a sub-interpreter if needed:
286
        if (!inMainInterpreter)
287
        {
288
                Carrier->ScriptRunning = true;
289
                qApp->setOverrideCursor(QCursor(waitCursor), false);
290
                // Actually make the sub interpreter
291
                // FIXME: This calls abort() in a Python debug build. We're doing something wrong.
292
                stateo = PyEval_SaveThread();
293
                state = Py_NewInterpreter();
294
                // chdir to the dir the script is in
295
                QDir::setCurrent(fi.dirPath(true));
296
                // init the 'scribus' module in the sub-interpreter
297
                initscribus(Carrier);
298
        }
299
        // make sure sys.argv[0] is the path to the script
82 Franz 300
        comm[0] = na.data();
1384 cbradney 301
        PySys_SetArgv(1, comm);
221 Franz 302
        // call python script
666 fschmid 303
        PyObject* m = PyImport_AddModule((char*)"__main__");
551 fschmid 304
        if (m == NULL)
305
                qDebug("Failed to get __main__ - aborting script");
306
        else
332 Franz 307
        {
857 cbradney 308
                // FIXME: If filename contains chars outside 7bit ascii, might be problems
551 fschmid 309
                PyObject* globals = PyModule_GetDict(m);
310
                // Build the Python code to run the script
1384 cbradney 311
                QString cm = QString("from __future__ import division\n");
312
                cm        += QString("import sys\n");
313
                cm        += QString("import cStringIO\n");
551 fschmid 314
                cm        += QString("sys.path[0] = \"%1\"\n").arg(fi.dirPath(true));
1384 cbradney 315
                // Replace sys.stdin with a dummy StringIO that always returns
316
                // "" for read
317
                if (useDummyStdin)
318
                        cm    += QString("sys.stdin = cStringIO.StringIO()\n");
551 fschmid 319
                cm        += QString("try:\n");
320
                cm        += QString("    execfile(\"%1\")\n").arg(fileName);
321
                cm        += QString("except SystemExit:\n");
322
                cm        += QString("    pass\n");
323
                // Capture the text of any other exception that's raised by the interpreter
324
                // into a StringIO buffer for later extraction.
1384 cbradney 325
                cm        += QString("except:\n");
326
                cm        += QString("    import traceback\n");
327
                cm        += QString("    import scribus\n");                  // we stash our working vars here
328
                cm        += QString("    scribus._f=cStringIO.StringIO()\n");
329
                cm        += QString("    traceback.print_exc(file=scribus._f)\n");
330
                cm        += QString("    _errorMsg = scribus._f.getvalue()\n");
331
                cm        += QString("    del(scribus._f)\n");
332
                // We re-raise the exception so the return value of PyRun_StringFlags reflects
551 fschmid 333
                // the fact that an exception has ocurred.
334
                cm        += QString("    raise\n");
857 cbradney 335
                // FIXME: if cmd contains chars outside 7bit ascii, might be problems
551 fschmid 336
                QCString cmd = cm.latin1();
1384 cbradney 337
                // Now run the script in the interpreter's global scope. It'll run in a
338
                // sub-interpreter if we created and switched to one earlier, otherwise
339
                // it'll run in the main interpreter.
551 fschmid 340
                PyObject* result = PyRun_String(cmd.data(), Py_file_input, globals, globals);
341
                // NULL is returned if an exception is set. We don't care about any
342
                // other return value (most likely None anyway) and can ignore it.
343
                if (result == NULL)
344
                {
1384 cbradney 345
                        // We've already saved the exception text, so clear the exception
346
                        PyErr_Clear();
347
                        PyObject* errorMsgPyStr = PyMapping_GetItemString(globals, (char*)"_errorMsg");
551 fschmid 348
                        if (errorMsgPyStr == NULL)
349
                        {
350
                                // It's rather unlikely that this will ever be reached - to get here
351
                                // we'd have to fail to retrive the string we just created.
352
                                qDebug("Error retrieving error message content after script exception!");
353
                                qDebug("Exception was:");
354
                                PyErr_Print();
355
                        }
356
                        else
357
                        {
358
                                QString errorMsg = PyString_AsString(errorMsgPyStr);
359
                                // Display a dialog to the user with the exception
360
                                QClipboard *cp = QApplication::clipboard();
361
                                cp->setText(errorMsg);
362
                                QMessageBox::warning(Carrier,
363
                                                                        tr("Script error"),
364
                                                                        tr("If you are running an official script report it at <a href=\"http://bugs.scribus.net\">bugs.scribus.net</a> please.")
365
                                                                        + "<pre>" +errorMsg + "</pre>"
366
                                                                        + tr("This message is in your clipboard too. Use Ctrl+V to paste it into bug tracker."));
367
                        }
368
                } // end if result == NULL
369
                // Because 'result' may be NULL, not a PyObject*, we must call PyXDECREF not Py_DECREF
370
                Py_XDECREF(result);
371
        } // end if m == NULL
1384 cbradney 372
        if (!inMainInterpreter)
373
        {
374
                Py_EndInterpreter(state);
375
                PyEval_RestoreThread(stateo);
376
                Carrier->ScriptRunning = false;
377
                qApp->restoreOverrideCursor();
378
        }
82 Franz 379
}
380
 
381
QString MenuTest::slotRunScript(QString Script)
382
{
1061 subik 383
        qApp->setOverrideCursor(QCursor(waitCursor), false);
82 Franz 384
        char* comm[1];
385
        QString cm;
386
        InValue = Script;
387
        QString CurDir = QDir::currentDirPath();
388
        if(PyThreadState_Get() != NULL)
282 Franz 389
        {
82 Franz 390
                initscribus(Carrier);
391
                if (RetVal == 0)
282 Franz 392
                {
857 cbradney 393
                        // FIXME: if CurDir contains chars outside 7bit ascii, might be problems
1384 cbradney 394
                        cm =  "import sys\n";
395
                        cm += "sys.path[0] = \""+CurDir+"\"\n";
82 Franz 396
                        cm += "import cStringIO\n";
1384 cbradney 397
                        cm += "import scribus\n";
398
                        // Only import all names from 'scribus' to the global namespace if the user wants us to.
399
                        // We still need to pull in a few special names used by Scribus though.
400
                        if (importAllNames)
401
                                cm += "from scribus import *\n";
402
                        if (useDummyStdin)
403
                                cm += "sys.stdin = cStringIO.StringIO()\n";
404
                        cm += "scribus._bu = cStringIO.StringIO()\n";
405
                        cm += "sys.stdout = scribus._bu\n";
406
                        cm += "sys.stderr = scribus._bu\n";
82 Franz 407
                        cm += "import code\n";
1384 cbradney 408
                        cm += "scribus._ia = code.InteractiveConsole(globals())\n";
282 Franz 409
                }
1384 cbradney 410
                cm += "scribus._sc = scribus._getval()\n";
411
                cm += "scribus._rv = scribus._ia.push(scribus._sc)\n";
412
                cm += "if scribus._rv == 1:\n";
413
                cm += "    scribus._re = \"...\"\n";
82 Franz 414
                cm += "else:\n";
1384 cbradney 415
                cm += "    scribus._re = scribus._bu.getvalue()\n";
416
                cm += "scribus._retval(scribus._re, scribus._rv)\n";
282 Franz 417
        }
857 cbradney 418
        // FIXME: if cmd contains chars outside 7bit ascii, might be problems
82 Franz 419
        QCString cmd = cm.latin1();
666 fschmid 420
        comm[0] = (char*)"scribus";
82 Franz 421
        PySys_SetArgv(1, comm);
422
        PyRun_SimpleString(cmd.data());
423
        if (RetVal == 0)
282 Franz 424
        {
82 Franz 425
                RetString += ">>>";
426
                pcon->OutWin->Prompt = ">>>";
282 Franz 427
        }
82 Franz 428
        else
429
                pcon->OutWin->Prompt = "...";
1061 subik 430
        qApp->restoreOverrideCursor();
82 Franz 431
        return RetString;
432
}
433
 
1384 cbradney 434
void MenuTest::loadScript()
435
{
436
        if (!this->enableExtPython)
437
        {
438
                QMessageBox::information(Carrier, tr("Scribus - Script Plugin"),
439
                        tr("The 'Load Script' function of the script plugin is currently disabled.\n"
440
                           "If you just want to run a normal script, you probably want to use\n"
441
                           "'Execute Script...' instead.\n\n"
442
                           "If you do actually want to load a Python extension script or macro, you\n"
443
                           "need to go into the Scripter Settings in the Script menu and enable\n"
444
                           "scripter extensions there.\n\n"
445
                           "Please read the documentation on extension scripts first.\n"));
446
                return;
447
        }
448
        QString fileName;
449
        QString scriptDir = Carrier->Prefs.ScriptDir;
450
        if (scriptDir == "")
451
                scriptDir = QDir::currentDirPath();
452
        CustomFDialog diaf((QWidget*)parent(), scriptDir, QObject::tr("Open"), QObject::tr("Python Scripts (*.py);; All Files (*)"));
453
        if (diaf.exec())
454
        {
455
                fileName = diaf.selectedFile();
456
                // Run the script in the main interpreter, not a sub-interpreter
457
                slotRunScriptFile(fileName, true);
458
        }
459
}
460
 
82 Franz 461
void MenuTest::slotInteractiveScript()
462
{
463
        if (pcon->isVisible())
282 Franz 464
        {
308 Franz 465
                men->changeItem(cons, tr("Show &Console"));
82 Franz 466
                pcon->hide();
282 Franz 467
        }
82 Franz 468
        else
282 Franz 469
        {
308 Franz 470
                men->changeItem(cons, tr("Hide &Console"));
82 Franz 471
                pcon->show();
282 Franz 472
        }
82 Franz 473
}
474
 
475
void MenuTest::slotExecute()
476
{
477
        pcon->OutWin->append(slotRunScript(pcon->OutWin->LastComm));
478
        pcon->OutWin->moveCursor(QTextEdit::MoveEnd, false);
479
        pcon->OutWin->scrollToBottom();
480
        pcon->OutWin->ensureCursorVisible();
222 Franz 481
        FinishScriptRun();
82 Franz 482
}
483
 
484
void MenuTest::ReadPlugPrefs()
485
{
486
        QDomDocument docu("scriptrc");
282 Franz 487
        QString ho = QDir::homeDirPath();
488
        QFile f(QDir::convertSeparators(ho+"/.scribus/scripter.rc"));
82 Franz 489
        if(!f.open(IO_ReadOnly))
490
                return;
491
        if(!docu.setContent(&f))
282 Franz 492
        {
82 Franz 493
                f.close();
494
                return;
282 Franz 495
        }
82 Franz 496
        f.close();
497
        QDomElement elem=docu.documentElement();
498
        if (elem.tagName() != "SCRIPTRC")
499
                return;
500
        QDomNode DOC=elem.firstChild();
501
        while(!DOC.isNull())
282 Franz 502
        {
82 Franz 503
                QDomElement dc=DOC.toElement();
504
                if (dc.tagName()=="RECENT")
505
                        SavedRecentScripts.append(dc.attribute("NAME"));
1384 cbradney 506
                // Check to see if the 'load script' menu item should be enabled
507
                else if (dc.tagName() == "EXTPYTHON")
508
                        enableExtPython = dc.attribute("ENABLE") == "TRUE";
509
                // and check whether we should do a 'from scribus import *' in the main interpreter;
510
                else if (dc.tagName() == "IMPORTNAMES")
511
                        importAllNames = dc.attribute("ENABLE") == "TRUE";
512
                // Should we import the old-style names?
513
                else if (dc.tagName() == "LEGACYALIASES")
514
                        legacyAliases = dc.attribute("ENABLE") == "TRUE";
515
                // Should we run a startup script? If so, where to load it from?
516
                else if (dc.tagName() == "STARTUPSCRIPT")
517
                {
518
                        startupScriptEnable = dc.attribute("ENABLE") == "TRUE";
519
                        startupScript = dc.attribute("FILE");
520
                }
521
                // replace stdin with a dummy object that always returns "" ?
522
                else if (dc.tagName() == "USEDUMMYSTDIN")
523
                        useDummyStdin = dc.attribute("ENABLE") == "TRUE";
82 Franz 524
                DOC=DOC.nextSibling();
282 Franz 525
        }
82 Franz 526
}
527
 
528
void MenuTest::SavePlugPrefs()
529
{
530
        QDomDocument docu("scriptrc");
531
        QString st="<SCRIPTRC></SCRIPTRC>";
532
        docu.setContent(st);
533
        QDomElement elem=docu.documentElement();
87 Franz 534
        for (uint rd=0; rd < Tes->RecentScripts.count(); ++rd)
282 Franz 535
        {
82 Franz 536
                QDomElement rde=docu.createElement("RECENT");
537
                rde.setAttribute("NAME",Tes->RecentScripts[rd]);
538
                elem.appendChild(rde);
282 Franz 539
        }
1384 cbradney 540
 
541
        // save the "load script" flag, from import flag, and aliases flag
542
        QDomElement extPythonItem = docu.createElement("EXTPYTHON");
543
        extPythonItem.setAttribute("ENABLE", enableExtPython ? "TRUE" : "FALSE");
544
        elem.appendChild(extPythonItem);
545
 
546
        QDomElement allNamesItem = docu.createElement("IMPORTNAMES");
547
        allNamesItem.setAttribute("ENABLE", importAllNames ? "TRUE" : "FALSE");
548
        elem.appendChild(allNamesItem);
549
 
550
        QDomElement legacyAliasesItem = docu.createElement("LEGACYALIASES");
551
        legacyAliasesItem.setAttribute("ENABLE", legacyAliases ? "TRUE" : "FALSE");
552
        elem.appendChild(legacyAliasesItem);
553
 
554
        QDomElement dummyStdinItem = docu.createElement("USEDUMMYSTDIN");
555
        dummyStdinItem.setAttribute("ENABLE", useDummyStdin ? "TRUE" : "FALSE");
556
        elem.appendChild(dummyStdinItem);
557
 
558
        // save the startup script path and flag
559
        QDomElement startupScriptItem = docu.createElement("STARTUPSCRIPT");
560
        startupScriptItem.setAttribute("ENABLE", startupScriptEnable ? "TRUE" : "FALSE");
561
        startupScriptItem.setAttribute("FILE", startupScript);
562
        elem.appendChild(startupScriptItem);
563
 
564
        // then write out the prefs file
282 Franz 565
        QString ho = QDir::homeDirPath();
566
        QFile f(QDir::convertSeparators(ho+"/.scribus/scripter.rc"));
82 Franz 567
        if(!f.open(IO_WriteOnly))
568
                return;
569
        QTextStream s(&f);
570
        s<<docu.toCString();
571
        f.close();
572
}
573
 
539 subik 574
/* 11/1/2004 pv - Show docstring of the script to the user.
575
 * I don't know how to get docstring via e.g. pydoc because of
576
 * it needs to run script => error cannot find scribus module
577
 */
538 subik 578
void MenuTest::aboutScript()
579
{
580
        QString fname = Carrier->CFileDialog(".", "about", "Scripts (*.py)", "", 0, 0, 0, 0);
581
        QFileInfo fi = QFileInfo(fname);
582
        QString html = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus/aboutScript.html");
583
        QFile input(fname);
584
        if(!input.open(IO_ReadOnly))
585
                return;
586
        QFile output(html);
587
        if(!output.open(IO_WriteOnly))
588
                return;
589
        QTextStream intputstream(&input);
590
        QTextStream outputstream(&output);
539 subik 591
        QString content = intputstream.read();
592
        QString docstring = content.section("\"\"\"", 1, 1);
593
        if (docstring != "")
594
        {
595
                outputstream << "<h1>Documentation for: " << fi.fileName() << "</h1><p>";
596
                outputstream << docstring.replace("\n\n", "<p>");
597
        }
598
        else
599
        {
600
                outputstream << "<pre>" << endl;
601
                outputstream << "<p><b>Script "<< fi.fileName() << " doesn't contain any docstring!</b></p>" << content;
602
                outputstream << "</pre>" << endl;
603
        }
538 subik 604
        output.close();
605
        input.close();
804 subik 606
        HelpBrowser *dia = new HelpBrowser(0, QObject::tr("About Script") + " " + fi.fileName(), "en", "", html);
538 subik 607
        dia->show();
608
}
609
 
1384 cbradney 610
/* 2005-01-02 CR
611
 * Display a preferences dialog to let the user configure
612
 * scripter settings such as enabling Python extension scripts
613
 * and setting a start-up script. The prefs dialog is defined in
614
 * scripterprefs.ui .
615
 */
616
void MenuTest::preferencesDialog()
617
{
618
        ScripterPreferences* prefDia = new ScripterPreferences(Carrier, "scripterPreferences");
619
        prefDia->extPythonChk->setChecked(this->enableExtPython);
620
        prefDia->startupScriptGroup->setChecked(this->startupScriptEnable);
621
        prefDia->startupScriptPath->setText(this->startupScript);
622
        prefDia->importNamesChk->setChecked(this->importAllNames);
623
        prefDia->legacyAliasesChk->setChecked(this->legacyAliases);
624
        prefDia->useFakeStdinChk->setChecked(this->useDummyStdin);
625
        if (prefDia->exec())
626
        {
627
                this->enableExtPython = prefDia->extPythonChk->isChecked();
628
                this->startupScriptEnable = prefDia->startupScriptGroup->isChecked();
629
                this->startupScript = prefDia->startupScriptPath->text();
630
                this->importAllNames = prefDia->importNamesChk->isChecked();
631
                this->legacyAliases = prefDia->legacyAliasesChk->isChecked();
632
                this->useDummyStdin = prefDia->useFakeStdinChk->isChecked();
633
        }
634
        delete prefDia;
635
}
636
 
551 fschmid 637
// This function builds a Python wrapper function called newName around the
638
// python function called oldName. The wrapper function prints a warning, then
639
// calls oldName with all passed arguments and returns the result from oldName.
640
// The wrapper is stored in the module dictionary passed, so it appears in the
641
// `scribus' module and will be imported by 'from scribus import'. A docstring
642
// is provided to direct the user to the correct function.
643
// By default the warning gets output only on the first use of the function in a given
644
// interpreter instance, but user scripts can change this.
645
void deprecatedFunctionAlias(PyObject* scribusdict, char* oldName, char* newName)
646
{
647
        // Build the Python code to create the wrapper function
648
        QString wrapperFunc = "";
649
        wrapperFunc += QString("def %1(*args, **kwargs):\n").arg(newName);
650
        wrapperFunc += QString("    \"\"\"Deprecated alias for function %1 - see help(%2).\"\"\"\n").arg(oldName).arg(oldName);
651
        wrapperFunc += QString("    warnings.warn(\"Warning, script function %1 is deprecated, use %2 instead.\\n\",exceptions.DeprecationWarning)\n").arg(newName).arg(oldName);
652
        wrapperFunc += QString("    return %1(*args,**kwargs)\n").arg(oldName);
857 cbradney 653
        QCString wsData = wrapperFunc.latin1(); //this should probably be utf8 now
551 fschmid 654
        // And run it in the namespace of the scribus module
655
        PyObject* result = PyRun_String(wsData, Py_file_input, scribusdict, scribusdict);
656
        // NULL is returned if an exception is set. We don't care about any other return value and
657
        // can ignore it.
658
        if (result == NULL)
659
        {
660
                qDebug("Failed to alias %s to %s in Python scripter - exception raised!", oldName, newName);
661
                PyErr_Print();
662
        }
663
        // Because 'result' may be NULL, not a PyObject*, we must call PyXDECREF not Py_DECREF
664
        Py_XDECREF(result);
665
}
666
 
736 subik 667
// Copy constants by coping the reference to them. Equivalent to
668
// scribus.__dict__[newName] = scribus.__dict__[oldName].
669
void constantAlias(PyObject* scribusdict, const char* oldName, const char* newName)
732 subik 670
{
736 subik 671
        /* Work around the braindead Python/C API not using 'const' for
672
         * strings it won't change. */
673
        char* newNameTemp = strndup(newName, strlen(newName));
674
        char* oldNameTemp = strndup(oldName, strlen(oldName));
675
        assert(newNameTemp != NULL);
676
        assert(oldNameTemp != NULL);
677
        /* We use PyMapping_GetItemString because unlike PyDict_GetItemString it
678
         * returns a new (not borrowed) reference, while PyDict_SetItemString
679
         * consumes the reference. That means we don't have to Py_INCREF anything.
680
         */
681
        PyObject* item = PyMapping_GetItemString(scribusdict, oldNameTemp);
682
        assert(item != NULL);
683
        PyDict_SetItemString(scribusdict, newNameTemp, item);
684
        free(newNameTemp);
685
        free(oldNameTemp);
732 subik 686
}
687
 
82 Franz 688
/****************************************************************************************/
689
/*                                                                                      */
538 subik 690
/*   Definitions of the Python commands                                                 */
82 Franz 691
/*                                                                                      */
692
/****************************************************************************************/
693
 
1384 cbradney 694
static PyObject *scribus_retval(PyObject* /*self*/, PyObject* args)
82 Franz 695
{
857 cbradney 696
        char *Name = NULL;
697
        int retV = 0;
666 fschmid 698
        if (!PyArg_ParseTuple(args, (char*)"si", &Name, &retV))
82 Franz 699
                return NULL;
857 cbradney 700
        // Because sysdefaultencoding is not utf-8, Python is returning utf-8 encoded
701
        // 8-bit char* strings. Make sure Qt understands that the input is utf-8 not
702
        // the default local encoding (usually latin-1) by using QString::fromUtf8()
703
        RetString = QString::fromUtf8(Name);
82 Franz 704
        RetVal = retV;
705
        return PyInt_FromLong(0L);
706
}
707
 
1384 cbradney 708
static PyObject *scribus_getval(PyObject* /*self*/)
82 Franz 709
{
857 cbradney 710
        return PyString_FromString(InValue.utf8().data());
82 Franz 711
}
712
 
852 subik 713
/*!
714
 * Translate a docstring. Small helper function for use with the
715
 * PyMethodDef struct.
716
 */
717
char* tr(const char* docstringConstant)
718
{
857 cbradney 719
        // Alas, there's a lot of wasteful string copying going on
720
        // here.
721
        QString translated = QObject::tr(docstringConstant, "scripter docstring");
722
        /*
723
         * Python doesn't support 'unicode' object docstrings in the PyMethodDef,
724
         * and has no way to specify what encoding docstrings are in. The passed C
725
         * strings passed are made into 'str' objects as-is. These are interpreted
726
         * as being in the Python sysdefaultencoding, usually 'ascii', when used.
727
         * We now set systemdefaultencoding to 'utf-8' ...  so we're going to pass
728
         * Python an 8-bit utf-8 encoded string in a char* .  With
729
         * sysdefaultencoding set correctly, Python will interpret it correctly and
730
         * we'll have our unicode docstrings. It's not as ugly a hack as it sounds,
731
         * you just have to remember that C and Python strings can both be
732
         * considered 8-bit strings of binary data that can be later interpreted as
733
         * a text string in a particular text encoding.
734
         */
862 cbradney 735
        QCString utfTranslated = translated.utf8();
736
        const char* trch = utfTranslated.data();
857 cbradney 737
        return strndup(trch, strlen(trch));
852 subik 738
}
739
 
857 cbradney 740
/* Now we're using the more pythonic convention for names:
741
 * class - ClassName
742
 * procedure/function/method - procedureName
743
 * etc. */
852 subik 744
PyMethodDef scribus_methods[] = {
421 Franz 745
        // 2004/10/03 pv - aliases with common Python syntax - ClassName methodName
551 fschmid 746
        // 2004-11-06 cr - move aliasing to dynamically generated wrapper functions, sort methoddef
935 subik 747
        {const_cast<char*>("changeColor"), scribus_setcolor, METH_VARARGS, tr(scribus_setcolor__doc__)},
748
        {const_cast<char*>("closeDoc"), (PyCFunction)scribus_closedoc, METH_NOARGS, tr(scribus_closedoc__doc__)},
749
        {const_cast<char*>("createBezierLine"), scribus_bezierline, METH_VARARGS, tr(scribus_bezierline__doc__)},
750
        {const_cast<char*>("createEllipse"), scribus_newellipse, METH_VARARGS, tr(scribus_newellipse__doc__)},
751
        {const_cast<char*>("createImage"), scribus_newimage, METH_VARARGS, tr(scribus_newimage__doc__)},
752
        {const_cast<char*>("createLayer"), scribus_createlayer, METH_VARARGS, tr(scribus_createlayer__doc__)},
753
        {const_cast<char*>("createLine"), scribus_newline, METH_VARARGS, tr(scribus_newline__doc__)},
754
        {const_cast<char*>("createPathText"), scribus_pathtext, METH_VARARGS, tr(scribus_pathtext__doc__)},
755
        {const_cast<char*>("createPolygon"), scribus_polygon, METH_VARARGS, tr(scribus_polygon__doc__)},
756
        {const_cast<char*>("createPolyLine"), scribus_polyline, METH_VARARGS, tr(scribus_polyline__doc__)},
757
        {const_cast<char*>("createRect"), scribus_newrect, METH_VARARGS, tr(scribus_newrect__doc__)},
758
        {const_cast<char*>("createText"), scribus_newtext, METH_VARARGS, tr(scribus_newtext__doc__)},
759
        {const_cast<char*>("currentPage"), (PyCFunction)scribus_actualpage, METH_NOARGS, tr(scribus_actualpage__doc__)},
760
        {const_cast<char*>("defineColor"), scribus_newcolor, METH_VARARGS, tr(scribus_newcolor__doc__)},
761
        {const_cast<char*>("deleteColor"), scribus_delcolor, METH_VARARGS, tr(scribus_delcolor__doc__)},
762
        {const_cast<char*>("deleteLayer"), scribus_removelayer, METH_VARARGS, tr(scribus_removelayer__doc__)},
763
        {const_cast<char*>("deleteObject"), scribus_deleteobj, METH_VARARGS, tr(scribus_deleteobj__doc__)},
764
        {const_cast<char*>("deletePage"), scribus_deletepage, METH_VARARGS, tr(scribus_deletepage__doc__)},
765
        {const_cast<char*>("deleteText"), scribus_deletetext, METH_VARARGS, tr(scribus_deletetext__doc__)},
766
        {const_cast<char*>("deselectAll"), (PyCFunction)scribus_deselect, METH_NOARGS, tr(scribus_deselect__doc__)},
767
        {const_cast<char*>("docChanged"), scribus_docchanged, METH_VARARGS, tr(scribus_docchanged__doc__)},
768
        {const_cast<char*>("fileDialog"), (PyCFunction)scribus_filedia, METH_VARARGS|METH_KEYWORDS, tr(scribus_filedia__doc__)},
769
        {const_cast<char*>("getActiveLayer"), (PyCFunction)scribus_getactlayer, METH_NOARGS, tr(scribus_getactlayer__doc__)},
770
        {const_cast<char*>("getAllObjects"), scribus_getallobj, METH_VARARGS, tr(scribus_getallobj__doc__)},
771
        {const_cast<char*>("getAllStyles"), (PyCFunction)scribus_getstylenames, METH_NOARGS, tr(scribus_getstylenames__doc__)},
772
        {const_cast<char*>("getAllText"), scribus_gettext, METH_VARARGS, tr(scribus_gettext__doc__)},
773
        {const_cast<char*>("getColorNames"), (PyCFunction)scribus_colornames, METH_NOARGS, tr(scribus_colornames__doc__)},
774
        {const_cast<char*>("getColor"), scribus_getcolor, METH_VARARGS, tr(scribus_getcolor__doc__)},
775
        {const_cast<char*>("getColumnGap"), scribus_getcolumngap, METH_VARARGS, tr(scribus_getcolumngap__doc__)},
776
        {const_cast<char*>("getColumns"), scribus_getcolumns, METH_VARARGS, tr(scribus_getcolumns__doc__)},
777
        {const_cast<char*>("getCornerRadius"), scribus_getcornerrad, METH_VARARGS, tr(scribus_getcornerrad__doc__)},
778
        {const_cast<char*>("getFillColor"), scribus_getfillcolor, METH_VARARGS, tr(scribus_getfillcolor__doc__)},
779
        {const_cast<char*>("getFillShade"), scribus_getfillshade, METH_VARARGS, tr(scribus_getfillshade__doc__)},
780
        {const_cast<char*>("getFontNames"), (PyCFunction)scribus_fontnames, METH_NOARGS, tr(scribus_fontnames__doc__)},
781
        {const_cast<char*>("getFont"), scribus_getfont, METH_VARARGS, tr(scribus_getfont__doc__)},
782
        {const_cast<char*>("getFontSize"), scribus_getfontsize, METH_VARARGS, tr(scribus_getfontsize__doc__)},
783
        {const_cast<char*>("getGuiLanguage"), (PyCFunction)scribus_getlanguage, METH_NOARGS, tr(scribus_getlanguage__doc__)},
784
        {const_cast<char*>("getHGuides"), (PyCFunction)scribus_getHguides, METH_NOARGS, tr(scribus_getHguides__doc__)},
785
        {const_cast<char*>("getImageFile"), scribus_getimgname, METH_VARARGS, tr(scribus_getimgname__doc__)},
786
        {const_cast<char*>("getImageScale"), scribus_getimgscale, METH_VARARGS, tr(scribus_getimgscale__doc__)},
787
        {const_cast<char*>("getLayers"), (PyCFunction)scribus_getlayers, METH_NOARGS, tr(scribus_getlayers__doc__)},
788
        {const_cast<char*>("getLineCap"), scribus_getlineend, METH_VARARGS, tr(scribus_getlineend__doc__)},
789
        {const_cast<char*>("getLineColor"), scribus_getlinecolor, METH_VARARGS, tr(scribus_getlinecolor__doc__)},
790
        {const_cast<char*>("getLineJoin"), scribus_getlinejoin, METH_VARARGS, tr(scribus_getlinejoin__doc__)},
791
        {const_cast<char*>("getLineShade"), scribus_getlineshade, METH_VARARGS, tr(scribus_getlineshade__doc__)},
792
        {const_cast<char*>("getLineSpacing"), scribus_getlinespace, METH_VARARGS, tr(scribus_getlinespace__doc__)},
793
        {const_cast<char*>("getLineStyle"), scribus_getlinestyle, METH_VARARGS, tr(scribus_getlinestyle__doc__)},
794
        {const_cast<char*>("getLineWidth"), scribus_getlinewidth, METH_VARARGS, tr(scribus_getlinewidth__doc__)},
795
        {const_cast<char*>("getPageItems"), (PyCFunction)scribus_getpageitems, METH_NOARGS, tr(scribus_getpageitems__doc__)},
796
        {const_cast<char*>("getPageMargins"), (PyCFunction)scribus_getpagemargins, METH_NOARGS, tr(scribus_getpagemargins__doc__)},
797
        {const_cast<char*>("getPageSize"), (PyCFunction)scribus_pagedimension, METH_NOARGS, tr(scribus_pagedimension__doc__)}, // just an alias to PageDimension()
798
        {const_cast<char*>("getPosition"), scribus_getposi, METH_VARARGS, tr(scribus_getposi__doc__)},
799
        {const_cast<char*>("getRotation"), scribus_getrotation, METH_VARARGS, tr(scribus_getrotation__doc__)},
800
        {const_cast<char*>("getSelectedObject"), scribus_getselobjnam, METH_VARARGS, tr(scribus_getselobjnam__doc__)},
801
        {const_cast<char*>("getSize"), scribus_getsize, METH_VARARGS, tr(scribus_getsize__doc__)},
802
        {const_cast<char*>("getTextColor"), scribus_getlinecolor, METH_VARARGS, tr(scribus_getlinecolor__doc__)},
803
        {const_cast<char*>("getTextLength"), scribus_gettextsize, METH_VARARGS, tr(scribus_gettextsize__doc__)},
804
        {const_cast<char*>("getText"), scribus_getframetext, METH_VARARGS, tr(scribus_getframetext__doc__)},
805
        {const_cast<char*>("getTextShade"), scribus_getlineshade, METH_VARARGS, tr(scribus_getlineshade__doc__)},
806
        {const_cast<char*>("getUnit"), (PyCFunction)scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)},
807
        {const_cast<char*>("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)},
808
        {const_cast<char*>("getXFontNames"), (PyCFunction)scribus_xfontnames, METH_NOARGS, tr(scribus_xfontnames__doc__)},
809
        {const_cast<char*>("gotoPage"), scribus_gotopage, METH_VARARGS, tr(scribus_gotopage__doc__)},
810
        {const_cast<char*>("groupObjects"), scribus_groupobj, METH_VARARGS, tr(scribus_groupobj__doc__)},
811
        {const_cast<char*>("haveDoc"), (PyCFunction)scribus_havedoc, METH_NOARGS, tr(scribus_havedoc__doc__)},
812
        {const_cast<char*>("insertText"), scribus_inserttext, METH_VARARGS, tr(scribus_inserttext__doc__)},
813
        {const_cast<char*>("isLayerPrintable"), scribus_glayerprint, METH_VARARGS, tr(scribus_glayerprint__doc__)},
814
        {const_cast<char*>("isLayerVisible"), scribus_glayervisib, METH_VARARGS, tr(scribus_glayervisib__doc__)},
815
        {const_cast<char*>("isLocked"), scribus_islocked, METH_VARARGS, tr(scribus_islocked__doc__)},
816
        {const_cast<char*>("linkTextFrames"), scribus_linktextframes, METH_VARARGS, tr(scribus_linktextframes__doc__)},
817
        {const_cast<char*>("loadImage"), scribus_loadimage, METH_VARARGS, tr(scribus_loadimage__doc__)},
818
        {const_cast<char*>("loadStylesFromFile"), scribus_loadstylesfromfile, METH_VARARGS, tr(scribus_loadstylesfromfile__doc__)},
819
        {const_cast<char*>("lockObject"), scribus_lockobject, METH_VARARGS, tr(scribus_lockobject__doc__)},
820
        {const_cast<char*>("messagebarText"), scribus_messagebartext, METH_VARARGS, tr(scribus_messagebartext__doc__)},
821
        {const_cast<char*>("messageBox"), (PyCFunction)scribus_messdia, METH_VARARGS|METH_KEYWORDS, tr(scribus_messdia__doc__)},
822
        {const_cast<char*>("moveObjectAbs"), scribus_moveobjabs, METH_VARARGS, tr(scribus_moveobjabs__doc__)},
823
        {const_cast<char*>("moveObject"), scribus_moveobjrel, METH_VARARGS, tr(scribus_moveobjrel__doc__)},
824
        {const_cast<char*>("newDocDialog"), (PyCFunction)scribus_newdocdia, METH_NOARGS, tr(scribus_newdocdia__doc__)},
825
        {const_cast<char*>("newDoc"), scribus_newdoc, METH_VARARGS, tr(scribus_newdoc__doc__)},
826
        {const_cast<char*>("newPage"), scribus_newpage, METH_VARARGS, tr(scribus_newpage__doc__)},
827
        {const_cast<char*>("objectExists"),scribus_objectexists, METH_VARARGS, tr(scribus_objectexists__doc__)},
828
        {const_cast<char*>("openDoc"), scribus_opendoc, METH_VARARGS, tr(scribus_opendoc__doc__)},
829
        {const_cast<char*>("pageCount"), (PyCFunction)scribus_pagecount, METH_NOARGS, tr(scribus_pagecount__doc__)},
830
        {const_cast<char*>("pageDimension"), (PyCFunction)scribus_pagedimension, METH_NOARGS, tr(scribus_pagedimension__doc__)},
831
        {const_cast<char*>("progressReset"), (PyCFunction)scribus_progressreset, METH_NOARGS, tr(scribus_progressreset__doc__)},
832
        {const_cast<char*>("progressSet"), scribus_progresssetprogress, METH_VARARGS, tr(scribus_progresssetprogress__doc__)},
833
        {const_cast<char*>("progressTotal"), scribus_progresssettotalsteps, METH_VARARGS, tr(scribus_progresssettotalsteps__doc__)},
834
        {const_cast<char*>("redrawAll"), (PyCFunction)scribus_redraw, METH_NOARGS, tr(scribus_redraw__doc__)},
835
        {const_cast<char*>("renderFont"), scribus_renderfont, METH_VARARGS, tr(scribus_renderfont__doc__)},
836
        {const_cast<char*>("replaceColor"), scribus_replcolor, METH_VARARGS, tr(scribus_replcolor__doc__)},
837
        {const_cast<char*>("rotateObjectAbs"), scribus_rotobjabs, METH_VARARGS, tr(scribus_rotobjabs__doc__)},
838
        {const_cast<char*>("rotateObject"), scribus_rotobjrel, METH_VARARGS, tr(scribus_rotobjrel__doc__)},
839
        {const_cast<char*>("saveDocAs"), scribus_savedocas, METH_VARARGS, tr(scribus_savedocas__doc__)},
840
        {const_cast<char*>("saveDoc"), (PyCFunction)scribus_savedoc, METH_NOARGS, tr(scribus_savedoc__doc__)},
841
        {const_cast<char*>("savePageAsEPS"), scribus_savepageeps, METH_VARARGS, tr(scribus_savepageeps__doc__)},
842
        {const_cast<char*>("scaleGroup"), scribus_scalegroup, METH_VARARGS, tr(scribus_scalegroup__doc__)},
843
        {const_cast<char*>("scaleImage"), scribus_scaleimage, METH_VARARGS, tr(scribus_scaleimage__doc__)},
844
        {const_cast<char*>("selectionCount"), (PyCFunction)scribus_selcount, METH_NOARGS, tr(scribus_selcount__doc__)},
845
        {const_cast<char*>("selectObject"), scribus_selectobj, METH_VARARGS, tr(scribus_selectobj__doc__)},
846
        {const_cast<char*>("selectText"), scribus_selecttext, METH_VARARGS, tr(scribus_selecttext__doc__)},
847
        {const_cast<char*>("sentToLayer"), scribus_senttolayer, METH_VARARGS, tr(scribus_senttolayer__doc__)},
848
        {const_cast<char*>("setActiveLayer"), scribus_setactlayer, METH_VARARGS, tr(scribus_setactlayer__doc__)},
849
        {const_cast<char*>("setColumnGap"), scribus_setcolumngap, METH_VARARGS, tr(scribus_setcolumngap__doc__)},
850
        {const_cast<char*>("setColumns"), scribus_setcolumns, METH_VARARGS, tr(scribus_setcolumns__doc__)},
851
        {const_cast<char*>("setCornerRadius"), scribus_setcornerrad, METH_VARARGS, tr(scribus_setcornerrad__doc__)},
852
        {const_cast<char*>("setCursor"), scribus_setcursor, METH_VARARGS, tr(scribus_setcursor__doc__)},
853
        {const_cast<char*>("setDocType"), scribus_setdoctype, METH_VARARGS, tr(scribus_setdoctype__doc__)},
854
        {const_cast<char*>("setFillColor"), scribus_setfillcolor, METH_VARARGS, tr(scribus_setfillcolor__doc__)},
855
        {const_cast<char*>("setFillShade"), scribus_setfillshade, METH_VARARGS, tr(scribus_setfillshade__doc__)},
856
        {const_cast<char*>("setFont"), scribus_setfont, METH_VARARGS, tr(scribus_setfont__doc__)},
857
        {const_cast<char*>("setFontSize"), scribus_setfontsize, METH_VARARGS, tr(scribus_setfontsize__doc__)},
858
        {const_cast<char*>("setGradientFill"), scribus_setgradfill, METH_VARARGS, tr(scribus_setgradfill__doc__)},
859
        {const_cast<char*>("setHGuides"), scribus_setHguides, METH_VARARGS, tr(scribus_setHguides__doc__)},
860
        {const_cast<char*>("setInfo"), scribus_setinfo, METH_VARARGS, tr(scribus_setinfo__doc__)},
861
        {const_cast<char*>("setLayerPrintable"), scribus_layerprint, METH_VARARGS, tr(scribus_layerprint__doc__)},
862
        {const_cast<char*>("setLayerVisible"), scribus_layervisible, METH_VARARGS, tr(scribus_layervisible__doc__)},
863
        {const_cast<char*>("setLineCap"), scribus_setlineend, METH_VARARGS, tr(scribus_setlineend__doc__)},
864
        {const_cast<char*>("setLineColor"), scribus_setlinecolor, METH_VARARGS, tr(scribus_setlinecolor__doc__)},
865
        {const_cast<char*>("setLineJoin"), scribus_setlinejoin, METH_VARARGS, tr(scribus_setlinejoin__doc__)},
866
        {const_cast<char*>("setLineShade"), scribus_setlineshade, METH_VARARGS, tr(scribus_setlineshade__doc__)},
867
        {const_cast<char*>("setLineSpacing"), scribus_setlinespace, METH_VARARGS, tr(scribus_setlinespace__doc__)},
868
        {const_cast<char*>("setLineStyle"), scribus_setlinestyle, METH_VARARGS, tr(scribus_setlinestyle__doc__)},
869
        {const_cast<char*>("setLineWidth"), scribus_setlinewidth, METH_VARARGS, tr(scribus_setlinewidth__doc__)},
870
        {const_cast<char*>("setMargins"), scribus_setmargins, METH_VARARGS, tr(scribus_setmargins__doc__)},
871
        {const_cast<char*>("setMultiLine"), scribus_setmultiline, METH_VARARGS, tr(scribus_setmultiline__doc__)},
732 subik 872
        // duplicity? {"setMultiLine", scribus_setmultiline, METH_VARARGS, "TODO: docstring"},
935 subik 873
        {const_cast<char*>("setRedraw"), scribus_setredraw, METH_VARARGS, tr(scribus_setredraw__doc__)},
732 subik 874
        // 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."},
1387 subik 875
        {const_cast<char*>("setScaleImageToFrame"), (PyCFunction)scribus_setscaleimagetoframe, METH_KEYWORDS, tr(scribus_setscaleimagetoframe__doc__)},
935 subik 876
        {const_cast<char*>("setStyle"), scribus_setstyle, METH_VARARGS, tr(scribus_setstyle__doc__)},
877
        {const_cast<char*>("setTextAlignment"), scribus_setalign, METH_VARARGS, tr(scribus_setalign__doc__)},
878
        {const_cast<char*>("setTextColor"), scribus_settextfill, METH_VARARGS, tr(scribus_settextfill__doc__)},
879
        {const_cast<char*>("setText"), scribus_setboxtext, METH_VARARGS, tr(scribus_setboxtext__doc__)},
880
        {const_cast<char*>("setTextShade"), scribus_settextshade, METH_VARARGS, tr(scribus_settextshade__doc__)},
881
        {const_cast<char*>("setTextStroke"), scribus_settextstroke, METH_VARARGS, tr(scribus_settextstroke__doc__)},
882
        {const_cast<char*>("setUnit"), scribus_setunit, METH_VARARGS, tr(scribus_setunit__doc__)},
883
        {const_cast<char*>("setVGuides"), scribus_setVguides, METH_VARARGS, tr(scribus_setVguides__doc__)},
884
        {const_cast<char*>("sizeObject"), scribus_sizeobjabs, METH_VARARGS, tr(scribus_sizeobjabs__doc__)},
885
        {const_cast<char*>("statusMessage"), scribus_messagebartext, METH_VARARGS, tr(scribus_messagebartext__doc__)},
886
        {const_cast<char*>("textFlowsAroundFrame"), scribus_textflow, METH_VARARGS, tr(scribus_textflow__doc__)},
887
        {const_cast<char*>("traceText"), scribus_tracetext, METH_VARARGS, tr(scribus_tracetext__doc__)},
888
        {const_cast<char*>("unGroupObject"), scribus_ungroupobj, METH_VARARGS, tr(scribus_ungroupobj__doc__)},
889
        {const_cast<char*>("unlinkTextFrames"), scribus_unlinktextframes, METH_VARARGS, tr(scribus_unlinktextframes__doc__)},
890
        {const_cast<char*>("valueDialog"), scribus_valdialog, METH_VARARGS, tr(scribus_valdialog__doc__)},
1384 cbradney 891
        // Functions for use by extension scripts
892
        {const_cast<char*>("register_macro_callable"), (PyCFunction)register_macro_callable, METH_KEYWORDS, tr(register_macro_callable__doc__)},
893
        {const_cast<char*>("register_macro_code"), (PyCFunction)register_macro_code, METH_KEYWORDS, tr(register_macro_code__doc__)},
894
        {const_cast<char*>("unregister_macro"), (PyCFunction)unregister_macro, METH_KEYWORDS, const_cast<char*>("Un-register a macro")},
895
        // Private functions for use by the scripter API its self
896
        {const_cast<char*>("_retval"), scribus_retval, METH_VARARGS, const_cast<char*>("Scribus internal API for console.")},
897
        {const_cast<char*>("_getval"), (PyCFunction)scribus_getval, METH_NOARGS, const_cast<char*>("Scribus internal API for console.")},
1042 subik 898
        {NULL, (PyCFunction)(0), 0, NULL} /* sentinel */
82 Franz 899
};
900
 
901
void initscribus(ScribusApp *pl)
902
{
903
        PyObject *m, *d;
666 fschmid 904
        PyImport_AddModule((char*)"scribus");
411 Franz 905
        PyType_Ready(&Printer_Type);
418 Franz 906
        PyType_Ready(&PDFfile_Type);
666 fschmid 907
        m = Py_InitModule((char*)"scribus", scribus_methods);
411 Franz 908
        Py_INCREF(&Printer_Type);
666 fschmid 909
        PyModule_AddObject(m, (char*)"Printer", (PyObject *) &Printer_Type);
418 Franz 910
        Py_INCREF(&PDFfile_Type);
666 fschmid 911
        PyModule_AddObject(m, (char*)"PDFfile", (PyObject *) &PDFfile_Type);
82 Franz 912
        d = PyModule_GetDict(m);
474 subik 913
 
914
        // Set up the module exceptions
915
        // common exc.
666 fschmid 916
        ScribusException = PyErr_NewException((char*)"scribus.ScribusException", NULL, NULL);
474 subik 917
        Py_INCREF(ScribusException);
666 fschmid 918
        PyModule_AddObject(m, (char*)"ScribusException", ScribusException);
474 subik 919
        // no doc open
666 fschmid 920
        NoDocOpenError = PyErr_NewException((char*)"scribus.NoDocOpenError", ScribusException, NULL);
474 subik 921
        Py_INCREF(NoDocOpenError);
666 fschmid 922
        PyModule_AddObject(m, (char*)"NoDocOpenError", NoDocOpenError);
852 subik 923
        // wrong type of frame for operation
924
        WrongFrameTypeError = PyErr_NewException((char*)"scribus.WrongFrameTypeError", ScribusException, NULL);
925
        Py_INCREF(WrongFrameTypeError);
926
        PyModule_AddObject(m, (char*)"WrongFrameTypeError", WrongFrameTypeError);
927
        // Couldn't find named object, or no named object and no selection
928
        NoValidObjectError = PyErr_NewException((char*)"scribus.NoValidObjectError", ScribusException, NULL);
929
        Py_INCREF(NoValidObjectError);
930
        PyModule_AddObject(m, (char*)"NoValidObjectError", NoValidObjectError);
857 cbradney 931
        // Couldn't find the specified resource - font, color, etc.
932
        NotFoundError = PyErr_NewException((char*)"scribus.NotFoundError", ScribusException, NULL);
933
        Py_INCREF(NotFoundError);
934
        PyModule_AddObject(m, (char*)"NotFoundError", NotFoundError);
935
        // Tried to create an object with the same name as one that already exists
936
        NameExistsError = PyErr_NewException((char*)"scribus.NameExistsError", ScribusException, NULL);
937
        Py_INCREF(NameExistsError);
938
        PyModule_AddObject(m, (char*)"NameExistsError", NameExistsError);
1384 cbradney 939
        // Tried to run an extension only function with python extensions disabled or from a normal script
940
        AccessDeniedError = PyErr_NewException((char*)"scribus.AccessDeniedError", ScribusException, NULL);
941
        Py_INCREF(AccessDeniedError);
942
        PyModule_AddObject(m, (char*)"AccessDeniedError", AccessDeniedError);
474 subik 943
        // Done with exception setup
944
 
421 Franz 945
        // CONSTANTS
935 subik 946
        PyDict_SetItemString(d, const_cast<char*>("UNIT_POINTS"), Py_BuildValue(const_cast<char*>("i"), 0));
947
        PyDict_SetItemString(d, const_cast<char*>("UNIT_MILLIMETERS"), Py_BuildValue(const_cast<char*>("i"), 1));
948
        PyDict_SetItemString(d, const_cast<char*>("UNIT_INCHES"), Py_BuildValue(const_cast<char*>("i"), 2));
949
        PyDict_SetItemString(d, const_cast<char*>("UNIT_PICAS"), Py_BuildValue(const_cast<char*>("i"), 3));
950
        PyDict_SetItemString(d, const_cast<char*>("PORTRAIT"), Py_BuildValue(const_cast<char*>("i"), 0));
951
        PyDict_SetItemString(d, const_cast<char*>("LANDSCAPE"), Py_BuildValue(const_cast<char*>("i"), 1));
952
        PyDict_SetItemString(d, const_cast<char*>("NOFACINGPAGES"), Py_BuildValue(const_cast<char*>("i"), 0));
953
        PyDict_SetItemString(d, const_cast<char*>("FACINGPAGES"),  Py_BuildValue(const_cast<char*>("i"), 1));
954
        PyDict_SetItemString(d, const_cast<char*>("FIRSTPAGERIGHT"), Py_BuildValue(const_cast<char*>("i"), 0));
955
        PyDict_SetItemString(d, const_cast<char*>("FIRSTPAGELEFT"), Py_BuildValue(const_cast<char*>("i"), 1));
956
        PyDict_SetItemString(d, const_cast<char*>("ALIGN_LEFT"), Py_BuildValue(const_cast<char*>("i"), 0));
957
        PyDict_SetItemString(d, const_cast<char*>("ALIGN_RIGHT"), Py_BuildValue(const_cast<char*>("i"), 2));
958
        PyDict_SetItemString(d, const_cast<char*>("ALIGN_CENTERED"), Py_BuildValue(const_cast<char*>("i"), 1));
959
        PyDict_SetItemString(d, const_cast<char*>("ALIGN_BLOCK"), Py_BuildValue(const_cast<char*>("i"), 4));
960
        PyDict_SetItemString(d, const_cast<char*>("ALIGN_FORCED"), Py_BuildValue(const_cast<char*>("i"), 4));
961
        PyDict_SetItemString(d, const_cast<char*>("FILL_NOG"), Py_BuildValue(const_cast<char*>("i"), 0));
962
        PyDict_SetItemString(d, const_cast<char*>("FILL_HORIZONTALG"), Py_BuildValue(const_cast<char*>("i"), 1));
963
        PyDict_SetItemString(d, const_cast<char*>("FILL_VERTICALG"), Py_BuildValue(const_cast<char*>("i"), 2));
964
        PyDict_SetItemString(d, const_cast<char*>("FILL_DIAGONALG"), Py_BuildValue(const_cast<char*>("i"), 3));
965
        PyDict_SetItemString(d, const_cast<char*>("FILL_CROSSDIAGONALG"), Py_BuildValue(const_cast<char*>("i"), 4));
966
        PyDict_SetItemString(d, const_cast<char*>("FILL_RADIALG"), Py_BuildValue(const_cast<char*>("i"), 5));
967
        PyDict_SetItemString(d, const_cast<char*>("LINE_SOLID"), Py_BuildValue(const_cast<char*>("i"), Qt::SolidLine));
968
        PyDict_SetItemString(d, const_cast<char*>("LINE_DASH"), Py_BuildValue(const_cast<char*>("i"), Qt::DashLine));
969
        PyDict_SetItemString(d, const_cast<char*>("LINE_DOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DotLine));
970
        PyDict_SetItemString(d, const_cast<char*>("LINE_DASHDOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DashDotLine));
971
        PyDict_SetItemString(d, const_cast<char*>("LINE_DASHDOTDOT"), Py_BuildValue(const_cast<char*>("i"), Qt::DashDotDotLine));
972
        PyDict_SetItemString(d, const_cast<char*>("JOIN_MITTER"), Py_BuildValue(const_cast<char*>("i"), Qt::MiterJoin));
973
        PyDict_SetItemString(d, const_cast<char*>("JOIN_BEVEL"), Py_BuildValue(const_cast<char*>("i"), Qt::BevelJoin));
974
        PyDict_SetItemString(d, const_cast<char*>("JOIN_ROUND"), Py_BuildValue(const_cast<char*>("i"), Qt::RoundJoin));
975
        PyDict_SetItemString(d, const_cast<char*>("CAP_FLAT"), Py_BuildValue(const_cast<char*>("i"), Qt::FlatCap));
976
        PyDict_SetItemString(d, const_cast<char*>("CAP_SQUARE"), Py_BuildValue(const_cast<char*>("i"), Qt::SquareCap));
977
        PyDict_SetItemString(d, const_cast<char*>("CAP_ROUND"), Py_BuildValue(const_cast<char*>("i"), Qt::RoundCap));
978
        PyDict_SetItemString(d, const_cast<char*>("BUTTON_NONE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::NoButton));
979
        PyDict_SetItemString(d, const_cast<char*>("BUTTON_OK"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Ok));
980
        PyDict_SetItemString(d, const_cast<char*>("BUTTON_CANCEL"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Cancel));
981
        PyDict_SetItemString(d, const_cast<char*>("BUTTON_YES"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Yes));
982
        PyDict_SetItemString(d, const_cast<char*>("BUTTON_NO"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::No));
983
        PyDict_SetItemString(d, const_cast<char*>("BUTTON_ABORT"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Abort));
984
        PyDict_SetItemString(d, const_cast<char*>("BUTTON_RETRY"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Retry));
985
        PyDict_SetItemString(d, const_cast<char*>("BUTTON_IGNORE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Ignore));
986
        PyDict_SetItemString(d, const_cast<char*>("ICON_NONE"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::NoIcon));
987
        PyDict_SetItemString(d, const_cast<char*>("ICON_INFORMATION"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Information));
988
        PyDict_SetItemString(d, const_cast<char*>("ICON_WARNING"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Warning));
989
        PyDict_SetItemString(d, const_cast<char*>("ICON_CRITICAL"), Py_BuildValue(const_cast<char*>("i"), QMessageBox::Critical));
990
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A0"), Py_BuildValue(const_cast<char*>("(ff)"), 2380.0, 3368.0));
991
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A1"), Py_BuildValue(const_cast<char*>("(ff)"), 1684.0, 2380.0));
992
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A2"), Py_BuildValue(const_cast<char*>("(ff)"), 1190.0, 1684.0));
993
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A3"), Py_BuildValue(const_cast<char*>("(ff)"), 842.0, 1190.0));
994
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A4"), Py_BuildValue(const_cast<char*>("(ff)"), 595.0, 842.0));
995
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A5"), Py_BuildValue(const_cast<char*>("(ff)"), 421.0, 595.0));
996
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A6"), Py_BuildValue(const_cast<char*>("(ff)"), 297.0, 421.0));
997
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A7"), Py_BuildValue(const_cast<char*>("(ff)"), 210.0, 297.0));
998
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A8"), Py_BuildValue(const_cast<char*>("(ff)"), 148.0, 210.0));
999
        PyDict_SetItemString(d, const_cast<char*>("PAPER_A9"), Py_BuildValue(const_cast<char*>("(ff)"), 105.0, 148.0));
1000
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B0"), Py_BuildValue(const_cast<char*>("(ff)"), 2836.0, 4008.0));
1001
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B1"), Py_BuildValue(const_cast<char*>("(ff)"), 2004.0, 2836.0));
1002
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B2"), Py_BuildValue(const_cast<char*>("(ff)"), 1418.0, 2004.0));
1003
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B3"), Py_BuildValue(const_cast<char*>("(ff)"), 1002.0, 1418.0));
1004
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B4"), Py_BuildValue(const_cast<char*>("(ff)"), 709.0, 1002.0));
1005
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B5"), Py_BuildValue(const_cast<char*>("(ff)"), 501.0, 709.0));
1006
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B6"), Py_BuildValue(const_cast<char*>("(ff)"), 355.0, 501.0));
1007
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B7"), Py_BuildValue(const_cast<char*>("(ff)"), 250.0, 355.0));
1008
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B8"), Py_BuildValue(const_cast<char*>("(ff)"), 178.0, 250.0));
1009
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B9"), Py_BuildValue(const_cast<char*>("(ff)"), 125.0, 178.0));
1010
        PyDict_SetItemString(d, const_cast<char*>("PAPER_B10"), Py_BuildValue(const_cast<char*>("(ff)"), 89.0, 125.0));
1011
        PyDict_SetItemString(d, const_cast<char*>("PAPER_C5E"), Py_BuildValue(const_cast<char*>("(ff)"), 462.0, 649.0));
1012
        PyDict_SetItemString(d, const_cast<char*>("PAPER_COMM10E"), Py_BuildValue(const_cast<char*>("(ff)"), 298.0, 683.0));
1013
        PyDict_SetItemString(d, const_cast<char*>("PAPER_DLE"),  Py_BuildValue(const_cast<char*>("(ff)"), 312.0, 624.0));
1014
        PyDict_SetItemString(d, const_cast<char*>("PAPER_EXECUTIVE"), Py_BuildValue(const_cast<char*>("(ff)"), 542.0, 720.0));
1015
        PyDict_SetItemString(d, const_cast<char*>("PAPER_FOLIO"), Py_BuildValue(const_cast<char*>("(ff)"), 595.0, 935.0));
1016
        PyDict_SetItemString(d, const_cast<char*>("PAPER_LEDGER"), Py_BuildValue(const_cast<char*>("(ff)"), 1224.0, 792.0));
1017
        PyDict_SetItemString(d, const_cast<char*>("PAPER_LEGAL"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 1008.0));
1018
        PyDict_SetItemString(d, const_cast<char*>("PAPER_LETTER"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 792.0));
1019
        PyDict_SetItemString(d, const_cast<char*>("PAPER_TABLOID"), Py_BuildValue(const_cast<char*>("(ff)"), 792.0, 1224.0));
732 subik 1020
 
1042 subik 1021
        // Export the Scribus version into the module namespace so scripts know what they're running in
1022
        PyDict_SetItemString(d, const_cast<char*>("scribus_version"), PyString_FromString(const_cast<char*>(VERSION)));
1023
        // Now build a version tuple like that provided by Python in sys.version_info
1024
        // The tuple is of the form (major, minor, patchlevel, extraversion, reserved)
1025
        QRegExp version_re("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
1026
        int pos = version_re.search(QString(VERSION));
1027
        // We ignore errors, causing the scribus_version_info attribute to simply not be created.
1028
        // This will make acceses raise AttrbuteError.
1029
        if (pos > -1)
1030
        {
1031
                int majorVersion = version_re.cap(1).toInt();
1032
                int minorVersion = version_re.cap(2).toInt();
1033
                int patchVersion = version_re.cap(3).toInt();
1034
                QString extraVersion = version_re.cap(4);
1035
                PyObject* versionTuple = Py_BuildValue(const_cast<char*>("(iiisi)"),\
1036
                                majorVersion, minorVersion, patchVersion, (const char*)extraVersion.utf8(), 0);
1037
                if (versionTuple != NULL)
1038
                                PyDict_SetItemString(d, const_cast<char*>("scribus_version_info"), versionTuple);
1039
                else
1040
                                qDebug("Failed to build version tuple for version string '%s' in scripter", VERSION);
1041
        }
1042
        else
1043
                        qDebug("Couldn't parse version string '%s' in scripter", VERSION);
1044
 
1384 cbradney 1045
        // Push some build defines into the scribus module so scripts can see them.
1046
        PyDict_SetItemString(d, const_cast<char*>("LIBDIR"),
1047
                PyString_FromString(const_cast<char*>(LIBDIR)));
1048
        PyDict_SetItemString(d, const_cast<char*>("SAMPLESDIR"),
1049
                PyString_FromString(const_cast<char*>(SAMPLESDIR)));
1050
        PyDict_SetItemString(d, const_cast<char*>("SCRIPTSDIR"),
1051
                PyString_FromString(const_cast<char*>(SCRIPTSDIR)));
1052
        PyDict_SetItemString(d, const_cast<char*>("ICONDIR"),
1053
                PyString_FromString(const_cast<char*>(ICONDIR)));
1054
        PyDict_SetItemString(d, const_cast<char*>("DOCDIR"),
1055
                PyString_FromString(const_cast<char*>(DOCDIR)));
1056
        PyDict_SetItemString(d, const_cast<char*>("TEMPLATEDIR"),
1057
                PyString_FromString(const_cast<char*>(TEMPLATEDIR)));
1058
        PyDict_SetItemString(d, const_cast<char*>("PLUGINDIR"),
1059
                PyString_FromString(const_cast<char*>(PLUGINDIR)));
1060
 
82 Franz 1061
        Carrier = pl;
551 fschmid 1062
        // Function aliases for compatibility
1063
        // We need to import the __builtins__, warnings and exceptions modules to be able to run
1064
        // the generated Python functions from inside the `scribus' module's context.
1065
        // This code makes it possible to extend the `scribus' module by running Python code
1066
        // from C in other ways too.
935 subik 1067
        PyObject* builtinModule = PyImport_ImportModuleEx(const_cast<char*>("__builtin__"),
1068
                        d, d, Py_BuildValue(const_cast<char*>("[]")));
551 fschmid 1069
        if (builtinModule == NULL)
1070
        {
1071
                qDebug("Failed to import __builtin__ module. Something is probably broken with your Python.");
1072
                return;
1073
        }
935 subik 1074
        PyDict_SetItemString(d, const_cast<char*>("__builtin__"), builtinModule);
1075
        PyObject* exceptionsModule = PyImport_ImportModuleEx(const_cast<char*>("exceptions"),
1076
                        d, d, Py_BuildValue(const_cast<char*>("[]")));
551 fschmid 1077
        if (exceptionsModule == NULL)
1078
        {
1079
                qDebug("Failed to import exceptions module. Something is probably broken with your Python.");
1080
                return;
1081
        }
935 subik 1082
        PyDict_SetItemString(d, const_cast<char*>("exceptions"), exceptionsModule);
1083
        PyObject* warningsModule = PyImport_ImportModuleEx(const_cast<char*>("warnings"),
1084
                        d, d, Py_BuildValue(const_cast<char*>("[]")));
551 fschmid 1085
        if (warningsModule == NULL)
1086
        {
1087
                qDebug("Failed to import warnings module. Something is probably broken with your Python.");
1088
                return;
1089
        }
935 subik 1090
        PyDict_SetItemString(d, const_cast<char*>("warnings"), warningsModule);
551 fschmid 1091
        // Now actually add the aliases
1384 cbradney 1092
        if (Tes->legacyAliases)
1093
        {
1094
                deprecatedFunctionAlias(d, const_cast<char*>("changeColor"), const_cast<char*>("ChangeColor"));
1095
                deprecatedFunctionAlias(d, const_cast<char*>("closeDoc"), const_cast<char*>("CloseDoc"));
1096
                deprecatedFunctionAlias(d, const_cast<char*>("createBezierLine"), const_cast<char*>("CreateBezierLine"));
1097
                deprecatedFunctionAlias(d, const_cast<char*>("createEllipse"), const_cast<char*>("CreateEllipse"));
1098
                deprecatedFunctionAlias(d, const_cast<char*>("createImage"), const_cast<char*>("CreateImage"));
1099
                deprecatedFunctionAlias(d, const_cast<char*>("createLayer"), const_cast<char*>("CreateLayer"));
1100
                deprecatedFunctionAlias(d, const_cast<char*>("createLine"), const_cast<char*>("CreateLine"));
1101
                deprecatedFunctionAlias(d, const_cast<char*>("createPathText"), const_cast<char*>("CreatePathText"));
1102
                deprecatedFunctionAlias(d, const_cast<char*>("createPolygon"), const_cast<char*>("CreatePolygon"));
1103
                deprecatedFunctionAlias(d, const_cast<char*>("createPolyLine"), const_cast<char*>("CreatePolyLine"));
1104
                deprecatedFunctionAlias(d, const_cast<char*>("createRect"), const_cast<char*>("CreateRect"));
1105
                deprecatedFunctionAlias(d, const_cast<char*>("createText"), const_cast<char*>("CreateText"));
1106
                deprecatedFunctionAlias(d, const_cast<char*>("currentPage"), const_cast<char*>("CurrentPage"));
1107
                deprecatedFunctionAlias(d, const_cast<char*>("defineColor"), const_cast<char*>("DefineColor"));
1108
                deprecatedFunctionAlias(d, const_cast<char*>("deleteColor"), const_cast<char*>("DeleteColor"));
1109
                deprecatedFunctionAlias(d, const_cast<char*>("deleteLayer"), const_cast<char*>("DeleteLayer"));
1110
                deprecatedFunctionAlias(d, const_cast<char*>("deleteObject"), const_cast<char*>("DeleteObject"));
1111
                deprecatedFunctionAlias(d, const_cast<char*>("deletePage"), const_cast<char*>("DeletePage"));
1112
                deprecatedFunctionAlias(d, const_cast<char*>("deleteText"), const_cast<char*>("DeleteText"));
1113
                deprecatedFunctionAlias(d, const_cast<char*>("deselectAll"), const_cast<char*>("DeselectAll"));
1114
                deprecatedFunctionAlias(d, const_cast<char*>("docChanged"), const_cast<char*>("DocChanged"));
1115
                deprecatedFunctionAlias(d, const_cast<char*>("fileDialog"), const_cast<char*>("FileDialog"));
1116
                deprecatedFunctionAlias(d, const_cast<char*>("getActiveLayer"), const_cast<char*>("GetActiveLayer"));
1117
                deprecatedFunctionAlias(d, const_cast<char*>("getAllObjects"), const_cast<char*>("GetAllObjects"));
1118
                deprecatedFunctionAlias(d, const_cast<char*>("getAllStyles"), const_cast<char*>("GetAllStyles"));
1119
                deprecatedFunctionAlias(d, const_cast<char*>("getAllText"), const_cast<char*>("GetAllText"));
1120
                deprecatedFunctionAlias(d, const_cast<char*>("getColor"), const_cast<char*>("GetColor"));
1121
                deprecatedFunctionAlias(d, const_cast<char*>("getColorNames"), const_cast<char*>("GetColorNames"));
1122
                deprecatedFunctionAlias(d, const_cast<char*>("getColumnGap"), const_cast<char*>("GetColumnGap"));
1123
                deprecatedFunctionAlias(d, const_cast<char*>("getColumns"), const_cast<char*>("GetColumns"));
1124
                deprecatedFunctionAlias(d, const_cast<char*>("getCornerRadius"), const_cast<char*>("GetCornerRadius"));
1125
                deprecatedFunctionAlias(d, const_cast<char*>("getFillColor"), const_cast<char*>("GetFillColor"));
1126
                deprecatedFunctionAlias(d, const_cast<char*>("getFillShade"), const_cast<char*>("GetFillShade"));
1127
                deprecatedFunctionAlias(d, const_cast<char*>("getFont"), const_cast<char*>("GetFont"));
1128
                deprecatedFunctionAlias(d, const_cast<char*>("getFontNames"), const_cast<char*>("GetFontNames"));
1129
                deprecatedFunctionAlias(d, const_cast<char*>("getFontSize"), const_cast<char*>("GetFontSize"));
1130
                deprecatedFunctionAlias(d, const_cast<char*>("getGuiLanguage"), const_cast<char*>("GetGuiLanguage"));
1131
                deprecatedFunctionAlias(d, const_cast<char*>("getHGuides"), const_cast<char*>("GetHGuides"));
1132
                deprecatedFunctionAlias(d, const_cast<char*>("getImageFile"), const_cast<char*>("GetImageFile"));
1133
                deprecatedFunctionAlias(d, const_cast<char*>("getImageScale"), const_cast<char*>("GetImageScale"));
1134
                deprecatedFunctionAlias(d, const_cast<char*>("getLayers"), const_cast<char*>("GetLayers"));
1135
                deprecatedFunctionAlias(d, const_cast<char*>("getLineCap"), const_cast<char*>("GetLineCap"));
1136
                deprecatedFunctionAlias(d, const_cast<char*>("getLineColor"), const_cast<char*>("GetLineColor"));
1137
                deprecatedFunctionAlias(d, const_cast<char*>("getLineJoin"), const_cast<char*>("GetLineJoin"));
1138
                deprecatedFunctionAlias(d, const_cast<char*>("getLineShade"), const_cast<char*>("GetLineShade"));
1139
                deprecatedFunctionAlias(d, const_cast<char*>("getLineSpacing"), const_cast<char*>("GetLineSpacing"));
1140
                deprecatedFunctionAlias(d, const_cast<char*>("getLineStyle"), const_cast<char*>("GetLineStyle"));
1141
                deprecatedFunctionAlias(d, const_cast<char*>("getLineWidth"), const_cast<char*>("GetLineWidth"));
1142
                deprecatedFunctionAlias(d, const_cast<char*>("getPageItems"), const_cast<char*>("GetPageItems"));
1143
                deprecatedFunctionAlias(d, const_cast<char*>("getPageMargins"), const_cast<char*>("GetPageMargins"));
1144
                deprecatedFunctionAlias(d, const_cast<char*>("getPageSize"), const_cast<char*>("GetPageSize"));
1145
                deprecatedFunctionAlias(d, const_cast<char*>("getPosition"), const_cast<char*>("GetPosition"));
1146
                deprecatedFunctionAlias(d, const_cast<char*>("getRotation"), const_cast<char*>("GetRotation"));
1147
                deprecatedFunctionAlias(d, const_cast<char*>("getSelectedObject"), const_cast<char*>("GetSelectedObject"));
1148
                deprecatedFunctionAlias(d, const_cast<char*>("getSize"), const_cast<char*>("GetSize"));
1149
                deprecatedFunctionAlias(d, const_cast<char*>("getText"), const_cast<char*>("GetText"));
1150
                deprecatedFunctionAlias(d, const_cast<char*>("getTextColor"), const_cast<char*>("GetTextColor"));
1151
                deprecatedFunctionAlias(d, const_cast<char*>("getTextLength"), const_cast<char*>("GetTextLength"));
1152
                deprecatedFunctionAlias(d, const_cast<char*>("getTextShade"), const_cast<char*>("GetTextShade"));
1153
                deprecatedFunctionAlias(d, const_cast<char*>("getUnit"), const_cast<char*>("GetUnit"));
1154
                deprecatedFunctionAlias(d, const_cast<char*>("getVGuides"), const_cast<char*>("GetVGuides"));
1155
                deprecatedFunctionAlias(d, const_cast<char*>("getXFontNames"), const_cast<char*>("GetXFontNames"));
1156
                deprecatedFunctionAlias(d, const_cast<char*>("gotoPage"), const_cast<char*>("GotoPage"));
1157
                deprecatedFunctionAlias(d, const_cast<char*>("groupObjects"), const_cast<char*>("GroupObjects"));
1158
                deprecatedFunctionAlias(d, const_cast<char*>("haveDoc"), const_cast<char*>("HaveDoc"));
1159
                deprecatedFunctionAlias(d, const_cast<char*>("insertText"), const_cast<char*>("InsertText"));
1160
                deprecatedFunctionAlias(d, const_cast<char*>("isLayerPrintable"), const_cast<char*>("IsLayerPrintable"));
1161
                deprecatedFunctionAlias(d, const_cast<char*>("isLayerVisible"), const_cast<char*>("IsLayerVisible"));
1162
                deprecatedFunctionAlias(d, const_cast<char*>("isLocked"), const_cast<char*>("IsLocked"));
1163
                deprecatedFunctionAlias(d, const_cast<char*>("linkTextFrames"), const_cast<char*>("LinkTextFrames"));
1164
                deprecatedFunctionAlias(d, const_cast<char*>("loadImage"), const_cast<char*>("LoadImage"));
1165
                deprecatedFunctionAlias(d, const_cast<char*>("loadStylesFromFile"), const_cast<char*>("LoadStylesFromFile"));
1166
                deprecatedFunctionAlias(d, const_cast<char*>("lockObject"), const_cast<char*>("LockObject"));
1167
                deprecatedFunctionAlias(d, const_cast<char*>("messagebarText"), const_cast<char*>("MessagebarText"));
1168
                deprecatedFunctionAlias(d, const_cast<char*>("messageBox"), const_cast<char*>("MessageBox"));
1169
                deprecatedFunctionAlias(d, const_cast<char*>("moveObject"), const_cast<char*>("MoveObject"));
1170
                deprecatedFunctionAlias(d, const_cast<char*>("moveObjectAbs"), const_cast<char*>("MoveObjectAbs"));
1171
                deprecatedFunctionAlias(d, const_cast<char*>("newDoc"), const_cast<char*>("NewDoc"));
1172
                deprecatedFunctionAlias(d, const_cast<char*>("newDocDialog"), const_cast<char*>("NewDocDialog"));
1173
                deprecatedFunctionAlias(d, const_cast<char*>("newPage"), const_cast<char*>("NewPage"));
1174
                deprecatedFunctionAlias(d, const_cast<char*>("objectExists"), const_cast<char*>("ObjectExists"));
1175
                deprecatedFunctionAlias(d, const_cast<char*>("openDoc"), const_cast<char*>("OpenDoc"));
1176
                deprecatedFunctionAlias(d, const_cast<char*>("pageCount"), const_cast<char*>("PageCount"));
1177
                deprecatedFunctionAlias(d, const_cast<char*>("pageDimension"), const_cast<char*>("PageDimension"));
1178
                deprecatedFunctionAlias(d, const_cast<char*>("progressReset"), const_cast<char*>("ProgressReset"));
1179
                deprecatedFunctionAlias(d, const_cast<char*>("progressSet"), const_cast<char*>("ProgressSet"));
1180
                deprecatedFunctionAlias(d, const_cast<char*>("progressTotal"), const_cast<char*>("ProgressTotal"));
1181
                deprecatedFunctionAlias(d, const_cast<char*>("redrawAll"), const_cast<char*>("RedrawAll"));
1182
                deprecatedFunctionAlias(d, const_cast<char*>("renderFont"), const_cast<char*>("RenderFont"));
1183
                deprecatedFunctionAlias(d, const_cast<char*>("replaceColor"), const_cast<char*>("ReplaceColor"));
1184
                deprecatedFunctionAlias(d, const_cast<char*>("rotateObject"), const_cast<char*>("RotateObject"));
1185
                deprecatedFunctionAlias(d, const_cast<char*>("rotateObjectAbs"), const_cast<char*>("RotateObjectAbs"));
1186
                deprecatedFunctionAlias(d, const_cast<char*>("saveDoc"), const_cast<char*>("SaveDoc"));
1187
                deprecatedFunctionAlias(d, const_cast<char*>("saveDocAs"), const_cast<char*>("SaveDocAs"));
1188
                deprecatedFunctionAlias(d, const_cast<char*>("savePageAsEPS"), const_cast<char*>("SavePageAsEPS"));
1189
                deprecatedFunctionAlias(d, const_cast<char*>("scaleGroup"), const_cast<char*>("ScaleGroup"));
1190
                deprecatedFunctionAlias(d, const_cast<char*>("scaleImage"), const_cast<char*>("ScaleImage"));
1191
                deprecatedFunctionAlias(d, const_cast<char*>("selectionCount"), const_cast<char*>("SelectionCount"));
1192
                deprecatedFunctionAlias(d, const_cast<char*>("selectObject"), const_cast<char*>("SelectObject"));
1193
                deprecatedFunctionAlias(d, const_cast<char*>("selectText"), const_cast<char*>("SelectText"));
1194
                deprecatedFunctionAlias(d, const_cast<char*>("sentToLayer"), const_cast<char*>("SentToLayer"));
1195
                deprecatedFunctionAlias(d, const_cast<char*>("setActiveLayer"), const_cast<char*>("SetActiveLayer"));
1196
                deprecatedFunctionAlias(d, const_cast<char*>("setColumnGap"), const_cast<char*>("SetColumnGap"));
1197
                deprecatedFunctionAlias(d, const_cast<char*>("setColumns"), const_cast<char*>("SetColumns"));
1198
                deprecatedFunctionAlias(d, const_cast<char*>("setCornerRadius"), const_cast<char*>("SetCornerRadius"));
1199
                deprecatedFunctionAlias(d, const_cast<char*>("setCursor"), const_cast<char*>("SetCursor"));
1200
                deprecatedFunctionAlias(d, const_cast<char*>("setDocType"), const_cast<char*>("SetDocType"));
1201
                deprecatedFunctionAlias(d, const_cast<char*>("setFillColor"), const_cast<char*>("SetFillColor"));
1202
                deprecatedFunctionAlias(d, const_cast<char*>("setFillShade"), const_cast<char*>("SetFillShade"));
1203
                deprecatedFunctionAlias(d, const_cast<char*>("setFont"), const_cast<char*>("SetFont"));
1204
                deprecatedFunctionAlias(d, const_cast<char*>("setFontSize"), const_cast<char*>("SetFontSize"));
1205
                deprecatedFunctionAlias(d, const_cast<char*>("setGradientFill"), const_cast<char*>("SetGradientFill"));
1206
                deprecatedFunctionAlias(d, const_cast<char*>("setHGuides"), const_cast<char*>("SetHGuides"));
1207
                deprecatedFunctionAlias(d, const_cast<char*>("setInfo"), const_cast<char*>("SetInfo"));
1208
                deprecatedFunctionAlias(d, const_cast<char*>("setLayerPrintable"), const_cast<char*>("SetLayerPrintable"));
1209
                deprecatedFunctionAlias(d, const_cast<char*>("setLayerVisible"), const_cast<char*>("SetLayerVisible"));
1210
                deprecatedFunctionAlias(d, const_cast<char*>("setLineCap"), const_cast<char*>("SetLineCap"));
1211
                deprecatedFunctionAlias(d, const_cast<char*>("setLineColor"), const_cast<char*>("SetLineColor"));
1212
                deprecatedFunctionAlias(d, const_cast<char*>("setLineJoin"), const_cast<char*>("SetLineJoin"));
1213
                deprecatedFunctionAlias(d, const_cast<char*>("setLineShade"), const_cast<char*>("SetLineShade"));
1214
                deprecatedFunctionAlias(d, const_cast<char*>("setLineSpacing"), const_cast<char*>("SetLineSpacing"));
1215
                deprecatedFunctionAlias(d, const_cast<char*>("setLineStyle"), const_cast<char*>("SetLineStyle"));
1216
                deprecatedFunctionAlias(d, const_cast<char*>("setLineWidth"), const_cast<char*>("SetLineWidth"));
1217
                deprecatedFunctionAlias(d, const_cast<char*>("setMargins"), const_cast<char*>("SetMargins"));
1218
                deprecatedFunctionAlias(d, const_cast<char*>("setMultiLine"), const_cast<char*>("SetMultiLine"));
1219
                deprecatedFunctionAlias(d, const_cast<char*>("setMultiLine"), const_cast<char*>("SetMultiLine"));
1220
                deprecatedFunctionAlias(d, const_cast<char*>("setRedraw"), const_cast<char*>("SetRedraw"));
1221
                deprecatedFunctionAlias(d, const_cast<char*>("setSelectedObject"), const_cast<char*>("SetSelectedObject"));
1222
                deprecatedFunctionAlias(d, const_cast<char*>("setStyle"), const_cast<char*>("SetStyle"));
1223
                deprecatedFunctionAlias(d, const_cast<char*>("setText"), const_cast<char*>("SetText"));
1224
                deprecatedFunctionAlias(d, const_cast<char*>("setTextAlignment"), const_cast<char*>("SetTextAlignment"));
1225
                deprecatedFunctionAlias(d, const_cast<char*>("setTextColor"), const_cast<char*>("SetTextColor"));
1226
                deprecatedFunctionAlias(d, const_cast<char*>("setTextShade"), const_cast<char*>("SetTextShade"));
1227
                deprecatedFunctionAlias(d, const_cast<char*>("setTextStroke"), const_cast<char*>("SetTextStroke"));
1228
                deprecatedFunctionAlias(d, const_cast<char*>("setUnit"), const_cast<char*>("SetUnit"));
1229
                deprecatedFunctionAlias(d, const_cast<char*>("setVGuides"), const_cast<char*>("SetVGuides"));
1230
                deprecatedFunctionAlias(d, const_cast<char*>("sizeObject"), const_cast<char*>("SizeObject"));
1231
                deprecatedFunctionAlias(d, const_cast<char*>("statusMessage"), const_cast<char*>("StatusMessage"));
1232
                deprecatedFunctionAlias(d, const_cast<char*>("textFlowsAroundFrame"), const_cast<char*>("TextFlowsAroundFrame"));
1233
                deprecatedFunctionAlias(d, const_cast<char*>("traceText"), const_cast<char*>("TraceText"));
1234
                deprecatedFunctionAlias(d, const_cast<char*>("unGroupObject"), const_cast<char*>("UnGroupObject"));
1235
                deprecatedFunctionAlias(d, const_cast<char*>("unlinkTextFrames"), const_cast<char*>("UnlinkTextFrames"));
1236
                deprecatedFunctionAlias(d, const_cast<char*>("valueDialog"), const_cast<char*>("ValueDialog"));
1237
        }
551 fschmid 1238
        // end function aliases
736 subik 1239
        // legacy constants - alas, we can't print warnings when these
1240
        // are used.
1384 cbradney 1241
        if (Tes->legacyAliases)
1242
        {
1243
                constantAlias(d, "UNIT_POINTS", "Points");
1244
                constantAlias(d, "UNIT_MILLIMETERS", "Millimeters");
1245
                constantAlias(d, "UNIT_INCHES", "Inches");
1246
                constantAlias(d, "UNIT_PICAS", "Picas");
1247
                constantAlias(d, "PORTRAIT", "Portrait");
1248
                constantAlias(d, "LANDSCAPE", "Landscape");
1249
                constantAlias(d, "NOFACINGPAGES", "NoFacingPages");
1250
                constantAlias(d, "FACINGPAGES", "FacingPages");
1251
                constantAlias(d, "FIRSTPAGERIGHT", "FirstPageRight");
1252
                constantAlias(d, "FIRSTPAGELEFT", "FirstPageLeft");
1253
                constantAlias(d, "ALIGN_LEFT", "LeftAlign");
1254
                constantAlias(d, "ALIGN_RIGHT", "RightAlign");
1255
                constantAlias(d, "ALIGN_CENTERED", "Centered");
1256
                constantAlias(d, "ALIGN_FORCED", "Forced");
1257
                constantAlias(d, "FILL_NOG", "NoGradient");
1258
                constantAlias(d, "FILL_HORIZONTALG", "HorizontalGradient");
1259
                constantAlias(d, "FILL_VERTICALG", "VerticalGradient");
1260
                constantAlias(d, "FILL_DIAGONALG", "DiagonalGradient");
1261
                constantAlias(d, "FILL_CROSSDIAGONALG", "CrossDiagonalGradient");
1262
                constantAlias(d, "FILL_RADIALG", "RadialGradient");
1263
                constantAlias(d, "LINE_SOLID", "SolidLine");
1264
                constantAlias(d, "LINE_DASH", "DashLine");
1265
                constantAlias(d, "LINE_DOT", "DotLine");
1266
                constantAlias(d, "LINE_DASHDOT", "DashDotLine");
1267
                constantAlias(d, "LINE_DASHDOTDOT", "DashDotDotLine");
1268
                constantAlias(d, "JOIN_MITTER", "MiterJoin");
1269
                constantAlias(d, "JOIN_BEVEL", "BevelJoin");
1270
                constantAlias(d, "JOIN_ROUND", "RoundJoin");
1271
                constantAlias(d, "CAP_FLAT", "FlatCap");
1272
                constantAlias(d, "CAP_SQUARE", "SquareCap");
1273
                constantAlias(d, "CAP_ROUND", "RoundCap");
1274
                constantAlias(d, "BUTTON_NONE", "NoButton");
1275
                constantAlias(d, "BUTTON_OK", "Ok");
1276
                constantAlias(d, "BUTTON_CANCEL", "Cancel");
1277
                constantAlias(d, "BUTTON_YES", "Yes");
1278
                constantAlias(d, "BUTTON_NO", "No");
1279
                constantAlias(d, "BUTTON_ABORT", "Abort");
1280
                constantAlias(d, "BUTTON_RETRY", "Retry");
1281
                constantAlias(d, "BUTTON_IGNORE", "Ignore");
1282
                constantAlias(d, "ICON_NONE", "NoIcon");
1283
                constantAlias(d, "ICON_INFORMATION", "Information");
1284
                constantAlias(d, "ICON_WARNING", "Warning");
1285
                constantAlias(d, "ICON_CRITICAL", "Critical");
1286
                constantAlias(d, "PAPER_A0", "Paper_A0");
1287
                constantAlias(d, "PAPER_A1", "Paper_A1");
1288
                constantAlias(d, "PAPER_A2", "Paper_A2");
1289
                constantAlias(d, "PAPER_A3", "Paper_A3");
1290
                constantAlias(d, "PAPER_A4", "Paper_A4");
1291
                constantAlias(d, "PAPER_A5", "Paper_A5");
1292
                constantAlias(d, "PAPER_A6", "Paper_A6");
1293
                constantAlias(d, "PAPER_A7", "Paper_A7");
1294
                constantAlias(d, "PAPER_A8", "Paper_A8");
1295
                constantAlias(d, "PAPER_A9", "Paper_A9");
1296
                constantAlias(d, "PAPER_B0", "Paper_B0");
1297
                constantAlias(d, "PAPER_B1", "Paper_B1");
1298
                constantAlias(d, "PAPER_B2", "Paper_B2");
1299
                constantAlias(d, "PAPER_B3", "Paper_B3");
1300
                constantAlias(d, "PAPER_B4", "Paper_B4");
1301
                constantAlias(d, "PAPER_B5", "Paper_B5");
1302
                constantAlias(d, "PAPER_B6", "Paper_B6");
1303
                constantAlias(d, "PAPER_B7", "Paper_B7");
1304
                constantAlias(d, "PAPER_B8", "Paper_B8");
1305
                constantAlias(d, "PAPER_B9", "Paper_B9");
1306
                constantAlias(d, "PAPER_B10", "Paper_B10");
1307
                constantAlias(d, "PAPER_C5E", "Paper_C5E");
1308
                constantAlias(d, "PAPER_COMM10E", "Paper_Comm10E");
1309
                constantAlias(d, "PAPER_DLE", "Paper_DLE");
1310
                constantAlias(d, "PAPER_EXECUTIVE", "Paper_Executive");
1311
                constantAlias(d, "PAPER_FOLIO", "Paper_Folio");
1312
                constantAlias(d, "PAPER_LEDGER", "Paper_Ledger");
1313
                constantAlias(d, "PAPER_LEGAL", "Paper_Legal");
1314
                constantAlias(d, "PAPER_LETTER", "Paper_Letter");
1315
                constantAlias(d, "PAPER_TABLOID", "Paper_Tabloid");
1316
        }
732 subik 1317
        // end of deprecated cosntants
852 subik 1318
 
1319
        // Create the module-level docstring. This can be a proper unicode string, unlike
1320
        // the others, because we can just create a Unicode object and insert it in our
1321
        // module dictionary.
1322
        QString docstring = QObject::tr("Scribus Python interface module\n\
1344 subik 1323
\n\
1324
This module is the Python interface for Scribus. It provides functions\n\
1325
to control scribus and to manipulate objects on the canvas. Each\n\
1326
function is documented individually below.\n\
1327
\n\
1328
A few things are common across most of the interface.\n\
1329
\n\
1330
Most functions operate on frames. Frames are identified by their name,\n\
1331
a string - they are not real Python objects. Many functions take an\n\
1332
optional (non-keyword) parameter, a frame name.\n\
1333
Many exceptions are also common across most functions. These are\n\
1334
not currently documented in the docstring for each function.\n\
1335
- Many functions will raise a NoDocOpenError if you try to use them\
1336
without a document to operate on.\n\
1337
- If you do not pass a frame name to a function that requires one,\
1338
the function will use the currently selected frame, if any, or\
1339
raise a NoValidObjectError if it can't find anything to operate\
1340
on.\n\
1341
- Many functions will raise WrongFrameTypeError if you try to use them\n\
1342
on a frame type that they do not make sense with. For example, setting\n\
1343
the text colour on a graphics frame doesn't make sense, and will result\n\
1344
in this exception being raised.\n\
1345
- Errors resulting from calls to the underlying Python API will be\n\
1346
passed through unaltered. As such, the list of exceptions thrown by\n\
1347
any function as provided here and in its docstring is incomplete.\n\
1348
\n\
1349
Details of what exceptions each function may throw are provided on the\n\
1350
function's documentation.");
852 subik 1351
 
1352
        // Py_UNICODE is a typedef for unsigned short
935 subik 1353
        PyObject* uniDocStr = Py_BuildValue(const_cast<char*>("u"), (Py_UNICODE*)(docstring.ucs2()));
852 subik 1354
        if (uniDocStr == NULL)
1355
                qDebug("Failed to create module-level docstring object!");
1356
        else
935 subik 1357
                PyDict_SetItemString(d, const_cast<char*>("__doc__"), uniDocStr);
852 subik 1358
        Py_DECREF(uniDocStr);
82 Franz 1359
}
1360