From 7ed83b6c6666eb8b6b104c211ae7e52907350372 Mon Sep 17 00:00:00 2001 From: craig Date: Sun, 1 Jan 2012 11:40:09 +0000 Subject: Branch 1.3.5 tree to 1.4.x tree, goodbye 1.3.x git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17163 11d20701-8431-0410-a711-e3c959e3b870 --- scribus/plugins/scriptplugin/CMakeLists.txt | 73 + scribus/plugins/scriptplugin/README.BOOST | 50 + scribus/plugins/scriptplugin/cmdcolor.cpp | 285 ++++ scribus/plugins/scriptplugin/cmdcolor.h | 140 ++ scribus/plugins/scriptplugin/cmddialog.cpp | 145 ++ scribus/plugins/scriptplugin/cmddialog.h | 115 ++ scribus/plugins/scriptplugin/cmddoc.cpp | 377 +++++ scribus/plugins/scriptplugin/cmddoc.h | 270 ++++ scribus/plugins/scriptplugin/cmdgetprop.cpp | 345 +++++ scribus/plugins/scriptplugin/cmdgetprop.h | 223 +++ scribus/plugins/scriptplugin/cmdgetsetprop.cpp | 499 +++++++ scribus/plugins/scriptplugin/cmdgetsetprop.h | 206 +++ scribus/plugins/scriptplugin/cmdmani.cpp | 492 ++++++ scribus/plugins/scriptplugin/cmdmani.h | 231 +++ scribus/plugins/scriptplugin/cmdmisc.cpp | 793 ++++++++++ scribus/plugins/scriptplugin/cmdmisc.h | 353 +++++ scribus/plugins/scriptplugin/cmdobj.cpp | 703 +++++++++ scribus/plugins/scriptplugin/cmdobj.h | 263 ++++ scribus/plugins/scriptplugin/cmdpage.cpp | 517 +++++++ scribus/plugins/scriptplugin/cmdpage.h | 228 +++ scribus/plugins/scriptplugin/cmdsetprop.cpp | 398 +++++ scribus/plugins/scriptplugin/cmdsetprop.h | 197 +++ scribus/plugins/scriptplugin/cmdstyle.cpp | 177 +++ scribus/plugins/scriptplugin/cmdstyle.h | 86 ++ scribus/plugins/scriptplugin/cmdtext.cpp | 1109 ++++++++++++++ scribus/plugins/scriptplugin/cmdtext.h | 430 ++++++ scribus/plugins/scriptplugin/cmdutil.cpp | 231 +++ scribus/plugins/scriptplugin/cmdutil.h | 71 + scribus/plugins/scriptplugin/cmdvar.h | 81 + scribus/plugins/scriptplugin/guiapp.cpp | 141 ++ scribus/plugins/scriptplugin/guiapp.h | 113 ++ scribus/plugins/scriptplugin/objimageexport.cpp | 259 ++++ scribus/plugins/scriptplugin/objimageexport.h | 46 + scribus/plugins/scriptplugin/objpdffile.cpp | 1251 ++++++++++++++++ scribus/plugins/scriptplugin/objpdffile.h | 31 + scribus/plugins/scriptplugin/objprinter.cpp | 613 ++++++++ scribus/plugins/scriptplugin/objprinter.h | 28 + scribus/plugins/scriptplugin/pconsole.cpp | 397 +++++ scribus/plugins/scriptplugin/pconsole.h | 141 ++ scribus/plugins/scriptplugin/pconsole.ui | 129 ++ scribus/plugins/scriptplugin/runscriptdialog.cpp | 57 + scribus/plugins/scriptplugin/runscriptdialog.h | 42 + scribus/plugins/scriptplugin/runscriptdialog.ui | 81 + scribus/plugins/scriptplugin/samples/3columnA4.py | 53 + .../plugins/scriptplugin/samples/3columnUSLTR.py | 51 + .../plugins/scriptplugin/samples/CMakeLists.txt | 22 + scribus/plugins/scriptplugin/samples/Calender.py | 75 + .../plugins/scriptplugin/samples/ExtractText.py | 81 + scribus/plugins/scriptplugin/samples/ReadMe | 22 + scribus/plugins/scriptplugin/samples/Sample1.py | 26 + .../plugins/scriptplugin/samples/boilerplate.py | 51 + .../plugins/scriptplugin/samples/golden-mean.py | 75 + scribus/plugins/scriptplugin/samples/legende.py | 39 + .../samples/moins_10_pourcent_group.py | 17 + .../scriptplugin/samples/plus_10_pourcent_group.py | 17 + .../plugins/scriptplugin/samples/pochette_cd.py | 117 ++ scribus/plugins/scriptplugin/samples/quote.py | 75 + .../scriptplugin/samples/sample_db_usage.py | 90 ++ .../plugins/scriptplugin/samples/trait_de_coupe.py | 42 + scribus/plugins/scriptplugin/samples/wordcount.py | 65 + .../scriptplugin/scripter2/scripter2_base.cpp | 85 ++ .../scripter2/scripter2_qtclass_qapplication.cpp | 37 + .../scripter2/scripter2_qtclass_qframe.cpp | 20 + .../scripter2/scripter2_qtclass_qmainwindow.cpp | 20 + .../scripter2/scripter2_qtclass_qobject.cpp | 22 + .../scripter2/scripter2_qtclass_qscrollview.cpp | 21 + .../scripter2/scripter2_qtclass_qwidget.cpp | 24 + .../scripter2/scripter2_qttype_qstring.cpp | 124 ++ .../scripter2/scripter2_scribus_pageitem.cpp | 302 ++++ .../scripter2/scripter2_scribus_scribusdoc.cpp | 36 + .../scripter2/scripter2_scribus_scribusmainwin.cpp | 29 + .../scripter2/scripter2_scribus_scribusqapp.cpp | 29 + .../scripter2/scripter2_scribus_scribusview.cpp | 20 + .../scripter2/scripter2_scribus_scribuswin.cpp | 18 + .../scripter2/scripter2_scribusstructs.cpp | 67 + .../scriptplugin/scripter2/scripter2_styles.cpp | 113 ++ scribus/plugins/scriptplugin/scriptercore.cpp | 627 ++++++++ scribus/plugins/scriptplugin/scriptercore.h | 89 ++ scribus/plugins/scriptplugin/scripterprefsgui.cpp | 151 ++ scribus/plugins/scriptplugin/scripterprefsgui.h | 47 + scribus/plugins/scriptplugin/scripterprefsgui.ui | 259 ++++ scribus/plugins/scriptplugin/scriptplugin.cpp | 828 ++++++++++ scribus/plugins/scriptplugin/scriptplugin.h | 50 + scribus/plugins/scriptplugin/scripts/Autoquote.py | 167 +++ .../plugins/scriptplugin/scripts/CMakeLists.txt | 20 + .../plugins/scriptplugin/scripts/CalendarWizard.py | 670 +++++++++ scribus/plugins/scriptplugin/scripts/ChangeLog | 181 +++ scribus/plugins/scriptplugin/scripts/ColorChart.py | 350 +++++ .../scriptplugin/scripts/DirectImageImport.py | 94 ++ scribus/plugins/scriptplugin/scripts/FontSample.py | 1578 ++++++++++++++++++++ scribus/plugins/scriptplugin/scripts/InfoBox.py | 163 ++ scribus/plugins/scriptplugin/scripts/NEWS | 40 + scribus/plugins/scriptplugin/scripts/ReadMe | 1 + scribus/plugins/scriptplugin/scripts/TODO | 13 + scribus/plugins/scriptplugin/scripts/color2csv.py | 160 ++ scribus/plugins/scriptplugin/scripts/csv2color.py | 187 +++ .../scriptplugin/scripts/importcsv2table.py | 208 +++ scribus/plugins/scriptplugin/svgimport.cpp | 172 +++ scribus/plugins/scriptplugin/svgimport.h | 61 + 99 files changed, 20418 insertions(+) create mode 100644 scribus/plugins/scriptplugin/CMakeLists.txt create mode 100644 scribus/plugins/scriptplugin/README.BOOST create mode 100644 scribus/plugins/scriptplugin/cmdcolor.cpp create mode 100644 scribus/plugins/scriptplugin/cmdcolor.h create mode 100644 scribus/plugins/scriptplugin/cmddialog.cpp create mode 100644 scribus/plugins/scriptplugin/cmddialog.h create mode 100644 scribus/plugins/scriptplugin/cmddoc.cpp create mode 100644 scribus/plugins/scriptplugin/cmddoc.h create mode 100644 scribus/plugins/scriptplugin/cmdgetprop.cpp create mode 100644 scribus/plugins/scriptplugin/cmdgetprop.h create mode 100644 scribus/plugins/scriptplugin/cmdgetsetprop.cpp create mode 100644 scribus/plugins/scriptplugin/cmdgetsetprop.h create mode 100644 scribus/plugins/scriptplugin/cmdmani.cpp create mode 100644 scribus/plugins/scriptplugin/cmdmani.h create mode 100644 scribus/plugins/scriptplugin/cmdmisc.cpp create mode 100644 scribus/plugins/scriptplugin/cmdmisc.h create mode 100644 scribus/plugins/scriptplugin/cmdobj.cpp create mode 100644 scribus/plugins/scriptplugin/cmdobj.h create mode 100644 scribus/plugins/scriptplugin/cmdpage.cpp create mode 100644 scribus/plugins/scriptplugin/cmdpage.h create mode 100644 scribus/plugins/scriptplugin/cmdsetprop.cpp create mode 100644 scribus/plugins/scriptplugin/cmdsetprop.h create mode 100644 scribus/plugins/scriptplugin/cmdstyle.cpp create mode 100644 scribus/plugins/scriptplugin/cmdstyle.h create mode 100644 scribus/plugins/scriptplugin/cmdtext.cpp create mode 100644 scribus/plugins/scriptplugin/cmdtext.h create mode 100644 scribus/plugins/scriptplugin/cmdutil.cpp create mode 100644 scribus/plugins/scriptplugin/cmdutil.h create mode 100644 scribus/plugins/scriptplugin/cmdvar.h create mode 100644 scribus/plugins/scriptplugin/guiapp.cpp create mode 100644 scribus/plugins/scriptplugin/guiapp.h create mode 100644 scribus/plugins/scriptplugin/objimageexport.cpp create mode 100644 scribus/plugins/scriptplugin/objimageexport.h create mode 100644 scribus/plugins/scriptplugin/objpdffile.cpp create mode 100644 scribus/plugins/scriptplugin/objpdffile.h create mode 100644 scribus/plugins/scriptplugin/objprinter.cpp create mode 100644 scribus/plugins/scriptplugin/objprinter.h create mode 100644 scribus/plugins/scriptplugin/pconsole.cpp create mode 100644 scribus/plugins/scriptplugin/pconsole.h create mode 100644 scribus/plugins/scriptplugin/pconsole.ui create mode 100644 scribus/plugins/scriptplugin/runscriptdialog.cpp create mode 100644 scribus/plugins/scriptplugin/runscriptdialog.h create mode 100644 scribus/plugins/scriptplugin/runscriptdialog.ui create mode 100644 scribus/plugins/scriptplugin/samples/3columnA4.py create mode 100644 scribus/plugins/scriptplugin/samples/3columnUSLTR.py create mode 100644 scribus/plugins/scriptplugin/samples/CMakeLists.txt create mode 100644 scribus/plugins/scriptplugin/samples/Calender.py create mode 100644 scribus/plugins/scriptplugin/samples/ExtractText.py create mode 100644 scribus/plugins/scriptplugin/samples/ReadMe create mode 100644 scribus/plugins/scriptplugin/samples/Sample1.py create mode 100644 scribus/plugins/scriptplugin/samples/boilerplate.py create mode 100644 scribus/plugins/scriptplugin/samples/golden-mean.py create mode 100644 scribus/plugins/scriptplugin/samples/legende.py create mode 100644 scribus/plugins/scriptplugin/samples/moins_10_pourcent_group.py create mode 100644 scribus/plugins/scriptplugin/samples/plus_10_pourcent_group.py create mode 100644 scribus/plugins/scriptplugin/samples/pochette_cd.py create mode 100644 scribus/plugins/scriptplugin/samples/quote.py create mode 100644 scribus/plugins/scriptplugin/samples/sample_db_usage.py create mode 100644 scribus/plugins/scriptplugin/samples/trait_de_coupe.py create mode 100644 scribus/plugins/scriptplugin/samples/wordcount.py create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_base.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qapplication.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qframe.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qmainwindow.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qobject.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qscrollview.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qwidget.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_qttype_qstring.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_scribus_pageitem.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusdoc.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusmainwin.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusqapp.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusview.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribuswin.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_scribusstructs.cpp create mode 100644 scribus/plugins/scriptplugin/scripter2/scripter2_styles.cpp create mode 100644 scribus/plugins/scriptplugin/scriptercore.cpp create mode 100644 scribus/plugins/scriptplugin/scriptercore.h create mode 100644 scribus/plugins/scriptplugin/scripterprefsgui.cpp create mode 100644 scribus/plugins/scriptplugin/scripterprefsgui.h create mode 100644 scribus/plugins/scriptplugin/scripterprefsgui.ui create mode 100644 scribus/plugins/scriptplugin/scriptplugin.cpp create mode 100644 scribus/plugins/scriptplugin/scriptplugin.h create mode 100644 scribus/plugins/scriptplugin/scripts/Autoquote.py create mode 100644 scribus/plugins/scriptplugin/scripts/CMakeLists.txt create mode 100644 scribus/plugins/scriptplugin/scripts/CalendarWizard.py create mode 100644 scribus/plugins/scriptplugin/scripts/ChangeLog create mode 100644 scribus/plugins/scriptplugin/scripts/ColorChart.py create mode 100644 scribus/plugins/scriptplugin/scripts/DirectImageImport.py create mode 100644 scribus/plugins/scriptplugin/scripts/FontSample.py create mode 100644 scribus/plugins/scriptplugin/scripts/InfoBox.py create mode 100644 scribus/plugins/scriptplugin/scripts/NEWS create mode 100644 scribus/plugins/scriptplugin/scripts/ReadMe create mode 100644 scribus/plugins/scriptplugin/scripts/TODO create mode 100644 scribus/plugins/scriptplugin/scripts/color2csv.py create mode 100644 scribus/plugins/scriptplugin/scripts/csv2color.py create mode 100644 scribus/plugins/scriptplugin/scripts/importcsv2table.py create mode 100644 scribus/plugins/scriptplugin/svgimport.cpp create mode 100644 scribus/plugins/scriptplugin/svgimport.h (limited to 'scribus/plugins/scriptplugin') diff --git a/scribus/plugins/scriptplugin/CMakeLists.txt b/scribus/plugins/scriptplugin/CMakeLists.txt new file mode 100644 index 0000000..6ed7b4d --- /dev/null +++ b/scribus/plugins/scriptplugin/CMakeLists.txt @@ -0,0 +1,73 @@ +INCLUDE_DIRECTORIES( +${CMAKE_SOURCE_DIR} +${CMAKE_SOURCE_DIR}/scribus +) + +ADD_SUBDIRECTORY(samples) +ADD_SUBDIRECTORY(scripts) + +SET(SCRIPTER_PLUGIN_UI_SRC + pconsole.ui + runscriptdialog.ui + scripterprefsgui.ui +) + +SET(SCRIPTER_PLUGIN_MOC_CLASSES + pconsole.h + scriptplugin.h + scriptercore.h + scripterprefsgui.h + runscriptdialog.h +) + +SET(SCRIPTER_PLUGIN_SOURCES + cmdcolor.cpp + cmddialog.cpp + cmddoc.cpp + cmdgetprop.cpp + cmdgetsetprop.cpp + cmdmani.cpp + cmdmisc.cpp + cmdobj.cpp + cmdpage.cpp + cmdsetprop.cpp + cmdstyle.cpp + cmdtext.cpp + cmdutil.cpp + guiapp.cpp + objimageexport.cpp + objpdffile.cpp + objprinter.cpp + pconsole.cpp + runscriptdialog.cpp + scriptercore.cpp + scripterprefsgui.cpp + scriptplugin.cpp + svgimport.cpp +) + +SET(SCRIBUS_SCRIPTER_PLUGIN "scriptplugin") + +QT4_WRAP_UI(SCRIPTER_PLUGIN_UI_SOURCES ${SCRIPTER_PLUGIN_UI_SRC} ) +QT4_WRAP_CPP(SCRIPTER_PLUGIN_MOC_SOURCES ${SCRIPTER_PLUGIN_MOC_CLASSES}) + +ADD_LIBRARY(${SCRIBUS_SCRIPTER_PLUGIN} MODULE + ${SCRIPTER_PLUGIN_SOURCES} + ${SCRIPTER_PLUGIN_MOC_SOURCES} + ${SCRIPTER_PLUGIN_UI_SOURCES}) + +TARGET_LINK_LIBRARIES(${SCRIBUS_SCRIPTER_PLUGIN} + ${PYTHON_LIBRARIES} +) + +TARGET_LINK_LIBRARIES(${SCRIBUS_SCRIPTER_PLUGIN} ${PLUGIN_LIBRARIES}) + +INSTALL(TARGETS ${SCRIBUS_SCRIPTER_PLUGIN} + LIBRARY + DESTINATION ${PLUGINDIR} + PERMISSIONS ${PLUGIN_PERMISSIONS} +) + +ADD_DEPENDENCIES(${SCRIBUS_SCRIPTER_PLUGIN} ${EXE_NAME}) + +# SET_TARGET_PROPERTIES(${SCRIBUS_SCRIPTER_PLUGIN} PROPERTIES VERSION "0.0.0") diff --git a/scribus/plugins/scriptplugin/README.BOOST b/scribus/plugins/scriptplugin/README.BOOST new file mode 100644 index 0000000..281c4a9 --- /dev/null +++ b/scribus/plugins/scriptplugin/README.BOOST @@ -0,0 +1,50 @@ +Experimental support for the use of Boost::Python has been added to the Python +interface. All Boost code is exported in a separate module, scribus2, that is +only created if Boost::Python is available. + +Currently there's no autotools support for this in Scribus, so to compile the +scripter with this highly experimental feature you must: + +$ make clean +$ make CXXFLAGS=" -Wno-extra -Wno-unused -DHAVE_BOOST_PYTHON -fexceptions " LDFLAGS=" -lboost_python " +$ make install + +For more information on Boost::Python see: + http://www.boost.org/libs/python/doc/ + http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/libs/python/doc/tutorial/ + +It's strongly recommended that you read the FAQ at: + http://www.boost.org/libs/python/doc/v2/faq.html +(probably once before reading the code, and again after). + +All the fun stuff is in the `scribus2' module and is used for manipulating +paragraph styles. There are currently two (dirty hack) interfaces. One is a +"value based" interface - ask for a /copy of/ a style, add a style by /copying/ +it into the style list, etc. The other interface is reference based - get a +dict of references to the existing styles and modify them directly. Soon, +hopefully, add and remove styles from the dict as if it was a Python one too. +The value based interface is safer but clumsier; the reference based one +can be a tad dangerous but is very handy. + +Examples: + +>>> import scribus2 +>>> p = scribus2.ParagraphStyle() +>>> p.Vname = "testing" +>>> scribus2.addStyle(p) +>>> scribus2.getStyleNames() +[ blah, blah, blah , "testing" ] +>>> scribus2.getStylesRef()['testing'].Vname = "newname" +>>> scribus2.getStyleNames() +[ blah, blah, blah, "newname"] +>>> ref = scribus2.getStyleRef("newname") +>>> ref.Vname = "renamed" +>>> scribus2.getStyleNames() +[ blah, blah, blah, "renamed"] +>>> val = scribus2.getStyleVal("renamed") +>>> val.Vname = "doesnothing" +>>> scribus2.getStyleNames() +[ blah, blah, blah, "renamed"] +>>> scribus2.addStyle(val) +>>> scribus2.getStyleNames() +[ blah, blah, blah, "renamed", "doesnothing"] diff --git a/scribus/plugins/scriptplugin/cmdcolor.cpp b/scribus/plugins/scriptplugin/cmdcolor.cpp new file mode 100644 index 0000000..485ca5d --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdcolor.cpp @@ -0,0 +1,285 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmdcolor.h" +#include "cmdutil.h" +#include "prefsmanager.h" +#include "commonstrings.h" +#include "scribuscore.h" +#include "sccolorengine.h" + +PyObject *scribus_colornames(PyObject* /* self */) +{ + ColorList edc; + PyObject *l; + int cc = 0; + edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet(); + ColorList::Iterator it; + l = PyList_New(edc.count()); + for (it = edc.begin(); it != edc.end(); ++it) + { + PyList_SetItem(l, cc, PyString_FromString(it.key().toUtf8())); + cc++; + } + return l; +} + +PyObject *scribus_getcolor(PyObject* /* self */, PyObject* args) +{ + ColorList edc; + char *Name = const_cast(""); + int c, m, y, k; + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if (strcmp(Name, "") == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot get a color with an empty name.","python error").toLocal8Bit().constData()); + return NULL; + } + edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet(); + ScribusDoc* currentDoc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc : NULL; + QString col = QString::fromUtf8(Name); + if (!edc.contains(col)) + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error").toLocal8Bit().constData()); + return NULL; + } + CMYKColor cmykValues; + ScColorEngine::getCMYKValues(edc[col], currentDoc, cmykValues); + cmykValues.getValues(c, m, y, k); + return Py_BuildValue("(iiii)", static_cast(c), static_cast(m), static_cast(y), static_cast(k)); +} + +PyObject *scribus_getcolorasrgb(PyObject* /* self */, PyObject* args) +{ + ColorList edc; + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if (strcmp(Name, "") == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot get a color with an empty name.","python error").toLocal8Bit().constData()); + return NULL; + } + edc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc->PageColors : PrefsManager::instance()->colorSet(); + ScribusDoc* currentDoc = ScCore->primaryMainWindow()->HaveDoc ? ScCore->primaryMainWindow()->doc : NULL; + QString col = QString::fromUtf8(Name); + if (!edc.contains(col)) + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error").toLocal8Bit().constData()); + return NULL; + } + QColor rgb = ScColorEngine::getRGBColor(edc[col], currentDoc); + return Py_BuildValue("(iii)", static_cast(rgb.red()), static_cast(rgb.green()), static_cast(rgb.blue())); +} + +PyObject *scribus_setcolor(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int c, m, y, k; + if (!PyArg_ParseTuple(args, "esiiii", "utf-8", &Name, &c, &m, &y, &k)) + return NULL; + if (strcmp(Name, "") == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot change a color with an empty name.","python error").toLocal8Bit().constData()); + return NULL; + } + QString col = QString::fromUtf8(Name); + if (ScCore->primaryMainWindow()->HaveDoc) + { + if (!ScCore->primaryMainWindow()->doc->PageColors.contains(col)) + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found in document.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->doc->PageColors[col].setColor(c, m, y, k); + } + else + { + ColorList* colorList=PrefsManager::instance()->colorSetPtr(); + if (!colorList->contains(col)) + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found in default colors.","python error").toLocal8Bit().constData()); + return NULL; + } + (*colorList)[col].setColor(c, m, y, k); + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_newcolor(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int c, m, y, k; + if (!PyArg_ParseTuple(args, "esiiii", "utf-8", &Name, &c, &m, &y, &k)) + return NULL; + if (strcmp(Name, "") == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot create a color with an empty name.","python error").toLocal8Bit().constData()); + return NULL; + } + QString col = QString::fromUtf8(Name); + if (ScCore->primaryMainWindow()->HaveDoc) + { + if (!ScCore->primaryMainWindow()->doc->PageColors.contains(col)) + ScCore->primaryMainWindow()->doc->PageColors.insert(col, ScColor(c, m, y, k)); + else + // FIXME: Given that we have a changeColour function, should we really be + // silently changing colours in newColour? + ScCore->primaryMainWindow()->doc->PageColors[col].setColor(c, m, y, k); + } + else + { + ColorList* colorList=PrefsManager::instance()->colorSetPtr(); + if (!colorList->contains(col)) + colorList->insert(col, ScColor(c, m, y, k)); + else + // FIXME: Given that we have a changeColour function, should we really be + // silently changing colours in newColour? + (*colorList)[col].setColor(c, m, y, k); + } + // Py_INCREF(Py_None); + // return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_delcolor(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Repl = const_cast(CommonStrings::None.toLatin1().constData()); + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Name, "utf-8", &Repl)) + return NULL; + if (strcmp(Name, "") == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot delete a color with an empty name.","python error").toLocal8Bit().constData()); + return NULL; + } + QString col = QString::fromUtf8(Name); + QString rep = QString::fromUtf8(Repl); + if (ScCore->primaryMainWindow()->HaveDoc) + { + if (ScCore->primaryMainWindow()->doc->PageColors.contains(col) && (ScCore->primaryMainWindow()->doc->PageColors.contains(rep) || (rep == CommonStrings::None))) + { + ScCore->primaryMainWindow()->doc->PageColors.remove(col); + ReplaceColor(col, rep); + } + else + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found in document.","python error").toLocal8Bit().constData()); + return NULL; + } + } + else + { + ColorList* colorList=PrefsManager::instance()->colorSetPtr(); + if (colorList->contains(col)) + colorList->remove(col); + else + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found in default colors.","python error").toLocal8Bit().constData()); + return NULL; + } + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_replcolor(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Repl = const_cast(CommonStrings::None.toLatin1().constData()); + //FIXME: this should definitely use keyword arguments + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Name, "utf-8", &Repl)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (strcmp(Name, "") == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot replace a color with an empty name.","python error").toLocal8Bit().constData()); + return NULL; + } + QString col = QString::fromUtf8(Name); + QString rep = QString::fromUtf8(Repl); + if (ScCore->primaryMainWindow()->doc->PageColors.contains(col) && (ScCore->primaryMainWindow()->doc->PageColors.contains(rep) || (rep == CommonStrings::None))) + ReplaceColor(col, rep); + else + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_isspotcolor(PyObject * /*self*/, PyObject* args) +{ + char *Name = const_cast(""); + + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (strcmp(Name, "") == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Color name cannot be an empty string.","python error").toLocal8Bit().constData()); + return NULL; + } + QString col = QString::fromUtf8(Name); + if (ScCore->primaryMainWindow()->doc->PageColors.contains(col)) + { + return PyBool_FromLong(static_cast(ScCore->primaryMainWindow()->doc->PageColors[col].isSpotColor())); + } + else + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_RETURN_NONE; +} + +PyObject *scribus_setspotcolor(PyObject * /*self*/, PyObject* args) +{ + char *Name = const_cast(""); + int enable; + + if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &enable)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (strcmp(Name, "") == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Color name cannot be an empty string.","python error").toLocal8Bit().constData()); + return NULL; + } + QString col = QString::fromUtf8(Name); + if (ScCore->primaryMainWindow()->doc->PageColors.contains(col)) + { + ScCore->primaryMainWindow()->doc->PageColors[col].setSpotColor(static_cast(enable)); + } + else + { + PyErr_SetString(NotFoundError, QObject::tr("Color not found.","python error").toLocal8Bit().constData()); + return NULL; + } + Py_RETURN_NONE; +} + + + +/*! HACK: this removes "warning: 'blash' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmdcolordocswarnings() +{ + QStringList s; + s << scribus_colornames__doc__ << scribus_getcolor__doc__ << scribus_getcolorasrgb__doc__; + s << scribus_setcolor__doc__ << scribus_newcolor__doc__ << scribus_delcolor__doc__; + s << scribus_replcolor__doc__ << scribus_isspotcolor__doc__ << scribus_setspotcolor__doc__; +} diff --git a/scribus/plugins/scriptplugin/cmdcolor.h b/scribus/plugins/scriptplugin/cmdcolor.h new file mode 100644 index 0000000..bf3f551 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdcolor.h @@ -0,0 +1,140 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDCOLOR_H +#define CMDCOLOR_H + +// Pulls in first +#include "cmdvar.h" + +/** Managing Colors */ + +/*! docstring */ +PyDoc_STRVAR(scribus_colornames__doc__, +QT_TR_NOOP("getColorNames() -> list\n\ +\n\ +Returns a list containing the names of all defined colors in the document.\n\ +If no document is open, returns a list of the default document colors.\n\ +")); +/** Returns a list with colours available in doc or in prefs. */ +PyObject *scribus_colornames(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_getcolor__doc__, +QT_TR_NOOP("getColor(\"name\") -> tuple\n\ +\n\ +Returns a tuple (C, M, Y, K) containing the four color components of the\n\ +color \"name\" from the current document. If no document is open, returns\n\ +the value of the named color from the default document colors.\n\ +\n\ +May raise NotFoundError if the named color wasn't found.\n\ +May raise ValueError if an invalid color name is specified.\n\ +")); +/** Returns a CMYK tuple of the specified color. */ +PyObject *scribus_getcolor(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getcolorasrgb__doc__, +QT_TR_NOOP("getColorAsRGB(\"name\") -> tuple\n\ +\n\ +Returns a tuple (R,G,B) containing the three color components of the\n\ +color \"name\" from the current document, converted to the RGB color\n\ +space. If no document is open, returns the value of the named color\n\ +from the default document colors.\n\ +\n\ +May raise NotFoundError if the named color wasn't found.\n\ +May raise ValueError if an invalid color name is specified.\n\ +")); +/** Returns a CMYK tuple of the specified color. */ +PyObject *scribus_getcolorasrgb(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setcolor__doc__, +QT_TR_NOOP("changeColor(\"name\", c, m, y, k)\n\ +\n\ +Changes the color \"name\" to the specified CMYK value. The color value is\n\ +defined via four components c = Cyan, m = Magenta, y = Yellow and k = Black.\n\ +Color components should be in the range from 0 to 255.\n\ +\n\ +May raise NotFoundError if the named color wasn't found.\n\ +May raise ValueError if an invalid color name is specified.\n\ +")); +/** Sets named color with C,M,Y,K params. */ +PyObject *scribus_setcolor(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_newcolor__doc__, +QT_TR_NOOP("defineColor(\"name\", c, m, y, k)\n\ +\n\ +Defines a new color \"name\". The color Value is defined via four components:\n\ +c = Cyan, m = Magenta, y = Yellow and k = Black. Color components should be in\n\ +the range from 0 to 255.\n\ +\n\ +May raise ValueError if an invalid color name is specified.\n\ +")); +/** Creates new color with name, C, M, Y, K params. */ +PyObject *scribus_newcolor(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_delcolor__doc__, +QT_TR_NOOP("deleteColor(\"name\", \"replace\")\n\ +\n\ +Deletes the color \"name\". Every occurence of that color is replaced by the\n\ +color \"replace\". If not specified, \"replace\" defaults to the color\n\ +\"None\" - transparent.\n\ +\n\ +deleteColor works on the default document colors if there is no document open.\n\ +In that case, \"replace\", if specified, has no effect.\n\ +\n\ +May raise NotFoundError if a named color wasn't found.\n\ +May raise ValueError if an invalid color name is specified.\n\ +")); +/** Deletes named color */ +PyObject *scribus_delcolor(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_replcolor__doc__, +QT_TR_NOOP("replaceColor(\"name\", \"replace\")\n\ +\n\ +Every occurence of the color \"name\" is replaced by the color \"replace\".\n\ +\n\ +May raise NotFoundError if a named color wasn't found.\n\ +May raise ValueError if an invalid color name is specified.\n\ +")); +/** Replaces color with the 2nd one. */ +PyObject *scribus_replcolor(PyObject * /*self*/, PyObject* args); + + +/*! docstring */ +PyDoc_STRVAR(scribus_isspotcolor__doc__, +QT_TR_NOOP("isSpotColor(\"name\") -> bool\n\ +\n\ +Returns True if the color \"name\" is a spot color.\n\ +See also setSpotColor()\n\ +\n\ +May raise NotFoundError if a named color wasn't found.\n\ +May raise ValueError if an invalid color name is specified.\n\ +")); +/** Replaces color with the 2nd one. */ +PyObject *scribus_isspotcolor(PyObject * /*self*/, PyObject* args); + + + +/*! docstring */ +PyDoc_STRVAR(scribus_setspotcolor__doc__, +QT_TR_NOOP("setSpotColor(\"name\", spot)\n\ +\n\ +Set the color \"name\" as a spot color if spot parameter is True.\n\ +See also isSpotColor()\n\ +\n\ +May raise NotFoundError if a named color wasn't found.\n\ +May raise ValueError if an invalid color name is specified.\n\ +")); +/** Replaces color with the 2nd one. */ +PyObject *scribus_setspotcolor(PyObject * /*self*/, PyObject* args); + +#endif + diff --git a/scribus/plugins/scriptplugin/cmddialog.cpp b/scribus/plugins/scriptplugin/cmddialog.cpp new file mode 100644 index 0000000..68b4865 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmddialog.cpp @@ -0,0 +1,145 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmddialog.h" +#include "cmdutil.h" +#include "scribuscore.h" +#include "customfdialog.h" +#include "stylemanager.h" + +#include +#include +#include + + +PyObject *scribus_newdocdia(PyObject* /* self */) +{ + QApplication::changeOverrideCursor(QCursor(Qt::ArrowCursor)); + bool ret = ScCore->primaryMainWindow()->slotFileNew(); + QApplication::changeOverrideCursor(Qt::ArrowCursor); + return PyInt_FromLong(static_cast(ret)); +} + +PyObject *scribus_filedia(PyObject* /* self */, PyObject* args, PyObject* kw) +{ + char *caption = const_cast(""); + char *filter = const_cast(""); + char *defName = const_cast(""); + int haspreview = 0; + int issave = 0; + int isdir = 0; + // FIXME: parsing named params failure. e.g. fileDialog(caption="foo", issave=True) + // FIXME: it's a bug in Python. I'm monitoring it + // https://sourceforge.net/tracker/index.php?func=detail&aid=893549&group_id=5470&atid=105470 + char* kwargs[] = {const_cast("caption"), const_cast("filter"), + const_cast("defaultname"), const_cast("haspreview"), + const_cast("issave"), const_cast("isdir"), + NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "es|esesiii", kwargs, + "utf-8", &caption, "utf-8", &filter, "utf-8", &defName, + &haspreview, &issave, &isdir)) + { + return NULL; + } + QApplication::changeOverrideCursor(QCursor(Qt::ArrowCursor)); + /* nobool = Nothing doing boolean for CFileDialog last attrs. + Due the 'isdir' parameter. CFileDialog needs the last 2 pointers + initialized. */ + bool nobool = false; + int optionFlags = 0; + if (haspreview) + optionFlags |= fdShowPreview; + if (issave) + optionFlags |= fdExistingFiles; + if (isdir) + optionFlags |= fdDirectoriesOnly; + QString fName = ScCore->primaryMainWindow()->CFileDialog(".", + QString::fromUtf8(caption), + QString::fromUtf8(filter), + QString::fromUtf8(defName), + optionFlags, + &nobool, + &nobool, + &nobool + ); +// QApplication::restoreOverrideCursor(); + // FIXME: filename return unicode OK? + return PyString_FromString(fName.toUtf8()); +} + +PyObject *scribus_messdia(PyObject* /* self */, PyObject* args, PyObject* kw) +{ + char *caption = const_cast(""); + char *message = const_cast(""); + uint result; + QMessageBox::Icon ico = QMessageBox::NoIcon; + int butt1 = QMessageBox::Ok|QMessageBox::Default; + int butt2 = QMessageBox::NoButton; + int butt3 = QMessageBox::NoButton; + char* kwargs[] = {const_cast("caption"), const_cast("message"), + const_cast("icon"), const_cast("button1"), + const_cast("button2"), const_cast("button3"), NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "eses|iiii", kwargs, "utf-8", &caption, "utf-8", &message, &ico, &butt1, &butt2, &butt3)) + return NULL; + QApplication::changeOverrideCursor(QCursor(Qt::ArrowCursor)); + QMessageBox mb(QString::fromUtf8(caption), QString::fromUtf8(message), ico, butt1, butt2, butt3, ScCore->primaryMainWindow()); + result = mb.exec(); +// QApplication::restoreOverrideCursor(); + return PyInt_FromLong(static_cast(result)); +} + +PyObject *scribus_valdialog(PyObject* /* self */, PyObject* args) +{ + char *caption = const_cast(""); + char *message = const_cast(""); + char *value = const_cast(""); + if (!PyArg_ParseTuple(args, "eses|es", "utf-8", &caption, "utf-8", &message, "utf-8", &value)) + return NULL; + QApplication::changeOverrideCursor(QCursor(Qt::ArrowCursor)); + QString txt = QInputDialog::getText(ScCore->primaryMainWindow(), + QString::fromUtf8(caption), + QString::fromUtf8(message), + QLineEdit::Normal, + QString::fromUtf8(value)); +// QApplication::restoreOverrideCursor(); + return PyString_FromString(txt.toUtf8()); +} + +PyObject *scribus_newstyledialog(PyObject*, PyObject* args) +{ + if(!checkHaveDocument()) + return NULL; + + ScribusDoc *d = ScCore->primaryMainWindow()->doc; + bool ok; + QString s = QInputDialog::getText(ScCore->primaryMainWindow(), "New Paragraph Style", + "Enter name of the new paragraph style:", QLineEdit::Normal, + QString::null, &ok); + + if (ok && !s.isEmpty()) + { + StyleSet st; + st.redefine(d->paragraphStyles(), true); + ParagraphStyle p; + p.setName(s); + st.create(p); + d->redefineStyles(st, false); + ScCore->primaryMainWindow()->styleMgr()->setDoc(d); + return PyString_FromString(s.toUtf8()); + } + else + Py_RETURN_NONE; +} + +/*! HACK: this removes "warning: 'blash' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmddialogdocwarnings() +{ + QStringList s; + s << scribus_newdocdia__doc__ << scribus_filedia__doc__ << scribus_messdia__doc__; + s << scribus_valdialog__doc__ << scribus_newstyledialog__doc__; +} diff --git a/scribus/plugins/scriptplugin/cmddialog.h b/scribus/plugins/scriptplugin/cmddialog.h new file mode 100644 index 0000000..52f8ef3 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmddialog.h @@ -0,0 +1,115 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDDIALOG_H +#define CMDDIALOG_H + +// Pulls in first +#include "cmdvar.h" + +/** Calling Dialogs from Scribus */ + +/*! docstring */ +PyDoc_STRVAR(scribus_newdocdia__doc__, +QT_TR_NOOP("newDocDialog() -> bool\n\ +\n\ +Displays the \"New Document\" dialog box. Creates a new document if the user\n\ +accepts the settings. Does not create a document if the user presses cancel.\n\ +Returns true if a new document was created.\n\ +")); +/** Raises the Scribus New Document dialog */ +PyObject *scribus_newdocdia(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_filedia__doc__, +QT_TR_NOOP("fileDialog(\"caption\", [\"filter\", \"defaultname\", haspreview, issave, isdir]) -> string with filename\n\ +\n\ +Shows a File Open dialog box with the caption \"caption\". Files are filtered\n\ +with the filter string \"filter\". A default filename or file path can also\n\ +supplied, leave this string empty when you don't want to use it. A value of\n\ +True for haspreview enables a small preview widget in the FileSelect box. When\n\ +the issave parameter is set to True the dialog acts like a \"Save As\" dialog\n\ +otherwise it acts like a \"File Open Dialog\". When the isdir parameter is True\n\ +the dialog shows and returns only directories. The default for all of the\n\ +optional parameters is False.\n\ +\n\ +The filter, if specified, takes the form 'comment (*.type *.type2 ...)'.\n\ +For example 'Images (*.png *.xpm *.jpg)'.\n\ +\n\ +Refer to the Qt-Documentation for QFileDialog for details on filters.\n\ +\n\ +Example: fileDialog('Open input', 'CSV files (*.csv)')\n\ +Example: fileDialog('Save report', defaultname='report.txt', issave=True)\n\ +")); +/** Raises file dialog. + Params - caption, filter, default name and opt. pre, mode. */ +PyObject *scribus_filedia(PyObject * /*self*/, PyObject* args, PyObject* kw); +/* duplicity Sends a string into the Message Bar +PyObject *scribus_mess(PyObject *self, PyObject* args); +*/ + +/*! docstring */ +PyDoc_STRVAR(scribus_messdia__doc__, +QT_TR_NOOP("messageBox(\"caption\", \"message\",\n\ + icon=ICON_NONE, button1=BUTTON_OK|BUTTONOPT_DEFAULT,\n\ + button2=BUTTON_NONE, button3=BUTTON_NONE) -> integer\n\ +\n\ +Displays a message box with the title \"caption\", the message \"message\", and\n\ +an icon \"icon\" and up to 3 buttons. By default no icon is used and a single\n\ +button, OK, is displayed. Only the caption and message arguments are required,\n\ +though setting an icon and appropriate button(s) is strongly\n\ +recommended. The message text may contain simple HTML-like markup.\n\ +\n\ +Returns the number of the button the user pressed. Button numbers start\n\ +at 1.\n\ +\n\ +For the icon and the button parameters there are predefined constants available\n\ +with the same names as in the Qt Documentation. These are the BUTTON_* and\n\ +ICON_* constants defined in the module. There are also two extra constants that\n\ +can be binary-ORed with button constants:\n\ + BUTTONOPT_DEFAULT Pressing enter presses this button.\n\ + BUTTONOPT_ESCAPE Pressing escape presses this button.\n\ +\n\ +Usage examples:\n\ +result = messageBox('Script failed',\n\ + 'This script only works when you have a text frame selected.',\n\ + ICON_ERROR)\n\ +result = messageBox('Monkeys!', 'Something went ook! Was it a monkey?',\n\ + ICON_WARNING, BUTTON_YES|BUTTONOPT_DEFAULT,\n\ + BUTTON_NO, BUTTON_IGNORE|BUTTONOPT_ESCAPE)\n\ +\n\ +Defined button and icon constants:\n\ +BUTTON_NONE, BUTTON_ABORT, BUTTON_CANCEL, BUTTON_IGNORE, BUTTON_NO,\n\ +BUTTON_NOALL, BUTTON_OK, BUTTON_RETRY, BUTTON_YES, BUTTON_YESALL,\n\ +ICON_NONE, ICON_INFORMATION, ICON_WARNING, ICON_CRITICAL.\n\ +")); +/** Displays a message box with - caption, message, icon, button + and two more buttons optional. */ +PyObject *scribus_messdia(PyObject * /*self*/, PyObject* args, PyObject* kw); + +/*! docstring */ +PyDoc_STRVAR(scribus_valdialog__doc__, +QT_TR_NOOP("valueDialog(caption, message [,defaultvalue]) -> string\n\ +\n\ +Shows the common 'Ask for string' dialog and returns its value as a string\n\ +Parameters: window title, text in the window and optional 'default' value.\n\ +\n\ +Example: valueDialog('title', 'text in the window', 'optional')\n\ +")); +/* 09/24/2004 petr vanek */ +PyObject *scribus_valdialog(PyObject * /*self*/, PyObject* args); + + +PyDoc_STRVAR(scribus_newstyledialog__doc__, +QT_TR_NOOP("newStyleDialog() -> string\n\ +\n\ +Shows 'Create new paragraph style' dialog. Function returns real\n\ +style name or None when user cancels the dialog.\n\ +")); +/* 09/24/2004 petr vanek */ +PyObject *scribus_newstyledialog(PyObject * /*self*/, PyObject* args); + +#endif diff --git a/scribus/plugins/scriptplugin/cmddoc.cpp b/scribus/plugins/scriptplugin/cmddoc.cpp new file mode 100644 index 0000000..52187e4 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmddoc.cpp @@ -0,0 +1,377 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmddoc.h" +#include "cmdutil.h" +#include "units.h" +#include "documentinformation.h" +#include "scribuscore.h" + +/* +newDocument(size, margins, orientation, firstPageNumber, + unit, pagesType, firstPageOrder)*/ +PyObject *scribus_newdocument(PyObject* /* self */, PyObject* args) +{ + double topMargin, bottomMargin, leftMargin, rightMargin; + double pageWidth, pageHeight; + int orientation, firstPageNr, unit, pagesType, facingPages, firstPageOrder, numPages; + + PyObject *p, *m; + + if ((!PyArg_ParseTuple(args, "OOiiiiii", &p, &m, &orientation, + &firstPageNr, &unit, + &pagesType, + &firstPageOrder, + &numPages)) || + (!PyArg_ParseTuple(p, "dd", &pageWidth, &pageHeight)) || + (!PyArg_ParseTuple(m, "dddd", &leftMargin, &rightMargin, + &topMargin, &bottomMargin))) + return NULL; + if (numPages <= 0) + numPages = 1; + if (pagesType == 0) + { + facingPages = 0; + firstPageOrder = 0; + } + else + facingPages = 1; + // checking the bounds + if (pagesType < firstPageOrder) + { + PyErr_SetString(ScribusException, QObject::tr("firstPageOrder is bigger than allowed.","python error").toLocal8Bit().constData()); + return NULL; + } + + pageWidth = value2pts(pageWidth, unit); + pageHeight = value2pts(pageHeight, unit); + if (orientation == 1) + { + double x = pageWidth; + pageWidth = pageHeight; + pageHeight = x; + } + leftMargin = value2pts(leftMargin, unit); + rightMargin = value2pts(rightMargin, unit); + topMargin = value2pts(topMargin, unit); + bottomMargin = value2pts(bottomMargin, unit); + + bool ret = ScCore->primaryMainWindow()->doFileNew(pageWidth, pageHeight, + topMargin, leftMargin, rightMargin, bottomMargin, + // autoframes. It's disabled in python + // columnDistance, numberCols, autoframes, + 0, 1, false, + pagesType, unit, firstPageOrder, + orientation, firstPageNr, "Custom", true, numPages); + ScCore->primaryMainWindow()->doc->pageSets[pagesType].FirstPage = firstPageOrder; + + return PyInt_FromLong(static_cast(ret)); +} + +PyObject *scribus_newdoc(PyObject* /* self */, PyObject* args) +{ + qDebug("WARNING: newDoc() procedure is obsolete, it will be removed in a forthcoming release. Use newDocument() instead."); + double b, h, lr, tpr, btr, rr, ebr; + int unit, ds, fsl, fNr, ori; + PyObject *p, *m; + if ((!PyArg_ParseTuple(args, "OOiiiii", &p, &m, &ori, &fNr, &unit, &ds, &fsl)) || + (!PyArg_ParseTuple(p, "dd", &b, &h)) || + (!PyArg_ParseTuple(m, "dddd", &lr, &rr, &tpr, &btr))) + return NULL; + + b = value2pts(b, unit); + h = value2pts(h, unit); + if (ori == 1) + { + ebr = b; + b = h; + h = ebr; + } + /*! \todo Obsolete! In the case of no facing pages use only firstpageleft + scripter is not new-page-size ready. + What is it: don't allow to use wrong FSL constant in the case of + onesided document. */ + if (ds!=1 && fsl>0) + fsl = 0; + // end of hack + + tpr = value2pts(tpr, unit); + lr = value2pts(lr, unit); + rr = value2pts(rr, unit); + btr = value2pts(btr, unit); + + bool ret = ScCore->primaryMainWindow()->doFileNew(b, h, tpr, lr, rr, btr, 0, 1, false, ds, unit, fsl, ori, fNr, "Custom", true); + // qApp->processEvents(); + return PyInt_FromLong(static_cast(ret)); +} + +PyObject *scribus_setmargins(PyObject* /* self */, PyObject* args) +{ + double lr, tpr, btr, rr; + if (!PyArg_ParseTuple(args, "dddd", &lr, &rr, &tpr, &btr)) + return NULL; + if(!checkHaveDocument()) + return NULL; + MarginStruct margins(ValueToPoint(tpr), ValueToPoint(lr), ValueToPoint(btr), ValueToPoint(rr)); + ScCore->primaryMainWindow()->doc->resetPage(margins, ScCore->primaryMainWindow()->doc->currentPageLayout); + ScCore->primaryMainWindow()->view->reformPages(); + ScCore->primaryMainWindow()->doc->setModified(true); + ScCore->primaryMainWindow()->view->GotoPage(ScCore->primaryMainWindow()->doc->currentPageNumber()); + ScCore->primaryMainWindow()->view->DrawNew(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_closedoc(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + ScCore->primaryMainWindow()->doc->setModified(false); + bool ret = ScCore->primaryMainWindow()->slotFileClose(); + qApp->processEvents(); + return PyInt_FromLong(static_cast(ret)); +} + +PyObject *scribus_havedoc(PyObject* /* self */) +{ + return PyInt_FromLong(static_cast(ScCore->primaryMainWindow()->HaveDoc)); +} + +PyObject *scribus_opendoc(PyObject* /* self */, PyObject* args) +{ + char *Name; + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + bool ret = ScCore->primaryMainWindow()->loadDoc(QString::fromUtf8(Name)); + if (!ret) + { + PyErr_SetString(ScribusException, QObject::tr("Failed to open document.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyBool_FromLong(static_cast(true)); +// Py_INCREF(Py_True); // compatibility: return true, not none, on success +// return Py_True; +// Py_RETURN_TRUE; +} + +PyObject *scribus_savedoc(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + ScCore->primaryMainWindow()->slotFileSave(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_getdocname(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + if (! ScCore->primaryMainWindow()->doc->hasName) + { + return PyString_FromString(""); + } + return PyString_FromString(ScCore->primaryMainWindow()->doc->DocName.toUtf8()); +} + +PyObject *scribus_savedocas(PyObject* /* self */, PyObject* args) +{ + char *Name; + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + bool ret = ScCore->primaryMainWindow()->DoFileSave(QString::fromUtf8(Name)); + if (!ret) + { + PyErr_SetString(ScribusException, QObject::tr("Failed to save document.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyBool_FromLong(static_cast(true)); +// Py_INCREF(Py_True); // compatibility: return true, not none, on success +// return Py_True; +// Py_RETURN_TRUE; +} + +PyObject *scribus_setinfo(PyObject* /* self */, PyObject* args) +{ + char *Author; + char *Title; + char *Desc; + // z means string, but None becomes a NULL value. QString() + // will correctly handle NULL. + if (!PyArg_ParseTuple(args, "zzz", &Author, &Title, &Desc)) + return NULL; + if(!checkHaveDocument()) + return NULL; + ScCore->primaryMainWindow()->doc->documentInfo.setAuthor(QString::fromUtf8(Author)); + ScCore->primaryMainWindow()->doc->documentInfo.setTitle(QString::fromUtf8(Title)); + ScCore->primaryMainWindow()->doc->documentInfo.setComments(QString::fromUtf8(Desc)); + ScCore->primaryMainWindow()->slotDocCh(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_setunit(PyObject* /* self */, PyObject* args) +{ + int e; + if (!PyArg_ParseTuple(args, "i", &e)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((e < UNITMIN) || (e > UNITMAX)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Unit out of range. Use one of the scribus.UNIT_* constants.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->slotChangeUnit(e); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_getunit(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + return PyInt_FromLong(static_cast(ScCore->primaryMainWindow()->doc->unitIndex())); +} + +PyObject *scribus_loadstylesfromfile(PyObject* /* self */, PyObject *args) +{ + char *fileName; + if (!PyArg_ParseTuple(args, "es", "utf-8", &fileName)) + return NULL; + if(!checkHaveDocument()) + return NULL; + ScCore->primaryMainWindow()->doc->loadStylesFromFile(QString::fromUtf8(fileName)); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_setdoctype(PyObject* /* self */, PyObject* args) +{ + int fp, fsl; + if (!PyArg_ParseTuple(args, "ii", &fp, &fsl)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (ScCore->primaryMainWindow()->doc->currentPageLayout == fp) + ScCore->primaryMainWindow()->doc->pageSets[ScCore->primaryMainWindow()->doc->currentPageLayout].FirstPage = fsl; + ScCore->primaryMainWindow()->view->reformPages(); + ScCore->primaryMainWindow()->view->GotoPage(ScCore->primaryMainWindow()->doc->currentPageNumber()); // is this needed? + ScCore->primaryMainWindow()->view->DrawNew(); // is this needed? + //CB TODO ScCore->primaryMainWindow()->pagePalette->RebuildPage(); // is this needed? + ScCore->primaryMainWindow()->slotDocCh(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_closemasterpage(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + ScCore->primaryMainWindow()->view->hideMasterPage(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_masterpagenames(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + PyObject* names = PyList_New(ScCore->primaryMainWindow()->doc->MasterPages.count()); + QMap::const_iterator it(ScCore->primaryMainWindow()->doc->MasterNames.constBegin()); + QMap::const_iterator itEnd(ScCore->primaryMainWindow()->doc->MasterNames.constEnd()); + int n = 0; + for ( ; it != itEnd; ++it ) + { + PyList_SET_ITEM(names, n++, PyString_FromString(it.key().toUtf8().data()) ); + } + return names; +} + +PyObject *scribus_editmasterpage(PyObject* /* self */, PyObject* args) +{ + char* name = 0; + if (!PyArg_ParseTuple(args, "es", const_cast("utf-8"), &name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + const QString masterPageName(name); + const QMap& masterNames(ScCore->primaryMainWindow()->doc->MasterNames); + const QMap::const_iterator it(masterNames.find(masterPageName)); + if ( it == masterNames.constEnd() ) + { + PyErr_SetString(PyExc_ValueError, "Master page not found"); + return NULL; + } + ScCore->primaryMainWindow()->view->showMasterPage(*it); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject* scribus_createmasterpage(PyObject* /* self */, PyObject* args) +{ + char* name = 0; + if (!PyArg_ParseTuple(args, "es", const_cast("utf-8"), &name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + const QString masterPageName(name); + if (ScCore->primaryMainWindow()->doc->MasterNames.contains(masterPageName)) + { + PyErr_SetString(PyExc_ValueError, "Master page already exists"); + return NULL; + } + ScCore->primaryMainWindow()->doc->addMasterPage(ScCore->primaryMainWindow()->doc->MasterPages.count(), masterPageName); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject* scribus_deletemasterpage(PyObject* /* self */, PyObject* args) +{ + char* name = 0; + if (!PyArg_ParseTuple(args, "es", const_cast("utf-8"), &name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + const QString masterPageName(name); + if (!ScCore->primaryMainWindow()->doc->MasterNames.contains(masterPageName)) + { + PyErr_SetString(PyExc_ValueError, "Master page does not exist"); + return NULL; + } + if (masterPageName == "Normal") + { + PyErr_SetString(PyExc_ValueError, "Can not delete the Normal master page"); + return NULL; + } + bool oldMode = ScCore->primaryMainWindow()->doc->masterPageMode(); + ScCore->primaryMainWindow()->doc->setMasterPageMode(true); + ScCore->primaryMainWindow()->DeletePage2(ScCore->primaryMainWindow()->doc->MasterNames[masterPageName]); + ScCore->primaryMainWindow()->doc->setMasterPageMode(oldMode); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmddocdocwarnings() +{ + QStringList s; + s << scribus_newdocument__doc__ << scribus_newdoc__doc__ << scribus_closedoc__doc__ << scribus_havedoc__doc__ << scribus_opendoc__doc__ << scribus_savedoc__doc__ << scribus_getdocname__doc__ << scribus_savedocas__doc__ << scribus_setinfo__doc__ <=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDDOC_H +#define CMDDOC_H + +// Pulls in first +#include "cmdvar.h" + +/** Document related Commands */ + +PyDoc_STRVAR(scribus_newdocument__doc__, +QT_TR_NOOP("newDocument(size, margins, orientation, firstPageNumber,\n\ + unit, pagesType, firstPageOrder, numPages) -> bool\n\ +\n\ +Creates a new document and returns true if successful. The parameters have the\n\ +following meaning:\n\ +\n\ +size = A tuple (width, height) describing the size of the document. You can\n\ +use predefined constants named PAPER_ e.g. PAPER_A4 etc.\n\ +\n\ +margins = A tuple (left, right, top, bottom) describing the document\n\ +margins\n\ +\n\ +orientation = the page orientation - constants PORTRAIT, LANDSCAPE\n\ +\n\ +firstPageNumer = is the number of the first page in the document used for\n\ +pagenumbering. While you'll usually want 1, it's useful to have higher\n\ +numbers if you're creating a document in several parts.\n\ +\n\ +unit: this value sets the measurement units used by the document. Use a\n\ +predefined constant for this, one of: UNIT_INCHES, UNIT_MILLIMETERS,\n\ +UNIT_PICAS, UNIT_POINTS.\n\ +\n\ +pagesType = One of the predefined constants PAGE_n. PAGE_1 is single page,\n\ +PAGE_2 is for double sided documents, PAGE_3 is for 3 pages fold and\n\ +PAGE_4 is 4-fold.\n\ +\n\ +firstPageOrder = What is position of first page in the document.\n\ +Indexed from 0 (0 = first).\n\ +\n\ +numPage = Number of pages to be created.\n\ +\n\ +The values for width, height and the margins are expressed in the given unit\n\ +for the document. PAPER_* constants are expressed in points. If your document\n\ +is not in points, make sure to account for this.\n\ +\n\ +example: newDocument(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 7, UNIT_POINTS,\n\ +PAGE_4, 3, 1)\n\ +\n\ +May raise ScribusError if is firstPageOrder bigger than allowed by pagesType.\n\ +")); +/** Creates a new document e.g. (Paper_A4, Margins, 1, 1, 1, NoFacingPages, FirstPageLeft) + first 2 args are lists (tuples) */ +PyObject *scribus_newdocument(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_newdoc__doc__, +QT_TR_NOOP("newDoc(size, margins, orientation, firstPageNumber,\n\ + unit, facingPages, firstSideLeft) -> bool\n\ +\n\ +WARNING: Obsolete procedure! Use newDocument instead.\n\ +\n\ +Creates a new document and returns true if successful. The parameters have the\n\ +following meaning:\n\ +\n\ + size = A tuple (width, height) describing the size of the document. You can\n\ + use predefined constants named PAPER_ e.g. PAPER_A4 etc.\n\ +\n\ + margins = A tuple (left, right, top, bottom) describing the document\n\ + margins\n\ +\n\ + orientation = the page orientation - constants PORTRAIT, LANDSCAPE\n\ +\n\ + firstPageNumer = is the number of the first page in the document used for\n\ + pagenumbering. While you'll usually want 1, it's useful to have higher\n\ + numbers if you're creating a document in several parts.\n\ +\n\ + unit: this value sets the measurement units used by the document. Use a\n\ + predefined constant for this, one of: UNIT_INCHES, UNIT_MILLIMETERS,\n\ + UNIT_PICAS, UNIT_POINTS.\n\ +\n\ + facingPages = FACINGPAGES, NOFACINGPAGES\n\ +\n\ + firstSideLeft = FIRSTPAGELEFT, FIRSTPAGERIGHT\n\ +\n\ +The values for width, height and the margins are expressed in the given unit\n\ +for the document. PAPER_* constants are expressed in points. If your document\n\ +is not in points, make sure to account for this.\n\ +\n\ +example: newDoc(PAPER_A4, (10, 10, 20, 20), LANDSCAPE, 1, UNIT_POINTS,\n\ + FACINGPAGES, FIRSTPAGERIGHT)\n\ +")); +/** Creates a new document e.g. (Paper_A4, Margins, 1, 1, 1, NoFacingPages, FirstPageLeft) + first 2 args are lists (tuples) */ +PyObject *scribus_newdoc(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_closedoc__doc__, +QT_TR_NOOP("closeDoc()\n\ +\n\ +Closes the current document without prompting to save.\n\ +\n\ +May throw NoDocOpenError if there is no document to close\n\ +")); +/** Closes active doc. No params */ +PyObject *scribus_closedoc(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_havedoc__doc__, +QT_TR_NOOP("haveDoc() -> bool\n\ +\n\ +Returns true if there is a document open.\n\ +")); +/** Checks if is a document opened. */ +PyObject *scribus_havedoc(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_opendoc__doc__, +QT_TR_NOOP("openDoc(\"name\")\n\ +\n\ +Opens the document \"name\".\n\ +\n\ +May raise ScribusError if the document could not be opened.\n\ +")); +/** Opens a document with given name. */ +PyObject *scribus_opendoc(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_savedoc__doc__, +QT_TR_NOOP("saveDoc()\n\ +\n\ +Saves the current document with its current name, returns true if successful.\n\ +If the document has not already been saved, this may bring up an interactive\n\ +save file dialog.\n\ +\n\ +If the save fails, there is currently no way to tell.\n\ +")); +PyObject *scribus_savedoc(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_getdocname__doc__, +QT_TR_NOOP("getDocName() -> string\n\ +\n\ +Returns the name the document was saved under.\n\ +If the document was not saved before the name is empty.\n\ +")); +/** Saves active document with given name */ +PyObject *scribus_getdocname(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_savedocas__doc__, +QT_TR_NOOP("saveDocAs(\"name\")\n\ +\n\ +Saves the current document under the new name \"name\" (which may be a full or\n\ +relative path).\n\ +\n\ +May raise ScribusError if the save fails.\n\ +")); +/** Saves active document with given name */ +PyObject *scribus_savedocas(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setinfo__doc__, +QT_TR_NOOP("setInfo(\"author\", \"info\", \"description\") -> bool\n\ +\n\ +Sets the document information. \"Author\", \"Info\", \"Description\" are\n\ +strings.\n\ +")); +/** Sets document infos - author, title and description */ +PyObject *scribus_setinfo(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setmargins__doc__, +QT_TR_NOOP("setMargins(lr, rr, tr, br)\n\ +\n\ +Sets the margins of the document, Qt::DockLeft(lr), Qt::DockRight(rr), Qt::DockTop(tr) and Qt::DockBottom(br)\n\ +margins are given in the measurement units of the document - see UNIT_\n\ +constants.\n\ +")); +/** Sets document margins - left, right, top and bottom. */ +PyObject *scribus_setmargins(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setunit__doc__, +QT_TR_NOOP("setUnit(type)\n\ +\n\ +Changes the measurement unit of the document. Possible values for \"unit\" are\n\ +defined as constants UNIT_.\n\ +\n\ +May raise ValueError if an invalid unit is passed.\n\ +")); +/** Changes unit scale. */ +PyObject *scribus_setunit(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getunit__doc__, +QT_TR_NOOP("getUnit() -> integer (Scribus unit constant)\n\ +\n\ +Returns the measurement units of the document. The returned value will be one\n\ +of the UNIT_* constants:\n\ +UNIT_INCHES, UNIT_MILLIMETERS, UNIT_PICAS, UNIT_POINTS.\n\ +")); +/** Returns actual unit scale. */ +PyObject *scribus_getunit(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_loadstylesfromfile__doc__, +QT_TR_NOOP("loadStylesFromFile(\"filename\")\n\ +\n\ +Loads paragraph styles from the Scribus document at \"filename\" into the\n\ +current document.\n\ +")); +/** Loads styles from another .sla file (craig r.)*/ +PyObject *scribus_loadstylesfromfile(PyObject * /*self*/, PyObject *args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setdoctype__doc__, +QT_TR_NOOP("setDocType(facingPages, firstPageLeft)\n\ +\n\ +Sets the document type. To get facing pages set the first parameter to\n\ +FACINGPAGES, to switch facingPages off use NOFACINGPAGES instead. If you want\n\ +to be the first page a left side set the second parameter to FIRSTPAGELEFT, for\n\ +a right page use FIRSTPAGERIGHT.\n\ +")); +PyObject *scribus_setdoctype(PyObject * /*self*/, PyObject* args); + +PyDoc_STRVAR(scribus_closemasterpage__doc__, +QT_TR_NOOP("closeMasterPage()\n\ +\n\ +Closes the currently active master page, if any, and returns editing\n\ +to normal. Begin editing with editMasterPage().\n\ +")); +PyObject* scribus_closemasterpage(PyObject* self); + +PyDoc_STRVAR(scribus_masterpagenames__doc__, +QT_TR_NOOP("masterPageNames()\n\ +\n\ +Returns a list of the names of all master pages in the document.\n\ +")); +PyObject* scribus_masterpagenames(PyObject* self); + +PyDoc_STRVAR(scribus_editmasterpage__doc__, +QT_TR_NOOP("editMasterPage(pageName)\n\ +\n\ +Enables master page editing and opens the named master page\n\ +for editing. Finish editing with closeMasterPage().\n\ +")); +PyObject* scribus_editmasterpage(PyObject* self, PyObject* args); + +PyDoc_STRVAR(scribus_createmasterpage__doc__, +QT_TR_NOOP("createMasterPage(pageName)\n\ +\n\ +Creates a new master page named pageName and opens it for\n\ +editing.\n\ +")); +PyObject* scribus_createmasterpage(PyObject* self, PyObject* args); + +PyDoc_STRVAR(scribus_deletemasterpage__doc__, +QT_TR_NOOP("deleteMasterPage(pageName)\n\ +\n\ +Delete the named master page.\n\ +")); +PyObject* scribus_deletemasterpage(PyObject* self, PyObject* args); + +#endif + diff --git a/scribus/plugins/scriptplugin/cmdgetprop.cpp b/scribus/plugins/scriptplugin/cmdgetprop.cpp new file mode 100644 index 0000000..a786ccb --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdgetprop.cpp @@ -0,0 +1,345 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmdgetprop.h" +#include "cmdutil.h" +#include "scribuscore.h" + +/* getObjectType(name) */ +PyObject *scribus_getobjecttype(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + PageItem *item = NULL; + QString result = ""; + + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + + if(!checkHaveDocument()) + return NULL; + + item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + + if (item->itemType() == PageItem::TextFrame) { + result = "TextFrame"; + } else if (item->itemType() == PageItem::PathText) { + result = "PathText"; + } else if (item->itemType() == PageItem::ImageFrame) { + result = "ImageFrame"; + } else if (item->itemType() == PageItem::Line) { + result = "Line"; + } else if (item->itemType() == PageItem::Polygon) { + result = "Polygon"; + } else if (item->itemType() == PageItem::PolyLine) { + result = "Polyline"; + } else if (item->itemType() == PageItem::LatexFrame) { + result = "LatexFrame"; + } else if (item->itemType() == PageItem::Multiple) { + result = "Multiple"; + } + + return PyString_FromString(result.toUtf8()); +} + +PyObject *scribus_getfillcolor(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyString_FromString(i->fillColor().toUtf8()) : NULL; +} + +PyObject *scribus_getfilltrans(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyFloat_FromDouble(static_cast(1.0 - i->fillTransparency())) : NULL; +} + +PyObject *scribus_getfillblend(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyInt_FromLong(static_cast(i->fillBlendmode())) : NULL; +} + +PyObject *scribus_getlinecolor(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + PageItem *it; + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + it = GetUniqueItem(QString::fromUtf8(Name)); + if (it == NULL) + return NULL; + if ((it->HasSel) && ((it->itemType() == PageItem::TextFrame) || (it->itemType() == PageItem::PathText))) + { + for (int b = 0; b < it->itemText.length(); ++b) + { + if (it->itemText.selected(b)) + return PyString_FromString(it->itemText.charStyle(b).fillColor().toUtf8()); + } + } + else + return PyString_FromString(it->lineColor().toUtf8()); + PyErr_SetString(NotFoundError, QObject::tr("Color not found - python error", "python error").toLocal8Bit().constData()); + return NULL; +} + +PyObject *scribus_getlinetrans(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyFloat_FromDouble(static_cast(1.0 - i->lineTransparency())) : NULL; +} + +PyObject *scribus_getlineblend(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyInt_FromLong(static_cast(i->lineBlendmode())) : NULL; +} + +PyObject *scribus_getlinewidth(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyFloat_FromDouble(static_cast(i->lineWidth())) : NULL; +} + +PyObject *scribus_getlineshade(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + PageItem *it; + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + it = GetUniqueItem(QString::fromUtf8(Name)); + if (it == NULL) + return NULL; + if ((it->HasSel) && ((it->itemType() == PageItem::TextFrame) || (it->itemType() == PageItem::PathText))) + { + for (int b = 0; b < it->itemText.length(); ++b) + { + if (it->itemText.selected(b)) + return PyInt_FromLong(static_cast(it->itemText.charStyle(b).fillShade())); + } + } + else + return PyInt_FromLong(static_cast(it->lineShade())); + return PyInt_FromLong(0L); +} + +PyObject *scribus_getlinejoin(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyInt_FromLong(static_cast(i->PLineJoin)) : NULL; +} + +PyObject *scribus_getlinecap(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyInt_FromLong(static_cast(i->PLineEnd)) : NULL; +} + +PyObject *scribus_getlinestyle(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyInt_FromLong(static_cast(i->PLineArt)) : NULL; +} + +PyObject *scribus_getfillshade(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyInt_FromLong(static_cast(i->fillShade())) : NULL; +} + +PyObject *scribus_getcornerrad(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyInt_FromLong(static_cast(i->cornerRadius())) : NULL; +} + +PyObject *scribus_getimgscale(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? Py_BuildValue("(ff)", i->imageXScale() / 72.0 * i->pixm.imgInfo.xres, i->imageYScale() / 72.0 * i->pixm.imgInfo.yres) : NULL; +} + +PyObject *scribus_getimgname(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyString_FromString(i->Pfile.toUtf8()) : NULL; +} + +PyObject *scribus_getposi(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (!i) + return NULL; + return Py_BuildValue("(ff)", docUnitXToPageX(i->xPos()), + docUnitYToPageY(i->yPos())); +} + +PyObject *scribus_getsize(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return (i != NULL) ? Py_BuildValue("(ff)", PointToValue(i->width()), PointToValue(i->height())) : NULL; +} + +PyObject *scribus_getrotation(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + return i != NULL ? PyFloat_FromDouble(static_cast(i->rotation() * -1)) : NULL; +} + +PyObject *scribus_getallobj(PyObject* /* self */, PyObject* args) +{ + PyObject *l; + int typ = -1; + uint counter = 0; + uint counter2 = 0; + uint pageNr = ScCore->primaryMainWindow()->doc->currentPageNumber(); + if (!PyArg_ParseTuple(args, "|i", &typ)) + return NULL; + if(!checkHaveDocument()) + return NULL; + // have doc already + if (typ != -1) + { + for (int lam2 = 0; lam2 < ScCore->primaryMainWindow()->doc->Items->count(); ++lam2) + { + if ((ScCore->primaryMainWindow()->doc->Items->at(lam2)->itemType() == typ) && (pageNr == static_cast(ScCore->primaryMainWindow()->doc->Items->at(lam2)->OwnPage))) + counter++; + } + } + else + { + for (int lam2 = 0; lam2 < ScCore->primaryMainWindow()->doc->Items->count(); ++lam2) + { + if (pageNr == static_cast(ScCore->primaryMainWindow()->doc->Items->at(lam2)->OwnPage)) + counter++; + } + } + + l = PyList_New(counter); + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Items->count(); ++lam) + { + if (pageNr == static_cast(ScCore->primaryMainWindow()->doc->Items->at(lam)->OwnPage)) + { + if (typ != -1) + { + if (ScCore->primaryMainWindow()->doc->Items->at(lam)->itemType() == typ) + { + PyList_SetItem(l, counter2, PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(lam)->itemName().toUtf8())); + counter2++; + } + } + else + { + PyList_SetItem(l, counter2, PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(lam)->itemName().toUtf8())); + counter2++; + } + } + } + return l; +} + +/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmdgetpropdocwarnings() +{ + QStringList s; + s << scribus_getobjecttype__doc__ << scribus_getfillcolor__doc__ + << scribus_getfilltrans__doc__ << scribus_getfillblend__doc__ + << scribus_getlinecolor__doc__ << scribus_getlinetrans__doc__ + << scribus_getlineblend__doc__ << scribus_getlinewidth__doc__ + << scribus_getlineshade__doc__ << scribus_getlinejoin__doc__ + << scribus_getlinecap__doc__ << scribus_getlinestyle__doc__ + << scribus_getfillshade__doc__ << scribus_getcornerrad__doc__ + << scribus_getimgscale__doc__ << scribus_getimgname__doc__ + << scribus_getposi__doc__ << scribus_getsize__doc__ + << scribus_getrotation__doc__ << scribus_getallobj__doc__; +} diff --git a/scribus/plugins/scriptplugin/cmdgetprop.h b/scribus/plugins/scriptplugin/cmdgetprop.h new file mode 100644 index 0000000..f2d89c5 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdgetprop.h @@ -0,0 +1,223 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDGETPROP_H +#define CMDGETPROP_H + +// Pulls in first +#include "cmdvar.h" + +/** Query-Functions */ + +/*! docstring */ +PyDoc_STRVAR(scribus_getobjecttype__doc__, +QT_TR_NOOP("getObjectType([\"name\"]) -> string\n\ +\n\ +Get type of object \"name\" as a string.\n\ +")); +/** Get Object Type of name. */ +PyObject *scribus_getobjecttype(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getfillcolor__doc__, +QT_TR_NOOP("getFillColor([\"name\"]) -> string\n\ +\n\ +Returns the name of the fill color of the object \"name\".\n\ +If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Returns fill color of the object */ +PyObject *scribus_getfillcolor(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getfilltrans__doc__, +QT_TR_NOOP("getFillTransparency([\"name\"]) -> float\n\ +\n\ +Returns the fill transparency of the object \"name\". If \"name\"\n\ +is not given the currently selected Item is used.\n\ +")); +/*! Returns fill transparency of the object */ +PyObject *scribus_getfilltrans(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getfillblend__doc__, +QT_TR_NOOP("getFillBlendmode([\"name\"]) -> integer\n\ +\n\ +Returns the fill blendmode of the object \"name\". If \"name\"\n\ +is not given the currently selected Item is used.\n\ +")); +/*! Returns fill blendmode of the object */ +PyObject *scribus_getfillblend(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlinecolor__doc__, +QT_TR_NOOP("getLineColor([\"name\"]) -> string\n\ +\n\ +Returns the name of the line color of the object \"name\".\n\ +If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Returns color of the line */ +PyObject *scribus_getlinecolor(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlinetrans__doc__, +QT_TR_NOOP("getLineTransparency([\"name\"]) -> float\n\ +\n\ +Returns the line transparency of the object \"name\". If \"name\"\n\ +is not given the currently selected Item is used.\n\ +")); +/*! Returns line transparency of the object */ +PyObject *scribus_getlinetrans(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlineblend__doc__, +QT_TR_NOOP("getLineBlendmode([\"name\"]) -> integer\n\ +\n\ +Returns the line blendmode of the object \"name\". If \"name\"\n\ +is not given the currently selected Item is used.\n\ +")); +/*! Returns line blendmode of the object */ +PyObject *scribus_getlineblend(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlinewidth__doc__, +QT_TR_NOOP("getLineWidth([\"name\"]) -> integer\n\ +\n\ +Returns the line width of the object \"name\". If \"name\"\n\ +is not given the currently selected Item is used.\n\ +")); +/*! Returns width of the line */ +PyObject *scribus_getlinewidth(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlineshade__doc__, +QT_TR_NOOP("getLineShade([\"name\"]) -> integer\n\ +\n\ +Returns the shading value of the line color of the object \"name\".\n\ +If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Returns shading of the line */ +PyObject *scribus_getlineshade(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlinejoin__doc__, +QT_TR_NOOP("getLineJoin([\"name\"]) -> integer (see constants)\n\ +\n\ +Returns the line join style of the object \"name\". If \"name\" is not given\n\ +the currently selected item is used. The join types are:\n\ +JOIN_BEVEL, JOIN_MITTER, JOIN_ROUND\n\ +")); +/*! Returns join type of the line */ +PyObject *scribus_getlinejoin(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlinecap__doc__, +QT_TR_NOOP("getLineCap([\"name\"]) -> integer (see constants)\n\ +\n\ +Returns the line cap style of the object \"name\". If \"name\" is not given the\n\ +currently selected item is used. The cap types are:\n\ +CAP_FLAT, CAP_ROUND, CAP_SQUARE\n\ +")); +/*! Returns cap type of the line */ +PyObject *scribus_getlinecap(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlinestyle__doc__, +QT_TR_NOOP("getLineStyle([\"name\"]) -> integer (see constants)\n\ +\n\ +Returns the line style of the object \"name\". If \"name\" is not given the\n\ +currently selected item is used. Line style constants are:\n\ +LINE_DASH, LINE_DASHDOT, LINE_DASHDOTDOT, LINE_DOT, LINE_SOLID\n\ +")); +/*! Returns style type of the line */ +PyObject *scribus_getlinestyle(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getfillshade__doc__, +QT_TR_NOOP("getFillShade([\"name\"]) -> integer\n\ +\n\ +Returns the shading value of the fill color of the object \"name\".\n\ +If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Returns fill shade of the object */ +PyObject *scribus_getfillshade(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getcornerrad__doc__, +QT_TR_NOOP("getCornerRadius([\"name\"]) -> integer\n\ +\n\ +Returns the corner radius of the object \"name\". The radius is\n\ +expressed in points. If \"name\" is not given the currently\n\ +selected item is used.\n\ +")); +/*! Returns corner radius of the object */ +PyObject *scribus_getcornerrad(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getimgscale__doc__, +QT_TR_NOOP("getImageScale([\"name\"]) -> (x,y)\n\ +\n\ +Returns a (x, y) tuple containing the scaling values of the image frame\n\ +\"name\". If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Returns image scale of the object */ +PyObject *scribus_getimgscale(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getimgname__doc__, +QT_TR_NOOP("getImageName([\"name\"]) -> string\n\ +\n\ +Returns the filename for the image in the image frame. If \"name\" is not\n\ +given the currently selected item is used.\n\ +")); +/*! Returns image name of the object */ +PyObject *scribus_getimgname(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getposi__doc__, +QT_TR_NOOP("getPosition([\"name\"]) -> (x,y)\n\ +\n\ +Returns a (x, y) tuple with the position of the object \"name\".\n\ +If \"name\" is not given the currently selected item is used.\n\ +The position is expressed in the actual measurement unit of the document\n\ +- see UNIT_ for reference.\n\ +")); +/*! Returns position of the object */ +PyObject *scribus_getposi(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getsize__doc__, +QT_TR_NOOP("getSize([\"name\"]) -> (width,height)\n\ +\n\ +Returns a (width, height) tuple with the size of the object \"name\".\n\ +If \"name\" is not given the currently selected item is used. The size is\n\ +expressed in the current measurement unit of the document - see UNIT_\n\ +for reference.\n\ +")); +/*! Returns size of the object */ +PyObject *scribus_getsize(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getrotation__doc__, +QT_TR_NOOP("getRotation([\"name\"]) -> integer\n\ +\n\ +Returns the rotation of the object \"name\". The value is expressed in degrees,\n\ +and clockwise is positive. If \"name\" is not given the currently selected item\n\ +is used.\n\ +")); +/*! Returns rotation of the object */ +PyObject *scribus_getrotation(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getallobj__doc__, +QT_TR_NOOP("getAllObjects() -> list\n\ +\n\ +Returns a list containing the names of all objects on the current page.\n\ +")); +/*! Returns a list with all objects in page */ +PyObject *scribus_getallobj(PyObject * /*self*/, PyObject* args); + +#endif + diff --git a/scribus/plugins/scriptplugin/cmdgetsetprop.cpp b/scribus/plugins/scriptplugin/cmdgetsetprop.cpp new file mode 100644 index 0000000..0f12e64 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdgetsetprop.cpp @@ -0,0 +1,499 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmdgetsetprop.h" +#include "cmdutil.h" + +#include +#include +#include +#include +#include + +QObject* getQObjectFromPyArg(PyObject* arg) +{ + if (PyString_Check(arg)) + // It's a string. Look for a pageItem by that name. Do NOT accept a + // selection. + return getPageItemByName(QString::fromUtf8(PyString_AsString(arg))); + else if (PyCObject_Check(arg)) + { + // It's a PyCObject, ie a wrapped pointer. Check it's not NULL + // and return it. + // FIXME: Try to check that its a pointer to a QObject instance + QObject* tempObject = (QObject*)PyCObject_AsVoidPtr(arg); + if (!tempObject) + { + PyErr_SetString(PyExc_TypeError, "INTERNAL: Passed NULL PyCObject"); + return NULL; + } + else + return tempObject; + } + else + { + // It's not a type we know what to do with + PyErr_SetString(PyExc_TypeError, QObject::tr("Argument must be page item name, or PyCObject instance").toLocal8Bit().constData()); + return NULL; + } +} + + +PyObject* wrapQObject(QObject* obj) +{ + return PyCObject_FromVoidPtr((void*)obj, NULL); +} + + +const char* getpropertytype(QObject* obj, const char* propname, bool includesuper) +{ + const QMetaObject* objmeta = obj->metaObject(); + int i = objmeta->indexOfProperty(propname); + if (i == -1) + return NULL; + QMetaProperty propmeta = objmeta->property(i); + if (!propmeta.isValid()) + return NULL; + const char* type = propmeta.typeName(); + return type; +} + + +PyObject* scribus_propertyctype(PyObject* /*self*/, PyObject* args, PyObject* kw) +{ + PyObject* objArg = NULL; + char* propertyname = NULL; + int includesuper = 1; + char* kwargs[] = {const_cast("object"), + const_cast("property"), + const_cast("includesuper"), + NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "Oes|i", kwargs, + &objArg, "ascii", &propertyname, &includesuper)) + return NULL; + + // Get the QObject* the object argument refers to + QObject* obj = getQObjectFromPyArg(objArg); + if (!obj) + return NULL; + objArg = NULL; // no need to decref, it's borrowed + + // Look up the property and retrive its type information + const char* type = getpropertytype( (QObject*)obj, propertyname, includesuper); + if (type == NULL) + { + PyErr_SetString(PyExc_KeyError, QObject::tr("Property not found").toLocal8Bit().constData()); + return NULL; + } + return PyString_FromString(type); +} + +PyObject* convert_QStringList_to_PyListObject(QStringList& origlist) +{ + PyObject* resultList = PyList_New(0); + if (!resultList) + return NULL; + + for ( QStringList::Iterator it = origlist.begin(); it != origlist.end(); ++it ) + if (PyList_Append(resultList, PyString_FromString((*it).toUtf8().data())) == -1) + return NULL; + + return resultList; +} + + +PyObject* convert_QObjectList_to_PyListObject(QObjectList* origlist) +{ + PyObject* resultList = PyList_New(0); + if (!resultList) + return NULL; + + PyObject* objPtr = NULL; + // Loop over the objects in the list and add them to the python + // list wrapped in PyCObjects . + for (int i = 0; i < origlist->count(); ++i) + { + // Wrap up the object pointer + objPtr = wrapQObject(origlist->at(i)); + if (!objPtr) + { + // Failed to wrap the object. An exception is already set. + Py_DECREF(resultList); + return NULL; + } + // and add it to the list + if (PyList_Append(resultList, (PyObject*)objPtr) == -1) + return NULL; + } + return resultList; +} + +/*Qt4 we either need to copy QObject::qChildHelper or rewrite this + +PyObject* scribus_getchildren(PyObject* , PyObject* args, PyObject* kw) +{ + PyObject* objArg = NULL; + char* ofclass = NULL; + char* ofname = NULL; + int recursive = 0; + int regexpmatch = 0; + char* kwnames[] = {const_cast("object"), + const_cast("ofclass"), + const_cast("ofname"), + const_cast("regexpmatch"), + const_cast("recursive"), + NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "O|esesii", kwnames, + &objArg, "ascii", &ofclass, "ascii", &ofname, ®expmatch, &recursive)) + return NULL; + + // Get the QObject* the object argument refers to + QObject* obj = getQObjectFromPyArg(objArg); + if (!obj) + return NULL; + objArg = NULL; // no need to decref, it's borrowed + + // Our job is to return a Python list containing the children of this + // widget (as PyCObjects). +//qt4 FIXME QObjectList* children; +//qt4 FIXME children = obj->queryList(ofclass, ofname, regexpmatch, recursive); + PyObject* itemlist = 0; +//qt4 FIXME itemlist = convert_QObjectList_to_PyListObject(children); +//qt4 FIXME delete children; + return itemlist; +} + + +// Perform a recursive (by default) search for the named child, possibly of a +// select class. +PyObject* scribus_getchild(PyObject* , PyObject* args, PyObject* kw) +{ + PyObject* objArg = NULL; + char* childname = NULL; + char* ofclass = NULL; + bool recursive = true; + char* kwnames[] = {const_cast("object"), + const_cast("childname"), + const_cast("ofclass"), + const_cast("recursive"), + NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "Oes|esi", kwnames, + &objArg, "ascii", &childname, "ascii", &ofclass, &recursive)) + return NULL; + + // Get the QObject* the object argument refers to + QObject* obj = getQObjectFromPyArg(objArg); + if (!obj) + return NULL; + objArg = NULL; // no need to decref, it's borrowed + + // Search for the child, possibly restricting the search to children + // of a particular type, and possibly recursively searching through + // grandchildren etc. + QObject* child = obj->child(childname, ofclass, recursive); + if (child == NULL) + { + PyErr_SetString(PyExc_KeyError, QObject::tr("Child not found").toLocal8Bit().constData()); + return NULL; + } + + return wrapQObject(child); +} +*/ + +PyObject* scribus_getpropertynames(PyObject* /*self*/, PyObject* args, PyObject* kw) +{ + PyObject* objArg = NULL; + int includesuper = 1; + char* kwargs[] = {const_cast("object"), + const_cast("includesuper"), + NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "O|i", kwargs, + &objArg, &includesuper)) + return NULL; + + // Get the QObject* the object argument refers to + QObject* obj = getQObjectFromPyArg(objArg); + if (!obj) + return NULL; + objArg = NULL; // no need to decref, it's borrowed + + // Retrive the object's meta object so we can query it + const QMetaObject* objmeta = obj->metaObject(); + if (!objmeta) + return NULL; + + // Return the list of properties + QStringList propertyNames; + int propertyOffset = includesuper ? 0 : objmeta->propertyOffset(); + for(int i = propertyOffset; i < objmeta->propertyCount(); ++i) + { + QString propName = objmeta->property(i).name(); + propertyNames << QString::fromLatin1(objmeta->property(i).name()); + } + return convert_QStringList_to_PyListObject(propertyNames); +} + + +PyObject* scribus_getproperty(PyObject* /*self*/, PyObject* args, PyObject* kw) +{ + PyObject* objArg = NULL; + char* propertyName = NULL; + char* kwargs[] = {const_cast("object"), + const_cast("property"), + NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "Oes", kwargs, + &objArg, "ascii", &propertyName)) + return NULL; + + // Get the QObject* the object argument refers to + QObject* obj = getQObjectFromPyArg(objArg); + if (!obj) + return NULL; + objArg = NULL; // no need to decref, it's borrowed + + // Get the QMetaProperty for the property, so we can check + // if it's a set/enum and do name/value translation. + const QMetaObject* objmeta = obj->metaObject(); + int i = objmeta->indexOfProperty(propertyName); + if (i == -1) + { + PyErr_SetString(PyExc_ValueError, + QObject::tr("Property not found").toLocal8Bit().data()); + return NULL; + } + + QMetaProperty propmeta = objmeta->property(i); + if (!propmeta.isValid()) + { + PyErr_SetString(PyExc_ValueError, + QObject::tr("Invalid property").toLocal8Bit().data()); + return NULL; + } + + // Get the property value as a variant type + QVariant prop = obj->property(propertyName); + + // Convert the property to an instance of the closest matching Python type. + PyObject* resultobj = NULL; + // NUMERIC TYPES + if (prop.type() == QVariant::Int) + resultobj = PyLong_FromLong(prop.toInt()); + else if (prop.type() == QVariant::Double) + resultobj = PyFloat_FromDouble(prop.toDouble()); + // BOOLEAN + else if (prop.type() == QVariant::Bool) + resultobj = PyBool_FromLong(prop.toBool()); + // STRING TYPES + else if (prop.type() == QVariant::ByteArray) + resultobj = PyString_FromString(prop.toByteArray().data()); + else if (prop.type() == QVariant::String) + resultobj = PyString_FromString(prop.toString().toUtf8().data()); + // HIGHER ORDER TYPES + else if (prop.type() == QVariant::Point) + { + // Return a QPoint as an (x,y) tuple. + QPoint pt = prop.toPoint(); + return Py_BuildValue("(ii)", pt.x(), pt.y()); + } + else if (prop.type() == QVariant::Rect) + { + // Return a QRect as an (x,y,width,height) tuple. + // FIXME: We should really construct and return an object that + // matches the API of QRect and has properties to keep + // left/top/right/bottom and x/y/width/height in sync. + QRect r = prop.toRect(); + return Py_BuildValue("(iiii)", r.x(), r.y(), r.width(), r.height()); + } + else if (prop.type() == QVariant::StringList) + { + QStringList tmp = prop.toStringList(); + return convert_QStringList_to_PyListObject(tmp); + } + // UNHANDLED TYPE + else + { + PyErr_SetString(PyExc_TypeError, QObject::tr("Couldn't convert result type '%1'.").arg(prop.typeName()).toLocal8Bit().constData() ); + return resultobj; + } + + // Return the resulting Python object + if (resultobj == NULL) + { + // An exception was set while assigning to resultobj + assert(PyErr_Occurred()); + return NULL; + } + else + return resultobj; +} + + + +PyObject* scribus_setproperty(PyObject* /*self*/, PyObject* args, PyObject* kw) +{ + PyObject* objArg = NULL; + char* propertyName = NULL; + PyObject* objValue = NULL; + char* kwargs[] = {const_cast("object"), + const_cast("property"), + const_cast("value"), + NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "OesO", kwargs, + &objArg, "ascii", &propertyName, &objValue)) + return NULL; + + // We're going to hang on to the value object for a while, so + // claim a reference to it. + Py_INCREF(objValue); + + // Get the QObject* the object argument refers to + QObject* obj = getQObjectFromPyArg(objArg); + if (!obj) + return NULL; + objArg = NULL; // no need to decref, it's borrowed + + const char* propertyTypeName = getpropertytype(obj, propertyName, true); + if (propertyTypeName == NULL) + return NULL; + QString propertyType = QString::fromLatin1(propertyTypeName); + + // Did we know how to convert the value argument to the right type? + bool matched = false; + // Did the set call succceed? + bool success = false; + + // Check the C++ type of the property, and try to convert the passed + // PyObject to something sensible looking for it. + // FIXME: handle enums/sets + // NUMERIC TYPES + // These are unfortuately a TOTAL PITA because of the multitude of + // C and Python numeric types. TODO This needs to be broken out into a subroutine. + if (propertyType == "bool") + { + matched = true; + if (PyObject_IsTrue(objValue) == 0) + success = obj->setProperty(propertyName, 0); + else if (PyObject_IsTrue(objValue) == 1) + success = obj->setProperty(propertyName, 1); + else if (PyInt_Check(objValue)) + success = obj->setProperty(propertyName, PyInt_AsLong(objValue) == 0); + else if (PyLong_Check(objValue)) + success = obj->setProperty(propertyName, PyLong_AsLong(objValue) == 0); + else + matched = false; + } + else if (propertyType == "int") + { + matched = true; + if (PyObject_IsTrue(objValue) == 0) + success = obj->setProperty(propertyName, 0); + else if (PyObject_IsTrue(objValue) == 1) + success = obj->setProperty(propertyName, 1); + else if (PyInt_Check(objValue)) + success = obj->setProperty(propertyName, (int)PyInt_AsLong(objValue)); + else if (PyLong_Check(objValue)) + success = obj->setProperty(propertyName, (int)PyLong_AsLong(objValue)); + else + matched = false; + } + else if (propertyType == "double") + { + matched = true; + // FIXME: handle int, long and bool too + if (PyFloat_Check(objValue)) + success = obj->setProperty(propertyName, PyFloat_AsDouble(objValue)); + else + matched = false; + } + // STRING TYPES + else if (propertyType == "QString") + { + matched = true; + if (PyString_Check(objValue)) + success = obj->setProperty(propertyName, QString::fromUtf8(PyString_AsString(objValue))); + else if (PyUnicode_Check(objValue)) + { + // Get a pointer to the internal buffer of the Py_Unicode object, which is UCS2 formatted + const unsigned short * ucs2Data = (const unsigned short *)PyUnicode_AS_UNICODE(objValue); + // and make a new QString from it (the string is copied) + success = obj->setProperty(propertyName, QString::fromUtf16(ucs2Data)); + } + else + matched = false; + } + else if (propertyType == "QCString") + { + matched = true; + if (PyString_Check(objValue)) + { + // FIXME: should raise an exception instead of mangling the string when + // out of charset chars present. + QString utfString = QString::fromUtf8(PyString_AsString(objValue)); + success = obj->setProperty(propertyName, utfString.toAscii()); + } + else if (PyUnicode_Check(objValue)) + { + // Get a pointer to the internal buffer of the Py_Unicode object, which is UCS2 formatted + const unsigned short * utf16Data = (const unsigned short *)PyUnicode_AS_UNICODE(objValue); + // and make a new QString from it (the string is copied) + success = obj->setProperty(propertyName, QString::fromUtf16(utf16Data).toAscii()); + } + else + matched = false; + } + // HIGHER ORDER TYPES + // ... which I can't be stuffed supporting yet. FIXME. + else + { + Py_DECREF(objValue); + PyErr_SetString(PyExc_TypeError, + QObject::tr("Property type '%1' not supported").arg(propertyType).toLocal8Bit().constData()); + return NULL; + } + + // If `matched' is false, we recognised the C type but weren't able to + // convert the passed Python value to anything suitable. + if (!matched) + { + // Get a string representation of the object + PyObject* objRepr = PyObject_Repr(objValue); + Py_DECREF(objValue); // We're done with it now + if (!objRepr) + return NULL; + // Extract the repr() string + QString reprString = QString::fromUtf8(PyString_AsString(objRepr)); + Py_DECREF(objRepr); + + // And return an error + PyErr_SetString(PyExc_TypeError, + QObject::tr("Couldn't convert '%1' to property type '%2'").arg(reprString).arg(propertyType).toLocal8Bit().constData()); + return NULL; + } + + // `success' is the return value of the setProperty() call + if (!success) + { + Py_DECREF(objValue); + PyErr_SetString(PyExc_ValueError, QObject::tr("Types matched, but setting property failed.").toLocal8Bit().constData()); + return NULL; + } + + Py_DECREF(objValue); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmdgetsetpropdocwarnings() +{ + QStringList s; + s << scribus_propertyctype__doc__ << scribus_getpropertynames__doc__ << scribus_getproperty__doc__ << scribus_setproperty__doc__; + //Qt4 << scribus_getchildren__doc__ << scribus_getchild__doc__; +} diff --git a/scribus/plugins/scriptplugin/cmdgetsetprop.h b/scribus/plugins/scriptplugin/cmdgetsetprop.h new file mode 100644 index 0000000..7a2e508 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdgetsetprop.h @@ -0,0 +1,206 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMD_GETSETPROP_H +#define CMD_GETSETPROP_H + +// Pulls in Python.h first +#include "cmdvar.h" +#include + + +/** + * @brief Return a pointer to the QObject that the PyObject* args refers to + * + * This function looks up the PyObject* argument and tries to return a + * corresponding QObject. + * + * If the argument is a PyCObject, it will return the contained pointer. + * If the pointer is NULL an exception is set before returning. + * + * If the argument is a string, a PageItem by that name will be looked for + * and, if found, returned. If no such object could be found, an exception + * is set and NULL is returned. + * + * If any other type is specified, an exception is set and NULL is returned. + * + * @attention may return NULL with an exception set + * + * @sa wrapQObject() + */ +QObject* getQObjectFromPyArg(PyObject* arg); + + +/** + * @brief Return a PyCObject containing the passed QObject pointer + * @sa getQObjectFromPyArg() + * @attention may return NULL with an exception set + */ +PyObject* wrapQObject(QObject* obj); + + +/** + * @brief Convert a QStringList to a Python list of str objects + * @attention may return NULL with an exception set + */ +PyObject* convert_QStringList_to_PyListObject(QStringList& origlist); + +/** + * @brief Convert a QObjectList to a Python list of PyCObjects + * @attention may return NULL with an exception set + */ +PyObject* convert_QObjectList_to_PyListObject(QObjectList* origlist); + +/** + * @brief return the name of the C type of the specified property + * + * Look up `propname' on `obj', searching through parent classes if + * `includsuper' is true. Get and return the name of the C type + * of the property. + * + * If the property cannot be found, a null string is returned. NO + * EXCEPTION IS SET. + * + * @sa scribus_propertyctype() + */ +const char* getpropertytype(QObject* obj, const char* propname, bool includesuper = true); + +/** + * @brief Get name of C type of property of object + * @returns Python string object containing name of C type of property. + * @sa getpropertytype(), scribus_getproperty(), scribus_setproperty() + */ +PyDoc_STRVAR(scribus_propertyctype__doc__, +QT_TR_NOOP("getPropertyCType(object, property, includesuper=True)\n\ +\n\ +Returns the name of the C type of `property' of `object'. See getProperty()\n\ +for details of arguments.\n\ +\n\ +If `includesuper' is true, search inherited properties too.\n\ +")); +PyObject* scribus_propertyctype(PyObject* /*self*/, PyObject* args, PyObject* kw); + + +/** + * @brief Return a list of the property names of the passed object + * + * See the Python docstring for details on this function. + * + * @sa QMetaObject::propertyNames(), scribus_getproperty(), + * scribus_setproperty() + */ +PyDoc_STRVAR(scribus_getpropertynames__doc__, +QT_TR_NOOP("getPropertyNames(object, includesuper=True)\n\ +\n\ +Return a list of property names supported by `object'.\n\ +If `includesuper' is true, return properties supported\n\ +by parent classes as well.\n\ +")); +PyObject* scribus_getpropertynames(PyObject* self, PyObject* args, PyObject* kw); + + +/** + * @brief Generic Python getter for Qt object properties + * + * This getter uses the Qt property interface (see the Qt object + * model documentation) to provide a generic getter for any property + * of a supported type. It finds the closest Python type match to the + * property's C++ type, converts the property value to the Python type, + * and returns it. + * + * If an unsupported type is encountered, TypeError will be raised. + * + * See the Python docstring for details of this function's Python + * interface. + * + * @sa scribus_setproperty(), QObject::property(), QMetaObject. + * scribus_propertyctype() + */ +PyDoc_STRVAR(scribus_getproperty__doc__, +QT_TR_NOOP("getProperty(object, property)\n\ +\n\ +Return the value of the property `property' of the passed `object'.\n\ +\n\ +The `object' argument may be a string, in which case the named PageItem\n\ +is searched for. It may also be a PyCObject, which may point to any\n\ +C++ QObject instance.\n\ +\n\ +The `property' argument must be a string, and is the name of the property\n\ +to look up on `object'.\n\ +\n\ +The return value varies depending on the type of the property.\n\ +")); +PyObject* scribus_getproperty(PyObject* /*self*/, PyObject* args, PyObject* kw); + + +/** + * @brief Generic setter for Qt object properties + * + * This setter uses the Qt property intercace to provide a generic setter + * for any property of a supported type. It checks the Property's C type + * and attempts to convert the passed Python object to a compatible type, + * then call the object's property setter method with the converted value. + * + * If an unsupported type is encountered, TypeError will be raised. + * If the passed object can't be converted to a compatible type, + * TypeError will be raised. + * + * See the Python docstring for details of this function's Python + * interface. + * + * @sa scribus_getproperty(), QObject::property(), QMetaObject, + * scribus_propertyctype() + */ +PyDoc_STRVAR(scribus_setproperty__doc__, +QT_TR_NOOP("setProperty(object, property, value)\n\ +\n\ +Set `property' of `object' to `value'. If `value' cannot be converted to a type\n\ +compatible with the type of `property', an exception is raised. An exception may\n\ +also be raised if the underlying setter fails.\n\ +\n\ +See getProperty() for more information.\n\ +")); +PyObject* scribus_setproperty(PyObject* /*self*/, PyObject* args, PyObject* kw); + + +/** + * @brief Return a list of children of the passed object + * + * See the Python docstring for details on this function. + * + * @sa QObject::children(), scribus_getchild() + */ +/*Qt4 +PyDoc_STRVAR(scribus_getchildren__doc__, +QT_TR_NOOP("getChildren(object, ofclass=None, ofname=None, regexpmatch=False, recursive=True)\n\ +\n\ +Return a list of children of `object', possibly restricted to children\n\ +of class named `ofclass' or children named `ofname'. If `recursive' is true,\n\ +search recursively through children, grandchildren, etc.\n\ +\n\ +See QObject::children() in the Qt docs for more information.\n\ +")); +PyObject* scribus_getchildren(PyObject* self, PyObject* args, PyObject* kw); +*/ + +/** + * @brief Return a wrapped PyObject* for the named child, if found. + * + * See the Python docstring for details on this function. + * + * @sa QObject::child(), scribus_children() + */ +/*Qt4 +PyDoc_STRVAR(scribus_getchild__doc__, +QT_TR_NOOP("getChild(object, childname, ofclass=None, recursive=True)\n\ +\n\ +Return the first child of `object' named `childname', possibly restricting\n\ +the search to children of type name `ofclass'. If `recursive' is true,\n\ +search recursively through children, grandchildren, etc.\n\ +")); +PyObject* scribus_getchild(PyObject* self, PyObject* args, PyObject* kw); +*/ +#endif diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp new file mode 100644 index 0000000..d9875d5 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdmani.cpp @@ -0,0 +1,492 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmdmani.h" +#include "cmdutil.h" +#include "propertiespalette.h" //CB argh.. noooooooooooooooooooooooooooooooooooo FIXME see other FIXME +#include "selection.h" +#include "scribuscore.h" +#include "undomanager.h" + +PyObject *scribus_loadimage(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Image; + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Image, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + if (!item->asImageFrame()) + { + PyErr_SetString(WrongFrameTypeError, QObject::tr("Target is not an image frame.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->doc->LoadPict(QString::fromUtf8(Image), item->ItemNr); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_scaleimage(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double x, y; + if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + if (! item->asImageFrame()) + { + PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->doc->itemSelection_SetImageScale(x, y); //CB why when this is done above? + ScCore->primaryMainWindow()->doc->updatePic(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_setimagescale(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double x, y; + if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + if (! item->asImageFrame()) + { + PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData()); + return NULL; + } + double newScaleX = x / item->pixm.imgInfo.xres * 72.0; + double newScaleY = y / item->pixm.imgInfo.yres * 72.0; + ScCore->primaryMainWindow()->doc->itemSelection_SetImageScale(newScaleX, newScaleY); //CB why when this is done above? + ScCore->primaryMainWindow()->doc->updatePic(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_setimageoffset(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double x, y; + if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + if (! item->asImageFrame()) + { + PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData()); + return NULL; + } + + // Grab the old selection - but use it only where is there any + Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection); + bool hadOrigSelection = (tempSelection.count() != 0); + + ScCore->primaryMainWindow()->doc->m_Selection->clear(); + // Clear the selection + ScCore->primaryMainWindow()->view->Deselect(); + // Select the item, which will also select its group if + // there is one. + ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr); + + // offset + double newOffsetX = x / ((item->imageXScale() != 0.0) ? item->imageXScale() : 1); + double newOffsetY = y / ((item->imageYScale() != 0.0) ? item->imageYScale() : 1); + ScCore->primaryMainWindow()->doc->itemSelection_SetImageOffset(newOffsetX, newOffsetY); //CB why when this is done above? + ScCore->primaryMainWindow()->doc->updatePic(); + + // Now restore the selection. + ScCore->primaryMainWindow()->view->Deselect(); + if (hadOrigSelection) + *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection; + + // Py_INCREF(Py_None); + // return Py_None; + Py_RETURN_NONE; +} + + +PyObject *scribus_moveobjrel(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double x, y; + if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item==NULL) + return NULL; + // Grab the old selection - but use it only where is there any + Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection); + bool hadOrigSelection = (tempSelection.count() != 0); + + ScCore->primaryMainWindow()->doc->m_Selection->clear(); + // Clear the selection + ScCore->primaryMainWindow()->view->Deselect(); + // Select the item, which will also select its group if + // there is one. + ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr); + // Move the item, or items + if (ScCore->primaryMainWindow()->doc->m_Selection->count() > 1) + { + ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Move, "", Um::IMove); + ScCore->primaryMainWindow()->doc->moveGroup(ValueToPoint(x), ValueToPoint(y)); + ScCore->primaryMainWindow()->view->endGroupTransaction(); + } + else + ScCore->primaryMainWindow()->doc->MoveItem(ValueToPoint(x), ValueToPoint(y), item); + // Now restore the selection. + ScCore->primaryMainWindow()->view->Deselect(); + if (hadOrigSelection) + *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection; + + Py_RETURN_NONE; +} + +PyObject *scribus_moveobjabs(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double x, y; + if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + // Grab the old selection - but use it only where is there any + Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection); + bool hadOrigSelection = (tempSelection.count() != 0); + + // Clear the selection + ScCore->primaryMainWindow()->view->Deselect(); + // Select the item, which will also select its group if + // there is one. + ScCore->primaryMainWindow()->view->SelectItemNr(item->ItemNr); + // Move the item, or items + if (ScCore->primaryMainWindow()->doc->m_Selection->count() > 1) + { + ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Move, "", Um::IMove); + double x2, y2, w, h; + ScCore->primaryMainWindow()->doc->m_Selection->getGroupRect(&x2, &y2, &w, &h); + ScCore->primaryMainWindow()->doc->moveGroup(pageUnitXToDocX(x) - x2, pageUnitYToDocY(y) - y2); + ScCore->primaryMainWindow()->view->endGroupTransaction(); + } + else + ScCore->primaryMainWindow()->doc->MoveItem(pageUnitXToDocX(x) - item->xPos(), pageUnitYToDocY(y) - item->yPos(), item); + // Now restore the selection. + ScCore->primaryMainWindow()->view->Deselect(); + if (hadOrigSelection) + *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection; + + Py_RETURN_NONE; +} + +PyObject *scribus_rotobjrel(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double x; + if (!PyArg_ParseTuple(args, "d|es", &x, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + ScCore->primaryMainWindow()->doc->RotateItem(item->rotation() - x, item->ItemNr); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_rotobjabs(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double x; + if (!PyArg_ParseTuple(args, "d|es", &x, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + ScCore->primaryMainWindow()->doc->RotateItem(x * -1.0, item->ItemNr); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_sizeobjabs(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double x, y; + if (!PyArg_ParseTuple(args, "dd|es", &x, &y, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + if (item == NULL) + return NULL; + ScCore->primaryMainWindow()->doc->SizeItem(ValueToPoint(x), ValueToPoint(y), item->ItemNr); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_groupobj(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + PyObject *il = 0; + if (!PyArg_ParseTuple(args, "|O", &il)) + return NULL; + if (!checkHaveDocument()) + return NULL; + if (il == 0 && ScCore->primaryMainWindow()->doc->m_Selection->count() < 2) + { + PyErr_SetString(PyExc_TypeError, QObject::tr("Need selection or argument list of items to group", "python error").toLocal8Bit().constData()); + return NULL; + } + Selection *tempSelection=0; + Selection *finalSelection=0; + //uint ap = ScCore->primaryMainWindow()->doc->currentPage()->pageNr(); + // If we were passed a list of items to group... + if (il != 0) + { + int len = PyList_Size(il); + tempSelection = new Selection(ScCore->primaryMainWindow(), false); + for (int i = 0; i < len; i++) + { + // FIXME: We might need to explicitly get this string as utf8 + // but as sysdefaultencoding is utf8 it should be a no-op to do + // so anyway. + Name = PyString_AsString(PyList_GetItem(il, i)); + PageItem *ic = GetUniqueItem(QString::fromUtf8(Name)); + if (ic == NULL) + { + delete tempSelection; + return NULL; + } + tempSelection->addItem (ic, true); + } + finalSelection=tempSelection; + } + else + finalSelection=ScCore->primaryMainWindow()->doc->m_Selection; + if (finalSelection->count() < 2) + { + // We can't very well group only one item + PyErr_SetString(NoValidObjectError, QObject::tr("Cannot group less than two items", "python error").toLocal8Bit().constData()); + finalSelection=0; + delete tempSelection; + return NULL; + } + ScCore->primaryMainWindow()->doc->itemSelection_GroupObjects(false, false, finalSelection); + finalSelection=0; + delete tempSelection; + Py_RETURN_NONE; +} + +PyObject *scribus_ungroupobj(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + ScCore->primaryMainWindow()->view->Deselect(); + ScCore->primaryMainWindow()->view->SelectItemNr(i->ItemNr); + ScCore->primaryMainWindow()->UnGroupObj(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_scalegroup(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double sc; + if (!PyArg_ParseTuple(args, "d|es", &sc, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (sc == 0.0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot scale by 0%.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + ScCore->primaryMainWindow()->view->Deselect(); + ScCore->primaryMainWindow()->view->SelectItemNr(i->ItemNr); +// int h = ScCore->primaryMainWindow()->view->frameResizeHandle; +// ScCore->primaryMainWindow()->view->frameResizeHandle = 1; + ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Resize, "", Um::IResize); + ScCore->primaryMainWindow()->doc->scaleGroup(sc, sc); + ScCore->primaryMainWindow()->view->endGroupTransaction(); +// ScCore->primaryMainWindow()->view->frameResizeHandle = h; +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_getselobjnam(PyObject* /* self */, PyObject* args) +{ + int i = 0; + if (!PyArg_ParseTuple(args, "|i", &i)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((i < static_cast(ScCore->primaryMainWindow()->doc->m_Selection->count())) && (i > -1)) + return PyString_FromString(ScCore->primaryMainWindow()->doc->m_Selection->itemAt(i)->itemName().toUtf8()); + else + // FIXME: Should probably return None if no selection? + return PyString_FromString(""); +} + +PyObject *scribus_selcount(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + return PyInt_FromLong(static_cast(ScCore->primaryMainWindow()->doc->m_Selection->count())); +} + +PyObject *scribus_selectobj(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + ScCore->primaryMainWindow()->view->SelectItemNr(i->ItemNr); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_deselect(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + ScCore->primaryMainWindow()->view->Deselect(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_lockobject(PyObject* /* self */, PyObject* args) +{ + char *name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(name)); + if (item == NULL) + return NULL; + item->toggleLock(); + if (item->locked()) + return PyInt_FromLong(1); + return PyInt_FromLong(0); +} + +PyObject *scribus_islocked(PyObject* /* self */, PyObject* args) +{ + char *name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) + return NULL; + // FIXME: Rather than toggling the lock, we should probably let the user set the lock state + // and instead provide a different function like toggleLock() + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(name)); + if (item == NULL) + return NULL; + if (item->locked()) + return PyBool_FromLong(1); + return PyBool_FromLong(0); +} + +PyObject *scribus_setscaleimagetoframe(PyObject* /* self */, PyObject* args, PyObject* kw) +{ + char *name = const_cast(""); + long int scaleToFrame = 0; + long int proportional = 1; + char* kwargs[] = {const_cast("scaletoframe"), + const_cast("proportional"), const_cast("name"), NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "i|ies", kwargs, &scaleToFrame, &proportional, "utf-8", &name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(name)); + if (item == NULL) + return NULL; + if (! item->asImageFrame()) + { + PyErr_SetString(ScribusException, QObject::tr("Specified item not an image frame.","python error").toLocal8Bit().constData()); + return NULL; + } + // Set the item to scale if appropriate. ScaleType 1 is free + // scale, 0 is scale to frame. + item->ScaleType = scaleToFrame == 0; + // Now, if the user has chosen to set the proportional mode, + // set it. 1 is proportional, 0 is free aspect. + if (proportional != -1) + item->AspectRatio = proportional > 0; + // Force the braindead app to notice the changes + + //FIXME emit or something so we dont need this + ScCore->primaryMainWindow()->propertiesPalette->setScaleAndOffset(item->imageXScale(), item->imageYScale(), item->imageXOffset(), item->imageYOffset()); + item->AdjustPictScale(); + //ScCore->primaryMainWindow()->view->AdjustPictScale(item); + + item->update(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmdmanidocwarnings() +{ + QStringList s; + s << scribus_moveobjrel__doc__ << scribus_moveobjabs__doc__ + << scribus_rotobjrel__doc__ << scribus_rotobjabs__doc__ + << scribus_sizeobjabs__doc__ << scribus_getselobjnam__doc__ + << scribus_selcount__doc__ << scribus_selectobj__doc__ + << scribus_deselect__doc__ << scribus_groupobj__doc__ + << scribus_ungroupobj__doc__ << scribus_scalegroup__doc__ + << scribus_loadimage__doc__ << scribus_scaleimage__doc__ + << scribus_setimagescale__doc__ << scribus_lockobject__doc__ + << scribus_islocked__doc__ << scribus_setscaleimagetoframe__doc__ + << scribus_setimageoffset__doc__ ; +} diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h new file mode 100644 index 0000000..d29ac3c --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdmani.h @@ -0,0 +1,231 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDMANI_H +#define CMDMANI_H + +// Pulls in first +#include "cmdvar.h" + +/** Manipulating Objects */ + +/*! docstring */ +PyDoc_STRVAR(scribus_moveobjrel__doc__, +QT_TR_NOOP("moveObject(dx, dy [, \"name\"])\n\ +\n\ +Moves the object \"name\" by dx and dy relative to its current position. The\n\ +distances are expressed in the current measurement unit of the document (see\n\ +UNIT constants). If \"name\" is not given the currently selected item is used.\n\ +If the object \"name\" belongs to a group, the whole group is moved.\n\ +")); +/*! Move REL the object */ +PyObject *scribus_moveobjrel(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_moveobjabs__doc__, +QT_TR_NOOP("moveObjectAbs(x, y [, \"name\"])\n\ +\n\ +Moves the object \"name\" to a new location. The coordinates are expressed in\n\ +the current measurement unit of the document (see UNIT constants). If \"name\"\n\ +is not given the currently selected item is used. If the object \"name\"\n\ +belongs to a group, the whole group is moved.\n\ +")); +/*! Move ABS the object */ +PyObject *scribus_moveobjabs(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_rotobjrel__doc__, +QT_TR_NOOP("rotateObject(rot [, \"name\"])\n\ +\n\ +Rotates the object \"name\" by \"rot\" degrees relatively. The object is\n\ +rotated by the vertex that is currently selected as the rotation point - by\n\ +default, the top left vertex at zero rotation. Positive values mean counter\n\ +clockwise rotation when the default rotation point is used. If \"name\" is not\n\ +given the currently selected item is used.\n\ +")); +/*! Rotate REL the object */ +PyObject *scribus_rotobjrel(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_rotobjabs__doc__, +QT_TR_NOOP("rotateObjectAbs(rot [, \"name\"])\n\ +\n\ +Sets the rotation of the object \"name\" to \"rot\". Positive values\n\ +mean counter clockwise rotation. If \"name\" is not given the currently\n\ +selected item is used.\n\ +")); +/*! Rotate ABS the object */ +PyObject *scribus_rotobjabs(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_sizeobjabs__doc__, +QT_TR_NOOP("sizeObject(width, height [, \"name\"])\n\ +\n\ +Resizes the object \"name\" to the given width and height. If \"name\"\n\ +is not given the currently selected item is used.\n\ +")); +/*! Resize ABS the object */ +PyObject *scribus_sizeobjabs(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getselobjnam__doc__, +QT_TR_NOOP("getSelectedObject([nr]) -> string\n\ +\n\ +Returns the name of the selected object. \"nr\" if given indicates the number\n\ +of the selected object, e.g. 0 means the first selected object, 1 means the\n\ +second selected Object and so on.\n\ +")); +/*! Returns name of the selected object */ +PyObject *scribus_getselobjnam(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_selcount__doc__, +QT_TR_NOOP("selectionCount() -> integer\n\ +\n\ +Returns the number of selected objects.\n\ +")); +/*! Returns count of the selected object */ +PyObject *scribus_selcount(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_selectobj__doc__, +QT_TR_NOOP("selectObject(\"name\")\n\ +\n\ +Selects the object with the given \"name\".\n\ +")); +/*! Count selection */ +PyObject *scribus_selectobj(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_deselect__doc__, +QT_TR_NOOP("deselectAll()\n\ +\n\ +Deselects all objects in the whole document.\n\ +")); +/*! Remove all selection */ +PyObject *scribus_deselect(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_groupobj__doc__, +QT_TR_NOOP("groupObjects(list)\n\ +\n\ +Groups the objects named in \"list\" together. \"list\" must contain the names\n\ +of the objects to be grouped. If \"list\" is not given the currently selected\n\ +items are used.\n\ +")); +/*! Group objects named in list. */ +PyObject *scribus_groupobj(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_ungroupobj__doc__, +QT_TR_NOOP("unGroupObjects(\"name\")\n\n\ +Destructs the group the object \"name\" belongs to.\ +If \"name\" is not given the currently selected item is used.")); +/*! Ungroup objects named in list. */ +PyObject *scribus_ungroupobj(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_scalegroup__doc__, +QT_TR_NOOP("scaleGroup(factor [,\"name\"])\n\ +\n\ +Scales the group the object \"name\" belongs to. Values greater than 1 enlarge\n\ +the group, values smaller than 1 make the group smaller e.g a value of 0.5\n\ +scales the group to 50 % of its original size, a value of 1.5 scales the group\n\ +to 150 % of its original size. The value for \"factor\" must be greater than\n\ +0. If \"name\" is not given the currently selected item is used.\n\ +\n\ +May raise ValueError if an invalid scale factor is passed.\n\ +")); +/*! Scale group with object name */ +PyObject *scribus_scalegroup(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_loadimage__doc__, +QT_TR_NOOP("loadImage(\"filename\" [, \"name\"])\n\ +\n\ +Loads the picture \"picture\" into the image frame \"name\". If \"name\" is\n\ +not given the currently selected item is used.\n\ +\n\ +May raise WrongFrameTypeError if the target frame is not an image frame\n\ +")); +/*! Loads image file into frame. */ +PyObject *scribus_loadimage(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_scaleimage__doc__, +QT_TR_NOOP("scaleImage(x, y [, \"name\"])\n\ +\n\ +Sets the internal scaling factors of the picture in the image frame \"name\".\n\ +If \"name\" is not given the currently selected item is used. A number of 1\n\ +means 100 %. Internal scaling factors are different from the values shown on \n\ +properties palette. Note : deprecated, use setImageScale() instead.\n\ +\n\ +May raise WrongFrameTypeError if the target frame is not an image frame\n\ +")); +/*! Scale Image. */ +PyObject *scribus_scaleimage(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setimagescale__doc__, +QT_TR_NOOP("setImageScale(x, y [, \"name\"])\n\ +\n\ +Sets the scaling factors of the picture in the image frame \"name\".\n\ +If \"name\" is not given the currently selected item is used. A number of 1\n\ +means 100 %. Scaling factors are equal to the values shown on properties palette.\n\ +\n\ +May raise WrongFrameTypeError if the target frame is not an image frame\n\ +")); +/*! Scale Image. */ +PyObject *scribus_setimagescale(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setimageoffset__doc__, +QT_TR_NOOP("setImageOffset(x, y [, \"name\"])\n\ +\n\ +Sets the position of the picture in the image frame \"name\".\n\ +If \"name\" is not given the currently selected item is used.\n\ +The specified offset values are equal to the values shown on \n\ +properties palette when point unit is used.\n\ +\n\ +May raise WrongFrameTypeError if the target frame is not an image frame\n\ +")); +/*! Scale Image. */ +PyObject *scribus_setimageoffset(PyObject * /*self*/, PyObject* args); + + +/*! docstring */ +PyDoc_STRVAR(scribus_lockobject__doc__, +QT_TR_NOOP("lockObject([\"name\"]) -> bool\n\ +\n\ +Locks the object \"name\" if it's unlocked or unlock it if it's locked.\n\ +If \"name\" is not given the currently selected item is used. Returns true\n\ +if locked.\n\ +")); +/*! (Un)Lock the object 2004/7/10 pv.*/ +PyObject *scribus_lockobject(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_islocked__doc__, +QT_TR_NOOP("isLocked([\"name\"]) -> bool\n\ +\n\ +Returns true if is the object \"name\" locked. If \"name\" is not given the\n\ +currently selected item is used.\n\ +")); +/*! Status of locking 2004/7/10 pv.*/ +PyObject *scribus_islocked(PyObject * /*self*/, PyObject* args); + +PyDoc_STRVAR(scribus_setscaleimagetoframe__doc__, +QT_TR_NOOP("setScaleImageToFrame(scaletoframe, proportional=None, name=)\n\ +\n\ +Sets the scale to frame on the selected or specified image frame to `scaletoframe'.\n\ +If `proportional' is specified, set fixed aspect ratio scaling to `proportional'.\n\ +Both `scaletoframe' and `proportional' are boolean.\n\ +\n\ +May raise WrongFrameTypeError.\n\ +")); +PyObject *scribus_setscaleimagetoframe(PyObject * /*self*/, PyObject* args, PyObject* kwargs); + +#endif diff --git a/scribus/plugins/scriptplugin/cmdmisc.cpp b/scribus/plugins/scriptplugin/cmdmisc.cpp new file mode 100644 index 0000000..a6f5ce0 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdmisc.cpp @@ -0,0 +1,793 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmdmisc.h" +#include "cmdutil.h" + +#include "qbuffer.h" +#include "qpixmap.h" +//Added by qt3to4: +#include + +#include "scribuscore.h" +#include "fonts/scfontmetrics.h" +#include "prefsmanager.h" + +PyObject *scribus_setredraw(PyObject* /* self */, PyObject* args) +{ + int e; + if (!PyArg_ParseTuple(args, "i", &e)) + return NULL; + if(!checkHaveDocument()) + return NULL; + ScCore->primaryMainWindow()->doc->DoDrawing = static_cast(e); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_fontnames(PyObject* /* self */) +{ + int cc2 = 0; + SCFontsIterator it2(PrefsManager::instance()->appPrefs.AvailFonts); + for ( ; it2.hasNext() ; it2.next()) + { + if (it2.current().usable()) + cc2++; + } + PyObject *l = PyList_New(cc2); + SCFontsIterator it(PrefsManager::instance()->appPrefs.AvailFonts); + int cc = 0; + for ( ; it.hasNext() ; it.next()) + { + if (it.current().usable()) + { + PyList_SetItem(l, cc, PyString_FromString(it.currentKey().toUtf8())); + cc++; + } + } + return l; +} + +PyObject *scribus_xfontnames(PyObject* /* self */) +{ + PyObject *l = PyList_New(PrefsManager::instance()->appPrefs.AvailFonts.count()); + SCFontsIterator it(PrefsManager::instance()->appPrefs.AvailFonts); + int cc = 0; + PyObject *row; + for ( ; it.hasNext() ; it.next()) + { + row = Py_BuildValue((char*)"(sssiis)", + it.currentKey().toUtf8().data(), + it.current().family().toUtf8().data(), + it.current().psName().toUtf8().data(), + it.current().subset(), + it.current().embedPs(), + it.current().fontFilePath().toUtf8().data() + ); + PyList_SetItem(l, cc, row); + cc++; + } // for + return l; +} + +// This function is fairly complex because it can either save its output to a +// file, or return it as a Python string. +PyObject *scribus_renderfont(PyObject* /*self*/, PyObject* args, PyObject* kw) +{ + char *Name = const_cast(""); + char *FileName = const_cast(""); + char *Sample = const_cast(""); + char *format = NULL; + int Size; + bool ret = false; + char *kwargs[] = {const_cast("fontname"), + const_cast("filename"), + const_cast("sample"), + const_cast("size"), + const_cast("format"), + NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "esesesi|es", kwargs, + "utf-8", &Name, "utf-8", &FileName, "utf-8", &Sample, &Size, "ascii", &format)) + return NULL; + if (!PrefsManager::instance()->appPrefs.AvailFonts.contains(QString::fromUtf8(Name))) + { + PyErr_SetString(NotFoundError, QObject::tr("Font not found.","python error").toLocal8Bit().constData()); + return NULL; + } + QString ts = QString::fromUtf8(Sample); + if (ts.isEmpty()) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot render an empty sample.","python error").toLocal8Bit().constData()); + return NULL; + } + if (!format) + // User specified no format, so use the historical default of PPM format. + format = const_cast("PPM"); + QPixmap pm = FontSample(PrefsManager::instance()->appPrefs.AvailFonts[QString::fromUtf8(Name)], Size, ts, Qt::white); + // If the user specified an empty filename, return the image data as + // a string. Otherwise, save it to disk. + if (QString::fromUtf8(FileName).isEmpty()) + { + QByteArray buffer_string = ""; + QBuffer buffer(&buffer_string); + buffer.open(QIODevice::WriteOnly); + bool ret = pm.save(&buffer, format); + if (!ret) + { + PyErr_SetString(ScribusException, QObject::tr("Unable to save pixmap","scripter error").toLocal8Bit().constData()); + return NULL; + } + int bufferSize = buffer.size(); + buffer.close(); + // Now make a Python string from the data we generated + PyObject* stringPython = PyString_FromStringAndSize(buffer_string,bufferSize); + // Return even if the result is NULL (error) since an exception will have been + // set in that case. + return stringPython; + } + else + // Save the pixmap to a file, since the filename is non-empty + { + ret = pm.save(QString::fromUtf8(FileName), format); + if (!ret) + { + PyErr_SetString(PyExc_Exception, QObject::tr("Unable to save pixmap","scripter error").toLocal8Bit().constData()); + return NULL; + } + // For historical reasons, we need to return true on success. +// Py_INCREF(Py_True); +// return Py_True; +// Py_RETURN_TRUE; + return PyBool_FromLong(static_cast(true)); + } +} + +PyObject *scribus_getlayers(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + PyObject *l; + l = PyList_New(ScCore->primaryMainWindow()->doc->Layers.count()); + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++) + PyList_SetItem(l, lam, PyString_FromString(ScCore->primaryMainWindow()->doc->Layers[lam].Name.toUtf8())); + return l; +} + +PyObject *scribus_setactlayer(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + bool found = ScCore->primaryMainWindow()->doc->setActiveLayer(QString::fromUtf8(Name)); + if (found) + ScCore->primaryMainWindow()->changeLayer(ScCore->primaryMainWindow()->doc->activeLayer()); + else + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_getactlayer(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + return PyString_FromString(ScCore->primaryMainWindow()->doc->activeLayerName().toUtf8()); +} + +PyObject *scribus_senttolayer(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Layer = const_cast(""); + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Layer, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Layer == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + ScCore->primaryMainWindow()->view->SelectItemNr(i->ItemNr); + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + ScCore->primaryMainWindow()->view->SelectItemNr(i->ItemNr); + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Layer)) + { + i->LayerNr = static_cast(lam); + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(ScribusException, QString("Layer not found").toLocal8Bit().constData()); + return NULL; + } + +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_layervisible(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int vis = 1; + if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QString("Cannot have an empty layer name").toLocal8Bit().constData()); + return NULL; + } + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + ScCore->primaryMainWindow()->doc->Layers[lam].isViewable = vis; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_layerprint(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int vis = 1; + if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + ScCore->primaryMainWindow()->doc->Layers[lam].isPrintable = vis; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_layerlock(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int vis = 1; + if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + ScCore->primaryMainWindow()->doc->Layers[lam].isEditable = vis; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_layeroutline(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int vis = 1; + if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + ScCore->primaryMainWindow()->doc->Layers[lam].outlineMode = vis; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_layerflow(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int vis = 1; + if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + ScCore->primaryMainWindow()->doc->Layers[lam].flowControl = vis; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_layerblend(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int vis = 0; + if (!PyArg_ParseTuple(args, "esi", "utf-8", &Name, &vis)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QString("Cannot have an empty layer name").toLocal8Bit().constData()); + return NULL; + } + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + ScCore->primaryMainWindow()->doc->Layers[lam].blendMode = vis; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_layertrans(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double vis = 1.0; + if (!PyArg_ParseTuple(args, "esd", "utf-8", &Name, &vis)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QString("Cannot have an empty layer name").toLocal8Bit().constData()); + return NULL; + } + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + ScCore->primaryMainWindow()->doc->Layers[lam].transparency = vis; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_glayervisib(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + int i = 0; + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + i = static_cast(ScCore->primaryMainWindow()->doc->Layers[lam].isViewable); + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyInt_FromLong(static_cast(i)); +} + +PyObject *scribus_glayerprint(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + int i = 0; + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + i = static_cast(ScCore->primaryMainWindow()->doc->Layers[lam].isPrintable); + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyInt_FromLong(static_cast(i)); +} + +PyObject *scribus_glayerlock(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + int i = 0; + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + i = static_cast(ScCore->primaryMainWindow()->doc->Layers[lam].isEditable); + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyInt_FromLong(static_cast(i)); +} + +PyObject *scribus_glayeroutline(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + int i = 0; + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + i = static_cast(ScCore->primaryMainWindow()->doc->Layers[lam].outlineMode); + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyInt_FromLong(static_cast(i)); +} + +PyObject *scribus_glayerflow(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + int i = 0; + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + i = static_cast(ScCore->primaryMainWindow()->doc->Layers[lam].flowControl); + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyInt_FromLong(static_cast(i)); +} + +PyObject *scribus_glayerblend(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + int i = 0; + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + i = ScCore->primaryMainWindow()->doc->Layers[lam].blendMode; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyInt_FromLong(static_cast(i)); +} + +PyObject *scribus_glayertrans(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + double i = 1.0; + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); lam++) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + i = ScCore->primaryMainWindow()->doc->Layers[lam].transparency; + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyFloat_FromDouble(i); +} + +PyObject *scribus_removelayer(PyObject* /* self */, PyObject* args) +{ +//FIXME: Use the docs remove layer code + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty layer name.","python error").toLocal8Bit().constData()); + return NULL; + } + if (ScCore->primaryMainWindow()->doc->Layers.count() == 1) + { + PyErr_SetString(ScribusException, QObject::tr("Cannot remove the last layer.","python error").toLocal8Bit().constData()); + return NULL; + } + bool found = false; + for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Layers.count(); ++lam) + { + if (ScCore->primaryMainWindow()->doc->Layers[lam].Name == QString::fromUtf8(Name)) + { + ScLayer it2 = ScCore->primaryMainWindow()->doc->Layers.at(lam); + int num2 = it2.LNr; + if (!num2) + { + // FIXME: WTF DOES THIS DO? + Py_INCREF(Py_None); + return Py_None; + } + ScCore->primaryMainWindow()->doc->removeLayer(num2); + ScCore->primaryMainWindow()->doc->Layers.removeLayerByNumber(num2); + ScCore->primaryMainWindow()->doc->setActiveLayer(0); + ScCore->primaryMainWindow()->changeLayer(0); + found = true; + break; + } + } + if (!found) + { + PyErr_SetString(NotFoundError, QObject::tr("Layer not found.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_createlayer(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (Name == EMPTY_STRING) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot create layer without a name.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->doc->addLayer(QString::fromUtf8(Name), true); + ScCore->primaryMainWindow()->changeLayer(ScCore->primaryMainWindow()->doc->activeLayer()); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_filequit(PyObject* /* self */, PyObject* args) +{ + QMetaObject::invokeMethod(ScCore->primaryMainWindow(), "slotFileQuit", Qt::QueuedConnection); + Py_RETURN_NONE; +} + +PyObject *scribus_getlanguage(PyObject* /* self */) +{ + return PyString_FromString(ScCore->getGuiLanguage().toUtf8()); +} + +/*! 04.01.2007 : Joachim Neu : Moves item selection to front. */ +PyObject *scribus_moveselectiontofront(PyObject*) +{ + ScCore->primaryMainWindow()->doc->bringItemSelectionToFront(); + Py_RETURN_NONE; +} + +/*! 04.01.2007 : Joachim Neu : Moves item selection to back. */ +PyObject *scribus_moveselectiontoback(PyObject*) +{ + ScCore->primaryMainWindow()->doc->sendItemSelectionToBack(); + Py_RETURN_NONE; +} + +/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmdmiscdocwarnings() +{ + QStringList s; + s << scribus_setredraw__doc__ <=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDMISC_H +#define CMDMISC_H + +// Pulls in first +#include "cmdvar.h" +//Added by qt3to4: +#include + +/** Other Commands */ + +/*! docstring */ +PyDoc_STRVAR(scribus_setredraw__doc__, +QT_TR_NOOP("setRedraw(bool)\n\ +\n\ +Disables page redraw when bool = False, otherwise redrawing is enabled.\n\ +This change will persist even after the script exits, so make sure to call\n\ +setRedraw(True) in a finally: clause at the top level of your script.\n\ +")); +/*! Enable/disable page redrawing. */ +PyObject *scribus_setredraw(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_fontnames__doc__, +QT_TR_NOOP("getFontNames() -> list\n\ +\n\ +Returns a list with the names of all available fonts.\n\ +")); +/*! simple list of font names. */ +PyObject *scribus_fontnames(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_xfontnames__doc__, +QT_TR_NOOP("getXFontNames() -> list of tuples\n\ +\n\ +Returns a larger font info. It's a list of the tuples with:\n\ +[ (Scribus name, Family, Real name, subset (1|0), embed PS (1|0), font file), (...), ... ]\n\ +")); +/*! + return a list of the tuples with + Scribus name, Family, Real name, subset (1|0), embed PS (1|0), font file +*/ +PyObject *scribus_xfontnames(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_renderfont__doc__, +QT_TR_NOOP("renderFont(\"name\", \"filename\", \"sample\", size, format=\"PPM\") -> bool\n\ +\n\ +Creates an image preview of font \"name\" with given text \"sample\" and size.\n\ +If \"filename\" is not \"\", image is saved into \"filename\". Otherwise\n\ +image data is returned as a string. The optional \"format\" argument\n\ +specifies the image format to generate, and supports any format allowed\n\ +by QPixmap.save(). Common formats are PPM, JPEG, PNG and XPM.\n\ +\n\ +May raise NotFoundError if the specified font can't be found.\n\ +May raise ValueError if an empty sample or filename is passed.\n\ +")); +/*! Font example to image. */ +PyObject *scribus_renderfont(PyObject* /*self*/, PyObject* args, PyObject* kw); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlayers__doc__, +QT_TR_NOOP("getLayers() -> list\n\ +\n\ +Returns a list with the names of all defined layers.\n\ +")); +/*! List of the layers */ +PyObject *scribus_getlayers(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_setactlayer__doc__, +QT_TR_NOOP("setActiveLayer(\"name\")\n\ +\n\ +Sets the active layer to the layer named \"name\".\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Move into layer */ +PyObject *scribus_setactlayer(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getactlayer__doc__, +QT_TR_NOOP("getActiveLayer() -> string\n\ +\n\ +Returns the name of the current active layer.\n\ +")); +/*! Get layer name */ +PyObject *scribus_getactlayer(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_senttolayer__doc__, +QT_TR_NOOP("sentToLayer(\"layer\" [, \"name\"])\n\ +\n\ +Sends the object \"name\" to the layer \"layer\". The layer must exist.\n\ +If \"name\" is not given the currently selected item is used.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Move object from one layer to other one */ +PyObject *scribus_senttolayer(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_layervisible__doc__, +QT_TR_NOOP("setLayerVisible(\"layer\", visible)\n\ +\n\ +Sets the layer \"layer\" to be visible or not. If is the visible set to false\n\ +the layer is invisible.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer visible */ +PyObject *scribus_layervisible(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_layerprint__doc__, +QT_TR_NOOP("setLayerPrintable(\"layer\", printable)\n\ +\n\ +Sets the layer \"layer\" to be printable or not. If is the\n\ +printable set to false the layer won't be printed.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer printable */ +PyObject *scribus_layerprint(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_layerlock__doc__, +QT_TR_NOOP("setLayerLocked(\"layer\", locked)\n\ +\n\ +Sets the layer \"layer\" to be locked or not. If locked is set to\n\ +true the layer will be locked.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer printable */ +PyObject *scribus_layerlock(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_layeroutline__doc__, +QT_TR_NOOP("setLayerOutlined(\"layer\", outline)\n\ +\n\ +Sets the layer \"layer\" to be locked or not. If outline is set to\n\ +true the layer will be displayed outlined.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer printable */ +PyObject *scribus_layeroutline(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_layerflow__doc__, +QT_TR_NOOP("setLayerFlow(\"layer\", flow)\n\ +\n\ +Sets the layers \"layer\" flowcontrol to flow. If flow is set to\n\ +true text in layers above this one will flow around objects on this layer.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer printable */ +PyObject *scribus_layerflow(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_layerblend__doc__, +QT_TR_NOOP("setLayerBlendmode(\"layer\", blend)\n\ +\n\ +Sets the layers \"layer\" blendmode to blend.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer printable */ +PyObject *scribus_layerblend(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_layertrans__doc__, +QT_TR_NOOP("setLayerTransparency(\"layer\", trans)\n\ +\n\ +Sets the layers \"layer\" transparency to trans.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer printable */ +PyObject *scribus_layertrans(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_glayervisib__doc__, +QT_TR_NOOP("isLayerVisible(\"layer\") -> bool\n\ +\n\ +Returns whether the layer \"layer\" is visible or not, a value of True means\n\ +that the layer \"layer\" is visible, a value of False means that the layer\n\ +\"layer\" is invisible.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer visible */ +PyObject *scribus_glayervisib(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_glayerprint__doc__, +QT_TR_NOOP("isLayerPrintable(\"layer\") -> bool\n\ +\n\ +Returns whether the layer \"layer\" is printable or not, a value of True means\n\ +that the layer \"layer\" can be printed, a value of False means that printing\n\ +the layer \"layer\" is disabled.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer printable */ +PyObject *scribus_glayerprint(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_glayerlock__doc__, +QT_TR_NOOP("isLayerLocked(\"layer\") -> bool\n\ +\n\ +Returns whether the layer \"layer\" is locked or not, a value of True means\n\ +that the layer \"layer\" is editable, a value of False means that the layer\n\ +\"layer\" is locked.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer visible */ +PyObject *scribus_glayerlock(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_glayeroutline__doc__, +QT_TR_NOOP("isLayerOutlined(\"layer\") -> bool\n\ +\n\ +Returns whether the layer \"layer\" is outlined or not, a value of True means\n\ +that the layer \"layer\" is outlined, a value of False means that the layer\n\ +\"layer\" is normal.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer visible */ +PyObject *scribus_glayeroutline(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_glayerflow__doc__, +QT_TR_NOOP("isLayerFlow(\"layer\") -> bool\n\ +\n\ +Returns whether text flows around objects on layer \"layer\", a value of True means\n\ +that text flows around, a value of False means that the text does not flow around.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer visible */ +PyObject *scribus_glayerflow(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_glayerblend__doc__, +QT_TR_NOOP("getLayerBlendmode(\"layer\") -> int\n\ +\n\ +Returns the \"layer\" layer blendmode,\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer visible */ +PyObject *scribus_glayerblend(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_glayertrans__doc__, +QT_TR_NOOP("getLayerTransparency(\"layer\") -> float\n\ +\n\ +Returns the \"layer\" layer transparency,\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Set layer visible */ +PyObject *scribus_glayertrans(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_removelayer__doc__, +QT_TR_NOOP("deleteLayer(\"layer\")\n\ +\n\ +Deletes the layer with the name \"layer\". Nothing happens if the layer doesn't\n\ +exists or if it's the only layer in the document.\n\ +\n\ +May raise NotFoundError if the layer can't be found.\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! Remove layer */ +PyObject *scribus_removelayer(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_createlayer__doc__, +QT_TR_NOOP("createLayer(layer)\n\ +\n\ +Creates a new layer with the name \"name\".\n\ +\n\ +May raise ValueError if the layer name isn't acceptable.\n\ +")); +/*! New layer */ +PyObject *scribus_createlayer(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_filequit__doc__, +QT_TR_NOOP("fileQuit()\n\ +\n\ +Quit Scribus.\n\ +")); +/*! Quit Scribus */ +PyObject *scribus_filequit(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getlanguage__doc__, +QT_TR_NOOP("getGuiLanguage() -> string\n\ +\n\ +Returns a string with the -lang value.\n\ +")); +/*! Language of the GUI */ +PyObject *scribus_getlanguage(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_moveselectiontofront__doc__, +QT_TR_NOOP("moveSelectionToFront()\n\ +\n\ +Moves current selection to front.\n\ +")); +/*! 04.01.2007 : Joachim Neu : Moves item selection to front. */ +PyObject *scribus_moveselectiontofront(PyObject*); + +/*! docstring */ +PyDoc_STRVAR(scribus_moveselectiontoback__doc__, +QT_TR_NOOP("moveSelectionToFront()\n\ +\n\ +Moves current selection to back.\n\ +")); +/*! 04.01.2007 : Joachim Neu : Moves item selection to back. */ +PyObject *scribus_moveselectiontoback(PyObject*); + +#endif + + diff --git a/scribus/plugins/scriptplugin/cmdobj.cpp b/scribus/plugins/scriptplugin/cmdobj.cpp new file mode 100644 index 0000000..de7f3a7 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdobj.cpp @@ -0,0 +1,703 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmdobj.h" +#include "cmdutil.h" +#include "selection.h" +#include "util_math.h" +#include "commonstrings.h" +#include "scribuscore.h" + + +PyObject *scribus_newrect(PyObject* /* self */, PyObject* args) +{ + double x, y, w, h; + char *Name = const_cast(""); + + if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error")); +// return NULL; +// } + int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, + pageUnitXToDocX(x), pageUnitYToDocY(y), + ValueToPoint(w), ValueToPoint(h), + ScCore->primaryMainWindow()->doc->toolSettings.dWidth, + ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true); +// ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i)); + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName); + } +// if (Name != EMPTY_STRING) +// ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name)); + return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8()); +} + + +PyObject *scribus_newellipse(PyObject* /* self */, PyObject* args) +{ + double x, y, w, h; + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, + pageUnitXToDocX(x), + pageUnitYToDocY(y), + ValueToPoint(w), + ValueToPoint(h), + ScCore->primaryMainWindow()->doc->toolSettings.dWidth, + ScCore->primaryMainWindow()->doc->toolSettings.dBrush, + ScCore->primaryMainWindow()->doc->toolSettings.dPen, + true); +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error")); +// return NULL; +// } +// ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i)); +// if (Name != EMPTY_STRING) +// ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name)); + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName); + } + return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8()); +} + + +PyObject *scribus_newimage(PyObject* /* self */, PyObject* args) +{ + double x, y, w, h; + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, + pageUnitXToDocX(x), + pageUnitYToDocY(y), + ValueToPoint(w), + ValueToPoint(h), + 1, ScCore->primaryMainWindow()->doc->toolSettings.dBrushPict, + CommonStrings::None, true); +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error")); +// return NULL; +// } +// ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i)); +// if (Name != EMPTY_STRING) +// ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name)); + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName); + } + return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8()); +} + + +PyObject *scribus_newtext(PyObject* /* self */, PyObject* args) +{ + double x, y, w, h; + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, + pageUnitXToDocX(x), + pageUnitYToDocY(y), + ValueToPoint(w), + ValueToPoint(h), + ScCore->primaryMainWindow()->doc->toolSettings.dWidth, CommonStrings::None, + ScCore->primaryMainWindow()->doc->toolSettings.dPenText, true); +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error")); +// return NULL; +// } +// ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i)); + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName); + } + return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8()); +} + +PyObject *scribus_newline(PyObject* /* self */, PyObject* args) +{ + double x, y, w, h; + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + x = pageUnitXToDocX(x); + y = pageUnitYToDocY(y); + w = pageUnitXToDocX(w); + h = pageUnitYToDocY(h); +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, +// QObject::tr("An object with the requested name already exists.", +// "python error")); +// return NULL; +// } + int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Line, PageItem::Unspecified, + x, y, w, h, + ScCore->primaryMainWindow()->doc->toolSettings.dWidth, + ScCore->primaryMainWindow()->doc->toolSettings.dBrush, + ScCore->primaryMainWindow()->doc->toolSettings.dPen, true); + PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(i); + it->setRotation(xy2Deg(w-x, h-y)); + it->setWidthHeight(sqrt(pow(x-w, 2.0) + pow(y-h, 2.0)), 1.0); + it->Sizing = false; + it->updateClip(); + it->setRedrawBounding(); +// ScCore->primaryMainWindow()->doc->setRedrawBounding(it); +/* WTF? maybe I'll examine who's author later. Or maybe I'll remove it later ;) + it->PoLine.resize(4); + it->PoLine.setPoint(0, 0, 0); + it->PoLine.setPoint(1, 0, 0); + it->PoLine.setPoint(2, w-x, h-y); + it->PoLine.setPoint(3, w-x, h-y); + FPoint np2 = getMinClipF(&it->PoLine); + if (np2.x() < 0) + { + it->PoLine.translate(-np2.x(), 0); + ScCore->primaryMainWindow()->view->MoveItem(np2.x(), 0, it); + } + if (np2.y() < 0) + { + it->PoLine.translate(0, -np2.y()); + ScCore->primaryMainWindow()->view->MoveItem(0, np2.y(), it); + } + ScCore->primaryMainWindow()->view->SizeItem(it->PoLine.WidthHeight().x(), + it->PoLine.WidthHeight().y(), i, false, false, false); + ScCore->primaryMainWindow()->view->AdjustItemSize(it);*/ +// if (Name != EMPTY_STRING) +// it->setItemName(QString::fromUtf8(Name)); + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName); + } + return PyString_FromString(it->itemName().toUtf8()); +} + + +PyObject *scribus_polyline(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + PyObject *il; + // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check. + if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il))) + return NULL; + if(!checkHaveDocument()) + return NULL; + int len = PyList_Size(il); + if (len < 4) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least two points (four values).","python error").toLocal8Bit().constData()); + return NULL; + } + if ((len % 2) != 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error").toLocal8Bit().constData()); + return NULL; + } +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error").toLocal8Bit().constData()); +// return NULL; +// } + double x, y, w, h; + int i = 0; + x = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + y = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1, ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true); + PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic); + it->PoLine.resize(2); + it->PoLine.setPoint(0, 0, 0); + it->PoLine.setPoint(1, 0, 0); + int pp = 6; + for (i = 2; i < len - 2; i += 2) + { + w = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + h = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i+1)))); + it->PoLine.resize(pp); + it->PoLine.setPoint(pp-4, w-x, h-y); + it->PoLine.setPoint(pp-3, w-x, h-y); + it->PoLine.setPoint(pp-2, w-x, h-y); + it->PoLine.setPoint(pp-1, w-x, h-y); + pp += 4; + } + pp -= 2; + w = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, len-2)))); + h = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, len-1)))); + it->PoLine.resize(pp); + it->PoLine.setPoint(pp-2, w-x, h-y); + it->PoLine.setPoint(pp-1, w-x, h-y); + FPoint np2 = getMinClipF(&it->PoLine); + if (np2.x() < 0) + { + it->PoLine.translate(-np2.x(), 0); + ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it); + } + if (np2.y() < 0) + { + it->PoLine.translate(0, -np2.y()); + ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it); + } + ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false); + ScCore->primaryMainWindow()->doc->AdjustItemSize(it); +// if (Name != EMPTY_STRING) +// { +// it->setItemName(QString::fromUtf8(Name)); +// } + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName); + } + return PyString_FromString(it->itemName().toUtf8()); +} + + +PyObject *scribus_polygon(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + PyObject *il; + // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check. + if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il))) + return NULL; + if(!checkHaveDocument()) + return NULL; + int len = PyList_Size(il); + if (len < 6) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least three points (six values).","python error").toLocal8Bit().constData()); + return NULL; + } + if ((len % 2) != 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error").toLocal8Bit().constData()); + return NULL; + } +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error").toLocal8Bit().constData()); +// return NULL; +// } + double x, y, w, h; + int i = 0; + x = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + y = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, 1, 1, ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true); + PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic); + it->PoLine.resize(2); + it->PoLine.setPoint(0, 0, 0); + it->PoLine.setPoint(1, 0, 0); + int pp = 6; + for (i = 2; i < len - 2; i += 2) + { + w = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + h = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i+1)))); + it->PoLine.resize(pp); + it->PoLine.setPoint(pp-4, w-x, h-y); + it->PoLine.setPoint(pp-3, w-x, h-y); + it->PoLine.setPoint(pp-2, w-x, h-y); + it->PoLine.setPoint(pp-1, w-x, h-y); + pp += 4; + } + w = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, len-2)))); + h = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, len-1)))); + it->PoLine.resize(pp); + it->PoLine.setPoint(pp-4, w-x, h-y); + it->PoLine.setPoint(pp-3, w-x, h-y); + it->PoLine.setPoint(pp-2, w-x, h-y); + it->PoLine.setPoint(pp-1, w-x, h-y); + pp += 2; + it->PoLine.resize(pp); + it->PoLine.setPoint(pp-2, 0, 0); + it->PoLine.setPoint(pp-1, 0, 0); + FPoint np2 = getMinClipF(&it->PoLine); + if (np2.x() < 0) + { + it->PoLine.translate(-np2.x(), 0); + ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it); + } + if (np2.y() < 0) + { + it->PoLine.translate(0, -np2.y()); + ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it); + } + ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false); + ScCore->primaryMainWindow()->doc->AdjustItemSize(it); +// if (Name != EMPTY_STRING) +// it->setItemName(QString::fromUtf8(Name)); + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName); + } + return PyString_FromString(it->itemName().toUtf8()); +} + +PyObject *scribus_bezierline(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + PyObject *il; + // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check. + if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il))) + return NULL; + if(!checkHaveDocument()) + return NULL; + int len = PyList_Size(il); + if (len < 8) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least four points (eight values).","python error").toLocal8Bit().constData()); + return NULL; + } + if ((len % 6) != 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values.","python error").toLocal8Bit().constData()); + return NULL; + } +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error").toLocal8Bit().constData()); +// return NULL; +// } + double x, y, w, h, kx, ky, kx2, ky2; + int i = 0; + x = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + y = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + kx = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + ky = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + kx2 = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + ky2 = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + i++; + //int ic = ScCore->primaryMainWindow()->view->PaintPolyLine(x, y, 1, 1, ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen); + int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1, ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true); + PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic); + it->PoLine.resize(2); + it->PoLine.setPoint(0, 0, 0); + it->PoLine.setPoint(1, kx-x, ky-y); + int pp = 6; + for (i = 6; i < len - 6; i += 6) + { + w = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i)))); + h = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i+1)))); + kx = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i+2)))); + ky = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i+3)))); + kx2 = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i+4)))); + ky2 = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, i+5)))); + it->PoLine.resize(pp); + it->PoLine.setPoint(pp-4, w-x, h-y); + it->PoLine.setPoint(pp-3, kx-x, ky-y); + it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4)); + it->PoLine.setPoint(pp-1, kx2-x, ky2-y); + pp += 4; + } + pp -= 2; + w = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, len-6)))); + h = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, len-5)))); + kx = pageUnitXToDocX(static_cast(PyFloat_AsDouble(PyList_GetItem(il, len-4)))); + ky = pageUnitYToDocY(static_cast(PyFloat_AsDouble(PyList_GetItem(il, len-3)))); + it->PoLine.resize(pp); + it->PoLine.setPoint(pp-2, w-x, h-y); + it->PoLine.setPoint(pp-1, kx-x, ky-y); + FPoint np2 = getMinClipF(&it->PoLine); + if (np2.x() < 0) + { + it->PoLine.translate(-np2.x(), 0); + ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it); + } + if (np2.y() < 0) + { + it->PoLine.translate(0, -np2.y()); + ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it); + } + ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false); + ScCore->primaryMainWindow()->doc->AdjustItemSize(it); +// if (Name != EMPTY_STRING) +// it->setItemName(QString::fromUtf8(Name)); + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(ic)->setItemName(objName); + } + return PyString_FromString(it->itemName().toUtf8()); +} + + +/* 03/31/2004 - xception handling + */ +PyObject *scribus_pathtext(PyObject* /* self */, PyObject* args) +{ + double x, y; + char *Name = const_cast(""); + char *TextB = const_cast(""); + char *PolyB = const_cast(""); + if (!PyArg_ParseTuple(args, "ddeses|es", &x, &y, "utf-8", &TextB, "utf-8", &PolyB, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; +// if (ItemExists(QString::fromUtf8(Name))) +// { +// PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error")); +// return NULL; +// } + //FIXME: Why use GetItem not GetUniqueItem? Maybe use GetUniqueItem and use the exceptions + // its sets for us? + int i = GetItem(QString::fromUtf8(TextB)); + int ii = GetItem(QString::fromUtf8(PolyB)); + if ((i == -1) || (ii == -1)) + { + PyErr_SetString(NotFoundError, QObject::tr("Object not found.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->doc->m_Selection->clear(); + ScCore->primaryMainWindow()->doc->m_Selection->addItem(ScCore->primaryMainWindow()->doc->Items->at(i)); + ScCore->primaryMainWindow()->doc->m_Selection->addItem(ScCore->primaryMainWindow()->doc->Items->at(ii)); + PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(i); + ScCore->primaryMainWindow()->view->ToPathText(); + ScCore->primaryMainWindow()->doc->MoveItem(pageUnitXToDocX(x) - it->xPos(), pageUnitYToDocY(y) - it->yPos(), it); +// if (Name != EMPTY_STRING) +// it->setItemName(QString::fromUtf8(Name)); + if (Name != EMPTY_STRING) + { + QString objName = QString::fromUtf8(Name); + if (!ItemExists(objName)) + ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName); + } + return PyString_FromString(it->itemName().toUtf8()); +} + + +/* 03/21/2004 - exception raised when Name doesn't exists. Doesn't crash then. (subik) + */ +PyObject *scribus_deleteobj(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + ScCore->primaryMainWindow()->doc->m_Selection->clear(); + ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); + ScCore->primaryMainWindow()->doc->itemSelection_DeleteItem(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + + +/* 03/21/2004 - exception raises by non existent name (subik) + */ +PyObject *scribus_textflow(PyObject* /* self */, PyObject* args) +{ + char *name = const_cast(""); + int state = -1; + + if (!PyArg_ParseTuple(args, "es|i", "utf-8", &name, &state)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(name)); + if (i == NULL) + return NULL; + if (state == -1) + { + if (i->textFlowAroundObject()) + i->setTextFlowMode(PageItem::TextFlowDisabled); + else + i->setTextFlowMode(PageItem::TextFlowUsesFrameShape); + } + else if( state == (int) PageItem::TextFlowDisabled ) + i->setTextFlowMode(PageItem::TextFlowDisabled); + else if( state == (int) PageItem::TextFlowUsesFrameShape ) + i->setTextFlowMode(PageItem::TextFlowUsesFrameShape); + else if( state == (int) PageItem::TextFlowUsesBoundingBox ) + i->setTextFlowMode(PageItem::TextFlowUsesBoundingBox); + else if( state == (int) PageItem::TextFlowUsesContourLine ) + i->setTextFlowMode(PageItem::TextFlowUsesContourLine); + ScCore->primaryMainWindow()->view->DrawNew(); + ScCore->primaryMainWindow()->slotDocCh(true); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + + +PyObject *scribus_objectexists(PyObject* /* self */, PyObject* args) +{ + char* name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (ItemExists(QString::fromUtf8(name))) + return PyBool_FromLong(static_cast(true)); + return PyBool_FromLong(static_cast(false)); +} + +/* + * Craig Ringer, 2004-09-09 + * Apply the named style to the currently selected object. + * pv, 2004-09-13, optionaly param objectName + "check the page" stuff + */ +PyObject *scribus_setstyle(PyObject* /* self */, PyObject* args) +{ + char *style = const_cast(""); + char *name = const_cast(""); + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *item = GetUniqueItem(QString::fromUtf8(name)); + if (item == NULL) + return NULL; + if ((item->itemType() == PageItem::TextFrame) || (item->itemType() == PageItem::PathText)) + { + // First, find the style number associated with the requested style + // by scanning through the styles looking for the name. If + // we can't find it, raise PyExc_Exception. + // FIXME: Should use a more specific exception. + bool found = false; + uint styleid = 0; + // We start at zero here because it's OK to match an internal name + int docParagraphStylesCount=ScCore->primaryMainWindow()->doc->paragraphStyles().count(); + for (int i=0; i < docParagraphStylesCount; ++i) + { + if (ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name() == QString::fromUtf8(style)) { + found = true; + styleid = i; + break; + } + } + if (!found) { + // whoops, the user specified an invalid style, complain loudly. + PyErr_SetString(NotFoundError, QObject::tr("Style not found.","python error").toLocal8Bit().constData()); + return NULL; + } + // for current item only + if (ScCore->primaryMainWindow()->doc->m_Selection->count() == 0 || name != EMPTY_STRING) + { + // quick hack to always apply on the right frame - pv + ScCore->primaryMainWindow()->view->Deselect(true); + //CB I dont think we need to draw here. Its faster if we dont. + ScCore->primaryMainWindow()->view->SelectItem(item, false); + // Now apply the style. + int mode = ScCore->primaryMainWindow()->doc->appMode; + ScCore->primaryMainWindow()->doc->appMode = modeEdit; + ScCore->primaryMainWindow()->setNewParStyle(QString::fromUtf8(style)); + ScCore->primaryMainWindow()->doc->appMode = mode; + } + else // for multiple selection + { + int mode = ScCore->primaryMainWindow()->doc->appMode; + ScCore->primaryMainWindow()->doc->appMode = modeNormal; + ScCore->primaryMainWindow()->doc->itemSelection_ApplyParagraphStyle(ScCore->primaryMainWindow()->doc->paragraphStyles()[styleid]); + ScCore->primaryMainWindow()->doc->appMode = mode; + } + } + else + { + PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set style on a non-text frame.","python error").toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +/* + * Craig Ringer, 2004-09-09 + * Enumerate all known paragraph styles + */ +PyObject *scribus_getstylenames(PyObject* /* self */) +{ + PyObject *styleList; + if(!checkHaveDocument()) + return NULL; + styleList = PyList_New(0); + for (int i=0; i < ScCore->primaryMainWindow()->doc->paragraphStyles().count(); ++i) + { + if (PyList_Append(styleList, PyString_FromString(ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name().toUtf8()))) + { + // An exception will have already been set by PyList_Append apparently. + return NULL; + } + } + return styleList; +} + +PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args) +{ + char* name = const_cast(""); + if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) { + return NULL; + } + if(!checkHaveDocument()) { + return NULL; + } + // Is there a special name given? Yes -> add this to selection + PageItem *i = GetUniqueItem(QString::fromUtf8(name)); + if (i != NULL) { + ScCore->primaryMainWindow()->doc->m_Selection->clear(); + ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); + } + else + return NULL; + // do the duplicate + ScCore->primaryMainWindow()->slotEditCopy(); + ScCore->primaryMainWindow()->slotEditPaste(); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmdobjdocwarnings() +{ + QStringList s; + s << scribus_newrect__doc__ <=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDOBJ_H +#define CMDOBJ_H + +// Pulls in first +#include "cmdvar.h" + +/** Object related Commands */ + +/*! docstring */ +PyDoc_STRVAR(scribus_newrect__doc__, +QT_TR_NOOP("createRect(x, y, width, height, [\"name\"]) -> string\n\ +\n\ +Creates a new rectangle on the current page and returns its name. The\n\ +coordinates are given in the current measurement units of the document\n\ +(see UNIT constants). \"name\" should be a unique identifier for the object\n\ +because you need this name to reference that object in future. If \"name\"\n\ +is not given Scribus will create one for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +")); +/** Creates a rectangular with params X, Y (base position) + b, h (width, height) and optional name of the object. + */ +PyObject *scribus_newrect(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_newellipse__doc__, +QT_TR_NOOP("createEllipse(x, y, width, height, [\"name\"]) -> string\n\ +\n\ +Creates a new ellipse on the current page and returns its name.\n\ +The coordinates are given in the current measurement units of the document\n\ +(see UNIT constants). \"name\" should be a unique identifier for the object\n\ +because you need this name for further referencing of that object. If \"name\"\n\ +is not given Scribus will create one for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +")); +/** Creates an ellipse with x, y, b and h - name optionally + params. + */ +PyObject *scribus_newellipse(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_newimage__doc__, +QT_TR_NOOP("createImage(x, y, width, height, [\"name\"]) -> string\n\ +\n\ +Creates a new picture frame on the current page and returns its name. The\n\ +coordinates are given in the current measurement units of the document.\n\ +\"name\" should be a unique identifier for the object because you need this\n\ +name for further access to that object. If \"name\" is not given Scribus will\n\ +create one for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +")); +/** Creates an image frame - x, y, b, h and opt. name. */ +PyObject *scribus_newimage(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_newtext__doc__, +QT_TR_NOOP("createText(x, y, width, height, [\"name\"]) -> string\n\ +\n\ +Creates a new text frame on the actual page and returns its name.\n\ +The coordinates are given in the actual measurement unit of the document (see\n\ +UNIT constants). \"name\" should be a unique identifier for the object because\n\ +you need this name for further referencing of that object. If \"name\" is not\n\ +given Scribus will create one for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +")); +/** Creates a text frame - x, y, b, h and opt. name. */ +PyObject *scribus_newtext(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_newline__doc__, +QT_TR_NOOP("createLine(x1, y1, x2, y2, [\"name\"]) -> string\n\ +\n\ +Creates a new line from the point(x1, y1) to the point(x2, y2) and returns\n\ +its name. The coordinates are given in the current measurement unit of the\n\ +document (see UNIT constants). \"name\" should be a unique identifier for the\n\ +object because you need this name for further access to that object. If\n\ +\"name\" is not given Scribus will create one for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +")); +/** Creates a line object - x, y, b, h and opt. name. */ +PyObject *scribus_newline(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_polyline__doc__, +QT_TR_NOOP("createPolyLine(list, [\"name\"]) -> string\n\ +\n\ +Creates a new polyline and returns its name. The points for the polyline are\n\ +stored in the list \"list\" in the following order: [x1, y1, x2, y2...xn. yn].\n\ +The coordinates are given in the current measurement units of the document (see\n\ +UNIT constants). \"name\" should be a unique identifier for the object because\n\ +you need this name for further access to that object. If \"name\" is not given\n\ +Scribus will create one for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +May raise ValueError if an insufficient number of points is passed or if\n\ +the number of values passed don't group into points without leftovers.\n\ +")); +/** Creates a polygon line - list with points and opt. name as params. */ +PyObject *scribus_polyline(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_polygon__doc__, +QT_TR_NOOP("createPolygon(list, [\"name\"]) -> string\n\ +\n\ +Creates a new polygon and returns its name. The points for the polygon are\n\ +stored in the list \"list\" in the following order: [x1, y1, x2, y2...xn. yn].\n\ +At least three points are required. There is no need to repeat the first point\n\ +to close the polygon. The polygon is automatically closed by connecting the\n\ +first and the last point. The coordinates are given in the current measurement\n\ +units of the document (see UNIT constants). \"name\" should be a unique\n\ +identifier for the object because you need this name for further access to that\n\ +object. If \"name\" is not given Scribus will create one for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +May raise ValueError if an insufficient number of points is passed or if\n\ +the number of values passed don't group into points without leftovers.\n\ +")); +/** Creates a polygon - list with points and opt. name as params. */ +PyObject *scribus_polygon(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_bezierline__doc__, +QT_TR_NOOP("createBezierLine(list, [\"name\"]) -> string\n\ +\n\ +Creates a new bezier curve and returns its name. The points for the bezier\n\ +curve are stored in the list \"list\" in the following order:\n\ +[x1, y1, kx1, ky1, x2, y2, kx2, ky2...xn. yn, kxn. kyn]\n\ +In the points list, x and y mean the x and y coordinates of the point and kx\n\ +and ky meaning the control point for the curve. The coordinates are given in\n\ +the current measurement units of the document (see UNIT constants). \"name\"\n\ +should be a unique identifier for the object because you need this name for\n\ +further access to that object. If \"name\" is not given Scribus will create one\n\ +for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +May raise ValueError if an insufficient number of points is passed or if\n\ +the number of values passed don't group into points without leftovers.\n\ +")); +/** Creates a Bezier line - list with points and opt. name as params. */ +PyObject *scribus_bezierline(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_pathtext__doc__, +QT_TR_NOOP("createPathText(x, y, \"textbox\", \"beziercurve\", [\"name\"]) -> string\n\ +\n\ +Creates a new pathText by merging the two objects \"textbox\" and\n\ +\"beziercurve\" and returns its name. The coordinates are given in the current\n\ +measurement unit of the document (see UNIT constants). \"name\" should be a\n\ +unique identifier for the object because you need this name for further access\n\ +to that object. If \"name\" is not given Scribus will create one for you.\n\ +\n\ +May raise NameExistsError if you explicitly pass a name that's already used.\n\ +May raise NotFoundError if one or both of the named base object don't exist.\n\ +")); +/** Joins 2 objects - textframe and line - into text on path. + Uses x, y (base of the new object), name of the text frame, + name of the line and opt. new name as params. */ +PyObject *scribus_pathtext(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_deleteobj__doc__, +QT_TR_NOOP("deleteObject([\"name\"])\n\ +\n\ +Deletes the item with the name \"name\". If \"name\" is not given the currently\n\ +selected item is deleted.\n\ +")); +/** Deletes an object - if is the name given the named object is + deleted else the active object erased. */ +PyObject *scribus_deleteobj(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_textflow__doc__, +QT_TR_NOOP("textFlowMode(\"name\" [, state])\n\ +\n\ +Enables/disables \"Text Flows Around Frame\" feature for object \"name\".\n\ +Called with parameters string name and optional int \"state\" (0 <= state <= 3).\n\ +Setting \"state\" to 0 will disable text flow.\n\ +Setting \"state\" to 1 will make text flow around object frame.\n\ +Setting \"state\" to 2 will make text flow around bounding box.\n\ +Setting \"state\" to 3 will make text flow around contour line.\n\ +If \"state\" is not passed, text flow is toggled.\n\ +")); +/** +Enables/disables "Text Flows Around Object" feature for object. +Called with params string objectName and state 0|1|2|3. +When set to 0 disable flowing, 1 text flows around frame, +2 around bounding box, 3 around contour line. When is second param +empty flowing is reverted. +02/28/2004 petr vanek + */ +PyObject *scribus_textflow(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_objectexists__doc__, +QT_TR_NOOP("objectExists([\"name\"]) -> bool\n\ +\n\ +Test if an object with specified name really exists in the document.\n\ +The optional parameter is the object name. When no object name is given,\n\ +returns True if there is something selected.\n\ +")); +/** +User test if an object with specified name really exists in +the doc. Object name as param. +03/29/2004 petr vanek +ObjectName is now optional. When none set, search for selection... +07/11/2004 pv +*/ +PyObject *scribus_objectexists(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setstyle__doc__, +QT_TR_NOOP("setStyle(\"style\" [, \"name\"])\n\ +\n\ +Apply the named \"style\" to the object named \"name\". If is no object name\n\ +given, it's applied on the selected object.\n\ +")); +/** + Craig Ringer, 2004-09-09 + Apply the named style to the currently selected object. + pv, 2004-09-13, optionaly param objectName + "check the page" stuff + */ +PyObject *scribus_setstyle(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getstylenames__doc__, +QT_TR_NOOP("getAllStyles() -> list\n\ +\n\ +Return a list of the names of all paragraph styles in the current document.\n\ +")); +/** + Craig Ringer, 2004-09-09 + Enumerate all known paragraph styles +*/ +PyObject *scribus_getstylenames(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_duplicateobject__doc__, +QT_TR_NOOP("duplicateObject([\"name\"]) -> string\n\ +\n\ +creates a Duplicate of the selected Object (or Selection Group).\n\ +")); +/** + Christian Hausknecht, 2006-07-12 + duplicate an object +*/ +PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args); + +/* Internal function not intended for general use; no docstring */ +PyObject* scribus_getframetype(PyObject* self, PyObject* args, PyObject* kw); + +#endif + diff --git a/scribus/plugins/scriptplugin/cmdpage.cpp b/scribus/plugins/scriptplugin/cmdpage.cpp new file mode 100644 index 0000000..52ad3f2 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdpage.cpp @@ -0,0 +1,517 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmdpage.h" +#include "cmdutil.h" +#include "page.h" +#include "scribuscore.h" +#include "commonstrings.h" + + +PyObject *scribus_actualpage(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + return PyInt_FromLong(static_cast(ScCore->primaryMainWindow()->doc->currentPageNumber() + 1)); +} + +PyObject *scribus_redraw(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + ScCore->primaryMainWindow()->view->DrawNew(); + qApp->processEvents(); + // Py_INCREF(Py_None); + // return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_pageposition(PyObject* /* self */, PyObject* args) +{ + int e; + if (!PyArg_ParseTuple(args, "i", &e)) + return NULL; + if(!checkHaveDocument()) + return NULL; + e--; + if ((e < 0) || (e > static_cast(ScCore->primaryMainWindow()->doc->Pages->count())-1)) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData()); + return NULL; + } + return PyInt_FromLong(static_cast(ScCore->primaryMainWindow()->doc->locationOfPage(e))); +} + +PyObject *scribus_savepageeps(PyObject* /* self */, PyObject* args) +{ + char *Name; + if (!PyArg_ParseTuple(args, "es", "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + QString epsError; + bool ret = ScCore->primaryMainWindow()->DoSaveAsEps(QString::fromUtf8(Name), epsError); + if (!ret) + { + QString message = QObject::tr("Failed to save EPS.","python error"); + if (!epsError.isEmpty()) + message += QString("\n%1").arg(epsError); + PyErr_SetString(ScribusException, message.toLocal8Bit().constData()); + return NULL; + } +// Py_INCREF(Py_True); // return True not None for backward compat +// return Py_True; +// Py_RETURN_TRUE; + return PyBool_FromLong(static_cast(true)); +} + +PyObject *scribus_deletepage(PyObject* /* self */, PyObject* args) +{ + int e; + if (!PyArg_ParseTuple(args, "i", &e)) + return NULL; + if(!checkHaveDocument()) + return NULL; + e--; + if ((e < 0) || (e > static_cast(ScCore->primaryMainWindow()->doc->Pages->count())-1)) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->DeletePage2(e); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_gotopage(PyObject* /* self */, PyObject* args) +{ + int e; + if (!PyArg_ParseTuple(args, "i", &e)) + return NULL; + if(!checkHaveDocument()) + return NULL; + e--; + if ((e < 0) || (e > static_cast(ScCore->primaryMainWindow()->doc->Pages->count())-1)) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->view->GotoPage(e); +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_newpage(PyObject* /* self */, PyObject* args) +{ + int e; + char *name = const_cast(""); + QString qName(CommonStrings::trMasterPageNormal); + if (!PyArg_ParseTuple(args, "i|es", &e, "utf-8", &name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + + int loc = (e > -1) ? e : ScCore->primaryMainWindow()->doc->Pages->count(); + if (ScCore->primaryMainWindow()->doc->pageSets[ScCore->primaryMainWindow()->doc->currentPageLayout].Columns != 1) + { + switch (ScCore->primaryMainWindow()->doc->locationOfPage(loc)) + { + case LeftPage: + qName = CommonStrings::trMasterPageNormalLeft; + break; + case RightPage: + qName = CommonStrings::trMasterPageNormalRight; + break; + case MiddlePage: + qName = CommonStrings::trMasterPageNormalMiddle; + break; + } + } + if (QString(name).length() != 0) + qName = QString::fromUtf8(name); + + if (!ScCore->primaryMainWindow()->doc->MasterNames.contains(qName)) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Given master page name does not match any existing.","python error").toLocal8Bit().constData()); + return NULL; + } + if (e < 0) + ScCore->primaryMainWindow()->slotNewPageP(loc, qName); + else + { + e--; + if ((e < 0) || (e > static_cast(loc - 1))) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData()); + return NULL; + } + ScCore->primaryMainWindow()->slotNewPageP(e, qName); + } +// Py_INCREF(Py_None); + // return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_pagecount(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + return PyInt_FromLong(static_cast(ScCore->primaryMainWindow()->doc->Pages->count())); +} + +PyObject *scribus_pagedimension(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + PyObject *t; + t = Py_BuildValue( + "(dd)", + PointToValue(ScCore->primaryMainWindow()->doc->pageWidth), // it's just view scale... * ScCore->primaryMainWindow()->doc->Scale), + PointToValue(ScCore->primaryMainWindow()->doc->pageHeight) // * ScCore->primaryMainWindow()->doc->Scale) + ); + return t; +} + +PyObject *scribus_pagensize(PyObject* /* self */, PyObject* args) +{ + int e; + if (!PyArg_ParseTuple(args, "i", &e)) + return NULL; + if(!checkHaveDocument()) + return NULL; + e--; + if ((e < 0) || (e > static_cast(ScCore->primaryMainWindow()->doc->Pages->count())-1)) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData()); + return NULL; + } + PyObject *t; + t = Py_BuildValue( + "(dd)", + PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->width()), + PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->height()) + ); + return t; +} + +PyObject *scribus_pagenmargins(PyObject* /* self */, PyObject* args) +{ + int e; + if (!PyArg_ParseTuple(args, "i", &e)) + return NULL; + if(!checkHaveDocument()) + return NULL; + e--; + if ((e < 0) || (e > static_cast(ScCore->primaryMainWindow()->doc->Pages->count())-1)) + { + PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData()); + return NULL; + } + PyObject *margins = NULL; + margins = Py_BuildValue("ffff", PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->Margins.Top), + PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->Margins.Left), + PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->Margins.Right), + PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->Margins.Bottom)); + return margins; +} + +PyObject *scribus_getpageitems(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + if (ScCore->primaryMainWindow()->doc->Items->count() == 0) + return Py_BuildValue((char*)"[]"); + uint counter = 0; + int pageNr = ScCore->primaryMainWindow()->doc->currentPageNumber(); + for (int lam2 = 0; lam2 < ScCore->primaryMainWindow()->doc->Items->count(); ++lam2) + { + if (pageNr == ScCore->primaryMainWindow()->doc->Items->at(lam2)->OwnPage) + counter++; + } + PyObject *l = PyList_New(counter); + PyObject *row; + counter = 0; + for (int i = 0; iprimaryMainWindow()->doc->Items->count(); ++i) + { + if (pageNr == ScCore->primaryMainWindow()->doc->Items->at(i)->OwnPage) + { + row = Py_BuildValue((char*)"(sii)", + ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8().constData(), + ScCore->primaryMainWindow()->doc->Items->at(i)->itemType(), + ScCore->primaryMainWindow()->doc->Items->at(i)->ItemNr + ); + PyList_SetItem(l, counter, row); + counter++; + } + } // for + return l; +} + +PyObject *scribus_getHguides(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + Guides g = ScCore->primaryMainWindow()->doc->currentPage()->guides.horizontals(GuideManagerCore::Standard); + int n = g.count();//ScCore->primaryMainWindow()->doc->currentPage->YGuides.count(); + if (n == 0) + return Py_BuildValue((char*)"[]"); + int i; + double tmp; + PyObject *l, *guide; + l = PyList_New(0); + for (i=0; iprimaryMainWindow()->doc->currentPage()->guides.clearHorizontals(GuideManagerCore::Standard); + for (i=0; iprimaryMainWindow()->doc->currentPage()->guides.addHorizontal(ValueToPoint(guide), GuideManagerCore::Standard); + } + Py_INCREF(Py_None); + return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_getVguides(PyObject* /* self */) +{ + if(!checkHaveDocument()) + return NULL; + Guides g = ScCore->primaryMainWindow()->doc->currentPage()->guides.verticals(GuideManagerCore::Standard); + int n = g.count();//ScCore->primaryMainWindow()->doc->currentPage->XGuides.count(); + if (n == 0) + return Py_BuildValue((char*)"[]"); + int i; + double tmp; + PyObject *l, *guide; + l = PyList_New(0); + for (i=0; iprimaryMainWindow()->doc->currentPage()->guides.clearVerticals(GuideManagerCore::Standard); + for (i=0; iprimaryMainWindow()->doc->currentPage()->guides.addVertical(ValueToPoint(guide), GuideManagerCore::Standard); + } +// Py_INCREF(Py_None); +// return Py_None; + Py_RETURN_NONE; +} + +PyObject *scribus_getpagemargins(PyObject* /* self */) +{ + PyObject *margins = NULL; + if(!checkHaveDocument()) + return NULL; + margins = Py_BuildValue("ffff", PointToValue(ScCore->primaryMainWindow()->doc->pageMargins.Top), + PointToValue(ScCore->primaryMainWindow()->doc->pageMargins.Left), + PointToValue(ScCore->primaryMainWindow()->doc->pageMargins.Right), + PointToValue(ScCore->primaryMainWindow()->doc->pageMargins.Bottom)); + return margins; +} + +/*! + \fn import_addpages(int total, int pos) + \author Alessandro Pira + \date 11-11-2007 + \param total number of pages to add, pos: position in the document + \param pos position of the imported pages + \retval void + */ +// This function is used by scribus_importpage() to add new pages +void import_addpages(int total, int pos) { + for (int i=0; i ScCore->primaryMainWindow()->doc->Pages->count()) + loc = ScCore->primaryMainWindow()->doc->Pages->count(); + + QString qName(CommonStrings::trMasterPageNormal); + + if (ScCore->primaryMainWindow()->doc->pageSets[ScCore->primaryMainWindow()->doc->currentPageLayout].Columns != 1) { + ScCore->primaryMainWindow()->doc->locationOfPage(loc); + switch (ScCore->primaryMainWindow()->doc->locationOfPage(loc)) + { + case LeftPage: + qName = CommonStrings::trMasterPageNormalLeft; + break; + case RightPage: + qName = CommonStrings::trMasterPageNormalRight; + break; + case MiddlePage: + qName = CommonStrings::trMasterPageNormalMiddle; + break; + } + } + ScCore->primaryMainWindow()->slotNewPageP(locreal, qName); + } +} + +/*! + \fn scribus_importpage(PyObject*, PyObject* args) + \author Alessandro Pira + \date 11-11-2007 + \param PyObject unused reference + \param args Python function args ("fromDoc", (pageList), [create, imortwhere, importwherePage]) + \retval Py_RETURN_NONE if ok, null if error + */ +PyObject *scribus_importpage(PyObject* /* self */, PyObject* args) +{ + char *doc = NULL; + PyObject *pages = NULL; + int createPageI = 1; + int importWhere = 2; + int importWherePage = 0; + + if (!PyArg_ParseTuple(args, "sO|iii", &doc, &pages, &createPageI, &importWhere, &importWherePage)) + return NULL; + if(!checkHaveDocument()) + return NULL; + + if (!PyTuple_Check(pages)) + { + PyErr_SetString(PyExc_TypeError, QObject::tr("second argument is not tuple: must be tuple of int values.","python error").toLocal8Bit().constData()); + return NULL; + } + + Py_INCREF(pages); + std::vector pageNs; + int i, n, p; + n = PyTuple_Size(pages); + for (i=0; iprimaryMainWindow()->doc->masterPageMode()) + { + if (nrToImport > 1) + ScCore->primaryMainWindow()->loadPage(fromDoc, pageNs[0] - 1, false); + doIt = false; + } + else if (createPage) + { + if (importWhere == 0) //Before page + startPage = importWherePage; + else if (importWhere == 1) //After page + startPage = importWherePage + 1; + else //at end + startPage = ScCore->primaryMainWindow()->doc->DocPages.count();// + 1; + + import_addpages(nrToImport, startPage); + } + else + { + startPage = ScCore->primaryMainWindow()->doc->currentPage()->pageNr() + 1; + if (nrToImport > (ScCore->primaryMainWindow()->doc->DocPages.count() - ScCore->primaryMainWindow()->doc->currentPage()->pageNr())) + { + int tmp=nrToImport - (ScCore->primaryMainWindow()->doc->DocPages.count() - ScCore->primaryMainWindow()->doc->currentPage()->pageNr()); + import_addpages(tmp, ScCore->primaryMainWindow()->doc->DocPages.count()); + } + } + + if (doIt) + { + if (nrToImport > 0) + { + int counter = startPage + 1; + for (int i = 0; i < nrToImport; ++i) + { + ScCore->primaryMainWindow()->view->GotoPa(counter); + ScCore->primaryMainWindow()->loadPage(fromDoc, pageNs[i] - 1, false); + counter++; + } + } + } + + Py_RETURN_NONE; +} + + +/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmdpagedocwarnings() +{ + QStringList s; + s << scribus_newpage__doc__ << scribus_pageposition__doc__ + << scribus_actualpage__doc__ << scribus_redraw__doc__ + << scribus_savepageeps__doc__ << scribus_deletepage__doc__ + << scribus_gotopage__doc__ << scribus_pagecount__doc__ + << scribus_getHguides__doc__ << scribus_setHguides__doc__ + << scribus_getVguides__doc__ << scribus_setVguides__doc__ + << scribus_pagedimension__doc__ << scribus_getpageitems__doc__ + << scribus_getpagemargins__doc__ << scribus_importpage__doc__ + << scribus_pagensize__doc__ << scribus_pagenmargins__doc__; +} diff --git a/scribus/plugins/scriptplugin/cmdpage.h b/scribus/plugins/scriptplugin/cmdpage.h new file mode 100644 index 0000000..c3880d5 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdpage.h @@ -0,0 +1,228 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDPAGE_H +#define CMDPAGE_H + +// Pulls in first +#include "cmdvar.h" + +/** Page related Commands */ + +/*! docstring */ +PyDoc_STRVAR(scribus_newpage__doc__, +QT_TR_NOOP("newPage(where [,\"masterpage\"])\n\ +\n\ +Creates a new page. If \"where\" is -1 the new Page is appended to the\n\ +document, otherwise the new page is inserted before \"where\". Page numbers are\n\ +counted from 1 upwards, no matter what the displayed first page number of your\n\ +document is. The optional parameter \"masterpage\" specifies the name of the\n\ +master page for the new page.\n\ +\n\ +May raise IndexError if the page number is out of range\n\ +")); +/*! new page */ +PyObject *scribus_newpage(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_actualpage__doc__, +QT_TR_NOOP("currentPage() -> integer\n\ +\n\ +Returns the number of the current working page. Page numbers are counted from 1\n\ +upwards, no matter what the displayed first page number of your document is.\n\ +")); +/*! get actual page */ +PyObject *scribus_actualpage(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_redraw__doc__, +QT_TR_NOOP("redrawAll()\n\ +\n\ +Redraws all pages.\n\ +")); +/*! redraw all */ +PyObject *scribus_redraw(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_pageposition__doc__, +QT_TR_NOOP("getPageType() -> integer\n\ +\n\ +Returns the type of the Page, 0 means left Page, 1 is a middle Page and 2 is a right Page\n\ +")); +/*! Go to page */ +PyObject *scribus_pageposition(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_savepageeps__doc__, +QT_TR_NOOP("savePageAsEPS(\"name\")\n\ +\n\ +Saves the current page as an EPS to the file \"name\".\n\ +\n\ +May raise ScribusError if the save failed.\n\ +")); +/*! Export page as EPS file */ +PyObject *scribus_savepageeps(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_deletepage__doc__, +QT_TR_NOOP("deletePage(nr)\n\ +\n\ +Deletes the given page. Does nothing if the document contains only one page.\n\ +Page numbers are counted from 1 upwards, no matter what the displayed first\n\ +page number is.\n\ +\n\ +May raise IndexError if the page number is out of range\n\ +")); +/*! Delete page */ +PyObject *scribus_deletepage(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_gotopage__doc__, +QT_TR_NOOP("gotoPage(nr)\n\ +\n\ +Moves to the page \"nr\" (that is, makes the current page \"nr\"). Note that\n\ +gotoPage doesn't (currently) change the page the user's view is displaying, it\n\ +just sets the page that script commands will operates on.\n\ +\n\ +May raise IndexError if the page number is out of range.\n\ +")); +/*! Go to page */ +PyObject *scribus_gotopage(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_pagecount__doc__, +QT_TR_NOOP("pageCount() -> integer\n\ +\n\ +Returns the number of pages in the document.\n\ +")); +/*! Go to page */ +PyObject *scribus_pagecount(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_getHguides__doc__, +QT_TR_NOOP("getHGuides() -> list\n\ +\n\ +Returns a list containing positions of the horizontal guides. Values are in the\n\ +document's current units - see UNIT_ constants.\n\ +")); +/*! get H guides */ +PyObject *scribus_getHguides(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_setHguides__doc__, +QT_TR_NOOP("setHGuides(list)\n\ +\n\ +Sets horizontal guides. Input parameter must be a list of guide positions\n\ +measured in the current document units - see UNIT_ constants.\n\ +\n\ +Example: setHGuides(getHGuides() + [200.0, 210.0] # add new guides without any lost\n\ + setHGuides([90,250]) # replace current guides entirely\n\ +")); +/*! set H guides */ +PyObject *scribus_setHguides(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getVguides__doc__, +QT_TR_NOOP("getVGuides()\n\ +\n\ +See getHGuides.\n\ +")); +/*! get V guides */ +PyObject *scribus_getVguides(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_setVguides__doc__, +QT_TR_NOOP("setVGuides()\n\ +\n\ +See setHGuides.\n\ +")); +/*! set V guides */ +PyObject *scribus_setVguides(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_pagedimension__doc__, +QT_TR_NOOP("getPageSize() -> tuple\n\ +\n\ +Returns a tuple with document page dimensions measured in the document's current units.\n\ +See UNIT_ constants and getPageMargins()\n\ +")); +/** +returns a tuple with page domensions in used system +e.g. when is the doc in picas returns picas ;) +(Petr Vanek 02/17/04) +*/ +PyObject *scribus_pagedimension(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_pagensize__doc__, +QT_TR_NOOP("getPageNSize(nr) -> tuple\n\ +\n\ +Returns a tuple with a particular page's size measured in the document's current units.\n\ +See UNIT_ constants and getPageMargins()\n\ +")); +/** +returns a tuple with a particular page's size in used system +e.g. when is the doc in picas returns picas ;) +*/ +PyObject *scribus_pagensize(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getpagemargins__doc__, +QT_TR_NOOP("getPageMargins()\n\ +\n\ +Returns the document page margins as a (top, left, right, bottom) tuple in the document's current\n\ +units. See UNIT_ constants and getPageSize().\n\ +")); +/** +returns a tuple with page margins +Craig Ringer, Petr Vanek 09/25/2004 +*/ +PyObject *scribus_getpagemargins(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_pagenmargins__doc__, +QT_TR_NOOP("getPageNMargins(nr) -> tuple\n\ +\n\ +Returns a tuple with a particular page's margins measured in the document's current units.\n\ +See UNIT_ constants and getPageMargins()\n\ +")); +/** +returns a tuple with a particular page's size in used system +e.g. when is the doc in picas returns picas ;) +*/ +PyObject *scribus_pagenmargins(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_getpageitems__doc__, +QT_TR_NOOP("getPageItems() -> list\n\ +\n\ +Returns a list of tuples with items on the current page. The tuple is:\n\ +(name, objectType, order) E.g. [('Text1', 4, 0), ('Image1', 2, 1)]\n\ +means that object named 'Text1' is a text frame (type 4) and is the first at\n\ +the page...\n\ +")); +/** +returns a list of tuples with items on the actual page +TODO: solve utf/iso chars in object names +(Petr Vanek 03/02/2004) +*/ +PyObject *scribus_getpageitems(PyObject * /*self*/); + +/*! importpage */ +PyDoc_STRVAR(scribus_importpage__doc__, +QT_TR_NOOP("importPage(\"fromDoc\", (pageList), [create, imortwhere, importwherePage])\n\ +\n\ +Imports a set of pages (given as a tuple) from an existing document (the file name must be given). This functions maps the \"Page->Import\" dropdown menu function.\n\ +fromDoc: string; the filename of the document to import pages from\n\ +pageList: tuple with page numbers of pages to import\n\ +create: number; 0 to replace existing pages, 1 (default) to insert new pages\n\ +importWhere: number; the page number (of the current document) at which import the pages\n\ +importWherePage: number; used if create==1; 0 to create pages before selected page; 1 to create pages after selected page; 2 (default) to create pages at the end of the document\n\ +")); +PyObject *scribus_importpage(PyObject */*self*/, PyObject* args); + +#endif + diff --git a/scribus/plugins/scriptplugin/cmdsetprop.cpp b/scribus/plugins/scriptplugin/cmdsetprop.cpp new file mode 100644 index 0000000..2f82272 --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdsetprop.cpp @@ -0,0 +1,398 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#include "cmdsetprop.h" +#include "cmdutil.h" +#include "scribuscore.h" + +PyObject *scribus_setgradfill(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Color1; + char *Color2; + int typ, shade1, shade2; + if (!PyArg_ParseTuple(args, "iesiesi|es", &typ, "utf-8", &Color1, &shade1, "utf-8", &Color2, &shade2, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((shade1 < 0) || (shade1 > 100) || (shade2 < 0) || (shade2 > 100)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Stop shade out of bounds, must be 0 <= shade <= 100.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name)); + if (currItem == NULL) + return NULL; + QColor tmp; + currItem->fill_gradient.clearStops(); + QString c1 = QString::fromUtf8(Color1); + QString c2 = QString::fromUtf8(Color2); + currItem->SetQColor(&tmp, c1, shade1); + currItem->fill_gradient.addStop(tmp, 0.0, 0.5, 1.0, c1, shade1); + currItem->SetQColor(&tmp, c2, shade2); + currItem->fill_gradient.addStop(tmp, 1.0, 0.5, 1.0, c2, shade2); + currItem->GrType = typ; + switch (currItem->GrType) + { + case 0: + case 1: + currItem->GrStartX = 0; + currItem->GrStartY = currItem->height() / 2.0; + currItem->GrEndX = currItem->width(); + currItem->GrEndY = currItem->height() / 2.0; + break; + case 2: + currItem->GrStartX = currItem->width() / 2.0; + currItem->GrStartY = 0; + currItem->GrEndX = currItem->width() / 2.0; + currItem->GrEndY = currItem->height(); + break; + case 3: + currItem->GrStartX = 0; + currItem->GrStartY = 0; + currItem->GrEndX = currItem->width(); + currItem->GrEndY = currItem->height(); + break; + case 4: + currItem->GrStartX = 0; + currItem->GrStartY = currItem->height(); + currItem->GrEndX = currItem->width(); + currItem->GrEndY = 0; + break; + case 5: + currItem->GrStartX = currItem->width() / 2.0; + currItem->GrStartY = currItem->height() / 2.0; + if (currItem->width() >= currItem->height()) + { + currItem->GrEndX = currItem->width(); + currItem->GrEndY = currItem->height() / 2.0; + } + else + { + currItem->GrEndX = currItem->width() / 2.0; + currItem->GrEndY = currItem->height(); + } + break; + default: + break; + } + //ScCore->primaryMainWindow()->view->updateGradientVectors(currItem); + currItem->updateGradientVectors(); + currItem->update(); + Py_RETURN_NONE; +} + +PyObject *scribus_setgradstop(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Color1; + int shade1; + double rampPoint, opacity; + if (!PyArg_ParseTuple(args, "esidd|es", "utf-8", &Color1, &shade1, &opacity, &rampPoint, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((shade1 < 0) || (shade1 > 100)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Stop shade out of bounds, must be 0 <= shade <= 100.","python error").toLocal8Bit().constData()); + return NULL; + } + if ((rampPoint < 0.0) || (rampPoint > 1.0)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Ramp point out of bounds, must be 0 <= rampPoint <= 1.","python error").toLocal8Bit().constData()); + return NULL; + } + if ((opacity < 0.0) || (opacity > 1.0)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Opacity out of bounds, must be 0 <= transparency <= 1.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name)); + if (currItem == NULL) + return NULL; + QColor tmp; + QString c1 = QString::fromUtf8(Color1); + currItem->SetQColor(&tmp, c1, shade1); + currItem->fill_gradient.setStop(tmp, rampPoint, 0.5, opacity, c1, shade1); + currItem->updateGradientVectors(); + currItem->update(); + Py_RETURN_NONE; +} + +PyObject *scribus_setfillcolor(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Color; + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->setFillColor(QString::fromUtf8(Color)); + Py_RETURN_NONE; +} + +PyObject *scribus_setfilltrans(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double w; + if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((w < 0.0) || (w > 1.0)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Transparency out of bounds, must be 0 <= transparency <= 1.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->setFillTransparency(1.0 - w); + Py_RETURN_NONE; +} + +PyObject *scribus_setfillblend(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int w; + if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((w < 0) || (w > 15)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Blendmode out of bounds, must be 0 <= blendmode <= 15.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->setFillBlendmode(w); + Py_RETURN_NONE; +} + +PyObject *scribus_setlinecolor(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Color; + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); + if (it == NULL) + return NULL; + it->setLineColor(QString::fromUtf8(Color)); + Py_RETURN_NONE; +} + +PyObject *scribus_setlinetrans(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double w; + if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((w < 0.0) || (w > 1.0)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Transparency out of bounds, must be 0 <= transparency <= 1.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->setLineTransparency(1.0 - w); + Py_RETURN_NONE; +} + +PyObject *scribus_setlineblend(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int w; + if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((w < 0) || (w > 15)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Blendmode out of bounds, must be 0 <= blendmode <= 15.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->setLineBlendmode(w); + Py_RETURN_NONE; +} + +PyObject *scribus_setlinewidth(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + double w; + if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((w < 0.0) || (w > 300.0)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Line width out of bounds, must be 0 <= line_width <= 300.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->setLineWidth(w); + Py_RETURN_NONE; +} + +PyObject *scribus_setlineshade(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int w; + if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((w < 0) || (w > 100)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Line shade out of bounds, must be 0 <= shade <= 100.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); + if (it == NULL) + return NULL; + it->setLineShade(w); + Py_RETURN_NONE; +} + +PyObject *scribus_setfillshade(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int w; + if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if ((w < 0) || (w > 100)) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Fill shade out of bounds, must be 0 <= shade <= 100.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->setFillShade(w); + Py_RETURN_NONE; +} + +PyObject *scribus_setlinejoin(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int w; + if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->PLineJoin = Qt::PenJoinStyle(w); + Py_RETURN_NONE; +} + +PyObject *scribus_setlinecap(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int w; + if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->PLineEnd = Qt::PenCapStyle(w); + Py_RETURN_NONE; +} + +PyObject *scribus_setlinestyle(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int w; + if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); + if (i == NULL) + return NULL; + i->PLineArt = Qt::PenStyle(w); + Py_RETURN_NONE; +} + +PyObject *scribus_setcornerrad(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + int w; + if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + if (w < 0) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Corner radius must be a positive number.","python error").toLocal8Bit().constData()); + return NULL; + } + PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name)); + if (currItem == NULL) + return NULL; + // apply rounding + currItem->setCornerRadius(w); + currItem->SetFrameRound(); + ScCore->primaryMainWindow()->doc->setRedrawBounding(currItem); + ScCore->primaryMainWindow()->view->SetFrameRounded(); + Py_RETURN_NONE; +} + +PyObject *scribus_setmultiline(PyObject* /* self */, PyObject* args) +{ + char *Name = const_cast(""); + char *Style = NULL; + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Style, "utf-8", &Name)) + return NULL; + if(!checkHaveDocument()) + return NULL; + PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name)); + if (currItem == NULL) + return NULL; + if (!ScCore->primaryMainWindow()->doc->MLineStyles.contains(QString::fromUtf8(Style))) + { + PyErr_SetString(NotFoundError, QObject::tr("Line style not found.","python error").toLocal8Bit().constData()); + return NULL; + } + currItem->NamedLStyle = QString::fromUtf8(Style); + Py_RETURN_NONE; +} + +/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings +with header files structure untouched (docstrings are kept near declarations) +PV */ +void cmdsetpropdocwarnings() +{ + QStringList s; + s << scribus_setgradfill__doc__ << scribus_setgradstop__doc__ + << scribus_setfillcolor__doc__ << scribus_setfilltrans__doc__ + << scribus_setfillblend__doc__ << scribus_setlinecolor__doc__ + << scribus_setlinetrans__doc__ << scribus_setlineblend__doc__ + << scribus_setlinewidth__doc__ << scribus_setlineshade__doc__ + << scribus_setlinejoin__doc__ << scribus_setlinecap__doc__ + << scribus_setlinestyle__doc__ << scribus_setfillshade__doc__ + << scribus_setcornerrad__doc__ << scribus_setmultiline__doc__; +} diff --git a/scribus/plugins/scriptplugin/cmdsetprop.h b/scribus/plugins/scriptplugin/cmdsetprop.h new file mode 100644 index 0000000..991608c --- /dev/null +++ b/scribus/plugins/scriptplugin/cmdsetprop.h @@ -0,0 +1,197 @@ +/* +For general Scribus (>=1.3.2) copyright and licensing information please refer +to the COPYING file provided with the program. Following this notice may exist +a copyright and/or license notice that predates the release of Scribus 1.3.2 +for which a new license (GPL+exception) is in place. +*/ +#ifndef CMDSETPROP_H +#define CMDSETPROP_H + +// Pulls in first +#include "cmdvar.h" + +/** Setting Object Properties */ + +/*! docstring */ +PyDoc_STRVAR(scribus_setgradfill__doc__, +QT_TR_NOOP("setGradientFill(type, \"color1\", shade1, \"color2\", shade2, [\"name\"])\n\ +\n\ +Sets the gradient fill of the object \"name\" to type. Color descriptions are\n\ +the same as for setFillColor() and setFillShade(). See the constants for\n\ +available types (FILL_).\n\ +")); +/*! Set gradient */ +PyObject *scribus_setgradfill(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setgradstop__doc__, +QT_TR_NOOP("setGradientStop(\"color\", shade, opacity, ramppoint, [\"name\"])\n\ +\n\ +Set or add a gradient stop to the gradient fill of the object \"name\" at position ramppoint.\n\ +Color descriptions are the same as for setFillColor() and setFillShade(). setGradientFill()\n\ +must have been called previously for the gradient fill to be visible.\n\ +")); +/*! Set gradient */ +PyObject *scribus_setgradstop(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setfillcolor__doc__, +QT_TR_NOOP("setFillColor(\"color\", [\"name\"])\n\ +\n\ +Sets the fill color of the object \"name\" to the color \"color\". \"color\"\n\ +is the name of one of the defined colors. If \"name\" is not given the\n\ +currently selected item is used.\n\ +")); +/*! Set fill color */ +PyObject *scribus_setfillcolor(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setfilltrans__doc__, +QT_TR_NOOP("setFillTransparency(transparency, [\"name\"])\n\ +\n\ +Sets the fill transparency of the object \"name\" to transparency\n\ +If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Set fill transparency */ +PyObject *scribus_setfilltrans(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setfillblend__doc__, +QT_TR_NOOP("setFillBlendmode(blendmode, [\"name\"])\n\ +\n\ +Sets the fill blendmode of the object \"name\" to blendmode\n\ +If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Set fill blendmode */ +PyObject *scribus_setfillblend(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setlinecolor__doc__, +QT_TR_NOOP("setLineColor(\"color\", [\"name\"])\n\ +\n\ +Sets the line color of the object \"name\" to the color \"color\". If \"name\"\n\ +is not given the currently selected item is used.\n\ +")); +/*! Set line color */ +PyObject *scribus_setlinecolor(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setlinetrans__doc__, +QT_TR_NOOP("setLineTransparency(transparency, [\"name\"])\n\ +\n\ +Sets the line transparency of the object \"name\" to transparency\n\ +If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Set line transparency */ +PyObject *scribus_setlinetrans(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setlineblend__doc__, +QT_TR_NOOP("setLineBlendmode(blendmode, [\"name\"])\n\ +\n\ +Sets the line blendmode of the object \"name\" to blendmode\n\ +If \"name\" is not given the currently selected item is used.\n\ +")); +/*! Set line blendmode */ +PyObject *scribus_setlineblend(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setlinewidth__doc__, +QT_TR_NOOP("setLineWidth(width, [\"name\"])\n\ +\n\ +Sets line width of the object \"name\" to \"width\". \"width\" must be in the\n\ +range from 0.0 to 12.0 inclusive, and is measured in points. If \"name\" is not\n\ +given the currently selected item is used.\n\ +\n\ +May raise ValueError if the line width is out of bounds.\n\ +")); +/*! Set line width */ +PyObject *scribus_setlinewidth(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setlineshade__doc__, +QT_TR_NOOP("setLineShade(shade, [\"name\"])\n\ +\n\ +Sets the shading of the line color of the object \"name\" to \"shade\".\n\ +\"shade\" must be an integer value in the range from 0 (lightest) to 100\n\ +(full color intensity). If \"name\" is not given the currently selected item\n\ +is used.\n\ +\n\ +May raise ValueError if the line shade is out of bounds.\n\ +")); +/*! Set line shade */ +PyObject *scribus_setlineshade(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setlinejoin__doc__, +QT_TR_NOOP("setLineJoin(join, [\"name\"])\n\ +\n\ +Sets the line join style of the object \"name\" to the style \"join\".\n\ +If \"name\" is not given the currently selected item is used. There are\n\ +predefined constants for join - JOIN_.\n\ +")); +/*! Set line join */ +PyObject *scribus_setlinejoin(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setlinecap__doc__, +QT_TR_NOOP("setLineCap(endtype, [\"name\"])\n\ +\n\ +Sets the line cap style of the object \"name\" to the style \"cap\".\n\ +If \"name\" is not given the currently selected item is used. There are\n\ +predefined constants for \"cap\" - CAP_.\n\ +")); +/*! Set line end */ +PyObject *scribus_setlinecap(PyObject * /*self*/, PyObject* args); + +/*! docstring */ +PyDoc_STRVAR(scribus_setlinestyle__doc__, +QT_TR_NOOP("setLineStyle(style, [\"name\"])\n\ +\n\ +Sets the line style of the object \"name\" to the style \"style\". If \"name\"\n\ +is not given the currently selected item is used. There are predefined\n\ +constants for \"style\" - LINE_