Refresh of the Issue Watcher Wx based system tray demo
This commit is contained in:
parent
e36266ae38
commit
b75c04eaf1
|
@ -1,18 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
from PySimpleGUIWx import SystemTray
|
||||
from PySimpleGUIWx import EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED
|
||||
from PySimpleGUIWx import EVENT_SYSTEM_TRAY_ICON_ACTIVATED
|
||||
from PySimpleGUIWx import EVENT_SYSTEM_TRAY_ICON_RIGHT_CLICK
|
||||
from PySimpleGUIWx import EVENT_SYSTEM_TRAY_MESSAGE_CLICKED
|
||||
import PySimpleGUIWx as sgwx
|
||||
import PySimpleGUI as sg
|
||||
|
||||
import PySimpleGUIWx as sg
|
||||
import subprocess
|
||||
import time
|
||||
import re
|
||||
# Import requests (to download the page)
|
||||
import requests
|
||||
import datetime
|
||||
import time
|
||||
|
||||
# Import BeautifulSoup (to parse what we download)
|
||||
from bs4 import BeautifulSoup
|
||||
|
@ -22,7 +15,10 @@ CHROME = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
|
|||
DISCORD = r"C:\Users\mike\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Discord Inc\Discord.lnk"
|
||||
VIEW_ISSUES_URL = r'https://github.com/MikeTheWatchGuy/PySimpleGUI/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc'
|
||||
PULL_REQUEST_URL = r'https://github.com/MikeTheWatchGuy/PySimpleGUI/compare/master...Dev-latest'
|
||||
|
||||
ANNOUCEMENTS = r'https://github.com/MikeTheWatchGuy/PySimpleGUI/issues/142'
|
||||
TRAFFIC = r'https://github.com/MikeTheWatchGuy/PySimpleGUI/graphs/traffic'
|
||||
SEARCH = r'https://github.com/search?o=desc&q=pysimplegui&s=indexed&type=Code'
|
||||
PYPI_STATS = r'https://pepy.tech/project/pysimplegui'
|
||||
ICON_FILE = r'C:\Python\PycharmProjects\GooeyGUI\default_icon.ico'
|
||||
|
||||
# search github for total open issues and Issue Number of first issue
|
||||
|
@ -40,14 +36,16 @@ def get_num_issues():
|
|||
# parse the downloaded homepage and grab all text,
|
||||
soup = BeautifulSoup(response.text, "lxml")
|
||||
# look for phrase "XXX Open"
|
||||
# print(soup)
|
||||
findopen = re.compile(r"\d+ Open")
|
||||
# get number of open issues
|
||||
number_open_string = findopen.search(str(soup)).group(0)
|
||||
number_open_string = findopen.search(str(soup)).group()
|
||||
num_open_issues = number_open_string[0:number_open_string.index(' ')]
|
||||
# find the first issue in the list by earing for "issue-id-XXXX"
|
||||
find_first_issue = re.compile(r'issue-id-\d+')
|
||||
first_issue_string = find_first_issue.search(str(soup)).group(0)
|
||||
first_issue = first_issue_string[9:]
|
||||
soup = str(soup).replace('\n', '')
|
||||
find_first_issue = re.compile(r'#\d+\s+opened')
|
||||
first_issue_string = find_first_issue.search(str(soup)).group()
|
||||
first_issue = first_issue_string[1:first_issue_string.find(' ')]
|
||||
return num_open_issues, first_issue
|
||||
|
||||
|
||||
|
@ -93,7 +91,7 @@ def gui():
|
|||
if issues == 0 and first_issue == 0:
|
||||
print('Read error', time.time())
|
||||
continue
|
||||
issues_elem.Update('{} Issues. {} is first issue'.format(issues, initial_first_issue))
|
||||
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:
|
||||
|
@ -113,51 +111,75 @@ def system_tray():
|
|||
|
||||
menu_def = ['Root',
|
||||
['E&xit']]
|
||||
tray = SystemTray(menu=menu_def, data_base64=logo, tooltip='GitHub Issue Watcher')
|
||||
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=2000)
|
||||
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 == EVENT_SYSTEM_TRAY_ICON_ACTIVATED:
|
||||
tray.ShowMessage('Issue', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sgwx.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION, )
|
||||
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','&Discord', '---','&Run GUI', '&Refresh', 'E&xit']]
|
||||
['{} 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.Popup('Issues changed on GitHub ', 'First issue # is {}'.format(first_issue), background_color='red', keep_on_top=True)
|
||||
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())
|
||||
if menu_item in('Refresh', EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED):
|
||||
issues, first_issue = get_num_issues()
|
||||
tray.ShowMessage('Issue', '{} Issues\n{} First Issue'.format(issues, first_issue), messageicon=sgwx.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION, )
|
||||
sp = subprocess.Popen([CHROME, VIEW_ISSUES_URL], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
elif menu_item == EVENT_SYSTEM_TRAY_MESSAGE_CLICKED or menu_item.startswith('View Issues'):
|
||||
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('Discord'):
|
||||
sp = subprocess.Popen([DISCORD, r''], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
seconds += poll_fr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