Ejemplo n.º 1
0
def start_app():
    layout = [[
        sg.Text('Enter the last four of your phone number',
                size=(75, 1),
                justification='center',
                font=("Helvetica", 18))
    ],
              [
                  sg.Text('', size=(35, 1)),
                  sg.InputText(font=("Helvetica", 18),
                               justification='center',
                               size=(30, 1),
                               key='input_box')
              ],
              [
                  sg.Text('', size=(35, 1)),
                  sg.ReadButton('Submit'),
                  sg.Text('', size=(18, 1)),
                  sg.ReadButton('Clear')
              ], [sg.Exit(key='Exit')]]

    window = sg.Window('Log In/Out',
                       auto_size_buttons=False,
                       return_keyboard_events=True).Layout(layout)

    while True:
        button, values = window.Read()

        if button == 'Exit' or values is None:
            break
        elif button == 'Clear':
            element = window.FindElement('input_box')
            element.Update('')
        elif button == 'Submit' or ord(str(button)) == 13:
            phone_number = values['input_box']
            try:
                int(phone_number)
                if int(phone_number) > 9999:
                    sg.Popup('Enter last four of your phone number.')
                elif len(phone_number) < 4:
                    sg.Popup('Enter last four of your phone number.')
                else:
                    failed = fetch_user(phone_number)
                    if failed:
                        sg.Popup('Invalid phone number.')

                    element = window.FindElement('input_box')
                    element.Update('')
            except:
                sg.Popup('Number values only.')
                element = window.FindElement('input_box')
                element.Update('')
    'Pyplot Scatter With Legend': PyplotScatterWithLegend,
    'Artist Customized Box Plots': PyplotArtistBoxPlots,
    'Artist Customized Box Plots 2': ArtistBoxplot2,
    'Pyplot Histogram': PyplotHistogram
}

sg.ChangeLookAndFeel('LightGreen')
figure_w, figure_h = 650, 650
# define the form layout
listbox_values = [key for key in fig_dict.keys()]
col_listbox = [[
    sg.Listbox(values=listbox_values,
               change_submits=True,
               size=(28, len(listbox_values)),
               key='func')
], [sg.T(' ' * 12), sg.Exit(size=(5, 2))]]

layout = [
    [sg.Text('Matplotlib Plot Test', font=('current 18'))],
    [
        sg.Column(col_listbox, pad=(5, (3, 330))),
        sg.Canvas(size=(figure_w, figure_h), key='canvas'),
        sg.Multiline(size=(70, 35), pad=(5, (3, 90)), key='multiline')
    ],
]

# create the form and show it without the plot
window = sg.Window('Demo Application - Embedding Matplotlib In PySimpleGUI',
                   grab_anywhere=False).Layout(layout)
window.Finalize()
def main():
    global g_interval, g_procs, g_exit

    # ----------------  Create Form  ----------------
    sg.ChangeLookAndFeel('Black')
    layout = [
        [
            sg.Text('',
                    size=(8, 1),
                    font=('Helvetica', 20),
                    text_color=sg.YELLOWS[0],
                    justification='center',
                    key='text')
        ],
        [
            sg.Text('',
                    size=(30, 8),
                    font=('Courier New', 12),
                    text_color='white',
                    justification='left',
                    key='processes')
        ],
        [
            sg.Exit(button_color=('white', 'firebrick4'), pad=((15, 0), 0)),
            sg.Spin([x + 1 for x in range(10)], 1, key='spin')
        ],
    ]

    window = sg.Window('CPU Utilization',
                       no_titlebar=True,
                       auto_size_buttons=False,
                       keep_on_top=True,
                       grab_anywhere=True).Layout(layout)

    # start cpu measurement thread
    thread = Thread(target=CPU_thread, args=(None, ))
    thread.start()
    # ----------------  main loop  ----------------
    while (True):
        # --------- Read and update window --------
        button, values = window.ReadNonBlocking()

        # --------- Do Button Operations --------
        if values is None or button == 'Exit':
            break
        try:
            g_interval = int(values['spin'])
        except:
            g_interval = 1

        # cpu_percent = psutil.cpu_percent(interval=interval)       # if don't wan to use a task
        cpu_percent = g_cpu_percent

        # let the GUI run ever 700ms regardless of CPU polling time. makes window be more responsive
        time.sleep(.7)

        display_string = ''
        if g_procs:
            # --------- Create list of top % CPU porocesses --------
            try:
                top = {proc.name(): proc.cpu_percent() for proc in g_procs}
            except:
                pass

            top_sorted = sorted(top.items(),
                                key=operator.itemgetter(1),
                                reverse=True)
            if top_sorted:
                top_sorted.pop(0)
            display_string = ''
            for proc, cpu in top_sorted:
                display_string += '{:2.2f} {}\n'.format(cpu / 10, proc)

        # --------- Display timer in window --------
        window.FindElement('text').Update('CPU {}'.format(cpu_percent))
        window.FindElement('processes').Update(display_string)

    # Broke out of main loop. Close the window.
    window.CloseNonBlocking()
    g_exit = True
    thread.join()
Ejemplo n.º 4
0
          ],
          [
              sg.Text('1- mkdir name                       :',
                      pad=((3, 10), 10)),
              sg.Input()
          ],
          [
              sg.Text('2- mkfile name                      :',
                      pad=((3, 10), 10)),
              sg.Input()
          ],
          [
              sg.Text("3- Search file                      :",
                      pad=((3, 10), 20)),
              sg.Input()
          ], [sg.Submit(), sg.Exit()],
          [sg.Text("By Miss.Robot", pad=((3, 10), 20))]]

window = sg.Window('File Manager', layout)
while True:
    event, values = window.Read()
    if event == 'Exit':
        break
    elif values[0] != '' and values[5] != '':
        folder = values[0]
        name = values[5]
        os.system(('mkdir ' + (folder + "/" + name)))
        print(folder + "," + name)
    elif values[0] != '' and values[6] != '':
        folder = values[0]
        name = values[6]
Ejemplo n.º 5
0
    import PySimpleGUI as sg

import psutil

# ----------------  Create Form  ----------------
sg.ChangeLookAndFeel('Black')
layout = [[sg.Text('')],
          [
              sg.Text('',
                      size=(8, 2),
                      font=('Helvetica', 20),
                      justification='center',
                      key='text')
          ],
          [
              sg.Exit(button_color=('white', 'firebrick4'), pad=((15, 0), 0)),
              sg.Spin([x + 1 for x in range(10)], 1, key='spin')
          ]]
# Layout the rows of the form and perform a read. Indicate the form is non-blocking!
window = sg.Window('CPU Meter',
                   no_titlebar=True,
                   auto_size_buttons=False,
                   keep_on_top=True,
                   grab_anywhere=True).Layout(layout)

# ----------------  main loop  ----------------
while (True):
    # --------- Read and update window --------
    button, values = window.ReadNonBlocking()

    # --------- Do Button Operations --------
layout = [[sg.Text('')],
          [
              sg.Text('',
                      size=(8, 2),
                      font=('Helvetica', 20),
                      justification='center',
                      key='text')
          ],
          [
              sg.ReadButton('Pause',
                            key='button',
                            button_color=('white', '#001480')),
              sg.ReadButton('Reset',
                            button_color=('white', '#007339'),
                            key='Reset'),
              sg.Exit(button_color=('white', 'firebrick4'), key='Exit')
          ]]

window = sg.Window('Running Timer',
                   no_titlebar=True,
                   auto_size_buttons=False,
                   keep_on_top=True,
                   grab_anywhere=True).Layout(layout)

# ----------------  main loop  ----------------
current_time = 0
paused = False
start_time = int(round(time.time() * 100))
while (True):
    # --------- Read and update window --------
    if not paused: