[scribus] Word Count of selected text

a.l.e ale.comp_06 at xox.ch
Wed Jul 14 12:42:44 CEST 2010


hi harsha,



> > I wished to know whether there was a way to know the 
> word count of selected
> > text.
> >
> > The "Edit Story" section shows the world count of the text 
> automatically of
> > the whole story. Or of the current paragraphs.
> >
> > But what if if wish to know the word count of a selected 
> text of the story?


this script will also solve your problem, but it won't work in the story editor: you have to use it on the text frame.

#--- 8< ---
"""
this script counts the character in the current selection
@author: alessandro rimoldi
@version: 1.0 / 20100714
@copyright (c) 2010 alessandro rimoldi under the mit license
           http://www.opensource.org/licenses/mit-license.html
"""
import sys
try:
   import scribus
except ImportError:
   print "This script only works from within Scribus"
   sys.exit(1)

# check that the selection is one text frame and get that frame
frame_n = scribus.selectionCount()
if frame_n == 0 :
    scribus.messageBox('Error:', 'No frame selected');
    sys.exit(1)
elif frame_n > 1 :
    scribus.messageBox('Error:', 'You may select only one frame');
    sys.exit(1)

frame = scribus.getSelectedObject(0)
try:
    char_n = scribus.getTextLength(frame)
except scribus.WrongFrameTypeError:
    scribus.messageBox('Error:', 'You have to first select a text frame');
    sys.exit(1)

if char_n == 0 :
    scribus.messageBox('Error:', 'There is no text in the frame');
    sys.exit(1)

scribus.messageBox('Character count:', 'There are
'+str(len(scribus.getText()))+' characters selected');
#--- >8 ---


ciao
a.l.e



More information about the scribus mailing list