diff --git a/PySimpleGUI27.py b/PySimpleGUI27.py index 0dd2540f..72e3fe3c 100644 --- a/PySimpleGUI27.py +++ b/PySimpleGUI27.py @@ -240,7 +240,6 @@ def RGB(red, green, blue): return '#%02x%02x%02x' % (red, green, blue) # ------------------------- Button types ------------------------- # # todo Consider removing the Submit, Cancel types... they are just 'RETURN' type in reality # uncomment this line and indent to go back to using Enums -# class ButtonType(Enum): BUTTON_TYPE_BROWSE_FOLDER = 1 BUTTON_TYPE_BROWSE_FILE = 2 BUTTON_TYPE_BROWSE_FILES = 21 @@ -906,13 +905,13 @@ class Radio(Element): self.Disabled = disabled self.TextColor = text_color or DEFAULT_TEXT_COLOR self.ChangeSubmits = change_submits or enable_events - + self.EncodedRadioValue = None super().__init__(ELEM_TYPE_INPUT_RADIO, size=size, auto_size_text=auto_size_text, font=font, background_color=background_color, text_color=self.TextColor, key=key, pad=pad, tooltip=tooltip, visible=visible) def Update(self, value=None, disabled=None, visible=None): - location = EncodeRadioRowCol(self.Position[0], self.Position[1]) + location = EncodeRadioRowCol(self.ParentForm.ContainerElemementNumber, self.Position[0], self.Position[1]) if value is not None: try: self.TKIntVar.set(location) @@ -1123,7 +1122,9 @@ class Multiline(Element): text_color=fg, key=key, pad=pad, tooltip=tooltip, font=font or DEFAULT_FONT, visible=visible) return - def Update(self, value=None, disabled=None, append=False, font=None, text_color=None, background_color=None, visible=None): + def Update(self, value=None, disabled=None, append=False, font=None, text_color=None, background_color=None, visible=None, autoscroll=None): + if autoscroll is not None: + self.Autoscroll = autoscroll if value is not None: try: if not append: @@ -1149,6 +1150,8 @@ class Multiline(Element): elif visible is True: self.TKText.pack() + + def Get(self): return self.TKText.get(1.0, tk.END) @@ -1897,7 +1900,10 @@ class Image(Element): else: return width, height = size[0] or image.width(), size[1] or image.height() - self.tktext_label.configure(image=image, width=width, height=height) + try: # sometimes crashes if user closed with X + self.tktext_label.configure(image=image, width=width, height=height) + except: + pass self.tktext_label.image = image if visible is False: self.tktext_label.pack_forget() @@ -2321,6 +2327,8 @@ class Frame(Element): self.BorderWidth = border_width self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR self.RightClickMenu = right_click_menu + self.ContainerElemementNumber = Window.GetAContainerNumber() + self.Layout(layout) super().__init__(ELEM_TYPE_FRAME, background_color=background_color, text_color=title_color, size=size, @@ -2425,6 +2433,7 @@ class Tab(Element): self.TabID = None self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR self.RightClickMenu = right_click_menu + self.ContainerElemementNumber = Window.GetAContainerNumber() self.Layout(layout) @@ -2588,7 +2597,7 @@ class Slider(Element): :param tooltip: :param visible: ''' - self.TKScale = None + self.TKScale = None # type: tk.Scale self.Range = (1, 10) if range == (None, None) else range self.DefaultValue = self.Range[0] if default_value is None else default_value self.Orientation = orientation if orientation else DEFAULT_SLIDER_ORIENTATION @@ -2770,7 +2779,7 @@ class Column(Element): self.VerticalScrollOnly = vertical_scroll_only self.RightClickMenu = right_click_menu bg = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR - + self.ContainerElemementNumber = Window.GetAContainerNumber() self.Layout(layout) @@ -3490,7 +3499,7 @@ class Window(object): user_defined_icon = None hidden_master_root = None 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), 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, @@ -3583,6 +3592,13 @@ class Window(object): self.ElementPadding = element_padding or DEFAULT_ELEMENT_PADDING self.RightClickMenu = right_click_menu self.Margins = margins if margins != (None, None) else DEFAULT_MARGINS + self.ContainerElemementNumber = Window.GetAContainerNumber() + + + @classmethod + def GetAContainerNumber(cls): + cls.container_element_counter += 1 + return cls.container_element_counter @classmethod def IncrementOpenCount(self): @@ -4350,13 +4366,14 @@ def InitializeResults(form): # ===== Radio Button RadVar encoding and decoding =====# # ===== The value is simply the row * 1000 + col =====# def DecodeRadioRowCol(RadValue): + container = RadValue // 100000 row = RadValue // 1000 col = RadValue % 1000 - return row, col + return container, row, col -def EncodeRadioRowCol(row, col): - RadValue = row * 1000 + col +def EncodeRadioRowCol(container, row, col): + RadValue = container*100000 + row * 1000 + col return RadValue @@ -4459,7 +4476,8 @@ def BuildResultsForSubform(form, initialize_only, top_level_form): value = (value != 0) elif element.Type == ELEM_TYPE_INPUT_RADIO: RadVar = element.TKIntVar.get() - this_rowcol = EncodeRadioRowCol(row_num, col_num) + this_rowcol = EncodeRadioRowCol(form.ContainerElemementNumber, row_num, col_num) + # this_rowcol = element.EncodedRadioValue # could use the saved one value = RadVar == this_rowcol elif element.Type == ELEM_TYPE_BUTTON: if top_level_form.LastButtonClicked == element.ButtonText: @@ -4781,6 +4799,7 @@ else: # Y88b. 888 "88b 888 888 888 Y88b. Y8b. 888 # "Y888 888 888 888 888 888 "Y888 "Y8888 888 +# My crappy tkinter code starts here # ======================== TK CODE STARTS HERE ========================================= # @@ -4940,7 +4959,6 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): wraplen = tktext_label.winfo_reqwidth() + 40 # width of widget in Pixels if not auto_size_text and height == 1: wraplen = 0 - # print("wraplen, width, height", wraplen, width, height) tktext_label.configure(anchor=anchor, wraplen=wraplen) # set wrap to width of widget if element.Relief is not None: tktext_label.configure(relief=element.Relief) @@ -5371,11 +5389,13 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): element.TKProgressBar.TKProgressBarForReal.pack_forget() # ------------------------- RADIO BUTTON element ------------------------- # elif element_type == ELEM_TYPE_INPUT_RADIO: + element = element # type: Radio width = 0 if auto_size_text else element_size[0] default_value = element.InitialState ID = element.GroupID # see if ID has already been placed - value = EncodeRadioRowCol(row_num, col_num) # value to set intvar to if this radio is selected + value = EncodeRadioRowCol(form.ContainerElemementNumber, row_num, col_num) # value to set intvar to if this radio is selected + element.EncodedRadioValue = value if ID in toplevel_form.RadioDict: RadVar = toplevel_form.RadioDict[ID] else: