From 2672e520583705fb7da85ed0e650955fea65ad52 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 28 Aug 2008 21:32:36 +1000 Subject: [PATCH] Autosave Save current page after 20 seconds idle. This flushes the current text too - it will have to be re-selected. --- scribble.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scribble.py b/scribble.py index b0dbbfb..b1cafcc 100755 --- a/scribble.py +++ b/scribble.py @@ -29,6 +29,7 @@ import pygtk import gtk import os import pango +import gobject ########################################################### # Writing recognistion code @@ -772,6 +773,8 @@ class ScribblePad: self.lineheight = (met.get_ascent() + met.get_descent()) / pango.SCALE self.lineascent = met.get_ascent() / pango.SCALE + self.timeout = None + def close_application(self, widget): self.save_page() gtk.main_quit() @@ -792,12 +795,18 @@ class ScribblePad: def press(self, c, ev): # Start a new line + if self.timeout: + gobject.source_remove(self.timeout) + self.timeout = None self.line = [ self.colourname, [int(ev.x), int(ev.y)] ] return def release(self, c, ev): if self.line == None: return + if self.timeout == None: + self.timeout = gobject.timeout_add(20*1000, self.tick) + if len(self.line) == 2: # just set a cursor self.flush_text() @@ -860,6 +869,12 @@ class ScribblePad: self.line.append([x,y]) return + def tick(self): + # nothing for 20 seconds, flush the page + self.save_page() + gobject.source_remove(self.timeout) + self.timeout = None + def find_text(self, pos): x = pos[0]; y = pos[1] for i in range(0, len(self.lines)): -- 2.43.0