understanding event/event propagation and implementation

Hi,

I am building an overlay widget library for gl.canvas. At present there are simple ones, like panel, button, checkbox, slider etc.

The frame work is similar to any other gui kit and follows parent-child hierarchy.

I am implementing a simple event system. Here are the steps:

  1. You bind an event directly to widget. For example : self.button.bind(“click”, myfunction)

  2. When user click on canvas, canvas return the unique widget id and event type.

  3. Start a search for this widget using id from the top level frame.

  4. If widget found, find if this widget has registered an event of same type

  5. If event matches then execute the function.

This is simple and so far working fine. I was reading these two articles earlier for some tips:

http://wiki.wxpython.org/EventPropagation

http://wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind

My question is do I need event propagation? If yes, then why?

Is it possible that above logic will fail some where?

Cheers

Prashant

I am building an overlay widget library for gl.canvas.

as in rendering the widgets with GL itself?

Sounds cool, but I'm curious -- why?

At present there are
simple ones, like panel, button, checkbox, slider etc.
The frame work is similar to any other gui kit and follows parent-child
hierarchy.

I am implementing a simple event system. Here are the steps:

1. You bind an event directly to widget. For example :
self.button.bind("click", myfunction)
2. When user click on canvas, canvas return the unique widget id and event
type.

so you are doing hit testing, and know which widget was clicked on -- yes?

3. Start a search for this widget using id from the top level frame.

why search? could you not have either:
  a dict or data structure, or something that has the widget mapped to
the click-point already?
  and then keep the bindings in the widget itself.

so it would look like:

1. capture the click
2. determine which (if any) widget has been clocked
3. call The_Widget.HandleTheEvent()

the .HandleTheEvent() method would get set by the Bind() call.

This is simple and so far working fine. I was reading these two articles
earlier for some tips:
EventPropagation - wxPyWiki
self.Bind vs. self.button.Bind - wxPyWiki

My question is do I need event propagation? If yes, then why?
Is it possible that above logic will fail some where?

I think it comes down, to some extent to how closely you want to
emulate the wx event system.

HTH,
  -Chris

···

On Thu, May 31, 2012 at 4:42 AM, King <animator333@gmail.com> wrote:

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

One other note:

Can a widget exist on more than one Canvas?

With wx.lib.floatcanvas, I do a similar thing, but I've always had it
in mind for the same "DrawObject" to be able to exist on more than one
Canvas, (or none at all) -- this complicates the event binding, as a
single DrawObject could have have different bindings on different
canvases. But if you only need a one-to-one relationship, then it's
more straightforward.

-Chris

···

On Thu, May 31, 2012 at 8:56 AM, Chris Barker <chris.barker@noaa.gov> wrote:

On Thu, May 31, 2012 at 4:42 AM, King <animator333@gmail.com> wrote:

I am building an overlay widget library for gl.canvas.

as in rendering the widgets with GL itself?

Sounds cool, but I'm curious -- why?

At present there are
simple ones, like panel, button, checkbox, slider etc.
The frame work is similar to any other gui kit and follows parent-child
hierarchy.

I am implementing a simple event system. Here are the steps:

1. You bind an event directly to widget. For example :
self.button.bind("click", myfunction)
2. When user click on canvas, canvas return the unique widget id and event
type.

so you are doing hit testing, and know which widget was clicked on -- yes?

3. Start a search for this widget using id from the top level frame.

why search? could you not have either:
a dict or data structure, or something that has the widget mapped to
the click-point already?
and then keep the bindings in the widget itself.

so it would look like:

1. capture the click
2. determine which (if any) widget has been clocked
3. call The_Widget.HandleTheEvent()

the .HandleTheEvent() method would get set by the Bind() call.

This is simple and so far working fine. I was reading these two articles
earlier for some tips:
EventPropagation - wxPyWiki
self.Bind vs. self.button.Bind - wxPyWiki

My question is do I need event propagation? If yes, then why?
Is it possible that above logic will fail some where?

I think it comes down, to some extent to how closely you want to
emulate the wx event system.

HTH,
-Chris

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov