Hi everyone,
just signed up here because of I would need some help. Within a Python script, I am trying to create a character style that is based on another, already existing character style.
When using the normal GUI, the process is clear, simply select the 'parent' style in the 'Based On:' dropdown list in the Style Manager. But how do I achieve it with a Python script? scribus.createCharStyle() has no obvious parameter for that. There is the string 'inherit' for the features parameter, but I have no idea what it does.
I tried:
•features='inherit'
-> does nothing obvious, unsurprisingly
•features='inherit parentstyle'
-> does nothing, too
Anybody able to help me out?
BR
Jens
Hi,
As far as I can tell the Scripter simply doesn't expose the "Based on:" option for character styles at all. createCharStyle() has no parameter for setting a parent, and that parent (CPARENT) you see in the .sla XML just isn't reachable from Python.
The features="inherit" part is a bit confusing. It doesn't create a parent style. It only applies the parent's font features if a parent already exists.
Since the style you create in Python has no parent, there's basically nothing to inherit from, so nothing happens.....
Right now the only workarounds are (I think):
make the style hierarchy manually in a template .sla and just use the styles from Python
or load them from another .sla with loadStylesFromFile(), which keeps the "Based on" relationships
anything else means editing the .sla XML by hand afterwards (not ideal and a bit fragile)
Hopefully they expose this in the API one day, because it feels like half the style system is missing from Scripter.
If you need complex styles (hierarchies), I think that working with a template is the best approach.
Of course, the scripter API does not let you create a document based on a template, so some more thoughts and prayers are needed here.
No idea if it would a feature that is easy to add.
I've now created a patch for setting a parent when creating the character and paragraph styles:
https://bugs.scribus.net/view.php?id=17706
Btw, creating patches for the Scripter API is a good way to get started with hacking on Scribus : - )
Creating the linked patch was for sure easier than trying to figure out how to create or modify a style directly in the .sla...
Good evening,
Thanks for your replies! I think Bastian's approach with templates is my best option. Unfortunately I cannot code, so no way to hack the Scripter API. And no, calling a few simple functions from a Python module is not coding ;) Otherwise, there would be a few things I could look at, like paragraph styles with lists...
BR
Jens