def SourceDestFolders():
    with g.FlexForm('Demo Source / Destination Folders',
                    auto_size_text=True) as form:
        form_rows = [[g.Text('Enter the Source and Destination folders')],
                     [g.Text('Choose Source and Destination Folders')],
                     [
                         g.Text('Source Folder',
                                size=(15, 1),
                                auto_size_text=False),
                         g.InputText('Source'),
                         g.FolderBrowse()
                     ],
                     [
                         g.Text('Destination Folder',
                                size=(15, 1),
                                auto_size_text=False),
                         g.InputText('Dest'),
                         g.FolderBrowse()
                     ], [g.Submit(), g.Cancel()]]

        (button, (source, dest)) = form.LayoutAndShow(form_rows)
    if button == 'Submit':
        # do something useful with the inputs
        g.MsgBox('Submitted', 'The user entered source folder', source,
                 'And destination folder', dest)
    else:
        g.MsgBoxError('Cancelled', 'User Cancelled')
예제 #2
0
def SourceDestFolders():
    with sg.FlexForm('Demo Source / Destination Folders') as form:
        form_rows = ([sg.Text('Enter the Source and Destination folders')],
                     [sg.Text('Source Folder', size=(15, 1), justification='right'), sg.InputText('Source', key='source'), sg.FolderBrowse()],
                     [sg.Text('Destination Folder', size=(15, 1), justification='right'), sg.InputText('Dest', key='dest'), sg.FolderBrowse()],
                     [sg.Submit(), sg.Cancel()])

        button, values = form.LayoutAndRead(form_rows)
    if button is 'Submit':
        sg.MsgBox('Submitted', values, 'The user entered source:', values['source'], 'Destination folder:', values['dest'], 'Using button', button)
    else:
        sg.MsgBoxError('Cancelled', 'User Cancelled')
예제 #3
0
def HashManuallyBuiltGUINonContext():
    # -------  Form design ------- #
    form = SG.FlexForm('SHA-1 & 256 Hash', auto_size_text=True)
    form_rows = [[SG.Text('SHA-1 and SHA-256 Hashes for the file')],
                 [SG.InputText(), SG.FileBrowse()], [SG.Submit(),
                                                     SG.Cancel()]]
    (button, (source_filename, )) = form.LayoutAndShow(form_rows)

    if button == 'Submit':
        if source_filename != '':
            hash_sha1 = compute_sha1_hash_for_file(source_filename).upper()
            hash_sha256 = compute_sha256_hash_for_file(source_filename).upper()
            SG.MsgBox('Display A Hash in PySimpleGUI',
                      'The SHA-1 Hash for the file\n',
                      source_filename,
                      hash_sha1,
                      'SHA-256 is',
                      hash_sha256,
                      line_width=75)
        else:
            SG.MsgBoxError('Display A Hash in PySimpleGUI', 'Illegal filename')
    else:
        SG.MsgBoxError('Display A Hash in PySimpleGUI', '* Cancelled *')
예제 #4
0
def main():
    button, (f1, f2) = GetFilesToCompare()
    if any((button != 'Submit', f1 =='', f2 == '')):
        sg.MsgBoxError('Operation cancelled')
        exit(69)

    with open(f1, 'rb') as file1:
        with open(f2, 'rb') as file2:
            a = file1.read()
            b = file2.read()

        for i, x in enumerate(a):
            if x != b[i]:
                sg.MsgBox('Compare results for files', f1, f2, '**** Mismatch at offset {} ****'.format(i))
                break
        else:
            if len(a) == len(b):
                sg.MsgBox('**** The files are IDENTICAL ****')
import PySimpleGUI as sg

sg.MsgBox('Title', 'My first message... Is the length the same?')
rc, number = sg.GetTextBox('Title goes here', 'Enter a number')
if not rc:
    sg.MsgBoxError('You have cancelled')
    exit(0)

msg = '\n'.join([f'{i}' for i in range(0,int(number))])

sg.ScrolledTextBox(msg, height=10)
예제 #6
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!':
        g.MsgBoxCancel('Cancelled...\nAutoclose in 2 sec...',
                       auto_close=True,
                       auto_close_duration=2)
        exit(69)
    if values['device']:
        midi_port = values['device'][0]
    else:
        g.MsgBoxCancel('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:
        g.MsgBoxError('*** Error - No MIDI files specified ***')
        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))
            g.MsgBoxError('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(filelist[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.
                    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
    exit(69)