Major update of all demo programs to use new PEP8 bindings, etc
This commit is contained in:
parent
3f7c87c562
commit
7f52778bcc
307 changed files with 19546 additions and 3297 deletions
|
@ -1,10 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
import PySimpleGUI as sg
|
||||
# import PySimpleGUIQt as sg # portable to QT
|
||||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
import PySimpleGUI as sg
|
||||
|
||||
#
|
||||
# An Async Demonstration of a media player
|
||||
|
@ -12,42 +7,39 @@ else:
|
|||
# See how it looks here:
|
||||
# https://user-images.githubusercontent.com/13696193/43159403-45c9726e-8f50-11e8-9da0-0d272e20c579.jpg
|
||||
#
|
||||
|
||||
|
||||
def MediaPlayerGUI():
|
||||
background = '#F0F0F0'
|
||||
# Set the backgrounds the same as the background on the buttons
|
||||
sg.SetOptions(background_color=background, element_background_color=background)
|
||||
# Images are located in a subfolder in the Demo Media Player.py folder
|
||||
image_pause = './ButtonGraphics/Pause.png'
|
||||
image_restart = './ButtonGraphics/Restart.png'
|
||||
image_next = './ButtonGraphics/Next.png'
|
||||
image_exit = './ButtonGraphics/Exit.png'
|
||||
sg.set_options(background_color=background,
|
||||
element_background_color=background)
|
||||
|
||||
# A text element that will be changed to display messages in the GUI
|
||||
|
||||
ImageButton = lambda image_filename, key:sg.Button('', button_color=(background,background), image_filename=image_filename, image_size=(50, 50), image_subsample=2, border_width=0, key=key)
|
||||
def ImageButton(title, key):
|
||||
return sg.Button(title, button_color=(background, background),
|
||||
border_width=0, key=key)
|
||||
|
||||
# define layout of the rows
|
||||
layout= [[sg.Text('Media File Player', font=("Helvetica", 25))],
|
||||
[sg.Text('', size=(15, 2), font=("Helvetica", 14), key='output')],
|
||||
[ImageButton(image_restart, key='Restart Song'), sg.Text(' ' * 2),
|
||||
ImageButton(image_pause, key='Pause'),
|
||||
sg.Text(' ' * 2),
|
||||
ImageButton(image_next, key='Next'),
|
||||
sg.Text(' ' * 2),
|
||||
sg.Text(' ' * 2),ImageButton(image_exit, key='Exit')],
|
||||
]
|
||||
layout = [[sg.Text('Media File Player', font=("Helvetica", 25))],
|
||||
[sg.Text('', size=(15, 2), font=("Helvetica", 14), key='output')],
|
||||
[ImageButton('restart', key='Restart Song'), sg.Text(' ' * 2),
|
||||
ImageButton('pause', key='Pause'), sg.Text(' ' * 2),
|
||||
ImageButton('next', key='Next'), sg.Text(' ' * 2),
|
||||
sg.Text(' ' * 2), ImageButton('exit', key='Exit')],
|
||||
]
|
||||
|
||||
# Open a form, note that context manager can't be used generally speaking for async forms
|
||||
window = sg.Window('Media File Player', auto_size_text=True, default_element_size=(20, 1),
|
||||
font=("Helvetica", 25)).Layout(layout)
|
||||
# Our event loop
|
||||
while(True):
|
||||
event, values = window.Read(timeout=100) # Poll every 100 ms
|
||||
window = sg.Window('Media File Player', layout,
|
||||
default_element_size=(20, 1),
|
||||
font=("Helvetica", 25))
|
||||
|
||||
while True:
|
||||
event, values = window.read(timeout=100)
|
||||
if event == 'Exit' or event is None:
|
||||
break
|
||||
# If a button was pressed, display it on the GUI by updating the text element
|
||||
if event != sg.TIMEOUT_KEY:
|
||||
window.FindElement('output').Update(event)
|
||||
window['output'].update(event)
|
||||
|
||||
window.close()
|
||||
|
||||
|
||||
MediaPlayerGUI()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue