dotfiles/VSCodium/User/History/-66890744/MF2k

103 lines
2.5 KiB
Python
Executable File

#!/usr/bin/env python
### FOR TEST
import time
# Get needed modules
import yaml
import functools
import subprocess
from os import path
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
# Available Updates holders
avail = ""
# pkgList = ""
outputList = ""
# Use config.yml file to allow for compatibility with
# most terminal emulators possible & custom icon / timer duration
with open(path.expanduser("~/.config/systrayUpdater/systrayUpdater.yml")) as f:
conf = yaml.load(f, yaml.FullLoader)
term = str(conf['terminal'])
opt = str(conf['option'])
wait = int(conf['timer']) * 60000
icn = path.join(path.expanduser("~/.config/systrayUpdater/"), str(conf['icon']))
f.close()
# Run checkupdates command
# Populates the available updates and count
# Sets the list and count in proper spots
def count():
cmd = ['checkupdates']
p1 = subprocess.Popen(cmd, stdout=subprocess.PIPE)
global outputList
outputList = ((p1.communicate()[0]).decode()).rstrip('\n')
outputCount = len(outputList.splitlines())
# global pkgList
# if outputCount >= 1:
# pkgList = str(outputList)
# else:
# pkgList = str(outputCount)+" Updates"
# option1.setText(pkgList)
global avail
avail = str(outputCount)+" Updates"
tray.setToolTip(avail)
# Run system update
def update():
cmd = [ term, opt, 'sudo', 'pacman', '-Syu' ]
subprocess.Popen(cmd)
# Get pkg info
def infos():
cmd = [ term, opt, 'pacman', '-Qik' ]
subprocess.Popen(cmd)
def printMe(self, text):
print(text, "selected")
# Create an app surface
app = QApplication([])
app.setQuitOnLastWindowClosed(False)
# Set up timer to update count
timer = QTimer()
timer.timeout.connect(count)
timer.singleShot(1,count) # Initially populate available updates
timer.start(wait)
# Adding items to the menu
tray = QSystemTrayIcon()
icon = QIcon(icn)
tray.setIcon(icon)
tray.setToolTip(avail)
tray.setVisible(True)
# Creating the options
menu = QMenu()
option1 = QAction("Update")
option1.triggered.connect(update)
option1.triggered.connect(count)
count()
for i in outputList.splitlines():
# print(i)
# time.sleep(2)
# i = QAction(str(i))
# i.triggered.connect(infos)
# menu.addAction(i)
menu.addAction(i, functools.partial(printMe, i))
menu.addAction(option1)
# To quit the app
quit = QAction("Quit")
quit.triggered.connect(app.quit)
menu.addAction(quit)
# Place the app in the System Tray
tray.setContextMenu(menu)
app.exec_()