[scribus] while loop in python script crashes scribus

Chantal Rosmuller chantal at antenna.nl
Fri Jan 30 12:29:40 CET 2009


Hi list,

I want to write a python script that imports text and automatically resizes 
the size of the text boxes when they are too small. I use the textoverflows 
function for this. But for some reason my script crashes the whole program 
(scribus 1.3.3.11). This is caused by the while loop, if you replace "while" 
by "if" it kind of works, well, it doesn't crash, but it does not do what I 
want.

Another (minor) issue, the script works from the script console but not 
from "execute scripts"
Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "/home/chantal/scribus/loopcrash.py", line 67, in <module>
    deleteObject(TextBox)
NameError: name 'deleteObject' is not defined

Here is my script (change the TexFile value if you want to execute it), the 
text is longer than the page but you can ignore that I already solved it in 
the long version of the script:

#!/usr/bin/env python
# ---------------------------------------------------#
# check of het script vanuit scribus wordt gestart   #
#----------------------------------------------------#
import sys
try:
   import scribus
except ImportError:
   print "This script only works from within Scribus"
   sys.exit(1)
#----------------------------------------------------#
# declareer variabelen                               #
#----------------------------------------------------#
VerticalPosition = 100 #verticale positie eerste textbox tov, voor de volgende 
wordt het uitgerekend aan de hand van de hoogte
Width = 325.99 #text box width
Height = 50 #initial text box height
VerticalMarge = 10 #afstand tussen de tekstboxen
TextFile='' #tekst file dat geimporteerd moet worden
Page = 0 # bladzijde, we beginnen bij 0
Add = ''
OverflowChar = 0 #overflowing characters, we will adjust textbox height until 
this is 0
#----------------------------------------------------#
# actie                                              #
#----------------------------------------------------#
if scribus.newDoc(scribus.PAPER_A5, 
(51.02,42.52,42.52,53.86),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, 
scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT):
    # laad stylen
    TextFile = open('/home/chantal/scribus/wiki.txt', 'r')
    while 1:
        info = TextFile.readline()
        if not info: break
        if info != '\n':
            Add = Add + info
        else:
		#maak textbox
		TextBox = scribus.createText(60, VerticalPosition, Width, Height)
		VerticalPosition=VerticalPosition+VerticalMarge+Height
		#vul de textbox
		scribus.setText(Add, TextBox)
		#check of alles wel past
		OverflowChar = scribus.textOverflows(TextBox)
		while OverflowChar > 0:
			Height=Height+100
			deleteObject(TextBox)
			TextBox = scribus.createText(60, VerticalPosition, Width, Height)
			scribus.setText(Add, TextBox)
			OverflowChar = scribus.textOverflows(TextBox)




More information about the scribus mailing list