def main(): # 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) # ---===--- Get some Stats --- # num_frames = vidFile.get(cv.CAP_PROP_FRAME_COUNT) fps = vidFile.get(cv.CAP_PROP_FPS) sg.ChangeLookAndFeel('Dark') # 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.ReadButton('Exit', size=(10, 2), pad=((600, 0), 3), font='Helvetica 14') ]] # 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 = window.ReadNonBlocking() if button is 'Exit' or values is None: os.remove(temp_filename) exit(69) ret, frame = vidFile.read() if not ret: # if out of data stop looping break 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 window.FindElement('image').Update(filename=temp_filename)
def PlayerPlaybackGUIStart(self, NumFiles=1): # ------- Make a new FlexForm ------- # image_pause = './ButtonGraphics/Pause.png' image_restart = './ButtonGraphics/Restart.png' image_next = './ButtonGraphics/Next.png' image_exit = './ButtonGraphics/Exit.png' self.TextElem = sg.T('Song loading....', size=(70, 5 + NumFiles), font=("Helvetica", 14), auto_size_text=False) self.SliderElem = sg.Slider(range=(1, 100), size=(50, 8), orientation='h', text_color='#f0f0f0') layout = [[ sg.T('MIDI File Player', size=(30, 1), font=("Helvetica", 25)) ], [self.TextElem], [self.SliderElem], [ sg.ReadFormButton('PAUSE', button_color=sg.TRANSPARENT_BUTTON, image_filename=image_pause, image_size=(50, 50), image_subsample=2, border_width=0), sg.T(' '), sg.ReadFormButton('NEXT', button_color=sg.TRANSPARENT_BUTTON, image_filename=image_next, image_size=(50, 50), image_subsample=2, border_width=0), sg.T(' '), sg.ReadFormButton('Restart Song', button_color=sg.TRANSPARENT_BUTTON, image_filename=image_restart, image_size=(50, 50), image_subsample=2, border_width=0), sg.T(' '), sg.SimpleButton( 'EXIT', button_color=sg.TRANSPARENT_BUTTON, image_filename=image_exit, image_size=(50, 50), image_subsample=2, border_width=0, ) ]] window = sg.FlexForm('MIDI File Player', default_element_size=(30, 1), font=("Helvetica", 25)).Layout(layout).Finalize() self.Window = window
title='Options', title_color='red', relief=sg.RELIEF_SUNKEN, tooltip='Use these to set flags') ], [ sg.Multiline( default_text= 'This is the default Text should you decide not to type anything', size=(35, 3)), sg.Multiline(default_text='A second multi-line', size=(35, 3)) ], [ sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 1)), sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85) ], [sg.InputOptionMenu(('Menu Option 1', 'Menu Option 2', 'Menu Option 3'))], [ sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)), sg.Frame('Labelled Group', [[ sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25), sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
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' # A text element that will be changed to display messages in the GUI # define layout of the rows layout = [[ sg.Text('Media File Player', size=(17, 1), font=("Helvetica", 25)) ], [sg.Text('', size=(15, 2), font=("Helvetica", 14), key='output')], [ sg.ReadButton('Restart Song', button_color=(background, background), image_filename=image_restart, image_size=(50, 50), image_subsample=2, border_width=0), sg.Text(' ' * 2), sg.ReadButton('Pause', button_color=(background, background), image_filename=image_pause, image_size=(50, 50), image_subsample=2, border_width=0), sg.Text(' ' * 2), sg.ReadButton('Next', button_color=(background, background), image_filename=image_next, image_size=(50, 50), image_subsample=2, border_width=0), sg.Text(' ' * 2), sg.Text(' ' * 2), sg.Button('Exit', button_color=(background, background), image_filename=image_exit, image_size=(50, 50), image_subsample=2, border_width=0) ], [sg.Text('_' * 20)], [sg.Text(' ' * 30)], [ sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15)), sg.Text(' ' * 2), sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15)), sg.Text(' ' * 2), sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15)) ], [ sg.Text(' Bass', font=("Helvetica", 15), size=(9, 1)), sg.Text('Treble', font=("Helvetica", 15), size=(7, 1)), sg.Text('Volume', font=("Helvetica", 15), size=(7, 1)) ]] # 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), no_titlebar=True).Layout(layout) # Our event loop while (True): # Read the form (this call will not block) button, values = window.ReadNonBlocking() if button == 'Exit': break # If a button was pressed, display it on the GUI by updating the text element if button: window.FindElement('output').Update(button)
[ sg.T('Output:', pad=((3, 0), 0)), sg.T('', size=(44, 1), text_color='white', key='output') ], [ sg.CBox('Checkbox:', default=True, pad=((3, 0), 0), key='cbox'), sg.Listbox((1, 2, 3, 4), size=(8, 3), key='listbox'), sg.Radio('Radio 1', default=True, group_id='1', key='radio1'), sg.Radio('Radio 2', default=False, group_id='1', key='radio2') ], [ sg.Spin((1, 2, 3, 4), 1, key='spin'), sg.OptionMenu((1, 2, 3, 4), key='option'), sg.Combo(values=(1, 2, 3, 4), key='combo') ], [sg.Multiline('Multiline', size=(20, 3), key='multi')], [sg.Slider((1, 10), size=(20, 20), orientation='h', key='slider')], [ sg.ReadButton('Enable', button_color=('white', 'black')), sg.ReadButton('Disable', button_color=('white', 'black')), sg.ReadButton('Reset', button_color=('white', '#9B0023'), key='reset'), sg.ReadButton('Values', button_color=('white', 'springgreen4')), sg.Button('Exit', button_color=('white', '#00406B')) ]] window = sg.Window("Disable Elements Demo", default_element_size=(12, 1), text_justification='r', auto_size_text=False, auto_size_buttons=False,
def Everything(): sg.ChangeLookAndFeel('TanBlue') column1 = [[ sg.Text('Column 1', background_color=sg.DEFAULT_BACKGROUND_COLOR, justification='center', size=(10, 1)) ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1', key='spin1') ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2', key='spin2') ], [ sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3', key='spin3') ]] layout = [ [ sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25)) ], [sg.Text('Here is some text.... and a place to enter text')], [sg.InputText('This is my text', key='in1', do_not_clear=True)], [ sg.Checkbox('Checkbox', key='cb1'), sg.Checkbox('My second checkbox!', key='cb2', default=True) ], [ sg.Radio('My first Radio! ', "RADIO1", key='rad1', default=True), sg.Radio('My second Radio!', "RADIO1", key='rad2') ], [ sg.Multiline( default_text= 'This is the default Text should you decide not to type anything', size=(35, 3), key='multi1', do_not_clear=True), sg.Multiline(default_text='A second multi-line', size=(35, 3), key='multi2', do_not_clear=True) ], [ sg.InputCombo(('Combobox 1', 'Combobox 2'), key='combo', size=(20, 1)), sg.Slider(range=(1, 100), orientation='h', size=(34, 20), key='slide1', default_value=85) ], [ sg.InputOptionMenu( ('Menu Option 1', 'Menu Option 2', 'Menu Option 3'), key='optionmenu') ], [ sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3), key='listbox'), sg.Slider( range=(1, 100), orientation='v', size=(5, 20), default_value=25, key='slide2', ), sg.Slider( range=(1, 100), orientation='v', size=(5, 20), default_value=75, key='slide3', ), sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10, key='slide4'), sg.Column(column1, background_color='gray34') ], [sg.Text('_' * 80)], [sg.Text('Choose A Folder', size=(35, 1))], [ sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Default Folder', key='folder', do_not_clear=True), sg.FolderBrowse() ], [ sg.ReadButton('Exit'), sg.Text(' ' * 40), sg.ReadButton('SaveSettings'), sg.ReadButton('LoadSettings') ] ] window = sg.Window('Form Fill Demonstration', default_element_size=(40, 1), grab_anywhere=False) # button, values = window.LayoutAndRead(layout, non_blocking=True) window.Layout(layout) while True: button, values = window.Read() if button is 'SaveSettings': filename = sg.PopupGetFile('Save Settings', save_as=True, no_window=True) window.SaveToDisk(filename) # save(values) elif button is 'LoadSettings': filename = sg.PopupGetFile('Load Settings', no_window=True) window.LoadFromDisk(filename) # load(form) elif button in ['Exit', None]: break
def main(): fig = Figure() ax = fig.add_subplot(111) ax.set_xlabel("X axis") ax.set_ylabel("Y axis") ax.grid() # define the form layout layout = [[ sg.Text('Animated Matplotlib', size=(40, 1), justification='center', font='Helvetica 20') ], [sg.Canvas(size=(640, 480), key='canvas')], [ sg.Slider(range=(0, 10000), size=(60, 10), orientation='h', key='slider') ], [ sg.ReadButton('Exit', size=(10, 2), pad=((280, 0), 3), font='Helvetica 14') ]] # create the form and show it without the plot window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI' ).Layout(layout).Finalize() canvas_elem = window.FindElement('canvas') slider_elem = window.FindElement('slider') graph = FigureCanvasTkAgg(fig, master=canvas_elem.TKCanvas) canvas = canvas_elem.TKCanvas dpts = [randint(0, 10) for x in range(10000)] for i in range(len(dpts)): button, values = window.ReadNonBlocking() if button is 'Exit' or values is None: exit(69) slider_elem.Update(i) ax.cla() ax.grid() DATA_POINTS_PER_SCREEN = 40 ax.plot(range(DATA_POINTS_PER_SCREEN), dpts[i:i + DATA_POINTS_PER_SCREEN], color='purple') graph.draw() figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds figure_w, figure_h = int(figure_w), int(figure_h) photo = tk.PhotoImage(master=canvas, width=figure_w, height=figure_h) canvas.create_image(640 / 2, 480 / 2, image=photo) figure_canvas_agg = FigureCanvasAgg(fig) figure_canvas_agg.draw() # Unfortunately, there's no accessor for the pointer to the native renderer tkagg.blit(photo, figure_canvas_agg.get_renderer()._renderer, colormode=2)