Python PySimpleGUI.Cancel() Examples

The following are 14 code examples of PySimpleGUI.Cancel(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PySimpleGUI , or try the search function .
Example #1
Source File: Demo_Progress_Meters.py    From PySimpleGUI with GNU Lesser General Public License v3.0 9 votes vote down vote up
def custom_meter_example():
    # layout the form
    layout = [[sg.Text('A typical custom progress meter')],
              [sg.ProgressBar(1, orientation='h', size=(20,20), key='progress')],
              [sg.Cancel()]]

    # create the form`
    window = sg.Window('Custom Progress Meter').Layout(layout)
    progress_bar = window.FindElement('progress')
    # loop that would normally do something useful
    for i in range(10000):
        # check to see if the cancel button was clicked and exit loop if clicked
        event, values = window.Read(timeout=0)
        if event == 'Cancel' or event == None:
            break
        # update bar with loop value +1 so that bar eventually reaches the maximum
        progress_bar.UpdateBar(i+1, 10000)
    # done with loop... need to destroy the window as it's still open
    window.Close() 
Example #2
Source File: Demo_Machine_Learning.py    From PySimpleGUI with GNU Lesser General Public License v3.0 9 votes vote down vote up
def CustomMeter():
    # layout the form
    layout = [[sg.Text('A custom progress meter')],
              [sg.ProgressBar(1000, orientation='h', size=(20,20), key='progress')],
              [sg.Cancel()]]

    # create the form`
    window = sg.Window('Custom Progress Meter').Layout(layout)
    progress_bar = window.FindElement('progress')
    # loop that would normally do something useful
    for i in range(1000):
        # check to see if the cancel button was clicked and exit loop if clicked
        event, values = window.Read(timeout=0, timeout_key='timeout')
        if event == 'Cancel' or event == None:
            break
        # update bar with loop value +1 so that bar eventually reaches the maximum
        progress_bar.UpdateBar(i+1)
    # done with loop... need to destroy the window as it's still open
    window.CloseNonBlocking() 
Example #3
Source File: Demo_Machine_Learning.py    From PySimpleGUI with GNU Lesser General Public License v3.0 6 votes vote down vote up
def MachineLearningGUI():
    sg.SetOptions(text_justification='right')

    flags = [[sg.Checkbox('Normalize', size=(12, 1), default=True), sg.Checkbox('Verbose', size=(20, 1))],
    [sg.Checkbox('Cluster', size=(12, 1)), sg.Checkbox('Flush Output', size=(20, 1), default=True)],
    [sg.Checkbox('Write Results', size=(12, 1)), sg.Checkbox('Keep Intermediate Data', size=(20, 1))],
    [sg.Checkbox('Normalize', size=(12, 1), default=True), sg.Checkbox('Verbose', size=(20, 1))],
    [sg.Checkbox('Cluster', size=(12, 1)), sg.Checkbox('Flush Output', size=(20, 1), default=True)],
    [sg.Checkbox('Write Results', size=(12, 1)), sg.Checkbox('Keep Intermediate Data', size=(20, 1))],]

    loss_functions = [[sg.Radio('Cross-Entropy', 'loss', size=(12, 1)), sg.Radio('Logistic', 'loss', default=True, size=(12, 1))],
        [sg.Radio('Hinge', 'loss', size=(12, 1)), sg.Radio('Huber', 'loss', size=(12, 1))],
        [sg.Radio('Kullerback', 'loss', size=(12, 1)), sg.Radio('MAE(L1)', 'loss', size=(12, 1))],
        [sg.Radio('MSE(L2)', 'loss', size=(12, 1)), sg.Radio('MB(L0)', 'loss', size=(12, 1))],]

    command_line_parms = [[sg.Text('Passes', size=(8, 1)), sg.Spin(values=[i for i in range(1, 1000)], initial_value=20, size=(6, 1)),
         sg.Text('Steps', size=(8, 1), pad=((7,3))), sg.Spin(values=[i for i in range(1, 1000)], initial_value=20, size=(6, 1))],
        [sg.Text('ooa', size=(8, 1)), sg.In(default_text='6', size=(8, 1)), sg.Text('nn', size=(8, 1)),
         sg.In(default_text='10', size=(10, 1))],
        [sg.Text('q', size=(8, 1)), sg.In(default_text='ff', size=(8, 1)), sg.Text('ngram', size=(8, 1)),
         sg.In(default_text='5', size=(10, 1))],
        [sg.Text('l', size=(8, 1)), sg.In(default_text='0.4', size=(8, 1)), sg.Text('Layers', size=(8, 1)),
         sg.Drop(values=('BatchNorm', 'other'), auto_size_text=True)],]

    layout = [[sg.Frame('Command Line Parameteres', command_line_parms, title_color='green', font='Any 12')],
              [sg.Frame('Flags', flags, font='Any 12', title_color='blue')],
                [sg.Frame('Loss Functions',  loss_functions, font='Any 12', title_color='red')],
              [sg.Submit(), sg.Cancel()]]

    window = sg.Window('Machine Learning Front End', font=("Helvetica", 12)).Layout(layout)
    button, values = window.Read()
    sg.SetOptions(text_justification='left')

    print(button, values) 
Example #4
Source File: Demo_Progress_Meters.py    From PySimpleGUI with GNU Lesser General Public License v3.0 6 votes vote down vote up
def custom_meter_example():
    # layout the form
    layout = [[sg.Text('A typical custom progress meter')],
              [sg.ProgressBar(1, orientation='h', size=(20, 20), key='progress')],
              [sg.Cancel()]]

    # create the form`
    window = sg.Window('Custom Progress Meter', layout)
    progress_bar = window['progress']
    # loop that would normally do something useful
    for i in range(10000):
        # check to see if the cancel button was clicked and exit loop if clicked
        event, values = window.read(timeout=0)
        if event == 'Cancel' or event == None:
            break
        # update bar with loop value +1 so that bar eventually reaches the maximum
        progress_bar.update_bar(i+1, 10000)
    # done with loop... need to destroy the window as it's still open
    window.close() 
Example #5
Source File: Demo_MIDI_Player.py    From PySimpleGUI with GNU Lesser General Public License v3.0 6 votes vote down vote up
def PlayerChooseSongGUI(self):

        # ---------------------- DEFINION OF CHOOSE WHAT TO PLAY GUI ----------------------------

        helv = ("Helvetica", 15)
        layout = [[sg.Text('MIDI File Player', font=helv15, size=(20, 1), text_color='green')],
                  [sg.Text('File Selection', font=helv15, size=(20, 1))],
                  [sg.Text('Single File Playback', justification='right'),
                      sg.InputText(size=(65, 1), key='midifile'),
                      sg.FileBrowse(size=(10, 1), file_types=(("MIDI files", "*.mid"),))],
                  [sg.Text('Or Batch Play From This Folder', auto_size_text=False, justification='right'),
                      sg.InputText(size=(65, 1), key='folder'),
                      sg.FolderBrowse(size=(10, 1))],
                  [sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
                  [sg.Text('Choose MIDI Output Device', size=(22, 1)),
                   sg.Listbox(values=self.PortList, size=(30, len(self.PortList) + 1), default_values=(self.PortList[0],), key='device')],
                  [sg.Text('_' * 250, auto_size_text=False, size=(100, 1))],
                  [sg.SimpleButton('PLAY', size=(12, 2), button_color=('red', 'white'), font=helv15, bind_return_key=True),
                      sg.Text(' ' * 2, size=(4, 1)),
                      sg.Cancel(size=(8, 2), font=helv15)]]

        window = sg.Window('MIDI File Player', layout, auto_size_text=False, default_element_size=(30, 1), font=helv)
        self.Window = window
        return window.read() 
Example #6
Source File: Demo_Compare_Files.py    From PySimpleGUI with GNU Lesser General Public License v3.0 6 votes vote down vote up
def GetFilesToCompare():
    form_rows = [[sg.Text('Enter 2 files to comare')],
                 [sg.Text('File 1', size=(15, 1)),
                    sg.InputText(key='-file1-'), sg.FileBrowse()],
                 [sg.Text('File 2', size=(15, 1)), sg.InputText(key='-file2-'),
                  sg.FileBrowse(target='-file2-')],
                 [sg.Submit(), sg.Cancel()]]

    window = sg.Window('File Compare', form_rows)
    event, values = window.read()
    window.close()
    return event, values 
Example #7
Source File: Demo_Popup_Custom.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def PopupDropDown(title, text, values):
    window = sg.Window(title).Layout([[sg.Text(text)],
                                      [sg.DropDown(values, key='_DROP_')],
                                      [sg.OK(), sg.Cancel()]])
    event, values = window.Read()
    return None if event != 'OK' else values['_DROP_']


# -----------------------  Calling your PopupDropDown function ----------------------- 
Example #8
Source File: Demo_Compare_Files.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def GetFilesToCompare():
    form_rows = [[sg.Text('Enter 2 files to comare')],
                 [sg.Text('File 1', size=(15, 1)), sg.InputText(key='file1'), sg.FileBrowse()],
                 [sg.Text('File 2', size=(15, 1)), sg.InputText(key='file2'), sg.FileBrowse(target='file2')],
                 [sg.Submit(), sg.Cancel()]]

    window = sg.Window('File Compare')
    event, values = window.Layout(form_rows).Read()
    return event, values 
Example #9
Source File: Demo_Layout_Generation.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def layout3():
    # in terms of formatting, the layout to the RIGHT of the = sign looks like a 2-line GUI (ignore the layout +=
    layout =  [[sg.Button(i) for i in range(4)]]
    layout += [[sg.OK()]]               # this row is better than, but is the same as
    layout.append([sg.Cancel()])        # .. this row in that they both add a new ROW with a button on it

    window = sg.Window('Generated Layouts', layout)

    event, values = window.Read()

    print(event, values)
    window.Close() 
Example #10
Source File: Demo_Popup_Custom.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def PopupDropDown(title, text, values):
    window = sg.Window(title,
        [[sg.Text(text)],
        [sg.DropDown(values, key='-DROP-')],
        [sg.OK(), sg.Cancel()]
    ])
    event, values = window.read()
    return None if event != 'OK' else values['-DROP-']

# -----------------------  Calling your PopupDropDown function ----------------------- 
Example #11
Source File: Demo_Machine_Learning.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def MachineLearningGUI():
    sg.set_options(text_justification='right')

    flags = [[sg.CB('Normalize', size=(12, 1), default=True), sg.CB('Verbose', size=(20, 1))],
             [sg.CB('Cluster', size=(12, 1)), sg.CB(
                 'Flush Output', size=(20, 1), default=True)],
             [sg.CB('Write Results', size=(12, 1)), sg.CB(
                 'Keep Intermediate Data', size=(20, 1))],
             [sg.CB('Normalize', size=(12, 1), default=True),
              sg.CB('Verbose', size=(20, 1))],
             [sg.CB('Cluster', size=(12, 1)), sg.CB(
                 'Flush Output', size=(20, 1), default=True)],
             [sg.CB('Write Results', size=(12, 1)), sg.CB('Keep Intermediate Data', size=(20, 1))], ]

    loss_functions = [[sg.Rad('Cross-Entropy', 'loss', size=(12, 1)), sg.Rad('Logistic', 'loss', default=True, size=(12, 1))],
                      [sg.Rad('Hinge', 'loss', size=(12, 1)),
                       sg.Rad('Huber', 'loss', size=(12, 1))],
                      [sg.Rad('Kullerback', 'loss', size=(12, 1)),
                       sg.Rad('MAE(L1)', 'loss', size=(12, 1))],
                      [sg.Rad('MSE(L2)', 'loss', size=(12, 1)), sg.Rad('MB(L0)', 'loss', size=(12, 1))], ]

    command_line_parms = [[sg.Text('Passes', size=(8, 1)), sg.Spin(values=[i for i in range(1, 1000)], initial_value=20, size=(6, 1)),
                           sg.Text('Steps', size=(8, 1), pad=((7, 3))), sg.Spin(values=[i for i in range(1, 1000)], initial_value=20, size=(6, 1))],
                          [sg.Text('ooa', size=(8, 1)), sg.Input(default_text='6', size=(8, 1)), sg.Text('nn', size=(8, 1)),
                           sg.Input(default_text='10', size=(10, 1))],
                          [sg.Text('q', size=(8, 1)), sg.Input(default_text='ff', size=(8, 1)), sg.Text('ngram', size=(8, 1)),
                           sg.Input(default_text='5', size=(10, 1))],
                          [sg.Text('l', size=(8, 1)), sg.Input(default_text='0.4', size=(8, 1)), sg.Text('Layers', size=(8, 1)),
                           sg.Drop(values=('BatchNorm', 'other'))], ]

    layout = [[sg.Frame('Command Line Parameteres', command_line_parms, title_color='green', font='Any 12')],
              [sg.Frame('Flags', flags, font='Any 12', title_color='blue')],
              [sg.Frame('Loss Functions',  loss_functions,
                        font='Any 12', title_color='red')],
              [sg.Submit(), sg.Cancel()]]

    sg.set_options(text_justification='left')

    window = sg.Window('Machine Learning Front End',
                       layout, font=("Helvetica", 12))
    button, values = window.read()
    window.close()
    print(button, values) 
Example #12
Source File: Demo_Layout_Generation.py    From PySimpleGUI with GNU Lesser General Public License v3.0 5 votes vote down vote up
def layout3():
    # in terms of formatting, the layout to the RIGHT of the = sign looks like a 2-line GUI (ignore the layout +=
    layout = [[sg.Button(i) for i in range(4)]]
    # this row is better than, but is the same as
    layout += [[sg.OK()]]
    # .. this row in that they both add a new ROW with a button on it
    layout.append([sg.Cancel()])

    window = sg.Window('Generated Layouts', layout)

    event, values = window.read()

    print(event, values)
    window.close() 
Example #13
Source File: test_utilities.py    From pynvme with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def sg_show_hex_buffer(buf):
    import PySimpleGUI as sg
    layout = [ [sg.OK(), sg.Cancel()],
               [sg.Multiline(buf.dump(),
                             enter_submits=True,
                             disabled=True, 
                             size=(80, 25))]
             ]
    sg.Window(str(buf), layout, font=('monospace', 12)).Read() 
Example #14
Source File: Demo_Graph_Noise.py    From PySimpleGUI with GNU Lesser General Public License v3.0 4 votes vote down vote up
def main():
    global g_exit, g_response_time

    layout = [[sg.T('Enter width, height of graph')],
              [sg.In(size=(6, 1)), sg.In(size=(6, 1))],
              [sg.Ok(), sg.Cancel()]]

    window = sg.Window('Enter graph size').Layout(layout)
    b,v = window.Read()
    if b is None or b == 'Cancel':
        sys.exit(69)
    w, h = int(v[0]), int(v[1])
    CANVAS_SIZE = (w,h)

    # start ping measurement thread

    sg.ChangeLookAndFeel('Black')
    sg.SetOptions(element_padding=(0,0))

    layout = [  [sg.Button('Quit', button_color=('white','black'))],
               [sg.Graph(CANVAS_SIZE, (0,0), (SAMPLES,SAMPLE_MAX),background_color='black', key='graph')],]

    window = sg.Window('Canvas test', grab_anywhere=True, background_color='black', no_titlebar=False, use_default_focus=False).Layout(layout).Finalize()
    graph = window.FindElement('graph')

    prev_response_time = None
    i=0
    prev_x, prev_y = 0, 0
    graph_value = 250
    while True:
        # time.sleep(.2)
        event, values = window.Read(timeout=0)
        if event == 'Quit' or event is None:
            break
        graph_offset = random.randint(-10, 10)
        graph_value = graph_value + graph_offset
        if graph_value > SAMPLE_MAX:
            graph_value = SAMPLE_MAX
        if graph_value < 0:
            graph_value = 0
        new_x, new_y = i, graph_value
        prev_value = graph_value
        if i >= SAMPLES:
            graph.Move(-STEP_SIZE,0)
            prev_x = prev_x - STEP_SIZE
        graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white')
        # window.FindElement('graph').DrawPoint((new_x, new_y), color='red')
        prev_x, prev_y = new_x, new_y
        i += STEP_SIZE if i < SAMPLES else 0