sugarlabs / write-activity

A simple word processor for the Sugar learning environment
GNU General Public License v2.0
2 stars 25 forks source link

Add feature of word count and character count #36

Open nswarup14 opened 5 years ago

nswarup14 commented 5 years ago

Changes 1) toolbar.py

Updates Now, the word and character count is displayed on the ViewToolbar of the activity. The count is updated every time there is a change in the AbiWord canvas.

The PR is based upon another PR.

I cannot find the AbiWord API for counting words on the official Abi 3.0 , hence I'm not sure if a python binding for such an API exists.

I have chosen to keep the word count and character count in the ViewToolbar itself, because I feel that is the right place to show. Buttons of common utility such as zoom-out, zoom-in and page no are also on the same toolbar.

Tested Ubuntu 18.04, Sugar v0.114. Thanks.

quozl commented 5 years ago

Fetching the whole document in order after every change to count the words is very inefficient. Is there a better way? Look at the AbiWord method dlgWordCount?

rhl-bthr commented 5 years ago

@nswarup14 ping

nswarup14 commented 5 years ago

@quozl @pro-panda I tried as you suggested. I looked up the method called dlgWordCount. It is an Edit method of the Abi.Widget class. https://www.abisource.com/doxygen/classap__EditMethods.html#a1bca73daaba032f99f6061997bb771da

I used Abi.Widget's invoke_ex method, as it has been used in a number of other places in the activity. However I get the following traceback with no change in the activity usage. Selection_002

I looked up as much as I could, as to why this was happening, but I could not find anything useful, particular to AbiWord.

quozl commented 5 years ago

Thanks. Underlines were destroyed in your screenshot. I suggest using text copy and paste for log errors, so they can be searched. There was no traceback in your screenshot. I don't know what you tried, as you haven't pushed. If you're not sure how to use the API, or get unexpected results, read the AbiWord source code.