enthought / traitsui

TraitsUI: Traits-capable windowing framework
http://docs.enthought.com/traitsui
Other
297 stars 96 forks source link

InstanceEditor Demo Raises TraitError #331

Closed jvickroy closed 7 years ago

jvickroy commented 7 years ago

0 down vote favorite 1

The InstanceEditor demo example at Enthought GitHub Repository raises the following exception:

    Traceback (most recent call last):
  File "C:\Users\jgv\AppData\Local\Programs\Python\Python36\lib\site-packages\traitsui\ui.py", line 232, in dispose
    self.result = result
  File "C:\Users\jgv\AppData\Local\Programs\Python\Python36\lib\site-packages\traits\trait_handlers.py", line 172, in error
    value )
traits.trait_errors.TraitError: The 'result' trait of an UI instance must be a boolean, but a value of <PyQt4.QtCore.QObject object at 0x000001EA249AEB88> <class 'PyQt4.QtCore.QObject'> was specified.
Traceback (most recent call last):
  File "C:\Users\jgv\AppData\Local\Programs\Python\Python36\lib\site-packages\traitsui\ui.py", line 232, in dispose
    self.result = result
  File "C:\Users\jgv\AppData\Local\Programs\Python\Python36\lib\site-packages\traits\trait_handlers.py", line 172, in error
    value )
traits.trait_errors.TraitError: The 'result' trait of an UI instance must be a boolean, but a value of <PyQt4.QtCore.QObject object at 0x000001EA249AEB88> <class 'PyQt4.QtCore.QObject'> was specified.

when the user interface is used to specify a trait setting.

My system is: Python 3.6.0, traits 4.6.0, PyQt4-4.11.4, and Microsoft Windows 10.

I have personal code, of a similar nature, that also triggers the same error.

corranwebster commented 7 years ago

Thanks for the report. I can replicate this on OS X under Python 3.5 as well (and I suspect it will be seen on other platforms and Python versions too).

corranwebster commented 7 years ago

This code seems sufficient to trigger:

from traits.api import HasTraits, Instance, Str
from traitsui.api import View, Item

class OtherClass(HasTraits):

    other_value = Str

    view = View('other_value', buttons=['OK'])

class Test(HasTraits):

    other = Instance(OtherClass, ())

    view = View(
        Item('other', style='simple'),
        buttons=['OK'],
    )

if __name__ == '__main__':
    test = Test()
    test.configure_traits()

To replicate: run, click button to open instance editor, close dialogs.

Only happens under Qt.

jvickroy commented 7 years ago

Thanks for your fast response! Using your simplified example code (above) to reproduce the behavior, I changed other_value = Str to other_value = Enum(['a','b']) and tried the new version of instance_editor.py. Now, the Enum is no longer properly handled in the user interface. Perhaps, I have done something wrong.

corranwebster commented 7 years ago

Are you using the current master of pyface from github as well? We've been refactoring code somewhat between the two libraries recently, so that may account for any problems you are running in to. Or it may be something else is happening. When you say that Enum isn't properly handled in the UI, what exactly is going wrong?

jvickroy commented 7 years ago

Hi Corran. Thanks so much for your fast responses! I am a traits novice and I really like the package.

Please see my inline comments below.

------ Original Message ------ From: "Corran Webster" notifications@github.com To: "enthought/traitsui" traitsui@noreply.github.com Cc: "jvickroy" jgv.home@gmail.com; "Author" author@noreply.github.com Sent: 1/16/2017 8:37:52 AM Subject: Re: [enthought/traitsui] InstanceEditor Demo Raises TraitError (#331)

Are you using the current master of pyface from github as well?

I am not. I have only installed packages using binary installers. I am not familiar with github and need to understand it. We've been refactoring code somewhat between the two libraries recently, so that may account for any problems you are running in to. Or it may be something else is happening.

When you say that Enum isn't properly handled in the UI, what exactly is going wrong?

Apologies for the vague description. With the previous version of qt4\instance_editor.py (the one raising TraitError), an "Other" Button is presented which, when clicked presents, as expected, an "Other value" drop-down list widget of the enumeration choices. With the new version of instance_editor.py, which I copied from github into the Python36\Lib\site-packages\traitsui\qt4 folder, a read-only, string field, containing what may be a memory address, is presented instead of an "Other" Button.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

corranwebster commented 7 years ago

That sounds like something is going wrong during the editor setup. Can you set the TRAITS_DEBUG environment variable to 1 (or any other non-empty value) and run again and report any errors you see.

jvickroy commented 7 years ago

The following script:

ETSConfig.toolkit = 'qt4'

from traits.api import HasTraits, Instance, Enum
from traitsui.api import View, Item

import traits
print ('traits version:',traits.__version__)
import os
os.environ['TRAITS_DEBUG'] = '1'

class OtherClass(HasTraits):
    other_value = Enum (['a','b','c'])
    view = View('other_value', buttons=['OK'])

class Test(HasTraits):
    other = Instance(OtherClass, ())
    view = View(
        Item('other', style='simple'),
        buttons=['OK'],
    )

if __name__ == '__main__':
    print ('TRAITS_DEBUG :',os.environ.get('TRAITS_DEBUG'))
    test = Test()
    test.configure_traits()

produces the following output:


traits version: 4.6.0
TRAITS_DEBUG : 1

C:\Users\jgv\Documents\Projects\Astronomy\Imaging\database>```

Unfortunately, there are no diagnostic messages.
corranwebster commented 7 years ago

I can't replicate the issue you're seeing. What happens if you start up an interactive python prompt and do something like from traitsui.qt4.instance_editor import SimpleEditor?

I'm going to merge #332 and mark the issue as resolved, but feel free to re-open it if you continue to see problems, particularly after the next release.

jvickroy commented 7 years ago

What happens if you start up an interactive python prompt and do something like from traitsui.qt4.instance_editor import SimpleEditor?

>>> 
>>> from traitsui.qt4.instance_editor import SimpleEditor
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "\\JV-HP-DESKTOP\Users\jgv\AppData\Local\Programs\Python\Python36\lib\site-packages\traitsui\qt4\instance_editor.py", line 585, in <module>
    from editor \
ModuleNotFoundError: No module named 'editor'
>>>

I see some imports, in the former version of qt4.instance_editor, differ from those in this new version by performing dot imports as follows:

from .editor \
    import Editor
from .constants \
    import DropColor
from .helper \
    import position_window

Why is this?

... feel free to re-open it if you continue to see problems, particularly after the next release.

When is the next release and how can I be notified?

corranwebster commented 7 years ago

Ah! Yes, you are running under Python 3, but the source code is currently written for Python 2 and then converted to Python 3 using 2to3 (that's what inserted the . in front of all the imports) on install, so you can't just copy the file into your Python 3 install. Try doing this:

As for the when the next release is, we don't currently have a date set, but would expect sometime in the next 3 months. Qt5 support is probably the biggest thing I'd like to get into the next release, but it is currently held up by technical issues around continuous testing. If those issues continue, we'll probably give up and make a release sooner rather than later.

When we update we currently push releases to PyPI and this project's releases page. See http://stackoverflow.com/questions/17395151/how-can-i-subscribe-to-updates-of-a-package-on-pypi for some suggestions about how to monitor PyPI for updates.

jvickroy commented 7 years ago

Ah! Yes, you are running under Python 3, but the source code is currently written for Python 2 and then converted to Python 3 using 2to3 (that's what inserted the . in front of all the imports) on install, so you can't just copy the file into your Python 3 install. Try doing this:

get the new version of the instance_editor.py file
do 2to3 instance_editor.py
copy the changed version of the file into your install

Thanks. All is well now. FWIW, I did have to insert the dot qualifier, for the editor, constants, and help imports, by hand; 2to3.py did not do this.

When we update we currently push releases to PyPI and this project's releases page. See http://stackoverflow.com/questions/17395151/how-can-i-subscribe-to-updates-of-a-package-on-pypi for some suggestions about how to monitor PyPI for updates.

Thanks for this information.