enaml, chaco and traits-enaml

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

enaml, chaco and traits-enaml

Lee Taylor
I'm working on using enaml 0.8.2 with chaco. I want to use the
EnableCanvas from traits-enaml and I have some observations.

1) I'm unable to import EnableCanvas.  It looks like it needs to be
updated for enaml 0.8.

 >>> from traits_enaml.widgets.traits_view import EnableCanvas
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File ".../traits_enaml/__init__.py", line 9, in <module>
     from .trait_operators import TRAIT_OPERATORS
   File ".../traits_enaml/trait_operators.py", line 8, in <module>
     from enaml.core.operators import SubscriptionObserver,
OperatorBase, op_simple, \
ImportError: cannot import name SubscriptionObserver

2) I copied the file enable_canvas.py[1] from github into my local
directory and tried to use it directly with my sample enaml file
(attached).

$ enaml-run test2.enaml
Traceback (most recent call last):
   File ".../bin/enaml-run", line 9, in <module>
     load_entry_point('enaml==0.8.2', 'console_scripts', 'enaml-run')()
   File
".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/runner.py",
line 61, in main
     from enaml.qt.qt_application import QtApplication
   File
".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/qt/__init__.py",
line 37, in <module>
     prepare_pyqt()
   File
".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/qt/__init__.py",
line 13, in prepare_pyqt
     sip.setapi('QDate', 2)
ValueError: API 'QDate' has already been set to version 1

I'm using enable-4.3, Qt-4.8.5 and PyQt-x11-gpl-4.10.3 on linux.
I was unable to find who was setting it to 1 but I assume it's enable.

3) I was able to write a python file which imported the enaml file to
work around this problem.  It fails in enable_canvas.py in the
routine:

     def create_widget(self, parent):
         if self.component is not None:
             self._window = Window(parent, component=self.component,
                                   bgcolor=self.component.bgcolor)
             enable_widget = self._window.control
         else:
             self._window = None
             enable_widget = None
         return enable_widget

     @observe('component')
     def component_changed(self, new):
         self._window.component = new['value']

   $ python test2py.py
   File ".../local/enable_canvas.py", line 27, in create_widget
     if self.component is not None:
   File ".../local/enable_canvas.py", line 40, in component_changed
     self._window.component = new['value']
AttributeError: 'NoneType' object has no attribute 'component'

It seems to be calling the observer component_changed while
referencing self.component.  I expected it to call the observer only
when changing component's value.

If I add a test on _window in the observer, it works:
     @observe('component')
     def component_changed(self, new):
         if self._window:
             self._window.component = new['value']

4) Is this the best place to ask question about enaml >= 0.7 and atom?
I don't want to be too far out on the bleeding edge, but the 0.8.2
release from last Friday added a feature I need (Add 'selected_tab'
attribute to the Notebook.)

[1]
https://github.com/enthought/traits-enaml/blob/master/traits_enaml/widgets/enable_canvas.py

Lee Taylor

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

test2.enaml (785 bytes) Download Attachment
test2py.py (240 bytes) Download Attachment
enable_canvas.py (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: enaml, chaco and traits-enaml

Corran Webster
Hi Lee,

thanks for the report, and yes, this is as reasonable a place as any to discuss this.  I'm not currently working with Enaml, so I can't solve all your issues right now, but hopefully I can give some pointers:


On Sun, Oct 13, 2013 at 11:06 PM, Lee Taylor <[hidden email]> wrote:
I'm working on using enaml 0.8.2 with chaco. I want to use the
EnableCanvas from traits-enaml and I have some observations.

1) I'm unable to import EnableCanvas.  It looks like it needs to be
updated for enaml 0.8.

>>> from traits_enaml.widgets.traits_view import EnableCanvas
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../traits_enaml/__init__.py", line 9, in <module>
    from .trait_operators import TRAIT_OPERATORS
  File ".../traits_enaml/trait_operators.py", line 8, in <module>
    from enaml.core.operators import SubscriptionObserver, OperatorBase, op_simple, \
ImportError: cannot import name SubscriptionObserver

Yep, we don't have any Traits-based code on 0.8 right now (I think, others may know better), and the subscription mechanism looks like its been rewritten.
 
2) I copied the file enable_canvas.py[1] from github into my local
directory and tried to use it directly with my sample enaml file
(attached).

$ enaml-run test2.enaml
Traceback (most recent call last):
  File ".../bin/enaml-run", line 9, in <module>
    load_entry_point('enaml==0.8.2', 'console_scripts', 'enaml-run')()
  File ".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/runner.py", line 61, in main
    from enaml.qt.qt_application import QtApplication
  File ".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/qt/__init__.py", line 37, in <module>
    prepare_pyqt()
  File ".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/qt/__init__.py", line 13, in prepare_pyqt
    sip.setapi('QDate', 2)
ValueError: API 'QDate' has already been set to version 1

I'm using enable-4.3, Qt-4.8.5 and PyQt-x11-gpl-4.10.3 on linux.
I was unable to find who was setting it to 1 but I assume it's enable.

This is almost certainly being set in Pyface on the Traits side.  We do this for compatibility with PySide.  This might at least let you resolve things enough to avoid this error.  You should take care that date editors may not work correctly on one side or other of the Traits/Enaml divide.
 
3) I was able to write a python file which imported the enaml file to
work around this problem.  It fails in enable_canvas.py in the
routine:

    def create_widget(self, parent):
        if self.component is not None:
            self._window = Window(parent, component=self.component,
                                  bgcolor=self.component.bgcolor)
            enable_widget = self._window.control
        else:
            self._window = None
            enable_widget = None
        return enable_widget

    @observe('component')
    def component_changed(self, new):
        self._window.component = new['value']

  $ python test2py.py
  File ".../local/enable_canvas.py", line 27, in create_widget
    if self.component is not None:
  File ".../local/enable_canvas.py", line 40, in component_changed
    self._window.component = new['value']
AttributeError: 'NoneType' object has no attribute 'component'

It seems to be calling the observer component_changed while
referencing self.component.  I expected it to call the observer only
when changing component's value.

If I add a test on _window in the observer, it works:
    @observe('component')
    def component_changed(self, new):
        if self._window:
            self._window.component = new['value']

I think we'd accept a PR to fix this in traits_enaml, if you could put one together, assuming it isn't a symptom of other things going wrong (ie. the window doesn't exist for some other reason).
 
4) Is this the best place to ask question about enaml >= 0.7 and atom?
I don't want to be too far out on the bleeding edge, but the 0.8.2
release from last Friday added a feature I need (Add 'selected_tab'
attribute to the Notebook.)

This is as good a place as any, but you are way out on the bleeding edge as far as Enaml usage goes right now.

-- Corran

[1] https://github.com/enthought/traits-enaml/blob/master/traits_enaml/widgets/enable_canvas.py

Lee Taylor

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: enaml, chaco and traits-enaml

Robert Kern
On Mon, Oct 14, 2013 at 12:09 PM, Corran Webster <[hidden email]> wrote:
> On Sun, Oct 13, 2013 at 11:06 PM, Lee Taylor <[hidden email]> wrote:

>> 2) I copied the file enable_canvas.py[1] from github into my local
>> directory and tried to use it directly with my sample enaml file
>> (attached).
>>
>> $ enaml-run test2.enaml
>> Traceback (most recent call last):
>>   File ".../bin/enaml-run", line 9, in <module>
>>     load_entry_point('enaml==0.8.2', 'console_scripts', 'enaml-run')()
>>   File
>> ".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/runner.py",
>> line 61, in main
>>     from enaml.qt.qt_application import QtApplication
>>   File
>> ".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/qt/__init__.py",
>> line 37, in <module>
>>     prepare_pyqt()
>>   File
>> ".../lib/python2.7/site-packages/enaml-0.8.2-py2.7-linux-x86_64.egg/enaml/qt/__init__.py",
>> line 13, in prepare_pyqt
>>     sip.setapi('QDate', 2)
>> ValueError: API 'QDate' has already been set to version 1
>>
>> I'm using enable-4.3, Qt-4.8.5 and PyQt-x11-gpl-4.10.3 on linux.
>> I was unable to find who was setting it to 1 but I assume it's enable.
>
>
> This is almost certainly being set in Pyface on the Traits side.  We do this
> for compatibility with PySide.  This might at least let you resolve things
> enough to avoid this error.  You should take care that date editors may not
> work correctly on one side or other of the Traits/Enaml divide.

We never sip.setapi() to anything but version 2. However, if QDate is
imported and used before the sip.setapi() gets called, it will be
implicitly set to version 1, and PyFace doesn't do sip.setapi('QDate',
2). It probably should, though (the only difference between the two is
the __hash__()). For the workaround, just import enaml.qt before
anything else.

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

Re: enaml, chaco and traits-enaml

_jelle_
Hi Robert,

It probably should - on tvtk / mayavi this issue pops up too...

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