chaco icon indicating copy to clipboard operation
chaco copied to clipboard

Calling edit_traits on ScatterPlot raises TypeError

Open achabotl opened this issue 8 years ago • 1 comments

Given the following example, running scatter.edit_traits() crashes with TypeError: object of type 'float' has no len() (see full traceback below), whereas line.edit_traits() works.

  • traits: '4.6.0'
  • traitsui: '5.1.0'
  • chaco: '4.6.0'
  • Python: '2.7.13 |Enthought, Inc. (x86_64)| (default, Mar 2 2017, 08:20:50) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]'
from chaco.api import ArrayPlotData, Plot
from enable.api import ComponentEditor
from traits.api import HasTraits, Instance
import numpy as np
from traitsui.api import Item, View


class ChacoPlot(HasTraits):
    my_plot = Instance(Plot)    

    _traits_view = View(
        Item('my_plot', editor=ComponentEditor(), show_label=False),
    )
    
    def _my_plot_default(self):
        x = np.arange(10)
        y = np.sin(x)
        p = Plot(ArrayPlotData(x=x, y=y))
        p.plot(('x', 'y'), type='scatter', name='scatter plot')
        p.plot(('x', 'y'), name='line plot')
        return p
        
if __name__ == "__main__":
    cp = ChacoPlot()
    cp.edit_traits()
    scatter = cp.my_plot.plots['scatter plot'][0]
    line = cp.my_plot.plots['line plot'][0]
>>> scatter.edit_traits()
TypeErrorTraceback (most recent call last)
<ipython-input-19-590fa09d9b39> in <module>()
----> 1 scatter.edit_traits()

/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traits/has_traits.pyc in edit_traits(self, view, parent, kind, context, handler, id, scrollable, **args)
   1869 
   1870         return view.ui( context, parent, kind, self.trait_view_elements(),
-> 1871                         handler, id, scrollable, args )
   1872 
   1873     #---------------------------------------------------------------------------
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/view.pyc in ui(self, context, parent, kind, view_elements, handler, id, scrollable, args)
    431             kind = self.kind
    432 
--> 433         ui.ui( parent, kind )
    434 
    435         return ui
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/ui.pyc in ui(self, parent, kind)
    219                                    dispatch = 'ui' )
    220         self.rebuild = getattr( toolkit(), 'ui_' + kind )
--> 221         self.rebuild( self, parent )
    222 
    223     #---------------------------------------------------------------------------
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/toolkit.pyc in ui_live(self, ui, parent)
    153         """
    154         import ui_live
--> 155         ui_live.ui_live( ui, parent )
    156 
    157     def ui_modal ( self, ui, parent ):
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/ui_live.pyc in ui_live(ui, parent)
     37     """Creates a live, non-modal PyQt user interface for a specified UI object.
     38     """
---> 39     _ui_dialog(ui, parent, BaseDialog.NONMODAL)
     40 
     41 def ui_livemodal(ui, parent):
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/ui_live.pyc in _ui_dialog(ui, parent, style)
     57         ui.owner = _LiveWindow()
     58 
---> 59     BaseDialog.display_ui(ui, parent, style)
     60 
     61 
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/ui_base.pyc in display_ui(ui, parent, style)
    480         """Display the UI."""
    481 
--> 482         ui.owner.init(ui, parent, style)
    483         ui.control = ui.owner.control
    484         ui.control._parent = parent
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/ui_live.pyc in init(self, ui, parent, style)
    175             bbox = None
    176 
--> 177         self.add_contents(panel(ui), bbox)
    178 
    179     def close(self, rc=True):
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/ui_panel.pyc in panel(ui)
    253         panel = None
    254     if nr_groups == 1:
--> 255         panel = _GroupPanel(content[0], ui).control
    256     elif nr_groups > 1:
    257         panel = QtGui.QTabWidget()
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/ui_panel.pyc in __init__(self, group, ui, suppress_label)
    590                 layout = self._add_groups(content, inner)
    591             else:
--> 592                 layout = self._add_items(content, inner)
    593             layout.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
    594 
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/ui_panel.pyc in _add_items(self, content, outer)
    858             # that it is not None (otherwise the main TraitsUI code can change
    859             # the "kind" of the created UI object).
--> 860             editor.prepare(inner)
    861             control = editor.control
    862 
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/editor.pyc in prepare(self, parent)
    154             self.context_object.on_trait_change( self._update_editor, name,
    155                                                  dispatch = 'ui' )
--> 156         self.init( parent )
    157         self._sync_values()
    158         self.update_editor()
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/qt4/compound_editor.pyc in init(self, parent)
     65             editor = getattr( factory, self.kind )( self.ui, self.object,
     66                                        self.name, self.description, None )
---> 67             editor.prepare(self.control)
     68             layout.addWidget(editor.control)
     69             editors.append(editor)
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/editor.pyc in prepare(self, parent)
    154             self.context_object.on_trait_change( self._update_editor, name,
    155                                                  dispatch = 'ui' )
--> 156         self.init( parent )
    157         self._sync_values()
    158         self.update_editor()
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/editors/tuple_editor.pyc in init(self, parent)
     92             widget.
     93         """
---> 94         self._ts     = ts = TupleStructure( self )
     95         self._ui     = ui = ts.view.ui( ts, parent, kind = 'subpanel' ).set(
     96                                         parent = self.ui )
/Users/achabot/Library/Enthought/Canopy/edm/envs/User/lib/python2.7/site-packages/traitsui/editors/tuple_editor.pyc in __init__(self, editor)
    161         # definition and default value:
    162         content     = []
--> 163         self.fields = len( object )
    164         len_labels  = len( labels )
    165         len_editors = len( editors )
TypeError: object of type 'float' has no len() 

achabotl avatar Apr 11 '17 16:04 achabotl

It's probably the marker_size trait, which is Either(Float, Array)

rkern avatar Apr 11 '17 17:04 rkern