Exemplo n.º 1
0
import PySimpleGUIWx as sg
import sys
import time

sg.Popup('Test' * 10, title='My title')
# sg.Print('test', location=(400,200))
# sg.PopupScrolled(sg.ObjToString(sg.Window), title='My scrolled popup', non_blocking=True)
# sg.Print('Outputting to another line\n')
sg.PopupNonBlocking('Issues changed on GitHub ',
                    'First issue # is {}'.format(1),
                    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',
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