[Scribus] Scripter and pdf

Craig Ringer craig
Tue Dec 7 07:48:33 CET 2004

On Tue, 2004-12-07 at 06:08, Kobus Wolvaardt wrote:

> I tried to add a feature to the scripter but think i'm doing something
> wrong. I added a new command and hooked it up to the TextFlow variable
> in scribus. I was hoping to get a way of telling if a textbox is
> overflowing. But I am doing something wrong or Textflow isnt the
> variable i'm looking for. Below I include a snippet of the code from
> cmdtext.cpp:
> PyObject *scribus_gettextfill1(PyObject *self, PyObject* args)
> { long frik;
>   char *Name = "";
>   if (!PyArg_ParseTuple(args, "|s", &Name))
>    {PyErr_SetString(PyExc_Exception, ERRPARAM +        
> 	QString("getTextLength([objectname])"));
>     return NULL;
>    }
>   if(!checkHaveDocument())
>    return NULL;
>   PageItem *i = GetUniqueItem(QString(Name));
>   frik=0;
>   if (i->Textflow) // IF TEXTFLOW TRUE MAKE frik=1
>     frik=1;
>   return i != NULL ? PyInt_FromLong(frik) : NULL; //RETURN frik
> }

Separate to the issue of why the code isn't working, you shouldn't
return NULL from a Python API function unless either you or a function
you have called has set a Python exception. In this case, it looks like
you actually want to write:

if (i->Textflow)
	return Py_True;
	return Py_False;

Alternately, I think you might've been able to write:

return PyBool_FromLong( i->Textflow ? 1 : 0 );

but I'm not sure of that.

Also, if PyArg_ParseTuple fails, you should just return NULL - there is
no need to set an exception, as PyArg_ParseTuple has already done so for
you. If you set an exception, it masks the one from PyArg_ParseTuple,
which may be more informative - eg "unicode decode error". Now that
function usage information is in the docstrings in the scripter, that
code has been removed from the main scripter code too.

GetUniqueItem will set an exception if it returns NULL, so you should
simply return NULL in turn if it fails. Your code does that, but first
tries to access the null pointer, so it'll crash with a segmentation
fault. Instead, consider using:

  PageItem *i = GetUniqueItem(Name);
  if (i == NULL)
	return NULL; // GetUniqueItem has already set an exception

As for the actual issue ... no idea. If I get time I'll look at it today
- this has been on my TO-DO list for a while, along with a way to get
the text _currently_ _visible_ in the text frame rather than its whole
contents including spills to subsequent frames.

> I also added the command to scriptplugin.cpp.

If you get it working, I'd suggest putting it in cmdtext.cpp, adding an
entry to the header file, and adding a docstring. You can just follow
how the other functions do it.

Craig Ringer

More information about the scribus mailing list