Hi,
I am doing some research into the RichTextCtrl and was wondering if there is any support in wxPython for counting characters and words in a text control? I am not seeing anything (not surprising), so I was wondering if anyone had any tips for implementing that. I know I can catch wx.EVT_CHAR and do some rudimentary character counting that way, but I thought this knowledgeable group might have a more elegant solution.
Thanks,
Mike
···
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Books: Python 101, Python 201: Intermediate Python, wxPython Recipes, Python Interviews
pá 29. 3. 2019 v 19:10 odesílatel Mike Driscoll <mike@pythonlibrary.org> napsal:
Hi,
I am doing some research into the RichTextCtrl and was wondering if there is any support in wxPython for counting characters and words in a text control? I am not seeing anything (not surprising), so I was wondering if anyone had any tips for implementing that. I know I can catch wx.EVT_CHAR and do some rudimentary character counting that way, but I thought this knowledgeable group might have a more elegant solution.
Thanks,
Mike
-----------------
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Books: Python 101, Python 201: Intermediate Python, wxPython Recipes, Python Interviews
Hi,
I am not sure, this is the functionality you are looking for, but
seems to be a method for the simple character count:
https://wxpython.org/Phoenix/docs/html/wx.richtext.RichTextCtrl.html#wx.richtext.RichTextCtrl.GetLastPosition
I am currently not using richtext in my code, but in some brief tests,
this value seems to correspond with the naive approach like
len(rtxt.GetValue())
On the other hand, the calculation of textstatistics in terms of words
(or even sentences, paragraphs etc.) might be more complex and
possibly language specific (even popular document editors sometimes
differ in this regard). I'd personally tend to use regex searches on
whole text content, but I am sure, this approach won't be shared
universally ...
best regards,
vbr