From 93a7dcc4a10fdadd67f2e9616b62a472fc58d1de Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Tue, 2 Apr 2019 18:01:40 +0200 Subject: [PATCH] Other basic fixes to avoid crashing. Release 3.0.2 --- VERSION | 2 +- src/mambatray | 72 ++++++++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/VERSION b/VERSION index 96c019b..6d1ae1c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -VERSION=3.0.1 +VERSION=3.0.2 diff --git a/src/mambatray b/src/mambatray index 1427723..d85396b 100755 --- a/src/mambatray +++ b/src/mambatray @@ -9,11 +9,13 @@ import os import gettext import libproxy from PyQt5.QtCore import pyqtSignal -from PyQt5 import QtGui -from PyQt5 import QtWidgets +from PyQt5.QtGui import QIcon +from PyQt5.QtWidgets import QSystemTrayIcon, QApplication, QMenu, QMainWindow, QMessageBox, QWidget from PyQt5 import QtCore -class SystemTrayIcon(QtWidgets.QSystemTrayIcon): +class SystemTrayIcon(QSystemTrayIcon): + + context_menu = None def __init__(self, icon, parent=None): global w, menu, contatore, srpm, lista, NetsrpmsArg, nOre, desktop_session @@ -23,8 +25,8 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): lista = [] contatore = 0 w = parent - QtWidgets.QSystemTrayIcon.__init__(self, icon, parent) - menu = QtWidgets.QMenu(parent) + QSystemTrayIcon.__init__(self, icon, parent) + menu = QMenu(parent) try: desktop_session = os.path.basename(os.getenv('DESKTOP_SESSION')) @@ -54,14 +56,14 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): softwareBaseInstallsProcess = QtCore.QProcess(self) dcopServerProcess = QtCore.QProcess(self) - softwareMenu = menu.addMenu(QtGui.QIcon.fromTheme("applications-system"),_("Software")) - softwareManageAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("applications-other"),_("Add/Remove software packages...")) + softwareMenu = menu.addMenu(QIcon.fromTheme("applications-system"),_("Software")) + softwareManageAction = softwareMenu.addAction(QIcon.fromTheme("applications-other"),_("Add/Remove software packages...")) softwareManageAction.triggered.connect(self.softwareManager) - softwareCheckUpgradesAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("system-software-update"),_("Check for updates now...")) + softwareCheckUpgradesAction = softwareMenu.addAction(QIcon.fromTheme("system-software-update"),_("Check for updates now...")) softwareCheckUpgradesAction.triggered.connect(self.softwareCheckUpgrades) - softwareBaseInstallsAction = softwareMenu.addAction(QtGui.QIcon.fromTheme("openmamba"),_("openmamba components...")) + softwareBaseInstallsAction = softwareMenu.addAction(QIcon.fromTheme("openmamba"),_("openmamba components...")) softwareBaseInstallsAction.triggered.connect(self.softwareBaseInstalls) # network menu @@ -71,27 +73,27 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): networkFirewallConfigureProcess = QtCore.QProcess(self) networkProxyProcess = QtCore.QProcess(self) - 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")) + networkMenu = menu.addMenu(QIcon.fromTheme("preferences-system-network"),_("Network")) + networkFirewallMenu = networkMenu.addMenu(QIcon.fromTheme("security-medium"),_("Firewall")) + networkFirewallDisableAction = networkFirewallMenu.addAction(QIcon.fromTheme("security-low"),_("Disable")) networkFirewallDisableAction.triggered.connect(self.networkFirewallDisable) networkFirewallDisableProcess.finished.connect(self.networkFirewallDisableMessage) - networkFirewallEnableAction = networkFirewallMenu.addAction(QtGui.QIcon.fromTheme("security-high"),_("Enable")) + networkFirewallEnableAction = networkFirewallMenu.addAction(QIcon.fromTheme("security-high"),_("Enable")) networkFirewallEnableAction.triggered.connect(self.networkFirewallEnable) networkFirewallEnableProcess.finished.connect(self.networkFirewallEnableMessage) - networkFirewallConfigureAction = networkFirewallMenu.addAction(QtGui.QIcon.fromTheme("security-medium"),_("Configure...")) + networkFirewallConfigureAction = networkFirewallMenu.addAction(QIcon.fromTheme("security-medium"),_("Configure...")) networkFirewallConfigureAction.triggered.connect(self.networkFirewallConfigure) - networkProxyAction = networkMenu.addAction(QtGui.QIcon.fromTheme("network-server"),_("Proxy...")) + networkProxyAction = networkMenu.addAction(QIcon.fromTheme("network-server"),_("Proxy...")) networkProxyAction.triggered.connect(self.networkProxy) SRPMUpdateProcess.finished.connect(self.SRPMSCheckUpgrade) # about box aboutAction = menu.addSeparator() - aboutAction = menu.addAction(QtGui.QIcon.fromTheme("help-about"),_("About")) + aboutAction = menu.addAction(QIcon.fromTheme("help-about"),_("About")) aboutAction.triggered.connect(self.about) - self.setContextMenu(menu) + self.context_menu = menu self.setToolTip(_("openmamba control center")) self.activated.connect(self.iconActivated) @@ -115,7 +117,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): break def iconActivated(self, reason): - if reason in (QtWidgets.QSystemTrayIcon.Trigger, QtWidgets.QSystemTrayIcon.DoubleClick): + if reason in (QSystemTrayIcon.Trigger, QSystemTrayIcon.DoubleClick): menu.popup(self.geometry().center()) def about(self): @@ -125,15 +127,15 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): v = open(path, 'r') version = v.read() a = self.FormattaInfo() - version = "" + version = "" v.close() else: version = _("Error: Unable to find /etc/openmamba-release") - QtWidgets.QMessageBox.about(menu, _("About"), + QMessageBox.about(menu, _("About"), "
"+_("openmamba control center")+"" "

Copyright(c) 2011-2019 by Silvan Calarco" - "
Copyright(c) 2011 by michiamophil" - "

"+_("System info:")+"
" + "
Copyright(c) 2011 by michiamophil" + "

"+_("System info:")+"" ""+_(version)+"
http://openmamba.org
") def FormattaInfo(self): @@ -149,7 +151,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): return networkOnlineProcess.execute("/usr/bin/nm-online",['-q','-x']) def softwareManager(self): - self.setProxyForSmart() + #self.setProxyForSmart() if desktop_session == 'plasma': softwareManagerProcess.execute("/usr/bin/plasma-discover", ['--mode', 'Browsing']) elif desktop_session == 'kde': @@ -158,7 +160,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): softwareManagerProcess.execute("/usr/bin/gpk-application") def softwareCheckUpgrades(self): - self.setProxyForSmart() + #self.setProxyForSmart() if desktop_session == 'plasma': softwareCheckUpgradesProcess.start("/usr/bin/plasma-discover", ['--mode', 'Update']) elif desktop_session == 'kde': @@ -167,7 +169,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): softwareCheckUpgradesProcess.start("/usr/bin/gpk-update-viewer") def refreshPackagesCache(self): - self.setProxyForSmart() + #self.setProxyForSmart() refreshPackagesTimer.stop() refreshPackagesCacheProcess.start("/usr/bin/pkcon", ['refresh']) @@ -186,7 +188,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): if (status == QtCore.QProcess.NormalExit): self.showMessage("Firewall", _("Firewall disabled in current session")) else: - self.showMessage("Firewall", _("Could not disable firewall")) + self.showMessage("Firewall", _("Could not disable firewall")) def networkFirewallEnable(self): networkFirewallEnableProcess.start("sudo",['/usr/sbin/ufw','enable']) @@ -210,7 +212,7 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): networkProxyProcess.execute("/opt/kde/bin/kcmshell4", list(set(['proxy']))) elif desktop_session == 'gnome': networkProxyProcess.execute("/usr/bin/gnome-control-center", "network") - self.setProxyForSmart() + #self.setProxyForSmart() def SRPMSCheckUpgradeList(self): checkSRPMSUpdatesTimer.stop() @@ -240,8 +242,8 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): global NetsrpmsArg, lista if not lista == []: Lista = self.Lista() - msg = QtWidgets.QMessageBox.question(menu, (_("Not Open Source openmamba components")), (_("The following components are available for update: ") + "\n\n" + Lista + "\n\n" + _("Ok to proceed?")), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.Yes) - if msg == QtWidgets.QMessageBox.Yes: + msg = QMessageBox.question(menu, (_("Not Open Source openmamba components")), (_("The following components are available for update: ") + "\n\n" + Lista + "\n\n" + _("Ok to proceed?")), QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) + if msg == QMessageBox.Yes: NetsrpmsArg = '-u' self.SRPMSCheckUpgradeList() else: @@ -257,18 +259,22 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon): testo = testo + a + ', ' return testo[0:len(testo)-2] + def main(): - app = QtWidgets.QApplication(sys.argv) + app = QApplication(sys.argv) if (app.isSessionRestored()): app.exit(1) else: app.setQuitOnLastWindowClosed(0) 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) + w = QWidget() + w.setWindowIcon(QIcon.fromTheme("mambatray",QIcon("/usr/share/icons/hicolor/64x64/apps/mambatray.png"))) + trayIcon = SystemTrayIcon(QIcon.fromTheme("mambatray", QIcon("/usr/share/icons/hicolor/32x32/apps/mambatray.png")), w) trayIcon.show() + trayIcon.setContextMenu(menu) + trayIcon.setVisible(True) sys.exit(app.exec_()) + if __name__ == '__main__': main()