Rick Muller | 9 Feb 18:53
Picon

Help with Traits Enum types

Thanks for Traits; I'm just learning it, but have been having a lot of fun thus far.

One thing that I haven't figured out how to do is to set the default value of an Enum type, when I want it to be something other than the first value.

choice = Enum(1,2,3,default=2)

or something. How can I do this?

Thanks,

Rick


--
Rick Muller
rpmuller-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
505-750-7557

_______________________________________________
Enthought-Dev mailing list
Enthought-Dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
sylvain roy | 9 Feb 16:51
Picon

More on: How to dispose of a GUI

Dear all,

I posted a request yesterday and was able to partially solve the problem.
Let me explain what the problem is. 

A main GUI (GUI #1) is displayed with a single button. When the user 
pushes the button, another GUI (GUI #2) appears with a Save button on it. When the user 
presses the Save button, a dialog box appears and prompts the user to select a file to be saved. 
When the user presses Save on the dialog box, the dialog box disappears of the screen as it should. Is 
there a way that GUI #2 disappears as well?

I include below an example. Notice that I partially solve the problem by adding "info.ui.dispose()"
in the handler. Unfortunately, this is not satisfactory for me. The problem is that once GUI #2 is gone, 
there is no trace of its attributes. To see that, I include in the example two print statements: 
(1) print 'a', filename #(inside GUI #2)
(2) print 'b', filename #(inside GUI #1, after disposing of GUI #2)

Have a look at the example:

from enthought.traits.api import HasTraits, Button, Str
from enthought.pyface.api import FileDialog, OK
from enthought.traits.ui.api import View, Item, Handler
from enthought.traits.ui.menu import Action

class UI_Handler(Handler):
    def save(self, info):
        """ Save location info to location file and load the location info """
        info.object.save()
        info.ui.dispose()

class MainClass(HasTraits):

    myButton = Button(label = 'My Button',
        height_padding = 30,
        orientation = 'horizontal')  

    traits_view = View(Item('myButton', show_label=False, style='custom'))

    def __init__(self, **traits):
        super(MainClass, self).__init__(**traits) 

    def _myButton_fired(self):
        sc = SubClass()
        print 'b', sc.filename

    
class SubClass(HasTraits):

    saveButton = Action(name='Save',action='save')
    filename = Str

    traits_view = View(
                       handler = UI_Handler(),
                       buttons=[saveButton],
                       resizable = True,
                       kind = 'modal')

    def __init__(self, **traits):
        super(SubClass, self).__init__(**traits) 
        self.configure_traits()

    def save(self):
        dialog = FileDialog(title='Save File',
                action='save as')
        if dialog.open() == OK:
            self.filename = dialog.path
            print 'a', self.filename

if __name__ == "__main__":
    main_object = MainClass()
    main_object.configure_traits()

Regards,
Sylvain
Kasper Kærgaard | 9 Feb 11:38
Picon

MayaVi: Problems exporting figures with large resolution using mlab.savefig

Hi All.

I have problems with mlab.savefig(). Everything works fine when exporting using the screen resolution, but when I try to increase the resolution using size=() or magnification=XX the exported image is not right. I have attatched the correct image and a distorted one.
Any ideas are welcome.

Regards Kasper



_______________________________________________
Enthought-Dev mailing list
Enthought-Dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
jos mih | 9 Feb 10:34
Picon

Problem with imshow in version 3.2.0

Hi,
I'm having some trouble with the adjustment of the extent of imshow. I would like to scale the image, but this
doesn't work:

imshow(s,extent=[0,255,0,255,80,80])

this leads to following error:
  File "/usr/lib/python2.6/dist-packages/enthought/mayavi/tools/helper_functions.py", line 32,
in the_function
    return pipeline(*args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/enthought/mayavi/tools/helper_functions.py", line 69,
in __call__
    return self.build_pipeline()
  File "/usr/lib/python2.6/dist-packages/enthought/mayavi/tools/helper_functions.py", line 97,
in build_pipeline
    object = pipe(object, **this_kwargs)._target
  File "/usr/lib/python2.6/dist-packages/enthought/mayavi/tools/modules.py", line 149, in __init__
    super(DataModuleFactory, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/enthought/mayavi/tools/pipe_base.py", line 150, in __init__
    self.set(**traits)
  File "/usr/lib/python2.6/dist-packages/enthought/mayavi/tools/pipe_base.py", line 166, in set
    callback()
  File "/usr/lib/python2.6/dist-packages/enthought/mayavi/tools/modules.py", line 91, in _extent_changed
    tools.set_extent(self._target, self.extent)
  File "/usr/lib/python2.6/dist-packages/enthought/mayavi/tools/tools.py", line 270, in set_extent
    xmin, xmax, ymin, ymax, zmin, zmax = module.actor.actor.bounds
AttributeError: 'ImageActor' object has no attribute 'actor'

if anybody has a clue where the problem is, i would be grateful to let me know.

--

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
Otrek Wilke | 9 Feb 08:46
Picon
Picon

{Mayavi} Howto change colormap from within python script

Hello Everybody!

I'm quite new to mayavi, so please make allowance with me if my question is kind of stupid, but right now i just
don't get it.

Anyways here's my problem:

I have a data set, stored in IJ ordered array, with x,y,z and scalar values in separate arrays.
I plot them using mlab:
mlab.mesh(x,y,z,colormap="blue-red",figure=one,scalars=u)

Further i've found that i can show the colorbar via:
mlab.scalarbar(title='Velocity u',orientation='vertical',nb_labels=11)

So far so good :)

Now here comes my problem:
I want to change the maximum and the minimum color of the scalarbar. Like: it should have the boundary values
[0.0 to 1.0] instead of [-0.05 to 1.135]
I found a way to do it via the gui, but i want to do it from within my python script.

I hope it's clear what i wanna do, any help is welcome :)
If this is the wrong board, I would be glad for directions to a proper one

Thanks and best regards
Otrek

--

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
sylvain roy | 9 Feb 00:03
Picon

How to dispose of a GUI

Dear all,

A main GUI (GUI #1) is displayed with a single button. When the user 
pushes the button,
another GUI (GUI #2) appears with a Save button on it. When the user 
presses the Save button,
a dialog box appears and prompt the user to select a file to be save. 
When the user presses Save on
the dialog box, the dialog box disappears of the screen as it should. Is 
there a way that GUI #2 disappears as well?

I include below an example. I would appreciate if someone can help me to 
complete this piece of code.

from enthought.traits.api import HasTraits, Button
from enthought.pyface.api import FileDialog, OK
from enthought.traits.ui.api import View, Item, Handler
from enthought.traits.ui.menu import Action

class UI_Handler(Handler):
    def save(self, info):
        info.object.save()

class MainClass(HasTraits):

    myButton = Button(label = 'My Button',
        height_padding = 30,
        orientation = 'horizontal') 

    traits_view = View(Item('myButton', show_label=False, style='custom'))

    def __init__(self, **traits):
        super(MainClass, self).__init__(**traits)

    def _myButton_fired(self):
        SubClass()

   
class SubClass(HasTraits):

    saveButton = Action(name='Save',action='save')

    traits_view = View(
                       handler = UI_Handler(),
                       buttons=[saveButton],
                       resizable = True,
                       kind = 'modal')

    def __init__(self, **traits):
        super(SubClass, self).__init__(**traits)
        self.configure_traits()

    def save(self):
        dialog = FileDialog(title='Save File',
                action='save as')
        if dialog.open() == OK:
            print 'Hello World'

if __name__ == "__main__":
    main_object = MainClass()
    main_object.configure_traits()
fredrikostlund | 8 Feb 12:32
Picon
Favicon

Forcing a new layout pass

Hi,

I have some problems with the layout system. Below is an example. Clicking 
the button changes the maximum value of the slider. All works fine, except 
that the new maximum label (100000) is too wide to fit in its allocated 
space. If one resizes the window a new layout pass is forced, giving the 
100000 label enough space. Is there any nice way of forcing such a update 
programmatically?

Fred

from enthought.traits.api import *
from enthought.traits.ui.api import *

class C(HasTraits):
    min_val = Int()
    max_val = Int(10)
    i = Int(0)

    b = Button('Change max')

    def _b_fired(self):
        self.max_val = 100000

    view = View(
        Item('i', editor=RangeEditor(low_name='min_val', 
high_name='max_val', mode='slider')),
        UItem('b'),
        resizable=True
    )

c = C()
c.configure_traits() 
Brennan Williams | 8 Feb 05:54

Undock option for tabbed group

I've notice there is an "Undock" option if I right click on a tab in a 
view but it is greyed out. Is there an example somewhere of how to 
enable this so a tab can be undocked to be in its own window?

I looked in the TraitsGUI_3.1.1/examples/dock directory but the examples 
all have UnDock greyed out.

BTW just upgraded my Dell notebook to Windows 7 Home Premium and 
installed EPD 6.0.4 and everything is working well. I'm going to retire 
my Vista partition.....and maybe replace it with Linux - I presume I 
should go for Ubuntu rather than Fedora given the preference for Ubuntu 
on the mailing list.?

Brennan
Gael Varoquaux | 7 Feb 11:01
Favicon

Problem with trac

I am not sure what is going on, but if I go to:
https://svn.enthought.com/enthought/log/, I get:

--------------------------------------------------------------------------------
Trac Error

TracError: The Trac Environment needs to be upgraded.

Run "trac-admin /srv/trac/enthought upgrade"
--------------------------------------------------------------------------------

Gaël
Gökhan Sever | 6 Feb 23:37
Picon
Gravatar

{Mayavi} Random points in a cube

Hello,

Any ideas why I can't change color of the points?

I[1]: from enthought.mayavi import mlab

I[2]: r = np.random.uniform(0,5,size=[3,1,300])

I[3]: mlab.points3d(r[0],r[1],r[2], scale_factor=0.5)
O[3]: <enthought.mayavi.modules.glyph.Glyph object at 0xc48774c>

I[4]: ---------------------------------------------------------------------------
TraitError                                Traceback (most recent call last)

/home/gsever/Desktop/python-repo/ETS_3.3.1/TraitsBackendWX_3.2.1/enthought/traits/ui/wx/color_editor.pyc in color_selected(self, event)
    140         color = event.GetColour()
    141         try:
--> 142             self.value = color
    143         except ValueError:
    144             pass

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc in _set_value(self, value)
    240     def _set_value ( self, value ):
    241         if self.name != 'None':
--> 242             self.ui.do_undoable( self.__set_value, value )
    243
    244     def __set_value ( self, value ):

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/ui.pyc in do_undoable(self, action, *args, **kw)
    707                 self._undoable = self.history.now
    708
--> 709             action( *args, **kw )
    710         finally:
    711             if undoable == -1:

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc in __set_value(self, value)
    253                             getattr( handler, '%s_setattr' % name, None ) or
    254                             getattr( handler, 'setattr' ))
--> 255                 method( self.ui.info, self.object, name, value )
    256             except TraitError, excp:
    257                 self.error( excp )

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/handler.pyc in setattr(self, info, object, name, value)
    274
    275         """
--> 276         setattr( object, name, value )
    277
    278     #---------------------------------------------------------------------------


/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/trait_handlers.pyc in error(self, object, name, value)
    173         """
    174         raise TraitError( object, name, self.full_info( object, name, value ),
--> 175                           value )
    176
    177     def arg_error ( self, method, arg_num, object, name, value ):

TraitError: The 'color' trait of a CameraLight instance must be a tuple of the form: (0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0), but a value of wx.Colour(226, 37, 37, 255) <class 'wx._gdi.Colour'> was specified.


Trying to set the foreground via the GUI yields similar result:

TraitError: The 'foreground' trait of a MayaviScene instance must be a tuple of the form: (0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0), but a value of wx.Colour(255, 255, 255, 255) <class 'wx._gdi.Colour'> was specified.

Should be rev_25196
https://svn.enthought.com/svn/enthought/Mayavi/trunk

This is Fedora 12
Linux ccn 2.6.31.9-174.fc12.i686.PAE #1 SMP Mon Dec 21 06:04:56 UTC 2009 i686 i686 i386 GNU/Linux

Thanks

--
Gökhan

_______________________________________________
Enthought-Dev mailing list
Enthought-Dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
Chris Kennedy | 6 Feb 04:28
Favicon

format_str in Item() affects subsequent Item()s in UI

hi,
Using the format_str in an Item() definition to format the string 
presentation, such as here:
Item( 'string_trait', style = 'text',     label = 'Text', format_str = 
"%.6s" ),

causes the Item() to have the format applied, but also every subsequent 
Str trait is affected by this format_str.

I don't know if that is the intent, but it doesn't seem right.

here's an example (based on texteditor demo):

from enthought.traits.api \
    import HasTraits, Str, Int, Password

from enthought.traits.ui.api \
    import Item, Group, View

# The main demo class:
class TextEditorDemo ( HasTraits ):
    """ Defines the TextEditor demo class.
    """

    # Define a trait for each of three TextEditor variants:
    string_trait = Str( "sample string" )
    another_string_trait = Str( "more than 6 characters" )

    # TextEditor display with multi-line capability (for various traits):
    text_str_group = Group(
        Item( 'string_trait', style = 'simple',  label = 'Simple' ),
        Item( '_' ),
        Item( 'string_trait', style = 'text',     label = 'Text', 
format_str = "%.6s" ),
        Item( '_' ),
        Item( 'string_trait', style = 'readonly', label = 'ReadOnly' ),
        Item( '_' ),
        Item( '_' ),
        Item( 'another_string_trait', style = 'simple',  label = 
'Simple' ),
        Item( '_' ),
        Item( 'another_string_trait', style = 'text',     label = 'Text' ),
        Item( '_' ),
        Item( 'another_string_trait', style = 'readonly', label = 
'ReadOnly' ),
        label = 'String'
    )

    # The view includes one group per data type. These will be displayed
    # on separate tabbed panels:
    view = View(
        text_str_group,
        title   = 'TextEditor',
        buttons = [ 'OK' ]
    )

# Create the demo:
demo =  TextEditorDemo()

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

Thanks

--

-- 
Chris Kennedy                  
Apex, NC  
http://www.quickactiondrumlug.com
http://www.thinkpeak.com

Gmane