[PATCH] implement OLPC #8865

Gonzalo Odiard godiard at gmail.com
Wed Jun 2 00:59:54 EDT 2010


---
 Area.py            |   13 ++++++++-----
 OficinaActivity.py |   15 +++++++++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/Area.py b/Area.py
index e81fcdc..8a5e523 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()
@@ -1163,8 +1161,13 @@ 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 f7dd088..8259ca8 100644
--- a/OficinaActivity.py
+++ b/OficinaActivity.py
@@ -116,6 +116,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):
@@ -130,6 +132,19 @@ class OficinaActivity(activity.Activity):

         self._setup_handle = self.connect('map', map_cp)

+
+    def key_press(self,widget,event):
+        if (event.keyval >= 65474) and (event.keyval <= 65477):
+            if event.keyval == 65474:
+                self.area.change_line_size(-5)
+            elif event.keyval == 65475:
+                self.area.change_line_size(-1)
+            elif event.keyval == 65476:
+                self.area.change_line_size(1)
+            elif event.keyval == 65477:
+                self.area.change_line_size(5)
+
+
     def read_file(self, file_path):
         '''Read file from Sugar Journal.'''

-- 
1.6.6.1


-- 
Gonzalo

--000e0cd48b14b5c97f048804fdc5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Tomeu was right. Catching the key stokes in the activity works.<br><br>From=
 08e0226731c13e74b993b59c1a2c8165e9ad3654 Mon Sep 17 00:00:00 2001<br>From:=
 Gonzalo Odiard &lt;<a href=3D"mailto:godiard at gmail.com">godiard at gmail.com<=
/a>&gt;<br>
Date: Wed, 2 Jun 2010 01:59:54 -0300<br>Subject: [PATCH] implement OLPC #88=
65<br><br>---<br>=A0Area.py=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 |=A0=A0 13 +++=
+++++-----<br>=A0OficinaActivity.py |=A0=A0 15 +++++++++++++++<br>=A02 file=
s changed, 23 insertions(+), 5 deletions(-)<br>
<br>diff --git a/Area.py b/Area.py<br>index e81fcdc..8a5e523 100644<br>--- =
a/Area.py<br>+++ b/Area.py<br>@@ -97,15 +97,13 @@ class Area(gtk.DrawingAre=
a):<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gtk.gdk.BUTTON_PRES=
S_MASK |<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gtk.gdk.BUTTON=
_RELEASE_MASK|<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gtk.gdk.EXPOSURE_MASK |<br=
>-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gtk.gdk.KEY_PRESS_MASK |<br=
>-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gtk.gdk.KEY_RELEASE_MASK) <=
br>+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 gtk.gdk.KEY_PRESS_MASK) <=
br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <br>=A0=A0=A0=A0=A0=A0=
=A0=A0 self.connect(&quot;expose_event&quot;,self.expose)<br>
=A0=A0=A0=A0=A0=A0=A0=A0 self.connect(&quot;motion_notify_event&quot;, self=
.mousemove)<br>=A0=A0=A0=A0=A0=A0=A0=A0 self.connect(&quot;button_press_eve=
nt&quot;, self.mousedown)<br>=A0=A0=A0=A0=A0=A0=A0=A0 self.connect(&quot;bu=
tton_release_event&quot;, self.mouseup)<br>=A0=A0=A0=A0=A0=A0=A0=A0 self.co=
nnect(&quot;key_press_event&quot;, self.key_press)<br>
-=A0=A0=A0=A0=A0=A0=A0 self.connect(&quot;key_release_event&quot;, self.key=
_release)<br>=A0<br>=A0=A0=A0=A0=A0=A0=A0=A0 self.set_flags(gtk.CAN_FOCUS)<=
br>=A0=A0=A0=A0=A0=A0=A0=A0 self.grab_focus()<br>@@ -1163,8 +1161,13 @@ cla=
ss Area(gtk.DrawingArea):<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0 self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.TCROSS))<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 widget.queue_draw()<br>=A0<br>-=A0=A0=
=A0 def key_release(self,widget,event):<br>-=A0=A0=A0=A0=A0=A0=A0 pass<br>+=
=A0=A0=A0 def change_line_size(self, delta):<br>+=A0=A0=A0=A0=A0=A0=A0 if s=
elf.tool[&#39;name&#39;] in [&#39;pencil&#39;,&#39;eraser&#39;,&#39;brush&#=
39;,&#39;rainbow&#39;]:<br>
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 size =3D self.tool[&#39;line size&#39;] =
+ delta<br>+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 self.tool[&#39;line size&#39;=
] =3D size<br>+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 self.configure_line(size)<=
br>+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 self.queue_draw()<br>+<br>=A0<br>=A0=
=A0=A0=A0 def _keep_selection_ratio(self, coords):<br>
=A0=A0=A0=A0=A0=A0=A0=A0 def sign(x):<br>diff --git a/OficinaActivity.py b/=
OficinaActivity.py<br>index f7dd088..8259ca8 100644<br>--- a/OficinaActivit=
y.py<br>+++ b/OficinaActivity.py<br>@@ -116,6 +116,8 @@ class OficinaActivi=
ty(activity.Activity):<br>
=A0=A0=A0=A0=A0=A0=A0=A0 self.set_toolbox(toolbox)<br>=A0=A0=A0=A0=A0=A0=A0=
=A0 toolbox.show()<br>=A0<br>+=A0=A0=A0=A0=A0=A0=A0 self.connect(&quot;key_=
press_event&quot;, self.key_press)<br>+<br>=A0=A0=A0=A0=A0=A0=A0=A0 # setup=
 self.area only once<br>=A0<br>=A0=A0=A0=A0=A0=A0=A0=A0 def map_cp(widget):=
<br>
@@ -130,6 +132,19 @@ class OficinaActivity(activity.Activity):<br>=A0<br>=
=A0=A0=A0=A0=A0=A0=A0=A0 self._setup_handle =3D self.connect(&#39;map&#39;,=
 map_cp)<br>=A0<br>+<br>+=A0=A0=A0 def key_press(self,widget,event):<br>+=
=A0=A0=A0=A0=A0=A0=A0 if (event.keyval &gt;=3D 65474) and (event.keyval &lt=
;=3D 65477):<br>
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if event.keyval =3D=3D 65474:<br>+=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 self.area.change_line_size(-5)<br>+=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 elif event.keyval =3D=3D 65475:<br>+=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 self.area.change_line_size(-1)<b=
r>+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 elif event.keyval =3D=3D 65476:<br>
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 self.area.change_line_size(1=
)<br>+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 elif event.keyval =3D=3D 65477:<br>=
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 self.area.change_line_size(5=
)<br>+<br>+<br>=A0=A0=A0=A0 def read_file(self, file_path):<br>=A0=A0=A0=A0=
=A0=A0=A0=A0 &#39;&#39;&#39;Read file from Sugar Journal.&#39;&#39;&#39;<br=
>
=A0<br>-- <br>1.6.6.1<br><br clear=3D"all"><br>-- <br>Gonzalo<br>

--000e0cd48b14b5c97f048804fdc5--
--000e0cd48b14b5c989048804fdc7
Content-Type: application/octet-stream; 
	name="0001-implement-OLPC-8865.patch"
Content-Disposition: attachment; filename="0001-implement-OLPC-8865.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_g9xozbv70

RnJvbSAwOGUwMjI2NzMxYzEzZTc0Yjk5M2I1OWMxYTJjODE2NWU5YWQzNjU0IE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBHb256YWxvIE9kaWFyZCA8Z29kaWFyZEBnbWFpbC5jb20+CkRh
dGU6IFdlZCwgMiBKdW4gMjAxMCAwMTo1OTo1NCAtMDMwMApTdWJqZWN0OiBbUEFUQ0hdIGltcGxl
bWVudCBPTFBDICM4ODY1CgotLS0KIEFyZWEucHkgICAgICAgICAgICB8ICAgMTMgKysrKysrKyst
LS0tLQogT2ZpY2luYUFjdGl2aXR5LnB5IHwgICAxNSArKysrKysrKysrKysrKysKIDIgZmlsZXMg
Y2hhbmdlZCwgMjMgaW5zZXJ0aW9ucygrKSwgNSBkZWxldGlvbnMoLSkKCmRpZmYgLS1naXQgYS9B
cmVhLnB5IGIvQXJlYS5weQppbmRleCBlODFmY2Rj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CIsIHNlbGYua2V5X3ByZXNzKQorCiAgICAgICAgICMgc2V0
dXAgc2VsZi5hcmVhIG9ubHkgb25jZQogCiAgICAgICAgIGRlZiBtYXBfY3Aod2lkZ2V0KToKQEAg
LTEzMCw2ICsxMzIsMTkgQEAgY2xhc3MgT2ZpY2luYUFjdGl2aXR5KGFjdGl2aXR5LkFjdGl2aXR5
KToKIAogICAgICAgICBzZWxmLl9zZXR1cF9oYW5kbGUgPSBzZWxmLmNvbm5lY3QoJ21hcCcsIG1h
cF9jcCkKIAorCisgICAgZGVmIGtleV9wcmVzcyhzZWxmLHdpZGdldCxldmVudCk6CisgICAgICAg
IGlmIChldmVudC5rZXl2YWwgPj0gNjU0NzQpIGFuZCAoZXZlbnQua2V5dmFsIDw9IDY1NDc3KToK
KyAgICAgICAgICAgIGlmIGV2ZW50LmtleXZhbCA9PSA2NTQ3NDoKKyAgICAgICAgICAgICAgICBz
ZWxmLmFyZWEuY2hhbmdlX2xpbmVfc2l6ZSgtNSkKKyAgICAgICAgICAgIGVsaWYgZXZlbnQua2V5
dmFsID09IDY1NDc1OgorICAgICAgICAgICAgICAgIHNlbGYuYXJlYS5jaGFuZ2VfbGluZV9zaXpl
KC0xKQorICAgICAgICAgICAgZWxpZiBldmVudC5rZXl2YWwgPT0gNjU0NzY6CisgICAgICAgICAg
ICAgICAgc2VsZi5hcmVhLmNoYW5nZV9saW5lX3NpemUoMSkKKyAgICAgICAgICAgIGVsaWYgZXZl
bnQua2V5dmFsID09IDY1NDc3OgorICAgICAgICAgICAgICAgIHNlbGYuYXJlYS5jaGFuZ2VfbGlu
ZV9zaXplKDUpCisKKwogICAgIGRlZiByZWFkX2ZpbGUoc2VsZiwgZmlsZV9wYXRoKToKICAgICAg
ICAgJycnUmVhZCBmaWxlIGZyb20gU3VnYXIgSm91cm5hbC4nJycKIAotLSAKMS42LjYuMQoK
--000e0cd48b14b5c989048804fdc7--


More information about the Sugar-devel mailing list