aroberge / easygui_qt

Inspired by easygui, designed for PyQt
BSD 3-Clause "New" or "Revised" License
59 stars 18 forks source link

modalSession exits prematurely #3

Open jeremygray opened 9 years ago

jeremygray commented 9 years ago

I know that Python 3 is the intended version to use, and testing is done on 3.4. Things seems to work with Python 2.7.8, and it would be nice if they did. But I typically get the warning / error message below.

>>> from easygui_qt.easygui_qt import *
>>> get_int()
2014-12-26 11:04:26.769 python[93886:303] modalSession has been exited prematurely - check for a reentrant call to endModalSession:
1

I get the same thing when calling that code as a script. Any ideas? I see the with_app decorator but just looking at it can't follow the logic of the inner _decorator.

aroberge commented 9 years ago

I'm downloading/installing Python 2 as a conda environment so that I can run the tests and see if I can fix this.

aroberge commented 9 years ago

I can not reproduce this bug.

Python 2.7.9 |Continuum Analytics, Inc.| (default, Dec 18 2014, 16:57:52) [MSC v.1500 64 bit (AMD64)] on win32
...
>>> from easygui_qt.easygui_qt import *
>>> get_list_of_choices()
[PyQt4.QtCore.QString(u'Item 3'), PyQt4.QtCore.QString(u'Item 7')]
>>> get_int()
3
>>> get_int()   # pressing cancel
>>> get_int()   # closing the window
>>>
aroberge commented 9 years ago

Explanation about the inner decorator mentioned when this issue was first open. The logic of the inner decorator can be greatly simplified if one does not call set_locale or select_language; Without these two, the code for the inner decorator would simply be:

def _decorator(*args, **kwargs):
    app = SimpleApp()
    response = func(*args, **kwargs)
    app.quit()
    return response

set_locale() and select_language() require that an app instance be passed as one of the parameters so that language/locale choices can be recorded. (I'm thinking of doing this differently in the future so that this approach will no longer be needed.)

So, the simple version of the inner decorator above changes so as to first add "app" as one of the kwargs and try running the function; if "app" was not a valid keyword argument in the first place, and exception is caught. With Python 3.3+, there is a way to find out if "app" was indeed an expected keyword argument. For earlier version, we just assume that the exception was raised for this reason; for Python 3.3, we examine to see if the unexpected "app" was the reason for the exception: if it looks like it, we just run the program again, otherwise we raise the exception.

jeremygray commented 9 years ago

This issue might be mac-specific: https://bugreports.qt-project.org/browse/QTBUG-37699