From 03e631083496418d6be69d16506a120817db94c4 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 11 Apr 2019 18:20:26 -0400 Subject: [PATCH] Mass update for Window Layout Change --- PySimpleGUI.py | 6 +++--- PySimpleGUI27.py | 21 +++++++++++++++------ PySimpleGUIQt/PySimpleGUIQt.py | 5 +++-- PySimpleGUIWeb/PySimpleGUIWeb.py | 5 ++++- PySimpleGUIWx/PySimpleGUIWx.py | 5 +++-- docs/cookbook.md | 29 +++++++++++++++-------------- docs/index.md | 26 +++++++++++++++----------- readme.md | 26 +++++++++++++++----------- 8 files changed, 73 insertions(+), 50 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index c33d3b2e..23962677 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -1180,7 +1180,6 @@ class Text(Element): :param key: :param right_click_menu: :param tooltip: - :param tooltip: :param visible: ''' self.DisplayText = str(text) @@ -3499,7 +3498,7 @@ class Window: animated_popup_dict = {} container_element_counter = 0 # used to get a number of Container Elements (Frame, Column, Tab) - def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), + def __init__(self, title, layout=None, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), auto_size_text=None, auto_size_buttons=None, location=(None, None), size=(None, None), element_padding=None, margins=(None, None), button_color=None, font=None, progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False, auto_close_duration=DEFAULT_AUTOCLOSE_TIME, icon=DEFAULT_WINDOW_ICON, force_toplevel=False, @@ -3591,7 +3590,8 @@ class Window: self.RightClickMenu = right_click_menu self.Margins = margins if margins != (None, None) else DEFAULT_MARGINS self.ContainerElemementNumber = Window.GetAContainerNumber() - + if layout is not None: + self.Layout(layout) @classmethod def GetAContainerNumber(cls): diff --git a/PySimpleGUI27.py b/PySimpleGUI27.py index e73f5d83..e3ea2be6 100644 --- a/PySimpleGUI27.py +++ b/PySimpleGUI27.py @@ -53,7 +53,6 @@ g_time_end = 0 g_time_delta = 0 - def TimerStart(): global g_time_start @@ -619,7 +618,7 @@ class InputText(Element): # ------------------------- INPUT TEXT Element lazy functions ------------------------- # In = InputText Input = InputText - +I = InputText # ---------------------------------------------------------------------- # # Combo # @@ -1494,7 +1493,7 @@ class Button(Element): self.FileTypes = file_types self.TKButton = None self.Target = target - self.ButtonText = button_text + self.ButtonText = str(button_text) if sys.platform == 'darwin' and button_color is not None: print('Button *** WARNING - Button colors are not supported on the Mac ***') self.ButtonColor = button_color if button_color else DEFAULT_BUTTON_COLOR @@ -1714,6 +1713,10 @@ class Button(Element): super().__del__() +# ------------------------- Button lazy functions ------------------------- # +B = Button +Btn = Button +Butt = Button # ---------------------------------------------------------------------- # # ButtonMenu Class # @@ -1889,7 +1892,7 @@ class Image(Element): self.CurrentFrameNumber = 0 self.TotalAnimatedFrames = 0 self.LastFrameTime = 0 - self.Source = filename or data + self.Source = filename if filename is not None else data super().__init__(ELEM_TYPE_IMAGE, size=size, background_color=background_color, pad=pad, key=key, tooltip=tooltip, visible=visible) @@ -3508,7 +3511,7 @@ class Window(object): animated_popup_dict = {} container_element_counter = 0 # used to get a number of Container Elements (Frame, Column, Tab) - def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), + def __init__(self, title, layout=None, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), auto_size_text=None, auto_size_buttons=None, location=(None, None), size=(None, None), element_padding=None, margins=(None, None), button_color=None, font=None, progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False, auto_close_duration=DEFAULT_AUTOCLOSE_TIME, icon=DEFAULT_WINDOW_ICON, force_toplevel=False, @@ -3600,7 +3603,8 @@ class Window(object): self.RightClickMenu = right_click_menu self.Margins = margins if margins != (None, None) else DEFAULT_MARGINS self.ContainerElemementNumber = Window.GetAContainerNumber() - + if layout is not None: + self.Layout(layout) @classmethod def GetAContainerNumber(cls): @@ -4699,6 +4703,10 @@ def _FindElementWithFocusInSubForm(form): if element.TKText is not None: if element.TKText is element.TKText.focus_get(): return element + if element.Type == ELEM_TYPE_BUTTON: + if element.TKButton is not None: + if element.TKButton is element.TKButton.focus_get(): + return element if sys.version_info[0] >= 3: def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False): @@ -6001,6 +6009,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): def ConvertFlexToTK(MyFlexForm): + MyFlexForm # type: Window master = MyFlexForm.TKroot master.title(MyFlexForm.Title) InitializeResults(MyFlexForm) diff --git a/PySimpleGUIQt/PySimpleGUIQt.py b/PySimpleGUIQt/PySimpleGUIQt.py index 18637308..4044bd55 100644 --- a/PySimpleGUIQt/PySimpleGUIQt.py +++ b/PySimpleGUIQt/PySimpleGUIQt.py @@ -3082,7 +3082,7 @@ class Window: active_popups = {} - def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), + def __init__(self, title, layout=None, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), auto_size_text=None, auto_size_buttons=None, location=(None, None), size=(None, None), element_padding=None, button_color=None, font=None, progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False, auto_close_duration=DEFAULT_AUTOCLOSE_TIME, icon=DEFAULT_WINDOW_ICON, force_toplevel=False, @@ -3174,7 +3174,8 @@ class Window: self.BackgroundImage = background_image self.XFound = False self.DisableMinimize = disable_minimize - + if layout is not None: + self.Layout(layout) @classmethod def IncrementOpenCount(self): diff --git a/PySimpleGUIWeb/PySimpleGUIWeb.py b/PySimpleGUIWeb/PySimpleGUIWeb.py index 9b8c662e..ae98a584 100644 --- a/PySimpleGUIWeb/PySimpleGUIWeb.py +++ b/PySimpleGUIWeb/PySimpleGUIWeb.py @@ -2646,7 +2646,7 @@ class Window: active_windows = [ ] # type: Window [] App = None # type: remi.App - def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), + def __init__(self, title, layout=None, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), auto_size_text=None, auto_size_buttons=None, location=(None, None), size=(None, None), element_padding=None, button_color=None, font=None, progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False, @@ -2757,6 +2757,9 @@ class Window: self.MessageQueue = Queue() self.master_widget = None # type: remi.gui.VBox + if layout is not None: + self.Layout(layout) + @classmethod def IncrementOpenCount(self): self.NumOpenWindows += 1 diff --git a/PySimpleGUIWx/PySimpleGUIWx.py b/PySimpleGUIWx/PySimpleGUIWx.py index 0ba3733d..7c8c2707 100644 --- a/PySimpleGUIWx/PySimpleGUIWx.py +++ b/PySimpleGUIWx/PySimpleGUIWx.py @@ -2948,7 +2948,7 @@ class Window: stdout_is_rerouted = False stdout_location = None - def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), + def __init__(self, title, layout=None, default_element_size=DEFAULT_ELEMENT_SIZE, default_button_element_size=(None, None), auto_size_text=None, auto_size_buttons=None, location=(None, None), size=(None, None), element_padding=None, button_color=None, font=None, progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False, auto_close_duration=None, icon=DEFAULT_BASE64_ICON, force_toplevel=False, @@ -3044,7 +3044,8 @@ class Window: self.MasterFrame = None # type: wx.Frame self.MasterPanel = None # type: wx.Panel self.IgnoreClose = False - + if layout is not None: + self.Layout(layout) @classmethod def IncrementOpenCount(self): diff --git a/docs/cookbook.md b/docs/cookbook.md index 9bff6667..f2fbf77d 100644 --- a/docs/cookbook.md +++ b/docs/cookbook.md @@ -68,12 +68,13 @@ Some of the more advanced programs operate with the window remaining visible on This code will present a window and will print values until the user clicks the exit button or closes window using an X. +Note the `do_not_clear` parameter that is described in the next design pattern. ```python import PySimpleGUI as sg layout = [[sg.Text('Persistent window')], - [sg.Input()], + [sg.Input(do_not_clear=True)], [sg.Button('Read'), sg.Exit()]] window = sg.Window('Window that stays open').Layout(layout) @@ -97,7 +98,7 @@ This is a slightly more complex, but maybe more realistic version that reads inp Do not worry yet what all of these statements mean. Just copy it so you can begin to play with it, make some changes. Experiment to see how thing work. -A final note... the parameter `do_not_clear` in the input call determines the action of the input field after a button event. If this value is True, the input value remains visible following button clicks. If False, then the input field is CLEARED of whatever was input. The default is True, which means whatever is input remains visible after buttons are clicked. If your Window is more of a "form" then you will likely want to set this parameter to False. +A final note... the parameter `do_not_clear` in the input call determines the action of the input field after a button event. If this value is True, the input value remains visible following button clicks. If False, then the input field is CLEARED of whatever was input. If you are building a "Form" type of window with data entry, you likely want False, the default setting (you can remove the parameter completely). ```python import sys @@ -107,7 +108,7 @@ else: import PySimpleGUI27 as sg layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', key='_OUTPUT_') ], - [sg.Input(key='_IN_')], + [sg.Input(do_not_clear=True, key='_IN_')], [sg.Button('Show'), sg.Button('Exit')]] window = sg.Window('Window Title').Layout(layout) @@ -124,7 +125,7 @@ while True: # Event Loop window.Close() ``` - + # Simple Data Entry - Return Values As List @@ -580,7 +581,7 @@ CHROME = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" layout = [ [sg.Text('Text area', key='_TEXT_')], - [sg.Input(key='_URL_')], + [sg.Input(do_not_clear=True, key='_URL_')], [sg.Button('Chrome'), sg.Button('Exit')]] window = sg.Window('Window Title').Layout(layout) @@ -809,7 +810,7 @@ import PySimpleGUI as sg # Design pattern 1 - First window does not remain active layout = [[ sg.Text('Window 1'),], - [sg.Input()], + [sg.Input(do_not_clear=True)], [sg.Text('', key='_OUTPUT_')], [sg.Button('Launch 2')]] @@ -925,7 +926,8 @@ There are a number of features used in this Recipe including: * Button * Dictionary Return values * Update of Elements in window (Input, Text) - +* do_not_clear of Input Elements + ![keypad 2](https://user-images.githubusercontent.com/13696193/44640891-57504d80-a992-11e8-93f4-4e97e586505e.jpg) @@ -939,10 +941,10 @@ There are a number of features used in this Recipe including: # Button # Dictionary return values # Update of elements in window (Text, Input) - + # do_not_clear of Input elements layout = [[sg.Text('Enter Your Passcode')], - [sg.Input(size=(10, 1), justification='right', key='input')], + [sg.Input(size=(10, 1), do_not_clear=True, justification='right', key='input')], [sg.Button('1'), sg.Button('2'), sg.Button('3')], [sg.Button('4'), sg.Button('5'), sg.Button('6')], [sg.Button('7'), sg.Button('8'), sg.Button('9')], @@ -1549,9 +1551,8 @@ That's all... Run your `my_program.exe` file on the Windows machine of your choo Your EXE file should run without creating a "shell window". Only the GUI window should show up on your taskbar. \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index c9505f2d..a196f52f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -33,15 +33,15 @@ -![Python Version](https://img.shields.io/badge/PySimpleGUI_For_Python_3.x_Version-3.27.0-red.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUI_For_Python_3.x_Version-3.28.0-red.svg?longCache=true&style=for-the-badge) -![Python Version](https://img.shields.io/badge/PySimpleGUI_For_Python_2.7_Version-1.27.0-blue.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUI_For_Python_2.7_Version-1.28.0-blue.svg?longCache=true&style=for-the-badge) -![Python Version](https://img.shields.io/badge/PySimpleGUIQt_Version-0.23.0-orange.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUIQt_Version-0.26.0-orange.svg?longCache=true&style=for-the-badge) -![Python Version](https://img.shields.io/badge/PySimpleGUIWx_version-0.9.0-orange.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUIWx_version-0.11.0-orange.svg?longCache=true&style=for-the-badge) -![Python Version](https://img.shields.io/badge/PySimpleGUIWeb_Version-0.18.0-orange.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUIWeb_Version-0.22.0-orange.svg?longCache=true&style=for-the-badge) [Announcements of Latest Developments](https://github.com/MikeTheWatchGuy/PySimpleGUI/issues/142) @@ -4916,6 +4916,14 @@ Mixup.... 3.26 changes don't appear to have been correctly released so releasing * PopupAnimated - image_source can be a filename or bytes (base64) * Option Menu can now have values updated +## 3.28.0 11-Apr-2019 PySimpleGUI + +* NEW Window Parameter - layout - second parameter. Can pass in layout directly now! +* New shortcuts + * I = InputText + * B = Btn = Butt = Button +* Convert button text to string when creating buttons +* Buttons are returned now as well as input fields when searching for element with focus ### Upcoming @@ -4961,18 +4969,14 @@ This is a language feature that is featured **heavily** in all of the API calls **tkinter** tkinter is the "official" GUI that Python supports. It runs on Windows, Linux, and Mac. It was chosen as the first target GUI framework due to its ***ubiquity***. Nearly all Python installations, with the exception of Ubuntu Linux, come pre-loaded with tkinter. It is the "simplest" of the GUI frameworks to get up an running (among Qt, WxPython, Kivy, etc). -From the start of the PSG project, tkinter was not meant to be the only underlying GUI framework for PySimpleGUI. It is merely a starting point. All journeys begin with one step forward and choosing tkinter was the first of many steps for PySimpleGUI. +From the start of the PSG project, tkinter was not meant to be the only underlying GUI framework for PySimpleGUI. It is merely a starting point. All journeys begin with one step forward and choosing tkinter was the first of many steps for PySimpleGUI. Now there are 4 ports up and running - tkinter, WxPython, Qt and Remi (web support) ## Author MikeB -## Demo Code Contributors - - [JorjMcKie](https://github.com/JorjMcKie) - PDF and image viewers (plus a number of code suggestions) -[Otherion](https://github.com/Otherion) - Table Demos Panda & CSV. Loads of suggestions to the core APIs - + ## License GNU Lesser General Public License (LGPL 3) + diff --git a/readme.md b/readme.md index c9505f2d..a196f52f 100644 --- a/readme.md +++ b/readme.md @@ -33,15 +33,15 @@ -![Python Version](https://img.shields.io/badge/PySimpleGUI_For_Python_3.x_Version-3.27.0-red.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUI_For_Python_3.x_Version-3.28.0-red.svg?longCache=true&style=for-the-badge) -![Python Version](https://img.shields.io/badge/PySimpleGUI_For_Python_2.7_Version-1.27.0-blue.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUI_For_Python_2.7_Version-1.28.0-blue.svg?longCache=true&style=for-the-badge) -![Python Version](https://img.shields.io/badge/PySimpleGUIQt_Version-0.23.0-orange.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUIQt_Version-0.26.0-orange.svg?longCache=true&style=for-the-badge) -![Python Version](https://img.shields.io/badge/PySimpleGUIWx_version-0.9.0-orange.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUIWx_version-0.11.0-orange.svg?longCache=true&style=for-the-badge) -![Python Version](https://img.shields.io/badge/PySimpleGUIWeb_Version-0.18.0-orange.svg?longCache=true&style=for-the-badge) +![Python Version](https://img.shields.io/badge/PySimpleGUIWeb_Version-0.22.0-orange.svg?longCache=true&style=for-the-badge) [Announcements of Latest Developments](https://github.com/MikeTheWatchGuy/PySimpleGUI/issues/142) @@ -4916,6 +4916,14 @@ Mixup.... 3.26 changes don't appear to have been correctly released so releasing * PopupAnimated - image_source can be a filename or bytes (base64) * Option Menu can now have values updated +## 3.28.0 11-Apr-2019 PySimpleGUI + +* NEW Window Parameter - layout - second parameter. Can pass in layout directly now! +* New shortcuts + * I = InputText + * B = Btn = Butt = Button +* Convert button text to string when creating buttons +* Buttons are returned now as well as input fields when searching for element with focus ### Upcoming @@ -4961,18 +4969,14 @@ This is a language feature that is featured **heavily** in all of the API calls **tkinter** tkinter is the "official" GUI that Python supports. It runs on Windows, Linux, and Mac. It was chosen as the first target GUI framework due to its ***ubiquity***. Nearly all Python installations, with the exception of Ubuntu Linux, come pre-loaded with tkinter. It is the "simplest" of the GUI frameworks to get up an running (among Qt, WxPython, Kivy, etc). -From the start of the PSG project, tkinter was not meant to be the only underlying GUI framework for PySimpleGUI. It is merely a starting point. All journeys begin with one step forward and choosing tkinter was the first of many steps for PySimpleGUI. +From the start of the PSG project, tkinter was not meant to be the only underlying GUI framework for PySimpleGUI. It is merely a starting point. All journeys begin with one step forward and choosing tkinter was the first of many steps for PySimpleGUI. Now there are 4 ports up and running - tkinter, WxPython, Qt and Remi (web support) ## Author MikeB -## Demo Code Contributors - - [JorjMcKie](https://github.com/JorjMcKie) - PDF and image viewers (plus a number of code suggestions) -[Otherion](https://github.com/Otherion) - Table Demos Panda & CSV. Loads of suggestions to the core APIs - + ## License GNU Lesser General Public License (LGPL 3) +