Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to wait for a pause in user input in a gtk.TextBuffer?
    text
    copied!<p>I'm trying to write a simple gui-based application in pygtk which provides 'live' previewing of text-based markup. The markup processing, however, can be quite computationally expensive and slow to run, so updating the preview on every keystroke is not really viable. Instead I'd like to have the update run only when user input lapses. Ideally, I'd have it update a specified interval after the last keystroke in a sequence.</p> <p>I've looked into using <code>threading.Timer</code>, by cancelling and re-starting a timer to invoke the update function each time the "changed" signal is emitted. I've also tried to use <code>gtk.idle_add()</code>, but I can't seem to get it working.</p> <p>Below is a very simple example - could someone suggest the best strategy to achieve what I'm after, preferably with an example?</p> <pre><code>import gtk class example: def __init__(self): window = gtk.Window() window.set_title("example") window.resize(600,400) box = gtk.HBox(homogeneous = True, spacing = 2) buf = gtk.TextBuffer() buf.connect("changed", self.buf_on_change) textInput = gtk.TextView(buf) box.add(textInput) self.lbl = gtk.Label() box.add(self.lbl) window.add(box) window.connect("destroy", gtk.main_quit) window.show_all() def buf_on_change(self, buf): txt = buf.get_text(*buf.get_bounds()) output = self.renderText(txt) self.lbl.set_text(output) def renderText(self, txt): # perform computation-intensive text-manipulation here output = txt return output if __name__ == '__main__': example() gtk.main() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload