[Sugar-devel] Paint: use keys for change line width (OLPC#8865)

Gonzalo Odiard godiard at gmail.com
Wed Jun 2 06:24:33 EDT 2010


On Wed, Jun 2, 2010 at 3:20 AM, James Cameron <quozl at laptop.org> wrote:

> On Wed, Jun 02, 2010 at 02:02:04AM -0300, Gonzalo Odiard wrote:
> > Tomeu was right. Catching the key stokes in the activity works.
>
> Yes, I see, that works well.
>
> Are you happy with relative size change rather than absolute?  The
> ticket originally asked for absolute size setting.  You have made the
> keys change the size relative to the current size.
>
> I think its better for a drawing activity. Absolute sizes limit to 4 line
widths only.


> Here is the patch with your usual whitespace errors fixed, and a rewrite
> of the key handling using a dictionary again.
>
> Thanks


> From e2f9eba803f44aeba778221825dc6f976087b3a4 Mon Sep 17 00:00:00 2001
> From: Gonzalo Odiard <godiard at gmail.com>
> Date: Wed, 2 Jun 2010 16:07:06 +1000
> Subject: [PATCH] slider keys change line size, dev.laptop.org #8865
>
> 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/
>



-- 
Gonzalo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.sugarlabs.org/archive/sugar-devel/attachments/20100602/726835a1/attachment.htm 


More information about the Sugar-devel mailing list