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