Re: [Envisage-dev] The road to Traits 2 (part 3)
>>>>> "DM" == David C Morrill <dmorrill@...> writes:
[...]
DM> End of week summary:
[...]
There are a few trivial bugs I spotted and have changed locally.
Attached at the end are the diffs. I'd rather not check them in since
you might have uncommitted changes that I don't want to mess up.
I know you still need to test a whole bunch of things but I jumped the
gun and played with a few things. Here are some comments.
In ui/toolkits.py::toolkit you have this defined:
48 for toolkit_name in toolkits:
49 try:
50 package = 'enthought.traits.ui.' + toolkit_name
51 module = __import__( package )
52 _toolkit = getattr( module.traits.ui, toolkit_name ).toolkit
53 return _toolkit
54 except:
55 pass
56 else:
57 raise TraitError, ("Could not find any UI toolkit called: %s" %
58 ', '.join( toolkits ))
The catch-all except befuddles error handling and its hard to figure
out why the import failed. I think it is a better idea to use an
'except ImportError' there.
Earlier, read-only properties would be ignored when one called
edit_traits. This is not the case anymore. For example::
In [8]: class A(HasTraits):
...: a = Trait('a', {'a':1, 'b':2})
...: def _get_b(self):
...: return 'b'
...: b = Property(_get_b)
...:
In [9]: a = A()
In [10]: a.edit_traits()
[snipped looong traceback ending with ]
/home/prabhu/stuff/python/modules/enthought/traits/ui/wx/ui_panel.py in add_items(self, content)
312
313 # Create the requested type of editor from the editor factory:
--> 314 factory_method = getattr( editor_factory, item.style + '_editor' )
315 editor = factory_method( ui, object, name, desc, panel )
316
AttributeError: 'NoneType' object has no attribute 'simple_editor'
Of course, if __editable_traits__ is set to ['a'], we are golden. But
this used to work earlier.
So with these small changes, the GUI editors seem to work (atleast
they popup cleanly!).
I assume that the new UI stuff is documented in the
traits2_ui_proposal. I haven't had a chance to read that yet, but
will do so soon. Is there any other documentation that you'd
recommend I read to use the new traits2 UI design effectively?
Thanks!
cheers,
prabhu
# --------------- DIFFS ------------------------------------------------
$ svn diff ui/toolkit.py ui/wx/constants.py
Index: ui/toolkit.py
===================================================================
--- ui/toolkit.py (revision 1757)
+++ ui/toolkit.py (working copy)
<at> <at> -17,7 +17,7 <at> <at>
# Imports:
#-------------------------------------------------------------------------------
-from enthought.traits import HasTraits, HasPrivateTraits
+from enthought.traits import HasTraits, HasPrivateTraits, TraitError
from ui_traits import SequenceTypes
#-------------------------------------------------------------------------------
Index: ui/wx/constants.py
===================================================================
--- ui/wx/constants.py (revision 1757)
+++ ui/wx/constants.py (working copy)
<at> <at> -37,7 +37,10 <at> <at>
standard_bitmap_width = 120
# Width of a scrollbar:
-scrollbar_dx = wx.SystemSettings_GetSystemMetric( wx.SYS_VSCROLL_X )
+try:
+ scrollbar_dx = wx.SystemSettings_GetSystemMetric( wx.SYS_VSCROLL_X )
+except AttributeError:
+ scrollbar_dx = wx.SystemSettings_GetMetric( wx.SYS_VSCROLL_X )
# Screen size:
screen_dx = wx.SystemSettings_GetMetric( wx.SYS_SCREEN_X )