[Sugar-devel] Paint: hide brush when leave area

James Cameron quozl at laptop.org
Thu Jun 3 03:03:54 EDT 2010


On Wed, Jun 02, 2010 at 08:03:29PM -0300, Gonzalo Odiard wrote:
> >From 3ac11e0be2adc0c805788c38ab90b3226d625a89 Mon Sep 17 00:00:00 2001
> From: Gonzalo Odiard <godiard at gmail.com>
> Date: Wed, 2 Jun 2010 20:01:10 -0300
> Subject: [PATCH] hide brush when mouse leave area
> 
> ---
>  Area.py |   15 ++++++++++++++-
>  1 files changed, 14 insertions(+), 1 deletions(-)
> 
> diff --git a/Area.py b/Area.py
> index 8a5e523..c83f38f 100644
> --- a/Area.py
> +++ b/Area.py
> @@ -97,11 +97,15 @@ class Area(gtk.DrawingArea):
>                  gtk.gdk.BUTTON_PRESS_MASK |
>                  gtk.gdk.BUTTON_RELEASE_MASK|
>                  gtk.gdk.EXPOSURE_MASK |
> +                gtk.gdk.LEAVE_NOTIFY_MASK|
> +                gtk.gdk.ENTER_NOTIFY_MASK|

Unnecessary change of spacing for expression.

>                  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("leave_notify_event", self.mouseleave)
> +        self.connect("enter_notify_event", self.mouseenter)
>          self.connect("button_release_event", self.mouseup)
>          self.connect("key_press_event", self.key_press)
>  
> @@ -353,8 +357,17 @@ class Area(gtk.DrawingArea):
>              self.desenha = True
>          widget.queue_draw()
>  
> -
> +    def mouseleave(self,widget,event):
> +        if self.tool['name'] in ['pencil','eraser','brush','rainbow']:

We are seeing this test more and more.  What pain you will experience
when you add another tool name to that list.  Perhaps it should be a
list in the object attributes, or even a function.

> +            self.drawing = True
> +            widget.queue_draw_area(self.x_cursor-size, self.y_cursor-size,
> size*2, size*2)

size is not defined, generates traceback in log.

>  
> +    def mouseenter(self,widget,event):
> +        if self.tool['name'] in ['pencil','eraser','brush','rainbow']:
> +            self.drawing = False
> +            widget.queue_draw_area(self.x_cursor-size, self.y_cursor-size,
> size*2, size*2)

size is not defined.

The call to queue_draw_area could be factored.

Counter-proposal:



More information about the Sugar-devel mailing list