[scribus] [Fwd: Re: while loop in python script crashes scribus]

a.l.e ale.comp_06 at xox.ch
Fri Jan 30 13:55:56 CET 2009


[sorry, wrong key... here the full message]

hi chantal

>     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
> 			sizeObject(Width,Height,TextBox)
> 			OverflowChar = scribus.textOverflows(TextBox)
>   
not sure if i got it right (can't try the script atm... i could do it 
tomorrow...) but:

i think you're not doing what you think you're doing :-)

here you are reading the text line by line and if the line is empty (are 
you sure that '\n' is the end of line character? in most languages you 
have to use "\n" (with double quotes)), set the text as the snippet read 
up to now, minus the empty lines.
you won't add the last lines before EOF since you will break before having the chance
to output the buffer in "Add".

but even then: i guess you'd better create two loops:
- the first loop will read the text file into a variable
- then you add it to the text frame
  (you may use scribus.setText() to add each line to the frame,
  without storing them in a variable)
- then you loop until the frame is high enough.

when setting the height of the frame, you should probably stop before getting
a frame which is longer than the page.

i would also do some test and see if OverflowChar ever returns a results which is > 0 ...

voilà, i hope that what i wrote will be of some help for you.
now i really have to go back to work!


good luck!
a.l.e





More information about the scribus mailing list