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

Chantal Rosmuller chantal at antenna.nl
Fri Jan 30 14:09:17 CET 2009


On Friday 30 January 2009 13:55:56 a.l.e wrote:
> [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
>
>
> _______________________________________________
> scribus mailing list
> scribus at lists.scribus.net
> http://lists.scribus.net/mailman/listinfo/scribus

Hi, thanks for your time. I based my script on:

http://wiki.scribus.net/index.php/Importing_addresses_from_a_text_file

it does work, each paragraph gets its own textframe. Only the height of the 
textbox frames is a problem.

At first I counted the characters and based the textframe height on that but 
that does not really work 100% of the time as you can imagine :).

Overflowchar does return a result I tried printing it, and when I use if 
instead of while it also works. But that is not really what I want ofcourse 
because it is not flexible enough. But I tried it anyway just to see if I got 
a result (and I did).

Thanks again for your time, its okay if the issue gets resolved later it 
doesn't have to be today , lots of other stuff in the script that I have to 
work on :).

Chantal




More information about the scribus mailing list