././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1648817217.7610354
easygui-0.98.3/ 0000777 0000000 0000000 00000000000 00000000000 010154 5 ustar 00 ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/LICENSE 0000666 0000000 0000000 00000002753 00000000000 011170 0 ustar 00 Copyright 2021 Easygui developers and Stephen Raymond Ferg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648817194.0
easygui-0.98.3/MANIFEST.in 0000666 0000000 0000000 00000000021 00000000000 011703 0 ustar 00 include README.md ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1648817217.7610354
easygui-0.98.3/PKG-INFO 0000666 0000000 0000000 00000020601 00000000000 011250 0 ustar 00 Metadata-Version: 2.1
Name: easygui
Version: 0.98.3
Summary: EasyGUI is a module for very simple, very easy GUI programming in Python. EasyGUI is different from other GUI generators in that EasyGUI is NOT event-driven. Instead, all GUI interactions are invoked by simple function calls.
Home-page: https://github.com/robertlugg/easygui
Author: easygui developers and Stephen Ferg
Author-email: robert.lugg@gmail.com
License: BSD
Keywords: gui linux windows graphical user interface
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: User Interfaces
Description-Content-Type: text/markdown
License-File: LICENSE
Project in Maintainance
=======================
Hi everyone. There hasn't been much activity but thankfully we have a new revision. Thank you contributors and thank you Stephen Ferg for creating EasyGui.
You might also consider the following alternatives:
- https://github.com/aroberge/easygui_qt
- https://github.com/ponty/psidialogs
For those who wish to contribute you are welcome to fork this respository. Or, take a look at the alternatives and contribute there.
Kind Regards, Robert
EasyGUI
=======
EasyGUI is a module for very simple, very easy GUI programming in Python. EasyGUI is different from other GUI
libraries in that EasyGUI is NOT event-driven. Instead, all GUI interactions are invoked by simple function calls.
EasyGUI runs on Python 2 and 3, and does not have any dependencies beyond python and Tk. Linux Python 2 users will have to run `sudo apt-get install python-tk` and Linux Python 3 users will have to run `sudo apt-get install python3-tk` to install Tkinter.
Example Usage
-------------
>>> import easygui
>>> easygui.ynbox('Shall I continue?', 'Title', ('Yes', 'No'))
1
>>> easygui.msgbox('This is a basic message box.', 'Title Goes Here')
'OK'
>>> easygui.buttonbox('Click on your favorite flavor.', 'Favorite Flavor', ('Chocolate', 'Vanilla', 'Strawberry'))
'Chocolate'
To see demo programs using EasyGUI, call the `easygui.egdemo()` function.
Full documentation is always available.
For the most-recent production version:
.
For our develop version which will be released next:
.
0.98.3
========================================================================
Update collections.abc import location (old location was deprecated since version 3.3, removed in version 3.10)
See: https://docs.python.org/3.9/library/collections.html#module-collections for details
Add some unit test coverage and test automation for TravisCI.
0.98.2
========================================================================
Several updates and fixes thanks to Al and others.
0.98.0
========================================================================
This is an exciting time for easygui. We continue to make good progress with refactoring as
well as some enhancements and bug fixes here and there.
We would like to welcome Juanjo Denis-Corrales to the team. He is responsible for lots of good new work
this release. Of course we appreciate the work of everyone who contributed.
NOTE: I decided in this release to change the API a bit. Please consult the function documentation for details.
BUG FIXES
---------
* Made changes guessing at fixes to any IDLE problems. Please report any problems found.
ENHANCEMENTS
------------
* Refactored the easygui.py file into several smaller files to improve our ability to manage the code
* Added callbacks to allow for more dynamic dialogs. See the docs for usage.
* Added class access to dialogs so properties may be changed.
KNOWN ISSUES
------------
* There were previous issues when using easygui with the IDLE IDE. I hope I resolved these problems, however,
I've never actually been able to repeat them. Please report any problems found in github.
OTHER CHANGES
-------------
* Centralized the Python 2 versus Python 3 "compatibility layer" into boxes/utils.py
0.97.4
========================================================================
This is a minor bug-fix release to address python 3 import errors.
0.97.3
========================================================================
We are happy to release version 0.97.3 of easygui. The intent of this release is to address some basic
functionality issues as well as improve easygui in the ways people have asked.
Robert Lugg (me) was searching for a GUI library for my python work. I saw easygui and liked very much its
paradigm. Stephen Ferg, the creator and developer of easygui, graciously allowed me to start development
back up. With the help of Alexander Zawadzki, Horst Jens, and others I set a goal to release before the
end of 2014.
We rely on user feedback so please bring up problems, ideas, or just say how you are using easygui.
BUG FIXES
---------
* sourceforge #4: easygui docs contain bad references to easygui_pydoc.html
* sourceforge #6: no index.html in docs download file. Updated to sphinx which as autolinking.
* sourceforge #8: unicode issues with file*box. Fixed all that I knew how.
* sourceforge #12: Cannot Exit with 'X'. Now X and escape either return "cancel_button", if set, or None
ENHANCEMENTS
------------
* Added ability to specify default_choice and cancel_choice for button widgets (See API docs)
* True and False are returned instead of 1 and 0 for several boxes
* Allow user to map keyboard keys to buttons by enclosing a hotkey in square braces like: "Pick [M]e", which would assign
keyboard key M to that button. Double braces hide that character, and keysyms are allowed:
[[q]]Exit Would show Exit on the button, and the button would be controlled by the q key
[]Help Would show Help on the button, and the button would be controlled by the F1 function key
NOTE: We are still working on the exact syntax of these key mappings as Enter, space, and arrows are already being used.
* Escape and the windows 'X' button always work in buttonboxes. Those return None in that case.
* sourceforge #9: let fileopenbox open multiple files. Added optional argument 'multiple'
* Location of dialogs on screen is preserved. This isn't perfect yet, but now, at least, the dialogs don't
always reset to their default position!
* added some, but not all of the bugs/enhancements developed by Robbie Brook:
http://all-you-need-is-tech.blogspot.com/2013/01/improving-easygui-for-python.html
KNOWN ISSUES
------------
* In the documentation, there were previous references to issues when using the IDLE IDE. I haven't
experienced those, but also didn't do anything to fix them, so they may still be there. Please report
any problems and we'll try to address them
* I am fairly new to contributing to open source, so I don't understand packaging, pypi, etc. There
are likely problems as well as better ways to do things. Again, I appreciate any help or guidance.
Other Changes (that you likely don't care about)
------------------------------------------------
* Restructured loading of image files to try PIL first throw error if file doesn't exist.
* Converted docs to sphinx with just a bit of doctest. Most content was retained from the old site, so
there might be some redundancies still. Please make any suggested improvements.
* Set up a GitHub repository for development: https://github.com/robertlugg/easygui
* Improved output/packaging for Debian distribution
EasyGui is licensed under what is generally known as
the "modified BSD license" (aka "revised BSD", "new BSD", "3-clause BSD").
This license is GPL-compatible but less restrictive than GPL.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648817194.0
easygui-0.98.3/README.md 0000666 0000000 0000000 00000016027 00000000000 011441 0 ustar 00 Project in Maintainance
=======================
Hi everyone. There hasn't been much activity but thankfully we have a new revision. Thank you contributors and thank you Stephen Ferg for creating EasyGui.
You might also consider the following alternatives:
- https://github.com/aroberge/easygui_qt
- https://github.com/ponty/psidialogs
For those who wish to contribute you are welcome to fork this respository. Or, take a look at the alternatives and contribute there.
Kind Regards, Robert
EasyGUI
=======
EasyGUI is a module for very simple, very easy GUI programming in Python. EasyGUI is different from other GUI
libraries in that EasyGUI is NOT event-driven. Instead, all GUI interactions are invoked by simple function calls.
EasyGUI runs on Python 2 and 3, and does not have any dependencies beyond python and Tk. Linux Python 2 users will have to run `sudo apt-get install python-tk` and Linux Python 3 users will have to run `sudo apt-get install python3-tk` to install Tkinter.
Example Usage
-------------
>>> import easygui
>>> easygui.ynbox('Shall I continue?', 'Title', ('Yes', 'No'))
1
>>> easygui.msgbox('This is a basic message box.', 'Title Goes Here')
'OK'
>>> easygui.buttonbox('Click on your favorite flavor.', 'Favorite Flavor', ('Chocolate', 'Vanilla', 'Strawberry'))
'Chocolate'
To see demo programs using EasyGUI, call the `easygui.egdemo()` function.
Full documentation is always available.
For the most-recent production version:
.
For our develop version which will be released next:
.
0.98.3
========================================================================
Update collections.abc import location (old location was deprecated since version 3.3, removed in version 3.10)
See: https://docs.python.org/3.9/library/collections.html#module-collections for details
Add some unit test coverage and test automation for TravisCI.
0.98.2
========================================================================
Several updates and fixes thanks to Al and others.
0.98.0
========================================================================
This is an exciting time for easygui. We continue to make good progress with refactoring as
well as some enhancements and bug fixes here and there.
We would like to welcome Juanjo Denis-Corrales to the team. He is responsible for lots of good new work
this release. Of course we appreciate the work of everyone who contributed.
NOTE: I decided in this release to change the API a bit. Please consult the function documentation for details.
BUG FIXES
---------
* Made changes guessing at fixes to any IDLE problems. Please report any problems found.
ENHANCEMENTS
------------
* Refactored the easygui.py file into several smaller files to improve our ability to manage the code
* Added callbacks to allow for more dynamic dialogs. See the docs for usage.
* Added class access to dialogs so properties may be changed.
KNOWN ISSUES
------------
* There were previous issues when using easygui with the IDLE IDE. I hope I resolved these problems, however,
I've never actually been able to repeat them. Please report any problems found in github.
OTHER CHANGES
-------------
* Centralized the Python 2 versus Python 3 "compatibility layer" into boxes/utils.py
0.97.4
========================================================================
This is a minor bug-fix release to address python 3 import errors.
0.97.3
========================================================================
We are happy to release version 0.97.3 of easygui. The intent of this release is to address some basic
functionality issues as well as improve easygui in the ways people have asked.
Robert Lugg (me) was searching for a GUI library for my python work. I saw easygui and liked very much its
paradigm. Stephen Ferg, the creator and developer of easygui, graciously allowed me to start development
back up. With the help of Alexander Zawadzki, Horst Jens, and others I set a goal to release before the
end of 2014.
We rely on user feedback so please bring up problems, ideas, or just say how you are using easygui.
BUG FIXES
---------
* sourceforge #4: easygui docs contain bad references to easygui_pydoc.html
* sourceforge #6: no index.html in docs download file. Updated to sphinx which as autolinking.
* sourceforge #8: unicode issues with file*box. Fixed all that I knew how.
* sourceforge #12: Cannot Exit with 'X'. Now X and escape either return "cancel_button", if set, or None
ENHANCEMENTS
------------
* Added ability to specify default_choice and cancel_choice for button widgets (See API docs)
* True and False are returned instead of 1 and 0 for several boxes
* Allow user to map keyboard keys to buttons by enclosing a hotkey in square braces like: "Pick [M]e", which would assign
keyboard key M to that button. Double braces hide that character, and keysyms are allowed:
[[q]]Exit Would show Exit on the button, and the button would be controlled by the q key
[]Help Would show Help on the button, and the button would be controlled by the F1 function key
NOTE: We are still working on the exact syntax of these key mappings as Enter, space, and arrows are already being used.
* Escape and the windows 'X' button always work in buttonboxes. Those return None in that case.
* sourceforge #9: let fileopenbox open multiple files. Added optional argument 'multiple'
* Location of dialogs on screen is preserved. This isn't perfect yet, but now, at least, the dialogs don't
always reset to their default position!
* added some, but not all of the bugs/enhancements developed by Robbie Brook:
http://all-you-need-is-tech.blogspot.com/2013/01/improving-easygui-for-python.html
KNOWN ISSUES
------------
* In the documentation, there were previous references to issues when using the IDLE IDE. I haven't
experienced those, but also didn't do anything to fix them, so they may still be there. Please report
any problems and we'll try to address them
* I am fairly new to contributing to open source, so I don't understand packaging, pypi, etc. There
are likely problems as well as better ways to do things. Again, I appreciate any help or guidance.
Other Changes (that you likely don't care about)
------------------------------------------------
* Restructured loading of image files to try PIL first throw error if file doesn't exist.
* Converted docs to sphinx with just a bit of doctest. Most content was retained from the old site, so
there might be some redundancies still. Please make any suggested improvements.
* Set up a GitHub repository for development: https://github.com/robertlugg/easygui
* Improved output/packaging for Debian distribution
EasyGui is licensed under what is generally known as
the "modified BSD license" (aka "revised BSD", "new BSD", "3-clause BSD").
This license is GPL-compatible but less restrictive than GPL.
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/README.txt 0000666 0000000 0000000 00000014045 00000000000 011656 0 ustar 00 EasyGUI
=======
EasyGUI is a module for very simple, very easy GUI programming in Python. EasyGUI is different from other GUI
libraries in that EasyGUI is NOT event-driven. Instead, all GUI interactions are invoked by simple function calls.
EasyGUI runs on Python 2 and 3, and does not have any dependencies beyond python and Tk.
Example Usage
-------------
>>> import easygui
>>> easygui.ynbox('Shall I continue?', 'Title', ('Yes', 'No'))
1
>>> easygui.msgbox('This is a basic message box.', 'Title Goes Here')
'OK'
>>> easygui.buttonbox('Click on your favorite flavor.', 'Favorite Flavor', ('Chocolate', 'Vanilla', 'Strawberry'))
'Chocolate'
Full documentation is always available.
For the most-recent production version:
.
For our develop version which will be released next:
.
0.98.2
========================================================================
Several updates and fixes thanks to Al and others.
0.98.0
========================================================================
This is an exciting time for easygui. We continue to make good progress with refactoring as
well as some enhancements and bug fixes here and there.
We would like to welcome Juanjo Denis-Corrales to the team. He is responsible for lots of good new work
this release. Of course we appreciate the work of everyone who contributed.
NOTE: I decided in this release to change the API a bit. Please consult the function documentation for details.
BUG FIXES
---------
* Made changes guessing at fixes to any IDLE problems. Please report any problems found.
ENHANCEMENTS
------------
* Refactored the easygui.py file into several smaller files to improve our ability to manage the code
* Added callbacks to allow for more dynamic dialogs. See the docs for usage.
* Added class access to dialogs so properties may be changed.
* in integerbox, allowed lower and upper bounds to be None which means they aren't checked.
KNOWN ISSUES
------------
* There were previous issues when using easygui with the IDLE IDE. I hope I resolved these problems, however,
I've never actually been able to repeat them. Please report any problems found in github.
OTHER CHANGES
-------------
* Centralized the Python 2 versus Python 3 "compatibility layer" into boxes/utils.py
0.97.4
========================================================================
This is a minor bug-fix release to address python 3 import errors.
0.97.3
========================================================================
We are happy to release version 0.97.3 of easygui. The intent of this release is to address some basic
functionality issues as well as improve easygui in the ways people have asked.
Robert Lugg (me) was searching for a GUI library for my python work. I saw easygui and liked very much its
paradigm. Stephen Ferg, the creator and developer of easygui, graciously allowed me to start development
back up. With the help of Alexander Zawadzki, Horst Jens, and others I set a goal to release before the
end of 2014.
We rely on user feedback so please bring up problems, ideas, or just say how you are using easygui.
BUG FIXES
---------
* sourceforge #4: easygui docs contain bad references to easygui_pydoc.html
* sourceforge #6: no index.html in docs download file. Updated to sphinx which as autolinking.
* sourceforge #8: unicode issues with file*box. Fixed all that I knew how.
* sourceforge #12: Cannot Exit with 'X'. Now X and escape either return "cancel_button", if set, or None
ENHANCEMENTS
------------
* Added ability to specify default_choice and cancel_choice for button widgets (See API docs)
* True and False are returned instead of 1 and 0 for several boxes
* Allow user to map keyboard keys to buttons by enclosing a hotkey in square braces like: "Pick [M]e", which would assign
keyboard key M to that button. Double braces hide that character, and keysyms are allowed:
[[q]]Exit Would show Exit on the button, and the button would be controlled by the q key
[]Help Would show Help on the button, and the button would be controlled by the F1 function key
NOTE: We are still working on the exact syntax of these key mappings as Enter, space, and arrows are already being
used.
* Escape and the windows 'X' button always work in buttonboxes. Those return None in that case.
* sourceforge #9: let fileopenbox open multiple files. Added optional argument 'multiple'
* Location of dialogs on screen is preserved. This isn't perfect yet, but now, at least, the dialogs don't
always reset to their default position!
* added some, but not all of the bugs/enhancements developed by Robbie Brook:
http://all-you-need-is-tech.blogspot.com/2013/01/improving-easygui-for-python.html
KNOWN ISSUES
------------
* In the documentation, there were previous references to issues when using the IDLE IDE. I haven't
experienced those, but also didn't do anything to fix them, so they may still be there. Please report
any problems and we'll try to address them
* I am fairly new to contributing to open source, so I don't understand packaging, pypi, etc. There
are likely problems as well as better ways to do things. Again, I appreciate any help or guidance.
Other Changes (that you likely don't care about)
------------------------------------------------
* Restructured loading of image files to try PIL first throw error if file doesn't exist.
* Converted docs to sphinx with just a bit of doctest. Most content was retained from the old site, so
there might be some redundancies still. Please make any suggested improvements.
* Set up a GitHub repository for development: https://github.com/robertlugg/easygui
* Improved output/packaging for Debian distribution
EasyGui is licensed under what is generally known as
the "modified BSD license" (aka "revised BSD", "new BSD", "3-clause BSD").
This license is GPL-compatible but less restrictive than GPL.
././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1648817217.7141874
easygui-0.98.3/easygui/ 0000777 0000000 0000000 00000000000 00000000000 011622 5 ustar 00 ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648571827.0
easygui-0.98.3/easygui/__init__.py 0000666 0000000 0000000 00000003375 00000000000 013743 0 ustar 00 """
Hello from easygui/__init__.py
"""
# __all__ must be defined in order for Sphinx to generate the API automatically.
__all__ = ['buttonbox',
'diropenbox',
'fileopenbox',
'filesavebox',
'textbox',
'ynbox',
'ccbox',
'boolbox',
'indexbox',
'msgbox',
'integerbox',
'multenterbox',
'enterbox',
'exceptionbox',
'choicebox',
'codebox',
'passwordbox',
'multpasswordbox',
'multchoicebox',
'EgStore',
'eg_version',
'egversion',
'abouteasygui',
'egdemo',
]
# Import all functions that form the API
from .boxes.button_box import buttonbox
from .boxes.diropen_box import diropenbox
from .boxes.fileopen_box import fileopenbox
from .boxes.filesave_box import filesavebox
from .boxes.text_box import textbox
from .boxes.derived_boxes import ynbox
from .boxes.derived_boxes import ccbox
from .boxes.derived_boxes import boolbox
from .boxes.derived_boxes import indexbox
from .boxes.derived_boxes import msgbox
from .boxes.derived_boxes import integerbox
from .boxes.multi_fillable_box import multenterbox
from .boxes.derived_boxes import enterbox
from .boxes.derived_boxes import exceptionbox
from .boxes.choice_box import choicebox
from .boxes.derived_boxes import codebox
from .boxes.derived_boxes import passwordbox
from .boxes.multi_fillable_box import multpasswordbox
from .boxes.choice_box import multchoicebox
from .boxes.egstore import EgStore, read_or_create_settings
from .boxes.about import eg_version, egversion, abouteasygui
from .boxes.demo import easygui_demo as egdemo
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/__main__.py 0000666 0000000 0000000 00000000064 00000000000 013714 0 ustar 00 from .boxes.demo import easygui_demo
easygui_demo() ././@PaxHeader 0000000 0000000 0000000 00000000034 00000000000 010212 x ustar 00 28 mtime=1648817217.7610354
easygui-0.98.3/easygui/boxes/ 0000777 0000000 0000000 00000000000 00000000000 012742 5 ustar 00 ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/__init__.py 0000666 0000000 0000000 00000000000 00000000000 015041 0 ustar 00 ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648571507.0
easygui-0.98.3/easygui/boxes/about.py 0000666 0000000 0000000 00000027405 00000000000 014436 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
"""
try:
from .derived_boxes import codebox
except (SystemError, ValueError, ImportError):
from derived_boxes import codebox
eg_version = '0.98.2-RELEASED'
egversion = eg_version
def abouteasygui():
"""
Shows the EasyGUI revision history.
"""
codebox("About EasyGui\n{}".format(eg_version),
"EasyGui", EASYGUI_ABOUT_INFORMATION)
return None
EASYGUI_ABOUT_INFORMATION = '''
0.98.2
========================================================================
Several updates and fixes thanks to Al and others.
0.98.0
========================================================================
This is an exciting time for easygui. We continue to make good progress with refactoring as
well as some enhancements and bug fixes here and there.
We would like to welcome Juanjo Corrales to the team. He is responsible for lots of good new work
this release. Of course we appreciate the work of everyone who contributed.
NOTE: I decided in this release to change the API a bit. Please consult the function documentation for details.
BUG FIXES
---------
* Made changes guessing at fixes to any IDLE problems. Please report any problems found.
ENHANCEMENTS
------------
* Refactored the easygui.py file into several smaller files to improve our ability to manage the code
* Added callbacks to allow for more dynamic dialogs. See the docs for usage.
* Added class access to dialogs so properties may be changed.
* Improved button boxes ability to resize during window resize by converting to Tkinter grid from packer.
KNOWN ISSUES
------------
* (old) In the documentation, there were previous references to issues when using the IDLE IDE. I haven't
experienced those, but also didn't do anything to fix them, so they may still be there. Please report
any problems and we'll try to address them
OTHER CHANGES
-------------
* Centralized the Python 2 versus Python 3 "compatibility layer" into boxes/utils.py
========================================================================
0.97.4
========================================================================
This is a minor bug-fix release to address python 3 import errors.
========================================================================
0.97.3
========================================================================
Some more fixes especially to fix Debian distro problems.
========================================================================
0.97.1 & 0.97.2 (2014-12-24)
========================================================================
Boring, embarrassing uploads to fix pypi install problems.
========================================================================
0.97(2014-12-20)
========================================================================
We are happy to release version 0.97 of easygui. The intent of this release is to address some basic
functionality issues as well as improve easygui in the ways people have asked.
Robert Lugg (me) was searching for a GUI library for my python work. I saw easygui and liked very much its
paradigm. Stephen Ferg, the creator and developer of easygui, graciously allowed me to start development
back up. With the help of Alexander Zawadzki, Horst Jens, and others I set a goal to release before the
end of 2014.
We rely on user feedback so please bring up problems, ideas, or just say how you are using easygui.
BUG FIXES
---------
* sourceforge #4: easygui docs contain bad references to easygui_pydoc.html
* sourceforge #6: no index.html in docs download file. Updated to sphinx which as autolinking.
* sourceforge #8: unicode issues with file*box. Fixed all that I knew how.
* sourceforge #12: Cannot Exit with 'X'. Now X and escape either return "cancel_button", if set, or None
ENHANCEMENTS
------------
* Added ability to specify default_choice and cancel_choice for button widgets (See API docs)
* True and False are returned instead of 1 and 0 for several boxes
* Allow user to map keyboard keys to buttons by enclosing a hotkey in square braces like: "Pick [M]e", which would assign
keyboard key M to that button. Double braces hide that character, and keysyms are allowed:
[[q]]Exit Would show Exit on the button, and the button would be controlled by the q key
[]Help Would show Help on the button, and the button would be controlled by the F1 function key
NOTE: We are still working on the exact syntax of these key mappings as Enter, space, and arrows are already being
used.
* Escape and the windows 'X' button always work in buttonboxes. Those return None in that case.
* sourceforge #9: let fileopenbox open multiple files. Added optional argument 'multiple'
* Location of dialogs on screen is preserved. This isn't perfect yet, but now, at least, the dialogs don't
always reset to their default position!
* added some, but not all of the bugs/enhancements developed by Robbie Brook:
http://all-you-need-is-tech.blogspot.com/2013/01/improving-easygui-for-python.html
KNOWN ISSUES
------------
* In the documentation, there were previous references to issues when using the IDLE IDE. I haven't
experienced those, but also didn't do anything to fix them, so they may still be there. Please report
any problems and we'll try to address them
* I am fairly new to contributing to open source, so I don't understand packaging, pypi, etc. There
are likely problems as well as better ways to do things. Again, I appreciate any help or guidance.
Other Changes (that you likely don't care about)
------------------------------------------------
* Restructured loading of image files to try PIL first throw error if file doesn't exiglobal_state.
* Converted docs to sphinx with just a bit of docteglobal_state. Most content was retained from the old site, so
there might be some redundancies still. Please make any suggested improvements.
* Set up a GitHub repository for development: https://github.com/robertlugg/easygui
EasyGui is licensed under what is generally known as
the "modified BSD license" (aka "revised BSD", "new BSD", "3-clause BSD").
This license is GPL-compatible but less restrictive than GPL.
========================================================================
0.96(2010-08-29)
========================================================================
This version fixes some problems with version independence.
BUG FIXES
------------------------------------------------------
* A statement with Python 2.x-style exception-handling syntax raised
a syntax error when running under Python 3.x.
Thanks to David Williams for reporting this problem.
* Under some circumstances, PIL was unable to display non-gif images
that it should have been able to display.
The cause appears to be non-version-independent import syntax.
PIL modules are now imported with a version-independent syntax.
Thanks to Horst Jens for reporting this problem.
LICENSE CHANGE
------------------------------------------------------
Starting with this version, EasyGui is licensed under what is generally known as
the "modified BSD license" (aka "revised BSD", "new BSD", "3-clause BSD").
This license is GPL-compatible but less restrictive than GPL.
Earlier versions were licensed under the Creative Commons Attribution License 2.0.
========================================================================
0.95(2010-06-12)
========================================================================
ENHANCEMENTS
------------------------------------------------------
* Previous versions of EasyGui could display only .gif image files using the
msgbox "image" argument. This version can now display all image-file formats
supported by PIL the Python Imaging Library) if PIL is installed.
If msgbox is asked to open a non-gif image file, it attempts to import
PIL and to use PIL to convert the image file to a displayable format.
If PIL cannot be imported (probably because PIL is not installed)
EasyGui displays an error message saying that PIL must be installed in order
to display the image file.
Note that
http://www.pythonware.com/products/pil/
says that PIL doesn't yet support Python 3.x.
========================================================================
0.94(2010-06-06)
========================================================================
ENHANCEMENTS
------------------------------------------------------
* The codebox and textbox functions now return the contents of the box, rather
than simply the name of the button ("Yes"). This makes it possible to use
codebox and textbox as data-entry widgets. A big "thank you!" to Dominic
Comtois for requesting this feature, patiently explaining his requirement,
and helping to discover the tkinter techniques to implement it.
NOTE THAT in theory this change breaks backward compatibility. But because
(in previous versions of EasyGui) the value returned by codebox and textbox
was meaningless, no application should have been checking it. So in actual
practice, this change should not break backward compatibility.
* Added support for SPACEBAR to command buttons. Now, when keyboard
focus is on a command button, a press of the SPACEBAR will act like
a press of the ENTER key; it will activate the command button.
* Added support for keyboard navigation with the arrow keys (up,down,left,right)
to the fields and buttons in enterbox, multenterbox and multpasswordbox,
and to the buttons in choicebox and all buttonboxes.
* added highlightthickness=2 to entry fields in multenterbox and
multpasswordbox. Now it is easier to tell which entry field has
keyboard focus.
BUG FIXES
------------------------------------------------------
* In EgStore, the pickle file is now opened with "rb" and "wb" rather than
with "r" and "w". This change is necessary for compatibility with Python 3+.
Thanks to Marshall Mattingly for reporting this problem and providing the fix.
* In integerbox, the actual argument names did not match the names described
in the docstring. Thanks to Daniel Zingaro of at University of Toronto for
reporting this problem.
* In integerbox, the "argLowerBound" and "argUpperBound" arguments have been
renamed to "lowerbound" and "upperbound" and the docstring has been corrected.
NOTE THAT THIS CHANGE TO THE ARGUMENT-NAMES BREAKS BACKWARD COMPATIBILITY.
If argLowerBound or argUpperBound are used, an AssertionError with an
explanatory error message is raised.
* In choicebox, the signature to choicebox incorrectly showed choicebox as
accepting a "buttons" argument. The signature has been fixed.
========================================================================
0.93(2009-07-07)
========================================================================
ENHANCEMENTS
------------------------------------------------------
* Added exceptionbox to display stack trace of exceptions
* modified names of some font-related constants to make it
easier to customize them
========================================================================
0.92(2009-06-22)
========================================================================
ENHANCEMENTS
------------------------------------------------------
* Added EgStore class to to provide basic easy-to-use persistence.
BUG FIXES
------------------------------------------------------
* Fixed a bug that was preventing Linux users from copying text out of
a textbox and a codebox. This was not a problem for Windows users.
'''
if __name__ == '__main__':
abouteasygui()
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/base_boxes.py 0000666 0000000 0000000 00000000726 00000000000 015433 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
boxRoot = None
def bindArrows(widget):
widget.bind("", tabRight)
widget.bind("", tabLeft)
widget.bind("", tabRight)
widget.bind("", tabLeft)
def tabRight(event):
boxRoot.event_generate("")
def tabLeft(event):
boxRoot.event_generate("")
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/button_box.py 0000666 0000000 0000000 00000043275 00000000000 015512 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
import os
import re
try:
from . import global_state
from . import utils as ut
from .text_box import textbox
except (SystemError, ValueError, ImportError):
import global_state
import utils as ut
from text_box import textbox
try:
import tkinter as tk # python 3
import tkinter.font as tk_Font
except (SystemError, ValueError, ImportError):
import Tkinter as tk # python 2
import tkFont as tk_Font
def demo_buttonbox_1():
print("hello from the demo")
value = buttonbox(
title="First demo",
msg="bonjour",
choices=["Button[1]", "Button[2]", "Button[3]"],
default_choice="Button[2]")
print("Return: {}".format(value))
def demo_buttonbox_2():
package_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) ;# My parent's directory
images = list()
images.append(os.path.join(package_dir, "python_and_check_logo.gif"))
images.append(os.path.join(package_dir, "zzzzz.gif"))
images.append(os.path.join(package_dir, "python_and_check_logo.png"))
images = [images, images, images, images, ]
value = buttonbox(
title="Second demo",
msg="Now is a good time to press buttons and show images",
choices=['ok', 'cancel'],
images=images)
print("Return: {}".format(value))
# REF: http://stackoverflow.com/questions/1835018/python-check-if-an-object-is-a-list-or-tuple-but-not-string
def is_sequence(arg):
return hasattr(arg, "__getitem__") or hasattr(arg, "__iter__")
def is_string(arg):
ret_val = None
try:
ret_val = isinstance(arg, basestring) #Python 2
except:
ret_val = isinstance(arg, str) #Python 3
return ret_val
def buttonbox(msg="",
title=" ",
choices=("Button[1]", "Button[2]", "Button[3]"),
image=None,
images=None,
default_choice=None,
cancel_choice=None,
callback=None,
run=True):
"""
Display a message, a title, an image, and a set of buttons.
The buttons are defined by the members of the choices argument.
:param str msg: the msg to be displayed
:param str title: the window title
:param list choices: a list or tuple of the choices to be displayed
:param str image: (Only here for backward compatibility)
:param str images: Filename of image or iterable or iteratable of iterable to display
:param str default_choice: The choice you want highlighted when the gui appears
:return: the text of the button that the user selected
"""
if image and images:
raise ValueError("Specify 'images' parameter only for buttonbox.")
if image:
images = image
bb = ButtonBox(
msg=msg,
title=title,
choices=choices,
images=images,
default_choice=default_choice,
cancel_choice=cancel_choice,
callback=callback)
if not run:
return bb
else:
reply = bb.run()
return reply
class ButtonBox(object):
""" Display various types of button boxes
This object separates user from ui, defines which methods can
the user invoke and which properties can he change.
It also calls the ui in defined ways, so if other gui
library can be used (wx, qt) without breaking anything for the user.
"""
def __init__(self, msg, title, choices, images, default_choice, cancel_choice, callback):
""" Create box object
Parameters
----------
msg : string
text displayed in the message area (instructions...)
title : str
the window title
choices : iterable of strings
build a button for each string in choices
images : iterable of filenames, or an iterable of iterables of filenames
displays each image
default_choice : string
one of the strings in choices to be the default selection
cancel_choice : string
if X or is pressed, it appears as if this button was pressed.
callback: function
if set, this function will be called when any button is pressed.
Returns
-------
object
The box object
"""
self.callback = callback
self.ui = GUItk(msg, title, choices, images, default_choice, cancel_choice, self.callback_ui)
def run(self):
""" Start the ui """
self.ui.run()
ret_val = self._text
self.ui = None
return ret_val
def stop(self):
""" Stop the ui """
self.ui.stop()
def callback_ui(self, ui, command):
""" This method is executed when buttons or x is pressed in the ui.
"""
if command == 'update': # Any button was pressed
self._text = ui.choice
self._choice_rc = ui.choice_rc
if self.callback:
# If a callback was set, call main process
self.callback(self)
else:
self.stop()
elif command == 'x':
self.stop()
self._text = None
elif command == 'cancel':
self.stop()
self._text = None
# methods to change properties --------------
@property
def msg(self):
"""Text in msg Area"""
return self._msg
@msg.setter
def msg(self, msg):
self._msg = self.to_string(msg)
self.ui.set_msg(self._msg)
@msg.deleter
def msg(self):
self._msg = ""
self.ui.set_msg(self._msg)
@property
def choice(self):
""" Name of button selected """
return self._text
@property
def choice_rc(self):
""" The row/column of the selected button (as a tuple) """
return self._choice_rc
# Methods to validate what will be sent to ui ---------
def to_string(self, something):
try:
basestring # python 2
except NameError:
basestring = str # Python 3
if isinstance(something, basestring):
return something
try:
text = "".join(something) # convert a list or a tuple to a string
except:
textbox(
"Exception when trying to convert {} to text in self.textArea"
.format(type(something)))
sys.exit(16)
return text
class GUItk(object):
""" This is the object that contains the tk root object"""
def __init__(self, msg, title, choices, images, default_choice, cancel_choice, callback):
""" Create ui object
Parameters
----------
msg : string
text displayed in the message area (instructions...)
title : str
the window title
choices : iterable of strings
build a button for each string in choices
images : iterable of filenames, or an iterable of iterables of filenames
displays each image
default_choice : string
one of the strings in choices to be the default selection
cancel_choice : string
if X or is pressed, it appears as if this button was pressed.
callback: function
if set, this function will be called when any button is pressed.
Returns
-------
object
The ui object
"""
self._title = title
self._msg = msg
self._choices = choices
self._default_choice = default_choice
self._cancel_choice = cancel_choice
self.callback = callback
self._choice_text = None
self._choice_rc = None
self._images = list()
self.boxRoot = tk.Tk()
# self.boxFont = tk_Font.Font(
# family=global_state.PROPORTIONAL_FONT_FAMILY,
# size=global_state.PROPORTIONAL_FONT_SIZE)
self.boxFont = tk_Font.nametofont("TkFixedFont")
self.width_in_chars = global_state.fixw_font_line_length
# default_font.configure(size=global_state.PROPORTIONAL_FONT_SIZE)
self.configure_root(title)
self.create_msg_widget(msg)
self.create_images_frame()
self.create_images(images)
self.create_buttons_frame()
self.create_buttons(choices, default_choice)
@property
def choice(self):
return self._choice_text
@property
def choice_rc(self):
return self._choice_rc
# Run and stop methods ---------------------------------------
def run(self):
self.boxRoot.mainloop()
self.boxRoot.destroy()
def stop(self):
# Get the current position before quitting
#self.get_pos()
self.boxRoot.quit()
# Methods to change content ---------------------------------------
def set_msg(self, msg):
self.messageArea.config(state=tk.NORMAL)
self.messageArea.delete(1.0, tk.END)
self.messageArea.insert(tk.END, msg)
self.messageArea.config(state=tk.DISABLED)
# Adjust msg height
self.messageArea.update()
self.set_msg_height()
self.messageArea.update()
def set_msg_height(self):
message_content = self.messageArea.get("1.0", tk.END)
lines = message_content.split("\n")
width = self.messageArea["width"]
num_lines = len(lines)
num_wordwraps = sum(len(line) // width for line in lines if len(line) != width)
height = num_lines + num_wordwraps + 1
self.messageArea.configure(height=height)
def set_pos(self, pos):
self.boxRoot.geometry(pos)
def get_pos(self):
# The geometry() method sets a size for the window and positions it on
# the screen. The first two parameters are width and height of
# the window. The last two parameters are x and y screen coordinates.
# geometry("250x150+300+300")
geom = self.boxRoot.geometry() # "628x672+300+200"
global_state.window_position = '+' + geom.split('+', 1)[1]
# Methods executing when a key is pressed -------------------------------
def x_pressed(self):
self._choice_text = self._cancel_choice
self.callback(self, command='x')
def cancel_pressed(self, event):
self._choice_text = self._cancel_choice
self.callback(self, command='cancel')
def button_pressed(self, button_text, button_rc):
self._choice_text = button_text
self._choice_rc = button_rc
self.callback(self, command='update')
def hotkey_pressed(self, event=None):
"""
Handle an event that is generated by a person interacting with a button. It may be a button press
or a key press.
TODO: Enhancement: Allow hotkey to be specified in filename of image as a shortcut too!!!
"""
# Determine window location and save to global
# TODO: Not sure where this goes, but move it out of here!
m = re.match(r"(\d+)x(\d+)([-+]\d+)([-+]\d+)", self.boxRoot.geometry())
if not m:
raise ValueError(
"failed to parse geometry string: {}".format(self.boxRoot.geometry()))
width, height, xoffset, yoffset = [int(s) for s in m.groups()]
global_state.window_position = '{0:+g}{1:+g}'.format(xoffset, yoffset)
# Hotkeys
if self._buttons:
for button_name, button in self._buttons.items():
hotkey_pressed = event.keysym
if event.keysym != event.char: # A special character
hotkey_pressed = '<{}>'.format(event.keysym)
if button['hotkey'] == hotkey_pressed:
self._choice_text = button_name
self.callback(self, command='update')
return
print("Event not understood")
# Auxiliary methods -----------------------------------------------
def calc_character_width(self):
char_width = self.boxFont.measure('W')
return char_width
# Initial configuration methods ---------------------------------------
# These ones are just called once, at setting.
def configure_root(self, title):
self.boxRoot.title(title)
self.set_pos(global_state.window_position)
# Resize setup
self.boxRoot.columnconfigure(0, weight=10)
self.boxRoot.minsize(100, 200)
# Quit when x button pressed
self.boxRoot.protocol('WM_DELETE_WINDOW', self.x_pressed)
self.boxRoot.bind("", self.cancel_pressed)
self.boxRoot.iconname('Dialog')
self.boxRoot.attributes("-topmost", True) # Put the dialog box in focus.
def create_msg_widget(self, msg):
if msg is None:
msg = ""
self.messageArea = tk.Text(
self.boxRoot,
width=self.width_in_chars,
state=tk.DISABLED,
padx=(global_state.default_hpad_in_chars) *
self.calc_character_width(),
relief="flat",
background=self.boxRoot.config()["background"][-1],
pady=global_state.default_hpad_in_chars *
self.calc_character_width(),
wrap=tk.WORD,
)
self.set_msg(msg)
self.messageArea.grid(row=0)
self.boxRoot.rowconfigure(0, weight=10, minsize='10m')
def create_images_frame(self):
self.imagesFrame = tk.Frame(self.boxRoot)
row = 1
self.imagesFrame.grid(row=row)
self.boxRoot.rowconfigure(row, weight=10, minsize='10m')
def create_images(self, filenames):
"""
Create one or more images in the dialog.
:param filenames:
May be a filename (which will generate a single image), a list of filenames (which will generate
a row of images), or a list of list of filename (which will create a 2D array of buttons.
:return:
"""
if filenames is None:
return
# Convert to a list of lists of filenames regardless of input
if is_string(filenames):
filenames = [[filenames,],]
elif is_sequence(filenames) and is_string(filenames[0]):
filenames = [filenames,]
elif is_sequence(filenames) and is_sequence(filenames[0]) and is_string(filenames[0][0]):
pass
else:
raise ValueError("Incorrect images argument.")
images = list()
for _r, images_row in enumerate(filenames):
row_number = len(filenames) - _r
for column_number, filename in enumerate(images_row):
this_image = dict()
try:
this_image['tk_image'] = ut.load_tk_image(filename)
except Exception as e:
print(e)
this_image['tk_image'] = None
this_image['widget'] = tk.Button(
self.imagesFrame,
takefocus=1,
compound=tk.TOP)
if this_image['widget'] is not None:
this_image['widget'].configure(image=this_image['tk_image'])
fn = lambda text=filename, row=_r, column=column_number: self.button_pressed(text, (row, column))
this_image['widget'].configure(command=fn)
sticky_dir = tk.N+tk.S+tk.E+tk.W
this_image['widget'].grid(row=row_number, column=column_number, sticky=sticky_dir, padx='1m', pady='1m', ipadx='2m', ipady='1m')
self.imagesFrame.rowconfigure(row_number, weight=10, minsize='10m')
self.imagesFrame.columnconfigure(column_number, weight=10)
images.append(this_image)
self._images = images # Image objects must live, so place them in self. Otherwise, they will be deleted.
def create_buttons_frame(self):
self.buttonsFrame = tk.Frame(self.boxRoot)
self.buttonsFrame.grid(row=2, column=0)
def create_buttons(self, choices, default_choice):
unique_choices = ut.uniquify_list_of_strings(choices)
# Create buttons dictionary and Tkinter widgets
buttons = dict()
i_hack = 0
for row, (button_text, unique_button_text) in enumerate(zip(choices, unique_choices)):
this_button = dict()
this_button['original_text'] = button_text
this_button['clean_text'], this_button['hotkey'], hotkey_position = ut.parse_hotkey(button_text)
this_button['widget'] = tk.Button(
self.buttonsFrame,
takefocus=1,
text=this_button['clean_text'],
underline=hotkey_position)
fn = lambda text=button_text, row=row, column=0: self.button_pressed(text, (row, column))
this_button['widget'].configure(command=fn)
this_button['widget'].grid(row=0, column=i_hack, padx='1m', pady='1m', ipadx='2m', ipady='1m')
self.buttonsFrame.columnconfigure(i_hack, weight=10)
i_hack += 1
buttons[unique_button_text] = this_button
self._buttons = buttons
if default_choice in buttons:
buttons[default_choice]['widget'].focus_force()
# Bind hotkeys
for hk in [button['hotkey'] for button in buttons.values() if button['hotkey']]:
self.boxRoot.bind_all(hk, lambda e: self.hotkey_pressed(e), add=True)
if __name__ == '__main__':
demo_buttonbox_1()
demo_buttonbox_2() ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648814214.0
easygui-0.98.3/easygui/boxes/choice_box.py 0000666 0000000 0000000 00000045771 00000000000 015434 0 ustar 00 import string
import sys
if sys.version_info < (3, 10):
from collections import Sequence
else:
from collections.abc import Sequence
try:
from . import global_state
from .base_boxes import bindArrows
except (SystemError, ValueError, ImportError):
import global_state
from base_boxes import bindArrows
try:
import tkinter as tk # python 3
import tkinter.font as tk_Font
except:
import Tkinter as tk # python 2
import tkFont as tk_Font
def choicebox(msg="Pick an item", title="", choices=None, preselect=0,
callback=None,
run=True):
"""
The ``choicebox()`` provides a list of choices in a list box to choose
from. The choices are specified in a sequence (a tuple or a list).
import easygui
msg ="What is your favorite flavor?"
title = "Ice Cream Survey"
choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"]
choice = easygui.choicebox(msg, title, choices) # choice is a string
:param str msg: the msg to be displayed
:param str title: the window title
:param list choices: a list or tuple of the choices to be displayed
:param preselect: Which item, if any are preselected when dialog appears
:return: A string of the selected choice or None if cancelled
"""
mb = ChoiceBox(msg, title, choices, preselect=preselect,
multiple_select=False,
callback=callback)
if run:
reply = mb.run()
return reply
else:
return mb
def multchoicebox(msg="Pick an item", title="", choices=None,
preselect=0, callback=None,
run=True):
"""
The ``multchoicebox()`` function provides a way for a user to select
from a list of choices. The interface looks just like the ``choicebox()``
function's dialog box, but the user may select zero, one, or multiple choices.
The choices are specified in a sequence (a tuple or a list).
import easygui
msg ="What is your favorite flavor?"
title = "Ice Cream Survey"
choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"]
choice = easygui.multchoicebox(msg, title, choices)
:param str msg: the msg to be displayed
:param str title: the window title
:param list choices: a list or tuple of the choices to be displayed
:param preselect: Which item, if any are preselected when dialog appears
:return: A list of strings of the selected choices or None if cancelled.
"""
mb = ChoiceBox(msg, title, choices, preselect=preselect,
multiple_select=True,
callback=callback)
if run:
reply = mb.run()
return reply
else:
return mb
# Utility function. But, is it generic enough to be moved out of here?
def make_list_or_none(obj, cast_type=None):
# -------------------------------------------------------------------
# for an object passed in, put it in standardized form.
# It may be None. Just return None
# If it is a scalar, attempt to cast it into cast_type. Raise error
# if not possible. Convert scalar to a single-element list.
# If it is a collections.Sequence (including a scalar converted to let),
# then cast each element to cast_type. Raise error if any cannot be converted.
# -------------------------------------------------------------------
ret_val = obj
if ret_val is None:
return None
# Convert any non-sequence to single-element list
if not isinstance(obj, Sequence):
if cast_type is not None:
try:
ret_val = cast_type(obj)
except Exception as e:
raise Exception("Value {} cannot be converted to type: {}".format(obj, cast_type))
ret_val = [ret_val,]
# Convert all elements to cast_type
if cast_type is not None:
try:
ret_val = [cast_type(elem) for elem in ret_val]
except:
raise Exception("Not all values in {}\n can be converted to type: {}".format(ret_val, cast_type))
return ret_val
class ChoiceBox(object):
def __init__(self, msg, title, choices, preselect, multiple_select, callback):
self.callback = callback
if choices is None:
# Use default choice selections if none were specified:
choices = ('Choice 1', 'Choice 2')
self.choices = self.to_list_of_str(choices)
# Convert preselect to always be a list or None.
preselect_list = make_list_or_none(preselect, cast_type=int)
if not multiple_select and len(preselect_list)>1:
raise ValueError("Multiple selections not allowed, yet preselect has multiple values:{}".format(preselect_list))
self.ui = GUItk(msg, title, self.choices, preselect_list, multiple_select,
self.callback_ui)
def run(self):
""" Start the ui """
self.ui.run()
self.ui = None
return self.choices
def stop(self):
""" Stop the ui """
self.ui.stop()
def callback_ui(self, ui, command, choices):
""" This method is executed when ok, cancel, or x is pressed in the ui.
"""
if command == 'update': # OK was pressed
self.choices = choices
if self.callback:
# If a callback was set, call main process
self.callback(self)
else:
self.stop()
elif command == 'x':
self.stop()
self.choices = None
elif command == 'cancel':
self.stop()
self.choices = None
# methods to change properties --------------
@property
def msg(self):
"""Text in msg Area"""
return self._msg
@msg.setter
def msg(self, msg):
self.ui.set_msg(msg)
@msg.deleter
def msg(self):
self._msg = ""
self.ui.set_msg(self._msg)
# Methods to validate what will be sent to ui ---------
def to_list_of_str(self, choices):
choices = [str(c) for c in choices]
while len(choices) < 2:
raise ValueError('at least two choices need to be specified')
return choices
class GUItk(object):
""" This object contains the tk root object.
It draws the window, waits for events and communicates them
to MultiBox, together with the entered values.
The position in wich it is drawn comes from a global variable.
It also accepts commands from Multibox to change its message.
"""
def __init__(self, msg, title, choices, preselect, multiple_select, callback):
self.callback = callback
self.choices = choices
self.width_in_chars = global_state.prop_font_line_length
# Initialize self.selected_choices
# This is the value that will be returned if the user clicks the close
# icon
# self.selected_choices = None
self.multiple_select = multiple_select
self.boxRoot = tk.Tk()
self.boxFont = tk_Font.nametofont("TkTextFont")
self.config_root(title)
self.set_pos(global_state.window_position) # GLOBAL POSITION
self.create_msg_widget(msg)
self.create_choicearea()
self.create_ok_button()
self.create_cancel_button()
self.create_special_buttons()
self.preselect_choice(preselect)
self.choiceboxWidget.focus_force()
# Run and stop methods ---------------------------------------
def run(self):
self.boxRoot.mainloop() # run it!
self.boxRoot.destroy() # Close the window
def stop(self):
# Get the current position before quitting
self.get_pos()
self.boxRoot.quit()
def x_pressed(self):
self.callback(self, command='x', choices=self.get_choices())
def cancel_pressed(self, event):
self.callback(self, command='cancel', choices=self.get_choices())
def ok_pressed(self, event):
self.callback(self, command='update', choices=self.get_choices())
# Methods to change content ---------------------------------------
# Methods to change content ---------------------------------------
def set_msg(self, msg):
self.messageArea.config(state=tk.NORMAL)
self.messageArea.delete(1.0, tk.END)
self.messageArea.insert(tk.END, msg)
self.messageArea.config(state=tk.DISABLED)
# Adjust msg height
self.messageArea.update()
numlines = self.get_num_lines(self.messageArea)
self.set_msg_height(numlines)
self.messageArea.update()
# put the focus on the entryWidget
def set_msg_height(self, numlines):
self.messageArea.configure(height=numlines)
def get_num_lines(self, widget):
end_position = widget.index(tk.END) # '4.0'
end_line = end_position.split('.')[0] # 4
return int(end_line) + 1 # 5
def set_pos(self, pos=None):
if not pos:
pos = global_state.window_position
self.boxRoot.geometry(pos)
def get_pos(self):
# The geometry() method sets a size for the window and positions it on
# the screen. The first two parameters are width and height of
# the window. The last two parameters are x and y screen coordinates.
# geometry("250x150+300+300")
geom = self.boxRoot.geometry() # "628x672+300+200"
global_state.window_position = '+' + geom.split('+', 1)[1]
def preselect_choice(self, preselect):
if preselect != None:
for v in preselect:
self.choiceboxWidget.select_set(v)
self.choiceboxWidget.activate(v)
def get_choices(self):
choices_index = self.choiceboxWidget.curselection()
if not choices_index:
return None
if self.multiple_select:
selected_choices = [self.choiceboxWidget.get(index)
for index in choices_index]
else:
selected_choices = self.choiceboxWidget.get(choices_index)
return selected_choices
# Auxiliary methods -----------------------------------------------
def calc_character_width(self):
char_width = self.boxFont.measure('W')
return char_width
def config_root(self, title):
screen_width = self.boxRoot.winfo_screenwidth()
screen_height = self.boxRoot.winfo_screenheight()
self.root_width = int((screen_width * 0.8))
root_height = int((screen_height * 0.5))
self.boxRoot.title(title)
self.boxRoot.iconname('Dialog')
self.boxRoot.expand = tk.NO
# self.boxRoot.minsize(width=62 * self.calc_character_width())
self.set_pos()
self.boxRoot.protocol('WM_DELETE_WINDOW', self.x_pressed)
self.boxRoot.bind('', self.KeyboardListener)
self.boxRoot.bind("", self.cancel_pressed)
self.boxRoot.attributes("-topmost", True) # Put the dialog box in focus.
def create_msg_widget(self, msg):
if msg is None:
msg = ""
self.msgFrame = tk.Frame(
self.boxRoot,
padx=2 * self.calc_character_width(),
)
self.messageArea = tk.Text(
self.msgFrame,
width=self.width_in_chars,
state=tk.DISABLED,
background=self.boxRoot.config()["background"][-1],
relief='flat',
padx=(global_state.default_hpad_in_chars *
self.calc_character_width()),
pady=(global_state.default_hpad_in_chars *
self.calc_character_width()),
wrap=tk.WORD,
)
self.set_msg(msg)
self.msgFrame.pack(side=tk.TOP, expand=1, fill='both')
self.messageArea.pack(side=tk.TOP, expand=1, fill='both')
def create_choicearea(self):
self.choiceboxFrame = tk.Frame(master=self.boxRoot)
self.choiceboxFrame.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES)
lines_to_show = min(len(self.choices), 20)
# -------- put the self.choiceboxWidget in the self.choiceboxFrame ---
self.choiceboxWidget = tk.Listbox(self.choiceboxFrame,
height=lines_to_show,
borderwidth="1m", relief="flat",
bg="white"
)
if self.multiple_select:
self.choiceboxWidget.configure(selectmode=tk.MULTIPLE)
# self.choiceboxWidget.configure(font=(global_state.PROPORTIONAL_FONT_FAMILY,
# global_state.PROPORTIONAL_FONT_SIZE))
# add a vertical scrollbar to the frame
rightScrollbar = tk.Scrollbar(self.choiceboxFrame, orient=tk.VERTICAL,
command=self.choiceboxWidget.yview)
self.choiceboxWidget.configure(yscrollcommand=rightScrollbar.set)
# add a horizontal scrollbar to the frame
bottomScrollbar = tk.Scrollbar(self.choiceboxFrame,
orient=tk.HORIZONTAL,
command=self.choiceboxWidget.xview)
self.choiceboxWidget.configure(xscrollcommand=bottomScrollbar.set)
# pack the Listbox and the scrollbars.
# Note that although we must define
# the textArea first, we must pack it last,
# so that the bottomScrollbar will
# be located properly.
bottomScrollbar.pack(side=tk.BOTTOM, fill=tk.X)
rightScrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.choiceboxWidget.pack(
side=tk.LEFT, padx="1m", pady="1m", expand=tk.YES, fill=tk.BOTH)
# Insert choices widgets
for choice in self.choices:
self.choiceboxWidget.insert(tk.END, choice)
# Bind the keyboard events
self.choiceboxWidget.bind("", self.ok_pressed)
self.choiceboxWidget.bind("",
self.ok_pressed)
def create_ok_button(self):
self.buttonsFrame = tk.Frame(self.boxRoot)
self.buttonsFrame.pack(side=tk.TOP, expand=tk.YES, pady=0)
# put the buttons in the self.buttonsFrame
okButton = tk.Button(self.buttonsFrame, takefocus=tk.YES,
text="OK", height=1, width=6)
bindArrows(okButton)
okButton.pack(expand=tk.NO, side=tk.RIGHT, padx='2m', pady='1m',
ipady="1m", ipadx="2m")
# for the commandButton, bind activation events
okButton.bind("", self.ok_pressed)
okButton.bind("", self.ok_pressed)
okButton.bind("", self.ok_pressed)
def create_cancel_button(self):
cancelButton = tk.Button(self.buttonsFrame, takefocus=tk.YES,
text="Cancel", height=1, width=6)
bindArrows(cancelButton)
cancelButton.pack(expand=tk.NO, side=tk.LEFT, padx='2m', pady='1m',
ipady="1m", ipadx="2m")
cancelButton.bind("", self.cancel_pressed)
cancelButton.bind("", self.cancel_pressed)
# self.cancelButton.bind("", self.cancel_pressed)
# for the commandButton, bind activation events to the activation event
# handler
def create_special_buttons(self):
# add special buttons for multiple select features
if not self.multiple_select:
return
selectAllButton = tk.Button(
self.buttonsFrame, text="Select All", height=1, width=6)
selectAllButton.pack(expand=tk.NO, side=tk.LEFT, padx='2m',
pady='1m',
ipady="1m", ipadx="2m")
clearAllButton = tk.Button(self.buttonsFrame, text="Clear All",
height=1, width=6)
clearAllButton.pack(expand=tk.NO, side=tk.LEFT,
padx='2m', pady='1m',
ipady="1m", ipadx="2m")
selectAllButton.bind("", self.choiceboxSelectAll)
bindArrows(selectAllButton)
clearAllButton.bind("", self.choiceboxClearAll)
bindArrows(clearAllButton)
def KeyboardListener(self, event):
key = event.keysym
if len(key) <= 1:
if key in string.printable:
# Find the key in the liglobal_state.
# before we clear the list, remember the selected member
try:
start_n = int(self.choiceboxWidget.curselection()[0])
except IndexError:
start_n = -1
# clear the selection.
self.choiceboxWidget.selection_clear(0, 'end')
# start from previous selection +1
for n in range(start_n + 1, len(self.choices)):
item = self.choices[n]
if item[0].lower() == key.lower():
self.choiceboxWidget.selection_set(first=n)
self.choiceboxWidget.see(n)
return
else:
# has not found it so loop from top
for n, item in enumerate(self.choices):
if item[0].lower() == key.lower():
self.choiceboxWidget.selection_set(first=n)
self.choiceboxWidget.see(n)
return
# nothing matched -- we'll look for the next logical choice
for n, item in enumerate(self.choices):
if item[0].lower() > key.lower():
if n > 0:
self.choiceboxWidget.selection_set(
first=(n - 1))
else:
self.choiceboxWidget.selection_set(first=0)
self.choiceboxWidget.see(n)
return
# still no match (nothing was greater than the key)
# we set the selection to the first item in the list
lastIndex = len(self.choices) - 1
self.choiceboxWidget.selection_set(first=lastIndex)
self.choiceboxWidget.see(lastIndex)
return
def choiceboxClearAll(self, event):
self.choiceboxWidget.selection_clear(0, len(self.choices) - 1)
def choiceboxSelectAll(self, event):
self.choiceboxWidget.selection_set(0, len(self.choices) - 1)
if __name__ == '__main__':
users_choice = multchoicebox(choices=['choice1', 'choice2'])
print("User's choice is: {}".format(users_choice))
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/demo.py 0000666 0000000 0000000 00000035605 00000000000 014251 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
"""
import os
import sys
try:
from . import utils as ut
from .button_box import buttonbox
from .text_box import textbox
from .diropen_box import diropenbox
from .fileopen_box import fileopenbox
from .filesave_box import filesavebox
from .multi_fillable_box import multenterbox
from .multi_fillable_box import multpasswordbox
from .derived_boxes import ynbox
from .derived_boxes import ccbox
from .derived_boxes import boolbox
from .derived_boxes import indexbox
from .derived_boxes import msgbox
from .derived_boxes import integerbox
from .derived_boxes import enterbox
from .derived_boxes import exceptionbox
from .derived_boxes import codebox
from .derived_boxes import passwordbox
from .choice_box import choicebox
from .choice_box import multchoicebox
from . import about
from .about import eg_version
from .about import abouteasygui
except (SystemError, ValueError, ImportError):
print("Please run demo.py from outside the package")
exit()
# --------------------------------------------------------------
#
# test/demo easygui
#
# -----------------------------------------------------------------------
package_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
class Demos(object):
""" Collection of demos
A choice is comprised of two pieces of data:
- a description, which is a string. The descriptions will be shown
in the choicebox, and one will be returned by it.
- a function to execute when the description is selected
"""
def __init__(self):
self.demos = [
("msgbox", demo_msgbox),
("ynbox", demo_ynbox),
("ccbox", demo_ccbox),
("boolbox", demo_boolbox),
("buttonbox", demo_buttonbox),
("buttonbox that displays an image", demo_buttonbox_with_image),
("buttonbox - select an image", demo_buttonbox_with_choice),
("indexbox", demo_indexbox),
("choicebox", demo_choicebox),
("multchoicebox", demo_multichoicebox),
("textbox", demo_textbox),
("codebox", demo_codebox),
("enterbox", demo_enterbox),
("integerbox", demo_integerbox),
("passwordbox", demo_passwordbox),
("multenterbox", demo_multenterbox),
("multpasswordbox", demo_multpasswordbox),
("enterbox that displays an image", demo_enterbox_image),
("filesavebox", demo_filesavebox),
("fileopenbox", demo_fileopenbox),
("diropenbox", demo_diropenbox),
("exceptionbox", demo_exceptionbox),
("About EasyGui", demo_about),
("Help", demo_help),
]
def list_descriptions(self):
descriptions = [c[0] for c in self.demos]
return descriptions
def get_demo(self, index):
demo = self.demos[index]
# demo = next((c[1] for c in self.demo if c[0] == description))
return demo[1]
def get_description(self, index):
demo = self.demos[index]
return demo[0]
def __len__(self):
return len(self.demos)
def easygui_demo():
"""
Run the EasyGui demo.
"""
demos = Demos()
replies = [''] * len(demos)
# clear the console
print('\n' * 100)
msg = []
msg.append("Pick the kind of box that you wish to demo.")
msg.append(" * Python version {}".format(sys.version))
msg.append(" * EasyGui version {}".format(eg_version))
msg.append(" * Tk version {}".format(ut.TkVersion))
intro_message = "\n".join(msg)
title = "EasyGui " + eg_version
# Table that relates keys in choicebox with functions to execute
descriptions = demos.list_descriptions()
preselected = 0
while True:
presented_choices = [
d + r for d, r in zip(descriptions, replies)]
reply = choicebox(msg=intro_message,
title=title,
choices=presented_choices,
preselect=preselected
)
if not reply:
break
print(reply)
index_chosen_demo = presented_choices.index(reply)
# Execute the chosen demo!
chosen_demo = demos.get_demo(index_chosen_demo)
demo_reply = chosen_demo()
# Save the reply
if demo_reply:
replies[index_chosen_demo] = ' - Last reply: {}'.format(demo_reply)
else:
replies[index_chosen_demo] = ''
preselected += 1
if preselected >= len(presented_choices):
preselected = 0
def demo_msgbox():
reply = msgbox("short msg", "This is a long title")
print("Reply was: {!r}".format(reply))
return reply
def demo_buttonbox():
reply = buttonbox(choices=['one', 'two', 'two', 'three'],
default_choice='two')
print("Reply was: {!r}".format(reply))
title = "Demo of Buttonbox with many, many buttons!"
msg = ("This buttonbox shows what happens when you "
"specify too many buttons.")
reply = buttonbox(msg=msg, title=title,
choices=['1', '2', '3', '4', '5', '6', '7'],
cancel_choice='7')
print("Reply was: {!r}".format(reply))
return reply
def demo_buttonbox_with_image():
msg = "Do you like this picture?\nIt is "
choices = ["Yes", "No", "No opinion"]
for image in [
os.path.join(package_dir, "python_and_check_logo.gif"),
os.path.join(package_dir, "python_and_check_logo.jpg"),
os.path.join(package_dir, "python_and_check_logo.png"),
os.path.join(package_dir, "zzzzz.gif")]:
reply = buttonbox(msg + image, image=image, choices=choices)
print("Reply was: {!r}".format(reply))
return reply
def demo_buttonbox_with_choice():
msg = "Pick an image"
choices = ['cancel']
images = list()
images.append(os.path.join(package_dir, "python_and_check_logo.gif"))
images.append(os.path.join(package_dir, "python_and_check_logo.jpg"))
images.append(os.path.join(package_dir, "python_and_check_logo.png"))
images.append(os.path.join(package_dir, "zzzzz.gif"))
reply = buttonbox(msg, images=images, choices=['cancel'])
print("Reply was: {!r}".format(reply))
return reply
def demo_ccbox():
msg = "Insert your favorite message here"
title = "Demo of ccbox"
reply = ccbox(msg, title)
print("Reply was: {!r}".format(reply))
return reply
def demo_multichoicebox():
listChoices = ["aaa", "bbb", "ccc", "ggg", "hhh", "iii",
"jjj", "kkk", "LLL", "mmm", "nnn", "ooo",
"ppp", "qqq", "rrr", "sss", "ttt", "uuu",
"vvv"]
preselect = None #[0, 2, 4]
msg = "Pick as many choices as you wish."
reply = multchoicebox(msg, "Demo of multchoicebox", listChoices, preselect)
print("Reply was: {!r}".format(reply))
return reply
def demo_ynbox():
title = "Demo of ynbox"
msg = "Were you expecting the Spanish Inquisition?"
reply = ynbox(msg, title)
print("Reply was: {!r}".format(reply))
if reply:
msgbox("NOBODY expects the Spanish Inquisition!", "Wrong!")
return reply
def demo_choicebox():
title = "Demo of choicebox"
longchoice = (
"This is an example of a very long option "
"which you may or may not wish to choose."
* 2)
listChoices = ["nnn", "ddd", "eee", "fff", "aaa",
longchoice, "aaa", "bbb", "ccc", "ggg", "hhh",
"iii", "jjj", "kkk", "LLL", "mmm", "nnn",
"ooo", "ppp", "qqq",
"rrr", "sss", "ttt", "uuu", "vvv"]
msg = ("Pick something. " +
("A wrapable sentence of text ?! " * 30) +
"\nA separate line of text." * 6)
reply = choicebox(msg=msg, choices=listChoices)
print("Reply was: {!r}".format(reply))
msg = "Pick something. "
reply = choicebox(msg=msg, title=title, choices=listChoices)
print("Reply was: {!r}".format(reply))
msg = "Pick something. "
reply = choicebox(
msg="The list of choices is empty!", choices=list())
print("Reply was: {!r}".format(reply))
return reply
def demo_integerbox():
reply = integerbox(
"Enter a number between 3 and 333",
"Demo: integerbox WITH a default value", 222, 3, 333)
print("Reply was: {!r}".format(reply))
reply = integerbox(
"Enter a number between 0 and 99",
"Demo: integerbox WITHOUT a default value"
)
print("Reply was: {!r}".format(reply))
return reply
def demo_about():
reply = abouteasygui()
print("Reply was: {!r}".format(reply))
return reply
def demo_enterbox():
image = os.path.join(package_dir, "python_and_check_logo.gif")
message = ("Enter the name of your best friend."
"\n(Result will be stripped.)")
reply = enterbox(message, "Love!", " Suzy Smith ")
print("Reply was: {!r}".format(reply))
message = ("Enter the name of your best friend."
"\n(Result will NOT be stripped.)")
reply = enterbox(
message, "Love!", " Suzy Smith ", strip=False)
print("Reply was: {!r}".format(reply))
reply = enterbox("Enter the name of your worst enemy:", "Hate!")
print("Reply was: {!r}".format(reply))
return reply
def demo_multpasswordbox():
msg = "Enter logon information"
title = "Demo of multpasswordbox"
fieldNames = ["Server ID", "User ID", "Password"]
fieldValues = list() # we start with blanks for the values
fieldValues = multpasswordbox(msg, title, fieldNames)
# make sure that none of the fields was left blank
while True:
if fieldValues is None:
break
errs = list()
for n, v in zip(fieldNames, fieldValues):
if v.strip() == "":
errs.append('"{}" is a required field.\n\n'.format(n))
if not len(errs):
break # no problems found
fieldValues = multpasswordbox(
"".join(errs), title, fieldNames, fieldValues)
print("Reply was: {!s}".format(fieldValues))
return fieldValues
def demo_textbox():
text_snippet = ((
"It was the best of times, and it was the worst of times. The rich "
"ate cake, and the poor had cake recommended to them, but wished "
"only for enough cash to buy bread. The time was ripe for "
"revolution! "
* 5) + "\n\n") * 10
title = "Demo of textbox"
msg = "Here is some sample text. " * 16
reply = textbox(msg, title, text_snippet)
print("Reply was: {!s}".format(reply))
return reply
def demo_codebox():
# TODO RL: Turn this sample code into the code in this module, just for fun
code_snippet = ("dafsdfa dasflkj pp[oadsij asdfp;ij asdfpjkop asdfpok asdfpok asdfpok" * 3) + "\n" + """# here is some dummy Python code
for someItem in myListOfStuff:
do something(someItem)
do something()
do something()
if somethingElse(someItem):
doSomethingEvenMoreInteresting()
""" * 16
msg = "Here is some sample code. " * 16
reply = codebox(msg, "Code Sample", code_snippet)
print("Reply was: {!r}".format(reply))
return reply
def demo_boolbox():
reply = boolbox()
print("Reply was: {!r}".format(reply))
return reply
def demo_enterbox_image():
image = os.path.join(package_dir, "python_and_check_logo.gif")
message = "What kind of snake is this?"
reply = enterbox(message, "Quiz", image=image)
print("Reply was: {!r}".format(reply))
return reply
def demo_passwordbox():
reply = passwordbox("Demo of password box WITHOUT default"
+ "\n\nEnter your secret password",
"Member Logon")
print("Reply was: {!s}".format(reply))
reply = passwordbox("Demo of password box WITH default"
+ "\n\nEnter your secret password",
"Member Logon", "alfie")
print("Reply was: {!s}".format(reply))
return reply
def demo_help():
codebox("EasyGui Help", text=about.EASYGUI_ABOUT_INFORMATION)
return None
def demo_filesavebox():
filename = "myNewFile.txt"
title = "File SaveAs"
msg = "Save file as:"
f = filesavebox(msg, title, default=filename)
print("You chose to save file: {}".format(f))
return f
def demo_diropenbox():
title = "Demo of diropenbox"
msg = "Pick the directory that you wish to open."
d = diropenbox(msg, title)
print("You chose directory...: {}".format(d))
d = diropenbox(msg, title, default="./")
print("You chose directory...: {}".format(d))
d = diropenbox(msg, title, default="c:/")
print("You chose directory...: {}".format(d))
return d
def demo_exceptionbox():
try:
thisWillCauseADivideByZeroException = 1 / 0
except:
exceptionbox()
return None
def demo_indexbox():
title = "Indexbox"
msg = "Demo of " + "indexbox"
choices = ["Choice1", "Choice2", "Choice3", "Choice4"]
reply = indexbox(msg, title, choices)
print("Reply was: {!r}".format(reply))
return reply
def demo_multenterbox():
msg = "Enter your personal information"
title = "Credit Card Application"
fieldNames = ["Name", "Street Address", "City", "State", "ZipCode"]
fieldValues = list() # we start with blanks for the values
fieldValues = multenterbox(msg, title, fieldNames)
# make sure that none of the fields was left blank
while True:
if fieldValues is None:
break
errs = list()
for n, v in zip(fieldNames, fieldValues):
if v.strip() == "":
errs.append('"{}" is a required field.'.format(n))
if not len(errs):
break # no problems found
fieldValues = multenterbox(
"\n".join(errs), title, fieldNames, fieldValues)
print("Reply was: {}".format(fieldValues))
return fieldValues
def demo_fileopenbox():
msg = "Python files"
title = "Open files"
default = "*.py"
f = fileopenbox(msg, title, default=default)
print("You chose to open file: {}".format(f))
default = "./*.gif"
msg = "Some other file types (Multi-select)"
filetypes = ["*.jpg", ["*.zip", "*.tgs", "*.gz",
"Archive files"], ["*.htm", "*.html", "HTML files"]]
f = fileopenbox(
msg, title, default=default, filetypes=filetypes, multiple=True)
print("You chose to open file: %s" % f)
return f
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/derived_boxes.py 0000666 0000000 0000000 00000037564 00000000000 016155 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
"""
try:
from .fillable_box import __fillablebox
from .button_box import buttonbox
from . import text_box as tb
from . import utils as ut
except (SystemError, ValueError, ImportError):
from fillable_box import __fillablebox
from button_box import buttonbox
import text_box as tb
import utils as ut
# -------------------------------------------------------------------
# various boxes built on top of the basic buttonbox
# -----------------------------------------------------------------------
# -----------------------------------------------------------------------
# ynbox
# -----------------------------------------------------------------------
def ynbox(msg="Shall I continue?", title=" ",
choices=("[]Yes", "[]No"), image=None,
default_choice='[]Yes', cancel_choice='[]No'):
"""
The ``ynbox()`` offers a choice of Yes and No, and returns either ``True`` or ``False``.
import easygui
result = easygui.ynbox('Is a hot dog a sandwich?', 'Hot Dog Question')
if result == True:
easygui.msgbox('That is an interesting answer.')
else:
easygui.msgbox('Well, that is your opinion.')
:param msg: the msg to be displayed
:type msg: str
:param str title: the window title
:param list choices: a list or tuple of the choices to be displayed
:param str image: Filename of image to display
:param str default_choice: The choice you want highlighted
when the gui appears
:param str cancel_choice: If the user presses the 'X' close, which
button should be pressed
:return: True if 'Yes' or dialog is cancelled, False if 'No'
"""
return boolbox(msg=msg,
title=title,
choices=choices,
image=image,
default_choice=default_choice,
cancel_choice=cancel_choice)
# -----------------------------------------------------------------------
# ccbox
# -----------------------------------------------------------------------
def ccbox(msg="Shall I continue?", title=" ",
choices=("C[o]ntinue", "C[a]ncel"), image=None,
default_choice='Continue', cancel_choice='Cancel'):
"""
The ``ccbox()`` function offers a choice of Continue and Cancel, and returns either True (for continue) or False (for cancel).
import easygui
msg = "Do you want to continue?"
title = "Please Confirm"
if easygui.ccbox(msg, title): # Show a Continue/Cancel dialog.
pass # User chose Continue.
else: # User chose Cancel.
sys.exit()
:param str msg: the msg to be displayed
:param str title: the window title
:param list choices: a list or tuple of the choices to be displayed
:param str image: Filename of image to display
:param str default_choice: The choice you want highlighted
when the gui appears
:param str cancel_choice: If the user presses the 'X' close,
which button should be pressed
:return: True if 'Continue' or dialog is cancelled, False if 'Cancel'
"""
return boolbox(msg=msg,
title=title,
choices=choices,
image=image,
default_choice=default_choice,
cancel_choice=cancel_choice)
# -----------------------------------------------------------------------
# boolbox
# -----------------------------------------------------------------------
def boolbox(msg="Shall I continue?", title=" ",
choices=("[T]rue", "[F]alse"), image=None,
default_choice='[T]rue', cancel_choice='[F]alse'):
"""
The ``boolbox()`` (boolean box) displays two buttons. Returns returns
``True`` if the first button is chosen. Otherwise returns ``False``.
import easygui
message = "What do they say?"
title = "Romantic Question"
if easygui.boolbox(message, title, ["They love me", "They love me not"]):
easygui.msgbox('You should send them flowers.')
else:
easygui.msgbox('It was not meant to be.')
:param str msg: The message shown in the center of the dialog window.
:param str title: The window title text.
:param list choices: A list or tuple of strings for the buttons' text.
:param str image: The filename of an image to display in the dialog window.
:param str default_choice: The text of the default selected button.
:param str cancel_choice: If the user presses the 'X' close, which button
should be pressed
:return: `True` if first button pressed or dialog is cancelled, `False`
if second button is pressed.
"""
if len(choices) != 2:
raise AssertionError(
'boolbox() takes exactly 2 choices! Consider using indexbox() instead.'
)
reply = buttonbox(msg=msg,
title=title,
choices=choices,
image=image,
default_choice=default_choice,
cancel_choice=cancel_choice)
if reply == choices[0]:
return True # The first button (True) was selected.
elif reply == choices[1]:
return False # The second button (False) was selected.
elif reply is None:
return None # The window was closed.
assert False, "The user selected an unexpected response."
# -----------------------------------------------------------------------
# indexbox
# -----------------------------------------------------------------------
def indexbox(msg="Shall I continue?", title=" ",
choices=("Yes", "No"), image=None,
default_choice='Yes', cancel_choice='No'):
"""
The ``indexbox()`` function displays a set of buttons, and returns the
index of the selected button. For example, if you invoked index box with
three choices (A, B, C), indexbox would return 0 if the user picked A, 1
if he picked B, and 2 if he picked C.
import easygui
result = easygui.indexbox('Which door do you choose?', 'Win Prizes!', choices=['Door 1', 'Door 2', 'Door 3'])
if result == 2:
easygui.msgbox('You win a new car!')
else:
easygui.msgbox('Better luck next time.')
:param str msg: the msg to be displayed
:param str title: the window title
:param list choices: a list or tuple of the choices to be displayed
:param str image: Filename of image to display
:param str default_choice: The choice you want highlighted
when the gui appears
:param str cancel_choice: If the user presses the 'X' close,
which button should be pressed
:return: the index of the choice selected, starting from 0
"""
reply = buttonbox(msg=msg,
title=title,
choices=choices,
image=image,
default_choice=default_choice,
cancel_choice=cancel_choice)
if reply is None:
return None
for i, choice in enumerate(choices):
if reply == choice:
return i
msg = ("There is a program logic error in the EasyGui code "
"for indexbox.\nreply={0}, choices={1}".format(
reply, choices))
raise AssertionError(msg)
# -----------------------------------------------------------------------
# msgbox
# -----------------------------------------------------------------------
def msgbox(msg="(Your message goes here)", title=" ",
ok_button="OK", image=None, root=None):
"""
The ``msgbox()`` function displays a text message and offers an OK
button. The message text appears in the center of the window, the title
text appears in the title bar, and you can replace the "OK" default text
on the button. Here is the signature::
def msgbox(msg="(Your message goes here)", title="", ok_button="OK"):
....
The clearest way to override the button text is to do it with a keyword
argument, like this::
easygui.msgbox("Backup complete!", ok_button="Good job!")
Here are a couple of examples::
easygui.msgbox("Hello, world!")
:param str msg: the msg to be displayed
:param str title: the window title
:param str ok_button: text to show in the button
:param str image: Filename of image to display
:param tk_widget root: Top-level Tk widget
:return: the text of the ok_button
"""
if not isinstance(ok_button, ut.basestring):
raise AssertionError(
"The 'ok_button' argument to msgbox must be a string.")
return buttonbox(msg=msg,
title=title,
choices=[ok_button],
image=image,
default_choice=ok_button,
cancel_choice=ok_button)
def convert_to_type(input_value, new_type, input_value_name=None):
"""
Attempts to convert input_value to type new_type and throws error if it can't.
If input_value is None, None is returned
If new_type is None, input_value is returned unchanged
:param input_value: Value to be converted
:param new_type: Type to convert to
:param input_value_name: If not None, used in error message if input_value cannot be converted
:return: input_value converted to new_type, or None
"""
if input_value is None or new_type is None:
return input_value
exception_string = (
'value {0}:{1} must be of type {2}.')
ret_value = new_type(input_value)
# except ValueError:
# raise ValueError(
# exception_string.format('default', default, type(default)))
return ret_value
# -------------------------------------------------------------------
# integerbox
# -------------------------------------------------------------------
def integerbox(msg="", title=" ", default=None,
lowerbound=0, upperbound=99, image=None, root=None):
"""
Show a box in which a user can enter an integer.
In addition to arguments for msg and title, this function accepts
integer arguments for "default", "lowerbound", and "upperbound".
The default, lowerbound, or upperbound may be None.
When the user enters some text, the text is checked to verify that it
can be converted to an integer between the lowerbound and upperbound.
If it can be, the integer (not the text) is returned.
If it cannot, then an error msg is displayed, and the integerbox is
redisplayed.
If the user cancels the operation, None is returned.
:param str msg: the msg to be displayed
:param str title: the window title
:param int default: The default value to return
:param int lowerbound: The lower-most value allowed
:param int upperbound: The upper-most value allowed
:param str image: Filename of image to display
:param tk_widget root: Top-level Tk widget
:return: the integer value entered by the user
"""
if not msg:
msg = "Enter an integer between {0} and {1}".format(
lowerbound, upperbound)
# Validate the arguments for default, lowerbound and upperbound and
# convert to integers
default = convert_to_type(default, int, "default")
lowerbound = convert_to_type(lowerbound, int, "lowerbound")
upperbound = convert_to_type(upperbound, int, "upperbound")
while True:
reply = enterbox(msg, title, default, image=image, root=root)
if reply is None:
return None
try:
reply = convert_to_type(reply, int)
except ValueError:
msgbox('The value that you entered:\n\t"{}"\nis not an integer.'.format(reply), "Error")
continue
if lowerbound is not None:
if reply < lowerbound:
msgbox('The value that you entered is less than the lower bound of {}.'.format(lowerbound), "Error")
continue
if upperbound is not None:
if reply > upperbound:
msgbox('The value that you entered is greater than the upper bound of {}.'.format(upperbound), "Error")
continue
# reply has passed all validation checks.
# It is an integer between the specified bounds.
break
return reply
# -------------------------------------------------------------------
# enterbox
# -------------------------------------------------------------------
def enterbox(msg="Enter something.", title=" ", default="",
strip=True, image=None, root=None):
"""
Show a box in which a user can enter some text.
You may optionally specify some default text, which will appear in the
enterbox when it is displayed.
Example::
import easygui
reply = easygui.enterbox('Enter your life story:')
if reply:
easygui.msgbox('Thank you for your response.')
else:
easygui.msgbox('Your response has been discarded.')
:param str msg: the msg to be displayed.
:param str title: the window title
:param str default: value returned if user does not change it
:param bool strip: If True, the return value will have
its whitespace stripped before being returned
:return: the text that the user entered, or None if they cancel
the operation.
"""
result = __fillablebox(
msg, title, default=default, mask=None, image=image, root=root)
if result and strip:
result = result.strip()
return result
def passwordbox(msg="Enter your password.", title=" ", default="",
image=None, root=None):
"""
Show a box in which a user can enter a password.
The text is masked with asterisks, so the password is not displayed.
:param str msg: the msg to be displayed.
:param str title: the window title
:param str default: value returned if user does not change it
:return: the text that the user entered, or None if they cancel
the operation.
"""
return __fillablebox(msg, title, default, mask="*",
image=image, root=root)
# -----------------------------------------------------------------------
# exceptionbox
# -----------------------------------------------------------------------
def exceptionbox(msg=None, title=None):
"""
Display a box that gives information about
an exception that has just been raised.
The caller may optionally pass in a title for the window, or a
msg to accompany the error information.
Note that you do not need to (and cannot) pass an exception object
as an argument. The latest exception will automatically be used.
:param str msg: the msg to be displayed
:param str title: the window title
:return: None
"""
if title is None:
title = "Error Report"
if msg is None:
msg = "An error (exception) has occurred in the program."
codebox(msg, title, ut.exception_format())
# -------------------------------------------------------------------
# codebox
# -------------------------------------------------------------------
def codebox(msg="", title=" ", text=""):
"""
Display some text in a monospaced font, with no line wrapping.
This function is suitable for displaying code and text that is
formatted using spaces.
The text parameter should be a string, or a list or tuple of lines to be
displayed in the textbox.
:param str msg: the msg to be displayed
:param str title: the window title
:param str text: what to display in the textbox
"""
return tb.textbox(msg, title, text, codebox=True)
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/diropen_box.py 0000666 0000000 0000000 00000003546 00000000000 015634 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
import os
try:
from . import utils as ut
except (SystemError, ValueError, ImportError):
import utils as ut
try:
import tkinter as tk # python 3
import tkinter.font as tk_Font
except:
import Tkinter as tk # python 2
import tkFont as tk_Font
# -------------------------------------------------------------------
# diropenbox
# -------------------------------------------------------------------
def diropenbox(msg=None, title=None, default=None):
"""
A dialog to get a directory name.
Returns the name of a directory, or None if user chose to cancel.
If the "default" argument specifies a directory name, and that
directory exists, then the dialog box will start with that directory.
:param str msg: used in the window title on some platforms
:param str title: the window title
:param str default: starting directory when dialog opens
:return: Normalized path selected by user
"""
title = ut.getFileDialogTitle(msg, title)
localRoot = tk.Tk()
localRoot.withdraw()
localRoot.lift()
localRoot.attributes('-topmost', 1)
localRoot.attributes('-topmost', 0)
if not default:
default = None
localRoot.update() #fix ghost window issue #119 on mac.
f = ut.tk_FileDialog.askdirectory(
parent=localRoot, title=title, initialdir=default, initialfile=None
)
localRoot.destroy()
if not f:
return None
return os.path.normpath(f)
if __name__ == '__main__':
print("Hello from base_boxes")
my_dir = diropenbox(
"You really should open a file",
title="Open a dir",
default='./')
print("directory {} selected.".format(my_dir))
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/egstore.py 0000666 0000000 0000000 00000010715 00000000000 014770 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
import errno
import os
import pickle
import datetime
def read_or_create_settings(file_name):
settings = Settings(file_name)
settings.restore()
return settings
class EgStore(object):
"""
A class to support persistent storage.
You can use ``EgStore`` to support the storage and retrieval
of user settings for an EasyGui application.
**First: define a class named Settings as a subclass of EgStore** ::
class Settings(EgStore):
def __init__(self, filename): # filename is required
# specify default values for variables that this application wants to remember
self.user_id = ''
self.target_server = ''
settings.restore()
*Second: create a persistent Settings object** ::
settings = Settings('app_settings.txt')
settings.user_id = 'obama_barak'
settings.targetServer = 'whitehouse1'
settings.store()
# run code that gets a new value for user_id, and persist the settings
settings.user_id = 'biden_joe'
settings.store()
**Example C: recover the Settings instance, change an attribute, and store it again.** ::
settings = Settings('app_settings.txt')
settings.restore()
print settings
settings.user_id = 'vanrossum_g'
settings.store()
"""
def __init__(self, filename):
"""Initialize a store with the given filename.
:param filename: the file that backs this store for saving and loading
"""
self.filename = filename
def restore(self):
try:
self._restore()
except IOError as e:
if e.errno != errno.ENOENT:
raise
def _restore(self):
"""
Set the values of whatever attributes are recoverable
from the pickle file.
Populate the attributes (the __dict__) of the EgStore object
from the attributes (the __dict__) of the pickled object.
If the pickled object has attributes that have been initialized
in the EgStore object, then those attributes of the EgStore object
will be replaced by the values of the corresponding attributes
in the pickled object.
If the pickled object is missing some attributes that have
been initialized in the EgStore object, then those attributes
of the EgStore object will retain the values that they were
initialized with.
Where possible, the attributes will have values recovered
from the pickled object.
"""
with open(self.filename, 'rb') as f:
store = pickle.load(f)
for key, value in store.__dict__.items():
self.__dict__[key] = value
self.last_time_restored = datetime.datetime.now()
def store(self):
"""Save this store to a pickle file.
All directories in :attr:`filename` must already exist.
"""
with open(self.filename, 'wb') as f:
self.last_time_stored = datetime.datetime.now()
pickle.dump(self, f)
def kill(self):
"""Delete this store's file if it exists."""
if os.path.isfile(self.filename):
os.remove(self.filename)
def __getstate__(self):
""" All attributes will be pickled """
state = self.__dict__.copy()
return state
def __setstate__(self, state):
""" Ensure filename won't be unpickled """
if 'filename' in state:
del state['filename']
self.__dict__.update(state)
def __str__(self):
""""Format this store as "key : value" pairs, one per line."""
stored_values = self.__dict__
lines = []
width = max(len(key) for key in stored_values)
for key in sorted(stored_values.keys()):
value = stored_values[key]
if isinstance(value, datetime.datetime):
value = value.isoformat()
lines.append('{0} : {1!r}'.format(key.ljust(width), value))
return '\n'.join(lines)
def __repr__(self):
return '{0}({1!r})'.format(self.__class__.__name__, self.filename)
class Settings(EgStore):
def __init__(self, filename):
self.filename = filename
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/fileboxsetup.py 0000666 0000000 0000000 00000012324 00000000000 016027 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
import os
try:
from . import utils as ut
except (SystemError, ValueError, ImportError):
import utils as ut
try:
import tkinter as tk # python 3
import tkinter.font as tk_Font
except:
import Tkinter as tk # python 2
import tkFont as tk_Font
# -------------------------------------------------------------------
#
# fileboxSetup
#
# -------------------------------------------------------------------
def fileboxSetup(default, filetypes):
if not default:
default = os.path.join(".", "*")
initialdir, initialfile = os.path.split(default)
if not initialdir:
initialdir = "."
if not initialfile:
initialfile = "*"
initialbase, initialext = os.path.splitext(initialfile)
initialFileTypeObject = FileTypeObject(initialfile)
allFileTypeObject = FileTypeObject("*")
ALL_filetypes_was_specified = False
if not filetypes:
filetypes = list()
filetypeObjects = list()
for filemask in filetypes:
fto = FileTypeObject(filemask)
if fto.isAll():
ALL_filetypes_was_specified = True # remember this
if fto == initialFileTypeObject:
initialFileTypeObject.add(fto) # add fto to initialFileTypeObject
else:
filetypeObjects.append(fto)
# ------------------------------------------------------------------
# make sure that the list of filetypes includes the ALL FILES type.
# ------------------------------------------------------------------
if ALL_filetypes_was_specified:
pass
elif allFileTypeObject == initialFileTypeObject:
pass
else:
filetypeObjects.insert(0, allFileTypeObject)
# ------------------------------------------------------------------
# Make sure that the list includes the initialFileTypeObject
# in the position in the list that will make it the default.
# This changed between Python version 2.5 and 2.6
# ------------------------------------------------------------------
if len(filetypeObjects) == 0:
filetypeObjects.append(initialFileTypeObject)
if initialFileTypeObject in (filetypeObjects[0], filetypeObjects[-1]):
pass
else:
if ut.runningPython27:
filetypeObjects.append(initialFileTypeObject)
else:
filetypeObjects.insert(0, initialFileTypeObject)
filetypes = [fto.toTuple() for fto in filetypeObjects]
return initialbase, initialfile, initialdir, filetypes
# Hotkeys
if buttons:
for button_name, button in buttons.items():
hotkey_pressed = event.keysym
if event.keysym != event.char: # A special character
hotkey_pressed = '<{}>'.format(event.keysym)
if button['hotkey'] == hotkey_pressed:
__replyButtonText = button_name
boxRoot.quit()
return
print("Event not understood")
# -------------------------------------------------------------------
# class FileTypeObject for use with fileopenbox
# -------------------------------------------------------------------
class FileTypeObject:
def __init__(self, filemask):
if len(filemask) == 0:
raise AssertionError('Filetype argument is empty.')
self.masks = list()
if isinstance(filemask, ut.basestring): # a str or unicode
self.initializeFromString(filemask)
elif isinstance(filemask, list):
if len(filemask) < 2:
raise AssertionError('Invalid filemask.\n'
+ 'List contains less than 2 members: "{}"'.format(filemask))
else:
self.name = filemask[-1]
self.masks = list(filemask[:-1])
else:
raise AssertionError('Invalid filemask: "{}"'.format(filemask))
def __eq__(self, other):
if self.name == other.name:
return True
return False
def add(self, other):
for mask in other.masks:
if mask in self.masks:
pass
else:
self.masks.append(mask)
def toTuple(self):
return self.name, tuple(self.masks)
def isAll(self):
if self.name == "All files":
return True
return False
def initializeFromString(self, filemask):
# remove everything except the extension from the filemask
self.ext = os.path.splitext(filemask)[1]
if self.ext == "":
self.ext = ".*"
if self.ext == ".":
self.ext = ".*"
self.name = self.getName()
self.masks = ["*" + self.ext]
def getName(self):
e = self.ext
file_types = {".*": "All", ".txt": "Text",
".py": "Python", ".pyc": "Python", ".xls": "Excel"}
if e in file_types:
return '{} files'.format(file_types[e])
if e.startswith("."):
return '{} files'.format(e[1:].upper())
return '{} files'.format(e.upper())
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/fileopen_box.py 0000666 0000000 0000000 00000010367 00000000000 015774 0 ustar 00 from __future__ import print_function
"""
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
import os
try:
from . import utils as ut
from . import fileboxsetup as fbs
except (SystemError, ValueError, ImportError):
import utils as ut
import fileboxsetup as fbs
tk = ut.tk
# -------------------------------------------------------------------
# fileopenbox
# -------------------------------------------------------------------
def fileopenbox(msg=None, title=None, default='*', filetypes=None, multiple=False):
"""
Displays an "open file" dialog box and returns the selected file as a string.
The "default" argument specifies a filepath that (normally)
contains one or more wildcards.
fileopenbox() will display only files that match the default filepath.
If omitted, defaults to "\\*" (all files in the current directory).
WINDOWS EXAMPLE::
...default="c:/myjunk/*.py"
will open in directory c:\\myjunk\\ and show all Python files.
WINDOWS EXAMPLE::
...default="c:/myjunk/test*.py"
will open in directory c:\\myjunk\\ and show all Python files
whose names begin with "test".
Note that on Windows, fileopenbox automatically changes the path
separator to the Windows path separator (backslash).
**About the "filetypes" argument**
If specified, it should contain a list of items,
where each item is either:
- a string containing a filemask # e.g. "\\*.txt"
- a list of strings, where all of the strings except the last one
are filemasks (each beginning with "\\*.",
such as "\\*.txt" for text files, "\\*.py" for Python files, etc.).
and the last string contains a filetype description
EXAMPLE::
filetypes = ["*.css", ["*.htm", "*.html", "HTML files"] ]
.. note:: If the filetypes list does not contain ("All files","*"), it will be added.
If the filetypes list does not contain a filemask that includes
the extension of the "default" argument, it will be added.
For example, if default="\\*abc.py"
and no filetypes argument was specified, then
"\\*.py" will automatically be added to the filetypes argument.
:param str msg: the msg to be displayed.
:param str title: the window title
:param str default: filepath with wildcards
:param object filetypes: filemasks that a user can choose, e.g. "\\*.txt"
:param bool multiple: If true, more than one file can be selected
:return: the name of a file, or None if user chose to cancel
"""
localRoot = tk.Tk()
localRoot.withdraw()
initialbase, initialfile, initialdir, filetypes = fbs.fileboxSetup(
default, filetypes)
# ------------------------------------------------------------
# if initialfile contains no wildcards; we don't want an
# initial file. It won't be used anyway.
# Also: if initialbase is simply "*", we don't want an
# initialfile; it is not doing any useful work.
# ------------------------------------------------------------
if (initialfile.find("*") < 0) and (initialfile.find("?") < 0):
initialfile = None
elif initialbase == "*":
initialfile = None
func = ut.tk_FileDialog.askopenfilenames if multiple else ut.tk_FileDialog.askopenfilename
ret_val = func(parent=localRoot,
title=ut.getFileDialogTitle(msg, title),
initialdir=initialdir, initialfile=initialfile,
filetypes=filetypes
)
if not ret_val or ret_val == '':
localRoot.destroy()
return None
if multiple:
f = [os.path.normpath(x) for x in localRoot.tk.splitlist(ret_val)]
else:
try:
f = os.path.normpath(ret_val)
except AttributeError as e:
print("ret_val is {}".format(ret_val))
raise e
localRoot.destroy()
if not f:
return None
return f
if __name__ == '__main__':
print("Hello from file open box")
ret_val = fileopenbox("Please select a file", "My File Open dialog")
print("Return value is:{}".format(ret_val))
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/filesave_box.py 0000666 0000000 0000000 00000005277 00000000000 015775 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
import os
try:
from . import utils as ut
from . import fileboxsetup as fbs
except (SystemError, ValueError, ImportError):
import utils as ut
import fileboxsetup as fbs
try:
import tkinter as tk # python 3
import tkinter.font as tk_Font
except:
import Tkinter as tk # python 2
import tkFont as tk_Font
# -------------------------------------------------------------------
# filesavebox
# -------------------------------------------------------------------
def filesavebox(msg=None, title=None, default="", filetypes=None):
"""
A file to get the name of a file to save.
Returns the name of a file, or None if user chose to cancel.
**About the "default" argument**
The ``default`` argument specifies the path and "glob pattern" for file
names. The "\\*" value, for example, sets the open file dialog to the
current working directory and showing all files.
For another example, setting the ``default`` argument to ``"C:/myjunk/*.py"``
sets the open file dialog to the C:\\myjunk folder and showing only files
that have the .py file extension. This glob pattern at the end of the
``default`` argument is required: passing ``"C:/myjunk"`` would not set the
open file dialog to the C:\\myjunk folder, but rather to the C:\\ folder
and "myjunk" as the initial filename.
Note that on Windows, ``fileopenbox()`` automatically changes the path
separator to the Windows path separator (backslash).
The "filetypes" argument works like the "filetypes" argument to
fileopenbox.
:param str msg: the msg to be displayed.
:param str title: the window title
:param str default: default filename to return
:param object filetypes: filemasks that a user can choose, e.g. " \\*.txt"
:return: the name of a file, or None if user chose to cancel
"""
localRoot = tk.Tk()
localRoot.withdraw()
initialbase, initialfile, initialdir, filetypes = fbs.fileboxSetup(
default, filetypes)
f = ut.tk_FileDialog.asksaveasfilename(
parent=localRoot,
title=ut.getFileDialogTitle(
msg, title),
initialfile=initialfile, initialdir=initialdir,
filetypes=filetypes
)
localRoot.destroy()
if not f:
return None
return os.path.normpath(f)
if __name__ == '__main__':
print("Hello from file save box")
ret_val = filesavebox("Please select a file to save to", "My File Save dialog")
print("Return value is:{}".format(ret_val)) ././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/fillable_box.py 0000666 0000000 0000000 00000013201 00000000000 015733 0 ustar 00 try:
from . import utils as ut
from . import global_state
from .base_boxes import bindArrows
except (SystemError, ValueError, ImportError):
import utils as ut
import global_state
from base_boxes import bindArrows
try:
import tkinter as tk # python 3
import tkinter.font as tk_Font
except:
import Tkinter as tk # python 2
import tkFont as tk_Font
# TODO: bindArrows seems to be in the wrong place.
boxRoot = None
entryWidget = None
__enterboxText = ''
__enterboxDefaultText = ''
cancelButton = None
okButton = None
def __fillablebox(msg, title="", default="", mask=None, image=None, root=None):
"""
Show a box in which a user can enter some text.
You may optionally specify some default text, which will appear in the
enterbox when it is displayed.
Returns the text that the user entered, or None if they cancel the operation.
"""
global boxRoot, __enterboxText, __enterboxDefaultText
global cancelButton, entryWidget, okButton
if title is None:
title = ""
if default is None:
default = ""
__enterboxDefaultText = default
__enterboxText = __enterboxDefaultText
if root:
root.withdraw()
boxRoot = tk.Toplevel(master=root)
boxRoot.withdraw()
else:
boxRoot = tk.Tk()
boxRoot.withdraw()
boxRoot.protocol('WM_DELETE_WINDOW', __enterboxQuit)
boxRoot.title(title)
boxRoot.iconname('Dialog')
boxRoot.geometry(global_state.window_position)
boxRoot.bind("", __enterboxCancel)
# ------------- define the messageFrame ---------------------------------
messageFrame = tk.Frame(master=boxRoot)
messageFrame.pack(side=tk.TOP, fill=tk.BOTH)
# ------------- define the imageFrame ---------------------------------
try:
tk_Image = ut.load_tk_image(image)
except Exception as inst:
print(inst)
tk_Image = None
if tk_Image:
imageFrame = tk.Frame(master=boxRoot)
imageFrame.pack(side=tk.TOP, fill=tk.BOTH)
label = tk.Label(imageFrame, image=tk_Image)
label.image = tk_Image # keep a reference!
label.pack(side=tk.TOP, expand=tk.YES, fill=tk.X, padx='1m', pady='1m')
# ------------- define the buttonsFrame ---------------------------------
buttonsFrame = tk.Frame(master=boxRoot)
buttonsFrame.pack(side=tk.TOP, fill=tk.BOTH)
# ------------- define the entryFrame ---------------------------------
entryFrame = tk.Frame(master=boxRoot)
entryFrame.pack(side=tk.TOP, fill=tk.BOTH)
# ------------- define the buttonsFrame ---------------------------------
buttonsFrame = tk.Frame(master=boxRoot)
buttonsFrame.pack(side=tk.TOP, fill=tk.BOTH)
# -------------------- the msg widget ----------------------------
messageWidget = tk.Message(messageFrame, width="4.5i", text=msg)
messageWidget.configure(
font=(global_state.PROPORTIONAL_FONT_FAMILY, global_state.PROPORTIONAL_FONT_SIZE))
messageWidget.pack(
side=tk.RIGHT, expand=1, fill=tk.BOTH, padx='3m', pady='3m')
# --------- entryWidget ----------------------------------------------
entryWidget = tk.Entry(entryFrame, width=40)
bindArrows(entryWidget)
entryWidget.configure(
font=(global_state.PROPORTIONAL_FONT_FAMILY, global_state.TEXT_ENTRY_FONT_SIZE))
if mask:
entryWidget.configure(show=mask)
entryWidget.pack(side=tk.LEFT, padx="3m")
entryWidget.bind("", __enterboxGetText)
entryWidget.bind("", __enterboxCancel)
# put text into the entryWidget
entryWidget.insert(0, __enterboxDefaultText)
# ------------------ ok button -------------------------------
okButton = tk.Button(buttonsFrame, takefocus=1, text="OK")
bindArrows(okButton)
okButton.pack(
expand=1, side=tk.LEFT, padx='3m', pady='3m', ipadx='2m', ipady='1m')
# for the commandButton, bind activation events to the activation event
# handler
commandButton = okButton
handler = __enterboxGetText
for selectionEvent in global_state.STANDARD_SELECTION_EVENTS:
commandButton.bind("<{}>".format(selectionEvent), handler)
# ------------------ cancel button -------------------------------
cancelButton = tk.Button(buttonsFrame, takefocus=1, text="Cancel")
bindArrows(cancelButton)
cancelButton.pack(
expand=1, side=tk.RIGHT, padx='3m', pady='3m', ipadx='2m', ipady='1m')
# for the commandButton, bind activation events to the activation event
# handler
commandButton = cancelButton
handler = __enterboxCancel
for selectionEvent in global_state.STANDARD_SELECTION_EVENTS:
commandButton.bind("<{}>".format(selectionEvent), handler)
# ------------------- time for action! -----------------
entryWidget.focus_force() # put the focus on the entryWidget
boxRoot.deiconify()
boxRoot.mainloop() # run it!
# -------- after the run has completed ----------------------------------
if root:
root.deiconify()
boxRoot.destroy() # button_click didn't destroy boxRoot, so we do it now
return __enterboxText
def __enterboxQuit():
return __enterboxCancel(None)
def __enterboxCancel(event):
global __enterboxText
__enterboxText = None
boxRoot.quit()
def __enterboxGetText(event):
global __enterboxText
__enterboxText = entryWidget.get()
boxRoot.quit()
def __enterboxRestore(event):
global entryWidget
entryWidget.delete(0, len(entryWidget.get()))
entryWidget.insert(0, __enterboxDefaultText)
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/global_state.py 0000666 0000000 0000000 00000001232 00000000000 015752 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
# Starting and global variables
window_position = "+300+200"
PROPORTIONAL_FONT_FAMILY = ("MS", "Sans", "Serif")
MONOSPACE_FONT_FAMILY = "Courier"
PROPORTIONAL_FONT_SIZE = 10
# a little smaller, because it is more legible at a smaller size
MONOSPACE_FONT_SIZE = 9
TEXT_ENTRY_FONT_SIZE = 12 # a little larger makes it easier to see
STANDARD_SELECTION_EVENTS = ["Return", "Button-1", "space"]
prop_font_line_length = 62
fixw_font_line_length = 80
num_lines_displayed = 50
default_hpad_in_chars = 2
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/multi_fillable_box.py 0000666 0000000 0000000 00000040306 00000000000 017153 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
try:
from . import global_state
except:
import global_state
try:
import tkinter as tk # python 3
except:
import Tkinter as tk # python 2
# -----------------------------------------------------------------------
# multpasswordbox
# -----------------------------------------------------------------------
def multpasswordbox(msg="Fill in values for the fields.",
title=" ", fields=tuple(), values=tuple(),
callback=None, run=True):
r"""
Same interface as multenterbox. But in multpassword box,
the last of the fields is assumed to be a password, and
is masked with asterisks.
:param str msg: the msg to be displayed.
:param str title: the window title
:param list fields: a list of fieldnames.
:param list values: a list of field values
:return: String
**Example**
Here is some example code, that shows how values returned from
multpasswordbox can be checked for validity before they are accepted::
msg = "Enter logon information"
title = "Demo of multpasswordbox"
fieldNames = ["Server ID", "User ID", "Password"]
fieldValues = [] # we start with blanks for the values
fieldValues = multpasswordbox(msg,title, fieldNames)
# make sure that none of the fields was left blank
while 1:
if fieldValues is None: break
errmsg = ""
for i in range(len(fieldNames)):
if fieldValues[i].strip() == "":
errmsg = errmsg + ('"%s" is a required field.\n\n' %
fieldNames[i])
if errmsg == "": break # no problems found
fieldValues = multpasswordbox(errmsg, title,
fieldNames, fieldValues)
print("Reply was: %s" % str(fieldValues))
"""
if run:
mb = MultiBox(msg, title, fields, values, mask_last=True,
callback=callback)
reply = mb.run()
return reply
else:
mb = MultiBox(msg, title, fields, values, mask_last=True,
callback=callback)
return mb
# -------------------------------------------------------------------
# multenterbox
# -------------------------------------------------------------------
# TODO RL: Should defaults be list constructors.
# i think after multiple calls, the value is retained.
# TODO RL: Rename/alias to multienterbox?
# default should be None and then in the logic create an empty liglobal_state.
def multenterbox(msg="Fill in values for the fields.", title=" ",
fields=[], values=[], callback=None, run=True):
r"""
Show screen with multiple data entry fields.
If there are fewer values than names, the list of values is padded with
empty strings until the number of values is the same as the number
of names.
If there are more values than names, the list of values
is truncated so that there are as many values as names.
Returns a list of the values of the fields,
or None if the user cancels the operation.
Here is some example code, that shows how values returned from
multenterbox can be checked for validity before they are accepted::
msg = "Enter your personal information"
title = "Credit Card Application"
fieldNames = ["Name","Street Address","City","State","ZipCode"]
fieldValues = [] # we start with blanks for the values
fieldValues = multenterbox(msg,title, fieldNames)
# make sure that none of the fields was left blank
while 1:
if fieldValues is None: break
errmsg = ""
for i in range(len(fieldNames)):
if fieldValues[i].strip() == "":
errmsg += ('"%s" is a required field.\n\n' % fieldNames[i])
if errmsg == "":
break # no problems found
fieldValues = multenterbox(errmsg, title, fieldNames, fieldValues)
print("Reply was: %s" % str(fieldValues))
:param str msg: the msg to be displayed.
:param str title: the window title
:param list fields: a list of fieldnames.
:param list values: a list of field values
:return: String
"""
if run:
mb = MultiBox(msg, title, fields, values, mask_last=False,
callback=callback)
reply = mb.run()
return reply
else:
mb = MultiBox(msg, title, fields, values, mask_last=False,
callback=callback)
return mb
class MultiBox(object):
""" Show multiple data entry fields
This object does a number of things:
- chooses a GUI framework (wx, qt)
- checks the data sent to the GUI
- performs the logic (button ok should close the window?)
- defines what methods the user can invoke and
what properties he can change.
- calls the ui in defined ways, so other gui
frameworks can be used without breaking anything to the user
"""
def __init__(self, msg, title, fields, values, mask_last, callback):
""" Create box object
Parameters
----------
msg : string
text displayed in the message area (instructions...)
title : str
the window title
fields: list
names of fields
values: list
initial values
callback: function
if set, this function will be called when OK is pressed
run: bool
if True, a box object will be created and returned, but not run
Returns
-------
self
The MultiBox object
"""
self.callback = callback
self.fields, self.values = self.check_fields(fields, values)
self.ui = GUItk(msg, title, self.fields, self.values,
mask_last, self.callback_ui)
def run(self):
""" Start the ui """
self.ui.run()
self.ui = None
return self.values
def stop(self):
""" Stop the ui """
self.ui.stop()
def callback_ui(self, ui, command, values):
""" This method is executed when ok, cancel, or x is pressed in the ui.
"""
if command == 'update': # OK was pressed
self.values = values
if self.callback:
# If a callback was set, call main process
self.callback(self)
else:
self.stop()
elif command == 'x':
self.stop()
self.values = None
elif command == 'cancel':
self.stop()
self.values = None
# methods to change properties --------------
@property
def msg(self):
"""Text in msg Area"""
return self._msg
@msg.setter
def msg(self, msg):
self.ui.set_msg(msg)
@msg.deleter
def msg(self):
self._msg = ""
self.ui.set_msg(self._msg)
# Methods to validate what will be sent to ui ---------
def check_fields(self, fields, values):
if len(fields) == 0:
return None
fields = list(fields[:]) # convert possible tuples to a list
values = list(values[:]) # convert possible tuples to a list
# TODO RL: The following seems incorrect when values>fields. Replace
# below with zip?
if len(values) == len(fields):
pass
elif len(values) > len(fields):
fields = fields[0:len(values)]
else:
while len(values) < len(fields):
values.append("")
return fields, values
class GUItk(object):
""" This object contains the tk root object.
It draws the window, waits for events and communicates them
to MultiBox, together with the entered values.
The position in wich it is drawn comes from a global variable.
It also accepts commands from Multibox to change its message.
"""
def __init__(self, msg, title, fields, values, mask_last, callback):
self.callback = callback
self.boxRoot = tk.Tk()
self.create_root(title)
self.set_pos(global_state.window_position) # GLOBAL POSITION
self.create_msg_widget(msg)
self.create_entryWidgets(fields, values, mask_last)
self.create_buttons()
self.entryWidgets[0].focus_force() # put the focus on the entryWidget
# Run and stop methods ---------------------------------------
def run(self):
self.boxRoot.mainloop() # run it!
self.boxRoot.destroy() # Close the window
def stop(self):
# Get the current position before quitting
self.get_pos()
self.boxRoot.quit()
def x_pressed(self):
self.callback(self, command='x', values=self.get_values())
def cancel_pressed(self, event):
self.callback(self, command='cancel', values=self.get_values())
def ok_pressed(self, event):
self.callback(self, command='update', values=self.get_values())
# Methods to change content ---------------------------------------
def set_msg(self, msg):
self.messageWidget.configure(text=msg)
self.entryWidgets[0].focus_force() # put the focus on the entryWidget
def set_pos(self, pos):
self.boxRoot.geometry(pos)
def get_pos(self):
# The geometry() method sets a size for the window and positions it on
# the screen. The first two parameters are width and height of
# the window. The last two parameters are x and y screen coordinates.
# geometry("250x150+300+300")
geom = self.boxRoot.geometry() # "628x672+300+200"
global_state.window_position = '+' + geom.split('+', 1)[1]
def get_values(self):
values = []
for entryWidget in self.entryWidgets:
values.append(entryWidget.get())
return values
# Initial configuration methods ---------------------------------------
# These ones are just called once, at setting.
def create_root(self, title):
self.boxRoot.protocol('WM_DELETE_WINDOW', self.x_pressed)
self.boxRoot.title(title)
self.boxRoot.iconname('Dialog')
self.boxRoot.bind("", self.cancel_pressed)
self.boxRoot.attributes("-topmost", True) # Put the dialog box in focus.
def create_msg_widget(self, msg):
# -------------------- the msg widget ----------------------------
self.messageWidget = tk.Message(self.boxRoot, width="4.5i", text=msg)
self.messageWidget.configure(
font=(global_state.PROPORTIONAL_FONT_FAMILY, global_state.PROPORTIONAL_FONT_SIZE))
self.messageWidget.pack(
side=tk.TOP, expand=1, fill=tk.BOTH, padx='3m', pady='3m')
def create_entryWidgets(self, fields, values, mask_last):
self.entryWidgets = []
lastWidgetIndex = len(fields) - 1
for widgetIndex in range(len(fields)):
name = fields[widgetIndex]
value = values[widgetIndex]
entryFrame = tk.Frame(master=self.boxRoot)
entryFrame.pack(side=tk.TOP, fill=tk.BOTH)
# --------- entryWidget -------------------------------------------
labelWidget = tk.Label(entryFrame, text=name)
labelWidget.pack(side=tk.LEFT)
entryWidget = tk.Entry(entryFrame, width=40, highlightthickness=2)
self.entryWidgets.append(entryWidget)
entryWidget.configure(
font=(global_state.PROPORTIONAL_FONT_FAMILY, global_state.TEXT_ENTRY_FONT_SIZE))
entryWidget.pack(side=tk.RIGHT, padx="3m")
self.bindArrows(entryWidget)
entryWidget.bind("", self.ok_pressed)
entryWidget.bind("", self.cancel_pressed)
# for the last entryWidget, if this is a multpasswordbox,
# show the contents as just asterisks
if widgetIndex == lastWidgetIndex:
if mask_last:
self.entryWidgets[widgetIndex].configure(show="*")
# put text into the entryWidget
if value is None:
value = ''
self.entryWidgets[widgetIndex].insert(
0, '{}'.format(value))
def create_buttons(self):
self.buttonsFrame = tk.Frame(master=self.boxRoot)
self.buttonsFrame.pack(side=tk.BOTTOM)
self.create_cancel_button()
self.create_ok_button()
def create_ok_button(self):
okButton = tk.Button(self.buttonsFrame, takefocus=1, text="OK")
self.bindArrows(okButton)
okButton.pack(expand=1, side=tk.LEFT, padx='3m', pady='3m',
ipadx='2m', ipady='1m')
# for the commandButton, bind activation events to the activation event
# handler
commandButton = okButton
handler = self.ok_pressed
for selectionEvent in global_state.STANDARD_SELECTION_EVENTS:
commandButton.bind("<%s>" % selectionEvent, handler)
def create_cancel_button(self):
cancelButton = tk.Button(self.buttonsFrame, takefocus=1, text="Cancel")
self.bindArrows(cancelButton)
cancelButton.pack(expand=1, side=tk.LEFT, padx='3m', pady='3m',
ipadx='2m', ipady='1m')
# for the commandButton, bind activation events to the activation event
# handler
commandButton = cancelButton
handler = self.cancel_pressed
for selectionEvent in global_state.STANDARD_SELECTION_EVENTS:
commandButton.bind("<%s>" % selectionEvent, handler)
def bindArrows(self, widget):
widget.bind("", self.tabRight)
widget.bind("", self.tabLeft)
widget.bind("", self.tabRight)
widget.bind("", self.tabLeft)
def tabRight(self, event):
self.boxRoot.event_generate("")
def tabLeft(self, event):
self.boxRoot.event_generate("")
def demo1():
msg = "Enter your personal information"
title = "Credit Card Application"
fieldNames = ["Name", "Street Address", "City", "State", "ZipCode"]
fieldValues = [] # we start with blanks for the values
# make sure that none of the fields was left blank
while True:
fieldValues = multenterbox(msg, title, fieldNames, fieldValues)
cancelled = fieldValues is None
errors = []
if cancelled:
pass
else: # check for errors
for name, value in zip(fieldNames, fieldValues):
if value.strip() == "":
errors.append('"{}" is a required field.'.format(name))
all_ok = not errors
if cancelled or all_ok:
break # no problems found
msg = "\n".join(errors)
print("Reply was: {}".format(fieldValues))
class Demo2():
def __init__(self):
msg = "Without flicker. Enter your personal information"
title = "Credit Card Application"
fieldNames = ["Name", "Street Address", "City", "State", "ZipCode"]
fieldValues = [] # we start with blanks for the values
fieldValues = multenterbox(msg, title, fieldNames, fieldValues,
callback=self.check_for_blank_fields)
print("Reply was: {}".format(fieldValues))
def check_for_blank_fields(self, box):
# make sure that none of the fields was left blank
cancelled = box.values is None
errors = []
if cancelled:
pass
else: # check for errors
for name, value in zip(box.fields, box.values):
if value.strip() == "":
errors.append('"{}" is a required field.'.format(name))
all_ok = not errors
if cancelled or all_ok:
box.stop() # no problems found
box.msg = "\n".join(errors)
if __name__ == '__main__':
demo1()
Demo2()
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/text_box.py 0000666 0000000 0000000 00000042251 00000000000 015154 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
import sys
try:
from . import global_state
except (SystemError, ValueError, ImportError):
import global_state
try:
import tkinter as tk # python 3
import tkinter.font as tk_Font
except:
import Tkinter as tk # python 2
import tkFont as tk_Font
def demo_textbox():
demo_1()
Demo2()
Demo3()
def demo_1():
title = "Demo of textbox: Classic box"
gnexp = ("This is a demo of the classic textbox call, "
"you can see it closes when ok is pressed.\n\n")
challenge = "INSERT A TEXT WITH MORE THAN TWO PARAGRAPHS"
text = "Insert your text here\n"
msg = gnexp + challenge
finished = False
while True:
text = textbox(msg, title, text)
escaped = not text
if escaped or finished:
break
if text.count("\n") >= 2:
msg = (u"You did it right! Press OK")
finished = True
else:
msg = u"You did it wrong! Try again!\n" + challenge
class Demo2(object):
""" Program that challenges the user to write 5 a's """
def __init__(self):
""" Set and run the program """
title = "Demo of textbox: Classic box with callback"
gnexp = ("This is a demo of the textbox with a callback, "
"it doesn't flicker!.\n\n")
msg = "INSERT A TEXT WITH FIVE OR MORE A\'s"
text_snippet = "Insert your text here"
self.finished = False
textbox(gnexp + msg, title, text_snippet, False,
callback=self.check_answer, run=True)
def check_answer(self, box):
""" Callback from TextBox
Parameters
-----------
box: object
object containing parameters and methods to communicate with the ui
Returns
-------
nothing:
its return is through the box object
"""
if self.finished:
box.stop()
if box.text.lower().count("a") >= 5:
box.msg = u"\n\nYou did it right! Press OK button to continue."
box.stop()
self.finished
else:
box.msg = u"\n\nMore a's are needed!"
class Demo3(object):
""" Program that challenges the user to find a typo """
def __init__(self):
""" Set and run the program """
self.finished = False
title = "Demo of textbox: Object with callback"
msg = ("This is a demo of the textbox set as "
"an object with a callback, "
"you can configure it and when you are finished, "
"you run it.\n\nThere is a typo in it. Find and correct it.")
text_snippet = "Hello" # This text wont show
box = textbox(
msg, title, text_snippet, False, callback=self.check_answer, run=False)
box.text = (
"It was the west of times, and it was the worst of times. "
"The rich ate cake, and the poor had cake recommended to them, "
"but wished only for enough cash to buy bread."
"The time was ripe for revolution! ")
box.run()
def check_answer(self, box):
""" Callback from TextBox
Parameters
----------
box: object
object containing parameters and methods to communicate with the ui
Returns
-------
nothing:
its return is through the box object
"""
if self.finished:
box.stop()
if "best" in box.text:
box.msg = u"\n\nYou did right! Press OK button to continue."
self.finished = True
else:
box.msg = u"\n\nLook to the west!"
def textbox(msg="", title=" ", text="",
codebox=False, callback=None, run=True):
"""Displays a dialog box with a large, multi-line text box, and returns
the entered text as a string. The message text is displayed in a
proportional font and wraps.
Parameters
----------
msg : string
text displayed in the message area (instructions...)
title : str
the window title
text: str, list or tuple
text displayed in textAreas (editable)
codebox: bool
if True, don't wrap and width is set to 80 chars
callback: function
if set, this function will be called when OK is pressed
run: bool
if True, a box object will be created and returned, but not run
Returns
-------
None
If cancel is pressed
str
If OK is pressed returns the contents of textArea
"""
tb = TextBox(msg=msg, title=title, text=text,
codebox=codebox, callback=callback)
if not run:
return tb
else:
reply = tb.run()
return reply
class TextBox(object):
""" Display a message and a text to edit
This object separates user from ui, defines which methods can
the user invoke and which properties can he change.
It also calls the ui in defined ways, so if other gui
library can be used (wx, qt) without breaking anything for the user.
"""
def __init__(self, msg, title, text, codebox, callback=lambda *args, **kwargs: True):
""" Create box object
Parameters
----------
msg : string
text displayed in the message area (instructions...)
title : str
the window title
text: str, list or tuple
text displayed in textAres (editable)
codebox: bool
if True, don't wrap and width is set to 80 chars
callback: function
if set, this function will be called when OK is pressed
Returns
-------
object
The box object
"""
self.callback = callback
self.ui = GUItk(msg, title, text, codebox, self.callback_ui)
self.text = text
def run(self):
""" Start the ui """
self.ui.run()
self.ui = None
return self._text
def stop(self):
""" Stop the ui """
self.ui.stop()
def callback_ui(self, ui, command, text):
""" This method is executed when ok, cancel, or x is pressed in the ui.
"""
if command == 'update': # OK was pressed
self._text = text
if self.callback:
# If a callback was set, call main process
self.callback(self)
else:
self.stop()
elif command == 'x':
self.stop()
self._text = None
elif command == 'cancel':
self.stop()
self._text = None
# methods to change properties --------------
@property
def text(self):
"""Text in text Area"""
return self._text
@text.setter
def text(self, text):
self._text = self.to_string(text)
self.ui.set_text(self._text)
@text.deleter
def text(self):
self._text = ""
self.ui.set_text(self._text)
@property
def msg(self):
"""Text in msg Area"""
return self._msg
@msg.setter
def msg(self, msg):
self._msg = self.to_string(msg)
self.ui.set_msg(self._msg)
@msg.deleter
def msg(self):
self._msg = ""
self.ui.set_msg(self._msg)
# Methods to validate what will be sent to ui ---------
def to_string(self, something):
try:
basestring # python 2
except NameError:
basestring = str # Python 3
if isinstance(something, basestring):
return something
try:
text = "".join(something) # convert a list or a tuple to a string
except:
textbox(
"Exception when trying to convert {} to text in self.textArea"
.format(type(something)))
sys.exit(16)
return text
class GUItk(object):
""" This is the object that contains the tk root object"""
def __init__(self, msg, title, text, codebox, callback):
""" Create ui object
Parameters
----------
msg : string
text displayed in the message area (instructions...)
title : str
the window title
text: str, list or tuple
text displayed in textAres (editable)
codebox: bool
if True, don't wrap, and width is set to 80 chars
callback: function
if set, this function will be called when OK is pressed
Returns
-------
object
The ui object
"""
self.callback = callback
self.boxRoot = tk.Tk()
# self.boxFont = tk_Font.Font(
# family=global_state.PROPORTIONAL_FONT_FAMILY,
# size=global_state.PROPORTIONAL_FONT_SIZE)
wrap_text = not codebox
if wrap_text:
self.boxFont = tk_Font.nametofont("TkTextFont")
self.width_in_chars = global_state.prop_font_line_length
else:
self.boxFont = tk_Font.nametofont("TkFixedFont")
self.width_in_chars = global_state.fixw_font_line_length
# default_font.configure(size=global_state.PROPORTIONAL_FONT_SIZE)
self.configure_root(title)
self.create_msg_widget(msg)
self.create_text_area(wrap_text)
self.create_buttons_frame()
self.create_cancel_button()
self.create_ok_button()
# Run and stop methods ---------------------------------------
def run(self):
self.boxRoot.mainloop()
self.boxRoot.destroy()
def stop(self):
# Get the current position before quitting
self.get_pos()
self.boxRoot.quit()
# Methods to change content ---------------------------------------
def set_msg(self, msg):
self.messageArea.config(state=tk.NORMAL)
self.messageArea.delete(1.0, tk.END)
self.messageArea.insert(tk.END, msg)
self.messageArea.config(state=tk.DISABLED)
# Adjust msg height
self.messageArea.update()
numlines = self.get_num_lines(self.messageArea)
self.set_msg_height(numlines)
self.messageArea.update()
def set_msg_height(self, numlines):
self.messageArea.configure(height=numlines)
def get_num_lines(self, widget):
end_position = widget.index(tk.END) # '4.0'
end_line = end_position.split('.')[0] # 4
return int(end_line) # 5
def set_text(self, text):
self.textArea.delete(1.0, tk.END)
self.textArea.insert(tk.END, text, "normal")
self.textArea.focus()
def set_pos(self, pos):
self.boxRoot.geometry(pos)
def get_pos(self):
# The geometry() method sets a size for the window and positions it on
# the screen. The first two parameters are width and height of
# the window. The last two parameters are x and y screen coordinates.
# geometry("250x150+300+300")
geom = self.boxRoot.geometry() # "628x672+300+200"
global_state.window_position = '+' + geom.split('+', 1)[1]
def get_text(self):
return self.textArea.get(0.0, 'end-1c')
# Methods executing when a key is pressed -------------------------------
def x_pressed(self):
self.callback(self, command='x', text=self.get_text())
def cancel_pressed(self, event):
self.callback(self, command='cancel', text=self.get_text())
def ok_button_pressed(self, event):
self.callback(self, command='update', text=self.get_text())
# Auxiliary methods -----------------------------------------------
def calc_character_width(self):
char_width = self.boxFont.measure('W')
return char_width
# Initial configuration methods ---------------------------------------
# These ones are just called once, at setting.
def configure_root(self, title):
self.boxRoot.title(title)
self.set_pos(global_state.window_position)
# Quit when x button pressed
self.boxRoot.protocol('WM_DELETE_WINDOW', self.x_pressed)
self.boxRoot.bind("", self.cancel_pressed)
self.boxRoot.iconname('Dialog')
self.boxRoot.attributes("-topmost", True) # Put the dialog box in focus.
def create_msg_widget(self, msg):
if msg is None:
msg = ""
self.msgFrame = tk.Frame(
self.boxRoot,
padx=1.25 * self.calc_character_width(),
)
self.messageArea = tk.Text(
self.msgFrame,
width=self.width_in_chars,
state=tk.DISABLED,
padx=(global_state.default_hpad_in_chars) *
self.calc_character_width(),
pady=self.calc_character_width(),
wrap=tk.WORD,
)
self.set_msg(msg)
self.msgFrame.pack(fill='x')
self.messageArea.pack(fill='x')
def create_text_area(self, wrap_text):
"""
Put a textArea in the top frame
Put and configure scrollbars
"""
self.textFrame = tk.Frame(
self.boxRoot,
padx=1.25 * self.calc_character_width(),
)
self.textFrame.pack(side=tk.TOP)
# self.textFrame.grid(row=1, column=0, sticky=tk.EW)
self.textArea = tk.Text(
self.textFrame,
padx=global_state.default_hpad_in_chars *
self.calc_character_width(),
pady=global_state.default_hpad_in_chars *
self.calc_character_width(),
height=25, # lines. Note: a user-set arg would be preferable to hardcoded value
width=self.width_in_chars, # chars of the current font
)
if wrap_text:
self.textArea.configure(wrap=tk.WORD)
else:
self.textArea.configure(wrap=tk.NONE)
# some simple keybindings for scrolling
self.boxRoot.bind("", self.textArea.yview_scroll(1, tk.PAGES))
self.boxRoot.bind(
"", self.textArea.yview_scroll(-1, tk.PAGES))
self.boxRoot.bind("", self.textArea.xview_scroll(1, tk.PAGES))
self.boxRoot.bind("", self.textArea.xview_scroll(-1, tk.PAGES))
self.boxRoot.bind("", self.textArea.yview_scroll(1, tk.UNITS))
self.boxRoot.bind("", self.textArea.yview_scroll(-1, tk.UNITS))
# add a vertical scrollbar to the frame
rightScrollbar = tk.Scrollbar(
self.textFrame, orient=tk.VERTICAL, command=self.textArea.yview)
self.textArea.configure(yscrollcommand=rightScrollbar.set)
# add a horizontal scrollbar to the frame
bottomScrollbar = tk.Scrollbar(
self.textFrame, orient=tk.HORIZONTAL, command=self.textArea.xview)
self.textArea.configure(xscrollcommand=bottomScrollbar.set)
# pack the textArea and the scrollbars. Note that although
# we must define the textArea first, we must pack it last,
# so that the bottomScrollbar will be located properly.
# Note that we need a bottom scrollbar only for code.
# Text will be displayed with wordwrap, so we don't need to have
# a horizontal scroll for it.
if not wrap_text:
bottomScrollbar.pack(side=tk.BOTTOM, fill=tk.X)
rightScrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.textArea.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.YES)
def create_buttons_frame(self):
self.buttonsFrame = tk.Frame(self.boxRoot,
# background="green",
)
self.buttonsFrame.pack(side=tk.TOP)
def create_cancel_button(self):
# put the buttons in the buttonsFrame
self.cancelButton = tk.Button(
self.buttonsFrame, takefocus=tk.YES, text="Cancel",
height=1, width=6)
self.cancelButton.pack(
expand=tk.NO, side=tk.LEFT, padx='2m', pady='1m', ipady="1m",
ipadx="2m")
# for the commandButton, bind activation events to the activation event
# handler
self.cancelButton.bind("", self.cancel_pressed)
self.cancelButton.bind("", self.cancel_pressed)
self.cancelButton.bind("", self.cancel_pressed)
def create_ok_button(self):
# put the buttons in the buttonsFrame
self.okButton = tk.Button(
self.buttonsFrame, takefocus=tk.YES, text="OK", height=1, width=6)
self.okButton.pack(
expand=tk.NO, side=tk.LEFT, padx='2m', pady='1m', ipady="1m",
ipadx="2m")
# for the commandButton, bind activation events to the activation event
# handler
self.okButton.bind("", self.ok_button_pressed)
self.okButton.bind("", self.ok_button_pressed)
if __name__ == '__main__':
demo_textbox()
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/boxes/utils.py 0000666 0000000 0000000 00000015306 00000000000 014461 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
"""
import os
import sys
import traceback
# A set of variables and functions to centralize differences between
# python 2 and 3
runningPython27 = False
runningPython34 = False
if 0x020700F0 <= sys.hexversion <= 0x030000F0:
runningPython27 = True
if 0x030400F0 <= sys.hexversion <= 0x040000F0:
runningPython34 = True
if not runningPython27 and not runningPython34:
raise Exception("You must run on Python 2.7+ or Python 3.4+")
# Import Tkinter, the tk filedialog, and put everything in tkinter into
# the current namespace
try:
import tkinter as tk # python3
# TODO: Ultimately this should go away once everything stops using it.
from tkinter import *
import tkinter.filedialog as tk_FileDialog
import tkinter.font as tk_Font
except ImportError:
try:
import Tkinter as tk # python2
# TODO: Ultimately this should go away once everything stops using it.
from Tkinter import *
import tkFileDialog as tk_FileDialog
import tkFont as tk_Font
except ImportError:
raise ImportError("Unable to find tkinter package.")
if tk.TkVersion < 8.0:
raise ImportError("You must use python-tk (tkinter) version 8.0 or higher")
# Try to import the Python Image Library. If it doesn't exist, only .gif
# images are supported.
try:
from PIL import Image as PILImage
from PIL import ImageTk as PILImageTk
except:
pass
# Code should use 'basestring' anywhere you might think to use the system 'str'. This is all to support
# Python 2. If 2 ever goes away, this logic can go away and uses of
# utils.basestring should be changed to just str
if runningPython27:
basestring = basestring
if runningPython34:
basestring = str
# -----------------------------------------------------------------------
# exception_format
# -----------------------------------------------------------------------
def exception_format():
"""
Convert exception info into a string suitable for display.
"""
return "".join(traceback.format_exception(
sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]
))
# -------------------------------------------------------------------
# utility routines
# -------------------------------------------------------------------
# These routines are used by several other functions in the EasyGui module.
def uniquify_list_of_strings(input_list):
"""
Ensure that every string within input_list is unique.
:param list input_list: List of strings
:return: New list with unique names as needed.
"""
output_list = list()
for i, item in enumerate(input_list):
tempList = input_list[:i] + input_list[i + 1:]
if item not in tempList:
output_list.append(item)
else:
output_list.append('{0}_{1}'.format(item, i))
return output_list
import re
def parse_hotkey(text):
"""
Extract a desired hotkey from the text. The format to enclose
the hotkey in square braces
as in Button_[1] which would assign the keyboard key 1 to that button.
The one will be included in the
button text. To hide they key, use double square braces as in: Ex[[qq]]
it , which would assign
the q key to the Exit button. Special keys such as may also be
used: Move [] for a full
list of special keys, see this reference: http://infohoglobal_state.nmt.edu/tcc/help/
pubs/tkinter/web/key-names.html
:param text:
:return: list containing cleaned text, hotkey, and hotkey position within
cleaned text.
"""
ret_val = [text, None, None] # Default return values
if text is None:
return ret_val
# Single character, remain visible
res = re.search(r'(?<=\[).(?=\])', text)
if res:
start = res.start(0)
end = res.end(0)
caption = text[:start - 1] + text[start:end] + text[end + 1:]
ret_val = [caption, text[start:end], start - 1]
# Single character, hide it
res = re.search(r'(?<=\[\[).(?=\]\])', text)
if res:
start = res.start(0)
end = res.end(0)
caption = text[:start - 2] + text[end + 2:]
ret_val = [caption, text[start:end], None]
# a Keysym. Always hide it
res = re.search(r'(?<=\[\<).+(?=\>\])', text)
if res:
start = res.start(0)
end = res.end(0)
caption = text[:start - 2] + text[end + 2:]
ret_val = [caption, '<{}>'.format(text[start:end]), None]
return ret_val
def load_tk_image(filename, tk_master=None):
"""
Load in an image file and return as a tk Image.
Loads an image. If the PIL library is available use it. otherwise use the tk method.
NOTE: tk_master is required if there are more than one Tk() instances, which there are very often.
REF: http://stackoverflow.com/a/23229091/2184122
:param filename: image filename to load
:param tk_master: root object (Tk())
:return: tk Image object
"""
if filename is None:
return None
if not os.path.isfile(filename):
raise ValueError(
'Image file {} does not exist.'.format(filename))
tk_image = None
filename = os.path.normpath(filename)
_, ext = os.path.splitext(filename)
try:
pil_image = PILImage.open(filename)
tk_image = PILImageTk.PhotoImage(pil_image, master=tk_master)
except:
try:
# Fallback if PIL isn't available
tk_image = tk.PhotoImage(file=filename, master=tk_master)
except:
msg = "Cannot load {}. Check to make sure it is an image file.".format(
filename)
try:
_ = PILImage
except:
msg += "\nPIL library isn't installed. If it isn't installed, only .gif files can be used."
raise ValueError(msg)
return tk_image
# -------------------------------------------------------------------
# getFileDialogTitle
# -------------------------------------------------------------------
def getFileDialogTitle(msg, title):
"""
Create nicely-formatted string based on arguments msg and title
:param msg: the msg to be displayed
:param title: the window title
:return: None
"""
if msg and title:
return "%s - %s" % (title, msg)
if msg and not title:
return str(msg)
if title and not msg:
return str(title)
return None # no message and no title
if __name__ == '__main__':
print("Hello from utils")
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648571507.0
easygui-0.98.3/easygui/easygui.py 0000666 0000000 0000000 00000006541 00000000000 013650 0 ustar 00 """
.. moduleauthor:: easygui developers and Stephen Raymond Ferg
.. default-domain:: py
.. highlight:: python
Version |release|
ABOUT EASYGUI
=============
EasyGUI provides an easy-to-use interface for simple GUI interaction
with a user. It does not require the programmer to know anything about
tkinter, frames, widgets, callbacks or lambda. All GUI interactions are
invoked by simple function calls that return results.
.. warning:: Using EasyGUI with IDLE
You may encounter problems using IDLE to run programs that use EasyGUI. Try it
and find out. EasyGUI is a collection of Tkinter routines that run their own
event loops. IDLE is also a Tkinter application, with its own event loop. The
two may conflict, with unpredictable results. If you find that you have
problems, try running your EasyGUI program outside of IDLE.
.. note:: EasyGUI requires Tk release 8.0 or greater.
LICENSE INFORMATION
===================
EasyGUI version |version|
Copyright (c) 2014, Stephen Raymond Ferg
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ABOUT THE EASYGUI LICENSE
-------------------------
| This license is what is generally known as the "modified BSD license",
| aka "revised BSD", "new BSD", "3-clause BSD".
| See http://www.opensource.org/licenses/bsd-license.php
|
| This license is GPL-compatible.
| See ``_
| See http://www.gnu.org/licenses/license-liglobal_state.html#GPLCompatibleLicenses
|
| The BSD License is less restrictive than GPL.
| It allows software released under the license to be incorporated into proprietary products.
| Works based on the software may be released under a proprietary license or as closed source software.
| ``_
API
===
"""
if __name__ == '__main__':
from boxes.demo import easygui_demo
easygui_demo()
# from boxes.alt_text_box import demo_textbox
# demo_textbox()
././@PaxHeader 0000000 0000000 0000000 00000000026 00000000000 010213 x ustar 00 22 mtime=1648567478.0
easygui-0.98.3/easygui/python_and_check_logo.gif 0000666 0000000 0000000 00000061030 00000000000 016631 0 ustar 00 GIF89aa a , U4D U } ( q0 ( y ( <