[PATCH] slider keys change line size, dev.laptop.org #8865

Gonzalo Odiard godiard at gmail.com
Wed Jun 2 02:07:06 EDT 2010


Connects XO-1 and XO-1.5 slider function keys to line size change for
pencil, eraser, brush and rainbow.  The size change is relative to
current size.

http://dev.laptop.org/ticket/8865

Reviewed-by: James Cameron <quozl at laptop.org>
Tested-by: James Cameron <quozl at laptop.org>
---
 Area.py            |   12 +++++++-----
 OficinaActivity.py |    7 +++++++
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/Area.py b/Area.py
index 7b8c8b4..570d093 100644
--- a/Area.py
+++ b/Area.py
@@ -97,15 +97,13 @@ class Area(gtk.DrawingArea):
                 gtk.gdk.BUTTON_PRESS_MASK |
                 gtk.gdk.BUTTON_RELEASE_MASK|
                 gtk.gdk.EXPOSURE_MASK |
-                gtk.gdk.KEY_PRESS_MASK |
-                gtk.gdk.KEY_RELEASE_MASK) 
+                gtk.gdk.KEY_PRESS_MASK)
                 
         self.connect("expose_event",self.expose)
         self.connect("motion_notify_event", self.mousemove)
         self.connect("button_press_event", self.mousedown)
         self.connect("button_release_event", self.mouseup)
         self.connect("key_press_event", self.key_press)
-        self.connect("key_release_event", self.key_release)
 
         self.set_flags(gtk.CAN_FOCUS)
         self.grab_focus()
@@ -1164,8 +1162,12 @@ class Area(gtk.DrawingArea):
                 self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.TCROSS))
             widget.queue_draw()
 
-    def key_release(self,widget,event):
-        pass
+    def change_line_size(self, delta):
+        if self.tool['name'] in ['pencil','eraser','brush','rainbow']:
+            size = self.tool['line size'] + delta
+            self.tool['line size'] = size
+            self.configure_line(size)
+            self.queue_draw()
 
     def _keep_selection_ratio(self, coords):
         def sign(x):
diff --git a/OficinaActivity.py b/OficinaActivity.py
index 332f198..c72576a 100644
--- a/OficinaActivity.py
+++ b/OficinaActivity.py
@@ -117,6 +117,8 @@ class OficinaActivity(activity.Activity):
         self.set_toolbox(toolbox)
         toolbox.show()
 
+        self.connect("key_press_event", self.key_press)
+
         # setup self.area only once
 
         def map_cp(widget):
@@ -131,6 +133,11 @@ class OficinaActivity(activity.Activity):
 
         self._setup_handle = self.connect('map', map_cp)
 
+    def key_press(self, widget, event):
+        sliders = {65474: -5, 65475: -1, 65476: 1, 65477: 5}
+        if event.keyval in sliders:
+            self.area.change_line_size(sliders[event.keyval])
+
     def read_file(self, file_path):
         '''Read file from Sugar Journal.'''
 
-- 
1.7.1

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list