Script to apply attributes - text attribute problems

Previous topic - Next topic


Hello all.
I'm making my first attempt at writing a scribus script. I started by copying and have my script almost working, but the remaining issues are quite stubborn. (I'm running Scribus 1.4.3 -- haven't yet been able to install 1.4.4 on my system, which runs Ubuntu 14.04.)
I need to auto-format passages in my novel which I've designated by enclosing them with << and >>. The script should find these passages and set everything within to an italic font. It doesn't delete the marker characters because I want to verify the results and then use the search/replace command to delete them.

1. Scribus can't find my desired font, which is named "GoudyBookletter1911Italic Regular". It does find "Arial Regular". Does it have a problem with OpenType fonts? Alternately, I created a character style and called scribus.setStyle("Body Text Character Italic") but scribus couldn't find the style. Does setStyle work for paragraph styles only?
2. The deselectAll command does not work, which means after the script executes one "setFont" command, my document is locked. I can't make any new selections, even by manually clicking on the text frame. If I do "Edit->Deselect All" Scribus crashes. I also tried selectAll(0,0,story), which didn't work either.
Below I've pasted the relevant code. Note that the name I use for the font is not the file name but the name displayed in Font Manager. Thanks in advance for any help you can give me.

contents = scribus.getTextLength(textbox)
prevchar = ' '
sel_start = 0
sel_length = 0
while c <= (contents -1):
    scribus.selectText(c, 1, textbox)
    char = scribus.getText(textbox)
    if (len(char) != 1):
        c += 1
    if (ord(char) == 60 and ord(prevchar) == 60):
        sel_start = c+1
    elif (ord(char) == 62 and ord(prevchar) == 62):
        if (sel_start > 0):
            sel_length = (c - 1) - sel_start
            msg = "Found text {} {}".format(sel_start, sel_length)
            scribus.messageBox('Scribus', msg, scribus.ICON_NONE, scribus.BUTTON_OK)
            story = scribus.getSelectedObject(0)
            scribus.selectText(sel_start, sel_length, story)
            scribus.setFont("GoudyBookletter1911Italic Regular", story)
            scribus.selectText(0, 0, story)
        sel_start = 0
    c += 1
    prevchar = char



Ok, I found a dumb error. I didn't realize that the original autoquote code was also using selectText to get each character. Therefore we needed an deselectAll at the end of the script rather than following the setFont call. Also the object "story" was a redundant variable, so I replaced all instances of the variable "story" with "textbox."
It still didn't fix selection problem but I discovered I can do a manual deselect (without crashing Scribus) by invoking the command Edit->Advanced Select All with no options selected. This is a workaround but I'd still prefer to have the deselect actually work.