Merge pull request #332 from MikeTheWatchGuy/Dev-latest

Dev latest
This commit is contained in:
MikeTheWatchGuy 2018-09-24 10:40:28 -04:00 committed by GitHub
commit ae1e5f574f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 182 additions and 0 deletions

20
Demo_Tabs.py Normal file
View File

@ -0,0 +1,20 @@
import PySimpleGUI as sg
tab1_layout = [[sg.T('This is inside tab 1')]]
tab2_layout = [[sg.T('This is inside tab 2')]]
tab3_layout = [[sg.T('This is inside tab 3')]]
tab4_layout = [[sg.T('This is inside tab 4')]]
tab5_layout = [[sg.T('This is inside tab 5')]]
tab6_layout = [[sg.T('This is inside tab 6')],
[sg.T('How about a second row of stuff in tab 6?')]]
layout = [[sg.T('My Window!')],
[sg.MultiTab([[sg.Tab('Tab 1', tab1_layout), sg.Tab('Tab 2', tab2_layout)]]), sg.MultiTab([[sg.Tab('Tab 3', tab3_layout), sg.Tab('Tab 4', tab4_layout)]])],
[sg.T('Text in the middle of the mess')],
[sg.MultiTab([[sg.Tab('Tab 5', tab5_layout), sg.Tab('Tab 6', tab6_layout)]])],
]
window = sg.Window('My window with tabs').Layout(layout)
b, v = window.Read()

View File

@ -194,6 +194,8 @@ ELEM_TYPE_IMAGE = 30
ELEM_TYPE_CANVAS = 40 ELEM_TYPE_CANVAS = 40
ELEM_TYPE_FRAME = 41 ELEM_TYPE_FRAME = 41
ELEM_TYPE_GRAPH = 42 ELEM_TYPE_GRAPH = 42
ELEM_TYPE_TAB = 50
ELEM_TYPE_MULTI_TAB = 51
ELEM_TYPE_INPUT_SLIDER = 10 ELEM_TYPE_INPUT_SLIDER = 10
ELEM_TYPE_INPUT_LISTBOX = 11 ELEM_TYPE_INPUT_LISTBOX = 11
ELEM_TYPE_OUTPUT = 300 ELEM_TYPE_OUTPUT = 300
@ -1379,6 +1381,121 @@ class Frame(Element):
super().__del__() super().__del__()
# ---------------------------------------------------------------------- #
# Tab #
# ---------------------------------------------------------------------- #
class Tab(Element):
def __init__(self, title, layout, title_color=None, background_color=None, size=(None, None), font=None, pad=None, border_width=None, key=None, tooltip=None):
self.UseDictionary = False
self.ReturnValues = None
self.ReturnValuesList = []
self.ReturnValuesDictionary = {}
self.DictionaryKeyCounter = 0
self.ParentWindow = None
self.Rows = []
self.TKFrame = None
self.Title = title
self.BorderWidth = border_width
self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
self.Layout(layout)
super().__init__(ELEM_TYPE_TAB, background_color=background_color, text_color=title_color, size=size, font=font, pad=pad, key=key, tooltip=tooltip)
return
def AddRow(self, *args):
''' Parms are a variable number of Elements '''
NumRows = len(self.Rows) # number of existing rows is our row number
CurrentRowNumber = NumRows # this row's number
CurrentRow = [] # start with a blank row and build up
# ------------------------- Add the elements to a row ------------------------- #
for i, element in enumerate(args): # Loop through list of elements and add them to the row
element.Position = (CurrentRowNumber, i)
element.ParentContainer = self
CurrentRow.append(element)
if element.Key is not None:
self.UseDictionary = True
# ------------------------- Append the row to list of Rows ------------------------- #
self.Rows.append(CurrentRow)
def Layout(self, rows):
for row in rows:
self.AddRow(*row)
def _GetElementAtLocation(self, location):
(row_num,col_num) = location
row = self.Rows[row_num]
element = row[col_num]
return element
def __del__(self):
for row in self.Rows:
for element in row:
element.__del__()
super().__del__()
# ---------------------------------------------------------------------- #
# MultiTab #
# ---------------------------------------------------------------------- #
class MultiTab(Element):
def __init__(self, layout, title_color=None, background_color=None, size=(None, None), font=None, pad=None, border_width=None, key=None, tooltip=None):
self.UseDictionary = False
self.ReturnValues = None
self.ReturnValuesList = []
self.ReturnValuesDictionary = {}
self.DictionaryKeyCounter = 0
self.ParentWindow = None
self.Rows = []
self.TKNotebook = None
self.BorderWidth = border_width
self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
self.Layout(layout)
super().__init__(ELEM_TYPE_MULTI_TAB, background_color=background_color, text_color=title_color, size=size, font=font, pad=pad, key=key, tooltip=tooltip)
return
def AddRow(self, *args):
''' Parms are a variable number of Elements '''
NumRows = len(self.Rows) # number of existing rows is our row number
CurrentRowNumber = NumRows # this row's number
CurrentRow = [] # start with a blank row and build up
# ------------------------- Add the elements to a row ------------------------- #
for i, element in enumerate(args): # Loop through list of elements and add them to the row
element.Position = (CurrentRowNumber, i)
element.ParentContainer = self
CurrentRow.append(element)
if element.Key is not None:
self.UseDictionary = True
# ------------------------- Append the row to list of Rows ------------------------- #
self.Rows.append(CurrentRow)
def Layout(self, rows):
for row in rows:
self.AddRow(*row)
def _GetElementAtLocation(self, location):
(row_num,col_num) = location
row = self.Rows[row_num]
element = row[col_num]
return element
def __del__(self):
for row in self.Rows:
for element in row:
element.__del__()
super().__del__()
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
# Slider # # Slider #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
@ -2043,6 +2160,14 @@ class Window:
return element return element
def UpdateElements(self, key_list, value_list):
for i, key in enumerate(key_list):
try:
self.FindElement(key).Update(value_list[i])
except:
pass
def SaveToDisk(self, filename): def SaveToDisk(self, filename):
try: try:
results = BuildResults(self, False, self) results = BuildResults(self, False, self)
@ -2998,6 +3123,42 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
labeled_frame.configure(borderwidth=element.BorderWidth) labeled_frame.configure(borderwidth=element.BorderWidth)
if element.Tooltip is not None: if element.Tooltip is not None:
element.TooltipObject = ToolTip(labeled_frame, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME) element.TooltipObject = ToolTip(labeled_frame, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME)
# ------------------------- Tab element ------------------------- #
elif element_type == ELEM_TYPE_TAB:
element.TKFrame = ttk.Frame(form.TKNotebook)
PackFormIntoFrame(element, element.TKFrame, toplevel_form)
form.TKNotebook.add(element.TKFrame, text='foo')
form.TKNotebook.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
# form.TKNotebook.pack(row=0, sticky=tk.NW)
# if element.BackgroundColor != COLOR_SYSTEM_DEFAULT and element.BackgroundColor is not None:
# element.TKFrame.configure(background=element.BackgroundColor,
# highlightbackground=element.BackgroundColor,
# highlightcolor=element.BackgroundColor)
# if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None:
# element.TKFrame.configure(foreground=element.TextColor)
# if element.BorderWidth is not None:
# element.TKFrame.configure(borderwidth=element.BorderWidth)
# if element.Tooltip is not None:
# element.TooltipObject = ToolTip(element.TKFrame, text=element.Tooltip,
# timeout=DEFAULT_TOOLTIP_TIME)
# ------------------------- MultiTab element ------------------------- #
elif element_type == ELEM_TYPE_MULTI_TAB:
element.TKNotebook = ttk.Notebook(tk_row_frame)
PackFormIntoFrame(element, toplevel_form.TKroot, toplevel_form)
# element.TKNotebook.pack(side=tk.LEFT)
# if element.BackgroundColor != COLOR_SYSTEM_DEFAULT and element.BackgroundColor is not None:
# element.TKNotebook.configure(background=element.BackgroundColor,
# highlightbackground=element.BackgroundColor,
# highlightcolor=element.BackgroundColor)
# if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None:
# element.TKNotebook.configure(foreground=element.TextColor)
# if element.BorderWidth is not None:
# element.TKNotebook.configure(borderwidth=element.BorderWidth)
# if element.Tooltip is not None:
# element.TooltipObject = ToolTip(element.TKNotebook, text=element.Tooltip,
# timeout=DEFAULT_TOOLTIP_TIME)
# ------------------------- SLIDER Box element ------------------------- # # ------------------------- SLIDER Box element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_SLIDER: elif element_type == ELEM_TYPE_INPUT_SLIDER:
slider_length = element_size[0] * CharWidthInPixels() slider_length = element_size[0] * CharWidthInPixels()
@ -3170,6 +3331,7 @@ def ShowTabbedForm(title, *args, auto_close=False, auto_close_duration=DEFAULT_A
for num,x in enumerate(args): for num,x in enumerate(args):
form, rows, tab_name = x form, rows, tab_name = x
form.AddRows(rows) form.AddRows(rows)
form.UseDictionary = True
if DEFAULT_BACKGROUND_COLOR: if DEFAULT_BACKGROUND_COLOR:
framestyle.theme_use('framestyle') framestyle.theme_use('framestyle')