Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: setText seems to change the formatting of the text #110

Open
probonopd opened this issue Jan 26, 2019 · 5 comments
Open

Python: setText seems to change the formatting of the text #110

probonopd opened this issue Jan 26, 2019 · 5 comments

Comments

@probonopd
Copy link

probonopd commented Jan 26, 2019

When using Python scripts, setText seems to change the formatting of the text rather than just to change the contents. A workaround can be used:

def changeText(text, textframe):
    """
    setText seems to change the formatting of the text, hence we are using this workaround
    """
    texlen = scribus.getTextLength(textframe)
    insertText(text, -1, textframe)
    selectText(0,texlen,textframe)
    deleteText(textframe)
    return

But this is a bug imho that should be fixed properly.

@aoloe
Copy link
Contributor

aoloe commented Jan 26, 2019

this is a well known bug that also happens in the UI.

there are a couple of changes needed to really solve this issue (without introducing further complexity):

it's imo an important change that should be done asap in scribus. but i don't dare to make such a change without first having a commitment from the team that they agree with it and are ready to merge patches in a timely manner.

@aoloe
Copy link
Contributor

aoloe commented Jan 26, 2019

to be more clear: i did not check in the code but this is what i think is happening:

  • you are deleting the whole content of the frame.
  • now the frame is empty and scribus looks at the formatting defined for the frame.
  • the next character will be using the frame formatting and not the formatting of the last deleted character.

of course, it would somehow be possible to solve the issue by storing somewhere the formatting of the last character. but this would add further complexity and, probably, new bugs.
the simple solution is to not store any formatting in the frame, except when the frame is empty.

@probonopd
Copy link
Author

probonopd commented Jan 26, 2019

The issue also occurs when the formatting is set for the entire frame, not just for the individual characters inside the frame. This is why I think it is a bug.

@badcommandorfilename
Copy link

Hi, apologies for hijacking the report,

I have a similar issue relating to the "getText()"/"getTextLines()" scripting API features. Am I correct in my understanding that there is no way to get/set the Style/Formatting of a single line... only the Text content as a string?

I found https://bugs.scribus.net/view.php?id=15403 in the Mantis tracker, which indicates that I can get the style of a frame, but that isn't able to get or manipulate the style of a paragraph. If you use the Story Editor to format your document then this isn't useful.

@aoloe - what can we do to read/write the style of a single line/paragraph within a frame through the scripting API without affecting the whole frame? Is this just something that I could expose to the API with a single method call, or would this rely on the "major changes" you referred to above?

Thanks for all your hard work - if it helps I can open this as a separate issue.

@aoloe
Copy link
Contributor

aoloe commented Jan 28, 2019

@badcommandorfilename i don't 100% get what you are asking for.

i did not test it, but you should be able to select part of the text (there is a scripter command for it) and then get or set the paragraph style (setStyle / getStyle).

please, open a separate ticket for different issues...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants