Beispiel #1
0
def main():
    # button, (filename,) = OneLineGUI()
    # DebugTe`st()
    sg.MsgBox('Hello')
    ChatBot()
    Everything()
    SourceDestFolders()
    NonBlockingPeriodicUpdateForm_ContextManager()
    NonBlockingPeriodicUpdateForm()
    ChatBot()
    Everything()
    sg.ChangeLookAndFeel('GreenTan')
    Everything()
    # ChatBot()

    SourceDestFolders()
    MachineLearningGUI()
    NonBlockingPeriodicUpdateForm()
    ProgressMeter()
    DebugTest()
    sg.ChangeLookAndFeel('Purple')
    Everything_NoContextManager()
    NonBlockingPeriodicUpdateForm_ContextManager()

    sg.MsgBox('Done with all recipes')
def FindDuplicatesFilesInFolder(path):
    shatab = []
    total = 0
    small_count, dup_count, error_count = 0, 0, 0
    pngdir = path
    if not os.path.exists(path):
        sg.MsgBox('Duplicate Finder', '** Folder doesn\'t exist***', path)
        return
    pngfiles = os.listdir(pngdir)
    total_files = len(pngfiles)
    for idx, f in enumerate(pngfiles):
        if not sg.EasyProgressMeter('Counting Duplicates', idx + 1,
                                    total_files, 'Counting Duplicate Files'):
            break
        total += 1
        fname = os.path.join(pngdir, f)
        if os.path.isdir(fname):
            continue
        x = open(fname, "rb").read()

        m = hashlib.sha256()
        m.update(x)
        f_sha = m.digest()
        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 = f'{total} Files processed\n'\
          f'{dup_count} Duplicates found\n'
    sg.MsgBox('Duplicate Finder Ended', msg)
Beispiel #3
0
def HashMostCompactGUI():
    # -------  INPUT GUI portion  ------- #

    rc, source_filename = SG.GetFileBox(
        'Display A Hash Using PySimpleGUI',
        'Display a Hash code for file of your choice')

    # -------  OUTPUT GUI results portion  ------- #
    if rc == True:
        hash = compute_sha1_hash_for_file(source_filename)
        SG.MsgBox('Display Hash - Compact GUI',
                  'The SHA-1 Hash for the file\n', source_filename, hash)
    else:
        SG.MsgBox('Display Hash - Compact GUI', '* Cancelled *')
Beispiel #4
0
def Everything_NoContextManager():
    form = sg.FlexForm('Everything bagel', default_element_size=(40, 1))
    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')],
        [sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)],
        [sg.Radio('My first Radio!     ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
        [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, 3)),
         sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
        [sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
         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),
         sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
         sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
        [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'), sg.FolderBrowse()],
        [sg.Submit(), sg.Cancel()]
         ]

    button, values = form.LayoutAndRead(layout)
    del(form)

    sg.MsgBox('Title', 'The results of the form.', 'The button clicked was "{}"'.format(button), 'The values are', values)
def main():

    Everything()
    ChatBot()

    sg.ChangeLookAndFeel('BrownBlue')
    SourceDestFolders()
    sg.ChangeLookAndFeel('BlueMono')
    Everything()
    sg.ChangeLookAndFeel('BluePurple')
    Everything()
    sg.ChangeLookAndFeel('LightGreen')
    Everything()
    sg.ChangeLookAndFeel('GreenMono')
    MachineLearningGUI()
    sg.ChangeLookAndFeel('TealMono')
    NonBlockingPeriodicUpdateForm()
    ChatBot()
    ProgressMeter()
    sg.ChangeLookAndFeel('Purple')
    Everything_NoContextManager()
    NonBlockingPeriodicUpdateForm_ContextManager()

    sg.MsgBox('Done with all recipes')
    DebugTest()
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')
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 ****')
def Everything():
    with g.FlexForm('Everything bagel',
                    auto_size_text=True,
                    default_element_size=(40, 1)) as form:
        layout = [
            [
                g.Text('All graphic widgets in one form!',
                       size=(30, 1),
                       font=("Helvetica", 25),
                       text_color='blue')
            ], [g.Text('Here is some text.... and a place to enter text')],
            [g.InputText()],
            [
                g.Checkbox('My first checkbox!'),
                g.Checkbox('My second checkbox!', default=True)
            ],
            [
                g.Radio('My first Radio!', "RADIO1", default=True),
                g.Radio('My second Radio!', "RADIO1")
            ],
            [
                g.Multiline(
                    default_text=
                    'This is the default Text should you decide not to type anything',
                    scale=(2, 10))
            ], [g.InputCombo(['choice 1', 'choice 2'], size=(20, 3))],
            [g.Text('_' * 100, size=(70, 1))],
            [g.Text('Choose Source and Destination Folders', size=(35, 1))],
            [
                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.SimpleButton('Your very own button',
                               button_color=('white', 'green'))
            ], [g.Submit(), g.Cancel()]
        ]

        (button, (values)) = form.LayoutAndShow(layout)

    g.MsgBox('Title',
             'Typical message box',
             'The results of the form are a lot of data!  Get ready... ',
             'The button clicked was "{}"'.format(button),
             'The values are',
             values,
             auto_close=True)
Beispiel #9
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')
Beispiel #10
0
def main():

    # sg.MsgBox('Changing look and feel.', 'Done by calling SetOptions')
    SourceDestFolders()

    sg.SetOptions(background_color='#9FB8AD',
                  text_element_background_color='#9FB8AD',
                  element_background_color='#9FB8AD',
                  scrollbar_color=None,
                  input_elements_background_color='#F7F3EC',
                  button_color=('white', '#475841'),
                  border_width=0,
                  slider_border_width=0,
                  progress_meter_border_depth=0)

    MachineLearningGUI()

    Everything_NoContextManager()

    # sg.SetOptions(background_color='#B89FB6', text_element_background_color='#B89FB6',  element_background_color='#B89FB6',   button_color=('white','#7E6C92'), text_color='#3F403F',border_width=0, slider_border_width=0, progress_meter_border_depth=0)

    sg.SetOptions(background_color='#A5CADD',
                  input_elements_background_color='#E0F5FF',
                  text_element_background_color='#A5CADD',
                  element_background_color='#A5CADD',
                  button_color=('white', '#303952'),
                  text_color='#822E45',
                  border_width=0,
                  progress_meter_color=('#3D8255', 'white'),
                  slider_border_width=0,
                  progress_meter_border_depth=0)

    Everything()

    ProgressMeter()

    # Set system-wide options that will affect all future forms

    NonBlockingPeriodicUpdateForm_ContextManager()

    NonBlockingPeriodicUpdateForm()

    ChatBot()

    DebugTest()

    sg.MsgBox('Done with all recipes')
def main():

    # Green & tan color scheme
    colors1 = {
        'BACKGROUND': '#9FB8AD',
        'TEXT': sg.COLOR_SYSTEM_DEFAULT,
        'INPUT': '#F7F3EC',
        'BUTTON': ('white', '#475841'),
        'PROGRESS': sg.DEFAULT_PROGRESS_BAR_COLOR
    }
    # light green with tan
    colors2 = {
        'BACKGROUND': '#B7CECE',
        'TEXT': 'black',
        'INPUT': '#FDFFF7',
        'BUTTON': ('white', '#658268'),
        'PROGRESS': ('#247BA0', '#F8FAF0')
    }
    # blue with light blue color scheme
    colors3 = {
        'BACKGROUND': '#A5CADD',
        'TEXT': '#6E266E',
        'INPUT': '#E0F5FF',
        'BUTTON': ('white', '#303952'),
        'PROGRESS': sg.DEFAULT_PROGRESS_BAR_COLOR
    }

    ChatBot()
    Everything()

    SourceDestFolders()
    ChangeLookAndFeel(colors2)
    ProgressMeter()
    ChangeLookAndFeel(colors3)
    Everything()
    ChangeLookAndFeel(colors2)
    MachineLearningGUI()
    Everything_NoContextManager()
    NonBlockingPeriodicUpdateForm_ContextManager()
    NonBlockingPeriodicUpdateForm()
    DebugTest()

    sg.MsgBox('Done with all recipes')
Beispiel #12
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 *')
def ShowMainForm():

    listbox_values = ('Text', 'InputText', 'Checkbox', 'Radio Button',
                      'Listbox', 'Slider')

    column2 = [[sg.Output(size=(50, 20))],
               [sg.ReadFormButton('Show Element'),
                sg.SimpleButton('Exit')]]

    column1 = [[
        sg.Listbox(values=listbox_values,
                   size=(20, len(listbox_values)),
                   key='listbox')
    ], [sg.Text('', size=(10, 15))]]

    layout = [[sg.Column(column1), sg.Column(column2)]]

    form = sg.FlexForm('Element Browser')
    form.Layout(layout)
    while True:
        button, values = form.Read()
        if button is None or button == 'Exit':
            break
        sg.MsgBox(button, values['listbox'][0])
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)
Beispiel #15
0
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.FlexForm('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.MsgBox("Cancel", "No filename supplied")
    raise SystemExit("Cancelling: no filename supplied")
Beispiel #16
0
    [
        sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'),
                   size=(30, 3)),
        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),
        sg.Slider(range=(1, 100),
                  orientation='v',
                  size=(5, 20),
                  default_value=10),
        sg.Column(column1, background_color='#d3dfda')
    ], [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'),
        sg.FolderBrowse()
    ], [sg.Submit(), sg.Cancel()]
]

button, values = form.LayoutAndRead(layout)
sg.MsgBox(button, values)

# Everything_NoContextManager()
Beispiel #17
0
def main():
    RemoteControlExample()
    StatusOutputExample()
    sg.MsgBox('End of non-blocking demonstration')
Beispiel #18
0
import PySimpleGUI as sg

# THIS FILE REQIRES THE LATEST PySimpleGUI.py FILE
# IT WILL NOT WORK WITH CURRENT PIP RELEASE (2.7)
#
# If you want to use the return values as Dictionary feature, you need to download the PySimpleGUI.py file
# from GitHub and then place it in your project's folder.  This SHOULD cause it to use this downloaded version
# instead of the pip installed one, if you've pip installed it.  You can always uninstall the pip one :-)


# This design pattern shows how to use return values in dictionary form

form = sg.FlexForm('Simple data entry form')  # begin with a blank form

layout = [
          [sg.Text('Please enter your Name, Address, Phone')],
          [sg.Text('Name', size=(15, 1)), sg.InputText('1')],
          [sg.Text('Address', size=(15, 1)), sg.InputText('2', key='address')],
          [sg.Text('Phone', size=(15, 1)), sg.InputText('3', key='phone')],
          [sg.Submit(), sg.Cancel()]
         ]

button, values = form.LayoutAndRead(layout)

sg.MsgBox(button, values, values[0], values['address'], values['phone'])

print(values)
Beispiel #19
0
def main():
    RemoteControlExample_NoGraphics()
    # Uncomment to get the fancy graphics version.  Be sure and download the button images!
    RemoteControlExample()
    sg.MsgBox('End of non-blocking demonstration')
Beispiel #20
0
import PySimpleGUI as sg

# Demo of how columns work
# Form has on row 1 a vertical slider followed by a COLUMN with 7 rows
# Prior to the Column element, this layout was not possible
# Columns layouts look identical to form layouts, they are a list of lists of elements.

# sg.ChangeLookAndFeel('BlueMono')

# Column layout
col = [[sg.Text('col Row 1', text_color='white', background_color='blue')],
       [sg.Text('col Row 2', text_color='white', background_color='blue'), sg.Input('col input 1')],
       [sg.Text('col Row 3', text_color='white', background_color='blue'), sg.Input('col input 2')]]

layout = [[sg.Listbox(values=('Listbox Item 1', 'Listbox Item 2', 'Listbox Item 3'), select_mode=sg.LISTBOX_SELECT_MODE_MULTIPLE, size=(20,3)), sg.Column(col, background_color='blue')],
          [sg.Input('Last input')],
          [sg.OK()]]

# Display the form and get values
# If you're willing to not use the "context manager" design pattern, then it's possible
# to collapse the form display and read down to a single line of code.
button, values = sg.FlexForm('Compact 1-line form with column').LayoutAndRead(layout)

sg.MsgBox(button, values, line_width=200)
Beispiel #21
0
def FlashLED():
    for i in range(5):
        GPIO.output(14, GPIO.HIGH)
        time.sleep(0.5)
        GPIO.output(14, GPIO.LOW)
        time.sleep(0.5)


layout = [[rg.T('Raspberry Pi LEDs')], [rg.T('', size=(14, 1), key='output')],
          [rg.ReadFormButton('Switch LED')], [rg.ReadFormButton('Flash LED')],
          [rg.Exit()]]

form = rg.FlexForm('Raspberry Pi GUI', grab_anywhere=False)
form.Layout(layout)

while True:
    button, values = form.Read()
    if button is None:
        break

    if button is 'Switch LED':
        form.FindElement('output').Update(SwitchLED())
    elif button is 'Flash LED':
        form.FindElement('output').Update('LED is Flashing')
        form.ReadNonBlocking()
        FlashLED()
        form.FindElement('output').Update('')

rg.MsgBox('Done... exiting')
Beispiel #22
0
df_name = "Batch_4061620_batch_results.csv"

annotations_results = pd.read_csv(f"data/{df_name}")

saved_df_name = df_name.split(".")[0] + "_completed.csv"

# Get the folder containing the images from the user
folder = sg.PopupGetFolder('AMT Annotation Verification for Bounding Boxes', 'Image folder to open', default_path=f'/home/ubuntu/Desktop/FY2020/MastersResearch/amazon-mechanical-turk-annotation-verification/output/{df_name.split(".")[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.MsgBox('No PNG images in folder')
    exit(0)

# create the form that also returns keyboard events
form = sg.FlexForm("AMT Annotation Verification for Bounding Boxes", return_keyboard_events=True, location=(0,0), size=(w, h), resizable=True, use_default_focus=False )

# make these 2 elements outside the layout because want to "update" them later
# initialize to the first PNG file in the list
image_elem = sg.Image(filename=png_files[0],size=(w, h))
filename_display_elem = sg.Text(png_files[0], size=(80, 3))
file_num_display_elem = sg.Text('File 1 of {}'.format(len(png_files)), size=(20,1))
addtional_info = sg.Text('Working Time:{}, Approval Rate: {}'.format(1,2), size=(25,3))
filename = png_files[0]
# define layout, show and read the form
col = [[filename_display_elem],
          [image_elem],
            layout_tab_2.append([sg.Text('_' * 100, size=(75, 1))])
            layout_tab_2.append([sg.Text('US Search String Override')])
            layout_tab_2.append([sg.InputText(size=(100, 1))])
            layout_tab_2.append([sg.Text('German Search String Override')])
            layout_tab_2.append([sg.InputText(size=(100, 1))])
            layout_tab_2.append([sg.Text('Typical US Search String')])
            layout_tab_2.append([
                sg.InputText(
                    size=(100, 1),
                    default_text=
                    'gruen -sara -quarz -quartz -embassy -bob -robert -elephants -adidas -LED '
                )
            ])
            layout_tab_2.append([sg.Text('_' * 100, size=(75, 1))])
            layout_tab_2.append([
                sg.Submit(button_color=('red', 'yellow')),
                sg.Cancel(button_color=('white', 'blue'))
            ])

            results = sg.ShowTabbedForm(
                'eBay Super Searcher', (form, layout_tab_1, 'Where To Save'),
                (form2, layout_tab_2, 'Categories & Search String'))

    return results


if __name__ == '__main__':
    results = eBaySuperSearcherGUI()
    print(results)
    sg.MsgBox('Results', results)
# Very basic form.  Return values as a dictionary
form = sg.FlexForm('Simple data entry form')  # begin with a blank form

layout = [
          [sg.Text('Please enter your Name, Address, Phone')],
          [sg.Text('Name', size=(15, 1)), sg.InputText('name', key='name')],
          [sg.Text('Address', size=(15, 1)), sg.InputText('address', key='address')],
          [sg.Text('Phone', size=(15, 1)), sg.InputText('phone', key='phone')],
          [sg.Ok(), sg.Cancel()]
         ]

button, values = form.LayoutAndRead(layout)

print(button, values['name'], values['address'], values['phone'])

form = sg.FlexForm('Simple data entry form')  # begin with a blank form

layout = [
          [sg.Text('Please enter your Name, Address, Phone')],
          [sg.Text('Name', size=(15, 1)), sg.InputText('name')],
          [sg.Text('Address', size=(15, 1)), sg.InputText('address')],
          [sg.Text('Phone', size=(15, 1)), sg.InputText('phone')],
          [sg.Ok(), sg.Cancel()]
         ]

button, values = form.LayoutAndRead(layout)

name, address, phone = values
sg.MsgBox(button, values[0], values[1], values[2])