Difference between revisions of "Category:Scripts"

From Scribus Wiki
Jump to: navigation, search
(Created page with "Category:Categories")
 
m (Auto-Output all Scripter Commands)
 
(101 intermediate revisions by 15 users not shown)
Line 1: Line 1:
[[Category:Categories]]
+
[[Category:EN]] [[Category:Categories]]
 +
'''Other languages:''' [[:Category:Skrypty_i_wtyczki|Polski (pl)]] [[:Category:Scripts_e_Plugins|Portuguese (pt_BR)]]
 +
{{TOC right}}
 +
= Scripter =
 +
 
 +
Here is documentation about the current scripting component in Scribus:
 +
 
 +
* [[Scripter API]] -- Routines which can be used in scripts to control Scribus
 +
* [[Scripter/Databases| Databases]] -- Scripts can interact with database software like MySQL or SQLite
 +
 
 +
This wiki is capable of letting users download raw code embedded into the pages and have it appear syntax highlighted.
 +
* So as to cite python script code with proper syntax hilight, use the following tag <nowiki><syntaxhighlight lang='python'></nowiki> instead of using the usual HTML tag <nowiki><pre></nowiki>.
 +
* See example and other possible tags : [[Raw_Code_Download| Wikitext for Raw Code Download]]
 +
 
 +
Note : A new script engine is currently being integrated into Scribus. The next steps will be to get the script engine to work (should already be ok), get the editor to work, revise the structure of the API, add new functions to the API and mostly : port scripts to the new scripter. See [[Scripter Architecture|Scripter NG non-complete documentation about architecture]]
 +
 
 +
== 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 ==
 +
 
 +
<div style="border:2px solid lightgrey;padding:2px">Needs some snippets</div>
 +
 
 +
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.
 +
[[Scripter/Snippet/Main| script template main()]]. There is also a template called [[boilerplate.py]] within Scribus Script directory.
 +
 
 +
You might also check out [[scriptmaker.py]], a Python script to run outside of Scribus to make the beginnings of a script that only runs inside of Scribus!
 +
 
 +
==[[Troubleshooting Scripts]]==
 +
The content is on another page, since this one has gotten a bit out of control in terms of its size.
 +
===Iterate over all elements on a page===
 +
<syntaxhighlight lang='python'>
 +
page = 1
 +
pagenum = scribus.pageCount()
 +
content = []
 +
while (page <= pagenum):
 +
    scribus.gotoPage(page)
 +
    d = scribus.getPageItems()
 +
    for item in d:
 +
        // do something
 +
    page += 1
 +
</syntaxhighlight>
 +
 
 +
===Get content like text from a frame===
 +
<syntaxhighlight lang='python'>
 +
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])
 +
</syntaxhighlight>
 +
 
 +
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
 +
 
 +
The output for this script is collected in [[Automatic Scripter Commands list]].
 +
 
 +
<syntaxhighlight lang='python'>
 +
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\nSYNTAX:'
 +
          print res
 +
  except: pass
 +
</syntaxhighlight>
 +
 
 +
==Image Manipulation==
 +
 
 +
* [[Scripter/Images| Objects: Images]] -- Example Scripts that manipulate images in a Scribus document
 +
 
 +
==[[Beginners Scripts]]==
 +
This content has been moved to a separate page to reduce the enormity of this one.
 +
 
 +
==Basic scripts==
 +
 
 +
Scripts which give you ideas how you can solve your tasks.
 +
 
 +
* [[Poor man's mail merge]]
 +
* [[Enlarge2Page]] - Enlarge an object to the size of the page.
 +
* [[Making Guides at an Object's Borders]]
 +
* [[Using the new applyMasterPage() command]]
 +
* [[Swap Images]]
 +
* [[Creating Text Frames for Image Captions]]
 +
* [[Horizontal Rule over Text Frame]]
 +
* [[Creating an Object-sized Document]]
 +
* [[Translation helper]]
 +
 
 +
==Full functional scripts==
 +
 
 +
Scripts that are ready for achieving specific tasks
 +
{|
 +
|
 +
* [[Export all text|Export all text]] from a Scribus file
 +
* [[Export list of frames and page numbers]]
 +
* [[Script Resize selected objects|Resize selected objects]]
 +
* [[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)
 +
* [[Bullets]] Make bulleted list
 +
* [[Bullets_and_numbered_lists|Bullets and numbered lists]]
 +
* [[Scribus_Generator|Scribus Generator]] Extend Scribus with Mail Merge functionality
 +
|
 +
* [[CalendarWizard]]
 +
* [[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==
 +
 
 +
Scripts which sketch new features which may be included in future releases of Scribus
 +
 
 +
* [[Adjust a text frame to fit its content|Adjust the text frame size according to various factors]]
 +
 
 +
== Extension scripts and PyQt ==
 +
 
 +
* [[Extension script discussion]]
 +
* [[Experimental PyQt projects]]
 +
 
 +
== Python issues ==
 +
 
 +
* [[Known Scripter Issues]]
 +
 
 +
= Other =
 +
* [[Extension_script_repository ]]
 +
* [[Web optimised PDF]] &mdash; learn how to minimize PDF size, make your life easier with the included Perl script (runs outside of 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
 +
* [[Using createParagraphStyle]]
 +
* [[Text and Text Manipulation]]
 +
* Alessandro Rimoldi's blog series on scripter functions - [http://www.graphicslab.org/Blog/Blog a_l_e's blog]
 +
* [[Windows Full Python Integration]]

Latest revision as of 19:05, 22 June 2018

Other languages: Polski (pl) Portuguese (pt_BR)

Scripter

Here is 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

This wiki is capable of letting users download raw code embedded into the pages and have it appear syntax highlighted.

  • So as to cite python script code with proper syntax hilight, use the following tag <syntaxhighlight lang='python'> instead of using the usual HTML tag <pre>.
  • See example and other possible tags : Wikitext for Raw Code Download

Note : A new script engine is currently being integrated into Scribus. The next steps will be to get the script engine to work (should already be ok), get the editor to work, revise the structure of the API, add new functions to the API and mostly : port scripts to the new scripter. See Scripter NG non-complete documentation about architecture

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.

You might also check out scriptmaker.py, a Python script to run outside of Scribus to make the beginnings of a script that only runs inside of Scribus!

Troubleshooting Scripts

The content is on another page, since this one has gotten a bit out of control in terms of its size.

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

The output for this script is collected in Automatic Scripter Commands list.

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\nSYNTAX:'
           print res
   except: pass

Image Manipulation

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

Beginners Scripts

This content has been moved to a separate page to reduce the enormity of this one.

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

Other

Pages in category "Scripts"

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