Giter VIP home page Giter VIP logo

easygui_qt's Introduction

EasyGUI_Qt

Inspired by EasyGUI, designed for PyQt

https://raw.githubusercontent.com/aroberge/easygui_qt/master/images/contribute.png

EasyGUI_Qt is a module for simple and easy GUI programming in Python.

EasyGUI_Qt was inspired by EasyGUI created by Stephen Ferg and is based on Tkinter. By contrast, EasyGUI_Qt is based on PyQt which is not included in the standard Python distribution - but is included in some other distributions like Continuum Analytics' Anaconda.

https://badge.fury.io/py/easygui_qt.png https://pypip.in/d/easygui_qt/badge.png 'Stories in Ready'

Python version

Officially, this is a project that targets only Python 3. However, I have now decided to attempt to provide some support for Python 2. Other than some unicode issues, all widgets should work with Python 2.

Design philosophy

Like the original EasyGUI, EasyGUI_Qt seeks to provide simple GUI widgets that can be called in a procedural program. EasyGUI_Qt is NOT event-driven: all GUI interactions are invoked by simple function calls.

The archetype is get_string(message) which pops a box whose purpose is exactly the same as Python's input(prompt), that is, present the user with a question/prompt, have the user enter an answer, and return the provided answer as a string. Thus easygui_qt.get_string() can be used as a drop-in replacement for input(). Similarly, instead of using a print() function to display a message, show_message() is used which pops a message window; however, note that unlike print, show_message interrupts the flow of the program and require some interaction from the user for the program to continue.

Unlike the original EasyGUI, which sometimes used cryptic names like msgbox or ynbox, EasyGUI_Qt attempts to use descriptive names which follow PEP8 convention. Thus, instead of msgbox, it uses show_message; instead of ynbox, it has get_yes_or_no. Most function names start with either get_, show_ or set_.

EasyGUI_QT is based on PyQt; it leverages the available dialogs that come with PyQt whenever possible. This makes it possible to have automatic translation of some GUI elements (such as text on standard buttons) provided the locale is set correctly and that the local distribution of PyQt includes the appropriate translation: when EasyGUI_Qt runs, it scans the standard PyQt location for translation files and note which ones are present and can be used when the locale is set.

An attempt is made at avoiding duplication of essentially identical functionality. Thus, multiple selections from a list of choices is done only one way: by using a dialog where choices appear as labels in text and not labels on buttons.

Roadmap

See #13 and feel free to add comments.

Similar projects

The following is an incomplete lists of a few cross-platform projects that share some similarity with EasyGUI_Qt, but use back-ends other than PyQt

  • easygui: the original; tkinter back-end
  • anygui: multiple back-ends; well known but no longer supported
  • psidialogs: multiple back-ends supported - possibly the most complete project from that point of view.
  • python-dialog: dialog/Xdialog/gdialog back-end

There are quite a few lesser known projects but none that seem to be actively supported. If you are aware of other projects that should be mentioned, do not hesitate to contact me and let me know.

easygui_qt's People

Contributors

achennu avatar aroberge avatar driscollis avatar jeremygray avatar royqh1979 avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easygui_qt's Issues

tests under python 2.7

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.

  1. 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

  2. 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.

  3. 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.)

  4. And then tests still fail with AssertionErrors

A simple question with matplotlib plot window

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.

Roadmap: widget to implement (and other added functionality)

Using this "issue" to document what should be implemented by version 1.0. People should feel free to comment.

  1. equivalent to easygui.ccbox(); probably called get_cancel_or_continue() and implemented via a PyQt "warning" dialog.Done
  2. equivalent to easygui.exception() - probably called handle_exception() and implemented via a PyQt "critical" dialog. Done
  3. equivalent to easygui.passwordbox() - probably called get_password() Done
  4. equivalent to easygui.textbox() - probably called show_text() Done name = show_file
  5. equivalent to easygui.codebox() - probably called show_code() Done name=show_file ... or show_code, depending on how the code is obtained.
  6. equivalent to easygui.multenterbox() - probably called get_fields() and returning a dict Done name=get_many_strings
  7. get_color_rgb() - implemented via PyQt's color dialog Done
  8. get_color_hex() Done
  9. get_date() - with a nice calendar dialog Done
  10. set_font_family() ? [to complement set_font_size()]
  11. possibly set_default_position(); right now the widgets are displayed centered on the screen, it might make sense to position them at a user-defined location (I believe this was a request for the original easygui)
  12. possibly implement get_username_and_password() with a viewable username field and a "masked" password field. Done
  13. possibly implement show_image()
  14. possibly implement get_image_selection() : showing multiples images and having the user choosing one of them; something very similar to the idea of get_choice() used for text items.
  15. An about dialog (with possible variations) - see description in comment below.: Note: most of this is available using show_file, with an appropriate html file.
  16. Change password dialog (with verification/confirmation of new password) Done
  17. Possible variation of get_fields (see 6 above) where some fields can be specified to be masked. Done name=get_many_strings()

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 ...)

easygui_qt.demos "Error importing PyQt5"

All buttons in the demo give me the error:

Error importing PyQt5. Have you installed it?
could not find function get_int

I am running Python version 3.9.0

imac:~ mel$ python -V
Python 3.9.0

Screen Shot

cannot find suitable PyQt installation

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

modalSession exits prematurely

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.

get_many_strings() return orderDict,which is not good for use

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?

persistent unresponsive window (python 2.7.8)

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.

issue with get_file_names(), get_save_file_name()

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'

cast return values to standard types?

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.

parameter errors in demo guessing_game.py

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'

Press "Cancel" on get_yes_or_no return False, not None.

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

hidden window problem

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.)

python 2.7 subprocess issues (affects launcher demo)

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.

get_date returns string instead of datetime.date

In the documentation it says that the output of the CalendarWidget would be a datetime.date object.

bildschirmfoto - 28 11 2016 - 20 51 42

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.

Save settings in local file

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.

Add optional argument handling to _launch_widget.py

_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.

ModuleNotFoundError

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'

error message in get_file_names

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

PyQt 5 or PySide support

Will easygui_qt eventually support PyQt5 or PySide? I already have PyQt5 on my machine so I cannot install PyQt4.

Bug with multichoice selector

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:

  1. Press select all with the mouse (or keyboard)
  2. Press 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.