Merge pull request #119 from MikeTheWatchGuy/Dev-latest

Dev latest
This commit is contained in:
MikeTheWatchGuy 2018-09-04 17:37:18 -04:00 committed by GitHub
commit 3e850494f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 1 deletions

54
Demo_Button_States.py Normal file
View File

@ -0,0 +1,54 @@
import PySimpleGUI as sg
"""
Demonstrates using a "tight" layout with a Dark theme.
Shows how button states can be controlled by a user application. The program manages the disabled/enabled
states for buttons and changes the text color to show greyed-out (disabled) buttons
"""
sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0,0))
StartButton = sg.ReadFormButton('Start', button_color=('white', 'black'))
StopButton = sg.ReadFormButton('Stop', button_color=('gray34','black'))
ResetButton = sg.ReadFormButton('Reset', button_color=('gray','firebrick3'))
SubmitButton = sg.ReadFormButton('Submit', button_color=('gray34','springgreen4'))
layout = [[sg.T('User:', pad=((3,0),0)), sg.OptionMenu(values = ('User 1', 'User 2'), size=(20,1)), sg.T('0', size=(8,1))],
[sg.T('Customer:', pad=((3,0),0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20,1)), sg.T('1', size=(8,1))],
[sg.T('Notes:', pad=((3,0),0)), sg.In(size=(44,1), background_color='white', text_color='black')],
[StartButton, StopButton, ResetButton, SubmitButton]
]
form = sg.FlexForm("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(12,1))
form.Layout(layout)
recording = have_data = False
while True:
button, values = form.Read()
if button is None:
exit(69)
if button is 'Start':
StartButton.Update(button_color=('gray34','black'))
StopButton.Update(button_color=('white', 'black'))
ResetButton.Update(button_color=('white', 'firebrick3'))
recording = True
elif button is 'Stop' and recording:
StopButton.Update(button_color=('gray34','black'))
StartButton.Update(button_color=('white', 'black'))
SubmitButton.Update(button_color=('white', 'springgreen4'))
recording = False
have_data = True
elif button is 'Reset':
StopButton.Update(button_color=('gray34','black'))
StartButton.Update(button_color=('white', 'black'))
SubmitButton.Update(button_color=('gray34', 'springgreen4'))
ResetButton.Update(button_color=('gray34', 'firebrick3'))
recording = False
have_data = False
elif button is 'Submit' and have_data:
StopButton.Update(button_color=('gray34','black'))
StartButton.Update(button_color=('white', 'black'))
SubmitButton.Update(button_color=('gray34', 'springgreen4'))
ResetButton.Update(button_color=('gray34', 'firebrick3'))
recording = False

View File

@ -232,6 +232,14 @@ class Element():
self.ParentForm.TKroot.quit() # kick the users out of the mainloop self.ParentForm.TKroot.quit() # kick the users out of the mainloop
def ComboboxSelectHandler(self, event):
MyForm = self.ParentForm
# first, get the results table built
# modify the Results table in the parent FlexForm object
self.ParentForm.LastButtonClicked = ''
self.ParentForm.FormRemainedOpen = True
self.ParentForm.TKroot.quit() # kick the users out of the mainloop
def __del__(self): def __del__(self):
try: try:
self.TKStringVar.__del__() self.TKStringVar.__del__()
@ -289,7 +297,7 @@ class InputText(Element):
# Combo # # Combo #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class InputCombo(Element): class InputCombo(Element):
def __init__(self, values, default_value=None, scale=(None, None), size=(None, None), auto_size_text=None, background_color=None, text_color=None, key=None, pad=None): def __init__(self, values, default_value=None, scale=(None, None), size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, key=None, pad=None):
''' '''
Input Combo Box Element (also called Dropdown box) Input Combo Box Element (also called Dropdown box)
:param values: :param values:
@ -301,6 +309,7 @@ class InputCombo(Element):
self.Values = values self.Values = values
self.DefaultValue = default_value self.DefaultValue = default_value
self.TKComboBox = None self.TKComboBox = None
self.ChangeSubmits = change_submits
bg = background_color if background_color else DEFAULT_INPUT_ELEMENTS_COLOR bg = background_color if background_color else DEFAULT_INPUT_ELEMENTS_COLOR
fg = text_color if text_color is not None else DEFAULT_INPUT_TEXT_COLOR fg = text_color if text_color is not None else DEFAULT_INPUT_TEXT_COLOR
@ -1996,6 +2005,8 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
break break
else: else:
element.TKCombo.current(0) element.TKCombo.current(0)
if element.ChangeSubmits:
element.TKCombo.bind('<<ComboboxSelected>>', element.ComboboxSelectHandler)
# ------------------------- OPTION MENU (Like ComboBox but different) element ------------------------- # # ------------------------- OPTION MENU (Like ComboBox but different) element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_OPTION_MENU: elif element_type == ELEM_TYPE_INPUT_OPTION_MENU:
max_line_len = max([len(str(l)) for l in element.Values]) max_line_len = max([len(str(l)) for l in element.Values])