[Scribus] Scripter setProperty(object, property, value) function
Craig Ringer
craig
Mon Sep 17 04:53:33 CEST 2007
Gregory Pittman wrote:
> Jeremy Brown wrote:
>> However, I can't figure out how to use the setProperty command. It keeps
>> giving me an error:
>> TypeError: Property type '' not supported
This code has never been widely used.
It was put in place because it does make it possible to do a bit more
with manipulating objects using the scripter. However, because Scribus's
internals are rather subtly interdependent and rely on a lot of manual
messaging, twiddling these properties might not always do what you
expect, or might not take effect immediately.
This is why it's not part of the main documentation. It's there for
people willing to play with it, but it's not a stable interface and it
has serious issues that cannot be resolved until the core code is improved.
That said, I did document it. Just run help(setProperty), like any other
function in the Scribus interface, and you'll get:
Help on built-in function setProperty in module scribus:
----------
setProperty(...)
setProperty(object, property, value)
Set `property' of `object' to `value'. If `value' cannot be
converted to a type compatible with the type of `property', an exception
is raised. An exception may also be raised if the underlying setter fails.
See getProperty() for more information.
----------
What's missing from that, and I should've included, is reference to the
getPropertyCType function.
>>> getPropertyCType("Polygon3", "imageXOffset")
double
... which gives you an idea what you need to send as a value. I haven't
written a Python<>C type mapping function but that should be pretty
trivial; you can see how the mapping is done in the C sources if you want.
Note that the current Python <> C type conversions are very strict. Even
obvious things like promoting ints to doubles are not done. For example:
>>> setProperty("Polygon3", "imageXOffset", "10.0")
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Couldn't convert ''10.0'' to property type 'double'
>>> setProperty("Polygon3", "imageXOffset", 10)
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Couldn't convert '10' to property type 'double'
>>> setProperty("Polygon3", "imageXOffset", 10.0)
>>>
This interface isn't what I'd call friendly. On the other hand, neither
is the underlying code. Depending on which property is altered, changes
may take effect on next redraw, when some other value is altered, never,
or on save/load. Behavior may change from version to version as the
cleanups progress.
>> for i in range(nbrSelected):
>> try:
>> obj = objList[i]
>> props = ""
>> propList = getPropertyNames(obj)
>> for p in propList:
>> props = props + p + ": " + str(getProperty(obj, p)) + " | " +
>> str(getPropertyCType(obj, p)) + "\n"
>> messageBox("Property Info for " + obj, "Below is a property list
>> for the selected object named " + obj + "\n" + props, ICON_INFORMATION)
>> #setProperty(obj, "imgXOffset", "10.0")
It looks like you are trying to pass a Python string to a double
property. Use 10.0 instead of "10.0" .
--
Craig Ringer
More information about the scribus
mailing list