[Sugar-devel] [PATCH] Timer for resize that prevents repetitive resize operation.
Manuel Quiñones
manuq at laptop.org
Fri Jul 1 09:20:03 EDT 2011
Fixes OLPC #10770 .
Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
Desenho.py | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/Desenho.py b/Desenho.py
index 9b6c7b5..5bab524 100644
--- a/Desenho.py
+++ b/Desenho.py
@@ -68,7 +68,10 @@ import gtk
import logging
import math
import gc
+import gobject
+RESIZE_TIMER = 1500 # The time to wait for the resize operation to be
+ # executed, after the resize controls are pressed.
##Pixmap manipulation
class Desenho:
@@ -80,6 +83,7 @@ class Desenho:
@param widget -- Area object (GtkDrawingArea)
"""
+ self.waiting_for_resize = False
#self.d = widget
def line(self, widget, coords):
@@ -706,6 +710,15 @@ class Desenho:
@param height_percent -- Percent of y scale
"""
+ self.width_percent = width_percent
+ self.height_percent = height_percent
+
+ # Add a timer for resize if there isn't any already:
+ if not self.waiting_for_resize:
+ self.waiting_for_resize = True
+ gobject.timeout_add(RESIZE_TIMER, self._do_resize, widget)
+
+ def _do_resize(self, widget):
width, height = widget.window.get_size()
widget.desenha = True
widget.selmove = True
@@ -723,8 +736,8 @@ class Desenho:
w = self.pixbuf_resize.get_width()
h = self.pixbuf_resize.get_height()
- wr = int(w * width_percent)
- hr = int(h * height_percent)
+ wr = int(w * self.width_percent)
+ hr = int(h * self.height_percent)
resized = self.pixbuf_resize.scale_simple(wr, hr, gtk.gdk.INTERP_HYPER)
@@ -750,6 +763,9 @@ class Desenho:
widget.queue_draw()
gc.collect()
+ self.waiting_for_resize = False
+ return False
+
def polygon(self, widget, coords, temp, fill, param=None):
"""Draw polygon.
--
1.7.4.4
More information about the Sugar-devel
mailing list