Basic PyQt5 + Python 3.6 support

This commit is contained in:
Silvan Calarco 2019-03-31 19:43:46 +02:00
parent 2038c0f763
commit c3e25efaef

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
#!/usr/bin/python3.6
# mambatray 2
# Copyright (C) 2011-2018 by Silvan Calarco
# Copyright (C) 2011-2019 by Silvan Calarco
# Copyright (C) 2011 by michiamophil
# Distributed under the terms of the GPL version 3 FLOSS License
#
@ -17,32 +17,35 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def __init__(self, icon, parent=None):
global w, menu, contatore, srpm, lista, NetsrpmsArg, nOre, desktop_session
nOre = 2
srpm = ["skype", "flashplugin", "win32codecs", "msttcorefonts", "b43-firmware", "sun-java7", "sun-java8", "virtualbox-extension-pack", "chromium-pepper-flash", "spotify"]
NetsrpmsArg = "-c"
lista = []
contatore = 0
nOre = 2
srpm = ["skype", "flashplugin", "win32codecs", "msttcorefonts", "b43-firmware", "sun-java7", "sun-java8", "virtualbox-extension-pack", "chromium-pepper-flash", "spotify"]
NetsrpmsArg = "-c"
lista = []
contatore = 0
w = parent
QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
menu = QtWidgets.QMenu(parent)
desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION'))
try:
desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION'))
except:
desktop_session = 'default'
if desktop_session == 'default':
desktop_session = 'plasma'
desktop_session = 'plasma'
elif desktop_session[:3] == 'kde':
desktop_session = 'kde'
desktop_session = 'kde'
# refresh packages cache timer
global refreshPackagesTimer, refreshPackagesCacheProcess, checkSRPMSUpdatesTimer, SRPMUpdateProcess, networkOnlineProcess
refreshPackagesTimer = QtCore.QTimer(self)
checkSRPMSUpdatesTimer = QtCore.QTimer(self)
checkSRPMSUpdatesTimer = QtCore.QTimer(self)
refreshPackagesCacheProcess = QtCore.QProcess(self)
SRPMUpdateProcess = QtCore.QProcess(self)
SRPMUpdateProcess = QtCore.QProcess(self)
networkOnlineProcess = QtCore.QProcess(self)
refreshPackagesTimer.timeout.connect(self.refreshPackagesCache)
refreshPackagesCacheProcess.finished.connect(self.restartRefreshPackagesTimer)
checkSRPMSUpdatesTimer.timeout.connect(self.SRPMSCheckUpgradeList)
checkSRPMSUpdatesTimer.timeout.connect(self.SRPMSCheckUpgradeList)
# software menu
global softwareManagerProcess, softwareCheckUpgradesProcess, softwareBaseInstallsProcess, dcopServerProcess
@ -95,76 +98,76 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
# the first time refresh packages cache after 5 minutes
refreshPackagesTimer.start( 5 * 60000 )
# the first time check for SRPMS updates after 4 minutes
checkSRPMSUpdatesTimer.start( 4 * 60000 )
checkSRPMSUpdatesTimer.start( 4 * 60000 )
def setProxyForSmart(self):
setProxyProcess = QtCore.QProcess(self)
pf = libproxy.ProxyFactory()
for protocol in ["http","https","ftp"]:
proxies = pf.getProxies("%s://openmamba.org" % protocol)
for proxy in proxies:
if proxy == "direct://":
setProxyProcess.execute("smart",['config','--remove','%s_proxy' % protocol])
break
else:
setProxyProcess.execute("smart",['config','--set','%s_proxy=%s' %(protocol,proxy)])
break
proxies = pf.getProxies("%s://openmamba.org" % protocol)
for proxy in proxies:
if proxy == "direct://":
setProxyProcess.execute("smart",['config','--remove','%s_proxy' % protocol])
break
else:
setProxyProcess.execute("smart",['config','--set','%s_proxy=%s' %(protocol,proxy)])
break
def iconActivated(self, reason):
if reason in (QtWidgets.QSystemTrayIcon.Trigger, QtWidgets.QSystemTrayIcon.DoubleClick):
menu.popup(self.geometry().center())
def about(self):
global version
path = '/etc/openmamba-release'
if os.path.exists(path):
v = open(path, 'r')
version = v.read()
a = self.FormattaInfo()
version = "<ul><li>"+_("<font color=\"green\">open</font>mamba release:")+" <i>"+a[0]+"</i><li>"+_("Platform: ")+"<i>"+a[1]+"</i></ul>"
v.close()
else:
version = _("Error: Unable to find /etc/openmamba-release")
global version
path = '/etc/openmamba-release'
if os.path.exists(path):
v = open(path, 'r')
version = v.read()
a = self.FormattaInfo()
version = "<ul><li>"+_("<font color=\"green\">open</font>mamba release:")+" <i>"+a[0]+"</i><li>"+_("Platform: ")+"<i>"+a[1]+"</i></ul>"
v.close()
else:
version = _("Error: Unable to find /etc/openmamba-release")
QtWidgets.QMessageBox.about(menu, _("About"),
"<center><b>"+_("openmamba control center")+"</b>"
"<br><br>Copyright(c) 2011-2018 by Silvan Calarco"
"<br>Copyright(c) 2011 by michiamophil"
"<br><br><b>"+_("System info:")+"</b></center>"
""+_(version)+"<center><a href=\"http://openmamba.org\">http://openmamba.org</a></center>")
"<br><br>Copyright(c) 2011-2019 by Silvan Calarco"
"<br>Copyright(c) 2011 by michiamophil"
"<br><br><b>"+_("System info:")+"</b></center>"
""+_(version)+"<center><a href=\"http://openmamba.org\">http://openmamba.org</a></center>")
def FormattaInfo(self):
result = []
v = version
#result[0]=versione
result.append(v[ v.find("openmamba release ")+18 : v.find(" for") ] + " " + v[ v.find("(") : v.find(")")+1 ])
#result[1] = piattaforma
result.append(v[ v.find("for")+4 : v.find("(") ])
return result
result = []
v = version
#result[0]=versione
result.append(v[ v.find("openmamba release ")+18 : v.find(" for") ] + " " + v[ v.find("(") : v.find(")")+1 ])
#result[1] = piattaforma
result.append(v[ v.find("for")+4 : v.find("(") ])
return result
def networkOnline(self):
return networkOnlineProcess.execute("/usr/bin/nm-online",['-q','-x'])
return networkOnlineProcess.execute("/usr/bin/nm-online",['-q','-x'])
def softwareManager(self):
self.setProxyForSmart()
if desktop_session == 'plasma':
softwareManagerProcess.execute("/usr/bin/plasma-discover", ['--mode', 'Browsing'])
elif desktop_session == 'kde':
softwareManagerProcess.execute("/opt/kde/bin/apper")
else:
softwareManagerProcess.execute("/usr/bin/gpk-application")
self.setProxyForSmart()
if desktop_session == 'plasma':
softwareManagerProcess.execute("/usr/bin/plasma-discover", ['--mode', 'Browsing'])
elif desktop_session == 'kde':
softwareManagerProcess.execute("/opt/kde/bin/apper")
else:
softwareManagerProcess.execute("/usr/bin/gpk-application")
def softwareCheckUpgrades(self):
self.setProxyForSmart()
if desktop_session == 'plasma':
softwareCheckUpgradesProcess.start("/usr/bin/plasma-discover", ['--mode', 'Update'])
elif desktop_session == 'kde':
softwareCheckUpgradesProcess.start("/opt/kde/bin/apper", ['--updates'])
self.setProxyForSmart()
if desktop_session == 'plasma':
softwareCheckUpgradesProcess.start("/usr/bin/plasma-discover", ['--mode', 'Update'])
elif desktop_session == 'kde':
softwareCheckUpgradesProcess.start("/opt/kde/bin/apper", ['--updates'])
else:
softwareCheckUpgradesProcess.start("/usr/bin/gpk-update-viewer")
softwareCheckUpgradesProcess.start("/usr/bin/gpk-update-viewer")
def refreshPackagesCache(self):
self.setProxyForSmart()
self.setProxyForSmart()
refreshPackagesTimer.stop()
refreshPackagesCacheProcess.start("/usr/bin/pkcon", ['refresh'])
@ -195,66 +198,64 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
self.showMessage("Firewall", _("Could not enable firewall"))
def networkFirewallConfigure(self):
if desktop_session == 'kde' or desktop_session == 'plasma':
networkFirewallConfigureProcess.execute("/opt/kde/bin/kcmshell4", list(set(['ufw'])))
else:
networkFirewallConfigureProcess.execute("/usr/bin/gufw")
if desktop_session == 'kde' or desktop_session == 'plasma':
networkFirewallConfigureProcess.execute("/opt/kde/bin/kcmshell4", list(set(['ufw'])))
else:
networkFirewallConfigureProcess.execute("/usr/bin/gufw")
def networkProxy(self):
if desktop_session == 'plasma':
networkProxyProcess.execute("/usr/bin/kcmshell5", list(set(['proxy'])))
elif desktop_session == 'kde':
networkProxyProcess.execute("/opt/kde/bin/kcmshell4", list(set(['proxy'])))
elif desktop_session == 'gnome':
networkProxyProcess.execute("/usr/bin/gnome-control-center", "network")
self.setProxyForSmart()
if desktop_session == 'plasma':
networkProxyProcess.execute("/usr/bin/kcmshell5", list(set(['proxy'])))
elif desktop_session == 'kde':
networkProxyProcess.execute("/opt/kde/bin/kcmshell4", list(set(['proxy'])))
elif desktop_session == 'gnome':
networkProxyProcess.execute("/usr/bin/gnome-control-center", "network")
self.setProxyForSmart()
def SRPMSCheckUpgradeList(self):
checkSRPMSUpdatesTimer.stop()
global contatore, lista, NetsrpmsArg
if (self.networkOnline() == 0):
try:
SRPMUpdateProcess.start("/usr/bin/openmamba-netsrpms",[NetsrpmsArg,srpm[contatore]])
except: #supera il limite dell'indice nella lista
contatore = 0
if NetsrpmsArg == '-c':
self.SRPMSAskAndInstall()
else:
lista = []
NetsrpmsArg = '-c'
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
checkSRPMSUpdatesTimer.stop()
global contatore, lista, NetsrpmsArg
if (self.networkOnline() == 0):
try:
SRPMUpdateProcess.start("/usr/bin/openmamba-netsrpms",[NetsrpmsArg,srpm[contatore]])
except: #supera il limite dell'indice nella lista
contatore = 0
if NetsrpmsArg == '-c':
self.SRPMSAskAndInstall()
else:
lista = []
NetsrpmsArg = '-c'
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
#viene eseguita per ogni SRPM al termine del processo SRPMUpdateProcess
def SRPMSCheckUpgrade(self, status):
global contatore, lista
if status == 1:
lista.append(srpm[contatore])
contatore += 1
self.SRPMSCheckUpgradeList()
global contatore, lista
if status == 1:
lista.append(srpm[contatore])
contatore += 1
self.SRPMSCheckUpgradeList()
#viene eseguita una volta terminata la fase di controllo degli aggiornamenti
def SRPMSAskAndInstall(self):
global NetsrpmsArg, lista
if not lista == []:
Lista = self.Lista()
msg = QtGui.QMessageBox.question(menu, (_("Not Open Source openmamba components")), (_("The following components are available for update: ") + "\n\n" + Lista + "\n\n" + _("Ok to proceed?")), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes)
if msg == QtGui.QMessageBox.Yes:
NetsrpmsArg = '-u'
self.SRPMSCheckUpgradeList()
else:
lista = []
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
else:
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
global NetsrpmsArg, lista
if not lista == []:
Lista = self.Lista()
msg = QtGui.QMessageBox.question(menu, (_("Not Open Source openmamba components")), (_("The following components are available for update: ") + "\n\n" + Lista + "\n\n" + _("Ok to proceed?")), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes)
if msg == QtGui.QMessageBox.Yes:
NetsrpmsArg = '-u'
self.SRPMSCheckUpgradeList()
else:
lista = []
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
else:
checkSRPMSUpdatesTimer.start((nOre * 60) * 60000)
#partendo dalla lista lista (scusate il gioco di parole :) ) restituisce la lista in modo 'leggibile'
def Lista(self):
testo = ''
for a in lista:
testo = testo + a + ', '
return testo[0:len(testo)-2]
testo = ''
for a in lista:
testo = testo + a + ', '
return testo[0:len(testo)-2]
def main():
app = QtWidgets.QApplication(sys.argv)
@ -262,7 +263,7 @@ def main():
app.exit(1)
else:
app.setQuitOnLastWindowClosed(0)
gettext.install('mambatray', '/usr/share/locale', unicode=1)
gettext.install('mambatray', '/usr/share/locale')
w = QtWidgets.QWidget()
w.setWindowIcon(QtGui.QIcon.fromTheme("mambatray",QtGui.QIcon("/usr/share/icons/hicolor/64x64/apps/mambatray.png")))
trayIcon = SystemTrayIcon(QtGui.QIcon.fromTheme("mambatray", QtGui.QIcon("/usr/share/icons/hicolor/32x32/apps/mambatray.png")), w)