Subversion Repositories Scribus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21700 gpittman 1
#!/usr/bin/env python
2
# -*- coding: utf-8  -*-
3
 
4
# ****************************************************************************
5
#  This program is free software; you can redistribute it and/or modify 
6
#  it under the terms of the GNU General Public License as published by
7
#  the Free Software Foundation; either version 2 of the License, or
8
#  (at your option) any later version.
9
#
10
#  This program is distributed in the hope that it will be useful,
11
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
#  GNU General Public License for more details.
14
#
15
#  You should have received a copy of the GNU General Public License
16
#  along with this program; if not, write to the Free Software
17
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
# 
19
# ****************************************************************************
20
 
21
 
22
"""
23
 
24
© 2017 Gregory Pittman
25
 
26
caption.py
27
 
28
Creates a text frame (caption) in selected location relative to
29
one or more selected frames.
30
 
31
USAGE
32
 
33
Select one or more object (can be any kind of frame, or even imported vector graphics),
34
 
35
run script. Dialog appears for choosing placement of all caption frames
36
 
37
B/T/R/L (Bottom/Top/Right/Left).
38
 
39
Bottom and Top caption frames are sized to width of parent object and height
40
 
41
of 24 points. Right and Left caption frames sized to 150 points width and
42
 
43
40 points height.
44
 
45
"""
46
 
47
try:
48
    import scribus
49
except ImportError:
50
    print "Unable to import the 'scribus' module. This script will only run within"
51
    print "the Python interpreter embedded in Scribus. Try Script->Execute Script."
52
    sys.exit(1)
53
 
54
numselect = scribus.selectionCount()
55
count = 0
56
frames = []
57
 
58
if numselect == 0:
59
    scribus.messageBox('Selection Count', "You must have at least one object selected",
60
                       scribus.ICON_WARNING, scribus.BUTTON_OK)
61
    sys.exit(2)
62
 
63
captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b")
64
captionloc = captionloc[0]
65
location = captionloc.upper()
66
 
67
pageunits = scribus.getUnit()
68
scribus.setUnit(scribus.UNIT_POINTS)
69
 
70
while count < numselect:
71
    frames.append(scribus.getSelectedObject(count))
72
    count += 1
73
 
74
for frame in frames:
75
    fwidth, fheight = scribus.getSize(frame)
76
    fx, fy = scribus.getPosition(frame)
77
    if location == "B":
78
        textf = scribus.createText(fx, fy+fheight, fwidth, 24)
79
    elif location == "T":
80
        textf = scribus.createText(fx, fy-24, fwidth, 24)
81
    elif location == "R":
82
        textf = scribus.createText(fx + fwidth, fy, 150, 40)
83
    elif location == "L":
84
        textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40)
85
scribus.setUnit(pageunits)
86
 
87
scribus.setRedraw(True)
88