Merge pull request #4762 from PySimpleGUI/Dev-latest

Dev latest
This commit is contained in:
PySimpleGUI 2021-10-01 09:29:55 -04:00 committed by GitHub
commit f06817d28d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 56 additions and 1 deletions

View File

@ -1,11 +1,15 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "4.49.0 Released 30-Sept-2021" version = __version__ = "4.49.0.1 Unreleased"
_change_log = """ _change_log = """
Changelog since 4.49.0 release to PyPI on 30 Sept 2021 Changelog since 4.49.0 release to PyPI on 30 Sept 2021
4.49.0.1
Element.set_right_click_menu added so can set or change the right click menu for an element
""" """
__version__ = version.split()[0] # For PEP 396 and PEP 345 __version__ = version.split()[0] # For PEP 396 and PEP 345
@ -1426,6 +1430,51 @@ class Element():
""" """
self.ParentForm._grab_anywhere_include_these_list.append(self.Widget) self.ParentForm._grab_anywhere_include_these_list.append(self.Widget)
def set_right_click_menu(self, menu):
if menu == MENU_RIGHT_CLICK_DISABLED:
return
if menu:
top_menu = tk.Menu(self.ParentForm.TKroot, tearoff=self.ParentForm.right_click_menu_tearoff, tearoffcommand=self._tearoff_menu_callback)
if self.ParentForm.right_click_menu_background_color not in (COLOR_SYSTEM_DEFAULT, None):
top_menu.config(bg=self.ParentForm.right_click_menu_background_color)
if self.ParentForm.right_click_menu_text_color not in (COLOR_SYSTEM_DEFAULT, None):
top_menu.config(fg=self.ParentForm.right_click_menu_text_color)
if self.ParentForm.right_click_menu_disabled_text_color not in (COLOR_SYSTEM_DEFAULT, None):
top_menu.config(disabledforeground=self.ParentForm.right_click_menu_disabled_text_color)
if self.ParentForm.right_click_menu_font is not None:
top_menu.config(font=self.ParentForm.right_click_menu_font)
if self.ParentForm.right_click_menu_selected_colors[0] not in (COLOR_SYSTEM_DEFAULT, None):
top_menu.config(activeforeground=self.ParentForm.right_click_menu_selected_colors[0])
if self.ParentForm.right_click_menu_selected_colors[1] not in (COLOR_SYSTEM_DEFAULT, None):
top_menu.config(activebackground=self.ParentForm.right_click_menu_selected_colors[1])
AddMenuItem(top_menu, menu[1], self, right_click_menu=True)
self.TKRightClickMenu = top_menu
if self.ParentForm.RightClickMenu: # if the top level has a right click menu, then setup a callback for the Window itself
if self.ParentForm.TKRightClickMenu is None:
self.ParentForm.TKRightClickMenu = top_menu
if (running_mac()):
self.ParentForm.TKroot.bind('<ButtonRelease-2>', self.ParentForm._RightClickMenuCallback)
else:
self.ParentForm.TKroot.bind('<ButtonRelease-3>', self.ParentForm._RightClickMenuCallback)
if (running_mac()):
self.Widget.bind('<ButtonRelease-2>', self._RightClickMenuCallback)
else:
self.Widget.bind('<ButtonRelease-3>', self._RightClickMenuCallback)
def update(self, *args, **kwargs): def update(self, *args, **kwargs):
""" """
A dummy update call. This will only be called if an element hasn't implemented an update method A dummy update call. This will only be called if an element hasn't implemented an update method
@ -1434,6 +1483,7 @@ class Element():
""" """
print('* Base Element Class update was called. Your element does not seem to have an update method') print('* Base Element Class update was called. Your element does not seem to have an update method')
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
""" """
Makes it possible to "call" an already existing element. When you do make the "call", it actually calls Makes it possible to "call" an already existing element. When you do make the "call", it actually calls
@ -1445,6 +1495,11 @@ class Element():
""" """
return self.update(*args, **kwargs) return self.update(*args, **kwargs)
SetTooltip = set_tooltip SetTooltip = set_tooltip
SetFocus = set_focus SetFocus = set_focus