Author Topic: setText Changes Alignment  (Read 580 times)

MattMiller

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
  • Scribus User
setText Changes Alignment
« on: February 18, 2021, 10:56:18 pm »
I create a text frame and set the alignment to "Align Text Right" using the Text Properties window, or to ALIGN_RIGHT using setTextAlignment.  If I then enter text into the frame manually the text aligns right as it should, but if I use setText() from the scripter to populate the frame the alignment suddenly changes to "Align Text Left."  If first use setText() to populate the frame, and then use setTextAlignment() to set ALIGN_RIGHT, then everything is fine.

So, I have a workaround, but I'm wondering if I'm missing something here.  Shouldn't I be able to use setTextAlignment() and then use setText() and have the alignment stay?

I'm on Windows, and I see this in 1.5.6.1 and 1.5.7.svn.
« Last Edit: February 18, 2021, 11:03:28 pm by MattMiller »

bastianilso

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
  • Scribus User
Re: setText Changes Alignment
« Reply #1 on: December 05, 2021, 04:40:12 pm »
I experienced the same as MattMiller - i figured its because setText first removes all text and therefore all settings applied to the previous text before it inserts the new text - this behaviour can be simulated in scribus editor too. To work around the problem, I implemented my own "replaceText()" function, which inserts the new text, before it deletes the old text. Essentially it creates the same result as setText, except it "remembers" the settings from the previous text in the text frame.

Code: [Select]
def replaceText(text, item):
    txtwidth = getTextLength(item[0])
    insertText(text, txtwidth, item[0])
    selectText(0,txtwidth, item[0])
    deleteText(item[0])

I hope this can help someone who search for this issue in the future.

 

palmate