I'm moving from EPD 6.2 to 7.2 on a 32-bit Windows 7 platform using wx.
I'm creating a view for an object (called a vector). It is of class RZVector. It can have an associated vector so I have the RZVector class has a trait called avector which is defined as an Instance("RZVector"). If the vector doesn't have an associated vector then avector=None Under Traits 3.x the following was ok... view=View( Item('object.avector.name',visible_when='avector'), etc.etc. ) This is actually in quite a complex view but basically it worked and I use visible_when='avector' quite a lot in the view. In Traits 4 (epd 7.2.2) the view is ok if there is an associated vector, i.e. avector is not None If a vector=None then I get the following error Traceback (most recent call last): File "c:\python27\lib\site-packages\traitsui\wx\tree_editor.py", line 1225, in _on_tree_sel_changed kind = 'subpanel' ) File "c:\python27\lib\site-packages\traits\has_traits.py", line 2266, in edit_traits handler, id, scrollable, args ) File "c:\python27\lib\site-packages\traitsui\view.py", line 433, in ui ui.ui( parent, kind ) File "c:\python27\lib\site-packages\traitsui\ui.py", line 218, in ui self.rebuild( self, parent ) File "c:\python27\lib\site-packages\traitsui\wx\toolkit.py", line 126, in ui_subpanel ui_panel.ui_subpanel( ui, parent ) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 100, in ui_subpanel ui_panel_for( ui, parent, False ) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 113, in ui_panel_for ui.control = control = Panel( ui, parent, buttons ).control File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 202, in __init__ sizer.Add( panel( ui, sw ), 1, wx.EXPAND ) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 349, in panel content[0], ui ) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 523, in fill_panel_for_group create_panel ) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 670, in __init__ self.add_groups( content, panel ) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 822, in add_groups fill_panel_for_group( panel, subgroup, self.ui ) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 523, in fill_panel_for_group create_panel ) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 672, in __init__ self.add_items(content, panel, self.sizer) File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line 975, in add_items trait = object.base_trait( name ) AttributeError: 'NoneType' object has no attribute 'base_trait' One final point. After I create my view, if I print it out there is no mention of visible_when. It looks like it is ignoring visible_when. Brennan _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
Brennan,
What you are seeing is the expected behavior with ETS 4, but it is also what I see in a simple example with EPD 6.2 (ETS 3), at least on OSX. Can you extract a simple example which works as you want in ETS 3 but not in ETS 4? Jonathan On Mon, Feb 13, 2012 at 3:56 AM, Brennan Williams < [hidden email]> wrote: > I'm moving from EPD 6.2 to 7.2 on a 32-bit Windows 7 platform using wx. > > I'm creating a view for an object (called a vector). It is of class > RZVector. > It can have an associated vector so I have the RZVector class has a > trait called avector which is defined as an Instance("RZVector"). > If the vector doesn't have an associated vector then avector=None > > Under Traits 3.x the following was ok... > > view=View( > Item('object.avector.name',visible_when='avector'), > etc.etc. > ) > > This is actually in quite a complex view but basically it worked and I > use visible_when='avector' quite a lot in the view. > > In Traits 4 (epd 7.2.2) the view is ok if there is an associated vector, > i.e. avector is not None > > If a vector=None then I get the following error > > Traceback (most recent call last): > File "c:\python27\lib\site-packages\traitsui\wx\tree_editor.py", line > 1225, in _on_tree_sel_changed > kind = 'subpanel' ) > File "c:\python27\lib\site-packages\traits\has_traits.py", line 2266, > in edit_traits > handler, id, scrollable, args ) > File "c:\python27\lib\site-packages\traitsui\view.py", line 433, in ui > ui.ui( parent, kind ) > File "c:\python27\lib\site-packages\traitsui\ui.py", line 218, in ui > self.rebuild( self, parent ) > File "c:\python27\lib\site-packages\traitsui\wx\toolkit.py", line > 126, in ui_subpanel > ui_panel.ui_subpanel( ui, parent ) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 100, in ui_subpanel > ui_panel_for( ui, parent, False ) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 113, in ui_panel_for > ui.control = control = Panel( ui, parent, buttons ).control > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 202, in __init__ > sizer.Add( panel( ui, sw ), 1, wx.EXPAND ) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 349, in panel > content[0], ui ) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 523, in fill_panel_for_group > create_panel ) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 670, in __init__ > self.add_groups( content, panel ) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 822, in add_groups > fill_panel_for_group( panel, subgroup, self.ui ) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 523, in fill_panel_for_group > create_panel ) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 672, in __init__ > self.add_items(content, panel, self.sizer) > File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line > 975, in add_items > trait = object.base_trait( name ) > AttributeError: 'NoneType' object has no attribute 'base_trait' > > One final point. After I create my view, if I print it out there is no > mention of visible_when. It looks like it is ignoring visible_when. > > Brennan > > > _______________________________________________ > 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 |
On 14/02/2012 6:54 a.m., Jonathan March wrote:
> Brennan, > > What you are seeing is the expected behavior with ETS 4, but it is also > what I see in a simple example with EPD 6.2 (ETS 3), at least on OSX. > > Can you extract a simple example which works as you want in ETS 3 but not > in ETS 4? See attached. I've left the imports as enthought. so it runs under both EPD 6.2 and 7.2 but in my own code I've switched to the new format. Brennan > Jonathan > > On Mon, Feb 13, 2012 at 3:56 AM, Brennan Williams< > [hidden email]> wrote: > >> I'm moving from EPD 6.2 to 7.2 on a 32-bit Windows 7 platform using wx. >> >> I'm creating a view for an object (called a vector). It is of class >> RZVector. >> It can have an associated vector so I have the RZVector class has a >> trait called avector which is defined as an Instance("RZVector"). >> If the vector doesn't have an associated vector then avector=None >> >> Under Traits 3.x the following was ok... >> >> view=View( >> Item('object.avector.name',visible_when='avector'), >> etc.etc. >> ) >> >> This is actually in quite a complex view but basically it worked and I >> use visible_when='avector' quite a lot in the view. >> >> In Traits 4 (epd 7.2.2) the view is ok if there is an associated vector, >> i.e. avector is not None >> >> If a vector=None then I get the following error >> >> Traceback (most recent call last): >> File "c:\python27\lib\site-packages\traitsui\wx\tree_editor.py", line >> 1225, in _on_tree_sel_changed >> kind = 'subpanel' ) >> File "c:\python27\lib\site-packages\traits\has_traits.py", line 2266, >> in edit_traits >> handler, id, scrollable, args ) >> File "c:\python27\lib\site-packages\traitsui\view.py", line 433, in ui >> ui.ui( parent, kind ) >> File "c:\python27\lib\site-packages\traitsui\ui.py", line 218, in ui >> self.rebuild( self, parent ) >> File "c:\python27\lib\site-packages\traitsui\wx\toolkit.py", line >> 126, in ui_subpanel >> ui_panel.ui_subpanel( ui, parent ) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 100, in ui_subpanel >> ui_panel_for( ui, parent, False ) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 113, in ui_panel_for >> ui.control = control = Panel( ui, parent, buttons ).control >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 202, in __init__ >> sizer.Add( panel( ui, sw ), 1, wx.EXPAND ) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 349, in panel >> content[0], ui ) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 523, in fill_panel_for_group >> create_panel ) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 670, in __init__ >> self.add_groups( content, panel ) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 822, in add_groups >> fill_panel_for_group( panel, subgroup, self.ui ) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 523, in fill_panel_for_group >> create_panel ) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 672, in __init__ >> self.add_items(content, panel, self.sizer) >> File "c:\python27\lib\site-packages\traitsui\wx\ui_panel.py", line >> 975, in add_items >> trait = object.base_trait( name ) >> AttributeError: 'NoneType' object has no attribute 'base_trait' >> >> One final point. After I create my view, if I print it out there is no >> mention of visible_when. It looks like it is ignoring visible_when. >> >> Brennan >> >> >> _______________________________________________ >> 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 |
I don't know if this is the cause of the problem (I don't have ETS on the
computer I am currently on), but you will have undefined behaviour if you do not call "super(Person, self).__init__()". Also, I would suggest removing the __init__ completely and passing input values as keyword arguments and letting Traits do the initialization. On Mon, Feb 13, 2012 at 9:15 PM, Brennan Williams < [hidden email]> wrote: > On 14/02/2012 6:54 a.m., Jonathan March wrote: > >> Brennan, >> >> What you are seeing is the expected behavior with ETS 4, but it is also >> what I see in a simple example with EPD 6.2 (ETS 3), at least on OSX. >> >> Can you extract a simple example which works as you want in ETS 3 but not >> in ETS 4? >> > See attached. I've left the imports as enthought. so it runs under both > EPD 6.2 and 7.2 but in my own code I've switched to the new format. > > Brennan > > Jonathan >> >> On Mon, Feb 13, 2012 at 3:56 AM, Brennan Williams< >> brennan.williams@**visualreservoir.com<[hidden email]>> >> wrote: >> >> I'm moving from EPD 6.2 to 7.2 on a 32-bit Windows 7 platform using wx. >>> >>> I'm creating a view for an object (called a vector). It is of class >>> RZVector. >>> It can have an associated vector so I have the RZVector class has a >>> trait called avector which is defined as an Instance("RZVector"). >>> If the vector doesn't have an associated vector then avector=None >>> >>> Under Traits 3.x the following was ok... >>> >>> view=View( >>> Item('object.avector.name',**visible_when='avector'), >>> etc.etc. >>> ) >>> >>> This is actually in quite a complex view but basically it worked and I >>> use visible_when='avector' quite a lot in the view. >>> >>> In Traits 4 (epd 7.2.2) the view is ok if there is an associated vector, >>> i.e. avector is not None >>> >>> If a vector=None then I get the following error >>> >>> Traceback (most recent call last): >>> File "c:\python27\lib\site-**packages\traitsui\wx\tree_**editor.py", >>> line >>> 1225, in _on_tree_sel_changed >>> kind = 'subpanel' ) >>> File "c:\python27\lib\site-**packages\traits\has_traits.py"**, line >>> 2266, >>> in edit_traits >>> handler, id, scrollable, args ) >>> File "c:\python27\lib\site-**packages\traitsui\view.py", line 433, in >>> ui >>> ui.ui( parent, kind ) >>> File "c:\python27\lib\site-**packages\traitsui\ui.py", line 218, in ui >>> self.rebuild( self, parent ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\toolkit.**py", line >>> 126, in ui_subpanel >>> ui_panel.ui_subpanel( ui, parent ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 100, in ui_subpanel >>> ui_panel_for( ui, parent, False ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 113, in ui_panel_for >>> ui.control = control = Panel( ui, parent, buttons ).control >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 202, in __init__ >>> sizer.Add( panel( ui, sw ), 1, wx.EXPAND ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 349, in panel >>> content[0], ui ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 523, in fill_panel_for_group >>> create_panel ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 670, in __init__ >>> self.add_groups( content, panel ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 822, in add_groups >>> fill_panel_for_group( panel, subgroup, self.ui ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 523, in fill_panel_for_group >>> create_panel ) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 672, in __init__ >>> self.add_items(content, panel, self.sizer) >>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>> 975, in add_items >>> trait = object.base_trait( name ) >>> AttributeError: 'NoneType' object has no attribute 'base_trait' >>> >>> One final point. After I create my view, if I print it out there is no >>> mention of visible_when. It looks like it is ignoring visible_when. >>> >>> Brennan >>> >>> >>> ______________________________**_________________ >>> Enthought-Dev mailing list >>> [hidden email].**com <[hidden email]> >>> https://mail.enthought.com/**mailman/listinfo/enthought-dev<https://mail.enthought.com/mailman/listinfo/enthought-dev> >>> >>> ______________________________**_________________ >> Enthought-Dev mailing list >> [hidden email].**com <[hidden email]> >> https://mail.enthought.com/**mailman/listinfo/enthought-dev<https://mail.enthought.com/mailman/listinfo/enthought-dev> >> >> > > _______________________________________________ > Enthought-Dev mailing list > [hidden email] > https://mail.enthought.com/mailman/listinfo/enthought-dev > > -- Simon Jagoe Enthought Ltd +44 79 312 11 506 [hidden email] _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
On 14/02/2012 10:22 a.m., Simon Jagoe wrote:
> I don't know if this is the cause of the problem (I don't have ETS on the > computer I am currently on), but you will have undefined behaviour if you > do not call "super(Person, self).__init__()". ok I'll look into that > Also, I would suggest removing the __init__ completely and passing input > values as keyword arguments and letting Traits do the initialization. Sorry, can you clarify what you mean by that? > > On Mon, Feb 13, 2012 at 9:15 PM, Brennan Williams< > [hidden email]> wrote: > >> On 14/02/2012 6:54 a.m., Jonathan March wrote: >> >>> Brennan, >>> >>> What you are seeing is the expected behavior with ETS 4, but it is also >>> what I see in a simple example with EPD 6.2 (ETS 3), at least on OSX. >>> >>> Can you extract a simple example which works as you want in ETS 3 but not >>> in ETS 4? >>> >> See attached. I've left the imports as enthought. so it runs under both >> EPD 6.2 and 7.2 but in my own code I've switched to the new format. >> >> Brennan >> >> Jonathan >>> On Mon, Feb 13, 2012 at 3:56 AM, Brennan Williams< >>> brennan.williams@**visualreservoir.com<[hidden email]>> >>> wrote: >>> >>> I'm moving from EPD 6.2 to 7.2 on a 32-bit Windows 7 platform using wx. >>>> I'm creating a view for an object (called a vector). It is of class >>>> RZVector. >>>> It can have an associated vector so I have the RZVector class has a >>>> trait called avector which is defined as an Instance("RZVector"). >>>> If the vector doesn't have an associated vector then avector=None >>>> >>>> Under Traits 3.x the following was ok... >>>> >>>> view=View( >>>> Item('object.avector.name',**visible_when='avector'), >>>> etc.etc. >>>> ) >>>> >>>> This is actually in quite a complex view but basically it worked and I >>>> use visible_when='avector' quite a lot in the view. >>>> >>>> In Traits 4 (epd 7.2.2) the view is ok if there is an associated vector, >>>> i.e. avector is not None >>>> >>>> If a vector=None then I get the following error >>>> >>>> Traceback (most recent call last): >>>> File "c:\python27\lib\site-**packages\traitsui\wx\tree_**editor.py", >>>> line >>>> 1225, in _on_tree_sel_changed >>>> kind = 'subpanel' ) >>>> File "c:\python27\lib\site-**packages\traits\has_traits.py"**, line >>>> 2266, >>>> in edit_traits >>>> handler, id, scrollable, args ) >>>> File "c:\python27\lib\site-**packages\traitsui\view.py", line 433, in >>>> ui >>>> ui.ui( parent, kind ) >>>> File "c:\python27\lib\site-**packages\traitsui\ui.py", line 218, in ui >>>> self.rebuild( self, parent ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\toolkit.**py", line >>>> 126, in ui_subpanel >>>> ui_panel.ui_subpanel( ui, parent ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 100, in ui_subpanel >>>> ui_panel_for( ui, parent, False ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 113, in ui_panel_for >>>> ui.control = control = Panel( ui, parent, buttons ).control >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 202, in __init__ >>>> sizer.Add( panel( ui, sw ), 1, wx.EXPAND ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 349, in panel >>>> content[0], ui ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 523, in fill_panel_for_group >>>> create_panel ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 670, in __init__ >>>> self.add_groups( content, panel ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 822, in add_groups >>>> fill_panel_for_group( panel, subgroup, self.ui ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 523, in fill_panel_for_group >>>> create_panel ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 672, in __init__ >>>> self.add_items(content, panel, self.sizer) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 975, in add_items >>>> trait = object.base_trait( name ) >>>> AttributeError: 'NoneType' object has no attribute 'base_trait' >>>> >>>> One final point. After I create my view, if I print it out there is no >>>> mention of visible_when. It looks like it is ignoring visible_when. >>>> >>>> Brennan >>>> >>>> >>>> ______________________________**_________________ >>>> Enthought-Dev mailing list >>>> [hidden email].**com<[hidden email]> >>>> https://mail.enthought.com/**mailman/listinfo/enthought-dev<https://mail.enthought.com/mailman/listinfo/enthought-dev> >>>> >>>> ______________________________**_________________ >>> Enthought-Dev mailing list >>> [hidden email].**com<[hidden email]> >>> https://mail.enthought.com/**mailman/listinfo/enthought-dev<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 |
In reply to this post by Simon Jagoe
On 14/02/2012 10:22 a.m., Simon Jagoe wrote:
> I don't know if this is the cause of the problem (I don't have ETS on the > computer I am currently on), but you will have undefined behaviour if you > do not call "super(Person, self).__init__()". No change when I added super. Still working ok under EPD 6.2 and the 'NoneType' object has no attribute 'base_trait' error under EPD 7.2. I looked at the traitsui\wx\ui_panel.py code for both and I couldn't see why they work differently. Have I just been getting away with this under previous versions? > > Also, I would suggest removing the __init__ completely and passing input > values as keyword arguments and letting Traits do the initialization. > > On Mon, Feb 13, 2012 at 9:15 PM, Brennan Williams< > [hidden email]> wrote: > >> On 14/02/2012 6:54 a.m., Jonathan March wrote: >> >>> Brennan, >>> >>> What you are seeing is the expected behavior with ETS 4, but it is also >>> what I see in a simple example with EPD 6.2 (ETS 3), at least on OSX. >>> >>> Can you extract a simple example which works as you want in ETS 3 but not >>> in ETS 4? >>> >> See attached. I've left the imports as enthought. so it runs under both >> EPD 6.2 and 7.2 but in my own code I've switched to the new format. >> >> Brennan >> >> Jonathan >>> On Mon, Feb 13, 2012 at 3:56 AM, Brennan Williams< >>> brennan.williams@**visualreservoir.com<[hidden email]>> >>> wrote: >>> >>> I'm moving from EPD 6.2 to 7.2 on a 32-bit Windows 7 platform using wx. >>>> I'm creating a view for an object (called a vector). It is of class >>>> RZVector. >>>> It can have an associated vector so I have the RZVector class has a >>>> trait called avector which is defined as an Instance("RZVector"). >>>> If the vector doesn't have an associated vector then avector=None >>>> >>>> Under Traits 3.x the following was ok... >>>> >>>> view=View( >>>> Item('object.avector.name',**visible_when='avector'), >>>> etc.etc. >>>> ) >>>> >>>> This is actually in quite a complex view but basically it worked and I >>>> use visible_when='avector' quite a lot in the view. >>>> >>>> In Traits 4 (epd 7.2.2) the view is ok if there is an associated vector, >>>> i.e. avector is not None >>>> >>>> If a vector=None then I get the following error >>>> >>>> Traceback (most recent call last): >>>> File "c:\python27\lib\site-**packages\traitsui\wx\tree_**editor.py", >>>> line >>>> 1225, in _on_tree_sel_changed >>>> kind = 'subpanel' ) >>>> File "c:\python27\lib\site-**packages\traits\has_traits.py"**, line >>>> 2266, >>>> in edit_traits >>>> handler, id, scrollable, args ) >>>> File "c:\python27\lib\site-**packages\traitsui\view.py", line 433, in >>>> ui >>>> ui.ui( parent, kind ) >>>> File "c:\python27\lib\site-**packages\traitsui\ui.py", line 218, in ui >>>> self.rebuild( self, parent ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\toolkit.**py", line >>>> 126, in ui_subpanel >>>> ui_panel.ui_subpanel( ui, parent ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 100, in ui_subpanel >>>> ui_panel_for( ui, parent, False ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 113, in ui_panel_for >>>> ui.control = control = Panel( ui, parent, buttons ).control >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 202, in __init__ >>>> sizer.Add( panel( ui, sw ), 1, wx.EXPAND ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 349, in panel >>>> content[0], ui ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 523, in fill_panel_for_group >>>> create_panel ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 670, in __init__ >>>> self.add_groups( content, panel ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 822, in add_groups >>>> fill_panel_for_group( panel, subgroup, self.ui ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 523, in fill_panel_for_group >>>> create_panel ) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 672, in __init__ >>>> self.add_items(content, panel, self.sizer) >>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>> 975, in add_items >>>> trait = object.base_trait( name ) >>>> AttributeError: 'NoneType' object has no attribute 'base_trait' >>>> >>>> One final point. After I create my view, if I print it out there is no >>>> mention of visible_when. It looks like it is ignoring visible_when. >>>> >>>> Brennan >>>> >>>> >>>> ______________________________**_________________ >>>> Enthought-Dev mailing list >>>> [hidden email].**com<[hidden email]> >>>> https://mail.enthought.com/**mailman/listinfo/enthought-dev<https://mail.enthought.com/mailman/listinfo/enthought-dev> >>>> >>>> ______________________________**_________________ >>> Enthought-Dev mailing list >>> [hidden email].**com<[hidden email]> >>> https://mail.enthought.com/**mailman/listinfo/enthought-dev<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 |
In reply to this post by Brennan Williams
On 14/02/2012 10:33 a.m., Brennan Williams wrote:
> On 14/02/2012 10:22 a.m., Simon Jagoe wrote: >> I don't know if this is the cause of the problem (I don't have ETS on the >> computer I am currently on), but you will have undefined behaviour if you >> do not call "super(Person, self).__init__()". > ok I'll look into that >> Also, I would suggest removing the __init__ completely and passing input >> values as keyword arguments and letting Traits do the initialization. > Sorry, can you clarify what you mean by that? DId you mean... from enthought.traits.api import HasTraits, Str, Instance from enthought.traits.ui.api import View, Item, VGroup from enthought.traits.ui.api import Handler from enthought.pyface.api import error, information, warning class Person(HasTraits): first_name = Str("Joe") last_name = Str("Blow") partner=Instance("Person") view = View('first_name', 'last_name', VGroup( Item('object.partner.first_name',style='readonly',visible_when='partner'), Item('object.partner.last_name',style='readonly',visible_when='partner'), label='Partner', ), ) # def __init__(self,first,last,partner): # super(Person,self).__init__() # self.first_name=first # self.last_name=last # if partner: # self.partner=partner gill = Person(first_name='Gill',last_name='Jones',partner=None) sam = Person(first_name='Sam',last_name='Smith',partner=gill) sam.configure_traits() gill.configure_traits() That still has the same behaviour - works in EPD 6.2, doesn't in 7.2 by which I suppose I really mean Traits 3 vs Traits 4. >> On Mon, Feb 13, 2012 at 9:15 PM, Brennan Williams< >> [hidden email]> wrote: >> >>> On 14/02/2012 6:54 a.m., Jonathan March wrote: >>> >>>> Brennan, >>>> >>>> What you are seeing is the expected behavior with ETS 4, but it is also >>>> what I see in a simple example with EPD 6.2 (ETS 3), at least on OSX. >>>> >>>> Can you extract a simple example which works as you want in ETS 3 but not >>>> in ETS 4? >>>> >>> See attached. I've left the imports as enthought. so it runs under both >>> EPD 6.2 and 7.2 but in my own code I've switched to the new format. >>> >>> Brennan >>> >>> Jonathan >>>> On Mon, Feb 13, 2012 at 3:56 AM, Brennan Williams< >>>> brennan.williams@**visualreservoir.com<[hidden email]>> >>>> wrote: >>>> >>>> I'm moving from EPD 6.2 to 7.2 on a 32-bit Windows 7 platform using wx. >>>>> I'm creating a view for an object (called a vector). It is of class >>>>> RZVector. >>>>> It can have an associated vector so I have the RZVector class has a >>>>> trait called avector which is defined as an Instance("RZVector"). >>>>> If the vector doesn't have an associated vector then avector=None >>>>> >>>>> Under Traits 3.x the following was ok... >>>>> >>>>> view=View( >>>>> Item('object.avector.name',**visible_when='avector'), >>>>> etc.etc. >>>>> ) >>>>> >>>>> This is actually in quite a complex view but basically it worked and I >>>>> use visible_when='avector' quite a lot in the view. >>>>> >>>>> In Traits 4 (epd 7.2.2) the view is ok if there is an associated vector, >>>>> i.e. avector is not None >>>>> >>>>> If a vector=None then I get the following error >>>>> >>>>> Traceback (most recent call last): >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\tree_**editor.py", >>>>> line >>>>> 1225, in _on_tree_sel_changed >>>>> kind = 'subpanel' ) >>>>> File "c:\python27\lib\site-**packages\traits\has_traits.py"**, line >>>>> 2266, >>>>> in edit_traits >>>>> handler, id, scrollable, args ) >>>>> File "c:\python27\lib\site-**packages\traitsui\view.py", line 433, in >>>>> ui >>>>> ui.ui( parent, kind ) >>>>> File "c:\python27\lib\site-**packages\traitsui\ui.py", line 218, in ui >>>>> self.rebuild( self, parent ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\toolkit.**py", line >>>>> 126, in ui_subpanel >>>>> ui_panel.ui_subpanel( ui, parent ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 100, in ui_subpanel >>>>> ui_panel_for( ui, parent, False ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 113, in ui_panel_for >>>>> ui.control = control = Panel( ui, parent, buttons ).control >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 202, in __init__ >>>>> sizer.Add( panel( ui, sw ), 1, wx.EXPAND ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 349, in panel >>>>> content[0], ui ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 523, in fill_panel_for_group >>>>> create_panel ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 670, in __init__ >>>>> self.add_groups( content, panel ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 822, in add_groups >>>>> fill_panel_for_group( panel, subgroup, self.ui ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 523, in fill_panel_for_group >>>>> create_panel ) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 672, in __init__ >>>>> self.add_items(content, panel, self.sizer) >>>>> File "c:\python27\lib\site-**packages\traitsui\wx\ui_panel.**py", line >>>>> 975, in add_items >>>>> trait = object.base_trait( name ) >>>>> AttributeError: 'NoneType' object has no attribute 'base_trait' >>>>> >>>>> One final point. After I create my view, if I print it out there is no >>>>> mention of visible_when. It looks like it is ignoring visible_when. >>>>> >>>>> Brennan >>>>> >>>>> >>>>> ______________________________**_________________ >>>>> Enthought-Dev mailing list >>>>> [hidden email].**com<[hidden email]> >>>>> https://mail.enthought.com/**mailman/listinfo/enthought-dev<https://mail.enthought.com/mailman/listinfo/enthought-dev> >>>>> >>>>> ______________________________**_________________ >>>> Enthought-Dev mailing list >>>> [hidden email].**com<[hidden email]> >>>> https://mail.enthought.com/**mailman/listinfo/enthought-dev<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 |
Yes, that is what I meant. I'm afraid I didn't expect it to change
behaviour much, but it is the preferred way of created HasTraits subclasses. In terms of your problem, possibly a workaround like this would be acceptable: class Person(HasTraits): first_name = Str("Joe") last_name = Str("Blow") partner=Instance("Person", args=()) _display_partner = Bool(False) def __init__(self, **traits): super(Person, self).__init__(**traits) if 'partner' in traits: DId you mean... > > from enthought.traits.api import HasTraits, Str, Instance > from enthought.traits.ui.api import View, Item, VGroup > from enthought.traits.ui.api import Handler > from enthought.pyface.api import error, information, warning > > class Person(HasTraits): > first_name = Str("Joe") > last_name = Str("Blow") > partner=Instance("Person") > > view = View('first_name', 'last_name', > VGroup( > > Item('object.partner.first_name',style='readonly',visible_when='partner'), > > Item('object.partner.last_name',style='readonly',visible_when='partner'), > label='Partner', > ), > ) > > # def __init__(self,first,last,partner): > # super(Person,self).__init__() > # self.first_name=first > # self.last_name=last > # if partner: > # self.partner=partner > > > > gill = Person(first_name='Gill',last_name='Jones',partner=None) > sam = Person(first_name='Sam',last_name='Smith',partner=gill) > sam.configure_traits() > gill.configure_traits() > > > Simon Jagoe Enthought Ltd +44 79 312 11 506 [hidden email] _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
Sorry, accidentally hit send too soon
class Person(HasTraits): first_name = Str("Joe") last_name = Str("Blow") partner=Instance("Person", args=()) _display_partner = Bool(False) def __init__(self, **traits): super(Person, self).__init__(**traits) if 'partner' in traits: self._display_partner = True then use _display_partner in your visible_when clause. On Mon, Feb 13, 2012 at 9:57 PM, Simon Jagoe <[hidden email]> wrote: > Yes, that is what I meant. I'm afraid I didn't expect it to change > behaviour much, but it is the preferred way of created HasTraits subclasses. > > In terms of your problem, > > possibly a workaround like this would be acceptable: > > class Person(HasTraits): > first_name = Str("Joe") > last_name = Str("Blow") > partner=Instance("Person", args=()) > _display_partner = Bool(False) > > def __init__(self, **traits): > super(Person, self).__init__(**traits) > if 'partner' in traits: > > > > DId you mean... >> >> from enthought.traits.api import HasTraits, Str, Instance >> from enthought.traits.ui.api import View, Item, VGroup >> from enthought.traits.ui.api import Handler >> from enthought.pyface.api import error, information, warning >> >> class Person(HasTraits): >> first_name = Str("Joe") >> last_name = Str("Blow") >> partner=Instance("Person") >> >> view = View('first_name', 'last_name', >> VGroup( >> >> Item('object.partner.first_name',style='readonly',visible_when='partner'), >> >> Item('object.partner.last_name',style='readonly',visible_when='partner'), >> label='Partner', >> ), >> ) >> >> # def __init__(self,first,last,partner): >> # super(Person,self).__init__() >> # self.first_name=first >> # self.last_name=last >> # if partner: >> # self.partner=partner >> >> >> >> gill = Person(first_name='Gill',last_name='Jones',partner=None) >> sam = Person(first_name='Sam',last_name='Smith',partner=gill) >> sam.configure_traits() >> gill.configure_traits() >> >> >> > -- > Simon Jagoe > Enthought Ltd > +44 79 312 11 506 > [hidden email] > -- Simon Jagoe Enthought Ltd +44 79 312 11 506 [hidden email] _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
I believe using visible_when="partner is not None" would also work.
- John On Mon, Feb 13, 2012 at 3:58 PM, Simon Jagoe <[hidden email]> wrote: > Sorry, accidentally hit send too soon > > class Person(HasTraits): > first_name = Str("Joe") > last_name = Str("Blow") > partner=Instance("Person", args=()) > _display_partner = Bool(False) > > def __init__(self, **traits): > super(Person, self).__init__(**traits) > if 'partner' in traits: > self._display_partner = True > > > then use _display_partner in your visible_when clause. > > On Mon, Feb 13, 2012 at 9:57 PM, Simon Jagoe <[hidden email]> wrote: > >> Yes, that is what I meant. I'm afraid I didn't expect it to change >> behaviour much, but it is the preferred way of created HasTraits subclasses. >> >> In terms of your problem, >> >> possibly a workaround like this would be acceptable: >> >> class Person(HasTraits): >> first_name = Str("Joe") >> last_name = Str("Blow") >> partner=Instance("Person", args=()) >> _display_partner = Bool(False) >> >> def __init__(self, **traits): >> super(Person, self).__init__(**traits) >> if 'partner' in traits: >> >> >> >> DId you mean... >>> >>> from enthought.traits.api import HasTraits, Str, Instance >>> from enthought.traits.ui.api import View, Item, VGroup >>> from enthought.traits.ui.api import Handler >>> from enthought.pyface.api import error, information, warning >>> >>> class Person(HasTraits): >>> first_name = Str("Joe") >>> last_name = Str("Blow") >>> partner=Instance("Person") >>> >>> view = View('first_name', 'last_name', >>> VGroup( >>> >>> Item('object.partner.first_name',style='readonly',visible_when='partner'), >>> >>> Item('object.partner.last_name',style='readonly',visible_when='partner'), >>> label='Partner', >>> ), >>> ) >>> >>> # def __init__(self,first,last,partner): >>> # super(Person,self).__init__() >>> # self.first_name=first >>> # self.last_name=last >>> # if partner: >>> # self.partner=partner >>> >>> >>> >>> gill = Person(first_name='Gill',last_name='Jones',partner=None) >>> sam = Person(first_name='Sam',last_name='Smith',partner=gill) >>> sam.configure_traits() >>> gill.configure_traits() >>> >>> >>> >> -- >> Simon Jagoe >> Enthought Ltd >> +44 79 312 11 506 >> [hidden email] >> > > > > -- > Simon Jagoe > Enthought Ltd > +44 79 312 11 506 > [hidden email] > _______________________________________________ > 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 |
In reply to this post by Simon Jagoe
On 14/02/2012 10:58 a.m., Simon Jagoe wrote:
> Sorry, accidentally hit send too soon > > class Person(HasTraits): > first_name = Str("Joe") > last_name = Str("Blow") > partner=Instance("Person", args=()) > _display_partner = Bool(False) > > def __init__(self, **traits): > super(Person, self).__init__(**traits) > if 'partner' in traits: > self._display_partner = True > > > then use _display_partner in your visible_when clause. Tried that and it worked. However that means I have a lot of editing to do in my code. And I have a confession to make. I should have done this earlier but I just did a diff on the ui_panel.py in EPD 7.2 with that in EPD 6.2 and I've realised that I added two lines to it - I did this about 16 months ago and didn't document it.... but if you look at ui_panel.py aorund line 974 it looks like.... # Otherwise, it must be a trait Item: object = eval( item.object_, globals(), ui.context ) trait = object.base_trait( name ) desc = trait.desc or '' label = None and I modified it to... # Otherwise, it must be a trait Item: object = eval( item.object_, globals(), ui.context ) if not object: return trait = object.base_trait( name ) desc = trait.desc or '' label = None In my defence I don't remember doing this but it worked. The processing of the item name is done before checking whether it is visible or not. Brennan > > On Mon, Feb 13, 2012 at 9:57 PM, Simon Jagoe<[hidden email]> wrote: > >> Yes, that is what I meant. I'm afraid I didn't expect it to change >> behaviour much, but it is the preferred way of created HasTraits subclasses. >> >> In terms of your problem, >> >> possibly a workaround like this would be acceptable: >> >> class Person(HasTraits): >> first_name = Str("Joe") >> last_name = Str("Blow") >> partner=Instance("Person", args=()) >> _display_partner = Bool(False) >> >> def __init__(self, **traits): >> super(Person, self).__init__(**traits) >> if 'partner' in traits: >> >> >> >> DId you mean... >>> from enthought.traits.api import HasTraits, Str, Instance >>> from enthought.traits.ui.api import View, Item, VGroup >>> from enthought.traits.ui.api import Handler >>> from enthought.pyface.api import error, information, warning >>> >>> class Person(HasTraits): >>> first_name = Str("Joe") >>> last_name = Str("Blow") >>> partner=Instance("Person") >>> >>> view = View('first_name', 'last_name', >>> VGroup( >>> >>> Item('object.partner.first_name',style='readonly',visible_when='partner'), >>> >>> Item('object.partner.last_name',style='readonly',visible_when='partner'), >>> label='Partner', >>> ), >>> ) >>> >>> # def __init__(self,first,last,partner): >>> # super(Person,self).__init__() >>> # self.first_name=first >>> # self.last_name=last >>> # if partner: >>> # self.partner=partner >>> >>> >>> >>> gill = Person(first_name='Gill',last_name='Jones',partner=None) >>> sam = Person(first_name='Sam',last_name='Smith',partner=gill) >>> sam.configure_traits() >>> gill.configure_traits() >>> >>> >>> >> -- >> Simon Jagoe >> Enthought Ltd >> +44 79 312 11 506 >> [hidden email] >> > > _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
Just thinking about this a bit more.... what I am aiming for is to have
one view definition (which is my app is quite large and includes plots, array tables etc) whether an instance of class Person has a partner or not. The reason I'm using visible_when is that you can add a partner after a person has been created and viewed. I also have a parent class, e.g. a class Family which has a list of persons and a family view which uses a TableEditor with a selected='currentperson' so that you have a combined view of the list with a current person view underneath. So my previous mod of adding " if not object: return" to ui_panel.py worked quite well. What do you think is the best way for me to handle this? Brennan On 14/02/2012 11:59 a.m., Brennan Williams wrote: > On 14/02/2012 10:58 a.m., Simon Jagoe wrote: >> Sorry, accidentally hit send too soon >> >> class Person(HasTraits): >> first_name = Str("Joe") >> last_name = Str("Blow") >> partner=Instance("Person", args=()) >> _display_partner = Bool(False) >> >> def __init__(self, **traits): >> super(Person, self).__init__(**traits) >> if 'partner' in traits: >> self._display_partner = True >> >> >> then use _display_partner in your visible_when clause. > Tried that and it worked. However that means I have a lot of editing to > do in my code. > > And I have a confession to make. I should have done this earlier but I > just did a diff on the ui_panel.py in EPD 7.2 with that in EPD 6.2 and > I've realised that I added two lines to it - I did this about 16 months > ago and didn't document it.... > > but if you look at ui_panel.py aorund line 974 it looks like.... > > # Otherwise, it must be a trait Item: > object = eval( item.object_, globals(), ui.context ) > trait = object.base_trait( name ) > desc = trait.desc or '' > label = None > > and I modified it to... > > # Otherwise, it must be a trait Item: > object = eval( item.object_, globals(), ui.context ) > if not object: > return > trait = object.base_trait( name ) > desc = trait.desc or '' > label = None > > In my defence I don't remember doing this but it worked. The processing > of the item name is done before checking whether it is visible or not. > > Brennan > >> On Mon, Feb 13, 2012 at 9:57 PM, Simon Jagoe<[hidden email]> wrote: >> >>> Yes, that is what I meant. I'm afraid I didn't expect it to change >>> behaviour much, but it is the preferred way of created HasTraits subclasses. >>> >>> In terms of your problem, >>> >>> possibly a workaround like this would be acceptable: >>> >>> class Person(HasTraits): >>> first_name = Str("Joe") >>> last_name = Str("Blow") >>> partner=Instance("Person", args=()) >>> _display_partner = Bool(False) >>> >>> def __init__(self, **traits): >>> super(Person, self).__init__(**traits) >>> if 'partner' in traits: >>> >>> >>> >>> DId you mean... >>>> from enthought.traits.api import HasTraits, Str, Instance >>>> from enthought.traits.ui.api import View, Item, VGroup >>>> from enthought.traits.ui.api import Handler >>>> from enthought.pyface.api import error, information, warning >>>> >>>> class Person(HasTraits): >>>> first_name = Str("Joe") >>>> last_name = Str("Blow") >>>> partner=Instance("Person") >>>> >>>> view = View('first_name', 'last_name', >>>> VGroup( >>>> >>>> Item('object.partner.first_name',style='readonly',visible_when='partner'), >>>> >>>> Item('object.partner.last_name',style='readonly',visible_when='partner'), >>>> label='Partner', >>>> ), >>>> ) >>>> >>>> # def __init__(self,first,last,partner): >>>> # super(Person,self).__init__() >>>> # self.first_name=first >>>> # self.last_name=last >>>> # if partner: >>>> # self.partner=partner >>>> >>>> >>>> >>>> gill = Person(first_name='Gill',last_name='Jones',partner=None) >>>> sam = Person(first_name='Sam',last_name='Smith',partner=gill) >>>> sam.configure_traits() >>>> gill.configure_traits() >>>> >>>> >>>> >>> -- >>> Simon Jagoe >>> Enthought Ltd >>> +44 79 312 11 506 >>> [hidden email] >>> >> > _______________________________________________ > 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 |
Free forum by Nabble | Edit this page |