Re: [Enthought-dev] Str invalid attribute (red background for invalid input)

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

Re: [Enthought-dev] Str invalid attribute (red background for invalid input)

Jonathan Blakes
I have been having trouble with File and Directory traits in the GUI
where their editors do not un-invalidate themselves (they stay red) when
a valid path is given if 'exists=True' in the trait metadata.

> ok, so I got it working by adding an 'invalid='error'" in the item
> definition of the view, instead of using the sync_to_view metadata of the
> property definition.
>
> According the docs and examples, it should work both ways, so I will try to
> make up a simple example that shows the variance in behavior.
>
> Chris

Eventually I came up with the same solution:

     _cwd = Directory
     # not Directory(exists=True) because that breaks the editor!

     def __cwd_default(self):
         _cwd = os.getcwd()
         return _cwd

     # external validation of '_cwd' ---

     _cwd_invalid = Property(Bool, depends_on='_cwd')

     def _get__cwd_invalid(self):
         return True if not os.path.isdir(self._cwd) else False

Perhaps it would be good to include the "Item('file',
invalid='file_invalid')" idiom in the code of the Invalid_state_handling
example as well as the docstring, or fix File and Directory traits not
un-invalidating themselves.

Jon

PS. This reply is not related to the other follow-up to the previous post.

> On Sat, Mar 7, 2009 at 8:35 PM, Chris Colbert <[hidden email]> wrote:
>
> ok, it doesnt seem like anything i am doing, so im attaching a zip file
> with my program if someone could please help me and take a look at it.
>
> Run controlsedugui.py  (you have to have ETS installed)
> clicking on the Test Invalid should change the background color of the text
> input "Enter Transfer Function" box.
> Now, uncomment lines 70 & 71 in controlsedugui.py. These actually embed the
> instances of the chaco plots in the gui.
> Whith these lines uncommented, the program fails with the error:
>
> enthought.traits.trait_errors.TraitError: No editor with id =
> 'user_tran_func' was found for the 'sync_to_view' metadata for the 'error'
> trait in the 'context' context object.
>
> I cant figure it out. The instances of those classes dont modify or use
> user_tran_func. Maybe this is a bug due to embedding the Chaco plots?
>
> System:
> Vista Ultimate 32 bit
> Thanks for any help!
> EPD Py25 4.1.30101
>
> Chris
>
> On Sat, Mar 7, 2009 at 6:49 PM, Chris Colbert <[hidden email]> wrote:
>
> alright this is weird. I stripped everything out of my application except
> the code necessary for this functionality, and now it works. But it makes no
> sense why (yet). So, im assuming i've done something wrong, and when/if i
> figure it out, I will update this post.
>
> On Sat, Mar 7, 2009 at 5:40 PM, Chris Colbert <[hidden email]>wrote:
>
> This has got to be an utterly noobish question, but I can't for the life
> of me figure it out.
>
> I accept text input from the user in a Str box. That string gets parsed
> and passed through various code, and if I catch an exception, I want to
> shade the background of that string box red to indicated the input is
> invalid.
>
> I have looked at the Invalid_state_handling example, but the Str box
> there is a Property, mine is not.
>
> Example Code:
> ####################################
>
> class Foo(HasTraits):
>
> input = Str()
> button = Button()
> error = Property(Bool, sync_to_view = 'input.invalid')
>
>      view = View(....)
>
>      def __init__(self):
>               .....
>
>     def bar(self):
>              ......
>
> @property_depends_on( 'button' )
>     def _get_error ( self ):
>         return True
> ########################################
>
> this gives me this error:
>
> enthought.traits.trait_errors.TraitError: No editor with id = 'input' was
> found for the 'sync_to_view' metadata for the 'error' trait in the 'context'
> context object.
>
> any help would be greatly appreciated!


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

Re: [Enthought-dev] Str invalid attribute (red background for invalid input)

Jonathan Blakes
Sorry, I forgot to include:

     traits_view = View(
         Item('_cwd',
             editor=DirectoryEditor(
                 invalid='_cwd_invalid',
                 auto_set=True,
             ),
         ),
     )

Jonathan Blakes wrote:

> I have been having trouble with File and Directory traits in the GUI
> where their editors do not un-invalidate themselves (they stay red) when
> a valid path is given if 'exists=True' in the trait metadata.
>
>> ok, so I got it working by adding an 'invalid='error'" in the item
>> definition of the view, instead of using the sync_to_view metadata of the
>> property definition.
>>
>> According the docs and examples, it should work both ways, so I will
>> try to
>> make up a simple example that shows the variance in behavior.
>>
>> Chris
>
> Eventually I came up with the same solution:
>
>     _cwd = Directory
>     # not Directory(exists=True) because that breaks the editor!
>
>     def __cwd_default(self):
>         _cwd = os.getcwd()
>         return _cwd
>
>     # external validation of '_cwd' ---
>
>     _cwd_invalid = Property(Bool, depends_on='_cwd')
>
>     def _get__cwd_invalid(self):
>         return True if not os.path.isdir(self._cwd) else False
>
> Perhaps it would be good to include the "Item('file',
> invalid='file_invalid')" idiom in the code of the Invalid_state_handling
> example as well as the docstring, or fix File and Directory traits not
> un-invalidating themselves.
>
> Jon
>
> PS. This reply is not related to the other follow-up to the previous post.
>
>> On Sat, Mar 7, 2009 at 8:35 PM, Chris Colbert <[hidden email]> wrote:
>>
>> ok, it doesnt seem like anything i am doing, so im attaching a zip file
>> with my program if someone could please help me and take a look at it.
>>
>> Run controlsedugui.py  (you have to have ETS installed)
>> clicking on the Test Invalid should change the background color of the
>> text
>> input "Enter Transfer Function" box.
>> Now, uncomment lines 70 & 71 in controlsedugui.py. These actually
>> embed the
>> instances of the chaco plots in the gui.
>> Whith these lines uncommented, the program fails with the error:
>>
>> enthought.traits.trait_errors.TraitError: No editor with id =
>> 'user_tran_func' was found for the 'sync_to_view' metadata for the
>> 'error'
>> trait in the 'context' context object.
>>
>> I cant figure it out. The instances of those classes dont modify or use
>> user_tran_func. Maybe this is a bug due to embedding the Chaco plots?
>>
>> System:
>> Vista Ultimate 32 bit
>> Thanks for any help!
>> EPD Py25 4.1.30101
>>
>> Chris
>>
>> On Sat, Mar 7, 2009 at 6:49 PM, Chris Colbert <[hidden email]> wrote:
>>
>> alright this is weird. I stripped everything out of my application except
>> the code necessary for this functionality, and now it works. But it
>> makes no
>> sense why (yet). So, im assuming i've done something wrong, and when/if i
>> figure it out, I will update this post.
>>
>> On Sat, Mar 7, 2009 at 5:40 PM, Chris Colbert <[hidden email]>wrote:
>>
>> This has got to be an utterly noobish question, but I can't for the life
>> of me figure it out.
>>
>> I accept text input from the user in a Str box. That string gets parsed
>> and passed through various code, and if I catch an exception, I want to
>> shade the background of that string box red to indicated the input is
>> invalid.
>>
>> I have looked at the Invalid_state_handling example, but the Str box
>> there is a Property, mine is not.
>>
>> Example Code:
>> ####################################
>>
>> class Foo(HasTraits):
>>
>> input = Str()
>> button = Button()
>> error = Property(Bool, sync_to_view = 'input.invalid')
>>
>>      view = View(....)
>>
>>      def __init__(self):
>>               .....
>>
>>     def bar(self):
>>              ......
>>
>> @property_depends_on( 'button' )
>>     def _get_error ( self ):
>>         return True
>> ########################################
>>
>> this gives me this error:
>>
>> enthought.traits.trait_errors.TraitError: No editor with id = 'input' was
>> found for the 'sync_to_view' metadata for the 'error' trait in the
>> 'context'
>> context object.
>>
>> any help would be greatly appreciated!
>
>
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev