Major demo refresh.. switched everything to new function names, new design patterns

Out with the old, in with the new!!
This commit is contained in:
MikeTheWatchGuy 2018-09-24 18:01:00 -04:00
parent 2a06683383
commit a1f4c60271
68 changed files with 706 additions and 1863 deletions

View file

@ -3,6 +3,7 @@ from PIL import Image
import tempfile
import PySimpleGUI as sg
import os
from sys import exit as exit
"""
Demo program to open and play a file using OpenCV
@ -14,8 +15,8 @@ Until then enjoy it working somewhat slowly.
def main():
filename = 'C:/Python/MIDIVideo/PlainVideos/- 08-30 Ted Talk/TED Talk Short - Video+.mp4'
# filename = sg.PopupGetFile('Filename to play')
# filename = 'C:/Python/MIDIVideo/PlainVideos/- 08-30 Ted Talk/TED Talk Short - Video+.mp4'
filename = sg.PopupGetFile('Filename to play')
if filename is None:
exit(69)
vidFile = cv.VideoCapture(filename)
@ -25,23 +26,23 @@ def main():
sg.ChangeLookAndFeel('Dark')
# define the form layout
# define the window layout
layout = [[sg.Text('OpenCV Demo', size=(15, 1),pad=((510,0),3), justification='center', font='Helvetica 20')],
[sg.Image(filename='', key='image')],
[sg.Slider(range=(0, num_frames), size=(115, 10), orientation='h', key='slider')],
[sg.ReadFormButton('Exit', size=(10, 2), pad=((600, 0), 3), font='Helvetica 14')]]
[sg.ReadButton('Exit', size=(10, 2), pad=((600, 0), 3), font='Helvetica 14')]]
# create the form and show it without the plot
form = sg.FlexForm('Demo Application - OpenCV Integration', no_titlebar=False, location=(0,0))
form.Layout(layout)
form.ReadNonBlocking()
# create the window and show it without the plot
window = sg.Window('Demo Application - OpenCV Integration', no_titlebar=False, location=(0,0))
window.Layout(layout)
window.ReadNonBlocking()
# ---===--- LOOP through video file by frame --- #
i = 0
temp_filename = next(tempfile._get_candidate_names()) + '.png'
while vidFile.isOpened():
button, values = form.ReadNonBlocking()
button, values = window.ReadNonBlocking()
if button is 'Exit' or values is None:
os.remove(temp_filename)
exit(69)
@ -49,12 +50,12 @@ def main():
if not ret: # if out of data stop looping
break
form.FindElement('slider').Update(i)
window.FindElement('slider').Update(i)
i += 1
with open(temp_filename, 'wb') as f:
Image.fromarray(frame).save(temp_filename, 'PNG') # save the PIL image as file
form.FindElement('image').Update(filename=temp_filename)
window.FindElement('image').Update(filename=temp_filename)
main()