Page 1 of 1

HiLite Tweak added...but not perfect

Posted: 15.11.2019 10:35
by Maxol
Recently I downloaded the HiLite plugin. Super! There was one side effect I didn't like: the flickering of the screen, especially when typeing text and/or moving the cursor around rapidly. I never used Python but I managed to tweak the script a little:

Added at the Top:

Code: Select all

import time
Added Time Init:

Code: Select all

  def __init__(self):
    do_load_ops()
    
    # Get the Time
    self.lasttime=time.clock()    
Added this code BEFORE the major highlighting:

Code: Select all

  def on_caret_move(self, ed_self):
    if ed_self.get_carets(): return #donot allow mul-carets
    if ed_self.get_text_len() > MAX_SIZE: return

    # Compare Current Time with Time from Previous Visit to this Function
    # and if that was too recent do NOT HiLite (this will prevent flickering)
    difftime=time.clock()-self.lasttime
    self.lasttime=time.clock()
    if difftime<1:return
The result of this is that the HiLite will not kick in as long as you are typeing or moving the cursor. But...there is a drawback: to HiLite you need to move the cursor again after all the activity.

Any other programming language on Windows I would have used a Timer that delays the Hilite for x milliseconds. This Timer is restarted everytime on_caret_move fires and thus cancelling the previous Timer.

I'd love to know how to do this in Python but I could not get threading.Timer to work... :(

Posted: 15.11.2019 21:13
by Alexey
I recommend to switch to CudaText where timer_proc() API exists (in module 'cudatext').
SynWrite also has timer_proc API:
https://sourceforge.net/p/synwrite/wiki ... functions/

Code: Select all

timer_proc(id, callback, interval): Performs action on timers. Documented at http://wiki.freepascal.org/CudaText_API#timer_proc
The same syntax as CudaText has.