How to make a gtk event?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make a gtk event?

Martin Matusiak
Hey guys,

I'm writing a program using using gtk# and I have a custom widget that
I want to make an event for. Here is what an event looks like:

>>> print self.mainwindow.Shown
<IronPython.Runtime.Types.ReflectedEvent+BoundEvent object at
0x000000000000002B
[IronPython.Runtime.Types.ReflectedEvent+BoundEvent]>

So I seem to need to instantiate this type with my event name and
trigger function somehow as parameters, but I don't know how. Any
ideas?


Martin
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: How to make a gtk event?

Dino Viehland
Martin wrote:

> Hey guys,
>
> I'm writing a program using using gtk# and I have a custom widget that I want
> to make an event for. Here is what an event looks like:
>
> >>> print self.mainwindow.Shown
> <IronPython.Runtime.Types.ReflectedEvent+BoundEvent object at
> 0x000000000000002B
> [IronPython.Runtime.Types.ReflectedEvent+BoundEvent]>
>
> So I seem to need to instantiate this type with my event name and trigger
> function somehow as parameters, but I don't know how. Any ideas?

The BoundEvent object supports in place addition and subtraction for adding/removing
the events and it'll accept any callable object on the right hand side.  So you should just do
+= on shown, such as:

def handler(sender, args):
    print('hello')

self.mainwindow.shown += handler
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: How to make a gtk event?

Martin Matusiak
I'm not talking about the handler, I'm talking about creating a new
event for this widget. As in:

mywidget.SomethingHappened += some_handler

2011/4/13 Dino Viehland <[hidden email]>:

> Martin wrote:
>> Hey guys,
>>
>> I'm writing a program using using gtk# and I have a custom widget that I want
>> to make an event for. Here is what an event looks like:
>>
>> >>> print self.mainwindow.Shown
>> <IronPython.Runtime.Types.ReflectedEvent+BoundEvent object at
>> 0x000000000000002B
>> [IronPython.Runtime.Types.ReflectedEvent+BoundEvent]>
>>
>> So I seem to need to instantiate this type with my event name and trigger
>> function somehow as parameters, but I don't know how. Any ideas?
>
> The BoundEvent object supports in place addition and subtraction for adding/removing
> the events and it'll accept any callable object on the right hand side.  So you should just do
> += on shown, such as:
>
> def handler(sender, args):
>    print('hello')
>
> self.mainwindow.shown += handler
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: How to make a gtk event?

Dino Viehland
Oh, reading comprehension fail...  as long as you don't want it statically declared
(e.g. it's only ever accessed from Python) then there's a sample pyevent.py in
the Tutorial which does this. It's just an object with __iadd__ / __isub__ and a
list of handlers to dispatch to.

> -----Original Message-----
> From: [hidden email] [mailto:users-
> [hidden email]] On Behalf Of Martin Matusiak
> Sent: Wednesday, April 13, 2011 9:41 AM
> To: Discussion of IronPython
> Subject: Re: [IronPython] How to make a gtk event?
>
> I'm not talking about the handler, I'm talking about creating a new event for
> this widget. As in:
>
> mywidget.SomethingHappened += some_handler
>
> 2011/4/13 Dino Viehland <[hidden email]>:
> > Martin wrote:
> >> Hey guys,
> >>
> >> I'm writing a program using using gtk# and I have a custom widget
> >> that I want to make an event for. Here is what an event looks like:
> >>
> >> >>> print self.mainwindow.Shown
> >> <IronPython.Runtime.Types.ReflectedEvent+BoundEvent object at
> >> 0x000000000000002B
> >> [IronPython.Runtime.Types.ReflectedEvent+BoundEvent]>
> >>
> >> So I seem to need to instantiate this type with my event name and
> >> trigger function somehow as parameters, but I don't know how. Any
> ideas?
> >
> > The BoundEvent object supports in place addition and subtraction for
> > adding/removing the events and it'll accept any callable object on the
> > right hand side.  So you should just do
> > += on shown, such as:
> >
> > def handler(sender, args):
> >    print('hello')
> >
> > self.mainwindow.shown += handler
> > _______________________________________________
> > Users mailing list
> > [hidden email]
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: How to make a gtk event?

Martin Matusiak
Yes, that works. But pedantically speaking, is it possible to
manufacture an event that would agree on type with the gtk produced
ones? I really don't know if this ever comes up but suppose at one
point it needs to be interchangeable with a built in event?


Martin

2011/4/13 Dino Viehland <[hidden email]>:

> Oh, reading comprehension fail...  as long as you don't want it statically declared
> (e.g. it's only ever accessed from Python) then there's a sample pyevent.py in
> the Tutorial which does this. It's just an object with __iadd__ / __isub__ and a
> list of handlers to dispatch to.
>
>> -----Original Message-----
>> From: [hidden email] [mailto:users-
>> [hidden email]] On Behalf Of Martin Matusiak
>> Sent: Wednesday, April 13, 2011 9:41 AM
>> To: Discussion of IronPython
>> Subject: Re: [IronPython] How to make a gtk event?
>>
>> I'm not talking about the handler, I'm talking about creating a new event for
>> this widget. As in:
>>
>> mywidget.SomethingHappened += some_handler
>>
>> 2011/4/13 Dino Viehland <[hidden email]>:
>> > Martin wrote:
>> >> Hey guys,
>> >>
>> >> I'm writing a program using using gtk# and I have a custom widget
>> >> that I want to make an event for. Here is what an event looks like:
>> >>
>> >> >>> print self.mainwindow.Shown
>> >> <IronPython.Runtime.Types.ReflectedEvent+BoundEvent object at
>> >> 0x000000000000002B
>> >> [IronPython.Runtime.Types.ReflectedEvent+BoundEvent]>
>> >>
>> >> So I seem to need to instantiate this type with my event name and
>> >> trigger function somehow as parameters, but I don't know how. Any
>> ideas?
>> >
>> > The BoundEvent object supports in place addition and subtraction for
>> > adding/removing the events and it'll accept any callable object on the
>> > right hand side.  So you should just do
>> > += on shown, such as:
>> >
>> > def handler(sender, args):
>> >    print('hello')
>> >
>> > self.mainwindow.shown += handler
>> > _______________________________________________
>> > Users mailing list
>> > [hidden email]
>> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>> >
>> _______________________________________________
>> Users mailing list
>> [hidden email]
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: How to make a gtk event?

Dino Viehland
Unless GTK has some event class of its own my guess is the answer is no.  But if
it doesn't have an event class of its own then it probably doesn't matter as I'd think
it would never consume your events - only other Python code would.

> -----Original Message-----
> From: Martin Matusiak [mailto:[hidden email]]
> Sent: Thursday, April 14, 2011 1:57 AM
> To: Discussion of IronPython
> Cc: Dino Viehland
> Subject: Re: [IronPython] How to make a gtk event?
>
> Yes, that works. But pedantically speaking, is it possible to manufacture an
> event that would agree on type with the gtk produced ones? I really don't
> know if this ever comes up but suppose at one point it needs to be
> interchangeable with a built in event?
>
>
> Martin
>
> 2011/4/13 Dino Viehland <[hidden email]>:
> > Oh, reading comprehension fail...  as long as you don't want it
> > statically declared (e.g. it's only ever accessed from Python) then
> > there's a sample pyevent.py in the Tutorial which does this. It's just
> > an object with __iadd__ / __isub__ and a list of handlers to dispatch to.
> >
> >> -----Original Message-----
> >> From: [hidden email] [mailto:users-
> >> [hidden email]] On Behalf Of Martin Matusiak
> >> Sent: Wednesday, April 13, 2011 9:41 AM
> >> To: Discussion of IronPython
> >> Subject: Re: [IronPython] How to make a gtk event?
> >>
> >> I'm not talking about the handler, I'm talking about creating a new
> >> event for this widget. As in:
> >>
> >> mywidget.SomethingHappened += some_handler
> >>
> >> 2011/4/13 Dino Viehland <[hidden email]>:
> >> > Martin wrote:
> >> >> Hey guys,
> >> >>
> >> >> I'm writing a program using using gtk# and I have a custom widget
> >> >> that I want to make an event for. Here is what an event looks like:
> >> >>
> >> >> >>> print self.mainwindow.Shown
> >> >> <IronPython.Runtime.Types.ReflectedEvent+BoundEvent object at
> >> >> 0x000000000000002B
> >> >> [IronPython.Runtime.Types.ReflectedEvent+BoundEvent]>
> >> >>
> >> >> So I seem to need to instantiate this type with my event name and
> >> >> trigger function somehow as parameters, but I don't know how. Any
> >> ideas?
> >> >
> >> > The BoundEvent object supports in place addition and subtraction
> >> > for adding/removing the events and it'll accept any callable object
> >> > on the right hand side.  So you should just do
> >> > += on shown, such as:
> >> >
> >> > def handler(sender, args):
> >> >    print('hello')
> >> >
> >> > self.mainwindow.shown += handler
> >> > _______________________________________________
> >> > Users mailing list
> >> > [hidden email]
> >> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >> >
> >> _______________________________________________
> >> Users mailing list
> >> [hidden email]
> >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > _______________________________________________
> > Users mailing list
> > [hidden email]
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com