From 0180c3a80ef5347247a8b81e4d069df6e981a19c Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Thu, 20 Aug 2020 18:15:02 -0400 Subject: [PATCH] grab parameter added to Text element --- PySimpleGUI.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 9d455675..db0143f2 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -1059,6 +1059,28 @@ class Element(): return False + def _grab_anywhere_on(self): + """ + Turns on Grab Anywhere functionality AFTER a window has been created. Don't try on a window that's not yet + been Finalized or Read. + """ + self.Widget.bind("", self.ParentForm._StartMove) + self.Widget.bind("", self.ParentForm._StopMove) + self.Widget.bind("", self.ParentForm._OnMotion) + + + def _grab_anywhere_off(self): + """ + Turns off Grab Anywhere functionality AFTER a window has been created. Don't try on a window that's not yet + been Finalized or Read. + """ + self.Widget.unbind("") + self.Widget.unbind("") + self.Widget.unbind("") + + + + def __call__(self, *args, **kwargs): """ Makes it possible to "call" an already existing element. When you do make the "call", it actually calls @@ -2428,7 +2450,7 @@ class Text(Element): """ def __init__(self, text='', size=(None, None), auto_size_text=None, click_submits=False, enable_events=False, - relief=None, font=None, text_color=None, background_color=None, border_width=None, justification=None, pad=None, key=None, k=None, right_click_menu=None, tooltip=None, visible=True, metadata=None): + relief=None, font=None, text_color=None, background_color=None, border_width=None, justification=None, pad=None, key=None, k=None, right_click_menu=None, grab=None, tooltip=None, visible=True, metadata=None): """ :param text: The text to display. Can include /n to achieve multiple lines. Will convert (optional) parameter into a string :type text: Any @@ -2460,6 +2482,8 @@ class Text(Element): :type k: Union[str, int, tuple, object] :param right_click_menu: A list of lists of Menu items to show when this element is right clicked. See user docs for exact format. :type right_click_menu: List[List[Union[List[str],str]]] + :param grab: If True can grab this element and move the window around. Default is False + :type grab: (bool) :param tooltip: text, that will appear when mouse hovers over the element :type tooltip: (str) :param visible: set visibility state of the element @@ -2480,6 +2504,7 @@ class Text(Element): self.RightClickMenu = right_click_menu self.TKRightClickMenu = None self.BorderWidth = border_width + self.Grab = grab key = key if key is not None else k super().__init__(ELEM_TYPE_TEXT, size, auto_size_text, background_color=bg, font=font if font else DEFAULT_FONT, text_color=self.TextColor, pad=pad, key=key, tooltip=tooltip, visible=visible, metadata=metadata) @@ -11101,6 +11126,8 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): AddMenuItem(top_menu, menu[1], element) element.TKRightClickMenu = top_menu tktext_label.bind('', element._RightClickMenuCallback) + if element.Grab: + element._grab_anywhere_on() # ------------------------- BUTTON placement element non-ttk version ------------------------- # elif (element_type == ELEM_TYPE_BUTTON and element.UseTtkButtons is False) or \ (element_type == ELEM_TYPE_BUTTON and element.UseTtkButtons is not True and toplevel_form.UseTtkButtons is not True):