<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[(Pythonscript) Status bar to display word count &amp; understanding SCINTILLANOTIFICATION]]></title><description><![CDATA[<p dir="auto">So using the following two posts I managed to make some progress on a simple script that displays the word count in my status bar.</p>
<p dir="auto"><a href="https://community.notepad-plus-plus.org/topic/14144/is-there-a-way-to-customize-the-status-bar-to-display-more-helpful-information">https://community.notepad-plus-plus.org/topic/14144/is-there-a-way-to-customize-the-status-bar-to-display-more-helpful-information</a><br />
<a href="https://community.notepad-plus-plus.org/topic/22101/status-bar-to-display-selected-word-count">https://community.notepad-plus-plus.org/topic/22101/status-bar-to-display-selected-word-count</a></p>
<p dir="auto">However I would like to modify it so that the script is more performant and runs only when a word / words are entered or removed. This would be cases like:</p>
<ul>
<li>A word is completed (Space or Return key is pressed)</li>
<li>Many words are added or removed (Undo, redo, cut, paste, delete, backspace)</li>
</ul>
<p dir="auto">I’ve spent a ton of time trying to understand the<code>SCINTILLANOTIFICATION.KEY</code> and <code>MODIFICATIONFLAGS</code> and what <code>'modificationType': 16400</code> mean but I’m getting stuck.</p>
<p dir="auto">Seems no matter what I do my update wordcount callback runs 2-3 times every time I press a single key.</p>
<p dir="auto">Here is what I have so far, which updates on every click, selection and key input:</p>
<pre><code>from re import findall

def callback_sci_UPDATEUI(args):
    if editor.getTextLength() &lt; 100000 and args['updated']:  # don't search "big" files
        text = editor.getText()
        word_count = len(findall(r'\w+', text))
        sbar_value = ' ' if word_count == 0 else 'Words: {}'.format(word_count)
        notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, sbar_value)

editor.callback(callback_sci_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])
</code></pre>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a></p>
]]></description><link>https://community.notepad-plus-plus.org/topic/23731/pythonscript-status-bar-to-display-word-count-understanding-scintillanotification</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 15:45:19 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/23731.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Nov 2022 15:36:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to (Pythonscript) Status bar to display word count &amp; understanding SCINTILLANOTIFICATION on Thu, 10 Nov 2022 17:11:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/81345">(Pythonscript) Status bar to display word count &amp; understanding SCINTILLANOTIFICATION</a>:</p>
<blockquote>
<p dir="auto">Is this causing some sort of problem for you, or does it merely bother you?</p>
</blockquote>
<p dir="auto">Mostly the latter, haha.</p>
<p dir="auto">In any case, I don’t really notice any impact on performance so I’m going to let it go. Here is my final script that I ended up writing for those that come along and want to see it.</p>
<pre><code>from re import findall

def callback_sci_UPDATEUI(args):
    SPEECH_SEC_PER_WORD = 0.66 # 0.55 = fast, 0.66 = normal, 0.75 = paused
    if editor.getTextLength() &lt; 100000 and args['updated']:  # don't search "big" files
        if editor.getSelections() == 1 and not editor.getSelectionEmpty():
            # show word count for selection
            text = editor.getSelText()
            sel_info = ' (For Selected)'
        else:
            # show word count for entire document
            text = editor.getText()
            sel_info = ''
        word_count = len(findall(r'\w+', text))       
        speech_minutes = (word_count * SPEECH_SEC_PER_WORD / 60) % 60
        speech_seconds = (word_count * SPEECH_SEC_PER_WORD) % 60
        speaking_time_str = "%02dm%02ds" % (speech_minutes, speech_seconds)
        sbar_value = 'Words: {}  Speaking Time: {}{}'.format(word_count, speaking_time_str, sel_info)
        notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, sbar_value)

editor.callback(callback_sci_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/81348</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81348</guid><dc:creator><![CDATA[Dimitri Sudomoin]]></dc:creator><pubDate>Thu, 10 Nov 2022 17:11:32 GMT</pubDate></item><item><title><![CDATA[Reply to (Pythonscript) Status bar to display word count &amp; understanding SCINTILLANOTIFICATION on Thu, 10 Nov 2022 16:31:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dimitri-sudomoin" aria-label="Profile: Dimitri-Sudomoin">@<bdi>Dimitri-Sudomoin</bdi></a> said in <a href="/post/81343">(Pythonscript) Status bar to display word count &amp; understanding SCINTILLANOTIFICATION</a>:</p>
<blockquote>
<p dir="auto">I couldn’t really find good documentation</p>
</blockquote>
<p dir="auto">I suppose this is the bible of documentation for it:  <a href="https://www.scintilla.org/ScintillaDoc.html#Notifications" rel="nofollow ugc">https://www.scintilla.org/ScintillaDoc.html#Notifications</a></p>
<p dir="auto">I do realize that some of the notifications fire “a lot”.  But in practice, I typically just ignore that and let my callbacks do their duty, no matter how redundant.  Is this causing some sort of problem for you, or does it merely bother you?</p>
<p dir="auto">Perhaps you can cut down on some of the “noise” by using: <a href="https://www.scintilla.org/ScintillaDoc.html#SCI_SETMODEVENTMASK" rel="nofollow ugc">https://www.scintilla.org/ScintillaDoc.html#SCI_SETMODEVENTMASK</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/81345</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81345</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 10 Nov 2022 16:31:27 GMT</pubDate></item><item><title><![CDATA[Reply to (Pythonscript) Status bar to display word count &amp; understanding SCINTILLANOTIFICATION on Thu, 10 Nov 2022 16:14:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a></p>
<p dir="auto">Yeah I tried <code>SCINTILLANOTIFICATION.MODIFIED</code> but it actually fired a lot more than <code>SCINTILLANOTIFICATION.UPDATEUI</code>.</p>
<p dir="auto">For example, just just one keystroke would call the function three times. Same with <code>SCINTILLANOTIFICATION.KEY</code> which would call it 2 times IIRC - though maybe its firing on key up and key down? I couldn’t really find good documentation or examples relating to SCINTILLANOTIFICATION.</p>
<p dir="auto">For example, <code>args</code> with SCINTILLANOTIFICATION.UPDATEUI contains  <code>'updated': 2</code> which seems to correspond to the type of action <code>'updated': 1</code> and <code>'updated': 3</code> being keystroke or backspace and <code>'updated': 2</code> being click. How does one figure out what number corresponds to what action?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81343</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81343</guid><dc:creator><![CDATA[Dimitri Sudomoin]]></dc:creator><pubDate>Thu, 10 Nov 2022 16:14:51 GMT</pubDate></item><item><title><![CDATA[Reply to (Pythonscript) Status bar to display word count &amp; understanding SCINTILLANOTIFICATION on Thu, 10 Nov 2022 15:46:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dimitri-sudomoin" aria-label="Profile: Dimitri-Sudomoin">@<bdi>Dimitri-Sudomoin</bdi></a></p>
<blockquote>
<p dir="auto">Here is what I have so far, which updates on every click, selection and key input…SCINTILLANOTIFICATION.UPDATEUI</p>
</blockquote>
<p dir="auto">Well “update ui” <em>IS</em> going to fire everytime the UI needs updating, hence its name.  :-)</p>
<p dir="auto">Perhaps <code>SCINTILLANOTIFICATION.MODIFIED</code> is better?<br />
That one fires when text content of the editor buffer is changed.<br />
It still may occur more times than you’d expect, but I would say have a look into it.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/81341</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/81341</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 10 Nov 2022 15:46:34 GMT</pubDate></item></channel></rss>