Scribus Forums

Scribus => Scripts and Plugins => Topic started by: eudoxos on September 12, 2017, 08:18:20 PM

Title: setting frame text without resetting style
Post by: eudoxos on September 12, 2017, 08:18:20 PM
I am working on a collaboratively translated document (a comic book) with many irregularly distributed text frames with different styles (think of descriptions, callouts, etc); the style is set per-frame. I export plain-text of text frames into google document, let people improve the translation, then load it back (it is a bit more complicated to match frames with pages and such, but that's is not important now).

I set new text of each frame, something like:
for page in range(1,scribus.pageCount()+1):
  for frame in scribus.getPageItems():
    if frame[1]!=4: continue # not a text frame
    newText=... # grab new text value
    scribus.setText(newText,frame)

but what happens is that styles of processed frames are reset.

Is there a way to set text while preserving the style information? Note that even in (rare) cases of multi-paragraph frames, they still all have the same style which I applied to the frame itself.

Thanks!
Title: Re: setting frame text without resetting style
Post by: a.l.e on September 12, 2017, 10:25:19 PM
stelf came up with this solution:

https://gist.github.com/stelf/d4e72a19ce1dbb18bffce4d4768d48ba


import scribus

tb = 'Text2'
repl = 'new cntent'

l = scribus.getTextLength(tb)
scribus.selectText(0, l-1, tb)
scribus.deleteText(tb)
scribus.insertText(repl, 0, tb)

l = scribus.getTextLength(tb)
scribus.selectText(l-1, 1, tb)
scribus.deleteText(tb)


which is also what you would do in the UI.

i hope that someday the way formatting is defined will be fixed... until that time such hacks will be needed...

Title: Re: setting frame text without resetting style
Post by: eudoxos on September 13, 2017, 07:32:57 PM
Thnanks :) works nicely. I hope new scripting functionality with a saner API (like the never-finished scripter-ng) will come, this feels so much like visual basic ;D
Title: Re: setting frame text without resetting style
Post by: a.l.e on September 13, 2017, 07:48:19 PM
i hope too (and i'm working to make it real... help is always welcome!)

but this issue is in scribus itself and cannot (really) be solved in the scripter...
Title: Re: setting frame text without resetting style
Post by: eudoxos on September 16, 2017, 08:29:39 PM
Quotei hope too (and i'm working to make it real... help is always welcome!)
where can I check what is being worked on? Github? And which scripter plugin? Got lost a bit, -ng, 2, ... ;) Thanks for your work!
Title: Re: setting frame text without resetting style
Post by: a.l.e on September 16, 2017, 09:39:31 PM
my work on the new scripter was/is in this github repository:

https://github.com/aoloe/scribus-plugin-scripter

the most interesting information source is

https://github.com/aoloe/scribus-plugin-scripter/issues/3

as you can read in the (currently) last comment of mine, i'm right now testing a new approach using pybind11.

my tentatives can be followed here:

https://github.com/aoloe/cpp-pybind11-playground

it still looks a bit wild but i'm close to get a prototype that could be used for building a new scripter.
and, with a bit of luck, that repository will transform in a nice manual on how to embed a python interpreter inside of a c++ application.
(imo, this is something that is not well documented, and every project is creating its own solution)

the reason why i'm trying a new approach is this issue:

https://github.com/aoloe/scribus-plugin-scripter/issues/7
(we cannot get signals and slot to cross the c++ -> python boundary)

combined with the issue 3 linked above -- which states that the technology used by the scripter created by henning is not supported anymore (and have never really been supported) -- i prefer restarting from scratch, get much inspiration from the wonderful previous new scripter (really, it looks like a very clever solution... even if i could not understand everything!), and produce a new scripter with a very similar API as the so called scripter 2.

i hope to have my tentatives finished by the end of next week and then i could need work with defining the API and porting the code from the scripter 1 and 2 to the scripter 3

ah, please, forget as soon as possible the name scripter 3... if it gets into scribus, it should simply be the new scripter or the pybind11 scripter : - )

To cut a long story short: it's saturday evening,  time to party!
Title: Re: setting frame text without resetting style
Post by: eudoxos on September 17, 2017, 10:20:40 PM
Wow, very happy you chose pybind11. I have a LOT of experience with boost::python and have liked pybind11 from the very beginning (still know only from docs), it is solving a lot of boost::python's issues, plus is much more lightweight. I will look at it. Good luck and thanks for the thorough information! vaclav
Title: Re: setting frame text without resetting style
Post by: a.l.e on September 18, 2017, 09:18:58 AM
thanks for your "insight" on pybind!

i'll open a topic about the "pybind11 based scripter" in the forums, as soon as i've cleaned up the repository in a way that helps understanding what i am up to : - )