def gui():
    sg.ChangeLookAndFeel('Topanga')

    sg.SetOptions(border_width=0)

    layout = [
            [sg.T('GitHub Issues Watcher' + 5 * ' ', click_submits=True, key='GitHub'),
            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=(2360,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()
    seconds = 0
    poll_frequncy = 1000

    while True:
        event, values = window.Read(timeout=poll_frequncy)
        if event in ('_quit_', None):
            break
        if seconds % 60 == 0 or event.startswith('GitHub'):     # Every 60 seconds read GitHub
            status_elem.Update('Reading...')
            window.Refresh()
            issues, first_issue = get_num_issues()
            if issues == 0 and first_issue == 0:
                print('Read error', time.time())
                continue
            issues_elem.Update('{} Issues. {} is first issue'.format(issues, 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 ', 'First issue # is {}'.format(first_issue), background_color='red', keep_on_top=True)
                initial_issue_count = issues
                initial_first_issue = first_issue
            status_elem.Update('')
        else:
            status_elem.Update('.' if seconds%2 else '')  # blink a '.' every 2 seconds so know still running

        seconds += poll_frequncy/1000
    window.Close()
Пример #2
0
                    background_color='red',
                    keep_on_top=False)
file = sg.PopupGetFile('Get file',
                       save_as=False,
                       file_types=(("ALL Files", "*.jpg"), ),
                       no_window=False)
folder = sg.PopupGetFolder('Getting a folder', no_window=False)
sg.Popup('Test' * 10, title='My title')
sg.Print('file = ', file)
sg.Print('folder = ', folder)
sg.Print(file)
# sg.Print(file)
sg.PopupQuickMessage('This is a quick message', location=(1000, 600))
# Here, have some windows on me....
[
    sg.PopupNoWait('No-wait Popup', location=(500 + 100 * x, 500))
    for x in range(10)
]

answer = sg.PopupYesNo(
    'Do not worry about all those open windows... they will disappear at the end',
    'Are you OK with that?')
print('answer=', answer)
if answer == 'No':
    # sg.PopupCancel('OK, we will destroy those windows as soon as you close this window', auto_close_duration=2, auto_close=True)
    sys.exit()

sg.PopupNonBlocking('Your answer was', answer, location=(1000, 600))

text = sg.PopupGetText('This is a call to PopopGetText', location=(1000, 200))
print(text)
def system_tray():

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

    # tray.Hide()
    initial_issue_count, initial_first_issue = get_num_issues()
    tray.ShowMessage('Starting up...', '{} Issues\n{} First Issue'.format(initial_issue_count, initial_first_issue),
                     messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_CRITICAL, )
    issues = first_issue = 0
    # The Event Loop runs every 5000ms
    poll_frequncy = 5000
    seconds = 0
    print('Starting', datetime.datetime.now())
    while True:
        menu_item = tray.Read(timeout=poll_frequncy)
        if menu_item == 'Exit':
            break
        if menu_item == 'Run GUI':
            tray.Update(data_base64=red_x)
            gui()
            tray.Update(data_base64=logo)
        elif menu_item.startswith('View Issues'):
            sg.PopupNoWait('Refreshing issue data...', auto_close=True, auto_close_duration=3)
            issues, first_issue = get_num_issues()
            tray.ShowMessage('Refreshed', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION, )
            sp = subprocess.Popen([CHROME, VIEW_ISSUES_URL], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        elif menu_item  in('Refresh', sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED):
            tray.ShowMessage('Refreshing', 'Old values are\n{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_NOICON )
            tray.Update(data_base64=red_x)
            issues, first_issue = get_num_issues()
            tray.ShowMessage('Refreshed', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_CRITICAL, )
            tray.Update(data_base64=logo)
        # elif menu_item == sg.EVENT_SYSTEM_TRAY_ICON_ACTIVATED:
        #     tray.ShowMessage('Last check', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION, )
        elif menu_item == sg.EVENT_SYSTEM_TRAY_MESSAGE_CLICKED :
            tray.Update(data_base64=logo)
            sp = subprocess.Popen([CHROME, VIEW_ISSUES_URL], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        elif  menu_item.startswith('Pull'):
            sp = subprocess.Popen([CHROME, PULL_REQUEST_URL], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        elif  menu_item.startswith('Announcements'):
            sp = subprocess.Popen([CHROME, ANNOUCEMENTS], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        elif  menu_item.startswith('Traffic'):
            sp = subprocess.Popen([CHROME, TRAFFIC], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        elif  menu_item.startswith('Search'):
            sp = subprocess.Popen([CHROME, SEARCH], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        elif  menu_item.startswith('Discord'):
            sp = subprocess.Popen([DISCORD, r''], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        elif  menu_item.startswith('PyPI'):
            sp = subprocess.Popen([CHROME, PYPI_STATS], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)


        if seconds % 12 == 0:     # Every 60 seconds read GitHub
            issues, first_issue = get_num_issues()
            if issues != 0:
                menu_def = ['root',
                            ['{} Issues'.format(issues), '{} First Issue'.format(first_issue), '---','&View Issues Online', '&Pull Request','---', 'Announcements', 'Traffic', 'PyPI Stats', 'Search for Project' , '&Discord', '---','&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.PopupNonBlocking('Issues changed on GitHub ', 'First issue # is {}'.format(first_issue), background_color='red', keep_on_top=True, grab_anywhere=True)
                    initial_issue_count = issues
                    initial_first_issue = first_issue
                    tray.Update(data_base64=logo32x32red)
                    tray.ShowMessage('Issues changes!', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_CRITICAL, )

            else:

                sg.PopupNonBlocking('Update error at: ',  datetime.datetime.now(),
                                    background_color='red', keep_on_top=True, grab_anywhere=True)
                print('Update failed', datetime.datetime.now())

        seconds += poll_frequncy/1000