2018-09-04 18:40:16 +00:00
|
|
|
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))
|
|
|
|
|
|
|
|
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')],
|
2018-09-18 16:05:44 +00:00
|
|
|
[sg.ReadFormButton('Start', button_color=('white', 'black'), key='Start'),
|
2018-09-19 14:39:46 +00:00
|
|
|
sg.ReadFormButton('Stop', button_color=('white', 'black'), key='Stop'),
|
|
|
|
sg.ReadFormButton('Reset', button_color=('white', 'firebrick3'), key='Reset'),
|
|
|
|
sg.ReadFormButton('Submit', button_color=('white', 'springgreen4'), key='Submit')]
|
2018-09-04 18:40:16 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
form = sg.FlexForm("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False,
|
2018-09-06 16:10:58 +00:00
|
|
|
default_button_element_size=(12,1))
|
2018-09-04 18:40:16 +00:00
|
|
|
form.Layout(layout)
|
2018-09-19 14:39:46 +00:00
|
|
|
form.Finalize()
|
|
|
|
form.FindElement('Stop').Update(disabled=True)
|
|
|
|
form.FindElement('Reset').Update(disabled=True)
|
|
|
|
form.FindElement('Submit').Update(disabled=True)
|
2018-09-04 18:40:16 +00:00
|
|
|
recording = have_data = False
|
|
|
|
while True:
|
|
|
|
button, values = form.Read()
|
2018-09-18 16:05:44 +00:00
|
|
|
print(button)
|
2018-09-04 18:40:16 +00:00
|
|
|
if button is None:
|
|
|
|
exit(69)
|
|
|
|
if button is 'Start':
|
2018-09-18 16:05:44 +00:00
|
|
|
form.FindElement('Start').Update(disabled=True)
|
|
|
|
form.FindElement('Stop').Update(disabled=False)
|
|
|
|
form.FindElement('Reset').Update(disabled=False)
|
2018-09-19 14:39:46 +00:00
|
|
|
form.FindElement('Submit').Update(disabled=True)
|
2018-09-04 18:40:16 +00:00
|
|
|
recording = True
|
|
|
|
elif button is 'Stop' and recording:
|
2018-09-18 16:05:44 +00:00
|
|
|
form.FindElement('Stop').Update(disabled=True)
|
|
|
|
form.FindElement('Start').Update(disabled=False)
|
|
|
|
form.FindElement('Submit').Update(disabled=False)
|
2018-09-04 18:40:16 +00:00
|
|
|
recording = False
|
|
|
|
have_data = True
|
|
|
|
elif button is 'Reset':
|
2018-09-19 14:39:46 +00:00
|
|
|
form.FindElement('Stop').Update(disabled=True)
|
|
|
|
form.FindElement('Start').Update(disabled=False)
|
|
|
|
form.FindElement('Submit').Update(disabled=True)
|
|
|
|
form.FindElement('Reset').Update(disabled=False)
|
2018-09-04 18:40:16 +00:00
|
|
|
recording = False
|
|
|
|
have_data = False
|
|
|
|
elif button is 'Submit' and have_data:
|
2018-09-19 14:39:46 +00:00
|
|
|
form.FindElement('Stop').Update(disabled=True)
|
|
|
|
form.FindElement('Start').Update(disabled=False)
|
|
|
|
form.FindElement('Submit').Update(disabled=True)
|
|
|
|
form.FindElement('Reset').Update(disabled=False)
|
2018-09-04 18:40:16 +00:00
|
|
|
recording = False
|
|
|
|
|