aroberge / easygui_qt Goto Github PK
View Code? Open in Web Editor NEWInspired by easygui, designed for PyQt
License: BSD 3-Clause "New" or "Revised" License
Inspired by easygui, designed for PyQt
License: BSD 3-Clause "New" or "Revised" License
Will easygui_qt eventually support PyQt5 or PySide? I already have PyQt5 on my machine so I cannot install PyQt4.
The mutliple choice selector has a bug in it. How to reproduce the bug:
import easygui_qt as eg
eg.get_list_of_choices()
As expected, this opens up a selector with 10 items. Now, do the following:
Esc
The returned list contains all the items in the choices. Isn't the Esc
key supposed to cancel the selection, just like Enter
finalizes it?
There is no explicit code in the multichoice.py
file which links the Esc
key, so it must be done internally in Qt. I thought a way to fix this would be to add this method to the dialog class:
def keyPressEvent(self, e):
if e.key() == QtCore.Qt.Key_Escape:
self.cancel()
elif e.key() == QtCore.Qt.Key_Enter:
self.selection_completed()
else:
super(MultipleChoicesDialog, self).keyPressEvent(e)
I don't know if this is canonical Qt way of handling the event, but this fixes the problem. I have included it in my pull request.
Now get_many_strings return an OrderedDict as the result, which is no easy to use if the labels is long or descriptive.
For example, If I have
import easygui_qt as easy values=easy.get_many_strings("Please input lengths of the triangle",lables=("length of a=","length of b=","length of c=")
I must use values["length of a="] / values["length of b=“] to retrive the results of the input,which is not so easy for use.
I wonder if we could add index/value pairs to the returned OrderedDict, so we can use values[0]/values[1] to retrieve results?
As discussed in issue #6 , there remains some problems with unicode handling for Python 2.7
get_string(), if passed the string "André" produces an error.
Please add a buttonbox like in easygui
Using this "issue" to document what should be implemented by version 1.0. People should feel free to comment.
I do not plan to implement an equivalent of the following from easygui:
easygui.buttonbox - use get_list_of_choices() instead (however, see comment from @jeremygray below ...)
_launch_widget.py is a "private" file in the demos subdirectory; it is executed as a subprocess by launcher.py to demonstrate what the various gui components are capable of doing. It might be very useful to be able to pass "arbitrary" arguments to it, arguments that could then be used in the function call.
Under python 2.7.8 (anaconda), I cannot even try out get_file_names()
or get_save_file_name()
:
>>> from easygui_qt.easygui_qt import *
>>> get_file_names()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jgray/code/easygui_qt/easygui_qt/easygui_qt.py", line 56, in _decorator
response = func(*args, **kwargs)
File "/Users/jgray/code/easygui_qt/easygui_qt/easygui_qt.py", line 570, in get_file_names
"All Files (*.*)", options)
TypeError: QFileDialog.getOpenFileNames(QWidget parent=None, QString caption=QString(), QString directory=QString(), QString filter=QString(), QString selectedFilter=None, QFileDialog.Options options=0): argument 5 has unexpected type 'Options'
In the documentation it says that the output of the CalendarWidget would be a datetime.date object.
This would be great for further processing but I get a string.
>>> date = easy.get_date("Select a date.")
>>> print(type(date))
<class 'str'>
Is it possible to return a datetime.date instance because a string is difficult to handle.
Maybe supporting python 2.7 is too much of a hassle...
The launcher demo is not working for me on 2.7.8, due to subprocess.check_input
expecting a list rather than string. The launcher is shown, but when trying to launch anything I get same the OSError:
>>> launcher.main()
Traceback (most recent call last):
File "easygui_qt/demos/launcher.py", line 153, in get_string
output = launch('get_string')
File "easygui_qt/demos/launcher.py", line 24, in launch
output = subprocess.check_output('python {} {}'.format(filename, name))
File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
For me, passing a string to subprocess fails:
>>> v = subprocess.check_output('python -c "import sys; print(sys.version)"')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/Users/jgray/anaconda/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
But doing as a list works as intended:
>>> v = subprocess.check_output(['python', '-c', "import sys; print(sys.version)"])
>>> v
'2.7.8 |Anaconda 2.0.1 (x86_64)| (default, Aug 21 2014, 15:21:46) \n[GCC 4.2.1 (Apple Inc. build 5577)]\n'
and when I hardcode that, then the launcher > python version button works as expected.
Hello
Thanks for this wonderful project. It is exactly what I searched for replacing some bash scripts using kdialog.
Unfortunately, I've got an error message using get_file_names() on Linux:
>>> easy.get_file_names()
QSettings::value: Empty key passed
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/alex/.local/lib/python3.9/site-packages/easygui_qt/easygui_qt.py", line 751, in get_file_names
files = qt_widgets.QFileDialog.getOpenFileNames(None, title, os.getcwd(),
TypeError: getOpenFileNames(parent: QWidget = None, caption: str = '', directory: str = '', filter: str = '', initialFilter: str = '', options: Union[QFileDialog.Options, QFileDialog.Option] = 0): argument 5 has unexpected type 'Options'
Same thing with the function get_save_file_name()
System is:
Linux 5.13.19-2-MANJARO x86_64 with KDE (Qt 5.15.2)
Thanks for your help
At least on Mac 10.9.5, python 2.7.8, various dialogs typically appear underneath another window (= invisible). For the launcher.py demo, I can make the main launcher appear on top of the terminal window that I call it from by adding 3 lines to the end of class Dialog.__init__
:
self.show()
self.raise_()
self.activateWindow()
To have various functions in easygui_qt.py
show up on top after launching, instead of everything in one line (here forget_string()
):
text, ok = QtGui.QInputDialog().getText(None, title, message,
QtGui.QLineEdit.Normal,
default_response, flags)
this works for me:
dialog = QtGui.QInputDialog()
dialog.show()
dialog.raise_()
text, ok = dialog.getText(None, title, message,
QtGui.QLineEdit.Normal,
default_response, flags)
I just committed a version of this to a temp branch. If it works in python 3 and non-Mac I'll tweak the other functions. (I presume its already showing on top properly, so my question is whether things break or not when adding these calls.)
Hey, all,
I have a question with matplotlib. When I run a simple code like this:
import matplotlib.pyplot as plt
import easygui_qt as easy
plt.ion()
plt.plot([1,2,3])
easy.get_int()
after I enter the integer and close the qt window, the plot window just crashes and cannot be closed. Any ideas?
This won't happen when I use easygui. So tkinter does not have such issue.
Currently, settings (language and font) are saved in a global object that remains available during a session; however, they have to be reinitialized every time the program is run. Furthermore, this require some added complication to the with_app decorator, as explained in a comment on Issue#3.
A nice enhancement would be so save/retrieve such configuration values in a local file - probably using pickle since the font selection is a QFont object. Doing this would likely allow to simplify the with_app decorator substantially.
In documentation:
get_yes_or_no return True for “Yes”, False for “No”, and None for “Cancel”.
So when i press “Cancel” get_yes_or_no return False, not None.
Windows 10 x64, Python 3.6, PyQT5, easygui_qt 0.9.3
File "D:\Program Files\Python36\lib\site-packages\easygui_qt_init_.py", line 6, in
from .easygui_qt import *
File "D:\Program Files\Python36\lib\site-packages\easygui_qt\easygui_qt.py", line 32, in
import language_selector
ModuleNotFoundError: No module named 'language_selector'
File "D:\Program Files\Python36\lib\site-packages\easygui_qt\utils.py", line 125, in
class MyPageDialog(QtGui.QDialog):
AttributeError: module 'PyQt5.QtGui' has no attribute 'QDialog'
easygui_qt looks nice. I'm playing with it in Python 2.7.8 (Anaconda 2.0.1 (x86_64)).
get_int
returns a python <type 'int'>
, but some of the return values are of type PyQt4.QtCore.xxx
:
>>> from easygui_qt.easygui_qt import *
>>> get_list_of_choices()
[PyQt4.QtCore.QString(u'Item 8'), PyQt4.QtCore.QString(u'Item 9'), PyQt4.QtCore.QString(u'Item 0'), PyQt4.QtCore.QString(u'Item 7'), PyQt4.QtCore.QString(u'Item 3'), PyQt4.QtCore.QString(u'Item 4')]
>>>
>>> map(unicode, get_list_of_choices())
[u'Item 3', u'Item 8', u'Item 5']
Its easy enough for the user to cast the return values to standard python types, but maybe this could / should be done within easygui_qt itself (prior to returning the values). The only reason I can think of not to do that would be performance (slightly slower, more memory), but that should be negligible in the context of a gui.
I tried demo on Linux, and got:
Traceback (most recent call last):
File "/usr/local/lib/python3.2/dist-packages/easygui_qt/init.py", line 53, in _decorator
response = func(_args, *_kwargs)
TypeError: show_message() got an unexpected keyword argument 'app'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "guessing_game.py", line 54, in
eg.show_message("Temporarily setting the locale to Spanish")
File "/usr/local/lib/python3.2/dist-packages/easygui_qt/init.py", line 55, in _decorator
sig = inspect.signature(func)
AttributeError: 'module' object has no attribute 'signature'
Either installing from the repo clone using
python setup.py install
or
pip install easygui_qt
I get the error
Could not find suitable distribution for Requirement.parse('PyQt4')
PyQt4 is install and importable. This is with python 2.7.9 under OSX 10.8.5
Automated tests would make it much easier to support both python 2.7 and 3.4, e.g., using https://travis-ci.org
I tried to get tests to run using python -m unittest discover
from the command line, but had multiple issues.
Fixed PIL not being able to import Image by:
% sudo mkdir -p /opt/anaconda1anaconda2anaconda3/lib/
% sudo ln /Users/jgray/anaconda/lib/libtiff.5.dylib /opt/anaconda1anaconda2anaconda3/lib/libtiff.5.dylib
See branch p2-tests-work-in-progress
for tweaks needed to test_easygui_qt.py
for it to be able to even run. These are just notes to share, not something to merge in this form.
The windows that come up are always behind other windows for me, and I have to manually bring them to the foreground in order for pyautogui to be able to send key-presses, etc. (This is a problem for me during normal usage, not just tests.)
And then tests still fail with AssertionErrors
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
.
The launcher demo works fine, but when I try to use the functions as a library, a GUI pops up and returns the value I set, but does not then go away. The window just becomes unresponsive and cannot be canceled or dismissed.
>>> import easygui_qt.easygui_qt as ez
>>> ez.get_int()
[warning message here: "modalSession has been exited prematurely blah blah", don't think its relevant but it might be; I get that with the launcher demo, which works anyway]
1
>>>
Same behavior from a script or interactive python session.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.