Re: getAllText Sometimes Failing
"Matt Miller" <matt.miller-97jfqw80gc5Wk0Htik3J/[email protected]>
| Newsgroups | gmane.comp.graphics.scribus |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Mar 4, 2021, at 06:32, Gregory Pittman wrote: > On 3/3/21 8:38 PM, Matt Miller wrote: > > I've attached a test case that seems to show that getAllText() is sometimes succeeding and sometimes failing. When it fails it doesn't throw an error, but it just retrieves a string of length 1, instead of retrieving the actual text of the chain. I see this on 1.5.6.1 and 1.5.7.svn, in both Linux and Windows. > > > > To run the test open the .sla and from the script menu execute chapter_heading_style.py. The text frame name "debug" at the very top will contain the word "Error" if the getAllText() call in the script fails. What I see is that it works fine the first time, then it fails on every subsequent try, until I alter something on the document. For example, if I grab and move the "debug" text frame a bit then getAllText() will succeed once, and then fail repeatedly again. Saving and reopening the document also causes the script to work again the first time. > > > > Thanks. > > > > > > -- > > > > Matt Miller > > mailto:matt.miller-97jfqw80gc5Wk0Htik3J/[email protected] > > > > -------------- next part -------------- > > An HTML attachment was scrubbed... > > URL: <http://lists.scribus.net/pipermail/scribus/attachments/20210303/83076fa0/attachment.htm> > > -------------- next part -------------- > > A non-text attachment was scrubbed... > > Name: 7.25x9-Wide-Margin-Self-Pronouning_Mal.sla > > Type: application/octet-stream > > Size: 83787 bytes > > Desc: not available > > URL: <http://lists.scribus.net/pipermail/scribus/attachments/20210303/83076fa0/attachment.obj> > > -------------- next part -------------- > > A non-text attachment was scrubbed... > > Name: chapter_heading_style.py > > Type: application/octet-stream > > Size: 3084 bytes > > Desc: not available > > URL: <http://lists.scribus.net/pipermail/scribus/attachments/20210303/83076fa0/attachment-0001.obj> > > Hi Matt, > > I have a hard time trying to figure out what you're trying to do with > this script. Somewhere in your Scribus installation there should be a > folder named samples. > On my Linux (Fedora), it's in /usr/share/scribus. Inside samples is a > script named ExtractText.py, which uses getAllText() to collect all the > text from a document and save it in a text file. This still works in > 1.5.x. Yes, I verified this works fine for me. Thanks. Digging into my code more I see that I was calling selectText() to select the first character of the paragraph I wanted to apply a custom paragraph style to, but then I was not deselecting the text. A subsequent call to getAllText() would then return only the single character of that selected text. To address this I've adopted a standard in my code of always calling selectText (0, 0, <text_frame>) right after making any call that relies on certain text being selected. So, this problem is solved. > > Greg > > > ___ > Scribus Mailing List: [email protected] > Edit your options or unsubscribe: > http://lists.scribus.net/mailman/listinfo/scribus > See also: > http://wiki.scribus.net > http://forums.scribus.net > -- Matt Miller mailto:matt.miller-97jfqw80gc5Wk0Htik3J/[email protected] ___ Scribus Mailing List: [email protected] Edit your options or unsubscribe: http://lists.scribus.net/mailman/listinfo/scribus See also: http://wiki.scribus.net http://forums.scribus.net