Want to add an Apply button to the standard set at teh bottom of a dialog.

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

Want to add an Apply button to the standard set at teh bottom of a dialog.

Alan Jackson
I'm struggling with adding an Apply button to the bottom of a dialog.
The snippet below does not work, but I think it illustrates what I want
to do. I want to add to the OK/Cancel set of buttons at the bottom of
the dialog, and I'm struggling to figure out how to get it to work. Any
help appreciated. What *is* the recommended way to do this?


class CurveEdit(HasTraits):
    newname = Str
    newcurve = Curve
    medval = Float
    Despike_med = Button('Median Despike')
    Despike_oct = Button('Octant Despike')
    Undo        = Button('Undo')
    doapply     = Button('Apply')
    edit_view = View(
            Item('newname', label="New Curve Name",),
            Item('medval', label="Median Value",),
            Item('Despike_med', show_label=False),
            Item('Despike_oct', show_label=False),
            Item('Undo', show_label=False),
            buttons = ['OK', 'Apply', 'Cancel'],
            title='Curve Editor', width = 200, height = 500, resizable=True,
            )
    def _doapply_fired(self):
        print "apply fired"

--
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| [hidden email]          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Want to add an Apply button to the standard set at teh bottom of a dialog.

Adam Hughes
You're not actually putting the doapply button on your screen.  The
'buttons' keyword that you used in the View call is calling some builtin
buttons; however, if you want to add a custom button to the view, I believe
you need to add it directly as its own Item.  I'm not sure if you can put
it into the buttons object, but it will work this way:

from traits.api import *
from traitsui.api import *

class Test(HasTraits):
    app=Button('Apply')

    edit_view=View(Item('app') )

    def _app_fired(self):
        print 'apply fired'

Test().configure_traits()

On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson <[hidden email]> wrote:

> I'm struggling with adding an Apply button to the bottom of a dialog.
> The snippet below does not work, but I think it illustrates what I want
> to do. I want to add to the OK/Cancel set of buttons at the bottom of
> the dialog, and I'm struggling to figure out how to get it to work. Any
> help appreciated. What *is* the recommended way to do this?
>
>
> class CurveEdit(HasTraits):
>    newname = Str
>    newcurve = Curve
>    medval = Float
>    Despike_med = Button('Median Despike')
>    Despike_oct = Button('Octant Despike')
>    Undo        = Button('Undo')
>    doapply     = Button('Apply')
>    edit_view = View(
>            Item('newname', label="New Curve Name",),
>            Item('medval', label="Median Value",),
>            Item('Despike_med', show_label=False),
>            Item('Despike_oct', show_label=False),
>            Item('Undo', show_label=False),
>            buttons = ['OK', 'Apply', 'Cancel'],
>            title='Curve Editor', width = 200, height = 500, resizable=True,
>            )
>    def _doapply_fired(self):
>        print "apply fired"
>
> --
> -----------------------------------------------------------------------
> | Alan K. Jackson            | To see a World in a Grain of Sand      |
> | [hidden email]          | And a Heaven in a Wild Flower,         |
> | www.ajackson.org           | Hold Infinity in the palm of your hand |
> | Houston, Texas             | And Eternity in an hour. - Blake       |
> -----------------------------------------------------------------------
> _______________________________________________
> 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: Want to add an Apply button to the standard set at teh bottom of a dialog.

Jonathan Rocher
Dear Alan,

Attached is a modified version of your code that implements something that
I think is close to what you want to do. What you did is good for a normal
button (see my implementation of the undo button) in the main part of the
view.

For the apply button, a custom action buttons in the bottom bar, I
recommend you add it to the list of buttons as an action, and specify their
name and the name of the method to be called when they are pressed. Where
things are a little more complex compared to what you wrote is that we
recommend the MVC architecture (MVC = Model View Controller) where the
behavior of the UI when user is contained in a Handler type object (also
called controller). In that scheme the method to be called is a method of
the handler object, which the view is aware of by specifying the handler
attribute. I added a couple of commands in the  method to illustrate how to
use the info object.

Also note that the OKCancelButtons is a list of the OKButton and the
CancelButton. (Therefore my +.)

Let me know if something is unclear in the code attached or if I
miss-understood what you wanted to do.

Best regards,
Jonathan

On Sat, Mar 10, 2012 at 3:26 PM, Adam Hughes <[hidden email]>wrote:

> You're not actually putting the doapply button on your screen.  The
> 'buttons' keyword that you used in the View call is calling some builtin
> buttons; however, if you want to add a custom button to the view, I believe
> you need to add it directly as its own Item.  I'm not sure if you can put
> it into the buttons object, but it will work this way:
>
> from traits.api import *
> from traitsui.api import *
>
> class Test(HasTraits):
>    app=Button('Apply')
>
>    edit_view=View(Item('app') )
>
>    def _app_fired(self):
>        print 'apply fired'
>
> Test().configure_traits()
>
> On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson <[hidden email]> wrote:
>
> > I'm struggling with adding an Apply button to the bottom of a dialog.
> > The snippet below does not work, but I think it illustrates what I want
> > to do. I want to add to the OK/Cancel set of buttons at the bottom of
> > the dialog, and I'm struggling to figure out how to get it to work. Any
> > help appreciated. What *is* the recommended way to do this?
> >
> >
> > class CurveEdit(HasTraits):
> >    newname = Str
> >    newcurve = Curve
> >    medval = Float
> >    Despike_med = Button('Median Despike')
> >    Despike_oct = Button('Octant Despike')
> >    Undo        = Button('Undo')
> >    doapply     = Button('Apply')
> >    edit_view = View(
> >            Item('newname', label="New Curve Name",),
> >            Item('medval', label="Median Value",),
> >            Item('Despike_med', show_label=False),
> >            Item('Despike_oct', show_label=False),
> >            Item('Undo', show_label=False),
> >            buttons = ['OK', 'Apply', 'Cancel'],
> >            title='Curve Editor', width = 200, height = 500,
> resizable=True,
> >            )
> >    def _doapply_fired(self):
> >        print "apply fired"
> >
> > --
> > -----------------------------------------------------------------------
> > | Alan K. Jackson            | To see a World in a Grain of Sand      |
> > | [hidden email]          | And a Heaven in a Wild Flower,         |
> > | www.ajackson.org           | Hold Infinity in the palm of your hand |
> > | Houston, Texas             | And Eternity in an hour. - Blake       |
> > -----------------------------------------------------------------------
> > _______________________________________________
> > 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
>


--
Jonathan Rocher, PhD
Scientific software developer
Enthought, Inc.
[hidden email]
1-512-536-1057
http://www.enthought.com

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

Re: Want to add an Apply button to the standard set at teh bottom of a dialog.

Alan Jackson
No attachment...

On Sat, 10 Mar 2012 16:07:52 -0800
Jonathan Rocher <[hidden email]> wrote:

> Dear Alan,
>
> Attached is a modified version of your code that implements something that
> I think is close to what you want to do. What you did is good for a normal
> button (see my implementation of the undo button) in the main part of the
> view.
>
> For the apply button, a custom action buttons in the bottom bar, I
> recommend you add it to the list of buttons as an action, and specify their
> name and the name of the method to be called when they are pressed. Where
> things are a little more complex compared to what you wrote is that we
> recommend the MVC architecture (MVC = Model View Controller) where the
> behavior of the UI when user is contained in a Handler type object (also
> called controller). In that scheme the method to be called is a method of
> the handler object, which the view is aware of by specifying the handler
> attribute. I added a couple of commands in the  method to illustrate how to
> use the info object.
>
> Also note that the OKCancelButtons is a list of the OKButton and the
> CancelButton. (Therefore my +.)
>
> Let me know if something is unclear in the code attached or if I
> miss-understood what you wanted to do.
>
> Best regards,
> Jonathan
>
> On Sat, Mar 10, 2012 at 3:26 PM, Adam Hughes <[hidden email]>wrote:
>
> > You're not actually putting the doapply button on your screen.  The
> > 'buttons' keyword that you used in the View call is calling some builtin
> > buttons; however, if you want to add a custom button to the view, I believe
> > you need to add it directly as its own Item.  I'm not sure if you can put
> > it into the buttons object, but it will work this way:
> >
> > from traits.api import *
> > from traitsui.api import *
> >
> > class Test(HasTraits):
> >    app=Button('Apply')
> >
> >    edit_view=View(Item('app') )
> >
> >    def _app_fired(self):
> >        print 'apply fired'
> >
> > Test().configure_traits()
> >
> > On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson <[hidden email]> wrote:
> >
> > > I'm struggling with adding an Apply button to the bottom of a dialog.
> > > The snippet below does not work, but I think it illustrates what I want
> > > to do. I want to add to the OK/Cancel set of buttons at the bottom of
> > > the dialog, and I'm struggling to figure out how to get it to work. Any
> > > help appreciated. What *is* the recommended way to do this?
> > >
> > >
> > > class CurveEdit(HasTraits):
> > >    newname = Str
> > >    newcurve = Curve
> > >    medval = Float
> > >    Despike_med = Button('Median Despike')
> > >    Despike_oct = Button('Octant Despike')
> > >    Undo        = Button('Undo')
> > >    doapply     = Button('Apply')
> > >    edit_view = View(
> > >            Item('newname', label="New Curve Name",),
> > >            Item('medval', label="Median Value",),
> > >            Item('Despike_med', show_label=False),
> > >            Item('Despike_oct', show_label=False),
> > >            Item('Undo', show_label=False),
> > >            buttons = ['OK', 'Apply', 'Cancel'],
> > >            title='Curve Editor', width = 200, height = 500,
> > resizable=True,
> > >            )
> > >    def _doapply_fired(self):
> > >        print "apply fired"
> > >
> > > --
> > > -----------------------------------------------------------------------
> > > | Alan K. Jackson            | To see a World in a Grain of Sand      |
> > > | [hidden email]          | And a Heaven in a Wild Flower,         |
> > > | www.ajackson.org           | Hold Infinity in the palm of your hand |
> > > | Houston, Texas             | And Eternity in an hour. - Blake       |
> > > -----------------------------------------------------------------------
> > > _______________________________________________
> > > 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
> >
>
>
>


--
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| [hidden email]          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Want to add an Apply button to the standard set at teh bottom of a dialog.

Jonathan Rocher
Strange. My mailer says there was a 2K file sent. Sending it again...

Jonathan

On Sun, Mar 11, 2012 at 11:18 AM, Alan Jackson <[hidden email]> wrote:

> No attachment...
>
> On Sat, 10 Mar 2012 16:07:52 -0800
> Jonathan Rocher <[hidden email]> wrote:
>
> > Dear Alan,
> >
> > Attached is a modified version of your code that implements something
> that
> > I think is close to what you want to do. What you did is good for a
> normal
> > button (see my implementation of the undo button) in the main part of the
> > view.
> >
> > For the apply button, a custom action buttons in the bottom bar, I
> > recommend you add it to the list of buttons as an action, and specify
> their
> > name and the name of the method to be called when they are pressed. Where
> > things are a little more complex compared to what you wrote is that we
> > recommend the MVC architecture (MVC = Model View Controller) where the
> > behavior of the UI when user is contained in a Handler type object (also
> > called controller). In that scheme the method to be called is a method of
> > the handler object, which the view is aware of by specifying the handler
> > attribute. I added a couple of commands in the  method to illustrate how
> to
> > use the info object.
> >
> > Also note that the OKCancelButtons is a list of the OKButton and the
> > CancelButton. (Therefore my +.)
> >
> > Let me know if something is unclear in the code attached or if I
> > miss-understood what you wanted to do.
> >
> > Best regards,
> > Jonathan
> >
> > On Sat, Mar 10, 2012 at 3:26 PM, Adam Hughes <[hidden email]
> >wrote:
> >
> > > You're not actually putting the doapply button on your screen.  The
> > > 'buttons' keyword that you used in the View call is calling some
> builtin
> > > buttons; however, if you want to add a custom button to the view, I
> believe
> > > you need to add it directly as its own Item.  I'm not sure if you can
> put
> > > it into the buttons object, but it will work this way:
> > >
> > > from traits.api import *
> > > from traitsui.api import *
> > >
> > > class Test(HasTraits):
> > >    app=Button('Apply')
> > >
> > >    edit_view=View(Item('app') )
> > >
> > >    def _app_fired(self):
> > >        print 'apply fired'
> > >
> > > Test().configure_traits()
> > >
> > > On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson <[hidden email]>
> wrote:
> > >
> > > > I'm struggling with adding an Apply button to the bottom of a dialog.
> > > > The snippet below does not work, but I think it illustrates what I
> want
> > > > to do. I want to add to the OK/Cancel set of buttons at the bottom of
> > > > the dialog, and I'm struggling to figure out how to get it to work.
> Any
> > > > help appreciated. What *is* the recommended way to do this?
> > > >
> > > >
> > > > class CurveEdit(HasTraits):
> > > >    newname = Str
> > > >    newcurve = Curve
> > > >    medval = Float
> > > >    Despike_med = Button('Median Despike')
> > > >    Despike_oct = Button('Octant Despike')
> > > >    Undo        = Button('Undo')
> > > >    doapply     = Button('Apply')
> > > >    edit_view = View(
> > > >            Item('newname', label="New Curve Name",),
> > > >            Item('medval', label="Median Value",),
> > > >            Item('Despike_med', show_label=False),
> > > >            Item('Despike_oct', show_label=False),
> > > >            Item('Undo', show_label=False),
> > > >            buttons = ['OK', 'Apply', 'Cancel'],
> > > >            title='Curve Editor', width = 200, height = 500,
> > > resizable=True,
> > > >            )
> > > >    def _doapply_fired(self):
> > > >        print "apply fired"
> > > >
> > > > --
> > > >
> -----------------------------------------------------------------------
> > > > | Alan K. Jackson            | To see a World in a Grain of Sand
>  |
> > > > | [hidden email]          | And a Heaven in a Wild Flower,
>   |
> > > > | www.ajackson.org           | Hold Infinity in the palm of your
> hand |
> > > > | Houston, Texas             | And Eternity in an hour. - Blake
>   |
> > > >
> -----------------------------------------------------------------------
> > > > _______________________________________________
> > > > 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
> > >
> >
> >
> >
>
>
> --
> -----------------------------------------------------------------------
> | Alan K. Jackson            | To see a World in a Grain of Sand      |
> | [hidden email]          | And a Heaven in a Wild Flower,         |
> | www.ajackson.org           | Hold Infinity in the palm of your hand |
> | Houston, Texas             | And Eternity in an hour. - Blake       |
> -----------------------------------------------------------------------
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>


--
Jonathan Rocher, PhD
Scientific software developer
Enthought, Inc.
[hidden email]
1-512-536-1057
http://www.enthought.com

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

Re: Want to add an Apply button to the standard set at teh bottom of a dialog.

Warren Weckesser
On Sun, Mar 11, 2012 at 2:06 PM, Jonathan Rocher <[hidden email]>wrote:

> Strange. My mailer says there was a 2K file sent. Sending it again...
>
>

Attachments are not getting through to enthought-dev.  You'll have to
include the code in the body of the email, or send it directly to Alan's
email address.

Warren


Jonathan

>
> On Sun, Mar 11, 2012 at 11:18 AM, Alan Jackson <[hidden email]> wrote:
>
> > No attachment...
> >
> > On Sat, 10 Mar 2012 16:07:52 -0800
> > Jonathan Rocher <[hidden email]> wrote:
> >
> > > Dear Alan,
> > >
> > > Attached is a modified version of your code that implements something
> > that
> > > I think is close to what you want to do. What you did is good for a
> > normal
> > > button (see my implementation of the undo button) in the main part of
> the
> > > view.
> > >
> > > For the apply button, a custom action buttons in the bottom bar, I
> > > recommend you add it to the list of buttons as an action, and specify
> > their
> > > name and the name of the method to be called when they are pressed.
> Where
> > > things are a little more complex compared to what you wrote is that we
> > > recommend the MVC architecture (MVC = Model View Controller) where the
> > > behavior of the UI when user is contained in a Handler type object
> (also
> > > called controller). In that scheme the method to be called is a method
> of
> > > the handler object, which the view is aware of by specifying the
> handler
> > > attribute. I added a couple of commands in the  method to illustrate
> how
> > to
> > > use the info object.
> > >
> > > Also note that the OKCancelButtons is a list of the OKButton and the
> > > CancelButton. (Therefore my +.)
> > >
> > > Let me know if something is unclear in the code attached or if I
> > > miss-understood what you wanted to do.
> > >
> > > Best regards,
> > > Jonathan
> > >
> > > On Sat, Mar 10, 2012 at 3:26 PM, Adam Hughes <[hidden email]
> > >wrote:
> > >
> > > > You're not actually putting the doapply button on your screen.  The
> > > > 'buttons' keyword that you used in the View call is calling some
> > builtin
> > > > buttons; however, if you want to add a custom button to the view, I
> > believe
> > > > you need to add it directly as its own Item.  I'm not sure if you can
> > put
> > > > it into the buttons object, but it will work this way:
> > > >
> > > > from traits.api import *
> > > > from traitsui.api import *
> > > >
> > > > class Test(HasTraits):
> > > >    app=Button('Apply')
> > > >
> > > >    edit_view=View(Item('app') )
> > > >
> > > >    def _app_fired(self):
> > > >        print 'apply fired'
> > > >
> > > > Test().configure_traits()
> > > >
> > > > On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson <[hidden email]>
> > wrote:
> > > >
> > > > > I'm struggling with adding an Apply button to the bottom of a
> dialog.
> > > > > The snippet below does not work, but I think it illustrates what I
> > want
> > > > > to do. I want to add to the OK/Cancel set of buttons at the bottom
> of
> > > > > the dialog, and I'm struggling to figure out how to get it to work.
> > Any
> > > > > help appreciated. What *is* the recommended way to do this?
> > > > >
> > > > >
> > > > > class CurveEdit(HasTraits):
> > > > >    newname = Str
> > > > >    newcurve = Curve
> > > > >    medval = Float
> > > > >    Despike_med = Button('Median Despike')
> > > > >    Despike_oct = Button('Octant Despike')
> > > > >    Undo        = Button('Undo')
> > > > >    doapply     = Button('Apply')
> > > > >    edit_view = View(
> > > > >            Item('newname', label="New Curve Name",),
> > > > >            Item('medval', label="Median Value",),
> > > > >            Item('Despike_med', show_label=False),
> > > > >            Item('Despike_oct', show_label=False),
> > > > >            Item('Undo', show_label=False),
> > > > >            buttons = ['OK', 'Apply', 'Cancel'],
> > > > >            title='Curve Editor', width = 200, height = 500,
> > > > resizable=True,
> > > > >            )
> > > > >    def _doapply_fired(self):
> > > > >        print "apply fired"
> > > > >
> > > > > --
> > > > >
> > -----------------------------------------------------------------------
> > > > > | Alan K. Jackson            | To see a World in a Grain of Sand
> >  |
> > > > > | [hidden email]          | And a Heaven in a Wild Flower,
> >   |
> > > > > | www.ajackson.org           | Hold Infinity in the palm of your
> > hand |
> > > > > | Houston, Texas             | And Eternity in an hour. - Blake
> >   |
> > > > >
> > -----------------------------------------------------------------------
> > > > > _______________________________________________
> > > > > 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
> > > >
> > >
> > >
> > >
> >
> >
> > --
> > -----------------------------------------------------------------------
> > | Alan K. Jackson            | To see a World in a Grain of Sand      |
> > | [hidden email]          | And a Heaven in a Wild Flower,         |
> > | www.ajackson.org           | Hold Infinity in the palm of your hand |
> > | Houston, Texas             | And Eternity in an hour. - Blake       |
> > -----------------------------------------------------------------------
> > _______________________________________________
> > Enthought-Dev mailing list
> > [hidden email]
> > https://mail.enthought.com/mailman/listinfo/enthought-dev
> >
>
>
>
> --
> Jonathan Rocher, PhD
> Scientific software developer
> Enthought, Inc.
> [hidden email]
> 1-512-536-1057
> http://www.enthought.com
>
> _______________________________________________
> 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: Want to add an Apply button to the standard set at teh bottom of a dialog.

Jonathan Rocher
Ah! I didn't realize that the enthought-dev doesn't transmit files. Sorry
about that. Below is the code I was going to suggest.

Best regards,
Jonathan

----------------------------------------------------------------------------------------------
Suggestion:
from traits.api import HasTraits, Str, Float, Button
from traitsui.api import Item, View, Handler, Action, OKCancelButtons

class Curve(HasTraits):
    a = Float()

class CurveHandler(Handler):
    """ Handler for the view
    """

    def on_doapply(self, info):
        """ What happens when doapply is clicked.
        """
        print "apply pressed"
        print info.object.newname
        info.ui.dispose()
        return

class CurveEdit(HasTraits):
   newname = Str("test name")
   newcurve = Curve
   medval = Float
   Despike_med = Button('Median Despike')
   Despike_oct = Button('Octant Despike')
   Undo        = Button('Undo')
   doapply     = Button('Apply')
   edit_view = View(
           Item('newname', label="New Curve Name",),
           Item('medval', label="Median Value",),
           Item('Despike_med', show_label=False),
           Item('Despike_oct', show_label=False),
           Item('Undo', show_label=False),
           buttons = [Action(name='My Apply',
                             action='on_doapply')]+OKCancelButtons,
           title='Curve Editor', width = 200, height = 500, resizable=True,
           handler = CurveHandler()
           )

   def _Undo_fired(self):
        print "undo pressed"

if __name__ == "__main__":
    c = Curve()
    cv = CurveEdit(newcurve=c)
    cv.configure_traits()


On Sun, Mar 11, 2012 at 12:35 PM, Warren Weckesser <
[hidden email]> wrote:

> On Sun, Mar 11, 2012 at 2:06 PM, Jonathan Rocher <[hidden email]
> >wrote:
>
> > Strange. My mailer says there was a 2K file sent. Sending it again...
> >
> >
>
> Attachments are not getting through to enthought-dev.  You'll have to
> include the code in the body of the email, or send it directly to Alan's
> email address.
>
> Warren
>
>
> Jonathan
> >
> > On Sun, Mar 11, 2012 at 11:18 AM, Alan Jackson <[hidden email]>
> wrote:
> >
> > > No attachment...
> > >
> > > On Sat, 10 Mar 2012 16:07:52 -0800
> > > Jonathan Rocher <[hidden email]> wrote:
> > >
> > > > Dear Alan,
> > > >
> > > > Attached is a modified version of your code that implements something
> > > that
> > > > I think is close to what you want to do. What you did is good for a
> > > normal
> > > > button (see my implementation of the undo button) in the main part of
> > the
> > > > view.
> > > >
> > > > For the apply button, a custom action buttons in the bottom bar, I
> > > > recommend you add it to the list of buttons as an action, and specify
> > > their
> > > > name and the name of the method to be called when they are pressed.
> > Where
> > > > things are a little more complex compared to what you wrote is that
> we
> > > > recommend the MVC architecture (MVC = Model View Controller) where
> the
> > > > behavior of the UI when user is contained in a Handler type object
> > (also
> > > > called controller). In that scheme the method to be called is a
> method
> > of
> > > > the handler object, which the view is aware of by specifying the
> > handler
> > > > attribute. I added a couple of commands in the  method to illustrate
> > how
> > > to
> > > > use the info object.
> > > >
> > > > Also note that the OKCancelButtons is a list of the OKButton and the
> > > > CancelButton. (Therefore my +.)
> > > >
> > > > Let me know if something is unclear in the code attached or if I
> > > > miss-understood what you wanted to do.
> > > >
> > > > Best regards,
> > > > Jonathan
> > > >
> > > > On Sat, Mar 10, 2012 at 3:26 PM, Adam Hughes <
> [hidden email]
> > > >wrote:
> > > >
> > > > > You're not actually putting the doapply button on your screen.  The
> > > > > 'buttons' keyword that you used in the View call is calling some
> > > builtin
> > > > > buttons; however, if you want to add a custom button to the view, I
> > > believe
> > > > > you need to add it directly as its own Item.  I'm not sure if you
> can
> > > put
> > > > > it into the buttons object, but it will work this way:
> > > > >
> > > > > from traits.api import *
> > > > > from traitsui.api import *
> > > > >
> > > > > class Test(HasTraits):
> > > > >    app=Button('Apply')
> > > > >
> > > > >    edit_view=View(Item('app') )
> > > > >
> > > > >    def _app_fired(self):
> > > > >        print 'apply fired'
> > > > >
> > > > > Test().configure_traits()
> > > > >
> > > > > On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson <[hidden email]>
> > > wrote:
> > > > >
> > > > > > I'm struggling with adding an Apply button to the bottom of a
> > dialog.
> > > > > > The snippet below does not work, but I think it illustrates what
> I
> > > want
> > > > > > to do. I want to add to the OK/Cancel set of buttons at the
> bottom
> > of
> > > > > > the dialog, and I'm struggling to figure out how to get it to
> work.
> > > Any
> > > > > > help appreciated. What *is* the recommended way to do this?
> > > > > >
> > > > > >
> > > > > > class CurveEdit(HasTraits):
> > > > > >    newname = Str
> > > > > >    newcurve = Curve
> > > > > >    medval = Float
> > > > > >    Despike_med = Button('Median Despike')
> > > > > >    Despike_oct = Button('Octant Despike')
> > > > > >    Undo        = Button('Undo')
> > > > > >    doapply     = Button('Apply')
> > > > > >    edit_view = View(
> > > > > >            Item('newname', label="New Curve Name",),
> > > > > >            Item('medval', label="Median Value",),
> > > > > >            Item('Despike_med', show_label=False),
> > > > > >            Item('Despike_oct', show_label=False),
> > > > > >            Item('Undo', show_label=False),
> > > > > >            buttons = ['OK', 'Apply', 'Cancel'],
> > > > > >            title='Curve Editor', width = 200, height = 500,
> > > > > resizable=True,
> > > > > >            )
> > > > > >    def _doapply_fired(self):
> > > > > >        print "apply fired"
> > > > > >
> > > > > > --
> > > > > >
> > > -----------------------------------------------------------------------
> > > > > > | Alan K. Jackson            | To see a World in a Grain of Sand
> > >  |
> > > > > > | [hidden email]          | And a Heaven in a Wild Flower,
> > >   |
> > > > > > | www.ajackson.org           | Hold Infinity in the palm of your
> > > hand |
> > > > > > | Houston, Texas             | And Eternity in an hour. - Blake
> > >   |
> > > > > >
> > > -----------------------------------------------------------------------
> > > > > > _______________________________________________
> > > > > > 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
> > > > >
> > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > -----------------------------------------------------------------------
> > > | Alan K. Jackson            | To see a World in a Grain of Sand      |
> > > | [hidden email]          | And a Heaven in a Wild Flower,
> |
> > > | www.ajackson.org           | Hold Infinity in the palm of your hand
> |
> > > | Houston, Texas             | And Eternity in an hour. - Blake       |
> > > -----------------------------------------------------------------------
> > > _______________________________________________
> > > Enthought-Dev mailing list
> > > [hidden email]
> > > https://mail.enthought.com/mailman/listinfo/enthought-dev
> > >
> >
> >
> >
> > --
> > Jonathan Rocher, PhD
> > Scientific software developer
> > Enthought, Inc.
> > [hidden email]
> > 1-512-536-1057
> > http://www.enthought.com
> >
> > _______________________________________________
> > 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
>



--
Jonathan Rocher, PhD
Scientific software developer
Enthought, Inc.
[hidden email]
1-512-536-1057
http://www.enthought.com
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Want to add an Apply button to the standard set at teh bottom of a dialog.

Brennan Williams
On 12/03/2012 10:58 a.m., Jonathan Rocher wrote:
> Ah! I didn't realize that the enthought-dev doesn't transmit files. Sorry
> about that. Below is the code I was going to suggest.
>
> Best regards,
> Jonathan
This is pretty much what I do except I define my Action outside of the
View definition, i.e. alongside my Button definitions....

MyApplyButton=Action(name='My Apply',action='on_doapply',tooltip='bla
bla bla')

and then I use...

buttons=[MyApplyButton,'OK','Cancel']

in the View definition.

If I dynamically create the view with something like
self.edit_view=self.create_edit_view() then...

def create_edit_view
     view=View(...,buttons=[self.MyApplyButton,'OK','Cancel'],....)
     return view

so, just cosmetic really.

Brennan

> ----------------------------------------------------------------------------------------------
> Suggestion:
> from traits.api import HasTraits, Str, Float, Button
> from traitsui.api import Item, View, Handler, Action, OKCancelButtons
>
> class Curve(HasTraits):
>      a = Float()
>
> class CurveHandler(Handler):
>      """ Handler for the view
>      """
>
>      def on_doapply(self, info):
>          """ What happens when doapply is clicked.
>          """
>          print "apply pressed"
>          print info.object.newname
>          info.ui.dispose()
>          return
>
> class CurveEdit(HasTraits):
>     newname = Str("test name")
>     newcurve = Curve
>     medval = Float
>     Despike_med = Button('Median Despike')
>     Despike_oct = Button('Octant Despike')
>     Undo        = Button('Undo')
>     doapply     = Button('Apply')
>     edit_view = View(
>             Item('newname', label="New Curve Name",),
>             Item('medval', label="Median Value",),
>             Item('Despike_med', show_label=False),
>             Item('Despike_oct', show_label=False),
>             Item('Undo', show_label=False),
>             buttons = [Action(name='My Apply',
>                               action='on_doapply')]+OKCancelButtons,
>             title='Curve Editor', width = 200, height = 500, resizable=True,
>             handler = CurveHandler()
>             )
>
>     def _Undo_fired(self):
>          print "undo pressed"
>
> if __name__ == "__main__":
>      c = Curve()
>      cv = CurveEdit(newcurve=c)
>      cv.configure_traits()
>
>
> On Sun, Mar 11, 2012 at 12:35 PM, Warren Weckesser<
> [hidden email]>  wrote:
>
>> On Sun, Mar 11, 2012 at 2:06 PM, Jonathan Rocher<[hidden email]
>>> wrote:
>>> Strange. My mailer says there was a 2K file sent. Sending it again...
>>>
>>>
>> Attachments are not getting through to enthought-dev.  You'll have to
>> include the code in the body of the email, or send it directly to Alan's
>> email address.
>>
>> Warren
>>
>>
>> Jonathan
>>> On Sun, Mar 11, 2012 at 11:18 AM, Alan Jackson<[hidden email]>
>> wrote:
>>>> No attachment...
>>>>
>>>> On Sat, 10 Mar 2012 16:07:52 -0800
>>>> Jonathan Rocher<[hidden email]>  wrote:
>>>>
>>>>> Dear Alan,
>>>>>
>>>>> Attached is a modified version of your code that implements something
>>>> that
>>>>> I think is close to what you want to do. What you did is good for a
>>>> normal
>>>>> button (see my implementation of the undo button) in the main part of
>>> the
>>>>> view.
>>>>>
>>>>> For the apply button, a custom action buttons in the bottom bar, I
>>>>> recommend you add it to the list of buttons as an action, and specify
>>>> their
>>>>> name and the name of the method to be called when they are pressed.
>>> Where
>>>>> things are a little more complex compared to what you wrote is that
>> we
>>>>> recommend the MVC architecture (MVC = Model View Controller) where
>> the
>>>>> behavior of the UI when user is contained in a Handler type object
>>> (also
>>>>> called controller). In that scheme the method to be called is a
>> method
>>> of
>>>>> the handler object, which the view is aware of by specifying the
>>> handler
>>>>> attribute. I added a couple of commands in the  method to illustrate
>>> how
>>>> to
>>>>> use the info object.
>>>>>
>>>>> Also note that the OKCancelButtons is a list of the OKButton and the
>>>>> CancelButton. (Therefore my +.)
>>>>>
>>>>> Let me know if something is unclear in the code attached or if I
>>>>> miss-understood what you wanted to do.
>>>>>
>>>>> Best regards,
>>>>> Jonathan
>>>>>
>>>>> On Sat, Mar 10, 2012 at 3:26 PM, Adam Hughes<
>> [hidden email]
>>>>> wrote:
>>>>>
>>>>>> You're not actually putting the doapply button on your screen.  The
>>>>>> 'buttons' keyword that you used in the View call is calling some
>>>> builtin
>>>>>> buttons; however, if you want to add a custom button to the view, I
>>>> believe
>>>>>> you need to add it directly as its own Item.  I'm not sure if you
>> can
>>>> put
>>>>>> it into the buttons object, but it will work this way:
>>>>>>
>>>>>> from traits.api import *
>>>>>> from traitsui.api import *
>>>>>>
>>>>>> class Test(HasTraits):
>>>>>>     app=Button('Apply')
>>>>>>
>>>>>>     edit_view=View(Item('app') )
>>>>>>
>>>>>>     def _app_fired(self):
>>>>>>         print 'apply fired'
>>>>>>
>>>>>> Test().configure_traits()
>>>>>>
>>>>>> On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson<[hidden email]>
>>>> wrote:
>>>>>>> I'm struggling with adding an Apply button to the bottom of a
>>> dialog.
>>>>>>> The snippet below does not work, but I think it illustrates what
>> I
>>>> want
>>>>>>> to do. I want to add to the OK/Cancel set of buttons at the
>> bottom
>>> of
>>>>>>> the dialog, and I'm struggling to figure out how to get it to
>> work.
>>>> Any
>>>>>>> help appreciated. What *is* the recommended way to do this?
>>>>>>>
>>>>>>>
>>>>>>> class CurveEdit(HasTraits):
>>>>>>>     newname = Str
>>>>>>>     newcurve = Curve
>>>>>>>     medval = Float
>>>>>>>     Despike_med = Button('Median Despike')
>>>>>>>     Despike_oct = Button('Octant Despike')
>>>>>>>     Undo        = Button('Undo')
>>>>>>>     doapply     = Button('Apply')
>>>>>>>     edit_view = View(
>>>>>>>             Item('newname', label="New Curve Name",),
>>>>>>>             Item('medval', label="Median Value",),
>>>>>>>             Item('Despike_med', show_label=False),
>>>>>>>             Item('Despike_oct', show_label=False),
>>>>>>>             Item('Undo', show_label=False),
>>>>>>>             buttons = ['OK', 'Apply', 'Cancel'],
>>>>>>>             title='Curve Editor', width = 200, height = 500,
>>>>>> resizable=True,
>>>>>>>             )
>>>>>>>     def _doapply_fired(self):
>>>>>>>         print "apply fired"
>>>>>>>
>>>>>>> --
>>>>>>>
>>>> -----------------------------------------------------------------------
>>>>>>> | Alan K. Jackson            | To see a World in a Grain of Sand
>>>>   |
>>>>>>> | [hidden email]          | And a Heaven in a Wild Flower,
>>>>    |
>>>>>>> | www.ajackson.org           | Hold Infinity in the palm of your
>>>> hand |
>>>>>>> | Houston, Texas             | And Eternity in an hour. - Blake
>>>>    |
>>>> -----------------------------------------------------------------------
>>>>>>> _______________________________________________
>>>>>>> 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
>>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>>>> -----------------------------------------------------------------------
>>>> | Alan K. Jackson            | To see a World in a Grain of Sand      |
>>>> | [hidden email]          | And a Heaven in a Wild Flower,
>> |
>>>> | www.ajackson.org           | Hold Infinity in the palm of your hand
>> |
>>>> | Houston, Texas             | And Eternity in an hour. - Blake       |
>>>> -----------------------------------------------------------------------
>>>> _______________________________________________
>>>> Enthought-Dev mailing list
>>>> [hidden email]
>>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>>>
>>>
>>>
>>> --
>>> Jonathan Rocher, PhD
>>> Scientific software developer
>>> Enthought, Inc.
>>> [hidden email]
>>> 1-512-536-1057
>>> http://www.enthought.com
>>>
>>> _______________________________________________
>>> 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: Want to add an Apply button to the standard set at teh bottom of a dialog.

Alan Jackson
In reply to this post by Jonathan Rocher
Thanks! Thats works nicely. One question - I noticed that I cannot name
the button "Apply", or it fails, but pretty much any other name is okay.


On Sun, 11 Mar 2012 14:58:57 -0700
Jonathan Rocher <[hidden email]> wrote:

> Ah! I didn't realize that the enthought-dev doesn't transmit files. Sorry
> about that. Below is the code I was going to suggest.
>
> Best regards,
> Jonathan
>
> ----------------------------------------------------------------------------------------------
> Suggestion:
> from traits.api import HasTraits, Str, Float, Button
> from traitsui.api import Item, View, Handler, Action, OKCancelButtons
>
> class Curve(HasTraits):
>     a = Float()
>
> class CurveHandler(Handler):
>     """ Handler for the view
>     """
>
>     def on_doapply(self, info):
>         """ What happens when doapply is clicked.
>         """
>         print "apply pressed"
>         print info.object.newname
>         info.ui.dispose()
>         return
>
> class CurveEdit(HasTraits):
>    newname = Str("test name")
>    newcurve = Curve
>    medval = Float
>    Despike_med = Button('Median Despike')
>    Despike_oct = Button('Octant Despike')
>    Undo        = Button('Undo')
>    doapply     = Button('Apply')
>    edit_view = View(
>            Item('newname', label="New Curve Name",),
>            Item('medval', label="Median Value",),
>            Item('Despike_med', show_label=False),
>            Item('Despike_oct', show_label=False),
>            Item('Undo', show_label=False),
>            buttons = [Action(name='My Apply',
>                              action='on_doapply')]+OKCancelButtons,
>            title='Curve Editor', width = 200, height = 500, resizable=True,
>            handler = CurveHandler()
>            )
>
>    def _Undo_fired(self):
>         print "undo pressed"
>
> if __name__ == "__main__":
>     c = Curve()
>     cv = CurveEdit(newcurve=c)
>     cv.configure_traits()
>
>
> On Sun, Mar 11, 2012 at 12:35 PM, Warren Weckesser <
> [hidden email]> wrote:
>
> > On Sun, Mar 11, 2012 at 2:06 PM, Jonathan Rocher <[hidden email]
> > >wrote:
> >
> > > Strange. My mailer says there was a 2K file sent. Sending it again...
> > >
> > >
> >
> > Attachments are not getting through to enthought-dev.  You'll have to
> > include the code in the body of the email, or send it directly to Alan's
> > email address.
> >
> > Warren
> >
> >
> > Jonathan
> > >
> > > On Sun, Mar 11, 2012 at 11:18 AM, Alan Jackson <[hidden email]>
> > wrote:
> > >
> > > > No attachment...
> > > >
> > > > On Sat, 10 Mar 2012 16:07:52 -0800
> > > > Jonathan Rocher <[hidden email]> wrote:
> > > >
> > > > > Dear Alan,
> > > > >
> > > > > Attached is a modified version of your code that implements something
> > > > that
> > > > > I think is close to what you want to do. What you did is good for a
> > > > normal
> > > > > button (see my implementation of the undo button) in the main part of
> > > the
> > > > > view.
> > > > >
> > > > > For the apply button, a custom action buttons in the bottom bar, I
> > > > > recommend you add it to the list of buttons as an action, and specify
> > > > their
> > > > > name and the name of the method to be called when they are pressed.
> > > Where
> > > > > things are a little more complex compared to what you wrote is that
> > we
> > > > > recommend the MVC architecture (MVC = Model View Controller) where
> > the
> > > > > behavior of the UI when user is contained in a Handler type object
> > > (also
> > > > > called controller). In that scheme the method to be called is a
> > method
> > > of
> > > > > the handler object, which the view is aware of by specifying the
> > > handler
> > > > > attribute. I added a couple of commands in the  method to illustrate
> > > how
> > > > to
> > > > > use the info object.
> > > > >
> > > > > Also note that the OKCancelButtons is a list of the OKButton and the
> > > > > CancelButton. (Therefore my +.)
> > > > >
> > > > > Let me know if something is unclear in the code attached or if I
> > > > > miss-understood what you wanted to do.
> > > > >
> > > > > Best regards,
> > > > > Jonathan
> > > > >
> > > > > On Sat, Mar 10, 2012 at 3:26 PM, Adam Hughes <
> > [hidden email]
> > > > >wrote:
> > > > >
> > > > > > You're not actually putting the doapply button on your screen.  The
> > > > > > 'buttons' keyword that you used in the View call is calling some
> > > > builtin
> > > > > > buttons; however, if you want to add a custom button to the view, I
> > > > believe
> > > > > > you need to add it directly as its own Item.  I'm not sure if you
> > can
> > > > put
> > > > > > it into the buttons object, but it will work this way:
> > > > > >
> > > > > > from traits.api import *
> > > > > > from traitsui.api import *
> > > > > >
> > > > > > class Test(HasTraits):
> > > > > >    app=Button('Apply')
> > > > > >
> > > > > >    edit_view=View(Item('app') )
> > > > > >
> > > > > >    def _app_fired(self):
> > > > > >        print 'apply fired'
> > > > > >
> > > > > > Test().configure_traits()
> > > > > >
> > > > > > On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson <[hidden email]>
> > > > wrote:
> > > > > >
> > > > > > > I'm struggling with adding an Apply button to the bottom of a
> > > dialog.
> > > > > > > The snippet below does not work, but I think it illustrates what
> > I
> > > > want
> > > > > > > to do. I want to add to the OK/Cancel set of buttons at the
> > bottom
> > > of
> > > > > > > the dialog, and I'm struggling to figure out how to get it to
> > work.
> > > > Any
> > > > > > > help appreciated. What *is* the recommended way to do this?
> > > > > > >
> > > > > > >
> > > > > > > class CurveEdit(HasTraits):
> > > > > > >    newname = Str
> > > > > > >    newcurve = Curve
> > > > > > >    medval = Float
> > > > > > >    Despike_med = Button('Median Despike')
> > > > > > >    Despike_oct = Button('Octant Despike')
> > > > > > >    Undo        = Button('Undo')
> > > > > > >    doapply     = Button('Apply')
> > > > > > >    edit_view = View(
> > > > > > >            Item('newname', label="New Curve Name",),
> > > > > > >            Item('medval', label="Median Value",),
> > > > > > >            Item('Despike_med', show_label=False),
> > > > > > >            Item('Despike_oct', show_label=False),
> > > > > > >            Item('Undo', show_label=False),
> > > > > > >            buttons = ['OK', 'Apply', 'Cancel'],
> > > > > > >            title='Curve Editor', width = 200, height = 500,
> > > > > > resizable=True,
> > > > > > >            )
> > > > > > >    def _doapply_fired(self):
> > > > > > >        print "apply fired"
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > -----------------------------------------------------------------------
> > > > > > > | Alan K. Jackson            | To see a World in a Grain of Sand
> > > >  |
> > > > > > > | [hidden email]          | And a Heaven in a Wild Flower,
> > > >   |
> > > > > > > | www.ajackson.org           | Hold Infinity in the palm of your
> > > > hand |
> > > > > > > | Houston, Texas             | And Eternity in an hour. - Blake
> > > >   |
> > > > > > >
> > > > -----------------------------------------------------------------------
> > > > > > > _______________________________________________
> > > > > > > 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
> > > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > -----------------------------------------------------------------------
> > > > | Alan K. Jackson            | To see a World in a Grain of Sand      |
> > > > | [hidden email]          | And a Heaven in a Wild Flower,
> > |
> > > > | www.ajackson.org           | Hold Infinity in the palm of your hand
> > |
> > > > | Houston, Texas             | And Eternity in an hour. - Blake       |
> > > > -----------------------------------------------------------------------
> > > > _______________________________________________
> > > > Enthought-Dev mailing list
> > > > [hidden email]
> > > > https://mail.enthought.com/mailman/listinfo/enthought-dev
> > > >
> > >
> > >
> > >
> > > --
> > > Jonathan Rocher, PhD
> > > Scientific software developer
> > > Enthought, Inc.
> > > [hidden email]
> > > 1-512-536-1057
> > > http://www.enthought.com
> > >
> > > _______________________________________________
> > > 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
> >
>
>
>


--
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| [hidden email]          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Want to add an Apply button to the standard set at teh bottom of a dialog.

Jonathan Rocher
Yes. This is because a few names are already reserved by traitsui. Apply is
one of them. The other 2 I can think of are OK and Cancel.

On Sun, Mar 11, 2012 at 3:45 PM, Alan Jackson <[hidden email]> wrote:

> Thanks! Thats works nicely. One question - I noticed that I cannot name
> the button "Apply", or it fails, but pretty much any other name is okay.
>
>
> On Sun, 11 Mar 2012 14:58:57 -0700
> Jonathan Rocher <[hidden email]> wrote:
>
> > Ah! I didn't realize that the enthought-dev doesn't transmit files. Sorry
> > about that. Below is the code I was going to suggest.
> >
> > Best regards,
> > Jonathan
> >
> >
> ----------------------------------------------------------------------------------------------
> > Suggestion:
> > from traits.api import HasTraits, Str, Float, Button
> > from traitsui.api import Item, View, Handler, Action, OKCancelButtons
> >
> > class Curve(HasTraits):
> >     a = Float()
> >
> > class CurveHandler(Handler):
> >     """ Handler for the view
> >     """
> >
> >     def on_doapply(self, info):
> >         """ What happens when doapply is clicked.
> >         """
> >         print "apply pressed"
> >         print info.object.newname
> >         info.ui.dispose()
> >         return
> >
> > class CurveEdit(HasTraits):
> >    newname = Str("test name")
> >    newcurve = Curve
> >    medval = Float
> >    Despike_med = Button('Median Despike')
> >    Despike_oct = Button('Octant Despike')
> >    Undo        = Button('Undo')
> >    doapply     = Button('Apply')
> >    edit_view = View(
> >            Item('newname', label="New Curve Name",),
> >            Item('medval', label="Median Value",),
> >            Item('Despike_med', show_label=False),
> >            Item('Despike_oct', show_label=False),
> >            Item('Undo', show_label=False),
> >            buttons = [Action(name='My Apply',
> >                              action='on_doapply')]+OKCancelButtons,
> >            title='Curve Editor', width = 200, height = 500,
> resizable=True,
> >            handler = CurveHandler()
> >            )
> >
> >    def _Undo_fired(self):
> >         print "undo pressed"
> >
> > if __name__ == "__main__":
> >     c = Curve()
> >     cv = CurveEdit(newcurve=c)
> >     cv.configure_traits()
> >
> >
> > On Sun, Mar 11, 2012 at 12:35 PM, Warren Weckesser <
> > [hidden email]> wrote:
> >
> > > On Sun, Mar 11, 2012 at 2:06 PM, Jonathan Rocher <
> [hidden email]
> > > >wrote:
> > >
> > > > Strange. My mailer says there was a 2K file sent. Sending it again...
> > > >
> > > >
> > >
> > > Attachments are not getting through to enthought-dev.  You'll have to
> > > include the code in the body of the email, or send it directly to
> Alan's
> > > email address.
> > >
> > > Warren
> > >
> > >
> > > Jonathan
> > > >
> > > > On Sun, Mar 11, 2012 at 11:18 AM, Alan Jackson <[hidden email]>
> > > wrote:
> > > >
> > > > > No attachment...
> > > > >
> > > > > On Sat, 10 Mar 2012 16:07:52 -0800
> > > > > Jonathan Rocher <[hidden email]> wrote:
> > > > >
> > > > > > Dear Alan,
> > > > > >
> > > > > > Attached is a modified version of your code that implements
> something
> > > > > that
> > > > > > I think is close to what you want to do. What you did is good
> for a
> > > > > normal
> > > > > > button (see my implementation of the undo button) in the main
> part of
> > > > the
> > > > > > view.
> > > > > >
> > > > > > For the apply button, a custom action buttons in the bottom bar,
> I
> > > > > > recommend you add it to the list of buttons as an action, and
> specify
> > > > > their
> > > > > > name and the name of the method to be called when they are
> pressed.
> > > > Where
> > > > > > things are a little more complex compared to what you wrote is
> that
> > > we
> > > > > > recommend the MVC architecture (MVC = Model View Controller)
> where
> > > the
> > > > > > behavior of the UI when user is contained in a Handler type
> object
> > > > (also
> > > > > > called controller). In that scheme the method to be called is a
> > > method
> > > > of
> > > > > > the handler object, which the view is aware of by specifying the
> > > > handler
> > > > > > attribute. I added a couple of commands in the  method to
> illustrate
> > > > how
> > > > > to
> > > > > > use the info object.
> > > > > >
> > > > > > Also note that the OKCancelButtons is a list of the OKButton and
> the
> > > > > > CancelButton. (Therefore my +.)
> > > > > >
> > > > > > Let me know if something is unclear in the code attached or if I
> > > > > > miss-understood what you wanted to do.
> > > > > >
> > > > > > Best regards,
> > > > > > Jonathan
> > > > > >
> > > > > > On Sat, Mar 10, 2012 at 3:26 PM, Adam Hughes <
> > > [hidden email]
> > > > > >wrote:
> > > > > >
> > > > > > > You're not actually putting the doapply button on your screen.
>  The
> > > > > > > 'buttons' keyword that you used in the View call is calling
> some
> > > > > builtin
> > > > > > > buttons; however, if you want to add a custom button to the
> view, I
> > > > > believe
> > > > > > > you need to add it directly as its own Item.  I'm not sure if
> you
> > > can
> > > > > put
> > > > > > > it into the buttons object, but it will work this way:
> > > > > > >
> > > > > > > from traits.api import *
> > > > > > > from traitsui.api import *
> > > > > > >
> > > > > > > class Test(HasTraits):
> > > > > > >    app=Button('Apply')
> > > > > > >
> > > > > > >    edit_view=View(Item('app') )
> > > > > > >
> > > > > > >    def _app_fired(self):
> > > > > > >        print 'apply fired'
> > > > > > >
> > > > > > > Test().configure_traits()
> > > > > > >
> > > > > > > On Sat, Mar 10, 2012 at 6:02 PM, Alan Jackson <
> [hidden email]>
> > > > > wrote:
> > > > > > >
> > > > > > > > I'm struggling with adding an Apply button to the bottom of a
> > > > dialog.
> > > > > > > > The snippet below does not work, but I think it illustrates
> what
> > > I
> > > > > want
> > > > > > > > to do. I want to add to the OK/Cancel set of buttons at the
> > > bottom
> > > > of
> > > > > > > > the dialog, and I'm struggling to figure out how to get it to
> > > work.
> > > > > Any
> > > > > > > > help appreciated. What *is* the recommended way to do this?
> > > > > > > >
> > > > > > > >
> > > > > > > > class CurveEdit(HasTraits):
> > > > > > > >    newname = Str
> > > > > > > >    newcurve = Curve
> > > > > > > >    medval = Float
> > > > > > > >    Despike_med = Button('Median Despike')
> > > > > > > >    Despike_oct = Button('Octant Despike')
> > > > > > > >    Undo        = Button('Undo')
> > > > > > > >    doapply     = Button('Apply')
> > > > > > > >    edit_view = View(
> > > > > > > >            Item('newname', label="New Curve Name",),
> > > > > > > >            Item('medval', label="Median Value",),
> > > > > > > >            Item('Despike_med', show_label=False),
> > > > > > > >            Item('Despike_oct', show_label=False),
> > > > > > > >            Item('Undo', show_label=False),
> > > > > > > >            buttons = ['OK', 'Apply', 'Cancel'],
> > > > > > > >            title='Curve Editor', width = 200, height = 500,
> > > > > > > resizable=True,
> > > > > > > >            )
> > > > > > > >    def _doapply_fired(self):
> > > > > > > >        print "apply fired"
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > >
> -----------------------------------------------------------------------
> > > > > > > > | Alan K. Jackson            | To see a World in a Grain of
> Sand
> > > > >  |
> > > > > > > > | [hidden email]          | And a Heaven in a Wild
> Flower,
> > > > >   |
> > > > > > > > | www.ajackson.org           | Hold Infinity in the palm of
> your
> > > > > hand |
> > > > > > > > | Houston, Texas             | And Eternity in an hour. -
> Blake
> > > > >   |
> > > > > > > >
> > > > >
> -----------------------------------------------------------------------
> > > > > > > > _______________________________________________
> > > > > > > > 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
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > >
> -----------------------------------------------------------------------
> > > > > | Alan K. Jackson            | To see a World in a Grain of Sand
>    |
> > > > > | [hidden email]          | And a Heaven in a Wild Flower,
> > > |
> > > > > | www.ajackson.org           | Hold Infinity in the palm of your
> hand
> > > |
> > > > > | Houston, Texas             | And Eternity in an hour. - Blake
>     |
> > > > >
> -----------------------------------------------------------------------
> > > > > _______________________________________________
> > > > > Enthought-Dev mailing list
> > > > > [hidden email]
> > > > > https://mail.enthought.com/mailman/listinfo/enthought-dev
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Jonathan Rocher, PhD
> > > > Scientific software developer
> > > > Enthought, Inc.
> > > > [hidden email]
> > > > 1-512-536-1057
> > > > http://www.enthought.com
> > > >
> > > > _______________________________________________
> > > > 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
> > >
> >
> >
> >
>
>
> --
> -----------------------------------------------------------------------
> | Alan K. Jackson            | To see a World in a Grain of Sand      |
> | [hidden email]          | And a Heaven in a Wild Flower,         |
> | www.ajackson.org           | Hold Infinity in the palm of your hand |
> | Houston, Texas             | And Eternity in an hour. - Blake       |
> -----------------------------------------------------------------------
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



--
Jonathan Rocher, PhD
Scientific software developer
Enthought, Inc.
[hidden email]
1-512-536-1057
http://www.enthought.com
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev