Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check tdb's script for creating captions #18

Open
aoloe opened this issue Aug 30, 2014 · 5 comments
Open

check tdb's script for creating captions #18

aoloe opened this issue Aug 30, 2014 · 5 comments

Comments

@aoloe
Copy link
Owner

aoloe commented Aug 30, 2014

http://www.tdb.fi/~tdb/tmp/image-frame.py.txt

import scribus

caption_line_height = 3.5
padding = 3
pt_per_mm = 72/25.4
corner_radius = -2*pt_per_mm
background_color = "White"
border_width = 0.25*pt_per_mm
border_color = "Black"

# Find the selected image and text frames
image = None
caption = None
i = 0
while 1:
    obj_name = scribus.getSelectedObject(i)
    if not obj_name:
        break
    obj_type = scribus.getObjectType(obj_name)
    if obj_type=="ImageFrame":
        image = obj_name
    elif obj_type=="TextFrame":
        caption = obj_name
    i += 1

if image:
    image_size = scribus.getSize(image)
    image_pos = scribus.getPosition(image)
    frame_height = image_size[1]+padding*2
    # If a text frame was present, match its size and position with the image
    if caption:
        caption_size = scribus.getSize(caption)
        caption_height = caption_line_height*int(caption_size[1]/caption_line_height+0.1)
        frame_height += caption_height+0.5
        scribus.sizeObject(image_size[0], caption_height, caption)
        scribus.moveObjectAbs(image_pos[0], image_pos[1]+image_size[1]+1, caption)

    # Create the frame rectangle
    frame = scribus.createRect(image_pos[0]-padding, image_pos[1]-padding, image_size[0]+padding*2, frame_height)
    scribus.setFillColor(background_color, frame)
    scribus.setCornerRadius(corner_radius, frame)
    scribus.setLineColor(border_color, frame)
    scribus.setLineWidth(border_width, frame)

    # Move the frame rectangle behind the other objects
    scribus.deselectAll()
    scribus.selectObject(frame)
    scribus.moveSelectionToBack()

    # Create group of all the objects.  It works better by selecting the
    # objects, as the group is then left selected after the operation.
    scribus.selectObject(image)
    if caption:
        scribus.selectObject(caption)
    scribus.groupObjects()
@luzpaz
Copy link
Contributor

luzpaz commented Jun 18, 2015

I get this error:

'Scribus Python Console\n\nThis is a standard Python console with some \nknown limitations. Please consult the Scribus \nScripter documentation for futher information. '
Traceback (most recent call last):
  File "<console>", line 2, in <module>
TypeError: an integer is required
  File "<console>", line 1
    frame = scribus.createRect(image_pos[0]-padding, image_pos[1]-padding, image_size[0]+padding*2, frame_height)
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.setFillColor(background_color, frame)
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.setCornerRadius(corner_radius, frame)
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.setLineColor(border_color, frame)
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.setLineWidth(border_width, frame)
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.deselectAll()
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.selectObject(frame)
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.moveSelectionToBack()
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.selectObject(image)
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    if caption:
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.selectObject(caption)
    ^
IndentationError: unexpected indent
  File "<console>", line 1
    scribus.groupObjects()
    ^
IndentationError: unexpected indent

@aoloe
Copy link
Owner Author

aoloe commented Jun 18, 2015

@luzpaz you should save the script in a text file and run the file from scribus...

@luzpaz
Copy link
Contributor

luzpaz commented Jun 18, 2015

@aoloe Ok.. thanks. What about the patch at the end of the tp://www.tdb.fi/~tdb/tmp/image-frame.py.txt

# Requires the following patch to Scribus:
"""
--- scribus-1.4.2.dfsg.3+r18267.orig/scribus/plugins/scriptplugin/cmdsetprop.cpp
+++ scribus-1.4.2.dfsg.3+r18267/scribus/plugins/scriptplugin/cmdsetprop.cpp
@@ -340,16 +340,11 @@ PyObject *scribus_setlinestyle(PyObject*
 PyObject *scribus_setcornerrad(PyObject* /* self */, PyObject* args)
 {
    char *Name = const_cast<char*>("");
-   int w;
-   if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
+   double w;
+   if (!PyArg_ParseTuple(args, "d|es", &w, "utf-8", &Name))
        return NULL;
    if(!checkHaveDocument())
        return NULL;
-   if (w < 0)
-   {
-       PyErr_SetString(PyExc_ValueError, QObject::tr("Corner radius must be a positive number.","python error").toLocal8Bit().constData());
-       return NULL;
-   }
    PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name));
    if (currItem == NULL)
        return NULL;
"""

@luzpaz
Copy link
Contributor

luzpaz commented Jun 18, 2015

Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "/Users/sphenoid/Downloads/FFbrowser/image-frame.py", line 41, in <module>
    scribus.setCornerRadius(corner_radius, frame)
TypeError: integer argument expected, got float

@luzpaz
Copy link
Contributor

luzpaz commented Jun 19, 2015

Does the script need to be run when scribus is in certain condition on the canvas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants