Discovering an Item's Properties: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
(New page: {{Scripting Index}} By selecting a Scribus object (image, line, textbox, etc.) and running this script, you can see the item's properties that are available to your script. This saves you...)
 
(Changed license to GPL2 per cbradney's request)
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
Once you know what properties are available, you can try accessing them in your script by using the getProperty(objectName, propertyName) and setProperty(objectName, propertyName, propertyValue) functions. This lets you change quite a few more object properties than are exposed through the other Scripter API functions.
Once you know what properties are available, you can try accessing them in your script by using the getProperty(objectName, propertyName) and setProperty(objectName, propertyName, propertyValue) functions. This lets you change quite a few more object properties than are exposed through the other Scripter API functions.


Please note that using the setProperty() function may not always have the effect your are looking for. Changing a value using setProperty() doesn't trigger any other effects that might happen when change the value in Scribus using the GUI. However, some things do work, as you can see by running these scrips:
Please note that using the setProperty() function may not always have the effect your are looking for. Changing a value using setProperty() doesn't trigger any other effects that might happen when change the value in Scribus using the GUI. However, some things do work, as you can see by running these scripts:


* [[Scale an Image to Fill a Frame Proportionally]]
* [[Scale an Image to Fill a Frame Proportionally]]
Line 11: Line 11:
* [[Image Wizard: Scale and Align an Image]]
* [[Image Wizard: Scale and Align an Image]]


This script has been updated for Scribus 1.4.0.
Save this script as ItemProperties.py, for example.
<pre><nowiki>
<pre><nowiki>
# License
# Copyright 2007 Jeremy Brown (TrnsltLife)
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
from scribus import *
from scribus import *


Line 17: Line 27:
     nbrSelected = selectionCount()
     nbrSelected = selectionCount()


objList = []
    objList = []


for i in range(nbrSelected):
    for i in range(nbrSelected):
    objList.append(getSelectedObject(i))
        objList.append(getSelectedObject(i))
       
for i in range(nbrSelected):
    for i in range(nbrSelected):
    try:
        try:
        obj = objList[i]
            obj = objList[i]
        props = ""
            props = ""
        propList = getPropertyNames(obj)
            propList = getPropertyNames(obj)
        for p in propList:
            for p in propList:
            props = props + p + " (" + str(getPropertyCType(obj, p) + "): " + str(getProperty(obj, p))) + "\n"
                try:
        messageBox("Property Info for " + obj, "Below is a property list for the selected object named " + obj + "\n" + props, ICON_INFORMATION)
                    props = props + p + " (" + str(getPropertyCType(obj, p)) + "): "
    except WrongFrameTypeError:
                    props = props + str(getProperty(obj, p))
    nothing = "nothing"
                except:
                    nothing = "nothing"
                props = props + "\n"
            messageBox("Property Info for " + obj, "Below is a property list for the selected object named " + obj + "\n" + props, ICON_INFORMATION)
        except WrongFrameTypeError:
            nothing = "nothing"
</nowiki></pre>
</nowiki></pre>

Latest revision as of 23:00, 10 February 2014

This article is part of the Scripts series.

By selecting a Scribus object (image, line, textbox, etc.) and running this script, you can see the item's properties that are available to your script. This saves you having to dig through the C++ code, if you're not into that kind of thing.

Once you know what properties are available, you can try accessing them in your script by using the getProperty(objectName, propertyName) and setProperty(objectName, propertyName, propertyValue) functions. This lets you change quite a few more object properties than are exposed through the other Scripter API functions.

Please note that using the setProperty() function may not always have the effect your are looking for. Changing a value using setProperty() doesn't trigger any other effects that might happen when change the value in Scribus using the GUI. However, some things do work, as you can see by running these scripts:

This script has been updated for Scribus 1.4.0.

Save this script as ItemProperties.py, for example.

# License
# Copyright 2007 Jeremy Brown (TrnsltLife)
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

from scribus import *

if haveDoc():
    nbrSelected = selectionCount()

    objList = []

    for i in range(nbrSelected):
        objList.append(getSelectedObject(i))
        
    for i in range(nbrSelected):
        try:
            obj = objList[i]
            props = ""
            propList = getPropertyNames(obj)
            for p in propList:
                try:
                    props = props + p + " (" + str(getPropertyCType(obj, p)) + "): "
                    props = props + str(getProperty(obj, p))
                except:
                    nothing = "nothing"
                props = props + "\n"
            messageBox("Property Info for " + obj, "Below is a property list for the selected object named " + obj + "\n" + props, ICON_INFORMATION)
        except WrongFrameTypeError:
            nothing = "nothing"