Exemplo n.º 1
0
def main():

    sg.ChangeLookAndFeel('LightGreen')

    # define the window layout
    layout = [[
        sg.Text('OpenCV Demo',
                size=(40, 1),
                justification='center',
                font='Helvetica 20')
    ], [sg.Image(filename='', key='image')],
              [
                  sg.Button('Record', size=(10, 1), font='Helvetica 14'),
                  sg.Button('Stop', size=(10, 1), font='Any 14'),
                  sg.Button('Exit', size=(10, 1), font='Helvetica 14'),
                  sg.Button('About', size=(10, 1), font='Any 14')
              ]]

    # create the window and show it without the plot
    window = sg.Window('Demo Application - OpenCV Integration',
                       location=(800, 400))
    window.Layout(layout)

    # ---===--- Event LOOP Read and display frames, operate the GUI --- #
    cap = cv2.VideoCapture(0)
    recording = False
    while True:
        event, values = window.Read(timeout=0, timeout_key='timeout')
        if event == 'Exit' or event is None:
            sys.exit(0)
            pass
        elif event == 'Record':
            recording = True
        elif event == 'Stop':
            recording = False
            img = np.full((480, 640), 255)
            imgbytes = cv2.imencode('.png', img)[1].tobytes(
            )  #this is faster, shorter and needs less includes
            window.FindElement('image').Update(data=imgbytes)
        elif event == 'About':
            sg.PopupNoWait(
                'Made with PySimpleGUI',
                'www.PySimpleGUI.org',
                'Check out how the video keeps playing behind this window.',
                'I finally figured out how to display frames from a webcam.',
                'ENJOY!  Go make something really cool with this... please!',
                keep_on_top=True)
        if recording:
            ret, frame = cap.read()
            imgbytes = cv2.imencode('.png', frame)[1].tobytes()  #ditto
            window.FindElement('image').Update(data=imgbytes)
Exemplo n.º 2
0
def gui():
    sg.ChangeLookAndFeel('Topanga')

    sg.SetOptions(border_width=0, margins=(0, 0), element_padding=(0, 0))

    layout = [
            [sg.T('GitHub Issues Watcher' + 48 * ' '),
            sg.Button('', size=(25,25),
                          image_data=red_x,
                          key='_quit_',button_color=(sg.LOOK_AND_FEEL_TABLE['Topanga']['TEXT'],sg.LOOK_AND_FEEL_TABLE['Topanga']['BACKGROUND']),
                          tooltip='Closes window')],
            [sg.T('', key='_status_', size=(12, 1))],
            [sg.T('', key='_numissues_', size=(20, 1))],
              ]

    window = sg.Window('Issue watcher',
                       no_titlebar=True,
                       grab_anywhere=True,
                       keep_on_top=True,
                       alpha_channel=.8,        # dim the lights a little
                       location=(2121,310),     # locate in upper right corner of screen
                       ).Layout(layout).Finalize()

    window.Refresh()
    status_elem = window.FindElement('_status_')
    issues_elem = window.FindElement('_numissues_')

    initial_issue_count, initial_first_issue = get_num_issues()
    # The Event Loop runs every 1000ms
    i = 0
    while True:
        if i % 60 == 0:     # Every 60 seconds read GitHub
            status_elem.Update('Reading...')
            window.Refresh()
            issues, first_issue = get_num_issues()
            issues_elem.Update('{} Issues. {} is first issue'.format(issues, initial_first_issue))
            window.Refresh()
            # if something changed, then make a popup
            if issues != initial_issue_count or first_issue != initial_first_issue:
                sg.PopupNoWait('Issues changed on GitHub', background_color='red')
                initial_issue_count = issues
                initial_first_issue = first_issue
            status_elem.Update('')
        else:
            status_elem.Update('.' if i%2 else '')  # blink a '.' every 2 seconds so know still running
        # read with a 1 second timeout
        event, values = window.Read(timeout=1000)
        if event in ('_quit_', None):
            break
        i += 1
def system_tray():

    menu_def = ['Root', ['E&xit']]
    tray = sg.SystemTray(data_base64=logo, tooltip='GitHub Issue Watcher')

    # tray.Hide()
    initial_issue_count, initial_first_issue = get_num_issues()
    # The Event Loop runs every 5000ms
    poll_frequncy = 5000
    seconds = 0
    while True:
        menu_item = tray.Read(timeout=5000)
        if menu_item == 'Exit':
            break
        if menu_item == 'Run GUI':
            tray.Update(data_base64=red_x)
            gui()
            tray.Update(data_base64=logo)
        if seconds % 12 == 0:  # Every 60 seconds read GitHub
            issues, first_issue = get_num_issues()
            menu_def = [
                'root',
                [
                    '{} Issues'.format(issues),
                    '{} First Issue'.format(first_issue), '---', '&Run GUI',
                    '&Refresh', 'E&xit'
                ]
            ]
            tray.Update(menu_def, tooltip='{} First Issue'.format(first_issue))
            # if something changed, then make a popup
            if issues != initial_issue_count or first_issue != initial_first_issue:
                sg.PopupNoWait('Issues changed on GitHub ',
                               'First issue # is {}'.format(first_issue),
                               background_color='red',
                               keep_on_top=True)
                initial_issue_count = issues
                initial_first_issue = first_issue
        if menu_item in ('Refresh', sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED):
            issues, first_issue = get_num_issues()
            tray.ShowMessage(
                'Issue',
                '{} Issues\n{} First Issue'.format(issues, first_issue),
                messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION,
            )

        seconds += poll_frequncy / 1000