tray menu update

This commit is contained in:
ingvar1995 2016-05-24 21:08:52 +03:00
parent b2210c21cf
commit 948776c31c
2 changed files with 42 additions and 6 deletions

View File

@ -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()

View File

@ -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)