PyObject *scribus_setalign(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); int alignment; if (!PyArg_ParseTuple(args, "i|es", &alignment, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if ((alignment > 4) || (alignment < 0)) { PyErr_SetString(PyExc_ValueError, QObject::tr("Alignment out of range. Use one of the scribus.ALIGN* constants.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text alignment on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->setNewAlignment(alignment); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; }
PyObject *scribus_newellipse(PyObject* /* self */, PyObject* args) { double x, y, w, h; char *Name = const_cast<char*>(""); 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->itemToolPrefs().shapeLineWidth, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor, true); 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_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; i<ScCore->primaryMainWindow()->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_layertrans(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); 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_glayertrans(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); 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_applymasterpage(PyObject* /* self */, PyObject* args) { char* name = nullptr; int page = 0; if (!PyArg_ParseTuple(args, "esi", const_cast<char*>("utf-8"), &name, &page)) return nullptr; if (!checkHaveDocument()) return nullptr; const QString masterPageName(name); ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc; if (!currentDoc->MasterNames.contains(masterPageName)) { PyErr_SetString(PyExc_ValueError, QObject::tr("Master page does not exist: '%1'","python error").arg(masterPageName).toLocal8Bit().constData()); return nullptr; } if ((page < 1) || (page > static_cast<int>(currentDoc->Pages->count()))) { PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range: %1.","python error").arg(page).toLocal8Bit().constData()); return nullptr; } if (!currentDoc->applyMasterPage(masterPageName, page-1)) { PyErr_SetString(ScribusException, QObject::tr("Failed to apply masterpage '%1' on page: %2","python error").arg(masterPageName).arg(page).toLocal8Bit().constData()); return nullptr; } Py_RETURN_NONE; }
void ItemAPI::moveAbs(double x, double y) { if (!checkHaveDocument()) return; if (item == NULL) return; // 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->SelectItem(item); // 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; }
PyObject *scribus_settextstroke(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); 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; if (!(it->asTextFrame()) && (it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text stroke on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } else { for (int b = 0; b < it->itemText.length(); b++) { //FIXME:NLS use document method for this if (it->HasSel) { if (it->itemText.selected(b)) it->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color)); } else it->itemText.item(b)->setStrokeColor(QString::fromUtf8(Color)); } // it->TxtStroke = QString::fromUtf8(Color); } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; }
PyObject *scribus_settextscalingv(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); double sc; if (!PyArg_ParseTuple(args, "d|es", &sc, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (sc < 10) { PyErr_SetString(PyExc_ValueError, QObject::tr("Character scaling out of bounds, must be >= 10","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->doc->itemSelection_SetScaleV(qRound(sc * 10)); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); Py_RETURN_NONE; }
PyObject *scribus_setcolumns(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); int w; if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (w < 1) { PyErr_SetString(PyExc_ValueError, QObject::tr("Column count out of bounds, must be > 1.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set number of columns on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } i->Cols = w; // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; }
PyObject *scribus_deletetext(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot delete text from a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } if (it->HasSel) dynamic_cast<PageItem_TextFrame*>(it)->deleteSelectedTextFromFrame(); else { it->itemText.clear(); it->CPos = 0; for (int a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a) { ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a; } } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; }
PyObject *scribus_settextdistances(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); double l,r,t,b; if (!PyArg_ParseTuple(args, "dddd|es", &l, &r, &t, &b, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if (l < 0.0 || r < 0.0 || t < 0.0 || b < 0.0) { PyErr_SetString(PyExc_ValueError, QObject::tr("Text distances out of bounds, must be positive.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text distances on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } i->setTextToFrameDist(ValueToPoint(l), ValueToPoint(r), ValueToPoint(t), ValueToPoint(b)); Py_INCREF(Py_None); return Py_None; }
PyObject *scribus_getfont(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *it = GetUniqueItem(QString::fromUtf8(Name)); if (it == NULL) return NULL; if (!(it->asTextFrame()) && !(it->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get font of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } if (it->HasSel) { for (int b = 0; b < it->itemText.length(); b++) if (it->itemText.selected(b)) return PyString_FromString(it->itemText.charStyle(b).font().scName().toUtf8()); return NULL; } else return PyString_FromString(it->currentCharStyle().font().scName().toUtf8()); }
PyObject *scribus_setfontsize(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); double size; if (!PyArg_ParseTuple(args, "d|es", &size, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; if ((size > 512) || (size < 1)) { PyErr_SetString(PyExc_ValueError, QObject::tr("Font size out of bounds - must be 1 <= size <= 512.","python error").toLocal8Bit().constData()); return NULL; } PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == NULL) return NULL; if (!i->asTextFrame()) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font size on a non-text frame.","python error").toLocal8Bit().constData()); return NULL; } int Apm = ScCore->primaryMainWindow()->doc->appMode; ScCore->primaryMainWindow()->doc->m_Selection->clear(); ScCore->primaryMainWindow()->doc->m_Selection->addItem(i); if (i->HasSel) ScCore->primaryMainWindow()->doc->appMode = modeEdit; ScCore->primaryMainWindow()->doc->itemSelection_SetFontSize(qRound(size * 10.0)); ScCore->primaryMainWindow()->doc->appMode = Apm; ScCore->primaryMainWindow()->view->Deselect(); // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; }
PyObject *scribus_savedoc(PyObject* /* self */) { if (!checkHaveDocument()) return nullptr; ScCore->primaryMainWindow()->slotFileSave(); Py_RETURN_NONE; }
PyObject *scribus_newtable(PyObject* /* self */, PyObject* args) { double x, y, w, h; int numRows, numColumns; char *Name = const_cast<char*>(""); if (!PyArg_ParseTuple(args, "ddddii|es", &x, &y, &w, &h, &numRows, &numColumns, "utf-8", &Name)) return NULL; if (!checkHaveDocument()) return NULL; if (numRows < 1 || numColumns < 1) { PyErr_SetString(PyExc_ValueError, QObject::tr("Both numRows and numColumns must be greater than 0.","python error").toLocal8Bit().constData()); return NULL; } int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Table, PageItem::Unspecified, pageUnitXToDocX(x), pageUnitYToDocY(y), ValueToPoint(w), ValueToPoint(h), 0, // Unused. CommonStrings::None, // Unused. CommonStrings::None); // Unused. PageItem_Table *table = ScCore->primaryMainWindow()->doc->Items->at(i)->asTable(); table->insertRows(0, numRows - 1); table->insertColumns(0, numColumns - 1); table->adjustTableToFrame(); table->adjustFrameToTable(); if (strlen(Name) > 0) { QString objName = QString::fromUtf8(Name); if (!ItemExists(objName)) ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(objName); } return PyString_FromString(table->itemName().toUtf8()); }
PyObject* scribus_deletemasterpage(PyObject* /* self */, PyObject* args) { char* name = nullptr; if (!PyArg_ParseTuple(args, "es", const_cast<char*>("utf-8"), &name)) return nullptr; if (!checkHaveDocument()) return nullptr; const QString masterPageName(name); ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc; if (!currentDoc->MasterNames.contains(masterPageName)) { PyErr_SetString(PyExc_ValueError, "Master page does not exist"); return nullptr; } if (masterPageName == "Normal") { PyErr_SetString(PyExc_ValueError, "Can not delete the Normal master page"); return nullptr; } bool oldMode = currentDoc->masterPageMode(); currentDoc->setMasterPageMode(true); ScCore->primaryMainWindow()->deletePage2(currentDoc->MasterNames[masterPageName]); currentDoc->setMasterPageMode(oldMode); Py_RETURN_NONE; }
PyObject *scribus_resizetablerow(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); int row; double height; if (!PyArg_ParseTuple(args, "id|es", &row, &height, "utf-8", &Name)) return nullptr; if (!checkHaveDocument()) return nullptr; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == nullptr) return nullptr; PageItem_Table *table = i->asTable(); if (!table) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot resize row on a non-table item.","python error").toLocal8Bit().constData()); return nullptr; } if (row < 0 || row >= table->rows()) { PyErr_SetString(PyExc_ValueError, QObject::tr("Table row index out of bounds, must be >= 0 and < %1", "python error").arg(table->rows()).toLocal8Bit().constData()); return nullptr; } if (height <= 0.0) { PyErr_SetString(PyExc_ValueError, QObject::tr("Table row height must be > 0.0", "python error").toLocal8Bit().constData()); return nullptr; } table->resizeRow(row, height); Py_RETURN_NONE; }
void ItemAPI::move(double dx, double dy) { if (!checkHaveDocument()) return; if (item==NULL) return; // 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->SelectItem(item); // 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(dx), ValueToPoint(dy)); ScCore->primaryMainWindow()->view->endGroupTransaction(); } else { ScCore->primaryMainWindow()->doc->MoveItem(ValueToPoint(dx), ValueToPoint(dy), item); } // Now restore the selection. ScCore->primaryMainWindow()->view->Deselect(); if (hadOrigSelection) *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection; }
PyObject *scribus_inserttablecolumns(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); int index, numColumns; if (!PyArg_ParseTuple(args, "ii|es", &index, &numColumns, "utf-8", &Name)) return nullptr; if (!checkHaveDocument()) return nullptr; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == nullptr) return nullptr; PageItem_Table *table = i->asTable(); if (!table) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot insert columns on a non-table item.","python error").toLocal8Bit().constData()); return nullptr; } if (index < 0 || index > table->columns()) { PyErr_SetString(PyExc_ValueError, QObject::tr("Table column index out of bounds, must be >= 0 and < %1", "python error").arg(table->columns()).toLocal8Bit().constData()); return nullptr; } if (numColumns < 1) { PyErr_SetString(PyExc_ValueError, QObject::tr("Table column count out of bounds, must be >= 1", "python error").toLocal8Bit().constData()); return nullptr; } table->insertColumns(index, numColumns); Py_RETURN_NONE; }
static PyObject *ImageExport_saveAs(ImageExport *self, PyObject *args) { char* value; if(!checkHaveDocument()) return NULL; if (!PyArg_ParseTuple(args, const_cast<char*>("es"), "utf-8", &value)) return NULL; /* a little magic here - I need to compute the "maxGr" value... * We need to know the right size of the page for landscape, * portrait and user defined sizes. */ double pixmapSize; (ScCore->primaryMainWindow()->doc->pageHeight > ScCore->primaryMainWindow()->doc->pageWidth) ? pixmapSize = ScCore->primaryMainWindow()->doc->pageHeight : pixmapSize = ScCore->primaryMainWindow()->doc->pageWidth; QImage im = ScCore->primaryMainWindow()->view->PageToPixmap(ScCore->primaryMainWindow()->doc->currentPage()->pageNr(), qRound(pixmapSize * self->scale * (self->dpi / 72.0) / 100.0), false); int dpi = qRound(100.0 / 2.54 * self->dpi); im.setDotsPerMeterY(dpi); im.setDotsPerMeterX(dpi); if (!im.save(value, PyString_AsString(self->type))) { PyErr_SetString(ScribusException, QObject::tr("Failed to export image", "python error").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<long>(true)); }
PyObject *scribus_resizetablecolumn(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); int column; double width; if (!PyArg_ParseTuple(args, "id|es", &column, &width, "utf-8", &Name)) return nullptr; if (!checkHaveDocument()) return nullptr; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == nullptr) return nullptr; PageItem_Table *table = i->asTable(); if (!table) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot resize column on a non-table item.","python error").toLocal8Bit().constData()); return nullptr; } if (column < 0 || column >= table->columns()) { PyErr_SetString(PyExc_ValueError, QObject::tr("Table column index out of bounds, must be >= 0 and < %1", "python error").arg(table->columns()).toLocal8Bit().constData()); return nullptr; } if (width <= 0.0) { PyErr_SetString(PyExc_ValueError, QObject::tr("Table column width must be > 0.0", "python error").toLocal8Bit().constData()); return nullptr; } table->resizeColumn(column, width); Py_RETURN_NONE; }
PyObject *scribus_glayerprint(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); 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<int>(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<long>(i)); }
PyObject *scribus_mergetablecells(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); int row, column, numRows, numColumns; if (!PyArg_ParseTuple(args, "iiii|es", &row, &column, &numRows, &numColumns, "utf-8", &Name)) return nullptr; if (!checkHaveDocument()) return nullptr; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == nullptr) return nullptr; PageItem_Table *table = i->asTable(); if (!table) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot merge cells on a non-table item.","python error").toLocal8Bit().constData()); return nullptr; } if (numRows < 1 || numColumns < 1) { PyErr_SetString(PyExc_ValueError, QObject::tr("Number of rows and columns must both be > 0.", "python error").toLocal8Bit().constData()); return nullptr; } if (row < 0 || row >= table->rows() || column < 0 || column >= table->columns() || row + numRows - 1 < 0 || row + numRows - 1 >= table->rows() || column + numColumns - 1 < 0 || column + numColumns - 1 >= table->columns()) { PyErr_SetString(PyExc_ValueError, QObject::tr("The area %1,%2 %3x%4 is not inside the table.", "python error").arg(row).arg(column).arg(numColumns).arg(numRows).toLocal8Bit().constData()); return nullptr; } table->mergeCells(row, column, numRows, numColumns); Py_RETURN_NONE; }
PyObject *scribus_newrect(PyObject* /* self */, PyObject* args) { double x, y, w, h; char *Name = const_cast<char*>(""); 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->itemToolPrefs().shapeLineWidth, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeFillColor, ScCore->primaryMainWindow()->doc->itemToolPrefs().shapeLineColor, 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); } return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8()); }
PyObject *scribus_settablebottomborder(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); PyObject* borderLines; if (!PyArg_ParseTuple(args, "O|es", &borderLines, "utf-8", &Name)) return nullptr; if (!checkHaveDocument()) return nullptr; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == nullptr) return nullptr; PageItem_Table *table = i->asTable(); if (!table) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set table bottom border on a non-table item.","python error").toLocal8Bit().constData()); return nullptr; } bool ok = false; TableBorder border = parseBorder(borderLines, &ok); if (ok) table->setBottomBorder(border); else return nullptr; Py_RETURN_NONE; }
/* 03/21/2004 - exception raises by non existent name (subik) */ PyObject *scribus_textflow(PyObject* /* self */, PyObject* args) { char *name = const_cast<char*>(""); 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_removetablerows(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); int index, numRows; if (!PyArg_ParseTuple(args, "ii|es", &index, &numRows, "utf-8", &Name)) return nullptr; if (!checkHaveDocument()) return nullptr; PageItem *i = GetUniqueItem(QString::fromUtf8(Name)); if (i == nullptr) return nullptr; PageItem_Table *table = i->asTable(); if (!table) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot remove rows from a non-table item.","python error").toLocal8Bit().constData()); return nullptr; } if (index < 0 || index >= table->rows()) { PyErr_SetString(PyExc_ValueError, QObject::tr("Table row index out of bounds, must be >= 0 and < %1", "python error").arg(table->rows()).toLocal8Bit().constData()); return nullptr; } if (numRows < 1 || numRows >= table->rows()) { PyErr_SetString(PyExc_ValueError, QObject::tr("Table row count out of bounds, must be >= 1 and < %1", "python error").arg(table->rows()).toLocal8Bit().constData()); return nullptr; } if (index + numRows > table->rows()) { PyErr_SetString(PyExc_ValueError, QObject::tr("Row deletion range out of bounds, index + numRows must be <= %1", "python error").arg(table->rows()).toLocal8Bit().constData()); return nullptr; } table->removeRows(index, numRows); Py_RETURN_NONE; }
PyObject *scribus_setVguides(PyObject* /* self */, PyObject* args) { PyObject *l; if (!PyArg_ParseTuple(args, "O", &l)) return NULL; if(!checkHaveDocument()) return NULL; if (!PyList_Check(l)) { PyErr_SetString(PyExc_TypeError, QObject::tr("argument is not list: must be list of float values.","python error").toLocal8Bit().constData()); return NULL; } int i, n; n = PyList_Size(l); double guide; ScCore->primaryMainWindow()->doc->currentPage()->guides.clearVerticals(GuideManagerCore::Standard); for (i=0; i<n; i++) { if (!PyArg_Parse(PyList_GetItem(l, i), "d", &guide)) { PyErr_SetString(PyExc_TypeError, QObject::tr("argument contains no-numeric values: must be list of float values.","python error").toLocal8Bit().constData()); return NULL; } ScCore->primaryMainWindow()->doc->currentPage()->guides.addVertical(ValueToPoint(guide), GuideManagerCore::Standard); } // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; }
PyObject *scribus_setboxtext(PyObject* /* self */, PyObject* args) { char *Name = const_cast<char*>(""); char *Text; if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Text, "utf-8", &Name)) return NULL; if(!checkHaveDocument()) return NULL; PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name)); if (currItem == NULL) return NULL; if (!(currItem->asTextFrame()) && !(currItem->asPathText())) { PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text of non-text frame.","python error").toLocal8Bit().constData()); return NULL; } QString Daten = QString::fromUtf8(Text); Daten.replace("\r\n", SpecialChars::PARSEP); Daten.replace(QChar('\n') , SpecialChars::PARSEP); PyMem_Free(Text); currItem->itemText.clear(); currItem->CPos = 0; for (int a = 0; a < ScCore->primaryMainWindow()->doc->FrameItems.count(); ++a) { ScCore->primaryMainWindow()->doc->FrameItems.at(a)->ItemNr = a; } currItem->itemText.insertChars(0, Daten); currItem->Dirty = false; // Py_INCREF(Py_None); // return Py_None; Py_RETURN_NONE; }