From 948776c31cb39fce93db971c73336f91c4a2b30a Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 24 May 2016 21:08:52 +0300 Subject: [PATCH] tray menu update --- src/main.py | 40 +++++++++++++++++++++++++++++++++++++--- src/profile.py | 8 +++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index 6b784ae..c3c8756 100644 --- a/src/main.py +++ b/src/main.py @@ -11,6 +11,7 @@ import styles.style import locale import toxencryptsave from passwordscreen import PasswordScreen +import profile class Toxygen(object): @@ -131,23 +132,56 @@ class Toxygen(object): self.tray.setObjectName('tray') class Menu(QtGui.QMenu): + + def newStatus(self, status): + profile.Profile.get_instance().set_status(status) + self.aboutToShow() + self.hide() + + def aboutToShow(self): + status = profile.Profile.get_instance().status + act = self.act + if status is None: + self.actions()[1].setVisible(False) + else: + self.actions()[1].setVisible(True) + act.actions()[0].setChecked(False) + act.actions()[1].setChecked(False) + act.actions()[2].setChecked(False) + act.actions()[status].setChecked(True) + def languageChange(self, *args, **kwargs): self.actions()[0].setText(QtGui.QApplication.translate('tray', 'Open Toxygen', None, QtGui.QApplication.UnicodeUTF8)) - self.actions()[1].setText(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8)) + self.actions()[1].setText(QtGui.QApplication.translate('tray', 'Set status', None, QtGui.QApplication.UnicodeUTF8)) + self.actions()[2].setText(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8)) + self.act.actions()[0].setText(QtGui.QApplication.translate('tray', 'Online', None, QtGui.QApplication.UnicodeUTF8)) + self.act.actions()[1].setText(QtGui.QApplication.translate('tray', 'Away', None, QtGui.QApplication.UnicodeUTF8)) + self.act.actions()[2].setText(QtGui.QApplication.translate('tray', 'Busy', None, QtGui.QApplication.UnicodeUTF8)) m = Menu() show = m.addAction(QtGui.QApplication.translate('tray', 'Open Toxygen', None, QtGui.QApplication.UnicodeUTF8)) + sub = m.addMenu(QtGui.QApplication.translate('tray', 'Set status', None, QtGui.QApplication.UnicodeUTF8)) + onl = sub.addAction(QtGui.QApplication.translate('tray', 'Online', None, QtGui.QApplication.UnicodeUTF8)) + away = sub.addAction(QtGui.QApplication.translate('tray', 'Away', None, QtGui.QApplication.UnicodeUTF8)) + busy = sub.addAction(QtGui.QApplication.translate('tray', 'Busy', None, QtGui.QApplication.UnicodeUTF8)) + onl.setCheckable(True) + away.setCheckable(True) + busy.setCheckable(True) + m.act = sub exit = m.addAction(QtGui.QApplication.translate('tray', 'Exit', None, QtGui.QApplication.UnicodeUTF8)) def show_window(): if not self.ms.isActiveWindow(): self.ms.setWindowState(self.ms.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive) self.ms.activateWindow() - if self.ms.isHidden(): - self.ms.show() + self.ms.show() m.connect(show, QtCore.SIGNAL("triggered()"), show_window) m.connect(exit, QtCore.SIGNAL("triggered()"), lambda: app.exit()) + m.connect(m, QtCore.SIGNAL("aboutToShow()"), lambda: m.aboutToShow()) + sub.connect(onl, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(0)) + sub.connect(away, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(1)) + sub.connect(busy, QtCore.SIGNAL("triggered()"), lambda: m.newStatus(2)) self.tray.setContextMenu(m) self.tray.show() diff --git a/src/profile.py b/src/profile.py index 67b61f5..4117387 100644 --- a/src/profile.py +++ b/src/profile.py @@ -329,9 +329,11 @@ class Profile(Contact, Singleton): Changes status of user (online, away, busy) """ if self._status is not None: - status = (self._status + 1) % 3 - super(self.__class__, self).set_status(status) - self._tox.self_set_status(status) + self.set_status((self._status + 1) % 3) + + def set_status(self, status): + super(Profile, self).set_status(status) + self._tox.self_set_status(status) def set_name(self, value): super(self.__class__, self).set_name(value)