]> git.neil.brown.name Git - scribble.git/commitdiff
Autosave
authorNeil Brown <neilb@notabene.brown>
Thu, 28 Aug 2008 11:32:36 +0000 (21:32 +1000)
committerNeil Brown <neilb@notabene.brown>
Thu, 28 Aug 2008 11:32:36 +0000 (21:32 +1000)
Save current page after 20 seconds idle.
This flushes the current text too - it will have to be re-selected.

scribble.py

index b0dbbfb9d90587f6f34bba1673544cb639620ecf..b1cafcc84c45b59de5f3b2c863885a21a97b7dd4 100755 (executable)
@@ -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)):