View Issue Details

IDProjectCategoryView StatusLast Update
0007117ScribusScripterpublic2008-07-01 21:57
Reporterelvstone Assigned Tojghali  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
PlatformLinuxOSKubuntuOS Version8.04
Product Version1.3.3.13svn 
Fixed in Version1.3.3.13svn 
Summary0007117: Add set-/getTextDistances() to Scripter API
DescriptionThe attached patch adds two functions:

setTextDistances(l, r, t, b, [name])
getTextDistances([name]) -> tuple

for setting the text distances of a text frame.
TagsNo tags attached.
Patch

Activities

2008-06-29 14:58

 

text_distances.diff (5,701 bytes)   
Index: Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdtext.cpp	(revision 12326)
+++ Scribus/scribus/plugins/scriptplugin/cmdtext.cpp	(working copy)
@@ -116,6 +116,28 @@
 	return PyFloat_FromDouble(static_cast<double>(i->lineSpacing()));
 }
 
+PyObject *scribus_gettextdistances(PyObject* /* self */, PyObject* args)
+{
+	char *Name = const_cast<char*>("");
+	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;
+	if (!i->asTextFrame())
+	{
+		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text distances of non-text frame.","python error"));
+		return NULL;
+	}
+	return Py_BuildValue("(dddd)",
+            PointToValue(i->textToFrameDistLeft()),
+            PointToValue(i->textToFrameDistRight()),
+            PointToValue(i->textToFrameDistTop()),
+            PointToValue(i->textToFrameDistBottom()));
+}
+
 PyObject *scribus_getcolumngap(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -530,6 +552,32 @@
 	return Py_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"));
+		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"));
+		return NULL;
+	}
+	i->setTextToFrameDist(ValueToPoint(l), ValueToPoint(r), ValueToPoint(t), ValueToPoint(b));
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 PyObject *scribus_setcolumngap(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
Index: Scribus/scribus/plugins/scriptplugin/cmdtext.h
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdtext.h	(revision 12326)
+++ Scribus/scribus/plugins/scriptplugin/cmdtext.h	(working copy)
@@ -81,6 +81,17 @@
 PyObject *scribus_getlinespace(PyObject */*self*/, PyObject* args);
 
 /*! docstring */
+PyDoc_STRVAR(scribus_gettextdistances__doc__,
+QT_TR_NOOP("getTextDistances([\"name\"]) -> tuple\n\
+\n\
+Returns the text distances of the text frame \"name\" expressed in points. The\n\
+distances are returned as a tuple like (left, right, top, bottom). If \"name\"\n\
+is not given the currently selected item is used.\n\
+"));
+/*! Get text distances */
+PyObject *scribus_gettextdistances(PyObject */*self*/, PyObject* args);
+
+/*! docstring */
 PyDoc_STRVAR(scribus_getcolumngap__doc__,
 QT_TR_NOOP("getColumnGap([\"name\"]) -> float\n\
 \n\
@@ -179,6 +190,19 @@
 PyObject *scribus_setcolumngap(PyObject */*self*/, PyObject* args);
 
 /*! docstring */
+PyDoc_STRVAR(scribus_settextdistances__doc__,
+QT_TR_NOOP("setTextDistances(left, right, top, bottom, [\"name\"])\n\
+\n\
+Sets the text distances of the text frame \"name\" to the values \"left\"\n\
+\"right\", \"top\" and \"bottom\". If \"name\" is not given the currently\n\
+selected item is used.\n\
+\n\
+May throw ValueError if any of the distances are out of bounds (must be positive).\n\
+"));
+/*! Set text distances */
+PyObject *scribus_settextdistances(PyObject */*self*/, PyObject* args);
+
+/*! docstring */
 PyDoc_STRVAR(scribus_setcolumns__doc__,
 QT_TR_NOOP("setColumns(nr, [\"name\"])\n\
 \n\
Index: Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(revision 12326)
+++ Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(working copy)
@@ -306,6 +306,7 @@
 	{const_cast<char*>("getColorNames"), (PyCFunction)scribus_colornames, METH_NOARGS, tr(scribus_colornames__doc__)},
 	{const_cast<char*>("getColor"), scribus_getcolor, METH_VARARGS, tr(scribus_getcolor__doc__)},
 	{const_cast<char*>("getColorAsRGB"), scribus_getcolorasrgb, METH_VARARGS, tr(scribus_getcolorasrgb__doc__)},
+	{const_cast<char*>("getTextDistances"), scribus_gettextdistances, METH_VARARGS, tr(scribus_gettextdistances__doc__)},
 	{const_cast<char*>("getColumnGap"), scribus_getcolumngap, METH_VARARGS, tr(scribus_getcolumngap__doc__)},
 	{const_cast<char*>("getColumns"), scribus_getcolumns, METH_VARARGS, tr(scribus_getcolumns__doc__)},
 	{const_cast<char*>("getCornerRadius"), scribus_getcornerrad, METH_VARARGS, tr(scribus_getcornerrad__doc__)},
@@ -388,6 +389,7 @@
 	{const_cast<char*>("setActiveLayer"), scribus_setactlayer, METH_VARARGS, tr(scribus_setactlayer__doc__)},
 	{const_cast<char*>("setPDFBookmark"), scribus_setpdfbookmark, METH_VARARGS, tr(scribus_setpdfbookmark__doc__)},
 	{const_cast<char*>("isPDFBookmark"), scribus_ispdfbookmark, METH_VARARGS, tr(scribus_ispdfbookmark__doc__)},
+	{const_cast<char*>("setTextDistances"), scribus_settextdistances, METH_VARARGS, tr(scribus_settextdistances__doc__)},
 	{const_cast<char*>("setColumnGap"), scribus_setcolumngap, METH_VARARGS, tr(scribus_setcolumngap__doc__)},
 	{const_cast<char*>("setColumns"), scribus_setcolumns, METH_VARARGS, tr(scribus_setcolumns__doc__)},
 	{const_cast<char*>("setCornerRadius"), scribus_setcornerrad, METH_VARARGS, tr(scribus_setcornerrad__doc__)},
text_distances.diff (5,701 bytes)   

2008-06-29 15:09

 

distances.py (657 bytes)   
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

try:
    from scribus import *
except ImportError,err:
    print "This Python script is written for the Scribus scripting interface."
    print "It can only be run from within Scribus."
    sys.exit(1)

def main(argv):
    setTextDistances(11, 12, 13, 14)
    messageBox("Distances", str(getTextDistances()));

def main_wrapper(argv):
    try:
        statusMessage("Running script...")
        progressReset()
        main(argv)
    finally:
        if haveDoc():
            setRedraw(True)
        statusMessage("")
        progressReset()

if __name__ == '__main__':
    main_wrapper(sys.argv)
distances.py (657 bytes)   

Issue History

Date Modified Username Field Change
2008-06-29 14:58 elvstone New Issue
2008-06-29 14:58 elvstone File Added: text_distances.diff
2008-06-29 15:09 elvstone File Added: distances.py
2008-06-29 22:09 jghali Status new => resolved
2008-06-29 22:09 jghali Fixed in Version => 1.3.3.13svn
2008-06-29 22:09 jghali Resolution open => fixed
2008-06-29 22:09 jghali Assigned To => jghali
2008-07-01 21:57 cbradney Status resolved => closed