Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Functions | Variables
wordcount Namespace Reference

Functions

def wordsplit
def main

Variables

string TITLE = "Word count"

Function Documentation

def wordcount.main ( )

Definition at line 27 of file wordcount.py.

00027 
00028 def main():
00029     words = 0
00030     sel_count = selectionCount()
00031     if sel_count:
00032         source = "selected textframe"
00033         if sel_count > 1: source += "s" #plural
00034         for i in range(sel_count):
00035             try:
00036                 text = getText(getSelectedObject(i))
00037                 words += len(wordsplit(text))
00038             except WrongFrameTypeError:
00039                 if sel_count == 1:
00040                     # If there's only one object selected, display a message
00041                     messageBox(TITLE, "Can't count words in a non-text frame", ICON_INFORMATION);
00042                     sys.exit(1)
00043                 else:
00044                     # otherwise ignore
00045                     pass
00046     else:
00047         source = "whole document"
00048         for page in range(1,pageCount() + 1):
00049             gotoPage(page)
00050             for obj in getAllObjects():
00051                 try:
00052                     text = getText(obj)
00053                     words += len(wordsplit(text))
00054                 except WrongFrameTypeError:
00055                     pass # ignore the error, it just wasn't a frame we can count
00056 
00057     if words == 0: words = "No"
00058     messageBox(TITLE, "%s words counted in %s" % (words, source),
00059                ICON_INFORMATION)
00060 

Here is the call graph for this function:

def wordcount.wordsplit (   text)

Definition at line 18 of file wordcount.py.

00018 
00019 def wordsplit(text):
00020     word_pattern = "([A-Za-zäöüÄÖÜß]+)"
00021     words = []
00022     for x in re.split(word_pattern, text):
00023         if re.match(word_pattern, x):
00024             words.append(x)
00025     return words
00026 

Here is the caller graph for this function:


Variable Documentation

string wordcount.TITLE = "Word count"

Definition at line 16 of file wordcount.py.