コード例 #1
0
def HashGeneratorGUI():
    layout = [
        [sg.T('Password Hash Generator', size=(30, 1), font='Any 15')],
        [sg.T('Password'), sg.In(key='password')],
        [sg.T('SHA Hash'),
         sg.In('', size=(40, 1), key='hash')],
    ]

    window = sg.Window('SHA Generator',
                       auto_size_text=False,
                       default_element_size=(10, 1),
                       text_justification='r',
                       return_keyboard_events=True,
                       grab_anywhere=False).Layout(layout)

    while True:
        button, values = window.Read()
        if button is None:
            exit(69)

        password = values['password']
        try:
            password_utf = password.encode('utf-8')
            sha1hash = hashlib.sha1()
            sha1hash.update(password_utf)
            password_hash = sha1hash.hexdigest()
            window.FindElement('hash').Update(password_hash)
        except:
            pass
コード例 #2
0
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.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)
        button, values = window.ReadNonBlocking()
        if button == 'Quit' or values 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
コード例 #3
0
def openFileBox():
    layout = [[sg.T('Source Folder')], [sg.In()],
              [sg.FileBrowse(target=(-1, 0)),
               sg.OK()]]
    window = sg.Window("Choose File", layout)
    event, values = window.Read()
    if event == "OK":
        return values
    else:
        return 0
コード例 #4
0
def TestMenus():
    import PySimpleGUI as sg

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

    # ------ Menu Definition ------ #
    menu_def = [
        ['File', ['Open', 'Save', 'Properties']],
        [
            'Edit',
            ['Paste', [
                'Special',
                'Normal',
            ], 'Undo'],
        ],
        ['Help', 'About...'],
    ]

    # ------ GUI Defintion ------ #
    layout = [[sg.Menu(menu_def, tearoff=True)], [sg.Output(size=(60, 20))],
              [sg.In('Test', key='input', do_not_clear=True)]]

    window = sg.Window("Windows-like program",
                       default_element_size=(12, 1),
                       auto_size_text=False,
                       auto_size_buttons=False,
                       default_button_element_size=(12, 1)).Layout(layout)

    # ------ Loop & Process button menu choices ------ #
    while True:
        button, values = window.Read()
        if button is None or button == 'Exit':
            return
        print('Button = ', button)
        # ------ Process menu choices ------ #
        if button == 'About...':
            sg.Popup('About this program', 'Version 1.0',
                     'PySimpleGUI rocks...')
        elif button == 'Open':
            filename = sg.PopupGetFile('file to open', no_window=True)
            print(filename)
        elif button == 'Properties':
            SecondForm()
コード例 #5
0
def DownloadSubtitlesGUI():
    sg.ChangeLookAndFeel('Dark')

    combobox = sg.InputCombo(values=['',], size=(10,1), key='lang')
    layout =  [
                [sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))],
                [sg.T('YouTube Link'),sg.In(default_text='',size=(60,1), key='link', do_not_clear=True) ],
                [sg.Output(size=(90,20), font='Courier 12')],
                [sg.ReadButton('Get List')],
                [sg.T('Language Code'), combobox, sg.ReadButton('Download')],
                [sg.Button('Exit', button_color=('white', 'firebrick3'))]
                ]

    window = sg.Window('Subtitle Grabber launcher', text_justification='r', default_element_size=(15,1), font=('Any 14')).Layout(layout)

    # ---===--- Loop taking in user input and using it to query HowDoI --- #
    while True:
        (button, gui) = window.Read()
        if button in ('EXIT', None):
            break           # exit button clicked
        link = gui['link']
        if button is 'Get List':
            print('Getting list of subtitles....')
            window.Refresh()
            command = [f'C:/Python/PycharmProjects/GooeyGUI/youtube-dl --list-subs {link}',]
            output = ExecuteCommandSubprocess(command, wait=True, quiet=True)
            lang_list = [o[:5].rstrip() for o in output.split('\n') if 'vtt' in o]
            lang_list = sorted(lang_list)
            combobox.Update(values=lang_list)
            print('Done')

        elif button is 'Download':
            lang = gui['lang']
            if lang is '':
                lang = 'en'
            print(f'Downloading subtitle for {lang}...')
            window.Refresh()
            command = (f'C:/Python/PycharmProjects/GooeyGUI/youtube-dl --sub-lang {lang} --write-sub {link}',)
            ExecuteCommandSubprocess(command, wait=True)
            print('Done')
コード例 #6
0
ファイル: Demo_Tabs.py プロジェクト: ShowerXu/PySimpleGUI
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

tab1_layout =  [[sg.T('This is inside tab 1')]]

tab2_layout = [[sg.T('This is inside tab 2')],
               [sg.In(key='in')]]

layout = [[sg.TabGroup([[sg.Tab('Tab 1', tab1_layout), sg.Tab('Tab 2', tab2_layout)]])],
          [sg.RButton('Read')]]

window = sg.Window('My window with tabs', default_element_size=(12,1)).Layout(layout)

while True:
    b, v = window.Read()
    print(b,v)
    if b is None:           # always,  always give a way out!
        break
コード例 #7
0
def TableSimulation():
    """
    Display data in a table format
    """
    sg.SetOptions(element_padding=(0, 0))
    sg.PopupNoWait('Give it a few seconds to load please...', auto_close=True)

    menu_def = [
        ['File', ['Open', 'Save', 'Exit']],
        [
            'Edit',
            ['Paste', [
                'Special',
                'Normal',
            ], 'Undo'],
        ],
        ['Help', 'About...'],
    ]

    columm_layout = [[]]

    MAX_ROWS = 60
    MAX_COL = 10
    for i in range(MAX_ROWS):
        inputs = [sg.T('{}'.format(i), size=(4, 1), justification='right')] + [
            sg.In(size=(10, 1),
                  pad=(1, 1),
                  justification='right',
                  key=(i, j),
                  do_not_clear=True) for j in range(MAX_COL)
        ]
        columm_layout.append(inputs)

    layout = [
        [sg.Menu(menu_def)],
        [sg.T('Table Using Combos and Input Elements', font='Any 18')],
        [
            sg.
            T('Type in a row, column and value. The form will update the values in realtime as you type'
              ),
            sg.In(key='inputrow',
                  justification='right',
                  size=(8, 1),
                  pad=(1, 1),
                  do_not_clear=True),
            sg.In(key='inputcol',
                  size=(8, 1),
                  pad=(1, 1),
                  justification='right',
                  do_not_clear=True),
            sg.In(key='value',
                  size=(8, 1),
                  pad=(1, 1),
                  justification='right',
                  do_not_clear=True)
        ], [sg.Column(columm_layout, size=(800, 600), scrollable=True)]
    ]

    window = sg.Window('Table',
                       return_keyboard_events=True,
                       grab_anywhere=False).Layout(layout)

    while True:
        button, values = window.Read()
        # --- Process buttons --- #
        if button is None or button == 'Exit':
            break
        elif button == 'About...':
            sg.Popup('Demo of table capabilities')
        elif button == 'Open':
            filename = sg.PopupGetFile('filename to open',
                                       no_window=True,
                                       file_types=(("CSV Files", "*.csv"), ))
            # --- populate table with file contents --- #
            if filename is not None:
                with open(filename, "r") as infile:
                    reader = csv.reader(infile)
                    try:
                        data = list(
                            reader)  # read everything else into a list of rows
                    except:
                        sg.PopupError('Error reading file')
                        continue
                # clear the table
                [
                    window.FindElement((i, j)).Update('')
                    for j in range(MAX_COL) for i in range(MAX_ROWS)
                ]

                for i, row in enumerate(data):
                    for j, item in enumerate(row):
                        location = (i, j)
                        try:  # try the best we can at reading and filling the table
                            target_element = window.FindElement(location)
                            new_value = item
                            if target_element is not None and new_value != '':
                                target_element.Update(new_value)
                        except:
                            pass

        # if a valid table location entered, change that location's value
        try:
            location = (int(values['inputrow']), int(values['inputcol']))
            target_element = window.FindElement(location)
            new_value = values['value']
            if target_element is not None and new_value != '':
                target_element.Update(new_value)
        except:
            pass
コード例 #8
0
sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0, 0))

layout = [[
    sg.T('User:'******'User 1', 'User 2'), size=(20, 1)),
    sg.T('0', size=(8, 1))
],
          [
              sg.T('Customer:', pad=((3, 0), 0)),
              sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)),
              sg.T('1', size=(8, 1))
          ],
          [
              sg.T('Notes:', pad=((3, 0), 0)),
              sg.In(size=(44, 1), background_color='white', text_color='black')
          ],
          [
              sg.ReadButton('Start',
                            button_color=('white', 'black'),
                            key='Start'),
              sg.ReadButton('Stop',
                            button_color=('white', 'black'),
                            key='Stop'),
              sg.ReadButton('Reset',
                            button_color=('white', 'firebrick3'),
                            key='Reset'),
              sg.ReadButton('Submit',
                            button_color=('white', 'springgreen4'),
                            key='Submit')
          ]]
コード例 #9
0
for i in range(10000):
    if i % 5 == 0:
        sg.OneLineProgressMeter('My 1-line progress meter', i + 1, 10000,
                                'single')

# Display a progress meter. Allow user to break out of loop using cancel button
for i in range(10000):
    if not sg.OneLineProgressMeter('My 1-line progress meter', i + 1, 10000,
                                   'single'):
        break

layout = [[sg.T('One-Line Progress Meter Demo', font=('Any 18'))],
          [
              sg.T('Outer Loop Count', size=(15, 1), justification='r'),
              sg.In(default_text='100',
                    size=(5, 1),
                    key='CountOuter',
                    do_not_clear=True),
              sg.T('Delay'),
              sg.In(default_text='10',
                    key='TimeOuter',
                    size=(5, 1),
                    do_not_clear=True),
              sg.T('ms')
          ],
          [
              sg.T('Inner Loop Count', size=(15, 1), justification='r'),
              sg.In(default_text='100',
                    size=(5, 1),
                    key='CountInner',
                    do_not_clear=True),
              sg.T('Delay'),
コード例 #10
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

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

layout = [[
    sg.T('Notes:', pad=((3, 0), 0)),
    sg.In(size=(44, 1),
          background_color='white',
          text_color='black',
          key='notes')
],
          [
              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')
コード例 #11
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

"""
    Demo of how to combine elements into your own custom element
"""

sg.SetOptions(element_padding=(0,0))
# sg.ChangeLookAndFeel('Dark')
# --- Define our "Big-Button-Spinner" compound element. Has 2 buttons and an input field --- #
NewSpinner =  [sg.ReadButton('-', size=(2,1), font='Any 12'),
               sg.In('0', size=(2,1), font='Any 14', justification='r', key='spin'),
               sg.ReadButton('+', size=(2,1), font='Any 12')]
# --- Define Window --- #
layout = [
          [sg.Text('Spinner simulation')],
            NewSpinner,
            [sg.T('')],
          [sg.Ok()]
         ]

window = sg.Window('Spinner simulation').Layout(layout)

# --- Event Loop --- #
counter = 0
while True:
    button, value = window.Read()
コード例 #12
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

sg.ChangeLookAndFeel('GreenTan')
tab2_layout = [[sg.T('This is inside tab 2')],
               [sg.T('Tabs can be anywhere now!')]]

tab1_layout = [[sg.T('Type something here and click button'), sg.In(key='in')]]

tab3_layout = [[sg.T('This is inside tab 3')]]
tab4_layout = [[sg.T('This is inside tab 4')]]

tab_layout = [[sg.T('This is inside of a tab')]]
tab_group = sg.TabGroup(
    [[sg.Tab('Tab 7', tab_layout),
      sg.Tab('Tab 8', tab_layout)]])

tab5_layout = [[sg.T('Watch this window')], [sg.Output(size=(40, 5))]]
tab6_layout = [[sg.T('This is inside tab 6')],
               [sg.T('How about a second row of stuff in tab 6?'), tab_group]]

layout = [
    [sg.T('My Window!')],
    [
        sg.Frame('A Frame',
                 layout=[[
                     sg.TabGroup([[
コード例 #13
0
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)
コード例 #14
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg
import sys
'''
Quickly add a GUI to your script!

This simple script shows a 1-line-GUI addition to a typical Python command line script.

Previously this script accepted 1 parameter on the command line.  When executed, that
parameter is read into the variable fname.

The 1-line-GUI shows a form that allows the user to browse to find the filename. The GUI
stores the result in the variable fname, just like the command line parsing did.
'''

if len(sys.argv) == 1:
    button, (fname, ) = sg.Window('My Script').LayoutAndRead(
        [[sg.T('Document to open')], [sg.In(), sg.FileBrowse()],
         [sg.Open(), sg.Cancel()]])
else:
    fname = sys.argv[1]

if not fname:
    sg.Popup("Cancel", "No filename supplied")
    raise SystemExit("Cancelling: no filename supplied")
コード例 #15
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

layout = [[sg.T('Calendar Test')], [sg.In('', size=(20, 1), key='input')],
          [sg.CalendarButton('Choose Date', target='input', key='date')],
          [sg.Ok(key=1)]]

window = sg.Window('Calendar', grab_anywhere=False).Layout(layout)
b, v = window.Read()
sg.Popup(v['input'])
コード例 #16
0
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

"""
Turn off padding in order to get a really tight looking layout.
"""

sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0, 0))
layout = [[sg.T('User:'******'User 1', 'User 2'), size=(20, 1)),
           sg.T('0', size=(8, 1))],
          [sg.T('Customer:', pad=((3, 0), 0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)),
           sg.T('1', size=(8, 1))],
          [sg.T('Notes:', pad=((3, 0), 0)), sg.In(size=(44, 1), background_color='white', text_color='black')],
          [sg.ReadButton('Start', button_color=('white', 'black')),
           sg.ReadButton('Stop', button_color=('gray50', 'black')),
           sg.ReadButton('Reset', button_color=('white', '#9B0023')),
           sg.ReadButton('Submit', button_color=('gray60', 'springgreen4')),
           sg.Button('Exit', button_color=('white', '#00406B'))]]

window = sg.Window("Time Tracker", default_element_size=(12, 1), text_justification='r', auto_size_text=False,
                   auto_size_buttons=False, no_titlebar=True,
                   default_button_element_size=(12, 1))

window.Layout(layout)

while True:
    button, values = window.Read()
    if button is None or button == 'Exit':