Forcing a button fire

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

Forcing a button fire

Adam Hughes
Hi,

I'm having a hard time finding the correct syntax to force a button fire
(without clicking it manually).  Does anyone have this handy.  I tried
searching the API and archives but could not find what I was looking for.

Thanks.

~Adam
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Jonathan March
myinstance.mybutton = whatever

On Mon, Apr 16, 2012 at 4:33 PM, Adam Hughes <[hidden email]>wrote:

> Hi,
>
> I'm having a hard time finding the correct syntax to force a button fire
> (without clicking it manually).  Does anyone have this handy.  I tried
> searching the API and archives but could not find what I was looking for.
>
> Thanks.
>
> ~Adam
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Brennan Williams
In reply to this post by Adam Hughes
On 17/04/2012 9:33 a.m., Adam Hughes wrote:

> Hi,
>
> I'm having a hard time finding the correct syntax to force a button fire
> (without clicking it manually).  Does anyone have this handy.  I tried
> searching the API and archives but could not find what I was looking for.
>
> Thanks.
>
> ~Adam
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
mybutton=Button('Click Me')
.....
def _mybutton_fired(self):
.....

so I take it you don't just mean you want to "manually" call
_mybutton_fired() ?

Brennan

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Adam Hughes
On Mon, Apr 16, 2012 at 9:36 PM, Brennan Williams <
[hidden email]> wrote:

> On 17/04/2012 9:33 a.m., Adam Hughes wrote:
> > Hi,
> >
> > I'm having a hard time finding the correct syntax to force a button fire
> > (without clicking it manually).  Does anyone have this handy.  I tried
> > searching the API and archives but could not find what I was looking for.
> >
> > Thanks.
> >
> > ~Adam
> > _______________________________________________
> > Enthought-Dev mailing list
> > [hidden email]
> > https://mail.enthought.com/mailman/listinfo/enthought-dev
> >
> mybutton=Button('Click Me')
> .....
> def _mybutton_fired(self):
> .....
>
> so I take it you don't just mean you want to "manually" call
> _mybutton_fired() ?
>

Yeah,I'm dumb...

Thanks :)

>
> Brennan
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Corran Webster
In reply to this post by Adam Hughes
Hi Adam,

completely untested, but a Button is just a subclass of event, so you
should just be able to set it to True to fire it:

    foo.button = True

-- Corran

On Mon, Apr 16, 2012 at 4:33 PM, Adam Hughes <[hidden email]>wrote:

> Hi,
>
> I'm having a hard time finding the correct syntax to force a button fire
> (without clicking it manually).  Does anyone have this handy.  I tried
> searching the API and archives but could not find what I was looking for.
>
> Thanks.
>
> ~Adam
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Adam Hughes
Thanks Corran.  Both your solution and Brennan's work fine (tested both).
I don't know why this wasn't obvious to me.

Thanks guys.

On Mon, Apr 16, 2012 at 11:33 PM, Corran Webster <[hidden email]>wrote:

> Hi Adam,
>
> completely untested, but a Button is just a subclass of event, so you
> should just be able to set it to True to fire it:
>
>    foo.button = True
>
> -- Corran
>
> On Mon, Apr 16, 2012 at 4:33 PM, Adam Hughes <[hidden email]
> >wrote:
>
> > Hi,
> >
> > I'm having a hard time finding the correct syntax to force a button fire
> > (without clicking it manually).  Does anyone have this handy.  I tried
> > searching the API and archives but could not find what I was looking for.
> >
> > Thanks.
> >
> > ~Adam
> > _______________________________________________
> > Enthought-Dev mailing list
> > [hidden email]
> > https://mail.enthought.com/mailman/listinfo/enthought-dev
> >
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Martin Chilvers
In reply to this post by Brennan Williams
G'day,

On 17/04/2012 02:36, Brennan Williams wrote:
> def _mybutton_fired(self):
> .....
>
> so I take it you don't just mean you want to "manually" call
> _mybutton_fired() ?

Unless the context is GUI testing, in general manually calling event
handlers is a classic code smell... The code that you want to call
should be abstracted into a method/function that is called from within
the event handler and then manually wherever you choose.. That way:-

a) You avoid the ugliness of passing in 'fake' arguments that are
required by the API of your event handler API

b) You can make the intent of the action clearer. The user's isn't
thinking 'I want to click this button' they are thinking 'I want to
shutdown the nuclear reactor' ;^) Hence create a method/function along
the lines of:-

def shutdown_nuclear_reactor():
    ...

or

class NuclearReactor(...):
     def shutdown(self):
         ...

and call that from your 'on-click' handler and wherever else you might
need it.

Martin
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Brennan Williams
On 17/04/2012 8:39 p.m., Martin Chilvers wrote:

> G'day,
>
> On 17/04/2012 02:36, Brennan Williams wrote:
>> def _mybutton_fired(self):
>> .....
>>
>> so I take it you don't just mean you want to "manually" call
>> _mybutton_fired() ?
> Unless the context is GUI testing, in general manually calling event
> handlers is a classic code smell... The code that you want to call
> should be abstracted into a method/function that is called from within
> the event handler and then manually wherever you choose.. That way:-
>
> a) You avoid the ugliness of passing in 'fake' arguments that are
> required by the API of your event handler API
>
> b) You can make the intent of the action clearer. The user's isn't
> thinking 'I want to click this button' they are thinking 'I want to
> shutdown the nuclear reactor' ;^) Hence create a method/function along
> the lines of:-
>
> def shutdown_nuclear_reactor():
>      ...
>
> or
>
> class NuclearReactor(...):
>       def shutdown(self):
>           ...
>
> and call that from your 'on-click' handler and wherever else you might
> need it.
Yes, good point. I do tend to do this even though it appears to be only
a thin and unrequired layer but it does differentiate,as you say,
between a GUI action and the real action you want to apply. You could
otherwise end up with some odd looking code where a _myvalue_changed
method then calls a _mybutton_fired method.

Brennan

> Martin
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Luigi Paioro
Hello!

I take the advantage of this thread, to post another similar issue. What
you have described here is applicable to the Button case... but how
could I force an Action execution?

Thanks in advance,

   Luigi


On 04/17/12 11:00, Brennan Williams wrote:

> On 17/04/2012 8:39 p.m., Martin Chilvers wrote:
>> G'day,
>>
>> On 17/04/2012 02:36, Brennan Williams wrote:
>>> def _mybutton_fired(self):
>>> .....
>>>
>>> so I take it you don't just mean you want to "manually" call
>>> _mybutton_fired() ?
>> Unless the context is GUI testing, in general manually calling event
>> handlers is a classic code smell... The code that you want to call
>> should be abstracted into a method/function that is called from within
>> the event handler and then manually wherever you choose.. That way:-
>>
>> a) You avoid the ugliness of passing in 'fake' arguments that are
>> required by the API of your event handler API
>>
>> b) You can make the intent of the action clearer. The user's isn't
>> thinking 'I want to click this button' they are thinking 'I want to
>> shutdown the nuclear reactor' ;^) Hence create a method/function along
>> the lines of:-
>>
>> def shutdown_nuclear_reactor():
>>       ...
>>
>> or
>>
>> class NuclearReactor(...):
>>        def shutdown(self):
>>            ...
>>
>> and call that from your 'on-click' handler and wherever else you might
>> need it.
> Yes, good point. I do tend to do this even though it appears to be only
> a thin and unrequired layer but it does differentiate,as you say,
> between a GUI action and the real action you want to apply. You could
> otherwise end up with some odd looking code where a _myvalue_changed
> method then calls a _mybutton_fired method.
>
> Brennan
>
>> Martin
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Adam Hughes
Thanks for the input guys.  My application has some bug where I need to
fire this button before one of the plots updates correctly.  I have no idea
where the bug is and so I'm patching it by adding an automatic button fire
for now.  It really strange because the button only calls a few methods, so
I think it has something to do with the GUI getting hung up.  I have no
idea, but that's why I was asking.

Luigi, actions really just point to methods right?  At the end of the day,
you action is merely calling a method that you can call yourself.  Wouldn't
that be the same thing?

On Tue, Apr 17, 2012 at 5:35 AM, Luigi Paioro <[hidden email]>wrote:

> Hello!
>
> I take the advantage of this thread, to post another similar issue. What
> you have described here is applicable to the Button case... but how
> could I force an Action execution?
>
> Thanks in advance,
>
>   Luigi
>
>
> On 04/17/12 11:00, Brennan Williams wrote:
> > On 17/04/2012 8:39 p.m., Martin Chilvers wrote:
> >> G'day,
> >>
> >> On 17/04/2012 02:36, Brennan Williams wrote:
> >>> def _mybutton_fired(self):
> >>> .....
> >>>
> >>> so I take it you don't just mean you want to "manually" call
> >>> _mybutton_fired() ?
> >> Unless the context is GUI testing, in general manually calling event
> >> handlers is a classic code smell... The code that you want to call
> >> should be abstracted into a method/function that is called from within
> >> the event handler and then manually wherever you choose.. That way:-
> >>
> >> a) You avoid the ugliness of passing in 'fake' arguments that are
> >> required by the API of your event handler API
> >>
> >> b) You can make the intent of the action clearer. The user's isn't
> >> thinking 'I want to click this button' they are thinking 'I want to
> >> shutdown the nuclear reactor' ;^) Hence create a method/function along
> >> the lines of:-
> >>
> >> def shutdown_nuclear_reactor():
> >>       ...
> >>
> >> or
> >>
> >> class NuclearReactor(...):
> >>        def shutdown(self):
> >>            ...
> >>
> >> and call that from your 'on-click' handler and wherever else you might
> >> need it.
> > Yes, good point. I do tend to do this even though it appears to be only
> > a thin and unrequired layer but it does differentiate,as you say,
> > between a GUI action and the real action you want to apply. You could
> > otherwise end up with some odd looking code where a _myvalue_changed
> > method then calls a _mybutton_fired method.
> >
> > Brennan
> >
> >> Martin
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Luigi Paioro
Alas it is not the same, since an Action performs a call to an Handler
method (the handler specified in the View, and the method specified in
the Action). I guess that it is not possible to directly call an Action
execution...

Luigi


On 04/17/12 17:49, Adam Hughes wrote:

> Thanks for the input guys.  My application has some bug where I need to
> fire this button before one of the plots updates correctly.  I have no idea
> where the bug is and so I'm patching it by adding an automatic button fire
> for now.  It really strange because the button only calls a few methods, so
> I think it has something to do with the GUI getting hung up.  I have no
> idea, but that's why I was asking.
>
> Luigi, actions really just point to methods right?  At the end of the day,
> you action is merely calling a method that you can call yourself.  Wouldn't
> that be the same thing?
>
> On Tue, Apr 17, 2012 at 5:35 AM, Luigi Paioro<[hidden email]>wrote:
>
>> Hello!
>>
>> I take the advantage of this thread, to post another similar issue. What
>> you have described here is applicable to the Button case... but how
>> could I force an Action execution?
>>
>> Thanks in advance,
>>
>>    Luigi
>>
>>
>> On 04/17/12 11:00, Brennan Williams wrote:
>>> On 17/04/2012 8:39 p.m., Martin Chilvers wrote:
>>>> G'day,
>>>>
>>>> On 17/04/2012 02:36, Brennan Williams wrote:
>>>>> def _mybutton_fired(self):
>>>>> .....
>>>>>
>>>>> so I take it you don't just mean you want to "manually" call
>>>>> _mybutton_fired() ?
>>>> Unless the context is GUI testing, in general manually calling event
>>>> handlers is a classic code smell... The code that you want to call
>>>> should be abstracted into a method/function that is called from within
>>>> the event handler and then manually wherever you choose.. That way:-
>>>>
>>>> a) You avoid the ugliness of passing in 'fake' arguments that are
>>>> required by the API of your event handler API
>>>>
>>>> b) You can make the intent of the action clearer. The user's isn't
>>>> thinking 'I want to click this button' they are thinking 'I want to
>>>> shutdown the nuclear reactor' ;^) Hence create a method/function along
>>>> the lines of:-
>>>>
>>>> def shutdown_nuclear_reactor():
>>>>        ...
>>>>
>>>> or
>>>>
>>>> class NuclearReactor(...):
>>>>         def shutdown(self):
>>>>             ...
>>>>
>>>> and call that from your 'on-click' handler and wherever else you might
>>>> need it.
>>> Yes, good point. I do tend to do this even though it appears to be only
>>> a thin and unrequired layer but it does differentiate,as you say,
>>> between a GUI action and the real action you want to apply. You could
>>> otherwise end up with some odd looking code where a _myvalue_changed
>>> method then calls a _mybutton_fired method.
>>>
>>> Brennan
>>>
>>>> Martin
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a button fire

Adam Hughes
Ah i see.

On Tue, Apr 17, 2012 at 12:17 PM, Luigi Paioro <[hidden email]>wrote:

> Alas it is not the same, since an Action performs a call to an Handler
> method (the handler specified in the View, and the method specified in
> the Action). I guess that it is not possible to directly call an Action
> execution...
>
> Luigi
>
>
> On 04/17/12 17:49, Adam Hughes wrote:
> > Thanks for the input guys.  My application has some bug where I need to
> > fire this button before one of the plots updates correctly.  I have no
> idea
> > where the bug is and so I'm patching it by adding an automatic button
> fire
> > for now.  It really strange because the button only calls a few methods,
> so
> > I think it has something to do with the GUI getting hung up.  I have no
> > idea, but that's why I was asking.
> >
> > Luigi, actions really just point to methods right?  At the end of the
> day,
> > you action is merely calling a method that you can call yourself.
>  Wouldn't
> > that be the same thing?
> >
> > On Tue, Apr 17, 2012 at 5:35 AM, Luigi Paioro<[hidden email]
> >wrote:
> >
> >> Hello!
> >>
> >> I take the advantage of this thread, to post another similar issue. What
> >> you have described here is applicable to the Button case... but how
> >> could I force an Action execution?
> >>
> >> Thanks in advance,
> >>
> >>    Luigi
> >>
> >>
> >> On 04/17/12 11:00, Brennan Williams wrote:
> >>> On 17/04/2012 8:39 p.m., Martin Chilvers wrote:
> >>>> G'day,
> >>>>
> >>>> On 17/04/2012 02:36, Brennan Williams wrote:
> >>>>> def _mybutton_fired(self):
> >>>>> .....
> >>>>>
> >>>>> so I take it you don't just mean you want to "manually" call
> >>>>> _mybutton_fired() ?
> >>>> Unless the context is GUI testing, in general manually calling event
> >>>> handlers is a classic code smell... The code that you want to call
> >>>> should be abstracted into a method/function that is called from within
> >>>> the event handler and then manually wherever you choose.. That way:-
> >>>>
> >>>> a) You avoid the ugliness of passing in 'fake' arguments that are
> >>>> required by the API of your event handler API
> >>>>
> >>>> b) You can make the intent of the action clearer. The user's isn't
> >>>> thinking 'I want to click this button' they are thinking 'I want to
> >>>> shutdown the nuclear reactor' ;^) Hence create a method/function along
> >>>> the lines of:-
> >>>>
> >>>> def shutdown_nuclear_reactor():
> >>>>        ...
> >>>>
> >>>> or
> >>>>
> >>>> class NuclearReactor(...):
> >>>>         def shutdown(self):
> >>>>             ...
> >>>>
> >>>> and call that from your 'on-click' handler and wherever else you might
> >>>> need it.
> >>> Yes, good point. I do tend to do this even though it appears to be only
> >>> a thin and unrequired layer but it does differentiate,as you say,
> >>> between a GUI action and the real action you want to apply. You could
> >>> otherwise end up with some odd looking code where a _myvalue_changed
> >>> method then calls a _mybutton_fired method.
> >>>
> >>> Brennan
> >>>
> >>>> Martin
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev