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 scripting: Set the paragraph style of a single paragraph #130

Closed
gvellut opened this issue Jun 4, 2020 · 2 comments
Closed

Python scripting: Set the paragraph style of a single paragraph #130

gvellut opened this issue Jun 4, 2020 · 2 comments

Comments

@gvellut
Copy link

gvellut commented Jun 4, 2020

Hello,

I am using Scribus 1.5.5 on macOS.

I am trying to set the paragraph style of a single paragraph inside a text frame with the Python API. However, when I select a text in a paragraph with selectText then call setStyle, the paragraph style of the whole text frame is changed, as well as the styles of each of the lines.

Here is how I tested:

  • I created a new Scribus document
  • I created a new paragraph style called 'My Style' ( just a clone of the default)
  • I created a new text frame with the contents consisting of 3 lines with a single character:
a
b
c

(The styles of each of the lines is No Style and the style of the frame is Default Paragraph Style)

  • I selected the text frame in Scribus
  • I opened the Python Script console and typed:
from scribus import *
s = "My Style"
selectText(0,1)
print repr(getText())
setStyle(s)

The output from getText is 'a' as expected. However, the styles of all the lines have been changed to My Style (as well as the style of the frame). I would have expected that only the first line (which contains the selected text) would have been affected by setStyle.

This issue was referenced in #110 (at the end).

Is it actually possible to set the style of only a single paragraph ?

Thank you.

@aoloe
Copy link
Contributor

aoloe commented Jun 5, 2020

with a somehow up to date 1.5.6svn i've created an "abc" style with a red text color.

if i run:

s = "abc"
selectText(0,1)
print(getText())
scribus.setStyle(s)

the a gets red. only the a.
scribus.setStyle(s, 'Text1')

a few general notes:

  • print should be used as a function
  • if your scribus has setParagraphStyleyou should used it

I've now tested in a 1.5.5 i have laying around and indeed -- as i thought -- this is related to a bug I've reported (but could not find anymore) and that has been fixed not so long ago:

If you want setStyle to apply to a selection, you need to pass the frame name name as the second parameter.

scribus.setStyle(s, 'Text1')

does what you want.

As you see at the beginning of my comment, this has been fixed in the current build.

@aoloe aoloe closed this as completed Jun 5, 2020
@gvellut
Copy link
Author

gvellut commented Jun 5, 2020

Thank you.

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

2 participants