Scribus Forums

Scribus => Text and Typography => Topic started by: sersha on September 04, 2023, 08:23:40 PM

Title: Formatting poetry
Post by: sersha on September 04, 2023, 08:23:40 PM
Greetings to all! I wonder, if anybody found the solution to properly indent a poetry piece of an arbitrary length. Like:

lineone line one line one
     linetwo line two line two
linethree line three line three
     linefour line four line four  ...and so on

I imagine creating a style with the second line indented, but that means you must apply it to every other line, which is still quite laborious with a longer piece. Maybe a script could be created for the purpose? Ideas, suggestions are very welcome!
Title: Re: Formatting poetry
Post by: Nermander on September 04, 2023, 09:01:51 PM
The simple solution is maybe to add a tab at the start of every second line?
Title: Re: Formatting poetry
Post by: PatJr on September 05, 2023, 05:21:08 AM
did you try and change the indents?
it can be a little tricky, you have to type the values in, the slider things are a little janky.
Title: Re: Formatting poetry
Post by: sersha on September 05, 2023, 01:38:34 PM
Thank you all who responded!
I did with tabs on second line, manually.
I also experimented with the second line indents and creating a style for that. It is better in a sense, but still a lot of manual work.
I am lazy! Thus looking for some sort of automated solution, like select a piece, apply a style or run a script and Voila! magic formatting happened!
But maybe it is not such a big deal, since rarely a poetry book is that huge... and it is easier to live with the manual setting of it.
Title: Re: Formatting poetry
Post by: a.l.e on September 05, 2023, 10:10:05 PM
hi sersha

in my eyes, using the tabs is rather a good idea.

but you mentioned that a script could also apply the styles and here is a script that does it:

- just apply the paragraph style to the first n paragraphs in the frames
- select the n paragraphs
- run the script to apply the style from the selection to the rest of the frame

https://github.com/aoloe/scribus-script-repository/tree/master/style-repeater

try:
    import scribus
except ImportError:
    print('This script must be run from inside Scribus')
    sys.exit()

def main():
    if not scribus.haveDoc():
        scribus.messageBox('Error', 'You need to have a document open')
        return

    if scribus.selectionCount() == 0 or scribus.getObjectType() != 'TextFrame':
        scribus.messageBox('Error', 'You need to select a text frame')
        return

    # get current selection
    selected_text = scribus.getFrameText()

    scribus.selectFrameText(0, 0)

    frame_text = scribus.getFrameText().strip('\r')
   
    if len(selected_text) == len(scribus.getFrameText()):
        scribus.messageBox('Error', 'There is no selection in the text frame')
        # no text selected
        return

    paragraphs_count = selected_text.count('\r') + 1

    frame_paragraphs = frame_text.strip('\r').split('\r')

    styles = []
    start = 0
    for paragraph in frame_paragraphs[0:paragraphs_count]:
        scribus.selectFrameText(start, len(paragraph))
        styles.append(scribus.getParagraphStyle())
        start += len(paragraph) + 1

    for i, paragraph in enumerate(frame_paragraphs[paragraphs_count:]):
        scribus.selectFrameText(start, len(paragraph))
        scribus.setParagraphStyle(styles[i % len(styles)])
        start += len(paragraph) + 1

    scribus.selectFrameText(0, 0)
       
if __name__ == "__main__":
    main()
Title: Re: Formatting poetry
Post by: a.l.e on September 08, 2023, 06:20:32 PM
btw, it looks like this:

(https://forums.scribus.net/index.php?action=dlattach;attach=4539)