Enthought python - Traits

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ash

    #1

    Enthought python - Traits

    Hello everyone !

    I am trying to find some sort of a cookbook or more examples for using
    Enthought Traits to build GUI's. I tried to follow the documentations
    present at the enthought site, but couldnt get too far - especially on
    how to handle a control event ?

    Also while i am on the topic:

    say i have a list "control" that create using the following two lines:

    class Project(HasTrai ts):
    coordinate_syst em=Enum('Cartes ian','Cylindric al')

    I added the following line to get the option selected by the user:

    def _coordinate_sys tem_changed(sel f,old,new):
    print 'System changed from %s to %s ' %(old,new)

    but it does not return what the user select. It should return either 0
    or 1 based on the two choices, but i can't seem to find a way to trap
    that.
    I am relatively new to this GUI programming in Python and really could
    use some tips/hints.

    Thanks,

    -Ash

  • Peter  Wang

    #2
    Re: Enthought python - Traits

    Ash wrote:
    Hello everyone !
    >
    I am trying to find some sort of a cookbook or more examples for using
    Enthought Traits to build GUI's. I tried to follow the documentations
    present at the enthought site, but couldnt get too far - especially on
    how to handle a control event ?
    The traits manual is in the lib/site-packages/enthought/traits/doc
    directory, named Traits2_UM.doc/.pdf. The traits UI manual/user guide
    is also in there. However, what is not so obvious is that there is
    also an excellent, massive set of powerpoint slides (121 pages) that
    Dave Morrill put together that talks about the architecture of Traits
    UI, and how to build GUIs using it. (Er, how to build them *well*,
    i.e. adhering to the M-V-C pattern and maximizing code reuse.) Those
    slides are in traits_ui.ppt.
    say i have a list "control" that create using the following two lines:
    >
    class Project(HasTrai ts):
    coordinate_syst em=Enum('Cartes ian','Cylindric al')
    >
    I added the following line to get the option selected by the user:
    >
    def _coordinate_sys tem_changed(sel f,old,new):
    print 'System changed from %s to %s ' %(old,new)
    >
    but it does not return what the user select. It should return either 0
    or 1 based on the two choices, but i can't seem to find a way to trap
    that.
    The way that this works is that _coordinate_sys tem_changed() gets
    called with the old value and the new value of self.coordinate _system.
    Thus, it doesn't "return" anything; your method is a "handler" method
    that gets called when the value of a particular trait gets changed.

    Why do you say it should return 0 or 1? Do you mean that you want to
    get the index into the list of enumeration choices? The Enum trait
    type is not quite like C in this regard. In C/C++, enums are really
    ints; in traits, enums are lists of values of possibly mixed type.
    I am relatively new to this GUI programming in Python and really could
    use some tips/hints.
    No problem, hope the above helped. You might want to email your
    questions to envisage-dev@enthought.c om (and subscribe to it!). That
    is the primary mailing list for several enthought libraries (including
    traits) and you'll get very speedy, in-depth answers to your questions
    there.


    -Peter

    Comment

    • Ash

      #3
      Re: Enthought python - Traits

      Thanks Peter .. I will check out the mailing list. In the meanwhile - i
      have made some progress. Now working out - how to get a button_fired
      event to actually return the values ..

      It's a process (as always..)

      Cheers,

      -A


      Peter Wang wrote:
      Ash wrote:
      Hello everyone !

      I am trying to find some sort of a cookbook or more examples for using
      Enthought Traits to build GUI's. I tried to follow the documentations
      present at the enthought site, but couldnt get too far - especially on
      how to handle a control event ?
      >
      The traits manual is in the lib/site-packages/enthought/traits/doc
      directory, named Traits2_UM.doc/.pdf. The traits UI manual/user guide
      is also in there. However, what is not so obvious is that there is
      also an excellent, massive set of powerpoint slides (121 pages) that
      Dave Morrill put together that talks about the architecture of Traits
      UI, and how to build GUIs using it. (Er, how to build them *well*,
      i.e. adhering to the M-V-C pattern and maximizing code reuse.) Those
      slides are in traits_ui.ppt.
      >
      say i have a list "control" that create using the following two lines:

      class Project(HasTrai ts):
      coordinate_syst em=Enum('Cartes ian','Cylindric al')

      I added the following line to get the option selected by the user:

      def _coordinate_sys tem_changed(sel f,old,new):
      print 'System changed from %s to %s ' %(old,new)

      but it does not return what the user select. It should return either 0
      or 1 based on the two choices, but i can't seem to find a way to trap
      that.
      >
      The way that this works is that _coordinate_sys tem_changed() gets
      called with the old value and the new value of self.coordinate _system.
      Thus, it doesn't "return" anything; your method is a "handler" method
      that gets called when the value of a particular trait gets changed.
      >
      Why do you say it should return 0 or 1? Do you mean that you want to
      get the index into the list of enumeration choices? The Enum trait
      type is not quite like C in this regard. In C/C++, enums are really
      ints; in traits, enums are lists of values of possibly mixed type.
      >
      I am relatively new to this GUI programming in Python and really could
      use some tips/hints.
      >
      No problem, hope the above helped. You might want to email your
      questions to envisage-dev@enthought.c om (and subscribe to it!). That
      is the primary mailing list for several enthought libraries (including
      traits) and you'll get very speedy, in-depth answers to your questions
      there.
      >
      >
      -Peter

      Comment

      Working...