diff options
| author | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-01 11:40:09 +0000 |
|---|---|---|
| committer | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-01 11:40:09 +0000 |
| commit | 7ed83b6c6666eb8b6b104c211ae7e52907350372 (patch) | |
| tree | 4430b556abac0ad660a0aacf1887d77f85d8be02 /scribus/plugins/scriptplugin/scripter2 | |
| download | scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.gz scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.xz scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.zip | |
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
Diffstat (limited to 'scribus/plugins/scriptplugin/scripter2')
16 files changed, 967 insertions, 0 deletions
diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_base.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_base.cpp new file mode 100644 index 0000000..e6f1100 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_base.cpp @@ -0,0 +1,85 @@ +/* +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 "cmdvar.h" + +#include "scribusstructs.h" + +using namespace boost::python; + +// Declare the export functions from the implementation +extern void export_QString(); +extern void export_QObject(); +extern void export_QWidget(); +extern void export_QFrame(); +extern void export_QScrollView(); +extern void export_QMainWindow(); +extern void export_QApplication(); + +extern void export_ScribusStructs(); +extern void export_PageItem(); +extern void export_ScribusMainWindow(); +extern void export_ScribusQApp(); +extern void export_ScribusWin(); +extern void export_ScribusDoc(); +extern void export_ScribusView(); + +extern void export_styles(); + +/** + * @brief A simple test function to wrap with Boost::Python + */ +int add_five(int x) +{ + return x+5; +} + +/** + * @brief Define the scribus2 module + */ +BOOST_PYTHON_MODULE(scribus2) +{ + qDebug("Exporting scribus2"); + + // Export our basic testing function + def("add_five", add_five); + + // Export type converters + export_QString(); + + // And Qt classes + export_QObject(); + export_QApplication(); + export_QWidget(); + export_QFrame(); + export_QScrollView(); + export_QMainWindow(); + + // Export Scribus types + export_ScribusStructs(); + export_ScribusQApp(); + export_ScribusDoc(); + export_ScribusView(); + export_ScribusWin(); + export_ScribusMainWindow(); + export_PageItem(); + + // Export access functions and dirty hacks + export_styles(); + + qDebug("Done"); +} + +/** + * @brief Initialize the module, including calling initscribus2() + * + * This method should be a no-op if we've been built without support + * for Boost::Python + */ +void scripter2_init() +{ + initscribus2(); +} diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qapplication.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qapplication.cpp new file mode 100644 index 0000000..9a7d088 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qapplication.cpp @@ -0,0 +1,37 @@ +/* +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 "cmdvar.h" + +#include <QSpplication> + +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(QApplication_processEvents_overloads, QApplication::processEvents, 0, 1) + +void QApplication_processEvents(QApplication& app) +{ + app.processEvents(); +} + +void QApplication_processEventsT(QApplication& app, int maxtime) +{ + app.processEvents(maxtime); +} + +void export_QApplication() +{ + using namespace boost::python; + + class_<QApplication,boost::noncopyable>( + "QApplication", + "The base Qt application class", + no_init) + //.def("exec", &QApplication::exec); // BAD PLAN to expose this + //.def("processEvents", &QApplication::processEvents); + .def("processEvents", &QApplication_processEvents) + .def("processEventsT", &QApplication_processEventsT); + + scope().attr("qApp") = boost::ref(qApp); +} diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qframe.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qframe.cpp new file mode 100644 index 0000000..84ef8b7 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qframe.cpp @@ -0,0 +1,20 @@ +/* +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 "cmdvar.h" + +#include <QFrame> + +void export_QFrame() +{ + using namespace boost::python; + + class_<QFrame,bases<QWidget>,boost::noncopyable>( + "QFrame", + "A generic Qt frame widget"); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qmainwindow.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qmainwindow.cpp new file mode 100644 index 0000000..d6b6091 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qmainwindow.cpp @@ -0,0 +1,20 @@ +/* +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 "cmdvar.h" + +#include <QMainWindow> + +void export_QMainWindow() +{ + using namespace boost::python; + + class_<QMainWindow,bases<QWidget>,boost::noncopyable>( + "QMainWindow", + "A Qt main window widget"); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qobject.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qobject.cpp new file mode 100644 index 0000000..013fe51 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qobject.cpp @@ -0,0 +1,22 @@ +/* +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 "cmdvar.h" + +#include <QWidget> + + + +void export_QObject() +{ + using namespace boost::python; + + class_<QObject, boost::noncopyable>( + "QObject", + "A generic Qt object"); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qscrollview.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qscrollview.cpp new file mode 100644 index 0000000..e8ff1f8 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qscrollview.cpp @@ -0,0 +1,21 @@ +/* +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 "cmdvar.h" + +#include <QScrollView> +#include <QFrame> + +void export_QScrollView() +{ + using namespace boost::python; + + class_<QScrollView,bases<QFrame>,boost::noncopyable>( + "QScrollView", + "A generic Qt scroll view widget"); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qwidget.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qwidget.cpp new file mode 100644 index 0000000..4a25c89 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_qtclass_qwidget.cpp @@ -0,0 +1,24 @@ +/* +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 "cmdvar.h" + +#include <QWidget> + + + +void export_QWidget() +{ + using namespace boost::python; + + class_<QWidget,bases<QObject>,boost::noncopyable>( + "QWidget", + "A generic Qt widget") + .def("show", &QWidget::show) + .def("hide", &QWidget::hide); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_qttype_qstring.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_qttype_qstring.cpp new file mode 100644 index 0000000..8672ddd --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_qttype_qstring.cpp @@ -0,0 +1,124 @@ +/* +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 "cmdvar.h" + +#include <QString> +#include <wchar.h> + + + +// Shamelessly cribbed from code in python-qt4 +// Originally by Eric Jardim <ericjardim@gmail.com> +// Rewritten by Craig Ringer <craig@postnewspapers.com.au> +// Ported to Scribus and Qt3 by Craig Ringer <craig@postnewspapers.com.au> + +using namespace boost::python; +/** + * @brief Boost::Python type converter for QString to Python `unicode' object + */ +struct QString_to_python_unicode +{ + static PyObject* + convert(QString const& s) + { + //FIXME: Done with Python/C API, needs Boost::Python-ifying + //FIXME: UCS-4 case can probably be done a lot more effciently. +#if defined(Py_UNICODE_WIDE) + //qDebug("Py_UNICODE_WIDE"); + int unichars = s.length(); + Py_UNICODE* buf = new Py_UNICODE[unichars]; + for (int i = 0; i < unichars; i++) + buf[i] = s.at(i).unicode(); + PyObject* tempObj = PyUnicode_FromUnicode(buf, unichars); + delete[] buf; + return tempObj; +#else + return PyUnicode_FromUnicode(s.utf16(), s.length()); +#endif + } +}; + + +/** + * @brief Boost::Python type converter for Python `unicode' or `str' to QString + */ +struct QString_from_python_str_or_unicode +{ + QString_from_python_str_or_unicode() + { + boost::python::converter::registry::push_back( &convertible, + &construct, + boost::python::type_id<QString>() ); + } + + static void* + convertible(PyObject* obj_ptr) + { + if (! (PyUnicode_Check(obj_ptr) || PyString_Check(obj_ptr)) ) + return 0; + return obj_ptr; + } + + static void + construct( PyObject* obj_ptr, + boost::python::converter::rvalue_from_python_stage1_data* data) + { + // First, convert the input to Python `unicode'. + PyObject* temp_obj_ptr; + if (PyString_Check(obj_ptr)) + { + // Coerce the `str' to `unicode' using sysdefaultencoding. UnicodeDecodeError + // is thrown if the string doesn't make sense in that encoding. + temp_obj_ptr = PyUnicode_FromObject(obj_ptr); // new reference + if (temp_obj_ptr == 0) + { + boost::python::throw_error_already_set(); + } + } + else + { + temp_obj_ptr = obj_ptr; + Py_INCREF(temp_obj_ptr); // to balance DECREF at end + } + + // FIXME: This implementation is probably rather inefficient + Py_UNICODE* value = PyUnicode_AsUnicode(temp_obj_ptr); + if (value == 0) + { + boost::python::throw_error_already_set(); + } + int unichars = PyUnicode_GET_SIZE(temp_obj_ptr); +#if defined(Py_UNICODE_WIDE) + + // Python is using a 4-byte unsigned buffer of UCS-4 + // FIXME: Qt doesn't give us any direct way to load UCS-4, so we're doing + // it a rather clunky way that can probably be improved. + // FIXME: Qt can't represent UCS-4 characters; we need to check for this + // and throw an exception. + QString tempString(""); + int i; + for (i = 0; i < unichars; i++) + tempString.append(QChar(value[i])); +#else + // Python is using a 2-byte unsigned buffer of UCS-2 with + // limited support for UTF-16 + QString tempString(QString::fromUtf16(value, unichars)); +#endif + Py_DECREF(temp_obj_ptr); + void* storage = ((boost::python::converter::rvalue_from_python_storage<QString>*) data)->storage.bytes; + new (storage) QString(tempString); + data->convertible = storage; + } +}; + +void export_QString() +{ + boost::python::to_python_converter<QString, QString_to_python_unicode>(); + QString_from_python_str_or_unicode(); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_pageitem.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_pageitem.cpp new file mode 100644 index 0000000..4d0c1f2 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_pageitem.cpp @@ -0,0 +1,302 @@ +/* +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 "cmdvar.h" + + + +#include "scribus.h" +#include "scribusdoc.h" +#include "pageitem.h" +#include <QList> + +using boost::python::list; +using boost::python::throw_error_already_set; + +PageItem & findItemByName(QList<PageItem*> & items, const QString name) +{ + for ( + QList<PageItem*>::iterator it(items.begin()) ; + it != items.end() ; + ++it) + { + if ( (*it)->itemName() == name) + return *(*it); + } + PyErr_SetString(PyExc_KeyError, "Item not found"); + throw_error_already_set(); +} + +PageItem & getItem(const QString name) +{ + return findItemByName(ScCore->primaryMainWindow()->doc->DocItems, name); +} + +list getItemNames() +{ + list l; + QList<PageItem*>& items( ScCore->primaryMainWindow()->doc->DocItems ); + for ( + QList<PageItem*>::iterator it(items.begin()) ; + it != items.end() ; + ++it) + { + l.append((*it)->itemName()); + } + return l; +} + +void export_PageItem() +{ + using namespace boost::python; + + def("getItemNames", getItemNames); + def("getItem", getItem, return_internal_reference<>()); + + { + scope p = class_<PageItem,boost::noncopyable>( + "PageItem", + "A Scribus canvas object", + no_init) + .def("clearContents", &PageItem::clearContents) + .def("AdjustPictScale", &PageItem::AdjustPictScale) + //TODO Needs: ObjAttrVector, Problem: pointer return + //.def("getObjectAttributes", &PageItem::getObjectAttributes, + //TODO Needs: ObjectAttribute + .def("getObjectAttribute", &PageItem::getObjectAttribute) + .def("setObjectAttributes", &PageItem::setObjectAttributes) + .def("SetFrameShape", &PageItem::SetFrameShape) + .def("SetRectFrame", &PageItem::SetRectFrame) + .def("SetOvalFrame", &PageItem::SetOvalFrame) + .def("SetFrameRound", &PageItem::SetFrameRound) + .def("SetPolyClip", &PageItem::SetPolyClip) + .def("getBoundingRect", &PageItem::getBoundingRect) + .def("pointWithinItem", &PageItem::pointWithinItem) + //.def("SetZeichAttr", &PageItem::SetZeichAttr) // WTF? + .def("SetFarbe", &PageItem::SetFarbe) + .def_readwrite("AspectRatio", &PageItem::AspectRatio) + .def_readwrite("AutoName", &PageItem::AutoName) + .def_readwrite("BottomLine", &PageItem::BottomLine) + .def_readwrite("ChangedMasterItem", &PageItem::ChangedMasterItem) + .def_readwrite("ClipEdited", &PageItem::ClipEdited) + .def_readwrite("Dirty", &PageItem::Dirty) + .def_readwrite("fillRule", &PageItem::fillRule) + .def_readwrite("Frame", &PageItem::Frame) + .def_readwrite("FrameOnly", &PageItem::FrameOnly) + .def_readwrite("HasSel", &PageItem::HasSel) + .def_readwrite("isAutoText", &PageItem::isAutoText) + .def_readwrite("isBookmark", &PageItem::isBookmark) + .def_readwrite("isEmbedded", &PageItem::isEmbedded) + .def_readwrite("isRaster", &PageItem::isRaster) + .def_readwrite("isSingleSel", &PageItem::isSingleSel) + .def_readwrite("isTableItem", &PageItem::isTableItem) + .def_readwrite("LeftLine", &PageItem::LeftLine) + .def_readwrite("PicArt", &PageItem::PicArt) + .def_readwrite("PictureIsAvailable", &PageItem::PictureIsAvailable) + .def_readwrite("PoShow", &PageItem::PoShow) + .def_readwrite("Redrawn", &PageItem::Redrawn) + .def_readwrite("RightLine", &PageItem::RightLine) + .def_readwrite("ScaleType", &PageItem::ScaleType) + .def_readwrite("Sizing", &PageItem::Sizing) + .def_readwrite("Tinput", &PageItem::Tinput) + .def_readwrite("toPixmap", &PageItem::toPixmap) + .def_readwrite("TopLine", &PageItem::TopLine) + .def_readwrite("UseEmbedded", &PageItem::UseEmbedded) + .def_readwrite("BaseOffs", &PageItem::BaseOffs) + .def_readwrite("BBoxH", &PageItem::BBoxH) + .def_readwrite("BBoxX", &PageItem::BBoxX) + .def_readwrite("BoundingH", &PageItem::BoundingH) + .def_readwrite("BoundingW", &PageItem::BoundingW) + .def_readwrite("BoundingX", &PageItem::BoundingX) + .def_readwrite("BoundingY", &PageItem::BoundingY) + .def_readwrite("ColGap", &PageItem::ColGap) + .def_readwrite("CurX", &PageItem::CurX) + .def_readwrite("CurY", &PageItem::CurY) + .def_readwrite("DashOffset", &PageItem::DashOffset) + .def_readwrite("gHeight", &PageItem::gHeight) + .def_readwrite("GrEndX", &PageItem::GrEndX) + .def_readwrite("GrEndY", &PageItem::GrEndY) + .def_readwrite("GrStartX", &PageItem::GrStartX) + .def_readwrite("GrStartY", &PageItem::GrStartY) + .def_readwrite("gWidth", &PageItem::gWidth) + .def_readwrite("gXpos", &PageItem::gXpos) + .def_readwrite("gYpos", &PageItem::gYpos) + .def_readwrite("LineSp", &PageItem::LineSp) + .def_readwrite("OldB", &PageItem::OldB) + .def_readwrite("OldB2", &PageItem::OldB2) + .def_readwrite("OldH", &PageItem::OldH) + .def_readwrite("OldH2", &PageItem::OldH2) + .def_readwrite("OldPwidth", &PageItem::OldPwidth) + .def_readwrite("Pwidth", &PageItem::Pwidth) + .def_readwrite("ContourLine", &PageItem::ContourLine) + .def_readwrite("imageClip", &PageItem::imageClip) + .def_readwrite("PoLine", &PageItem::PoLine) + .def_readwrite("BottomLinkID", &PageItem::BottomLinkID) + .def_readwrite("Cols", &PageItem::Cols) + .def_readwrite("CPos", &PageItem::CPos) + .def_readwrite("ExtraV", &PageItem::ExtraV) + .def_readwrite("FrameType", &PageItem::FrameType) + .def_readwrite("GrType", &PageItem::GrType) + .def_readwrite("IRender", &PageItem::IRender) + .def_readwrite("LayerNr", &PageItem::LayerNr) + .def_readwrite("LeftLinkID", &PageItem::LeftLinkID) + .def_readwrite("LineSpMode", &PageItem::LineSpMode) + .def_readwrite("NextIt", &PageItem::NextIt) + .def_readwrite("NextPg", &PageItem::NextPg) + .def_readwrite("oldOwnPage", &PageItem::oldOwnPage) + .def_readwrite("OrigH", &PageItem::OrigH) + .def_readwrite("OrigW", &PageItem::OrigW) + .def_readwrite("OwnPage", &PageItem::OwnPage) + .def_readwrite("RightLinkID", &PageItem::RightLinkID) + .def_readwrite("ShTxtFill", &PageItem::ShTxtFill) + .def_readwrite("ShTxtStroke", &PageItem::ShTxtStroke) + .def_readwrite("textAlignment", &PageItem::textAlignment) + .def_readwrite("TopLinkID", &PageItem::TopLinkID) + .def_readwrite("TxtBase", &PageItem::TxtBase) + .def_readwrite("TxtOutline", &PageItem::TxtOutline) + .def_readwrite("TxtScale", &PageItem::TxtScale) + .def_readwrite("TxtScaleV", &PageItem::TxtScaleV) + .def_readwrite("TxtShadowX", &PageItem::TxtShadowX) + .def_readwrite("TxtShadowY", &PageItem::TxtShadowY) + .def_readwrite("TxtStrikePos", &PageItem::TxtStrikePos) + .def_readwrite("TxtStrikeWidth", &PageItem::TxtStrikeWidth) + .def_readwrite("TxTStyle", &PageItem::TxTStyle) + .def_readwrite("TxtUnderPos", &PageItem::TxtUnderPos) + .def_readwrite("TxtUnderWidth", &PageItem::TxtUnderWidth) + .def_readwrite("*BackBox", &PageItem::BackBox) + .def_readwrite("BottomLink", &PageItem::BottomLink) + .def_readwrite("LeftLink", &PageItem::LeftLink) + .def_readwrite("*NextBox", &PageItem::NextBox) + .def_readwrite("RightLink", &PageItem::RightLink) + .def_readwrite("TopLink", &PageItem::TopLink) + .def_readwrite("PLineEnd", &PageItem::PLineEnd) + .def_readwrite("PLineJoin", &PageItem::PLineJoin) + .def_readwrite("PLineArt", &PageItem::PLineArt) + .def_readwrite("Clip", &PageItem::Clip) + .def_readwrite("itemText", &PageItem::itemText) + .def_readwrite("EmProfile", &PageItem::EmProfile) + .def_readwrite("IProfile", &PageItem::IProfile) + .def_readwrite("Language", &PageItem::Language) + .def_readwrite("NamedLStyle", &PageItem::NamedLStyle) + .def_readwrite("OnMasterPage", &PageItem::OnMasterPage) + .def_readwrite("Pfile", &PageItem::Pfile) + .def_readwrite("Pfile2", &PageItem::Pfile2) + .def_readwrite("Pfile3", &PageItem::Pfile3) + .def_readwrite("TxtFill", &PageItem::TxtFill) + .def_readwrite("TxtStroke", &PageItem::TxtStroke) + .def_readwrite("DashValues", &PageItem::DashValues) + .def_readwrite("effectsInUse", &PageItem::effectsInUse) + .def_readwrite("TabValues", &PageItem::TabValues) + .def_readwrite("Segments", &PageItem::Segments) + .def_readwrite("Groups", &PageItem::Groups) + .def_readwrite("pixm", &PageItem::pixm) + .def_readwrite("ItemNr", &PageItem::ItemNr) + .def_readwrite("MaxChars", &PageItem::MaxChars) + .def_readwrite("fill_gradient", &PageItem::fill_gradient) + .add_property("xPos", &PageItem::xPos, &PageItem::setXPos) + .add_property("yPos", &PageItem::yPos, &PageItem::setYPos) + .def("moveBy", &PageItem::moveBy) + .add_property("width", &PageItem::width, &PageItem::setWidth) + .add_property("height", &PageItem::height, &PageItem::setHeight) + .def("resizeBy", &PageItem::resizeBy) + // TODO: Weird error + //.def("rotation", &PageItem::rotation) + .def("setRotation", &PageItem::setRotation) + .def("rotateBy", &PageItem::rotateBy) + .add_property("selected", &PageItem::isSelected, &PageItem::setSelected) + .add_property("imageXscale", &PageItem::imageXScale, &PageItem::setImageXScale) + .add_property("imageYscale", &PageItem::imageYScale, &PageItem::setImageYScale) + .add_property("imageXOffset", &PageItem::imageXOffset, &PageItem::setImageXOffset) + .add_property("imageYOffset", &PageItem::imageYOffset, &PageItem::setImageYOffset) + .def("moveImageXYOffsetBy", &PageItem::moveImageXYOffsetBy) + .add_property("reversed", &PageItem::reversed, &PageItem::setReversed) + // TODO: Weird error + //.def("cornerRadius", &PageItem::cornerRadius) + .def("setCornerRadius", &PageItem::setCornerRadius) + .add_property("textToFrameDistLeft", &PageItem::textToFrameDistLeft, &PageItem::setTextToFrameDistLeft) + .add_property("textToFrameDistRight", &PageItem::textToFrameDistRight, &PageItem::setTextToFrameDistRight) + .add_property("textToFrameDistTop", &PageItem::textToFrameDistTop, &PageItem::setTextToFrameDistTop) + .add_property("textToFrameDistBottom", &PageItem::textToFrameDistBottom, &PageItem::setTextToFrameDistBottom) + .def("setTextToFrameDist", &PageItem::setTextToFrameDist) + .add_property("itemName", &PageItem::itemName, &PageItem::setItemName) + .add_property("fillColor", &PageItem::fillColor, &PageItem::setFillColor) + .add_property("fillShade", &PageItem::fillShade, &PageItem::setFillShade) + .add_property("fillTransparency", &PageItem::fillTransparency, &PageItem::setFillTransparency) + .add_property("lineColor", &PageItem::lineColor, &PageItem::setLineColor) + .add_property("lineShade", &PageItem::lineShade, &PageItem::setLineShade) + .add_property("lineTransparency", &PageItem::lineTransparency, &PageItem::setLineTransparency) + .add_property("setLineQColor", &PageItem::setLineQColor, &PageItem::setFillQColor) + .def("lineStyle", &PageItem::lineStyle) + // TODO: weird error + //.def("setLineStyle", &PageItem::setLineStyle) + // TODO: weird error + //.def("lineWidth", &PageItem::lineWidth) + .def("setLineWidth", &PageItem::setLineWidth) + .add_property("lineEnd", &PageItem::lineEnd, &PageItem::setLineEnd) + .add_property("lineJoin", &PageItem::lineJoin, &PageItem::setLineJoin) + .add_property("customLineStyle", &PageItem::customLineStyle, &PageItem::setCustomLineStyle) + .add_property("startArrowIndex", &PageItem::startArrowIndex, &PageItem::setStartArrowIndex) + .add_property("endArrowIndex", &PageItem::endArrowIndex, &PageItem::setEndArrowIndex) + .add_property("imageFlippedH", &PageItem::imageFlippedH, &PageItem::setImageFlippedH) + .def("flipImageH", &PageItem::flipImageH) + .add_property("imageFlippedV", &PageItem::imageFlippedV, &PageItem::setImageFlippedV) + .def("flipImageV", &PageItem::flipImageV) + .def("setImageScalingMode", &PageItem::setImageScalingMode) + .def("toggleLock", &PageItem::toggleLock) + .add_property("locked", &PageItem::locked, &PageItem::setLocked) + .def("toggleSizeLock", &PageItem::toggleSizeLock) + .add_property("sizeLocked", &PageItem::sizeLocked, &PageItem::setSizeLocked) + .add_property("font", &PageItem::font, &PageItem::setFont) + .add_property("fontSize", &PageItem::fontSize, &PageItem::setFontSize) + .add_property("fontHeight", &PageItem::fontHeight, &PageItem::setFontHeight) + .add_property("fontWidth", &PageItem::fontWidth, &PageItem::setFontWidth) + .add_property("fontFillColor", &PageItem::fontFillColor, &PageItem::setFontFillColor) + .add_property("fontFillShade", &PageItem::fontFillShade, &PageItem::setFontFillShade) + .add_property("fontStrokeColor", &PageItem::fontStrokeColor, &PageItem::setFontStrokeColor) + .add_property("fontStrokeShade", &PageItem::fontStrokeShade, &PageItem::setFontStrokeShade) + .add_property("fontEffects", &PageItem::fontEffects, &PageItem::setFontEffects) + .add_property("kerning", &PageItem::kerning, &PageItem::setKerning) + // TODO: weird error + //.def("lineSpacing", &PageItem::lineSpacing) + .def("setLineSpacing", &PageItem::setLineSpacing) + .add_property("language", &PageItem::language, &PageItem::setLanguage) + .add_property("textFlowMode", &PageItem::textFlowMode, &PageItem::setTextFlowMode) + .def("itemType", &PageItem::itemType) + .def("convertTo", &PageItem::convertTo) + .def("setLayer", &PageItem::setLayer) + .add_property("printable", &PageItem::printable, &PageItem::setPrintable) + .def("loadImage", &PageItem::loadImage) + .add_property("isAnnotation", &PageItem::isAnnotation, &PageItem::setIsAnnotation) + .def("annotation", &PageItem::annotation, return_internal_reference<>()); + + enum_<PageItem::ItemType>("ItemType") + .value("ImageFrame", PageItem::ImageFrame) + .value("ImageFrame", PageItem::ImageFrame) + .value("TextFrame", PageItem::TextFrame) + .value("Line", PageItem::Line) + .value("Polygon", PageItem::Polygon) + .value("PolyLine", PageItem::PolyLine) + .value("PathText", PageItem::PathText) + .export_values(); + + enum_<PageItem::ItemFrameType>("ItemFrameType") + .value("Unspecified", PageItem::Unspecified) + .value("Rectangle", PageItem::Rectangle) + .value("Ellipse", PageItem::Ellipse) + .value("Round", PageItem::Round) + .value("Other", PageItem::Other) + .export_values(); + + class_<PageItem::TabRecord>("TabRecord") + .def_readwrite("tabPosition", &PageItem::TabRecord::tabPosition) + .def_readwrite("tabType", &PageItem::TabRecord::tabType) + .add_property("tabFillChar", make_getter(&PageItem::TabRecord::tabFillChar, return_value_policy<return_by_value>()), + make_setter(&PageItem::TabRecord::tabFillChar, return_value_policy<return_by_value>())); + + } // end scope p +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusdoc.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusdoc.cpp new file mode 100644 index 0000000..0f41339 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusdoc.cpp @@ -0,0 +1,36 @@ +/* +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 "cmdvar.h" + +using boost::python::list; +using boost::python::throw_error_already_set; + +/* +PageItemList getDocItems(ScribusDoc & doc) +{ + return PageItemList(doc.DocItems); +} + +PageItemList getMasterItems(ScribusDoc & doc) +{ + return PageItemList(doc.MasterItems); +} +*/ + +void export_ScribusDoc() +{ + using namespace boost::python; + + scope d = class_<ScribusDoc, bases<QObject>, boost::noncopyable>("ScribusDoc", + "A Scribus document", + no_init) + .add_property("isModified", &ScribusDoc::isModified, &ScribusDoc::setModified); + /* + .add_property("items", &getDocItems) + .add_property("masterPageItems", &getMasterItems); + */ +} diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusmainwin.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusmainwin.cpp new file mode 100644 index 0000000..d9c9d74 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusmainwin.cpp @@ -0,0 +1,29 @@ +/* +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 "cmdvar.h" + +#include "scribus.h" +#include "scribuswin.h" +#include "scribusdoc.h" +#include "scribusview.h" + +void export_ScribusMainWindow() +{ + using namespace boost::python; + + class_<ScribusMainWindow, bases<QWidget>, boost::noncopyable>( + "ScribusMainWindow", + "The app's main window, which also provides much of its core functionality", + no_init) + .add_property("doc", make_getter(&ScribusMainWindow::doc, return_internal_reference<>())) + .add_property("view", make_getter(&ScribusMainWindow::view, return_internal_reference<>())) + .add_property("ActWin", make_getter(&ScribusMainWindow::ActWin, return_internal_reference<>())); + + scope().attr("ScMW") = boost::ref(ScMW); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusqapp.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusqapp.cpp new file mode 100644 index 0000000..2191492 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusqapp.cpp @@ -0,0 +1,29 @@ +/* +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 "cmdvar.h" + + + +#include "scribusapp.h" + +extern ScribusQApp* ScQApp; + +void export_ScribusQApp() +{ + using namespace boost::python; + + class_<ScribusQApp, bases<QApplication>, boost::noncopyable>("ScribusQApp", + "The core application", + no_init) + .add_property("usingGUI", &ScribusQApp::usingGUI) + .add_property("isMacGUI", &ScribusQApp::isMacGUI) + .add_property("reverseDialogButtons", &ScribusQApp::reverseDialogButtons); + + scope().attr("ScQApp") = boost::ref(ScQApp); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusview.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusview.cpp new file mode 100644 index 0000000..8e53506 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribusview.cpp @@ -0,0 +1,20 @@ +/* +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 "cmdvar.h" + +#include "scribusdoc.h" + +void export_ScribusView() +{ + using namespace boost::python; + + scope w = class_<ScribusView, bases<QScrollView>, boost::noncopyable>("ScribusView", + "The document display canvas", + no_init); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribuswin.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribuswin.cpp new file mode 100644 index 0000000..eee9171 --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_scribus_scribuswin.cpp @@ -0,0 +1,18 @@ +/* +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 "cmdvar.h" + +#include "scribuswin.h" + +void export_ScribusWin() +{ + using namespace boost::python; + + class_<ScribusWin, bases<QMainWindow>, boost::noncopyable>("ScribusWin", + "A Scribus document window", + no_init); +} diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_scribusstructs.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_scribusstructs.cpp new file mode 100644 index 0000000..eb2e6ef --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_scribusstructs.cpp @@ -0,0 +1,67 @@ +/* +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 "cmdvar.h" + +#include "scribusstructs.h" + + +using namespace boost::python; + +/** + * @brief Wrap the ParagraphStyle class + */ +void export_ParagraphStyle() +{ + class_<ParagraphStyle>("ParagraphStyle") +// .def_readwrite("Vname", &ParagraphStyle::Vname) + .add_property("Vname", make_getter(&ParagraphStyle::Vname, return_value_policy<return_by_value>()), + make_setter(&ParagraphStyle::Vname, return_value_policy<return_by_value>())) + .def_readwrite("LineSpaMode", &ParagraphStyle::LineSpaMode) + .def_readwrite("LineSpa", &ParagraphStyle::LineSpa) + .def_readwrite("textAlignment", &ParagraphStyle::textAlignment) + .def_readwrite("Indent", &ParagraphStyle::Indent) + .def_readwrite("First", &ParagraphStyle::First) + .def_readwrite("gapBefore", &ParagraphStyle::gapBefore) + .def_readwrite("gapAfter", &ParagraphStyle::gapAfter) +// .def_readwrite("Font", &ParagraphStyle::Font) + .add_property("Font", make_getter(&ParagraphStyle::Font, return_value_policy<return_by_value>()), + make_setter(&ParagraphStyle::Font, return_value_policy<return_by_value>())) + .def_readwrite("FontSize", &ParagraphStyle::FontSize) + .def_readwrite("TabValues", &ParagraphStyle::TabValues) + .def_readwrite("Drop", &ParagraphStyle::Drop) + .def_readwrite("DropLin", &ParagraphStyle::DropLin) + .def_readwrite("DropDist", &ParagraphStyle::DropDist) + .def_readwrite("FontEffect", &ParagraphStyle::FontEffect) +// .def_readwrite("FColor", &ParagraphStyle::FColor) + .add_property("FColor", make_getter(&ParagraphStyle::FColor, return_value_policy<return_by_value>()), + make_setter(&ParagraphStyle::FColor, return_value_policy<return_by_value>())) + .def_readwrite("FShade", &ParagraphStyle::FShade) +// .def_readwrite("SColor", &ParagraphStyle::SColor) + .add_property("SColor", make_getter(&ParagraphStyle::SColor, return_value_policy<return_by_value>()), + make_setter(&ParagraphStyle::SColor, return_value_policy<return_by_value>())) + .def_readwrite("SShade", &ParagraphStyle::SShade) + .def_readwrite("BaseAdj", &ParagraphStyle::BaseAdj) + .def_readwrite("txtShadowX", &ParagraphStyle::txtShadowX) + .def_readwrite("txtShadowY", &ParagraphStyle::txtShadowY) + .def_readwrite("txtOutline", &ParagraphStyle::txtOutline) + .def_readwrite("txtUnderPos", &ParagraphStyle::txtUnderPos) + .def_readwrite("txtUnderWidth", &ParagraphStyle::txtUnderWidth) + .def_readwrite("txtStrikePos", &ParagraphStyle::txtStrikePos) + .def_readwrite("txtStrikeWidth", &ParagraphStyle::txtStrikeWidth) + .def_readwrite("scaleH", &ParagraphStyle::scaleH) + .def_readwrite("scaleV", &ParagraphStyle::scaleV) + .def_readwrite("baseOff", &ParagraphStyle::baseOff) + .def_readwrite("kernVal", &ParagraphStyle::kernVal) + ; +} + +void export_ScribusStructs() +{ + export_ParagraphStyle(); +} + + diff --git a/scribus/plugins/scriptplugin/scripter2/scripter2_styles.cpp b/scribus/plugins/scriptplugin/scripter2/scripter2_styles.cpp new file mode 100644 index 0000000..f5d6dda --- /dev/null +++ b/scribus/plugins/scriptplugin/scripter2/scripter2_styles.cpp @@ -0,0 +1,113 @@ +/* +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 "cmdvar.h" + +#include "scribusstructs.h" +#include "scribusdoc.h" +#include "scribus.h" +#include <QList> + +// This file contains some basic methods for testing purposes, +// providing access to the docParagraphStyles member of the current +// ScribusDoc. It's a dirty hack that won't stay around. +// +// This will probably need to be replaced with a fake mapping class, since the +// styles are actually stored in a rather clumsy QValueList. + + + +using namespace boost::python; + +ParagraphStyle & getStyleRef(const QString & styleName) +{ + QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin()); + QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end()); + for ( ; it != itEnd; ++it) + { + if ((*it).Vname == styleName) + return *it; + } + throw "Style not found"; +} + +ParagraphStyle & getStyleRefi(int index) +{ + return ScCore->primaryMainWindow()->doc->docParagraphStyles[index]; +} + +ParagraphStyle getStyleVal(const QString & styleName) +{ + return getStyleRef(styleName); +} + +ParagraphStyle getStyleVali(int index) +{ + return getStyleRefi(index); +} + +void addStyle(const ParagraphStyle & style) +{ + QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin()); + QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end()); + for ( ; it != itEnd; ++it) + { + if ((*it).Vname == style.Vname) + throw "Style of same name already exists"; + } + ScCore->primaryMainWindow()->doc->docParagraphStyles.append(style); +} + +// This returns a COPY of the paragraph styles; modifications to this list do +// NOT affect the real paragraph style list. That'll have to happen much later, +// probably with a "fake mapping" class wrapper around the docParagraphStyles +// list, since we don't want Python users seeing the int-indexed list. +dict getStylesVal() +{ + dict d; + QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin()); + QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end()); + for ( ; it != itEnd; ++it) + d[(*it).Vname] = *it; + return d; +} + +dict getStylesRef() +{ + dict d; + QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin()); + QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end()); + for ( ; it != itEnd; ++it) + d[(*it).Vname] = boost::ref(*it); + return d; +} + +list getStyleNames() +{ + list l; + QList<ParagraphStyle>::iterator it(ScCore->primaryMainWindow()->doc->docParagraphStyles.begin()); + QList<ParagraphStyle>::iterator itEnd(ScCore->primaryMainWindow()->doc->docParagraphStyles.end()); + for ( ; it != itEnd; ++it) + l.append((*it).Vname); + return l; +} + +void nothing() { } + + +void export_styles() +{ + def("getStyleRef", getStyleRef, return_internal_reference<>()); + def("getStyleVal", getStyleVal); + def("getStyleRefi", getStyleRefi, return_internal_reference<>()); + def("getStyleVali", getStyleVali); + def("addStyle", addStyle); + def("getStylesVal", getStylesVal); + def("getStylesRef", getStylesRef); + def("getStyleNames", getStyleNames); +} + + |
