Word Count function

Previous topic - Next topic

JohnJR

Hi Folks,

I have searched high and low, but cannot find if Scribus has a word count feature.  If it does how do you access it?  What's the work around if it doesn't?

Thanks,

a.l.e

for a specific text frame, right click on the text frame and and click on "text info".

for the whole document: use the script to export the full document's text and use your usual tool.
(it would not be hard to create a word counter for the document (if it indeed does not exist) but i somehow wonder if it would really be that useful: hint: you're not really supposed to write longer texts in scribus...)

JohnJR

Thanks a.l.e,

I couldn't quite follow your suggested path.  I am a Mac user which might have something to do with it.  I "selected" the a text frame (red outline with little corner and side box nodes), but then could not find a "text info" to click on, nothing presented itself.  I looked in the main menu and at best found Scripter > Scribus Scripts > Info Box, but there was nothing there.

By the way, I use(d) Scribus to format a novella, and once I got the hang of it found it would work for longer works a chapter at a time.

Thanks,

a.l.e

depending on your mouse / touch pad / whatever there are different ways to open the context menu.

the most common way to open the context menu is to right click on something.
most macs don'have buttons on the mouse, so you have to find out how to activate context menues with your hardware.
(probably a double / triple touch (a touch with two or three fingers) on your device).

once you're able to activate the context menu on a text frame, you'll see where the "text info" is.

but, normally, you don't really need to know the number of characters and words in scribus.
this something you should do before importing your text into scribus.

qwazix

#4
I modified the "export all text" script to count all words in a document (and work with python3)

#!/usr/bin/env python
# File: count_words.py - Counts all words in a document
# also lists image files with pathnames
# 2006.03.04 Gregory Pittman
# 2008.02.28 Petr Vanek - fileDialog replaces valueDialog
# 2023.05.29 Michalis Demetriou - modify in order to just count all words
# this version 2023.05.29
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

import scribus
import re

def countWords():
    page = 1
    pagenum = scribus.pageCount()
    T = []
    content = []
    while (page <= pagenum):
        scribus.gotoPage(page)
        d = scribus.getPageItems()
        for item in d:
            if (item[1] == 4):
                contents = scribus.getAllText(item[0])
                if (contents in content):
                    contents = ''
                T.append(contents)
                content.append(contents)
        page += 1
#        T.append('')
    text = " ".join(T)
    text = re.sub(' +', ' ', text)
    count = len(text.split(" "))
    print(count)
    endmessage =  str(count) + ' words'
    scribus.messageBox("Finished", endmessage,scribus.ICON_INFORMATION, scribus.BUTTON_OK)


if scribus.haveDoc():
    try:
        countWords()
    except (Exception, e):
        print(e)

else:
    scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', \
                       icon=0, button1=1)


qwazix

Updated to ignore leading and trailing whitespaces

#!/usr/bin/env python
# File: count_words.py - Counts all words in a document
# also lists image files with pathnames
# 2006.03.04 Gregory Pittman
# 2008.02.28 Petr Vanek - fileDialog replaces valueDialog
# 2023.05.29 Michalis Demetriou - modify in order to just count all words
# this version 2023.05.29
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

import scribus
import re

def countWords():
    page = 1
    pagenum = scribus.pageCount()
    T = []
    content = []
    while (page <= pagenum):
        scribus.gotoPage(page)
        d = scribus.getPageItems()
        for item in d:
            if (item[1] == 4):
                contents = scribus.getAllText(item[0])
                if (contents in content):
                    contents = ''
                T.append(contents)
                content.append(contents)
        page += 1
    text = " ".join(T)
    text = re.sub('^ ','',re.sub(' $','',re.sub(' +', ' ', text)))
    count = len(text.split(" "))
    print(count)
    endmessage =  str(count) + ' words'
    scribus.messageBox("Finished", endmessage,scribus.ICON_INFORMATION, scribus.BUTTON_OK)


if scribus.haveDoc():
    try:
        countWords()
    except (Exception, e):
        print(e)

else:
    scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', \
                       icon=0, button1=1)