Apply of Controller not executed

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

Apply of Controller not executed

Raphael Walker
Hello All,

I would like to have a object properties dialog with 'OK', 'Apply' and
'Cancel'. A custom controller should overwrite the behavior of setattr,
apply and close functions.

But i found out that the apply function of the controller is not called.

what am I doing wrong?

Example at the end.

Regards,
Raphael


from enthought.traits.api \
     import HasTraits, Dict, Str, Bool, TraitError

from enthought.traits.ui.api \
     import View, VGroup, HGroup, Item, Controller


class MyViewController ( Controller ):

     traits_view = View('first_name',
                        'last_name',
                        buttons=['OK', 'Apply', 'Cancel'])

     def setattr(self, info, object, name, value):
       print 'set'
       super(MyViewController, self).setattr(info, object, name, value)

     def apply(self, info):
       print 'apply'

     def close(self, info, is_ok):
       if is_ok:
         print 'ok'
       else:
         print 'cancel'
       return True


class MyModel ( HasTraits ):

     first_name = Str
     last_name = Str


# Create the model and (demo) view/controller:
m = MyModel(first_name='Mister', last_name='Lucky')
demo = MyViewController( m )


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


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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

Re: Apply of Controller not executed

bryce hendrix-2
The 'apply' method is only called in your view is opened as 'modal'. Try
this:

demo.configure_traits(kind='modal')

Bryce

On 4/15/2010 8:53 AM, Raphael Walker wrote:

> Hello All,
>
> I would like to have a object properties dialog with 'OK', 'Apply' and
> 'Cancel'. A custom controller should overwrite the behavior of setattr,
> apply and close functions.
>
> But i found out that the apply function of the controller is not called.
>
> what am I doing wrong?
>
> Example at the end.
>
> Regards,
> Raphael
>
>
> from enthought.traits.api \
>       import HasTraits, Dict, Str, Bool, TraitError
>
> from enthought.traits.ui.api \
>       import View, VGroup, HGroup, Item, Controller
>
>
> class MyViewController ( Controller ):
>
>       traits_view = View('first_name',
>                          'last_name',
>                          buttons=['OK', 'Apply', 'Cancel'])
>
>       def setattr(self, info, object, name, value):
>         print 'set'
>         super(MyViewController, self).setattr(info, object, name, value)
>
>       def apply(self, info):
>         print 'apply'
>
>       def close(self, info, is_ok):
>         if is_ok:
>           print 'ok'
>         else:
>           print 'cancel'
>         return True
>
>
> class MyModel ( HasTraits ):
>
>       first_name = Str
>       last_name = Str
>
>
> # Create the model and (demo) view/controller:
> m = MyModel(first_name='Mister', last_name='Lucky')
> demo = MyViewController( m )
>
>
> # Run the demo (if invoked from the command line):
> if __name__ == '__main__':
>       demo.configure_traits()
>
>
>    

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

Re: Apply of Controller not executed

Raphael Walker
Hello Bryce,

Yes, its calling 'apply' now.
but I'm getting this error.

Traceback (most recent call last):
   File
"C:\Users\rwalker\even_sandbox\gui\python\traitsbackendwx-3.3.0-py2.6.egg\enthought\traits\ui\wx\ui_modal.py",
ne 338, in _on_apply
     self.revert.Enable( True )
AttributeError: 'ModalDialog' object has no attribute 'revert'

Regards,
Raphael

On 15.04.2010 16:02, Bryce Hendrix wrote:

> The 'apply' method is only called in your view is opened as 'modal'. Try
> this:
>
> demo.configure_traits(kind='modal')
>
> Bryce
>
> On 4/15/2010 8:53 AM, Raphael Walker wrote:
>> Hello All,
>>
>> I would like to have a object properties dialog with 'OK', 'Apply' and
>> 'Cancel'. A custom controller should overwrite the behavior of setattr,
>> apply and close functions.
>>
>> But i found out that the apply function of the controller is not called.
>>
>> what am I doing wrong?
>>
>> Example at the end.
>>
>> Regards,
>> Raphael
>>
>>
>> from enthought.traits.api \
>>        import HasTraits, Dict, Str, Bool, TraitError
>>
>> from enthought.traits.ui.api \
>>        import View, VGroup, HGroup, Item, Controller
>>
>>
>> class MyViewController ( Controller ):
>>
>>        traits_view = View('first_name',
>>                           'last_name',
>>                           buttons=['OK', 'Apply', 'Cancel'])
>>
>>        def setattr(self, info, object, name, value):
>>          print 'set'
>>          super(MyViewController, self).setattr(info, object, name, value)
>>
>>        def apply(self, info):
>>          print 'apply'
>>
>>        def close(self, info, is_ok):
>>          if is_ok:
>>            print 'ok'
>>          else:
>>            print 'cancel'
>>          return True
>>
>>
>> class MyModel ( HasTraits ):
>>
>>        first_name = Str
>>        last_name = Str
>>
>>
>> # Create the model and (demo) view/controller:
>> m = MyModel(first_name='Mister', last_name='Lucky')
>> demo = MyViewController( m )
>>
>>
>> # Run the demo (if invoked from the command line):
>> if __name__ == '__main__':
>>        demo.configure_traits()
>>
>>
>>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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

Re: Apply of Controller not executed

Raphael Walker
A fix that works for me is shown in the changed Example below.

The problem is when subclassing from the 'MyCustomController' is that
the 'apply_btn' have to be defined/imported every time. I think is much
easier to write:

buttons = ['OK', 'Apply', 'Cancel']

then:

apply_btn = Action(name="Apply", action="apply")
or
from base_controller import apply_btn
buttons = ['OK', apply_btn, 'Cancel']

Regards,
Raphael



On 15.04.2010 16:10, Raphael Walker wrote:

> Hello Bryce,
>
> Yes, its calling 'apply' now.
> but I'm getting this error.
>
> Traceback (most recent call last):
>     File
> "C:\Users\rwalker\even_sandbox\gui\python\traitsbackendwx-3.3.0-py2.6.egg\enthought\traits\ui\wx\ui_modal.py",
> ne 338, in _on_apply
>       self.revert.Enable( True )
> AttributeError: 'ModalDialog' object has no attribute 'revert'
>
> Regards,
> Raphael
>
> On 15.04.2010 16:02, Bryce Hendrix wrote:
>> The 'apply' method is only called in your view is opened as 'modal'. Try
>> this:
>>
>> demo.configure_traits(kind='modal')
>>
>> Bryce
>>
>> On 4/15/2010 8:53 AM, Raphael Walker wrote:
>>> Hello All,
>>>
>>> I would like to have a object properties dialog with 'OK', 'Apply' and
>>> 'Cancel'. A custom controller should overwrite the behavior of setattr,
>>> apply and close functions.
>>>
>>> But i found out that the apply function of the controller is not called.
>>>
>>> what am I doing wrong?
>>>
>>> Example at the end.
>>>
>>> Regards,
>>> Raphael
>>>
>>>
>>> from enthought.traits.api \
>>>         import HasTraits, Dict, Str, Bool, TraitError
>>>
>>> from enthought.traits.ui.api \
>>>         import View, VGroup, HGroup, Item, Controller
>>>
>>>
>>> class MyViewController ( Controller ):
>>>
>>>         traits_view = View('first_name',
>>>                            'last_name',
>>>                            buttons=['OK', 'Apply', 'Cancel'])
>>>
>>>         def setattr(self, info, object, name, value):
>>>           print 'set'
>>>           super(MyViewController, self).setattr(info, object, name, value)
>>>
>>>         def apply(self, info):
>>>           print 'apply'
>>>
>>>         def close(self, info, is_ok):
>>>           if is_ok:
>>>             print 'ok'
>>>           else:
>>>             print 'cancel'
>>>           return True
>>>
>>>
>>> class MyModel ( HasTraits ):
>>>
>>>         first_name = Str
>>>         last_name = Str
>>>
>>>
>>> # Create the model and (demo) view/controller:
>>> m = MyModel(first_name='Mister', last_name='Lucky')
>>> demo = MyViewController( m )
>>>
>>>
>>> # Run the demo (if invoked from the command line):
>>> if __name__ == '__main__':
>>>         demo.configure_traits()
>>>
>>>
>>>
>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>>
>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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

Re: Apply of Controller not executed

bryce hendrix-2
In reply to this post by Raphael Walker
On 04/15/2010 09:10 AM, Raphael Walker wrote:

> Hello Bryce,
>
> Yes, its calling 'apply' now.
> but I'm getting this error.
>
> Traceback (most recent call last):
>     File
> "C:\Users\rwalker\even_sandbox\gui\python\traitsbackendwx-3.3.0-py2.6.egg\enthought\traits\ui\wx\ui_modal.py",
> ne 338, in _on_apply
>       self.revert.Enable( True )
> AttributeError: 'ModalDialog' object has no attribute 'revert'
>
>    

Raphael,

I fixed that last week in SVN. If you can update your TraitsBackendWx
egg to the most recent development egg, or switch to a svn checkout, it
should work for you.

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

Re: Apply of Controller not executed

Raphael Walker
On 15.04.2010 17:52, bryce hendrix wrote:

> On 04/15/2010 09:10 AM, Raphael Walker wrote:
>> Hello Bryce,
>>
>> Yes, its calling 'apply' now.
>> but I'm getting this error.
>>
>> Traceback (most recent call last):
>> File
>> "C:\Users\rwalker\even_sandbox\gui\python\traitsbackendwx-3.3.0-py2.6.egg\enthought\traits\ui\wx\ui_modal.py",
>>
>> ne 338, in _on_apply
>> self.revert.Enable( True )
>> AttributeError: 'ModalDialog' object has no attribute 'revert'
>>
>
> Raphael,
>
> I fixed that last week in SVN. If you can update your TraitsBackendWx
> egg to the most recent development egg, or switch to a svn checkout, it
> should work for you.
>
> Bryce
>
>

That sounds great.

I will have a look next week ... and hope it will solve my issues.

Regards,
Raphael

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev