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