Skip to content
Permalink
Browse files

Catching up version 2.7 to 3.0 PySimpleGUI

  • Loading branch information...
MikeTheWatchGuy committed Mar 9, 2019
1 parent bed651b commit 1b88993244a6382a925bcd7766b78abe38f3f0d8
Showing with 34 additions and 14 deletions.
  1. +34 −14 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 @@ def __init__(self, text, group_id, default=False, disabled=False, size=(None, No
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 @@ def __init__(self, default_text='', enter_submits=False, disabled=False, autoscr
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 @@ def Update(self, value=None, disabled=None, append=False, font=None, text_color=
elif visible is True:
self.TKText.pack()



def Get(self):
return self.TKText.get(1.0, tk.END)

@@ -1897,7 +1900,10 @@ def Update(self, filename=None, data=None, size=(None,None), visible=None):
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 @@ def __init__(self, title, layout, title_color=None, background_color=None, title
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 @@ def __init__(self, title, layout, title_color=None, background_color=None, font=
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 @@ def __init__(self, range=(None, None), default_value=None, resolution=None, tick
: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 @@ def __init__(self, layout, background_color=None, size=(None, None), pad=None, s
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 @@ def __init__(self, title, default_element_size=DEFAULT_ELEMENT_SIZE, default_but
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 @@ def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False)
# 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 CharWidthInPixels():
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 CharWidthInPixels():
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:

0 comments on commit 1b88993

Please sign in to comment.
You can’t perform that action at this time.