Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to all boxes to allow user to change window/taskbar icon #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Changes to all boxes to allow user to change window/taskbar icon
  • Loading branch information
AustinTurney committed May 19, 2023
commit 77cd722615efb431c1ff12a6e95fcf95e6d5a8c1
18 changes: 13 additions & 5 deletions easygui/boxes/button_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def buttonbox(msg="",
default_choice=None,
cancel_choice=None,
callback=None,
run=True):
run=True,
icon = None):
"""
Display a message, a title, an image, and a set of buttons.
The buttons are defined by the members of the choices argument.
Expand Down Expand Up @@ -99,7 +100,8 @@ def buttonbox(msg="",
images=images,
default_choice=default_choice,
cancel_choice=cancel_choice,
callback=callback)
callback=callback,
icon = icon)
if not run:
return bb
else:
Expand All @@ -117,7 +119,7 @@ class ButtonBox(object):
library can be used (wx, qt) without breaking anything for the user.
"""

def __init__(self, msg, title, choices, images, default_choice, cancel_choice, callback):
def __init__(self, msg, title, choices, images, default_choice, cancel_choice, callback, icon):
""" Create box object

Parameters
Expand All @@ -144,7 +146,7 @@ def __init__(self, msg, title, choices, images, default_choice, cancel_choice, c
"""

self.callback = callback
self.ui = GUItk(msg, title, choices, images, default_choice, cancel_choice, self.callback_ui)
self.ui = GUItk(msg, title, choices, images, default_choice, cancel_choice, self.callback_ui, icon)

def run(self):
""" Start the ui """
Expand Down Expand Up @@ -224,7 +226,7 @@ def to_string(self, something):
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):
def __init__(self, msg, title, choices, images, default_choice, cancel_choice, callback, icon):
""" Create ui object

Parameters
Expand Down Expand Up @@ -272,6 +274,8 @@ def __init__(self, msg, title, choices, images, default_choice, cancel_choice, c

self.configure_root(title)

self.config_icon(icon)

self.create_msg_widget(msg)

self.create_images_frame()
Expand Down Expand Up @@ -398,6 +402,10 @@ def configure_root(self, title):
self.boxRoot.iconname('Dialog')
self.boxRoot.attributes("-topmost", True) # Put the dialog box in focus.

def config_icon(self, icon):
if icon:
self.boxRoot.iconbitmap(icon)

def create_msg_widget(self, msg):

if msg is None:
Expand Down
15 changes: 10 additions & 5 deletions easygui/boxes/choice_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

def choicebox(msg="Pick an item", title="", choices=None, preselect=0,
callback=None,
run=True):
run=True, icon=None):
"""
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).
Expand All @@ -44,7 +44,7 @@ def choicebox(msg="Pick an item", title="", choices=None, preselect=0,
"""
mb = ChoiceBox(msg, title, choices, preselect=preselect,
multiple_select=False,
callback=callback)
callback=callback, icon=icon)
if run:
reply = mb.run()
return reply
Expand Down Expand Up @@ -117,7 +117,7 @@ def make_list_or_none(obj, cast_type=None):

class ChoiceBox(object):

def __init__(self, msg, title, choices, preselect, multiple_select, callback):
def __init__(self, msg, title, choices, preselect, multiple_select, callback, icon):

self.callback = callback

Expand All @@ -132,7 +132,7 @@ def __init__(self, msg, title, choices, preselect, multiple_select, callback):
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)
self.callback_ui, icon)

def run(self):
""" Start the ui """
Expand Down Expand Up @@ -200,7 +200,7 @@ class GUItk(object):
It also accepts commands from Multibox to change its message.
"""

def __init__(self, msg, title, choices, preselect, multiple_select, callback):
def __init__(self, msg, title, choices, preselect, multiple_select, callback, icon):

self.callback = callback

Expand All @@ -219,6 +219,7 @@ def __init__(self, msg, title, choices, preselect, multiple_select, callback):
self.boxFont = tk_Font.nametofont("TkTextFont")

self.config_root(title)
self.config_icon(icon)

self.set_pos(global_state.window_position) # GLOBAL POSITION

Expand Down Expand Up @@ -336,6 +337,10 @@ def config_root(self, title):
self.boxRoot.bind("<Escape>", self.cancel_pressed)

self.boxRoot.attributes("-topmost", True) # Put the dialog box in focus.

def config_icon(self, icon):
if icon:
self.boxRoot.iconbitmap(icon)

def create_msg_widget(self, msg):

Expand Down
45 changes: 25 additions & 20 deletions easygui/boxes/derived_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

def ynbox(msg="Shall I continue?", title=" ",
choices=("[<F1>]Yes", "[<F2>]No"), image=None,
default_choice='[<F1>]Yes', cancel_choice='[<F2>]No'):
default_choice='[<F1>]Yes', cancel_choice='[<F2>]No', icon=None):
"""
The ``ynbox()`` offers a choice of Yes and No, and returns either ``True`` or ``False``.

Expand Down Expand Up @@ -56,7 +56,8 @@ def ynbox(msg="Shall I continue?", title=" ",
choices=choices,
image=image,
default_choice=default_choice,
cancel_choice=cancel_choice)
cancel_choice=cancel_choice,
icon = icon)

# -----------------------------------------------------------------------
# ccbox
Expand All @@ -65,7 +66,7 @@ def ynbox(msg="Shall I continue?", title=" ",

def ccbox(msg="Shall I continue?", title=" ",
choices=("C[o]ntinue", "C[a]ncel"), image=None,
default_choice='Continue', cancel_choice='Cancel'):
default_choice='Continue', cancel_choice='Cancel', icon = None):
"""
The ``ccbox()`` function offers a choice of Continue and Cancel, and returns either True (for continue) or False (for cancel).

Expand Down Expand Up @@ -93,7 +94,8 @@ def ccbox(msg="Shall I continue?", title=" ",
choices=choices,
image=image,
default_choice=default_choice,
cancel_choice=cancel_choice)
cancel_choice=cancel_choice,
icon = icon)

# -----------------------------------------------------------------------
# boolbox
Expand All @@ -102,7 +104,7 @@ def ccbox(msg="Shall I continue?", title=" ",

def boolbox(msg="Shall I continue?", title=" ",
choices=("[T]rue", "[F]alse"), image=None,
default_choice='[T]rue', cancel_choice='[F]alse'):
default_choice='[T]rue', cancel_choice='[F]alse', icon=None):
"""
The ``boolbox()`` (boolean box) displays two buttons. Returns returns
``True`` if the first button is chosen. Otherwise returns ``False``.
Expand Down Expand Up @@ -135,7 +137,8 @@ def boolbox(msg="Shall I continue?", title=" ",
choices=choices,
image=image,
default_choice=default_choice,
cancel_choice=cancel_choice)
cancel_choice=cancel_choice,
icon=icon)

if reply == choices[0]:
return True # The first button (True) was selected.
Expand All @@ -152,7 +155,7 @@ def boolbox(msg="Shall I continue?", title=" ",
# -----------------------------------------------------------------------
def indexbox(msg="Shall I continue?", title=" ",
choices=("Yes", "No"), image=None,
default_choice='Yes', cancel_choice='No'):
default_choice='Yes', cancel_choice='No', icon = None):
"""
The ``indexbox()`` function displays a set of buttons, and returns the
index of the selected button. For example, if you invoked index box with
Expand Down Expand Up @@ -181,7 +184,8 @@ def indexbox(msg="Shall I continue?", title=" ",
choices=choices,
image=image,
default_choice=default_choice,
cancel_choice=cancel_choice)
cancel_choice=cancel_choice,
icon=icon)
if reply is None:
return None
for i, choice in enumerate(choices):
Expand All @@ -197,7 +201,7 @@ def indexbox(msg="Shall I continue?", title=" ",
# msgbox
# -----------------------------------------------------------------------
def msgbox(msg="(Your message goes here)", title=" ",
ok_button="OK", image=None, root=None):
ok_button="OK", image=None, root=None, icon=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
Expand Down Expand Up @@ -232,7 +236,8 @@ def msgbox(msg="(Your message goes here)", title="", ok_button="OK"):
choices=[ok_button],
image=image,
default_choice=ok_button,
cancel_choice=ok_button)
cancel_choice=ok_button,
icon=icon)


def convert_to_type(input_value, new_type, input_value_name=None):
Expand Down Expand Up @@ -262,7 +267,7 @@ def convert_to_type(input_value, new_type, input_value_name=None):
# integerbox
# -------------------------------------------------------------------
def integerbox(msg="", title=" ", default=None,
lowerbound=0, upperbound=99, image=None, root=None):
lowerbound=0, upperbound=99, image=None, root=None, icon=None):
"""
Show a box in which a user can enter an integer.

Expand Down Expand Up @@ -303,7 +308,7 @@ def integerbox(msg="", title=" ", default=None,
upperbound = convert_to_type(upperbound, int, "upperbound")

while True:
reply = enterbox(msg, title, default, image=image, root=root)
reply = enterbox(msg, title, default, image=image, root=root, icon = icon)
if reply is None:
return None
try:
Expand Down Expand Up @@ -334,7 +339,7 @@ def integerbox(msg="", title=" ", default=None,
# enterbox
# -------------------------------------------------------------------
def enterbox(msg="Enter something.", title=" ", default="",
strip=True, image=None, root=None):
strip=True, image=None, root=None, icon=None):
"""
Show a box in which a user can enter some text.

Expand All @@ -359,14 +364,14 @@ def enterbox(msg="Enter something.", title=" ", default="",
the operation.
"""
result = __fillablebox(
msg, title, default=default, mask=None, image=image, root=root)
msg, title, default=default, mask=None, image=image, root=root, icon=icon)
if result and strip:
result = result.strip()
return result


def passwordbox(msg="Enter your password.", title=" ", default="",
image=None, root=None):
image=None, root=None, icon=None):
"""
Show a box in which a user can enter a password.
The text is masked with asterisks, so the password is not displayed.
Expand All @@ -378,13 +383,13 @@ def passwordbox(msg="Enter your password.", title=" ", default="",
the operation.
"""
return __fillablebox(msg, title, default, mask="*",
image=image, root=root)
image=image, root=root, icon=icon)


# -----------------------------------------------------------------------
# exceptionbox
# -----------------------------------------------------------------------
def exceptionbox(msg=None, title=None):
def exceptionbox(msg=None, title=None, icon=None):
"""
Display a box that gives information about
an exception that has just been raised.
Expand All @@ -405,14 +410,14 @@ def exceptionbox(msg=None, title=None):
if msg is None:
msg = "An error (exception) has occurred in the program."

codebox(msg, title, ut.exception_format())
codebox(msg, title, ut.exception_format(), icon=icon)


# -------------------------------------------------------------------
# codebox
# -------------------------------------------------------------------

def codebox(msg="", title=" ", text=""):
def codebox(msg="", title=" ", text="", icon=None):
"""
Display some text in a monospaced font, with no line wrapping.
This function is suitable for displaying code and text that is
Expand All @@ -425,4 +430,4 @@ def codebox(msg="", title=" ", text=""):
:param str title: the window title
:param str text: what to display in the textbox
"""
return tb.textbox(msg, title, text, codebox=True)
return tb.textbox(msg, title, text, codebox=True, icon=icon)
3 changes: 2 additions & 1 deletion easygui/boxes/diropen_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# -------------------------------------------------------------------
# diropenbox
# -------------------------------------------------------------------
def diropenbox(msg=None, title=None, default=None):
def diropenbox(msg=None, title=None, default=None, icon=None):
"""
A dialog to get a directory name.

Expand All @@ -42,6 +42,7 @@ def diropenbox(msg=None, title=None, default=None):
title = ut.getFileDialogTitle(msg, title)
localRoot = tk.Tk()
localRoot.withdraw()
localRoot.iconbitmap(icon)
localRoot.attributes("-topmost", True)
if not default:
default = None
Expand Down
3 changes: 2 additions & 1 deletion easygui/boxes/fileopen_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# -------------------------------------------------------------------


def fileopenbox(msg=None, title=None, default='*', filetypes=None, multiple=False):
def fileopenbox(msg=None, title=None, default='*', filetypes=None, multiple=False, icon = None):
"""
Displays an "open file" dialog box and returns the selected file as a string.

Expand Down Expand Up @@ -83,6 +83,7 @@ def fileopenbox(msg=None, title=None, default='*', filetypes=None, multiple=Fals
:return: the name of a file, or None if user chose to cancel
"""
localRoot = tk.Tk()
localRoot.iconbitmap(icon)
localRoot.withdraw()
localRoot.attributes("-topmost", True)

Expand Down
3 changes: 2 additions & 1 deletion easygui/boxes/filesave_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# -------------------------------------------------------------------


def filesavebox(msg=None, title=None, default="", filetypes=None):
def filesavebox(msg=None, title=None, default="", filetypes=None,icon=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.
Expand Down Expand Up @@ -64,6 +64,7 @@ def filesavebox(msg=None, title=None, default="", filetypes=None):
"""

localRoot = tk.Tk()
localRoot.iconbitmap(icon)
localRoot.withdraw()
localRoot.attributes("-topmost", True)

Expand Down
3 changes: 2 additions & 1 deletion easygui/boxes/fillable_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
okButton = None


def __fillablebox(msg, title="", default="", mask=None, image=None, root=None):
def __fillablebox(msg, title="", default="", mask=None, image=None, root=None, icon=None):
"""
Show a box in which a user can enter some text.
You may optionally specify some default text, which will appear in the
Expand Down Expand Up @@ -53,6 +53,7 @@ def __fillablebox(msg, title="", default="", mask=None, image=None, root=None):

boxRoot.protocol('WM_DELETE_WINDOW', __enterboxQuit)
boxRoot.title(title)
boxRoot.iconbitmap(icon)
boxRoot.iconname('Dialog')
boxRoot.geometry(global_state.window_position)
boxRoot.bind("<Escape>", __enterboxCancel)
Expand Down
Loading