Skip to content

Commit be1aa4f

Browse files
Release 3.14.1, 1.14.1 + new window feature disable_close
1 parent d343308 commit be1aa4f

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

PySimpleGUI.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_but
27022702
progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False,
27032703
auto_close_duration=DEFAULT_AUTOCLOSE_TIME, icon=DEFAULT_WINDOW_ICON, force_toplevel=False,
27042704
alpha_channel=1, return_keyboard_events=False, use_default_focus=True, text_justification=None,
2705-
no_titlebar=False, grab_anywhere=False, keep_on_top=False, resizable=False):
2705+
no_titlebar=False, grab_anywhere=False, keep_on_top=False, resizable=False, disable_close=False):
27062706
'''
27072707
Window
27082708
:param title:
@@ -2774,6 +2774,7 @@ def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_but
27742774
self.Timeout = None
27752775
self.TimeoutKey = '_timeout_'
27762776
self.TimerCancelled = False
2777+
self.DisableClose = disable_close
27772778

27782779
# ------------------------- Add ONE Row to Form ------------------------- #
27792780
def AddRow(self, *args):
@@ -3123,6 +3124,8 @@ def Close(self):
31233124

31243125
# IT FINALLY WORKED! 29-Oct-2018 was the first time this damned thing got called
31253126
def OnClosingCallback(self):
3127+
if self.DisableClose:
3128+
return
31263129
# print('Got closing callback')
31273130
self.TKroot.quit() # kick the users out of the mainloop
31283131
if self.CurrentlyRunningMainloop: # quit if this is the current mainloop, otherwise don't quit!
@@ -4679,9 +4682,9 @@ def StartupTK(my_flex_form):
46794682
# hidden window
46804683
_my_windows.Increment()
46814684
_my_windows.hidden_master_root = tk.Tk()
4682-
_my_windows.hidden_master_root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
4683-
_my_windows.hidden_master_root.wm_overrideredirect(True)
4684-
_my_windows.hidden_master_root.withdraw()
4685+
_my_windows.hidden_master_root.attributes('-alpha', 0) # HIDE this window really really really good
4686+
_my_windows.hidden_master_root.wm_overrideredirect(True) # damn, what did this do again?
4687+
_my_windows.hidden_master_root.withdraw() # no, REALLY hide it
46854688
# root = tk.Tk() # users windows are no longer using tk.Tk. They are all Toplevel windows
46864689
root = tk.Toplevel()
46874690
else:

PySimpleGUI27.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,10 +1224,7 @@ def __del__(self):
12241224
# ---------------------------------------------------------------------- #
12251225
class Button(Element):
12261226
def __init__(self, button_text='', button_type=BUTTON_TYPE_READ_FORM, target=(None, None), tooltip=None,
1227-
file_types=(("ALL Files", "*.*"),), initial_folder=None, disabled=False, image_filename=None,
1228-
image_data=None, image_size=(None, None), image_subsample=None, border_width=None, size=(None, None),
1229-
auto_size_button=None, button_color=None, font=None, bind_return_key=False,
1230-
focus=False, pad=None, key=None):
1227+
file_types=(("ALL Files", "*.*"),), initial_folder=None, disabled=False, change_submits=False, image_filename=None, image_data=None, image_size=(None, None), image_subsample=None, border_width=None, size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None):
12311228
'''
12321229
Button Element
12331230
:param button_text:
@@ -1271,6 +1268,7 @@ def __init__(self, button_text='', button_type=BUTTON_TYPE_READ_FORM, target=(No
12711268
self.DefaultDate_M_D_Y = (None, None, None)
12721269
self.InitialFolder = initial_folder
12731270
self.Disabled = disabled
1271+
self.ChangeSubmits = change_submits
12741272

12751273
super().__init__(ELEM_TYPE_BUTTON, size=size, font=font, pad=pad, key=key, tooltip=tooltip)
12761274
return
@@ -1530,7 +1528,7 @@ def __init__(self, filename=None, data=None, background_color=None, size=(None,
15301528
tooltip=tooltip)
15311529
return
15321530

1533-
def Update(self, filename=None, data=None):
1531+
def Update(self, filename=None, data=None, size=(None,None)):
15341532
if filename is not None:
15351533
image = tk.PhotoImage(file=filename)
15361534
elif data is not None:
@@ -1543,9 +1541,8 @@ def Update(self, filename=None, data=None):
15431541
# image = data
15441542
else:
15451543
return
1546-
width, height = image.width(), image.height()
1544+
width, height = size[0] or image.width(), size[1] or image.height()
15471545
self.tktext_label.configure(image=image, width=width, height=height)
1548-
# self.tktext_label.configure(image=image)
15491546
self.tktext_label.image = image
15501547

15511548
def __del__(self):
@@ -3223,46 +3220,45 @@ def __del__(self):
32233220

32243221
# ------------------------- FOLDER BROWSE Element lazy function ------------------------- #
32253222
def FolderBrowse(button_text='Browse', target=(ThisRow, -1), initial_folder=None, tooltip=None, size=(None, None),
3226-
auto_size_button=None, button_color=None, disabled=False, font=None, pad=None, key=None):
3223+
auto_size_button=None, button_color=None, disabled=False, change_submits=False, font=None, pad=None, key=None):
32273224
return Button(button_text=button_text, button_type=BUTTON_TYPE_BROWSE_FOLDER, target=target,
32283225
initial_folder=initial_folder, tooltip=tooltip, size=size, auto_size_button=auto_size_button,
3229-
disabled=disabled, button_color=button_color, font=font, pad=pad, key=key)
3226+
disabled=disabled, button_color=button_color,change_submits=change_submits, font=font, pad=pad, key=key)
32303227

32313228

32323229
# ------------------------- FILE BROWSE Element lazy function ------------------------- #
32333230
def FileBrowse(button_text='Browse', target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), initial_folder=None,
3234-
tooltip=None, size=(None, None), auto_size_button=None, button_color=None, font=None, disabled=False,
3231+
tooltip=None, size=(None, None), auto_size_button=None, button_color=None, change_submits=False, font=None, disabled=False,
32353232
pad=None, key=None):
32363233
return Button(button_text=button_text, button_type=BUTTON_TYPE_BROWSE_FILE, target=target, file_types=file_types,
3237-
initial_folder=initial_folder, tooltip=tooltip, size=size, auto_size_button=auto_size_button,
3238-
disabled=disabled, button_color=button_color, font=font, pad=pad, key=key)
3234+
initial_folder=initial_folder, tooltip=tooltip, size=size, auto_size_button=auto_size_button, change_submits=change_submits, disabled=disabled, button_color=button_color, font=font, pad=pad, key=key)
32393235

32403236

32413237
# ------------------------- FILES BROWSE Element (Multiple file selection) lazy function ------------------------- #
32423238
def FilesBrowse(button_text='Browse', target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), disabled=False,
3243-
initial_folder=None, tooltip=None, size=(None, None), auto_size_button=None, button_color=None,
3239+
initial_folder=None, tooltip=None, size=(None, None), auto_size_button=None, button_color=None, change_submits=False,
32443240
font=None, pad=None, key=None):
32453241
return Button(button_text=button_text, button_type=BUTTON_TYPE_BROWSE_FILES, target=target, file_types=file_types,
3246-
initial_folder=initial_folder, tooltip=tooltip, size=size, auto_size_button=auto_size_button,
3242+
initial_folder=initial_folder,change_submits=change_submits, tooltip=tooltip, size=size, auto_size_button=auto_size_button,
32473243
disabled=disabled, button_color=button_color, font=font, pad=pad, key=key)
32483244

32493245

32503246
# ------------------------- FILE BROWSE Element lazy function ------------------------- #
32513247
def FileSaveAs(button_text='Save As...', target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), initial_folder=None,
3252-
disabled=False, tooltip=None, size=(None, None), auto_size_button=None, button_color=None, font=None,
3248+
disabled=False, tooltip=None, size=(None, None), auto_size_button=None, button_color=None, change_submits=False, font=None,
32533249
pad=None, key=None):
32543250
return Button(button_text=button_text, button_type=BUTTON_TYPE_SAVEAS_FILE, target=target, file_types=file_types,
32553251
initial_folder=initial_folder, tooltip=tooltip, size=size, disabled=disabled,
3256-
auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key)
3252+
auto_size_button=auto_size_button, button_color=button_color, change_submits=change_submits, font=font, pad=pad, key=key)
32573253

32583254

32593255
# ------------------------- SAVE AS Element lazy function ------------------------- #
32603256
def SaveAs(button_text='Save As...', target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), initial_folder=None,
3261-
disabled=False, tooltip=None, size=(None, None), auto_size_button=None, button_color=None, font=None,
3257+
disabled=False, tooltip=None, size=(None, None), auto_size_button=None, button_color=None, change_submits=False, font=None,
32623258
pad=None, key=None):
32633259
return Button(button_text=button_text, button_type=BUTTON_TYPE_SAVEAS_FILE, target=target, file_types=file_types,
32643260
initial_folder=initial_folder, tooltip=tooltip, size=size, disabled=disabled,
3265-
auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key)
3261+
auto_size_button=auto_size_button, button_color=button_color, change_submits=change_submits, font=font, pad=pad, key=key)
32663262

32673263

32683264
# ------------------------- SAVE BUTTON Element lazy function ------------------------- #
@@ -4697,7 +4693,7 @@ def StartupTK(my_flex_form):
46974693
_my_windows.hidden_master_root = tk.Tk()
46984694
_my_windows.hidden_master_root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
46994695
_my_windows.hidden_master_root.wm_overrideredirect(True)
4700-
4696+
_my_windows.hidden_master_root.withdraw()
47014697
# root = tk.Tk() # users windows are no longer using tk.Tk. They are all Toplevel windows
47024698
root = tk.Toplevel()
47034699
else:
@@ -6663,8 +6659,9 @@ def main():
66636659
[Text('Destination Folder', size=(15, 1), justification='right'), InputText('Dest'), FolderBrowse()],
66646660
[Ok(), Cancel()]]
66656661

6666-
button, values = Window('Demo window..').Layout(layout).Read()
6667-
6662+
window = Window('Demo window..').Layout(layout)
6663+
event, values = window.Read()
6664+
window.Close()
66686665

66696666
if __name__ == '__main__':
66706667
main()

0 commit comments

Comments
 (0)