how to pass values in to set a trait in a gui

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

how to pass values in to set a trait in a gui

Simon Hook
Hi,

I have a trait widget in which I want to have a integer slider. The
limits of the slider are set when the widget is first initialized. There
is a partial example under the traits documentation at:

http://github.enthought.com/traits/traits_user_manual/advanced.html#dynamic-initialization

However, when I try and add the slider to my view all I get is the
address of an object. This should be done all the time so I am sure it
is possible. Any help much appreciated.

thanks, Simon

Here is my code:

#! /usr/bin/env python
"""
Implementation of the settings class
"""

from enthought.traits.api import HasTraits, Button, CFloat, Trait, Enum,
Range, Int
from enthought.traits.ui.api import Item, View, Group, Handler
from enthought.traits.ui.message import message
from enthought.traits.api import HasTraits, Str, File
from enthought.traits.api import HasTraits, Range

class GUISlider (HasTraits):

    def __init__(self, eval=None, label='Value',
                 trait=None, min=0.0, max=1.0,
                 initial=None, **traits):
        HasTraits.__init__(self, **traits)
        if trait is None:
            if min > max:
                min, max = max, min
            if initial is None:
                initial = min
            elif not (min <= initial <= max):
                initial = [min, max][
                            abs(initial - min) >
                            abs(initial - max)]
            trait = Range(min, max, value = initial)
        self.add_trait(label, trait)
           
       
    settings_group = Group(
        Item('trait', style = 'simple')
    )  

    # The view includes one group per data type. These will be displayed
    # on separate tabbed panels:
    view = View(
        settings_group,
        title   = 'test',
        width = 450,
        buttons = ['OK', 'Cancel', 'Help' ],
        kind = 'modal',
    )
       
# Create the demo:
test_popup = GUISlider(trait=Int, label='zzz', min=0, max=1)

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
    test_popup.configure_traits()
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: how to pass values in to set a trait in a gui

bryce hendrix-2
Simon,

You should declare the trait outside of the __init__, but I'm assuming you're uding add_trait for a good reason... The real issue is the Item() needs to have the name of the label you pass in to the constructor, not 'trait'. I suggest using a method with returns the View instead, which will give you greater control at runtime.

Bryce

On Mon, Feb 21, 2011 at 6:38 PM, Simon Hook <[hidden email]> wrote:
Hi,

I have a trait widget in which I want to have a integer slider. The
limits of the slider are set when the widget is first initialized. There
is a partial example under the traits documentation at:

http://github.enthought.com/traits/traits_user_manual/advanced.html#dynamic-initialization

However, when I try and add the slider to my view all I get is the
address of an object. This should be done all the time so I am sure it
is possible. Any help much appreciated.

thanks, Simon

Here is my code:

#! /usr/bin/env python
"""
Implementation of the settings class
"""

from enthought.traits.api import HasTraits, Button, CFloat, Trait, Enum,
Range, Int
from enthought.traits.ui.api import Item, View, Group, Handler
from enthought.traits.ui.message import message
from enthought.traits.api import HasTraits, Str, File
from enthought.traits.api import HasTraits, Range

class GUISlider (HasTraits):

   def __init__(self, eval=None, label='Value',
                trait=None, min=0.0, max=1.0,
                initial=None, **traits):
       HasTraits.__init__(self, **traits)
       if trait is None:
           if min > max:
               min, max = max, min
           if initial is None:
               initial = min
           elif not (min <= initial <= max):
               initial = [min, max][
                           abs(initial - min) >
                           abs(initial - max)]
           trait = Range(min, max, value = initial)
       self.add_trait(label, trait)


   settings_group = Group(
       Item('trait', style = 'simple')
   )

   # The view includes one group per data type. These will be displayed
   # on separate tabbed panels:
   view = View(
       settings_group,
       title   = 'test',
       width = 450,
       buttons = ['OK', 'Cancel', 'Help' ],
       kind = 'modal',
   )

# Create the demo:
test_popup = GUISlider(trait=Int, label='zzz', min=0, max=1)

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
   test_popup.configure_traits()
_______________________________________________
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: how to pass values in to set a trait in a gui

Simon Hook
Hi Bryce,

I have tried that or something like that and it did not work. I have
re-worked my example to try and make it more obvious what the problem
is. As you can see I am setting the range of the slider to 1 and 64 and
the label to 'thelabel'. Now when I use the init why doesn't the label
get set to 'zzz'. In other words when I call the widget I want to tell
it what to use for the label and max and min of the slider but it seems
like these have to be hard coded which I am sure is not the case. I am
using the label as an example but also want to set the min and max of
the slider.

thanks, Simon

#! /usr/bin/env python
"""
Implementation of the settings class
"""

from enthought.traits.api import HasTraits, Button, CFloat, Trait, Enum,
Range, Int
from enthought.traits.ui.api import Item, View, Group, Handler
from enthought.traits.ui.message import message
from enthought.traits.api import HasTraits, Str, File
from enthought.traits.api import HasTraits, Range

class GUISlider (HasTraits):

    theslider = Range(value=1, low=1, high=64, desc="How do you set the
range on the fly!")
    mylabel = 'thelabel'
   
    def __init__(self, label='Value', **traits):
        HasTraits.__init__(self, **traits)
        self.mylabel = label
           
    settings_group = Group(
        Item( 'theslider', style = 'simple',   label = mylabel )
    )  

    # The view includes one group per data type. These will be displayed
    # on separate tabbed panels:
    view = View(
        settings_group,
        title   = 'test',
        width = 450,
        buttons = ['OK', 'Cancel', 'Help' ],
        kind = 'modal',
    )
       
# Create the demo:
test_popup = GUISlider(label='zzz')

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
    test_popup.configure_traits()

bryce hendrix wrote:

> Simon,
>
> You should declare the trait outside of the __init__, but I'm assuming
> you're uding add_trait for a good reason... The real issue is the
> Item() needs to have the name of the label you pass in to the
> constructor, not 'trait'. I suggest using a method with returns the
> View instead, which will give you greater control at runtime.
>
> Bryce
>
> On Mon, Feb 21, 2011 at 6:38 PM, Simon Hook <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi,
>
>     I have a trait widget in which I want to have a integer slider. The
>     limits of the slider are set when the widget is first initialized.
>     There
>     is a partial example under the traits documentation at:
>
>     http://github.enthought.com/traits/traits_user_manual/advanced.html#dynamic-initialization
>
>     However, when I try and add the slider to my view all I get is the
>     address of an object. This should be done all the time so I am sure it
>     is possible. Any help much appreciated.
>
>     thanks, Simon
>
>     Here is my code:
>
>     #! /usr/bin/env python
>     """
>     Implementation of the settings class
>     """
>
>     from enthought.traits.api import HasTraits, Button, CFloat, Trait,
>     Enum,
>     Range, Int
>     from enthought.traits.ui.api import Item, View, Group, Handler
>     from enthought.traits.ui.message import message
>     from enthought.traits.api import HasTraits, Str, File
>     from enthought.traits.api import HasTraits, Range
>
>     class GUISlider (HasTraits):
>
>        def __init__(self, eval=None, label='Value',
>                     trait=None, min=0.0, max=1.0,
>                     initial=None, **traits):
>            HasTraits.__init__(self, **traits)
>            if trait is None:
>                if min > max:
>                    min, max = max, min
>                if initial is None:
>                    initial = min
>                elif not (min <= initial <= max):
>                    initial = [min, max][
>                                abs(initial - min) >
>                                abs(initial - max)]
>                trait = Range(min, max, value = initial)
>            self.add_trait(label, trait)
>
>
>        settings_group = Group(
>            Item('trait', style = 'simple')
>        )
>
>        # The view includes one group per data type. These will be
>     displayed
>        # on separate tabbed panels:
>        view = View(
>            settings_group,
>            title   = 'test',
>            width = 450,
>            buttons = ['OK', 'Cancel', 'Help' ],
>            kind = 'modal',
>        )
>
>     # Create the demo:
>     test_popup = GUISlider(trait=Int, label='zzz', min=0, max=1)
>
>     # Run the demo (if invoked from the command line):
>     if __name__ == '__main__':
>        test_popup.configure_traits()
>     _______________________________________________
>     Enthought-Dev mailing list
>     [hidden email]
>     <mailto:[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: how to pass values in to set a trait in a gui

German Salazar
I used traits once before and seem to recall trying something like this...and it did not work.

I vaguely remember a couple of things:
I think the label field truly needs to be a static string, period;
but, I think you can come back after the view has been built
and rename such attribute (the label) but you need to know
how to get to it

...somebody will come along and give the answer (again), I am sure,
I think I got it back then but decided not to go about it that way...
possibly about having to create a handler and dealing directly
with the info.ui object or something like that...

gsal



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

Re: how to pass values in to set a trait in a gui

Chris Colbert

You can change the limits of a range trait on the fly with other traits:


class Foo(HasTraits):
     low = Int(5)
     high = Int(10)
     my_range = Range(low='low', high='high')

     view = View(Item('low'), Item('high'), Item('my_range'))


f = Foo(low=16, high=28)
f.configure_traits()

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

Re: how to pass values in to set a trait in a gui

Simon Hook
Hi Chris,

Thanks, that works great for the range but does not work with the label
for the slider. Do you know how to make it work with the label for the
slider. I have attached my code to illustrate the problem.

thanks, Simon

#! /usr/bin/env python
"""
Demo of how to specify ranges and label of a slider when create
"""

from enthought.traits.api import HasTraits, Button, Range, Int, Str
from enthought.traits.ui.api import Item, View, Group
from enthought.traits.ui.message import message

class GUISlider (HasTraits):

    mylow = Int(5)
    myhigh = Int(10)
    mylabel = Str('123')
    theslider = Range(value=1, low='mylow', high='myhigh',
label='mylabel', desc="How do you set the range on the fly!")
   
    settings_group = Group(
       
        Item('theslider', style = 'simple')
    )  

    # The view includes one group per data type. These will be displayed
    # on separate tabbed panels:
    view = View(
        settings_group,
        title   = 'test',
        width = 450,
        buttons = ['OK', 'Cancel', 'Help' ],
        kind = 'modal',
    )
       
# Create the demo:
test_popup = GUISlider(mylow=5, myhigh=10, mylabel='zLabel')

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
    test_popup.configure_traits()


Chris Colbert wrote:

>
> You can change the limits of a range trait on the fly with other traits:
>
>
> class Foo(HasTraits):
>      low = Int(5)
>      high = Int(10)
>      my_range = Range(low='low', high='high')
>
>      view = View(Item('low'), Item('high'), Item('my_range'))
>
>
> f = Foo(low=16, high=28)
> f.configure_traits()
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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: how to pass values in to set a trait in a gui

Corran Webster
Hi Simon,

the label of an Item is not live (for any type of Item), but can be set on the fly in two ways:

1) if you don't need to change the label while the user is editing the item, you can simply use a trait_view() method to construct the view each time you need it.  This looks something like:

class GUISlider(HasTraits):

   mylow = Int(5)
   myhigh = Int(10)
   mylabel = Str('123')
   theslider = Range(value=1, low='mylow', high='myhigh')

   def trait_view(self):
      return
View(
         Group(
            Item('theslider', label=self.mylabel),
         ),

         title   = 'test',
         width = 450,
         buttons = ['OK', 'Cancel', 'Help' ],
         kind = 'modal',
      )

2) The other option you have is to use a Label item.  This will depend on the mylabel object completely dynamically.  This looks something like:

class GUISlider(HasTraits):

   mylow = Int(5)
   myhigh = Int(10)
   mylabel = Str('123')
   theslider = Range(value=1, low='mylow', high='myhigh')

   view = View(
      Group(
         HGroup(
            Label('mylabel'),
            Item('theslider', show_label=False),
         )
      ),

      title   = 'test',
      width = 450,
      buttons = ['OK', 'Cancel', 'Help' ],
      kind = 'modal',
   )

Note - I haven't tested this code, so there may be typos, but this should hopefully get you onto the right track.

-- Corran

On Tue, Feb 22, 2011 at 4:21 PM, Simon Hook <[hidden email]> wrote:
Hi Chris,

Thanks, that works great for the range but does not work with the label
for the slider. Do you know how to make it work with the label for the
slider. I have attached my code to illustrate the problem.

thanks, Simon

#! /usr/bin/env python
"""
Demo of how to specify ranges and label of a slider when create
"""

from enthought.traits.api import HasTraits, Button, Range, Int, Str
from enthought.traits.ui.api import Item, View, Group
from enthought.traits.ui.message import message

class GUISlider (HasTraits):

   mylow = Int(5)
   myhigh = Int(10)
   mylabel = Str('123')
   theslider = Range(value=1, low='mylow', high='myhigh',
label='mylabel', desc="How do you set the range on the fly!")

   settings_group = Group(

       Item('theslider', style = 'simple')
   )

   # The view includes one group per data type. These will be displayed
   # on separate tabbed panels:
   view = View(
       settings_group,
       title   = 'test',
       width = 450,
       buttons = ['OK', 'Cancel', 'Help' ],
       kind = 'modal',
   )

# Create the demo:
test_popup = GUISlider(mylow=5, myhigh=10, mylabel='zLabel')

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
   test_popup.configure_traits()


Chris Colbert wrote:
>
> You can change the limits of a range trait on the fly with other traits:
>
>
> class Foo(HasTraits):
>      low = Int(5)
>      high = Int(10)
>      my_range = Range(low='low', high='high')
>
>      view = View(Item('low'), Item('high'), Item('my_range'))
>
>
> f = Foo(low=16, high=28)
> f.configure_traits()
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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: how to pass values in to set a trait in a gui

Travis Vaught
Corran, I think that's close, but I really think you have to just use a UReadonly Item rather than a Label (the Label item is acting like a label and isn't dynamic).

You may have to fiddle with the sizing, however...

Code:
#############
#! /usr/bin/env python
"""
Demo of how to specify ranges and label of a slider when create
"""

from enthought.traits.api import HasTraits, Button, Range, Int, Str
from enthought.traits.ui.api import Item, View, HGroup, Group, Label, UReadonly
from enthought.traits.ui.message import message

class GUISlider(HasTraits):

   mylow = Int(5)
   myhigh = Int(10)
   mylabel = Str('123')
   theslider = Range(value=1, low='mylow', high='myhigh')

   view = View(
      Group(
         HGroup(
            UReadonly(value='mylabel'),
            Item('theslider', show_label=False),
         )
      ),
      title   = 'test',
      width = 450,
      buttons = ['OK', 'Cancel', 'Help' ],
      #kind = 'modal',
   )


# Create the demo:
test_popup = GUISlider(mylow=5, myhigh=10, mylabel='zLabel')

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
   test_popup.configure_traits()


#############

And screenshot:



On Feb 22, 2011, at 5:13 PM, Corran Webster wrote:

Hi Simon,

the label of an Item is not live (for any type of Item), but can be set on the fly in two ways:

1) if you don't need to change the label while the user is editing the item, you can simply use a trait_view() method to construct the view each time you need it.  This looks something like:

class GUISlider(HasTraits):

   mylow = Int(5)
   myhigh = Int(10)
   mylabel = Str('123')
   theslider = Range(value=1, low='mylow', high='myhigh')

   def trait_view(self):
      return
View(
         Group(
            Item('theslider', label=self.mylabel),
         ),

         title   = 'test',
         width = 450,
         buttons = ['OK', 'Cancel', 'Help' ],
         kind = 'modal',
      )

2) The other option you have is to use a Label item.  This will depend on the mylabel object completely dynamically.  This looks something like:

class GUISlider(HasTraits):

   mylow = Int(5)
   myhigh = Int(10)
   mylabel = Str('123')
   theslider = Range(value=1, low='mylow', high='myhigh')

   view = View(
      Group(
         HGroup(
            Label('mylabel'),
            Item('theslider', show_label=False),
         )
      ),

      title   = 'test',
      width = 450,
      buttons = ['OK', 'Cancel', 'Help' ],
      kind = 'modal',
   )

Note - I haven't tested this code, so there may be typos, but this should hopefully get you onto the right track.

-- Corran

On Tue, Feb 22, 2011 at 4:21 PM, Simon Hook <[hidden email]> wrote:
Hi Chris,

Thanks, that works great for the range but does not work with the label
for the slider. Do you know how to make it work with the label for the
slider. I have attached my code to illustrate the problem.

thanks, Simon

#! /usr/bin/env python
"""
Demo of how to specify ranges and label of a slider when create
"""

from enthought.traits.api import HasTraits, Button, Range, Int, Str
from enthought.traits.ui.api import Item, View, Group
from enthought.traits.ui.message import message

class GUISlider (HasTraits):

   mylow = Int(5)
   myhigh = Int(10)
   mylabel = Str('123')
   theslider = Range(value=1, low='mylow', high='myhigh',
label='mylabel', desc="How do you set the range on the fly!")

   settings_group = Group(

       Item('theslider', style = 'simple')
   )

   # The view includes one group per data type. These will be displayed
   # on separate tabbed panels:
   view = View(
       settings_group,
       title   = 'test',
       width = 450,
       buttons = ['OK', 'Cancel', 'Help' ],
       kind = 'modal',
   )

# Create the demo:
test_popup = GUISlider(mylow=5, myhigh=10, mylabel='zLabel')

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
   test_popup.configure_traits()


Chris Colbert wrote:
>
> You can change the limits of a range trait on the fly with other traits:
>
>
> class Foo(HasTraits):
>      low = Int(5)
>      high = Int(10)
>      my_range = Range(low='low', high='high')
>
>      view = View(Item('low'), Item('high'), Item('my_range'))
>
>
> f = Foo(low=16, high=28)
> f.configure_traits()
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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


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

Re: how to pass values in to set a trait in a gui

Simon Hook
Travis and Corran,

Thank you for your suggestions. Chris, your first option does not work
(self is not recognized), your second option does work but puts the
label on a different line. Travis' creation of a horizontal group solves
that problem but the slider no longer expands to fit the size of the
widget and the text is offset in the box. Unless there is another way
then it seems that Traits does not have a simple way to pass in a label
for a Range Trait -- it needs to be hard-coded. However, it is possible
to pass in the limits of a Range Trait which seems like a bit of a
mismatch to me, if you can do the limits then you should be able to do
the label.

thanks again, Simon

p.s. Here is the updated. It might be worth incl. this as an example, at
least in terms of changes the limits on a range -- I could not find one
in the traits examples although I am not used the latest EPD.

#! /usr/bin/env python
"""
Demo of how to specify ranges and label of a slider when create
"""

from enthought.traits.api import HasTraits, Button, Range, Int, Str
from enthought.traits.ui.api import Item, View, Group, Label, HGroup,
UReadonly
from enthought.traits.ui.message import message

class GUISlider (HasTraits):

    mylow = Int(5)
    myhigh = Int(10)
    mylabel = Str('123')
    theslider = Range(value=1, low='mylow', high='myhigh', desc="How to
set the range on the fly!")
   
    settings_group = Group(
         HGroup(
            UReadonly(value='mylabel'),
            Item('theslider', show_label=False )
        )
    )  

    # The view includes one group per data type. These will be displayed
    # on separate tabbed panels:
    view = View(
        settings_group,
        title   = 'test',
        width = 450,
        buttons = ['OK', 'Cancel', 'Help' ],
        kind = 'modal',
    )
       
# Create the demo:
test_popup = GUISlider(mylow=5, myhigh=10, mylabel='The Label    ')

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
    test_popup.configure_traits()

Travis Vaught wrote:

> Corran, I think that's close, but I really think you have to just use
> a UReadonly Item rather than a Label (the Label item is acting like a
> label and isn't dynamic).
>
> You may have to fiddle with the sizing, however...
>
> Code:
> #############
> #! /usr/bin/env python
> """
> Demo of how to specify ranges and label of a slider when create
> """
>
> from enthought.traits.api import HasTraits, Button, Range, Int, Str
> from enthought.traits.ui.api import Item, View, HGroup, Group, Label,
> UReadonly
> from enthought.traits.ui.message import message
>
> class GUISlider(HasTraits):
>
>    mylow = Int(5)
>    myhigh = Int(10)
>    mylabel = Str('123')
>    theslider = Range(value=1, low='mylow', high='myhigh')
>
>    view = View(
>       Group(
>          HGroup(
>             UReadonly(value='mylabel'),
>             Item('theslider', show_label=False),
>          )
>       ),
>       title   = 'test',
>       width = 450,
>       buttons = ['OK', 'Cancel', 'Help' ],
>       #kind = 'modal',
>    )
>
>
> # Create the demo:
> test_popup = GUISlider(mylow=5, myhigh=10, mylabel='zLabel')
>
> # Run the demo (if invoked from the command line):
> if __name__ == '__main__':
>    test_popup.configure_traits()
>
>
> #############
>
> And screenshot:
>
>
>
> On Feb 22, 2011, at 5:13 PM, Corran Webster wrote:
>
>> Hi Simon,
>>
>> the label of an Item is not live (for any type of Item), but can be
>> set on the fly in two ways:
>>
>> 1) if you don't need to change the label while the user is editing
>> the item, you can simply use a trait_view() method to construct the
>> view each time you need it.  This looks something like:
>>
>> class GUISlider(HasTraits):
>>
>>    mylow = Int(5)
>>    myhigh = Int(10)
>>    mylabel = Str('123')
>>    theslider = Range(value=1, low='mylow', high='myhigh')
>>
>>    def trait_view(self):
>>       return View(
>>          Group(
>>             Item('theslider', label=self.mylabel),
>>          ),
>>          title   = 'test',
>>          width = 450,
>>          buttons = ['OK', 'Cancel', 'Help' ],
>>          kind = 'modal',
>>       )
>>
>> 2) The other option you have is to use a Label item.  This will
>> depend on the mylabel object completely dynamically.  This looks
>> something like:
>>
>> class GUISlider(HasTraits):
>>
>>    mylow = Int(5)
>>    myhigh = Int(10)
>>    mylabel = Str('123')
>>    theslider = Range(value=1, low='mylow', high='myhigh')
>>
>>    view = View(
>>       Group(
>>          HGroup(
>>             Label('mylabel'),
>>             Item('theslider', show_label=False),
>>          )
>>       ),
>>       title   = 'test',
>>       width = 450,
>>       buttons = ['OK', 'Cancel', 'Help' ],
>>       kind = 'modal',
>>    )
>>
>> Note - I haven't tested this code, so there may be typos, but this
>> should hopefully get you onto the right track.
>>
>> -- Corran
>>
>> On Tue, Feb 22, 2011 at 4:21 PM, Simon Hook
>> <[hidden email] <mailto:[hidden email]>> wrote:
>>
>>     Hi Chris,
>>
>>     Thanks, that works great for the range but does not work with the
>>     label
>>     for the slider. Do you know how to make it work with the label
>>     for the
>>     slider. I have attached my code to illustrate the problem.
>>
>>     thanks, Simon
>>
>>     #! /usr/bin/env python
>>     """
>>     Demo of how to specify ranges and label of a slider when create
>>     """
>>
>>     from enthought.traits.api import HasTraits, Button, Range, Int, Str
>>     from enthought.traits.ui.api import Item, View, Group
>>     from enthought.traits.ui.message import message
>>
>>     class GUISlider (HasTraits):
>>
>>        mylow = Int(5)
>>        myhigh = Int(10)
>>        mylabel = Str('123')
>>        theslider = Range(value=1, low='mylow', high='myhigh',
>>     label='mylabel', desc="How do you set the range on the fly!")
>>
>>        settings_group = Group(
>>
>>            Item('theslider', style = 'simple')
>>        )
>>
>>        # The view includes one group per data type. These will be
>>     displayed
>>        # on separate tabbed panels:
>>        view = View(
>>            settings_group,
>>            title   = 'test',
>>            width = 450,
>>            buttons = ['OK', 'Cancel', 'Help' ],
>>            kind = 'modal',
>>        )
>>
>>     # Create the demo:
>>     test_popup = GUISlider(mylow=5, myhigh=10, mylabel='zLabel')
>>
>>     # Run the demo (if invoked from the command line):
>>     if __name__ == '__main__':
>>        test_popup.configure_traits()
>>
>>
>>     Chris Colbert wrote:
>>     >
>>     > You can change the limits of a range trait on the fly with
>>     other traits:
>>     >
>>     >
>>     > class Foo(HasTraits):
>>     >      low = Int(5)
>>     >      high = Int(10)
>>     >      my_range = Range(low='low', high='high')
>>     >
>>     >      view = View(Item('low'), Item('high'), Item('my_range'))
>>     >
>>     >
>>     > f = Foo(low=16, high=28)
>>     > f.configure_traits()
>>     >
>>     ------------------------------------------------------------------------
>>     >
>>     > _______________________________________________
>>     > Enthought-Dev mailing list
>>     > [hidden email]
>>     <mailto:[hidden email]>
>>     > https://mail.enthought.com/mailman/listinfo/enthought-dev
>>     >
>>     _______________________________________________
>>     Enthought-Dev mailing list
>>     [hidden email]
>>     <mailto:[hidden email]>
>>     https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> <mailto:[hidden email]>
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
> ------------------------------------------------------------------------
>
> This body part will be downloaded on demand.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev