79 lines
1.7 KiB
Python
Executable File
79 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# Get needed modules
|
|
import yaml
|
|
import subprocess
|
|
from PyQt5.QtCore import QTimer
|
|
from PyQt5.QtGui import *
|
|
from PyQt5.QtWidgets import *
|
|
|
|
# Available Updates count holder
|
|
avail = ""
|
|
|
|
# Use config.yml file to allow for compatibility with
|
|
# most terminal emulators possible & custom icon
|
|
with open('config.yml') as f:
|
|
conf = yaml.load(f, yaml.FullLoader)
|
|
term = str(conf['terminal'])
|
|
opt = str(conf['option'])
|
|
icn = str(conf['icon'])
|
|
f.close()
|
|
|
|
# Run checkupdates command
|
|
# Populates the available updates count holder
|
|
def count():
|
|
cmd = ['checkupdates']
|
|
p1 = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
p2 = subprocess.Popen(['wc', '-l'], stdin=p1.stdout, stdout=subprocess.PIPE)
|
|
output = ((p2.communicate()[0]).decode()).rstrip('\n')
|
|
global avail
|
|
avail = str(output)+" Updates"
|
|
|
|
# Run system update
|
|
def update():
|
|
cmd = [ term, opt, 'sudo', 'pacman', '-Syu']
|
|
subprocess.Popen(cmd)
|
|
|
|
# Sets new text for available updates
|
|
def newText():
|
|
count()
|
|
option1.setText(avail)
|
|
tray.setToolTip(avail)
|
|
|
|
# Initially populate available updates
|
|
count()
|
|
|
|
app = QApplication([])
|
|
app.setQuitOnLastWindowClosed(False)
|
|
|
|
# Adding an icon
|
|
icon = QIcon(icn)
|
|
|
|
# Adding item on the menu bar
|
|
tray = QSystemTrayIcon()
|
|
tray.setIcon(icon)
|
|
tray.setToolTip(avail)
|
|
tray.setVisible(True)
|
|
|
|
# Creating the options
|
|
menu = QMenu()
|
|
option1 = QAction(avail)
|
|
option1.triggered.connect(update)
|
|
option1.triggered.connect(newText)
|
|
menu.addAction(option1)
|
|
|
|
# Set up timer to update count
|
|
timer = QTimer()
|
|
timer.timeout.connect(newText)
|
|
timer.start(10000)
|
|
|
|
# To quit the app
|
|
quit = QAction("Quit")
|
|
quit.triggered.connect(app.quit)
|
|
menu.addAction(quit)
|
|
|
|
# Adding options to the System Tray
|
|
tray.setContextMenu(menu)
|
|
|
|
app.exec_()
|