Ability to have multiple different progress bar styles, fix tearoff menu problem, added title to Tab.update, Combox drop-down now sets font

This commit is contained in:
PySimpleGUI 2020-05-24 19:06:24 -04:00
parent 31af6eec96
commit a95fccad69
1 changed files with 43 additions and 15 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "4.19.0.8 Unreleased - Window.set_title added, removed resetting stdout when flush happens, fixed MenuBar tearoff not working, fixed get folder for Macs, fixed multiline color problem, option to set tooltip font, make typing module import optional, docstring" version = __version__ = "4.19.0.9 Unreleased - Window.set_title added, removed resetting stdout when flush happens, fixed MenuBar tearoff not working, fixed get folder for Macs, fixed multiline color problem, option to set tooltip font, make typing module import optional, docstring, combobox drop-down portion font change, ability to have multiple progress bar themes at one time, setting radio button to False will clear entire group, added changing title to Tab update"
port = 'PySimpleGUI' port = 'PySimpleGUI'
@ -648,7 +648,7 @@ class Element():
self.Visible = visible self.Visible = visible
self.TKRightClickMenu = None self.TKRightClickMenu = None
self.Widget = None # Set when creating window. Has the main tkinter widget for element self.Widget = None # Set when creating window. Has the main tkinter widget for element
# self.Tearoff = False # why was this here?? should already be in the Menubar element...confusing... self.Tearoff = False # needed because of right click menu code
self.ParentRowFrame = None # type tk.Frame self.ParentRowFrame = None # type tk.Frame
self.metadata = metadata # type: Any self.metadata = metadata # type: Any
self.user_bind_dict = {} # Used when user defines a tkinter binding using bind method - convert bind string to key modifier self.user_bind_dict = {} # Used when user defines a tkinter binding using bind method - convert bind string to key modifier
@ -1710,10 +1710,12 @@ class Radio(Element):
return return
if value is not None: if value is not None:
try: try:
if value: if value is True:
self.TKIntVar.set(self.EncodedRadioValue) self.TKIntVar.set(self.EncodedRadioValue)
elif value is False:
self.TKIntVar.set(0)
except: except:
pass print('Error updating Radio')
self.InitialState = value self.InitialState = value
if disabled == True: if disabled == True:
self.TKRadio['state'] = 'disabled' self.TKRadio['state'] = 'disabled'
@ -2443,6 +2445,8 @@ class StatusBar(Element):
class TKProgressBar(): class TKProgressBar():
uniqueness_counter = 0
def __init__(self, root, max, length=400, width=DEFAULT_PROGRESS_BAR_SIZE[1], style=DEFAULT_TTK_THEME, def __init__(self, root, max, length=400, width=DEFAULT_PROGRESS_BAR_SIZE[1], style=DEFAULT_TTK_THEME,
relief=DEFAULT_PROGRESS_BAR_RELIEF, border_width=DEFAULT_PROGRESS_BAR_BORDER_WIDTH, relief=DEFAULT_PROGRESS_BAR_RELIEF, border_width=DEFAULT_PROGRESS_BAR_BORDER_WIDTH,
orientation='horizontal', BarColor=(None, None), key=None): orientation='horizontal', BarColor=(None, None), key=None):
@ -2475,31 +2479,38 @@ class TKProgressBar():
self.Orientation = orientation self.Orientation = orientation
self.Count = None self.Count = None
self.PriorCount = 0 self.PriorCount = 0
self.StyleName = ''
TKProgressBar.uniqueness_counter += 1
if orientation.lower().startswith('h'): if orientation.lower().startswith('h'):
s = ttk.Style() s = ttk.Style()
s.theme_use(style) s.theme_use(style)
self.style_name = str(key) + str(TKProgressBar.uniqueness_counter) + "my.Horizontal.TProgressbar"
if BarColor != COLOR_SYSTEM_DEFAULT: if BarColor != COLOR_SYSTEM_DEFAULT:
s.configure(str(key) + "my.Horizontal.TProgressbar", background=BarColor[0], troughcolor=BarColor[1], s.configure(self.style_name, background=BarColor[0], troughcolor=BarColor[1],
troughrelief=relief, borderwidth=border_width, thickness=width) troughrelief=relief, borderwidth=border_width, thickness=width)
else: else:
s.configure(str(key) + "my.Horizontal.TProgressbar", troughrelief=relief, borderwidth=border_width, s.configure(self.style_name, troughrelief=relief, borderwidth=border_width,
thickness=width) thickness=width)
self.TKProgressBarForReal = ttk.Progressbar(root, maximum=self.Max, self.TKProgressBarForReal = ttk.Progressbar(root, maximum=self.Max,
style=str(key) + 'my.Horizontal.TProgressbar', length=length, style=self.style_name, length=length,
orient=tk.HORIZONTAL, mode='determinate') orient=tk.HORIZONTAL, mode='determinate')
else: else:
s = ttk.Style() s = ttk.Style()
s.theme_use(style) s.theme_use(style)
self.style_name = str(key) + str(TKProgressBar.uniqueness_counter) + "my.Vertical.TProgressbar"
if BarColor != COLOR_SYSTEM_DEFAULT: if BarColor != COLOR_SYSTEM_DEFAULT:
s.configure(str(key) + "my.Vertical.TProgressbar", background=BarColor[0],
s.configure(self.style_name, background=BarColor[0],
troughcolor=BarColor[1], troughrelief=relief, borderwidth=border_width, thickness=width) troughcolor=BarColor[1], troughrelief=relief, borderwidth=border_width, thickness=width)
else: else:
s.configure(str(key) + "my.Vertical.TProgressbar", troughrelief=relief, s.configure(self.style_name, troughrelief=relief,
borderwidth=border_width, thickness=width) borderwidth=border_width, thickness=width)
self.TKProgressBarForReal = ttk.Progressbar(root, maximum=self.Max, self.TKProgressBarForReal = ttk.Progressbar(root, maximum=self.Max,
style=str(key) + 'my.Vertical.TProgressbar', style=self.style_name,
length=length, orient=tk.VERTICAL, mode='determinate') length=length, orient=tk.VERTICAL, mode='determinate')
def Update(self, count=None, max=None): def Update(self, count=None, max=None):
@ -3225,14 +3236,14 @@ class ButtonMenu(Element):
self.Disabled = disabled self.Disabled = disabled
self.IsButtonMenu = True self.IsButtonMenu = True
self.MenuItemChosen = None self.MenuItemChosen = None
self.Tearoff = tearoff
self.TKButtonMenu = None # type: tk.Menubutton self.TKButtonMenu = None # type: tk.Menubutton
self.TKMenu = None # type: tk.Menu self.TKMenu = None # type: tk.Menu
# self.temp_size = size if size != (NONE, NONE) else # self.temp_size = size if size != (NONE, NONE) else
super().__init__(ELEM_TYPE_BUTTONMENU, size=size, font=font, pad=pad, key=key, tooltip=tooltip, super().__init__(ELEM_TYPE_BUTTONMENU, size=size, font=font, pad=pad, key=key, tooltip=tooltip,
text_color=self.TextColor, background_color=self.BackgroundColor, visible=visible, metadata=metadata) text_color=self.TextColor, background_color=self.BackgroundColor, visible=visible, metadata=metadata)
return self.Tearoff = tearoff
def _MenuItemChosenCallback(self, item_chosen): # ButtonMenu Menu Item Chosen Callback def _MenuItemChosenCallback(self, item_chosen): # ButtonMenu Menu Item Chosen Callback
""" """
@ -4699,10 +4710,12 @@ class Tab(Element):
return self return self
def Update(self, disabled=None, visible=None): # TODO Disable / enable of tabs is not complete def Update(self, title=None, disabled=None, visible=None): # TODO Disable / enable of tabs is not complete
""" """
Changes some of the settings for the Tab Element. Must call `Window.Read` or `Window.Finalize` prior Changes some of the settings for the Tab Element. Must call `Window.Read` or `Window.Finalize` prior
:param title: tab title
:type title: (str)
:param disabled: disable or enable state of the element :param disabled: disable or enable state of the element
:type disabled: (bool) :type disabled: (bool)
:param visible: control visibility of element :param visible: control visibility of element
@ -4719,6 +4732,11 @@ class Tab(Element):
if visible is False: if visible is False:
state = 'hidden' state = 'hidden'
self.ParentNotebook.tab(self.TabID, state=state) self.ParentNotebook.tab(self.TabID, state=state)
if title is not None:
self.Title = str(title)
self.ParentNotebook.tab(self.ContainerElemementNumber-1, text=self.Title)
# if visible is False: # if visible is False:
# self.ParentNotebook.pack_forget() # self.ParentNotebook.pack_forget()
# elif visible is True: # elif visible is True:
@ -4751,6 +4769,7 @@ class Tab(Element):
except Exception as e: except Exception as e:
print('Exception Selecting Tab {}'.format(e)) print('Exception Selecting Tab {}'.format(e))
add_row = AddRow add_row = AddRow
layout = Layout layout = Layout
select = Select select = Select
@ -5758,11 +5777,14 @@ class Menu(Element):
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.MenuDefinition = menu_definition self.MenuDefinition = menu_definition
self.Widget = self.TKMenu = None # type: tk.Menu self.Widget = self.TKMenu = None # type: tk.Menu
self.Tearoff = tearoff
self.MenuItemChosen = None self.MenuItemChosen = None
super().__init__(ELEM_TYPE_MENUBAR, background_color=background_color, size=size, pad=pad, key=key, super().__init__(ELEM_TYPE_MENUBAR, background_color=background_color, size=size, pad=pad, key=key,
visible=visible, font=font, metadata=metadata) visible=visible, font=font, metadata=metadata)
self.Tearoff = tearoff
return return
def _MenuItemChosenCallback(self, item_chosen): # Menu Menu Item Chosen Callback def _MenuItemChosenCallback(self, item_chosen): # Menu Menu Item Chosen Callback
@ -10294,11 +10316,14 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
combostyle.configure(style_name, fieldbackground=element.BackgroundColor) combostyle.configure(style_name, fieldbackground=element.BackgroundColor)
combostyle.configure(style_name, selectforeground=element.TextColor) combostyle.configure(style_name, selectforeground=element.TextColor)
# Strange code that is needed to set the font for the drop-down list
element._newfont = tkinter.font.Font(font=font)
tk_row_frame.option_add("*TCombobox*Listbox*Font", element._newfont)
element.TKCombo = element.Widget = ttk.Combobox(tk_row_frame, width=width, element.TKCombo = element.Widget = ttk.Combobox(tk_row_frame, width=width,
textvariable=element.TKStringVar, font=font, textvariable=element.TKStringVar, font=font,
style=style_name) style=style_name)
# Chr0nic # Chr0nic
element.TKCombo.bind("<Enter>", lambda event, em=element: testMouseHook2(em)) element.TKCombo.bind("<Enter>", lambda event, em=element: testMouseHook2(em))
element.TKCombo.bind("<Leave>", lambda event, em=element: testMouseUnhook2(em)) element.TKCombo.bind("<Leave>", lambda event, em=element: testMouseUnhook2(em))
@ -13543,6 +13568,7 @@ def Popup(*args, title=None, button_color=None, background_color=None, text_colo
message = str(message) message = str(message)
if message.count('\n'): if message.count('\n'):
message_wrapped = message message_wrapped = message
# message_wrapped = textwrap.fill(message, local_line_width)
else: else:
message_wrapped = textwrap.fill(message, local_line_width) message_wrapped = textwrap.fill(message, local_line_width)
message_wrapped_lines = message_wrapped.count('\n') + 1 message_wrapped_lines = message_wrapped.count('\n') + 1
@ -15687,6 +15713,7 @@ def main():
[Listbox(['Listbox 1', 'Listbox 2', 'Listbox 3'], select_mode=SELECT_MODE_EXTENDED, size=(20, 5), no_scrollbar=True)], [Listbox(['Listbox 1', 'Listbox 2', 'Listbox 3'], select_mode=SELECT_MODE_EXTENDED, size=(20, 5), no_scrollbar=True)],
[Combo(['Combo item %s' % i for i in range(5)], size=(20, 3), default_value='Combo item 2', key='_COMBO1_', )], [Combo(['Combo item %s' % i for i in range(5)], size=(20, 3), default_value='Combo item 2', key='_COMBO1_', )],
[Combo(['Combo item %s' % i for i in range(5)], size=(20, 3), font='Courier 20', default_value='Combo item 2', key='_COMBO2_', )],
# [Combo(['Combo item 1', 2,3,4], size=(20, 3), readonly=False, text_color='blue', background_color='red', key='_COMBO2_')], # [Combo(['Combo item 1', 2,3,4], size=(20, 3), readonly=False, text_color='blue', background_color='red', key='_COMBO2_')],
[Spin([1, 2, 3, 'a', 'b', 'c'], initial_value='a', size=(4, 3))], [Spin([1, 2, 3, 'a', 'b', 'c'], initial_value='a', size=(4, 3))],
] ]
@ -15735,6 +15762,7 @@ def main():
[Text('PySimpleGUI Location {}'.format(os.path.dirname(os.path.abspath(__file__))), size=(50, None), font='ANY 12')], [Text('PySimpleGUI Location {}'.format(os.path.dirname(os.path.abspath(__file__))), size=(50, None), font='ANY 12')],
[Text('Python Version {}'.format(sys.version), size=(50, None), font='ANY 12')], [Text('Python Version {}'.format(sys.version), size=(50, None), font='ANY 12')],
[Text('TK / TCL Versions {} / {}'.format(tk.TkVersion, tk.TclVersion), size=(50, None), font='ANY 12')], [Text('TK / TCL Versions {} / {}'.format(tk.TkVersion, tk.TclVersion), size=(50, None), font='ANY 12')],
[TabGroup([[tab1, tab2, tab3, tab4]], key='_TAB_GROUP_')], [TabGroup([[tab1, tab2, tab3, tab4]], key='_TAB_GROUP_')],
[Button('Button'), B('Hide Stuff', metadata='my metadata'), [Button('Button'), B('Hide Stuff', metadata='my metadata'),
Button('ttk Button', use_ttk_buttons=True, tooltip='This is a TTK Button'), Button('ttk Button', use_ttk_buttons=True, tooltip='This is a TTK Button'),