On 12-06-20 05:56 PM, Sam Bull wrote:
>> Oh, I also sketched out a sample of a "slot" mechanism that allows multiple
>> callbacks per event, currently just included in the examples directory.
> OK, in your example, it receives the widget as the implicit self argument, because the object is assigned in the class definition. What I'd really like is the option to assign it afterwards, like:
>
> btn = sgc.Button()
> btn.on_click = EventSlot("click")
>
> But, when done like this, it no longer receives the implicit self argument. This is the same reason we don't have a reference to the widget when assigning a callback function like this.
>
> Is there an easy way we can get a reference to the object it is being assigned to? The only thing I can think of, is to use __setattr__() in the widget and pass in self when a callback or event slot is being assigned to a widget.
class EventSlot(object):
def __set__( self, widget, value ):
...
That is, a descriptor (such as EventSlot) can decide what to do when you
go to set the value on the object, so it could simply append, or could
replace, or whatever you feel is appropriate. However, that implies
using an EventSlot (or some *other* descriptor) in the class as your
base definition. Which seems to be what you want to avoid.
On 12-06-20 05:56 PM, Sam Bull wrote:
>> Oh, I also sketched out a sample of a "slot" mechanism that allows multiple
>> callbacks per event, currently just included in the examples directory.
> OK, in your example, it receives the widget as the implicit self argument, because the object is assigned in the class definition. What I'd really like is the option to assign it afterwards, like:
>
> btn = sgc.Button()
> btn.on_click = EventSlot("click")
>
> But, when done like this, it no longer receives the implicit self argument. This is the same reason we don't have a reference to the widget when assigning a callback function like this.
>
> Is there an easy way we can get a reference to the object it is being assigned to? The only thing I can think of, is to use __setattr__() in the widget and pass in self when a callback or event slot is being assigned to a widget.
class EventSlot(object):
def __set__( self, widget, value ):
...
That is, a descriptor (such as EventSlot) can decide what to do when you
go to set the value on the object, so it could simply append, or could
replace, or whatever you feel is appropriate. However, that implies
using an EventSlot (or some *other* descriptor) in the class as your
base definition. Which seems to be what you want to avoid.
HTH,
Mike
-- _______ _______ _______ _______ _______ ______ www.vrplumber. com blog.vrplumber. com
_______
Mike C. Fletcher
Designer, VR Plumber, Coder
http://
http://