PyQt5 porting with 'plasma' session support

This commit is contained in:
Silvan Calarco 2018-02-10 18:19:32 +01:00
parent aa5c3e894d
commit 11c3d8be9e

View File

@ -8,11 +8,12 @@ import sys
import os
import gettext
import libproxy
from PyQt4.QtCore import SIGNAL
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt5.QtCore import pyqtSignal
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from PyQt5 import QtCore
class SystemTrayIcon(QtGui.QSystemTrayIcon):
class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def __init__(self, icon, parent=None):
global w, menu, contatore, srpm, lista, NetsrpmsArg, nOre, desktop_session
@ -22,14 +23,15 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
lista = []
contatore = 0
w = parent
QtGui.QSystemTrayIcon.__init__(self, icon, parent)
menu = QtGui.QMenu(parent)
QtWidgets.QSystemTrayIcon.__init__(self, icon, parent)
menu = QtWidgets.QMenu(parent)
desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION'))
desktop_session = QtCore.QString(os.getenv('DESKTOP_SESSION'))
if desktop_session == 'default':
desktop_session = QtCore.QString('kde')
if desktop_session.left(3) == 'kde':
desktop_session = QtCore.QString('kde')
desktop_session = 'plasma'
elif desktop_session[:3] == 'kde':
desktop_session = 'kde'
# refresh packages cache timer
global refreshPackagesTimer, refreshPackagesCacheProcess, checkSRPMSUpdatesTimer, SRPMUpdateProcess, networkOnlineProcess
@ -38,9 +40,9 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
refreshPackagesCacheProcess = QtCore.QProcess(self)
SRPMUpdateProcess = QtCore.QProcess(self)
networkOnlineProcess = QtCore.QProcess(self)
self.connect(refreshPackagesTimer, SIGNAL("timeout()"), self.refreshPackagesCache)
self.connect(refreshPackagesCacheProcess, SIGNAL("finished(int,QProcess::ExitStatus)"), self.restartRefreshPackagesTimer)
self.connect(checkSRPMSUpdatesTimer, SIGNAL("timeout()"), self.SRPMSCheckUpgradeList)
refreshPackagesTimer.timeout.connect(self.refreshPackagesCache)
refreshPackagesCacheProcess.finished.connect(self.restartRefreshPackagesTimer)
checkSRPMSUpdatesTimer.timeout.connect(self.SRPMSCheckUpgradeList)
# software menu
global softwareManagerProcess, softwareCheckUpgradesProcess, softwareBaseInstallsProcess, dcopServerProcess
@ -51,13 +53,13 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
softwareMenu = menu.addMenu(QtGui.QIcon.fromTheme("applications-system"),_("Software"))
softwareManageAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("applications-other"),_("Add/Remove software packages..."))
self.connect(softwareManageAction, SIGNAL("triggered()"), self.softwareManager)
softwareManageAction.triggered.connect(self.softwareManager)
softwareCheckUpgradesAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("system-software-update"),_("Check for updates now..."))
self.connect(softwareCheckUpgradesAction, SIGNAL("triggered()"), self.softwareCheckUpgrades)
softwareCheckUpgradesAction.triggered.connect(self.softwareCheckUpgrades)
softwareBaseInstallsAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("openmamba"),_("openmamba components..."))
self.connect(softwareBaseInstallsAction, SIGNAL("triggered()"), self.softwareBaseInstalls)
softwareBaseInstallsAction.triggered.connect(self.softwareBaseInstalls)
# network menu
global networkFirewallDisableProcess, networkFirewallEnableProcess, networkFirewallConfigureProcess, networkProxyProcess
@ -69,22 +71,22 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
networkMenu = menu.addMenu(QtGui.QIcon.fromTheme("preferences-system-network"),_("Network"))
networkFirewallMenu = networkMenu.addMenu(QtGui.QIcon.fromTheme("security-medium"),_("Firewall"))
networkFirewallDisableAction = networkFirewallMenu.addAction(QtGui.QIcon.fromTheme("security-low"),_("Disable"))
self.connect(networkFirewallDisableAction, SIGNAL("triggered()"), self.networkFirewallDisable)
self.connect(networkFirewallDisableProcess, SIGNAL("finished(int,QProcess::ExitStatus)"), self.networkFirewallDisableMessage)
networkFirewallDisableAction.triggered.connect(self.networkFirewallDisable)
networkFirewallDisableProcess.finished.connect(self.networkFirewallDisableMessage)
networkFirewallEnableAction = networkFirewallMenu.addAction(QtGui.QIcon.fromTheme("security-high"),_("Enable"))
self.connect(networkFirewallEnableAction, SIGNAL("triggered()"), self.networkFirewallEnable)
self.connect(networkFirewallEnableProcess, SIGNAL("finished(int,QProcess::ExitStatus)"), self.networkFirewallEnableMessage)
networkFirewallEnableAction.triggered.connect(self.networkFirewallEnable)
networkFirewallEnableProcess.finished.connect(self.networkFirewallEnableMessage)
networkFirewallConfigureAction = networkFirewallMenu.addAction(QtGui.QIcon.fromTheme("security-medium"),_("Configure..."))
self.connect(networkFirewallConfigureAction, SIGNAL("triggered()"), self.networkFirewallConfigure)
networkFirewallConfigureAction.triggered.connect(self.networkFirewallConfigure)
networkProxyAction = networkMenu.addAction(QtGui.QIcon.fromTheme("network-server"),_("Proxy..."))
self.connect(networkProxyAction, SIGNAL("triggered()"), self.networkProxy)
self.connect(SRPMUpdateProcess, SIGNAL("finished(int,QProcess::ExitStatus)"), self.SRPMSCheckUpgrade)
networkProxyAction.triggered.connect(self.networkProxy)
SRPMUpdateProcess.finished.connect(self.SRPMSCheckUpgrade)
# about box
aboutAction = menu.addSeparator()
aboutAction = menu.addAction(QtGui.QIcon.fromTheme("help-about"),_("About"))
self.connect(aboutAction, SIGNAL("triggered()"), self.about)
aboutAction.triggered.connect(self.about)
self.setContextMenu(menu)
self.setToolTip(_("openmamba control center"))
@ -95,6 +97,7 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
# the first time check for SRPMS updates after 4 minutes
checkSRPMSUpdatesTimer.start( 4 * 60000 )
def setProxyForSmart(self):
setProxyProcess = QtCore.QProcess(self)
pf = libproxy.ProxyFactory()
@ -109,7 +112,7 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
break
def iconActivated(self, reason):
if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick):
if reason in (QtWidgets.QSystemTrayIcon.Trigger, QtWidgets.QSystemTrayIcon.DoubleClick):
menu.popup(self.geometry().center())
def about(self):
@ -123,7 +126,7 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
v.close()
else:
version = _("Error: Unable to find /etc/openmamba-release")
QtGui.QMessageBox.about(menu, _("About"),
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"
@ -144,14 +147,18 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
def softwareManager(self):
self.setProxyForSmart()
if desktop_session == 'kde':
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 == 'kde':
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")
@ -188,14 +195,16 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
self.showMessage("Firewall", _("Could not enable firewall"))
def networkFirewallConfigure(self):
if desktop_session == 'kde':
networkFirewallConfigureProcess.execute("/opt/kde/bin/kcmshell4", QtCore.QStringList(list(set(['ufw']))))
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 == 'kde':
networkProxyProcess.execute("/opt/kde/bin/kcmshell5", QtCore.QStringList(list(set(['proxy']))))
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()
@ -248,13 +257,13 @@ class SystemTrayIcon(QtGui.QSystemTrayIcon):
def main():
app = QtGui.QApplication(sys.argv)
app = QtWidgets.QApplication(sys.argv)
if (app.isSessionRestored()):
app.exit(1)
else:
app.setQuitOnLastWindowClosed(0)
gettext.install('mambatray', '/usr/share/locale', unicode=1)
w = QtGui.QWidget()
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)
trayIcon.show()