Exemplo n.º 1
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

# Here, have some windows on me....
[sg.PopupNoWait(location=(10 * x, 0)) for x in range(10)]

print(sg.PopupYesNo('Yes No'))

print(sg.PopupGetText('Get text', location=(1000, 200)))
print(sg.PopupGetFile('Get file'))
print(sg.PopupGetFolder('Get folder'))

sg.Popup('Simple popup')

sg.PopupNonBlocking('Non Blocking', location=(500, 500))
sg.PopupNoTitlebar('No titlebar')
sg.PopupNoBorder('No border')
sg.PopupNoFrame('No frame')
# sg.PopupNoButtons('No Buttons')        # don't mix with non-blocking... disaster ahead...
sg.PopupCancel('Cancel')
sg.PopupOKCancel('OK Cancel')
sg.PopupAutoClose('Autoclose')
        if f_sha in shatab:
            # uncomment next line to remove duplicate files
            # os.remove(fname)
            dup_count += 1
            # sg.Print(f'Duplicate file - {f}')    # cannot current use sg.Print with Progress Meter
            continue
        shatab.append(f_sha)

    msg = '{} Files processed\n {} Duplicates found'.format(
        total_files, dup_count)
    sg.Popup('Duplicate Finder Ended', msg)


# ====____====____==== Pseudo-MAIN program ====____====____==== #
# This is our main-alike piece of code                          #
#   + Starts up the GUI                                         #
#   + Gets values from GUI                                      #
#   + Runs DeDupe_folder based on GUI inputs                    #
# ------------------------------------------------------------- #
if __name__ == '__main__':

    source_folder = None
    rc, source_folder = sg.PopupGetFolder(
        'Duplicate Finder - Count number of duplicate files',
        'Enter path to folder you wish to find duplicates in')
    if rc is True and source_folder is not None:
        FindDuplicatesFilesInFolder(source_folder)
    else:
        sg.PopupCancel('Cancelling', '*** Cancelling ***')
    exit(0)
Exemplo n.º 3
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg
import os
from sys import exit as exit

# Simple Image Browser based on PySimpleGUI

# Get the folder containing the images from the user
folder = sg.PopupGetFolder('Image folder to open')
if folder is None:
    sg.PopupCancel('Cancelling')
    exit(0)

# get list of PNG files in folder
png_files = [folder + '\\' + f for f in os.listdir(folder) if '.png' in f]
filenames_only = [f for f in os.listdir(folder) if '.png' in f]

if len(png_files) == 0:
    sg.Popup('No PNG images in folder')
    exit(0)


# define menu layout
menu = [['File', ['Open Folder', 'Exit']], ['Help', ['About',]]]

# define layout, show and read the window
col = [[sg.Text(png_files[0], size=(80, 3), key='filename')],
Exemplo n.º 4
0
def main():
    def GetCurrentTime():
        '''
        Get the current system time in milliseconds
        :return: milliseconds
        '''
        return int(round(time.time() * 1000))

    pback = PlayerGUI()

    button, values = pback.PlayerChooseSongGUI()
    if button != 'PLAY':
        sg.PopupCancel('Cancelled...\nAutoclose in 2 sec...',
                       auto_close=True,
                       auto_close_duration=2)
        sys.exit(69)
    if values['device']:
        midi_port = values['device'][0]
    else:
        sg.PopupCancel('No devices found\nAutoclose in 2 sec...',
                       auto_close=True,
                       auto_close_duration=2)

    batch_folder = values['folder']
    midi_filename = values['midifile']
    # ------ Build list of files to play --------------------------------------------------------- #
    if batch_folder:
        filelist = os.listdir(batch_folder)
        filelist = [
            batch_folder + '/' + f for f in filelist
            if f.endswith(('.mid', '.MID'))
        ]
        filetitles = [os.path.basename(f) for f in filelist]
    elif midi_filename:  # an individual filename
        filelist = [
            midi_filename,
        ]
        filetitles = [
            os.path.basename(midi_filename),
        ]
    else:
        sg.PopupError('*** Error - No MIDI files specified ***')
        sys.exit(666)

    # ------ LOOP THROUGH MULTIPLE FILES --------------------------------------------------------- #
    pback.PlayerPlaybackGUIStart(
        NumFiles=len(filelist) if len(filelist) <= 10 else 10)
    port = None
    # Loop through the files in the filelist
    for now_playing_number, current_midi_filename in enumerate(filelist):
        display_string = 'Playing Local File...\n{} of {}\n{}'.format(
            now_playing_number + 1, len(filelist), current_midi_filename)
        midi_title = filetitles[now_playing_number]
        # --------------------------------- REFRESH THE GUI ----------------------------------------- #
        pback.PlayerPlaybackGUIUpdate(display_string)

        # ---===--- Output Filename is .MID --- #
        midi_filename = current_midi_filename

        # --------------------------------- MIDI - STARTS HERE ----------------------------------------- #
        if not port:  # if the midi output port not opened yet, then open it
            port = mido.open_output(midi_port if midi_port else None)

        try:
            mid = mido.MidiFile(filename=midi_filename)
        except:
            print(
                '****** Exception trying to play MidiFile filename = {}***************'
                .format(midi_filename))
            sg.PopupError('Exception trying to play MIDI file:', midi_filename,
                          'Skipping file')
            continue

        # Build list of data contained in MIDI File using only track 0
        midi_length_in_seconds = mid.length
        display_file_list = '>> ' + '\n'.join([
            f for i, f in enumerate(filetitles[now_playing_number:]) if i < 10
        ])
        paused = cancelled = next_file = False
        ######################### Loop through MIDI Messages ###########################
        while (True):
            start_playback_time = GetCurrentTime()
            port.reset()

            for midi_msg_number, msg in enumerate(mid.play()):
                #################### GUI - read values ##################
                if not midi_msg_number % 4:  # update the GUI every 4 MIDI messages
                    t = (GetCurrentTime() - start_playback_time) // 1000
                    display_midi_len = '{:02d}:{:02d}'.format(
                        *divmod(int(midi_length_in_seconds), 60))
                    display_string = 'Now Playing {} of {}\n{}\n              {:02d}:{:02d} of {}\nPlaylist:'.\
                        format(now_playing_number+1, len(filelist), midi_title, *divmod(t, 60), display_midi_len)
                    # display list of next 10 files to be played.
                    pback.SliderElem.Update(t,
                                            range=(1, midi_length_in_seconds))
                    rc = pback.PlayerPlaybackGUIUpdate(display_string + '\n' +
                                                       display_file_list)
                else:  # fake rest of code as if GUI did nothing
                    rc = PLAYER_COMMAND_NONE
                if paused:
                    rc = PLAYER_COMMAND_NONE
                    while rc == PLAYER_COMMAND_NONE:  # TIGHT-ASS loop waiting on a GUI command
                        rc = pback.PlayerPlaybackGUIUpdate(display_string)
                        time.sleep(.25)

                ####################################### MIDI send data ##################################
                port.send(msg)

                # -------  Execute GUI Commands  after sending MIDI data ------- #
                if rc == PLAYER_COMMAND_EXIT:
                    cancelled = True
                    break
                elif rc == PLAYER_COMMAND_PAUSE:
                    paused = not paused
                    port.reset()
                elif rc == PLAYER_COMMAND_NEXT:
                    next_file = True
                    break
                elif rc == PLAYER_COMMAND_RESTART_SONG:
                    break

            if cancelled or next_file:
                break
        #------- DONE playing the song   ------- #
        port.reset()  # reset the midi port when done with the song

        if cancelled:
            break