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

Gonzalo Odiard godiard at gmail.com
Fri Jun 4 00:47:27 EDT 2010


Thanks.
I will add a function to detect the "brush_like_tools".

Gonzalo

On Thu, Jun 3, 2010 at 4:03 AM, James Cameron <quozl at laptop.org> wrote:

> 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:
>
> From e0b197a8b8058399c557d4e591b2cac4833ffdf2 Mon Sep 17 00:00:00 2001
> From: James Cameron <quozl at laptop.org>
> Date: Thu, 3 Jun 2010 16:59:10 +1000
> Subject: [PATCH] hide brush when mouse leave area
>
> Adds an enter and leave event handler for the drawing area, in order
> to draw or not draw the outline cursor.
>
> Tested-by: James Cameron <quozl at laptop.org>
> ---
>  Area.py |   20 +++++++++++++++++---
>  1 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/Area.py b/Area.py
> index 570d093..a7f0bd0 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.KEY_PRESS_MASK)
> -
> +                gtk.gdk.LEAVE_NOTIFY_MASK |
> +                gtk.gdk.ENTER_NOTIFY_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("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,18 @@ class Area(gtk.DrawingArea):
>              self.desenha = True
>         widget.queue_draw()
>
> +    def mouseleave(self, widget, event):
> +        if self.tool['name'] in ['pencil','eraser','brush','rainbow']:
> +            self.drawing = True
> +            size = self.tool['line size']
> +            widget.queue_draw_area(self.x_cursor-size, self.y_cursor-size,
> size*2, size*2)
> +
> +    def mouseenter(self, widget, event):
> +        if self.tool['name'] in ['pencil','eraser','brush','rainbow']:
> +            self.drawing = False
> +            size = self.tool['line size']
> +            widget.queue_draw_area(self.x_cursor-size, self.y_cursor-size,
> size*2, size*2)
>
> -
>     def mousemove(self,widget,event):
>         """Make the Area object (GtkDrawingArea) recognize that the mouse
> is moving.
>
> --
> 1.7.1
>
> --
> James Cameron
> http://quozl.linux.org.au/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.sugarlabs.org/archive/sugar-devel/attachments/20100604/20387599/attachment.htm 


More information about the Sugar-devel mailing list