>>>       def but_cb(self, widget):
>>>               widget.label("okay")
>>>               print widget.secret  #this line pukes
>>
>>         Maybe that last line should instead read:
>>
>>                 print self.but.secret
> 
> Actually it doesn't work in the case of a shared callback.
> I think a callback needs to be able to reference the widget
> that the event occured for.

        OK, I must have missed that shared callbacks were a goal.

        Yes, it's save some trouble if 'widget' was
        MyButton and not the Fl_Widget.

        I assume python doesn't give you access to the nasty
        'recasting pointer' tricks that C++ lets us get away with
        to access both.

        Sounds more like a question for the pyfltk mailing list;
        is it possible that the 'widget' passed to the callback
        could be the custom class instead of the Fl_Widget?
        Some implementation trickery might be necessary on the
        pyfltk side to pull this trick off.

        Certainly you should be able to get what you want
        the old fashioned way, passing the button as the userdata:

                self.but1 = MyButton(30,30,120,25,"Button #1")
                self.but1.callback(self.but_cb, but1)   # userdata but1

                self.but2 = MyButton(30,60,120,25,"Button #2")
                self.but2.callback(self.but_cb, but2)   # userdata but2
        [..]

        def but_cb(self, widget, userdata):
                print userdata.secret

        But I suppose it'd be nicer/make more sense if 'widget' did that
        for us.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to