Category:Scripts: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
(42 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[[Category:EN]] [[Category:Categories]]
[[Category:EN]] [[Category:Categories]]
'''Other languages:''' [[:Category:Skrypty_i_wtyczki|Polski (pl)]] [[:Category:Scripts_e_Plugins|Portuguese (pt_BR)]]
'''Other languages:''' [[:Category:Skrypty_i_wtyczki|Polski (pl)]] [[:Category:Scripts_e_Plugins|Portuguese (pt_BR)]]
 
{{TOC right}}
= Scripter =
= Scripter =


Line 7: Line 7:
Note: The new script engine "ScripterNG" is currently being integrated into Scribus. The next steps will be:
Note: The new script engine "ScripterNG" is currently being integrated into Scribus. The next steps will be:
* get the script engine to work (should already be ok)
* get the script engine to work (should already be ok)
* get the editor to work (i'm stucked there)
* get the editor to work (i'm stuck there)
* revise the structure of the API
* revise the structure of the API
* add new functions to the API
* add new functions to the API


* [[Scripter Architecture|Scripter NG non-complete documentation about architecture]]
[[Scripter Architecture|Scripter NG non-complete documentation about architecture]]
</div>
</div>


Line 19: Line 19:
* [[Scripter/Databases| Databases]] -- Scripts can interact with database software like MySQL or SQLite
* [[Scripter/Databases| Databases]] -- Scripts can interact with database software like MySQL or SQLite
* Alessandro Rimoldi's blog series on scripter functions - [http://www.graphicslab.org/Blog/Blog a_l_e's blog]
* Alessandro Rimoldi's blog series on scripter functions - [http://www.graphicslab.org/Blog/Blog a_l_e's blog]
This wiki is capable of letting users download raw code embedded into the pages. Here is how: - [[Raw_Code_Download| Wikitext for Raw Code Download]]
== Pure Python Functions ==
The open() function is a pure python function and does not involve any
Scribus code. Here are some pages with advices on how to handle unicode file
names in python:
- http://docs.python.org/tutorial/inputoutput.html
- http://www.evanjones.ca/python-utf8.html
- http://boodebr.org/main/python/all-about-python-and-unicode
The string returned by the Scribus fileDialog() function is always Unicode UTF-8 encoded.
If file is not closed after python error within Scribus:
This is up to you to handle python exceptions, Scribus cannot do that in your place


== Script snippets ==
== Script snippets ==
Line 26: Line 43:
This section contains snippets you can use to create your own scripts.
This section contains snippets you can use to create your own scripts.


It will feature:
It features:


* reading a file
* reading a file
Line 34: Line 51:


===Script Template===
===Script Template===
Here is a '''script template''' with all setups (for writing your own script): [[Scripter/Snippet/Main| main()]]
Here is a '''script template''' with all setups. Use it as a ''starting point'' for writing your own script, fill in your application specific code.
[[Scripter/Snippet/Main| script template main()]]. There is also a template called [[boilerplate.py]] within Scribus Script directory.


===Go through all elements on a page===
===Iterate over all elements on a page===
<pre>
<pre>
page = 1
page = 1
Line 49: Line 67:
</pre>
</pre>


===Get content like text out of a frame===
===Get content like text from a frame===
<pre>
<pre>
content = []
content = []
Line 74: Line 92:
*    LatexFrame = 9,
*    LatexFrame = 9,
*    Multiple = 99
*    Multiple = 99
===Auto-Output all Scripter Commands===
From Scribus User http://meiradarocha.jor.br  Mailinglist Feb. 2012
<pre>
d = dir(scribus)
for j in d:
  try:
      exec 'res = '+j+'.__doc__'
      if res[0:5] == 'float':
          print '\nCONSTANT:\n',j,'\nVALUE: float'
          exec 'print '+j+'\n'
      elif res[0:5] == 'int(x':
          print '\nCONSTANT:\n',j,'\nVALUE: integer'
          exec 'print '+j+'\n'
      elif res[0:5] == 'tuple':
          print '\nTUPLE:\n',j,'\nVALUE:'
          exec 'print repr('+j+')\n'
      elif res[0:4] == 'str(':
          print '\nSTRING:\n',j,'\nVALUE:'
          exec 'print repr('+j+')\n'
      else:
          print '\nFUNCTION:\n'+j+'\n\nSINTAX:'
          print res
  except: pass
</pre>


==Image Manipulation==
==Image Manipulation==
Line 80: Line 124:


==Beginners Scripts==
==Beginners Scripts==
{| cellpadding=5px |
{| cellpadding=5px | borders=1px
! Link to Script !! Scripter commands demonstrated
! Script (w/ Screenshot) !! Scripter commands demonstrated
|-
|-
| width=390px |
| width=390px |<center>[[Elementary Rectangle]]</center> [[Image:Elementary_rectangle.png|frame|link=Elementary Rectangle|200x300px|center|alt=simple rectangle made with scribus python script|Elementary Rectangle generated from python]]
* [[Elementary Rectangle]]
|newDocument, createRect, setCornerRadius, setLineWidth, setFillColor, setLineColor, saveDocAs  
| newDocument, createRect, setCornerRadius, setLineWidth, setFillColor, setLineColor, saveDocAs
|-
|-
|
|
* [[Drawing Lines and Python "For loops"]]
* [[Drawing Lines and Python "For loops"]]
| newDocument, createLine, setLineWidth, setLineColor, setFillShade, createRect, saveDocAs
| newDocument, createLine, setLineWidth, setLineColor, setFillShade, createRect, saveDocAs
|-
|
* [[Drawing Circles with Radii]]
| newDocument, createLine, setLineWidth, setLineColor, zoomDocument, saveDocAs
|-
|-
|
|
Line 129: Line 176:
| width=550px| haveDoc, createLine, setLineWidth, setLineColor, setFillColor, createText, setFont, setFontSize, setTextAlignment, valueDialog, messageBox, docChanged
| width=550px| haveDoc, createLine, setLineWidth, setLineColor, setFillColor, createText, setFont, setFontSize, setTextAlignment, valueDialog, messageBox, docChanged
|-
|-
|
| createColor(),
* [[A Standard Form with Barcodes and Custom Entries]]
* [[A Standard Form with Barcodes and Custom Entries]]
| newDoc, createLine, setLineWidth, setLineColor, setFillColor, createLayer, setActiveLayer, createText, setFont, setFontSize, setTextAlignment, selectText, setTextDistances, valueDialog, messageBox
| newDoc, createLine, setLineWidth, setLineColor, setFillColor, createLayer, setActiveLayer, createText, setFont, setFontSize, setTextAlignment, selectText, setTextDistances, valueDialog, messageBox
Line 173: Line 220:
|
|
* [[Image Wizard Advanced]]
* [[Image Wizard Advanced]]
|-
|
* [[Split Image Across Gutter]]
|-
|-
|
|
Line 213: Line 263:
|
|
* [[Autoquote2]] &ndash; a new and improved Autoquote.py
* [[Autoquote2]] &ndash; a new and improved Autoquote.py
|-
|
* [[copyObject() and pasteObject()]]
| haveDoc, selectionCount, messageBox, valueDialog, getSelectedObject, pageCount, currentPage, gotoPage. Also shows use of Python split function for parsing the input from valueDialog. copyObject and pasteObject are new commands that you will only have once you follow the directions to install them into your svn directory and rebuild Scribus.
|-
|
* [[Convert RGB imported colors to CMYK]]
| getColors(), defineColor(), replaceColor(), deleteColor()
|-
|
* [[Convert all colors to CMYK]]
| getColors(), defineColor(), replaceColor(), deleteColor()
|-
|
* [[en+emdash.py]]
|
|-
|}
|}


Line 229: Line 296:
* [[Export all text|Export all text]] from a Scribus file
* [[Export all text|Export all text]] from a Scribus file
* [[Script Resize selected objects|Resize selected objects]]
* [[Script Resize selected objects|Resize selected objects]]
* [[formatxml|Import xml and apply styles]]
* [[formatxml|Import XML and apply styles]]
* [[align_to_left_page_margin|Align to the left page margin]] (after adding a new page in a double page document)
* [[align_to_left_page_margin|Align to the left page margin]] (after adding a new page in a double page document)
* [[Bullets]]. Make bulleted list.
* [[Bullets]] Make bulleted list
* [[Bullets_and_numbered_lists | Bullets and numbered lists]]
* [[Bullets_and_numbered_lists|Bullets and numbered lists]]
* [[Scribus_Generator | Scribus Generator]]. Extend Scribus with Mail Merge functionality.
* [[Scribus_Generator|Scribus Generator]] Extend Scribus with Mail Merge functionality
* [[Image crop, resize and CMYK conversion. Save and reload in TIFF format]].
* [[Image crop, resize and CMYK conversion. Save and reload in TIFF format]]
* [[Image crop, resize and color conversion GUI]]
* [[Apply basic ligatures to a document]]
* [[Import CSV Data]]
* [[Automatic story formatting]]
* [[Clean-up the imported text based on the Slovak typographic rules]]


==Scripting new Scribus' functions==
==Scripting new Scribus' functions==
Line 250: Line 322:


* [[Known Scripter Issues]]
* [[Known Scripter Issues]]
[[Scrambling Text]]


= Other =
= Other =
Line 256: Line 330:
* [[Imagemagick Imposition]] &ndash; a bash script doing simple imposition of PNG files exported from Scribus
* [[Imagemagick Imposition]] &ndash; a bash script doing simple imposition of PNG files exported from Scribus
* [[Printing_4-up_tickets_to_hard_copy_printer]] Shows a) automatic numbering in text boxes and b) hard-copy printing from script
* [[Printing_4-up_tickets_to_hard_copy_printer]] Shows a) automatic numbering in text boxes and b) hard-copy printing from script
[[Applying a Frame Style]]
* [[Using createParagraphStyle]]

Revision as of 00:20, 8 June 2014

Other languages: Polski (pl) Portuguese (pt_BR)

Scripter

Note: The new script engine "ScripterNG" is currently being integrated into Scribus. The next steps will be:

  • get the script engine to work (should already be ok)
  • get the editor to work (i'm stuck there)
  • revise the structure of the API
  • add new functions to the API

Scripter NG non-complete documentation about architecture

Here ist documentation about the current scripting component in Scribus:

  • Scripter API -- Routines which can be used in scripts to control Scribus
  • Databases -- Scripts can interact with database software like MySQL or SQLite
  • Alessandro Rimoldi's blog series on scripter functions - a_l_e's blog

This wiki is capable of letting users download raw code embedded into the pages. Here is how: - Wikitext for Raw Code Download

Pure Python Functions

The open() function is a pure python function and does not involve any Scribus code. Here are some pages with advices on how to handle unicode file names in python:

- http://docs.python.org/tutorial/inputoutput.html - http://www.evanjones.ca/python-utf8.html - http://boodebr.org/main/python/all-about-python-and-unicode

The string returned by the Scribus fileDialog() function is always Unicode UTF-8 encoded.

If file is not closed after python error within Scribus: This is up to you to handle python exceptions, Scribus cannot do that in your place

Script snippets

Needs some snippets

This section contains snippets you can use to create your own scripts.

It features:

  • reading a file
  • updating a status bar
  • selecting a frame
  • pausing the screen update

Script Template

Here is a script template with all setups. Use it as a starting point for writing your own script, fill in your application specific code. script template main(). There is also a template called boilerplate.py within Scribus Script directory.

Iterate over all elements on a page

page = 1
pagenum = scribus.pageCount()
content = []
while (page <= pagenum):
    scribus.gotoPage(page)
    d = scribus.getPageItems()
    for item in d:
        // do something
    page += 1

Get content like text from a frame

content = []
d = scribus.getPageItems()
for item in d:
    if (item[1] == 4):
        contents = scribus.getAllText(item[0])
        if (contents in content):
            contents = 'Duplication, perhaps linked-to frame'
            content.append(contents)
        elif (item[1] == 2):
            imgname = scribus.getImageFile(item[0])

ITEM TYPE

  • ItemType1 = 1,
  • ImageFrame = 2,
  • ItemType3 = 3,
  • TextFrame = 4,
  • Line = 5,
  • Polygon = 6,
  • PolyLine = 7,
  • PathText = 8,
  • LatexFrame = 9,
  • Multiple = 99

Auto-Output all Scripter Commands

From Scribus User http://meiradarocha.jor.br Mailinglist Feb. 2012

d = dir(scribus)
for j in d:
   try:
       exec 'res = '+j+'.__doc__'
       if res[0:5] == 'float':
           print '\nCONSTANT:\n',j,'\nVALUE: float'
           exec 'print '+j+'\n'
       elif res[0:5] == 'int(x':
           print '\nCONSTANT:\n',j,'\nVALUE: integer'
           exec 'print '+j+'\n'
       elif res[0:5] == 'tuple':
           print '\nTUPLE:\n',j,'\nVALUE:'
           exec 'print repr('+j+')\n'
       elif res[0:4] == 'str(':
           print '\nSTRING:\n',j,'\nVALUE:'
           exec 'print repr('+j+')\n'
       else:
           print '\nFUNCTION:\n'+j+'\n\nSINTAX:'
           print res
   except: pass

Image Manipulation

  • Objects: Images -- Example Scripts that manipulate images in a Scribus document

Beginners Scripts

Script (w/ Screenshot) Scripter commands demonstrated
Elementary Rectangle
simple rectangle made with scribus python script
Elementary Rectangle generated from python
newDocument, createRect, setCornerRadius, setLineWidth, setFillColor, setLineColor, saveDocAs
newDocument, createLine, setLineWidth, setLineColor, setFillShade, createRect, saveDocAs
newDocument, createLine, setLineWidth, setLineColor, zoomDocument, saveDocAs
newDocument, createEllipse, setLineWidth, setFillColor, setFillShade, saveDocAs, currentPage, setHGuides, messageBox, statusMessage, progressReset
haveDoc, createLayer, getActiveLayer, setActiveLayer, createText, setUnit, setText, setTextColor, setFontSize, rotateObject
haveDoc, valueDialog, getUnit, setUnit, getPageSize, getPageMargins,
defineColor, createEllipse, setLineWidth, setLineColor, setFillColor, createLine, getPageSize, createRect
valueDialog, getColor, getLayers, createLayer, setActiveLayer, setHGuides, setVGuides, getHGuides, getVGuides, createText, setTextColor, insertText, setFontSize, setLineSpacing, defineColor, createRect, groupObjects, createLine, setLineColor, setLineWidth, createEllipse, haveDoc, messageBox
haveDoc, getUnit, setUnit, getPageSize, getPageMargins, setMargins, messageBox, statusMessage, progressReset
haveDoc, setUnit, valueDialog, createLine, setLineWidth, setLineColor, setFillColor
haveDoc, createLine, setLineWidth, setLineColor, setFillColor, createText, setFont, setFontSize, setTextAlignment, valueDialog, messageBox, docChanged
createColor(), newDoc, createLine, setLineWidth, setLineColor, setFillColor, createLayer, setActiveLayer, createText, setFont, setFontSize, setTextAlignment, selectText, setTextDistances, valueDialog, messageBox
haveDoc, valueDialog, createLine, setLineWidth, setLineColor, setFillColor, createText, setTextColor, setText, setTextAlignment, setFont, setFontSize, rotateObject
haveDoc, valueDialog, setUnit, createLine, setLineWidth, setLineColor, setFillColor, createText, setTextColor, setText, setTextAlignment, setFont, setFontSize
fileDialog, haveDoc, setUnit, valueDialog, createLine, setLineWidth, setLineColor, setFillColor, createPolyLine
valueDialog, messageBox, haveDoc, importSVG – much of the script involves mathematical calculations
getPageSize, fileDialog, createImage, setScaleImageToFrame, setFillColor, setLineColor, getImageScale, sizeObject, haveDoc, messageBox
This is an old script (Scribus 1.3.3.3), so be sure to check the precise names of commands. If you find errors, let us know or edit the wiki page to correct.
messageBox, createLine, setLineColor, haveDoc, statusMessage, progressReset
There is a minor usage of Scribus commands here, but it does show how to set up a Tkinter dialog for multiple variable entry.
newDoc, newPage, createText, setText, setTextAlignment, setFont, setFontSize
This is almost a script fragment even though it could work on its own. What it shows is the basic operation to import information from a simple structured text file and incorporate into a document. Could be adapted for mail merge, for example.
haveDoc, selectionCount, getSelectedObject, setScaleImageToFrame, getImageScale, scaleImage, docChanged
not sure if this script works
haveDoc, selectionCount, getSelectedObject, setProperty, moveObject, docChanged
replaceColor, docChanged
This is a "script-let" really, but quickly shows how to change or delete colors in a document. No checking for errors.
haveDoc, fileDialog, messageBox, pageCount, getPageItems, gotoPage, getAllText, getImageFile
valueDialog, messageBox
This is a utility that just happens to run in Scribus, using the valueDialog and messageBox to do what the title says.
getPageSize, getPageMargins, createText, setFontSize, setTextAlignment, insertText, getColorNames, statusMessage, progressTotal, getColor, progressSet, haveDoc, openDoc, fileDialog, messageBox, getColorsFromDocument, newDocument, setUnit, deleteColor, defineColor, valueDialog, newPage, createRect, setFillColor, setLineColor
messageBox, valueDialog
haveDoc, selectionCount, messageBox, valueDialog, getSelectedObject, pageCount, currentPage, gotoPage. Also shows use of Python split function for parsing the input from valueDialog. copyObject and pasteObject are new commands that you will only have once you follow the directions to install them into your svn directory and rebuild Scribus.
getColors(), defineColor(), replaceColor(), deleteColor()
getColors(), defineColor(), replaceColor(), deleteColor()

Basic scripts

Scripts which give you ideas how you can solve your tasks.

Full functional scripts

Scripts that are ready for achieving specific tasks

Scripting new Scribus' functions

Scripts which sketch new features which may be included in future releases of Scribus

Extension scripts and PyQt

Python issues

Scrambling Text

Other

Pages in category "Scripts"

The following 103 pages are in this category, out of 103 total.