Skip to content

Commit c59db9b

Browse files
authored
Merge pull request PySimpleGUI#5266 from PySimpleGUI/Dev-latest
ButtonMenu.Click aliased added. Debugger - automatically adds a time…
2 parents 170a44d + 37c3afc commit c59db9b

1 file changed

Lines changed: 45 additions & 9 deletions

File tree

PySimpleGUI.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python3
2-
version = __version__ = "4.57.0.6 Unreleased"
2+
version = __version__ = "4.57.0.8 Unreleased"
33

44
_change_log = """
55
Changelog since 4.57.0 released to PyPI on 13-Feb-2022
@@ -16,6 +16,10 @@
1616
Open GitHub Issue GUI - Tabs use 2 lines now. Added tab asking where found PSG.
1717
4.57.0.6
1818
New symbols SYMBOL_CHECKMARK_SMALL & SYMBOL_X_SMALL
19+
4.57.0.7
20+
Added click - PEP8 alias for ButtonMenu.Click
21+
4.57.0.8
22+
Automatically add timeouts to user reads if a debugger window is opened. Need to add support for multi-window applications still.
1923
"""
2024

2125
__version__ = version.split()[0] # For PEP 396 and PEP 345
@@ -4820,6 +4824,7 @@ def __init__(self, button_text, menu_def, tooltip=None, disabled=False, image_so
48204824
text_color=self.TextColor, background_color=self.BackgroundColor, visible=visible, metadata=metadata)
48214825
self.Tearoff = tearoff
48224826

4827+
48234828
def _MenuItemChosenCallback(self, item_chosen): # ButtonMenu Menu Item Chosen Callback
48244829
"""
48254830
Not a user callable function. Called by tkinter when an item is chosen from the menu.
@@ -4835,6 +4840,7 @@ def _MenuItemChosenCallback(self, item_chosen): # ButtonMenu Menu Item Chosen C
48354840
# self.ParentForm.TKroot.quit() # kick the users out of the mainloop
48364841
_exit_mainloop(self.ParentForm)
48374842

4843+
48384844
def update(self, menu_definition=None, visible=None, image_source=None, image_size=(None, None), image_subsample=None, button_text=None):
48394845
"""
48404846
Changes some of the settings for the ButtonMenu Element. Must call `Window.Read` or `Window.Finalize` prior
@@ -4917,7 +4923,7 @@ def update(self, menu_definition=None, visible=None, image_source=None, image_si
49174923
if visible is not None:
49184924
self._visible = visible
49194925

4920-
def Click(self):
4926+
def click(self):
49214927
"""
49224928
Generates a click of the button as if the user clicked the button
49234929
Calls the tkinter invoke method for the button
@@ -4928,7 +4934,7 @@ def Click(self):
49284934
print('Exception clicking button')
49294935

49304936
Update = update
4931-
4937+
Click = click
49324938

49334939
BMenu = ButtonMenu
49344940
BM = ButtonMenu
@@ -9615,6 +9621,11 @@ def read(self, timeout=None, timeout_key=TIMEOUT_KEY, close=False):
96159621
if not Window._read_call_from_debugger:
96169622
_refresh_debugger()
96179623

9624+
# if the user has not added timeout and a debug window is open, then set a timeout for them so the debugger continuously refreshes
9625+
if _debugger_window_is_open() and not Window._read_call_from_debugger:
9626+
if timeout is None or timeout > 3000:
9627+
timeout = 200
9628+
96189629
Window._root_running_mainloop = self.TKroot
96199630

96209631
while True:
@@ -10831,22 +10842,28 @@ def bind(self, bind_string, key):
1083110842
def _callback_main_debugger_window_create_keystroke(self, event):
1083210843
"""
1083310844
Called when user presses the key that creates the main debugger window
10834-
10845+
March 2022 - now causes the user reads to return timeout events automatically
1083510846
:param event: (event) not used. Passed in event info
1083610847
:type event:
1083710848
"""
1083810849
Window._main_debug_window_build_needed = True
10839-
# _Debugger.debugger._build_main_debugger_window()
10850+
# exit the event loop in a way that resembles a timeout occurring
10851+
self.LastButtonClicked = self.TimeoutKey
10852+
self.FormRemainedOpen = True
10853+
self.TKroot.quit() # kick the users out of the mainloop
1084010854

1084110855
def _callback_popout_window_create_keystroke(self, event):
1084210856
"""
1084310857
Called when user presses the key that creates the floating debugger window
10844-
10858+
March 2022 - now causes the user reads to return timeout events automatically
1084510859
:param event: (event) not used. Passed in event info
1084610860
:type event:
1084710861
"""
1084810862
Window._floating_debug_window_build_needed = True
10849-
# _Debugger.debugger._build_floating_window()
10863+
# exit the event loop in a way that resembles a timeout occurring
10864+
self.LastButtonClicked = self.TimeoutKey
10865+
self.FormRemainedOpen = True
10866+
self.TKroot.quit() # kick the users out of the mainloop
1085010867

1085110868
def enable_debugger(self):
1085210869
"""
@@ -21951,20 +21968,39 @@ def _refresh_debugger():
2195121968
_Debugger.debugger = _Debugger()
2195221969
debugger = _Debugger.debugger
2195321970
Window._read_call_from_debugger = True
21971+
rc = None
2195421972
# frame = inspect.currentframe()
2195521973
# frame = inspect.currentframe().f_back
21974+
2195621975
frame, *others = inspect.stack()[1]
2195721976
try:
2195821977
debugger.locals = frame.f_back.f_locals
2195921978
debugger.globals = frame.f_back.f_globals
2196021979
finally:
2196121980
del frame
21962-
debugger._refresh_floating_window() if debugger.popout_window else None
21963-
rc = debugger._refresh_main_debugger_window(debugger.locals, debugger.globals) if debugger.watcher_window else False
21981+
if debugger.popout_window:
21982+
rc = debugger._refresh_floating_window()
21983+
if debugger.watcher_window:
21984+
rc = debugger._refresh_main_debugger_window(debugger.locals, debugger.globals)
2196421985
Window._read_call_from_debugger = False
2196521986
return rc
2196621987

2196721988

21989+
def _debugger_window_is_open():
21990+
"""
21991+
Determines if one of the debugger window is currently open
21992+
:return: returns True if the popout window or the main debug window is open
21993+
:rtype: (bool)
21994+
"""
21995+
21996+
if _Debugger.debugger is None:
21997+
return False
21998+
debugger = _Debugger.debugger
21999+
if debugger.popout_window or debugger.watcher_window:
22000+
return True
22001+
return False
22002+
22003+
2196822004
def get_versions():
2196922005
"""
2197022006
Returns a human-readable string of version numbers for:

0 commit comments

Comments
 (0)