diff options
Diffstat (limited to 'scribus/plugins/scriptplugin/samples')
17 files changed, 918 insertions, 0 deletions
diff --git a/scribus/plugins/scriptplugin/samples/3columnA4.py b/scribus/plugins/scriptplugin/samples/3columnA4.py new file mode 100644 index 0000000..2609c72 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/3columnA4.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" Creates 3 column layout on A4 paper and save it under 3columnA4.sla filename. This is a simple way to demonstrate creating a doc on the fly. """ + +try: + # Please do not use 'from scribus import *' . If you must use a 'from import', + # Do so _after_ the 'import scribus' and only import the names you need, such + # as commonly used constants. + import scribus +except ImportError,err: + print "This Python script is written for the Scribus scripting interface." + print "It can only be run from within Scribus." + sys.exit(1) + +def main(argv): + """This is a simple way to demonstrate creating a doc on the fly. """ + + pass # <--- Delete this line +######################### +# YOUR IMPORTS GO HERE # +######################### + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +margins = (50, 50, 50, 50) +size = (612, 792) + +def main(): + if newDocument(PAPER_A4, margins, LANDSCAPE, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGELEFT,1): + a = createText(50, 50, 230, 495) + setTextAlignment(1,a) + setText("Column A", a) + setFontSize(12, a) + b = createText(280, 50, 230, 495) + setTextAlignment(1,b) + setText("Column B", b) + setFontSize(12, b) + c = createText(510, 50, 230, 495) + setTextAlignment(1,b) + setText("Column C", c) + setFontSize(12, c) + saveDocAs("3columnA4.sla") + + +if __name__ == '__main__': + main() diff --git a/scribus/plugins/scriptplugin/samples/3columnUSLTR.py b/scribus/plugins/scriptplugin/samples/3columnUSLTR.py new file mode 100644 index 0000000..0148bac --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/3columnUSLTR.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" Creates 3 column layout on US Letter paper and save it under 3columnUSLTR.sla filename. This is a simple way to demonstrate creating a doc on the fly. """ + +try: + # Please do not use 'from scribus import *' . If you must use a 'from import', + # Do so _after_ the 'import scribus' and only import the names you need, such + # as commonly used constants. + import scribus +except ImportError,err: + print "This Python script is written for the Scribus scripting interface." + print "It can only be run from within Scribus." + sys.exit(1) + +def main(argv): + """This is a simple way to demonstrate creating a doc on the fly. """ + + pass # <--- Delete this line + + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +margins = (50, 50, 50, 50) +size = (612, 792) + +def main(): + if newDocument(PAPER_LETTER, margins, LANDSCAPE, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGELEFT, 1): + a = createText(50, 50, 230, 512) + setTextAlignment(1,a) + setText("Column A", a) + setFontSize(12, a) + b = createText(280, 50, 230, 512) + setTextAlignment(1,b) + setText("Column B", b) + setFontSize(12, b) + c = createText(510, 50, 230, 512) + setTextAlignment(1,b) + setText("Column C", c) + setFontSize(12, c) + #saveDocAs("3columnUS.sla") + + +if __name__ == '__main__': + main() diff --git a/scribus/plugins/scriptplugin/samples/CMakeLists.txt b/scribus/plugins/scriptplugin/samples/CMakeLists.txt new file mode 100644 index 0000000..a7bf662 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/CMakeLists.txt @@ -0,0 +1,22 @@ +INCLUDE_DIRECTORIES( +"${CMAKE_SOURCE_DIR}/scribus" +) + +INSTALL(FILES +3columnUSLTR.py +3columnA4.py +boilerplate.py +Calender.py +ExtractText.py +golden-mean.py +legende.py +moins_10_pourcent_group.py +plus_10_pourcent_group.py +pochette_cd.py +quote.py +sample_db_usage.py +Sample1.py +trait_de_coupe.py +wordcount.py + DESTINATION ${SAMPLESDIR} +) diff --git a/scribus/plugins/scriptplugin/samples/Calender.py b/scribus/plugins/scriptplugin/samples/Calender.py new file mode 100644 index 0000000..2d80546 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/Calender.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" This Script creates a Calendar Sheet for the Current Month """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +import calendar +import time + +def main(): + Month = time.localtime()[1] + Year = time.localtime()[0] + Objects = [] + MonthList = ["January","February","March","April","May","June","July","August","September","October","November","December"] + DaysList = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] + Xcoor = 10 + Ycoor = 30 + DayC = 0 + Calend = calendar.monthcalendar(Year, Month) + ob = createText(10, 10, 245, 20) + Title = MonthList[Month-1] + " " + str(Year) + setText(Title, ob) + Objects.append(ob) + for lx in range(45, 245, 35): + ob = createLine(lx, 30, lx, 20*len(Calend)+50) + Objects.append(ob) + for ly in range(50, 20*len(Calend)+50, 20): + ob = createLine(10, ly, 255, ly) + Objects.append(ob) + ob = createRect(10, 30, 245, 20*len(Calend)+20) + setFillColor("None", ob) + Objects.append(ob) + for day in range(7): + ob = createText(Xcoor, Ycoor, 35, 20) + setTextAlignment(ALIGN_CENTERED, ob) + setFontSize(12, ob) + if day == 6: + setTextColor("Red", ob) + setText(DaysList[day], ob) + Objects.append(ob) + Xcoor = Xcoor + 35 + Ycoor = Ycoor + 20 + for lines in Calend: + Xcoor = 10 + DayC = 0 + for rows in lines: + if rows != 0: + ob = createText(Xcoor, Ycoor, 35, 20) + setTextAlignment(ALIGN_CENTERED, ob) + if DayC == 6: + setTextColor("Red", ob) + setText(str(rows), ob) + Objects.append(ob) + Xcoor = Xcoor + 35 + DayC = DayC + 1 + Ycoor = Ycoor + 20 + groupObjects(Objects) + +if __name__ == '__main__': + if haveDoc(): + try: + setRedraw(False) + main() + finally: + setRedraw(True) + redrawAll() + else: + messageBox("Calendar Script", "Please run this script with a document open.", ICON_INFORMATION); diff --git a/scribus/plugins/scriptplugin/samples/ExtractText.py b/scribus/plugins/scriptplugin/samples/ExtractText.py new file mode 100644 index 0000000..506174f --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/ExtractText.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + +(C)2006.03.04 Gregory Pittman + +(C)2008.02.28 Petr Vanek - fileDialog replaces valueDialog + +this version 2008.02.28 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GPL, v2 (GNU General Public License as published by +the Free Software Foundation, version 2 of the License), or any later version. +See the Scribus Copyright page in the Help Browser for further informaton +about GPL, v2. + +SYNOPSIS + +This script takes the current document and extracts all the text from text frames, +and also gets the pathnames to all images. This is then saved to a file named +by the user. + +REQUIREMENTS + +You must run from Scribus and must have a file open. + +USAGE + +Start the script. A file dialog appears for the name of the file +to save to. The above information is saved to the file. + +""" +# Craig Bradney, Scribus Team +# 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826, script is GPLd + +import scribus + + +def exportText(textfile): + page = 1 + pagenum = scribus.pageCount() + T = [] + content = [] + while (page <= pagenum): + scribus.gotoPage(page) + d = scribus.getPageItems() + strpage = str(page) + T.append('Page '+ strpage + '\n\n') + for item in d: + if (item[1] == 4): + contents = scribus.getAllText(item[0]) + if (contents in content): + contents = 'Duplication, perhaps linked-to frame' + T.append(item[0]+': '+ contents + '\n\n') + content.append(contents) + elif (item[1] == 2): + imgname = scribus.getImageFile(item[0]) + T.append(item[0]+': ' + imgname + '\n') + page += 1 + T.append('\n') + output_file = open(textfile,'w') + output_file.writelines(T) + output_file.close() + endmessage = textfile + ' was created' + scribus.messageBox("Finished", endmessage,icon=0,button1=1) + + +if scribus.haveDoc(): + textfile = scribus.fileDialog('Enter name of file to save to', \ + filter='Text Files (*.txt);;All Files (*)') + try: + if textfile == '': + raise Exception + exportText(textfile) + except Exception, e: + print e + +else: + scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', \ + icon=0, button1=1) diff --git a/scribus/plugins/scriptplugin/samples/ReadMe b/scribus/plugins/scriptplugin/samples/ReadMe new file mode 100644 index 0000000..377258e --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/ReadMe @@ -0,0 +1,22 @@ +This folder contains some Example Scripts: + +3columnA4.py = Sample 3 column layout +3columnUSLTR.py = Sample 3 column layout +Calender.py = Creates a Calendar of the current Month in the current Document as a Group +ReadMe = this file +Sample1.py = Very simple Example, creates a Docmument with some Objects, saves the Document and closes it. +boilerplate.py = A template for your scripts +golden-mean.py = Creates a non printable marks in the Golden Mean of the page. +legende.py = Creates a legende for Image (filename) +moins_10_pourcent_group.py = Decrease size of the object by 10% +plus_10_pourcent_group.py = Increase size of the object by 10% +pochette_cd.py = Creates a CD/DVD pochette +quote.py = French quotation marks +sample_db_usage.py = Database HOWTO +trait_de_coupe.py +wordcount.py = Counts the count of the words :) + +Copy these Examples to any location you like and play with them. +Each script contains Docstring in the file header - this is a common Python +documentation text. You can see it by selecting Script->About Script... menu +entry. diff --git a/scribus/plugins/scriptplugin/samples/Sample1.py b/scribus/plugins/scriptplugin/samples/Sample1.py new file mode 100644 index 0000000..5205543 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/Sample1.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" A sample script """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +margins = (10, 10, 10, 30) + +def main(): + if newDocument(PAPER_A4, margins, PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT, 1): + a = createText(50, 50, 200, 80) + setText("A Test for Scribus", a) + setFontSize(20, a) + b = createEllipse(267, 391, 60, 60) + setFillColor("Red", b) + saveDocAs("Sample1.sla") + +if __name__ == '__main__': + main() diff --git a/scribus/plugins/scriptplugin/samples/boilerplate.py b/scribus/plugins/scriptplugin/samples/boilerplate.py new file mode 100644 index 0000000..85e3b5b --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/boilerplate.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys + +try: + # Please do not use 'from scribus import *' . If you must use a 'from import', + # Do so _after_ the 'import scribus' and only import the names you need, such + # as commonly used constants. + import scribus +except ImportError,err: + print "This Python script is written for the Scribus scripting interface." + print "It can only be run from within Scribus." + sys.exit(1) + +######################### +# YOUR IMPORTS GO HERE # +######################### + +def main(argv): + """This is a documentation string. Write a description of what your code + does here. You should generally put documentation strings ("docstrings") + on all your Python functions.""" + ######################### + # YOUR CODE GOES HERE # + ######################### + pass # <--- Delete this line + +def main_wrapper(argv): + """The main_wrapper() function disables redrawing, sets a sensible generic + status bar message, and optionally sets up the progress bar. It then runs + the main() function. Once everything finishes it cleans up after the main() + function, making sure everything is sane before the script terminates.""" + try: + scribus.statusMessage("Running script...") + scribus.progressReset() + main(argv) + finally: + # Exit neatly even if the script terminated with an exception, + # so we leave the progress bar and status bar blank and make sure + # drawing is enabled. + if scribus.haveDoc(): + scribus.setRedraw(True) + scribus.statusMessage("") + scribus.progressReset() + +# This code detects if the script is being run as a script, or imported as a module. +# It only runs main() if being run as a script. This permits you to import your script +# and control it manually for debugging. +if __name__ == '__main__': + main_wrapper(sys.argv) diff --git a/scribus/plugins/scriptplugin/samples/golden-mean.py b/scribus/plugins/scriptplugin/samples/golden-mean.py new file mode 100644 index 0000000..f180f94 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/golden-mean.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +"""Golden Mean for Scribus. + +This script creates supplementary guides on the page to +help design the "right" layout in golden mean (golden +ratio). + +See scribus.net and CVS for fresh versions to come... + +REQUIREMENTS: +Scribus - CVS version later 02/24/2004 or later release 1.5 + +MORE INFO: +See e.g. +http://home.att.net/~vmueller/prop/theo.html +or Google for more theory :) + +CONTACT: +email : petr@yarpen.cz +Feature requests and bug reports welcomed + + +LICENSE: + +This program 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. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +""" + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +from math import sqrt + + +def goldenMean(aSize=0): + """x = (?5-1)/2""" + return aSize * ((sqrt(5) - 1)/2) + + +def main(): + # remember user settings + unit = getUnit() + # set my environment - points needed + setUnit(0) + # Paper format + paper = pageDimension() + # set the guides. The get* functions are for "remembering" the old ones... + setVGuides(getVGuides() + [goldenMean(paper[0]), paper[0] - goldenMean(paper[0])]) + setHGuides(getHGuides() + [goldenMean(paper[1]), paper[1] - goldenMean(paper[1])]) + # restore user settings + setUnit(unit) + +if __name__ == '__main__': + if haveDoc(): + main() + else: + messageBox("Golden Mean.py", "Please run this script with a document already open", ICON_INFORMATION); diff --git a/scribus/plugins/scriptplugin/samples/legende.py b/scribus/plugins/scriptplugin/samples/legende.py new file mode 100644 index 0000000..933bc7b --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/legende.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" When you have an image selected this script creates small text legende +(caption) below the image. The new textframe contains name of the file. """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +import os + +def main(): + userUnit = getUnit() + setUnit(1) + sel_count = selectionCount() + + if sel_count == 0: + messageBox("legende.py", + "Please select the object to add a caption to before running this script.", + ICON_INFORMATION) + sys.exit(1) + + x,y = getPosition() + l,h = getSize() + texte = getImageFile() + image = os.path.basename(texte) + a = createText(x,y+h+2,l,8) + insertText(image,0,a) + setTextAlignment(2,a) + setFontSize(7,a) + setUnit(userUnit) + +if __name__ == '__main__': + main() diff --git a/scribus/plugins/scriptplugin/samples/moins_10_pourcent_group.py b/scribus/plugins/scriptplugin/samples/moins_10_pourcent_group.py new file mode 100644 index 0000000..c1ee6ef --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/moins_10_pourcent_group.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" Make selected group smaller by 10% """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +if haveDoc() and selectionCount(): + scaleGroup(1/1.1) +else: + messageBox("moins_10_pourcent_group.py", "Please select an object to scale before running this script.", ICON_INFORMATION) diff --git a/scribus/plugins/scriptplugin/samples/plus_10_pourcent_group.py b/scribus/plugins/scriptplugin/samples/plus_10_pourcent_group.py new file mode 100644 index 0000000..36d174e --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/plus_10_pourcent_group.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" Make selected group larger by 10% """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +if haveDoc() and selectionCount(): + scaleGroup(1.1) +else: + messageBox("plus_10_pourcent_group.py", "Please select an object to scale before running this script.", ICON_INFORMATION) diff --git a/scribus/plugins/scriptplugin/samples/pochette_cd.py b/scribus/plugins/scriptplugin/samples/pochette_cd.py new file mode 100644 index 0000000..0b8700c --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/pochette_cd.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" This script creates a CD Pochette - a paper pocket for CD/DVD disc """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +margins = (0, 0, 0, 0) +paper = (210, 297) + +def main(): + if newDocument(paper, margins, 1, 1, 1, NOFACINGPAGES, FIRSTPAGELEFT,1): + setUnit(1) + newPage(-1) + gotoPage(1) + createLayer("normal") + setActiveLayer("normal") + a = createText(98.5, 20, 100, 10) + setText("CD pochette - front page", a) + setFontSize(11, a) + setTextAlignment(1, a) + b = createText(28.5, 45, 120, 120) + setFillColor("None", b) + c = createText(148.5, 45, 120, 120) + setFillColor("None", c) + createLayer("bords_perdus") + setActiveLayer("bords_perdus") + img1 = createImage(24.35, 41.25 , 124.20, 127.95,) + img2 = createImage(148.55, 41.25 , 124.20, 127.95,) + createLayer("coupe") + setActiveLayer("coupe") + t1 = createLine(28.5, 38, 28.5, 43) + setLineWidth(0.1, t1) + t2 = createLine(148.5, 38, 148.5, 43) + setLineWidth(0.1, t2) + t3 = createLine(268.5, 38, 268.5, 43) + setLineWidth(0.1, t3) + t4 = createLine(28.5, 172, 28.5, 167) + setLineWidth(0.1, t4) + t5 = createLine(148.5, 172, 148.5, 167) + setLineWidth(0.1, t5) + t6 = createLine(268.5, 172, 268.5, 167) + setLineWidth(0.1, t6) + t7 = createLine(21.5, 45, 26.5, 45) + setLineWidth(0.1, t7) + t8 = createLine(21.5, 165, 26.5, 165) + setLineWidth(0.1, t8) + t9 = createLine(270.5, 45, 275.5, 45) + setLineWidth(0.1, t9) + t10 = createLine(270.5, 165, 275.5, 165) + setLineWidth(0.1, t10) + gotoPage(2) + setActiveLayer("normal") + a2 = createText(98.5, 20, 100, 10) + setText("CD pochette - back page", a2) + setFontSize(11, a2) + setTextAlignment(1, a2) + a2t = createText(204, 44, 78, 9) + setText("Mode d'emploi :", a2t) + setFontSize(13, a2t) + setTextAlignment(1, a2t) + a21 = createText(204, 54, 78, 87) + setText("Usage. TODO: tranlslate it from french", a21) + setFontSize(11, a21) + setTextAlignment(0, a21) + b2 = createText(28.5, 162.10, 117, 6) + setText("Texte sur la tranche", b2) + setFontSize(9, b2) + setTextAlignment(1, b2) + rotateObjectAbs(90, b2) + setFillColor("None", b2) + c2 = createText(34.5, 45, 137.5, 117) + setFillColor("None", c2) + d2 = createText(28.5, 162.10, 117, 6) + setText("Texte sur la tranche", d2) + setFontSize(9, d2) + setTextAlignment(1, d2) + rotateObjectAbs(90, d2) + setFillColor("None", d2) + moveObject(143.5, 0, d2) + setActiveLayer("bords_perdus") + img3 = createImage(24.35, 41.25 , 157.50, 126.50,) + setActiveLayer("coupe") + t21 = createLine(28.5, 38, 28.5, 43) + setLineWidth(0.1, t21) + t22 = createLine(34.5, 38, 34.5, 43) + setLineWidth(0.1, t22) + t23 = createLine(172, 38, 172, 43) + setLineWidth(0.1, t23) + t24 = createLine(178, 38, 178, 43) + setLineWidth(0.1, t24) + t25 = createLine(28.5, 164.5, 28.5, 169.5) + setLineWidth(0.1, t25) + t26 = createLine(34.5, 164, 34.5, 169.5) + setLineWidth(0.1, t26) + t27 = createLine(172, 164, 172, 169.5) + setLineWidth(0.1, t27) + t28 = createLine(178, 164, 178, 169.5) + setLineWidth(0.1, t28) + t29 = createLine(22.5, 45, 27.5, 45) + setLineWidth(0.1, t29) + t30 = createLine(22.5, 162, 27.5, 162) + setLineWidth(0.1, t30) + t31 = createLine(179.5, 45, 184.5, 45) + setLineWidth(0.1, t31) + t32 = createLine(179.5, 162, 184.5, 162) + setLineWidth(0.1, t32) + saveDocAs("pochette_CD.sla") + +if __name__ == '__main__': + main() diff --git a/scribus/plugins/scriptplugin/samples/quote.py b/scribus/plugins/scriptplugin/samples/quote.py new file mode 100644 index 0000000..aee0337 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/quote.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# -*- coding: iso-8859-1 -*- + +""" This script changes quotation marks from " " to french style """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +import re + +TITLE = "Text quoting" + +# These need to be declared as unicode strings until some +# charset issues in the scripter are worked out. +QUOTE_START = u"" +QUOTE_END = u"" + +def quote(textobj): + quoted_re = re.compile('"[^"]*"') + try: + text = getText(textobj) + except WrongFrameTypeError: + messageBox("quote.py", "Cannot quote text in a non-text frame", ICON_INFORMATION); + sys.exit(1) + if len(text) == 0: + return 0 # We can't very well change anything in an empty frame + count = 0 + i = 0 + selectText(0, 0, textobj) + while i < len(text): + match = quoted_re.match(text[i:]) + if match: + end = match.end() + selectText(i, 1, textobj) + deleteText(textobj) + insertText(QUOTE_START, i, textobj) + selectText(i + end - 1, 1, textobj) + deleteText(textobj) + insertText(QUOTE_END, i + end - 1, textobj) + count += 1 + i = i + end + else: + i = i + 1 + return count + + +def main(): + changed = 0 + sel_count = selectionCount() + if sel_count: + for i in range(sel_count): + changed += quote(getSelectedObject(i)) + else: + for page in range(pageCount()): + gotoPage(page) + for obj in getAllObjects(): + changed += quote(obj) + messageBox(TITLE, "%s quotations changed" % changed, + ICON_INFORMATION, BUTTON_OK) + +if __name__ == '__main__': + if haveDoc(): + try: + setRedraw(False) + main() + finally: + setRedraw(True) + redrawAll() + else: + messageBox(TITLE, "No document open", ICON_WARNING, BUTTON_OK) diff --git a/scribus/plugins/scriptplugin/samples/sample_db_usage.py b/scribus/plugins/scriptplugin/samples/sample_db_usage.py new file mode 100644 index 0000000..2b8ef1e --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/sample_db_usage.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +"""OK. This is a sample Scribus database connection with Python HOWTO. + +DESCRIPTION: +I've got questions about DB and Scribus in my personal mailbox 3-4 +times in a month. So this is an common answer for asking people. + +Even through I'm an Oracle user/developer I choose MySQL for this +example, because of its presence in the Linux distributions and +hosting availability too. +But the DB server doesn't matter due the PEP 249 - standard DB interface +(http://www.python.org/peps/pep-0249.html). +There are various modules for database accessing: +http://www.python.org/topics/database/modules.html + +Anyway - this script provides connection to the database server by the +specified values in the hostname, dbname, username, and password variables. +Then it checks the system for table names in the specified databases +and it displays it in the new document finally. Easy and understandable. + + +CONTACT: +email : petr@yarpen.cz + + +LICENSE: +This program 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. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +""" + +import sys + +# environment checking +try: + import scribus +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +try: + import MySQLdb +except ImportError: + print "You must have 'MySQLdb' installed." + sys.exit(1) + + +# connection parameters +hostname = 'server.foo.org' +dbname = 'name' +username = 'username' +password = 'password' + +# connection to the network wide server would be time consuming. So get the hint to the user. +scribus.statusMessage('Connecting to the ' + hostname + ' server. Be patient, please...') + +# Database related issues +try: + conn = MySQLdb.connect(passwd=password, db=dbname, host=hostname, user=username) +except: + scribus.messageBox('DB connection example', 'Connection error. You should specify your login in the script') + sys.exit(1) + +cur = conn.cursor() +# get the list of the databases +# it's like 'select * from dba_tables' in Oracle +count = cur.execute('show tables') +# formating the output +result = str(count) + ' table(s) in the ' + dbname + ' database.\n\n' +for i in cur.fetchall(): + result = result + i[0] + '\n' + +# Scribus presentation part +scribus.newDoc(scribus.PAPER_A5, (10, 10, 20, 20), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT) +txtName = scribus.createText(10, 10, 200, 200) +scribus.setText(result, txtName) + +scribus.statusMessage('Script done.') diff --git a/scribus/plugins/scriptplugin/samples/trait_de_coupe.py b/scribus/plugins/scriptplugin/samples/trait_de_coupe.py new file mode 100644 index 0000000..12ad789 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/trait_de_coupe.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" Draws a "crop marks" around selected object """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +def main(): + userUnit = getUnit() + setUnit(1) + x,y = getPosition() + l,h = getSize() + t1 = createLine(x, y-2, x, y-7) + setLineWidth(0.1, t1) + t2 = createLine(x+l, y-2, x+l, y-7) + setLineWidth(0.1, t2) + t3 = createLine(x, y+7+h, x, y+2+h) + setLineWidth(0.1, t3) + t4 = createLine(x+l, y+7+h, x+l, y+2+h) + setLineWidth(0.1, t4) + t5 = createLine(x-2, y, x-7, y) + setLineWidth(0.1, t5) + t6 = createLine(x-2, y+h, x-7, y+h) + setLineWidth(0.1, t6) + t7 = createLine(x+l+2, y+h, x+l+7, y+h) + setLineWidth(0.1, t7) + t7 = createLine(x+l+2, y, x+l+7, y) + setLineWidth(0.1, t7) + deselectAll() + setUnit(userUnit) + +if __name__ == '__main__': + if haveDoc() and selectionCount(): + main() + else: + messageBox("trait_de_coupe.py", "Please select an object to put crop marks around<i>before</i> running this script.", ICON_INFORMATION) diff --git a/scribus/plugins/scriptplugin/samples/wordcount.py b/scribus/plugins/scriptplugin/samples/wordcount.py new file mode 100644 index 0000000..de372d6 --- /dev/null +++ b/scribus/plugins/scriptplugin/samples/wordcount.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" Counts the words in the whole document or in a textframe """ + +import sys + +try: + from scribus import * +except ImportError: + print "This script only runs from within Scribus." + sys.exit(1) + +import re + +TITLE = "Word count" + +def wordsplit(text): + word_pattern = "([A-Za-zäöüÄÖÜß]+)" + words = [] + for x in re.split(word_pattern, text): + if re.match(word_pattern, x): + words.append(x) + return words + + +def main(): + words = 0 + sel_count = selectionCount() + if sel_count: + source = "selected textframe" + if sel_count > 1: source += "s" #plural + for i in range(sel_count): + try: + text = getText(getSelectedObject(i)) + words += len(wordsplit(text)) + except WrongFrameTypeError: + if sel_count == 1: + # If there's only one object selected, display a message + messageBox(TITLE, "Can't count words in a non-text frame", ICON_INFORMATION); + sys.exit(1) + else: + # otherwise ignore + pass + else: + source = "whole document" + for page in range(1,pageCount() + 1): + gotoPage(page) + for obj in getAllObjects(): + try: + text = getText(obj) + words += len(wordsplit(text)) + except WrongFrameTypeError: + pass # ignore the error, it just wasn't a frame we can count + + if words == 0: words = "No" + messageBox(TITLE, "%s words counted in %s" % (words, source), + ICON_INFORMATION) + + +if __name__ == '__main__': + if haveDoc(): + main() + else: + messageBox(TITLE, "No document open", ICON_WARNING) |
