本文整理汇总了Python中PyQt4.QtGui.QSystemTrayIcon.setStatus方法的典型用法代码示例。如果您正苦于以下问题:Python QSystemTrayIcon.setStatus方法的具体用法?Python QSystemTrayIcon.setStatus怎么用?Python QSystemTrayIcon.setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QSystemTrayIcon
的用法示例。
在下文中一共展示了QSystemTrayIcon.setStatus方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tray
# 需要导入模块: from PyQt4.QtGui import QSystemTrayIcon [as 别名]
# 或者: from PyQt4.QtGui.QSystemTrayIcon import setStatus [as 别名]
class Tray(QObject):
activated = pyqtSignal()
def __init__(self, parent, title, icon):
QObject.__init__(self)
# Setup contextual menu
if kde:
self.menu = KMenu(parent)
self.tray = KStatusNotifierItem(parent)
self.tray.setStatus(KStatusNotifierItem.Passive)
self.tray.setCategory(KStatusNotifierItem.ApplicationStatus)
self.tray.setAssociatedWidget(parent)
self.tray.setStandardActionsEnabled(False)
self.tray.activateRequested.connect(self._activateRequested)
else:
self.menu = QMenu()
self.tray = QSystemTrayIcon()
self.tray.activated.connect(self._activated)
self.setIcon(icon)
self.setTitle(title)
if not kde:
self.tray.show()
self.tray.setContextMenu(self.menu)
def setActive(self, active=True):
if kde:
self.tray.setStatus(KStatusNotifierItem.Active if active else KStatusNotifierItem.Passive)
def setTitle(self, title):
if kde:
self.tray.setTitle(title)
self.tray.setToolTipTitle(title)
else:
self.tray.setToolTip(title)
self.menu.setTitle(title)
def setToolTipSubTitle(self, subtitle):
if kde:
self.tray.setToolTipSubTitle(subtitle)
def setIcon(self, icon):
if kde:
self.tray.setIconByPixmap(icon)
self.tray.setToolTipIconByPixmap(icon)
else:
self.tray.setIcon(icon)
def showMessage(self, title, message, icon=None):
if kde:
self.tray.showMessage(title, message, "network-server")
else:
self.tray.showMessage(title, message, QSystemTrayIcon.Information if icon is None else icon)
def _activated(self, reason):
if reason == QSystemTrayIcon.DoubleClick:
self.activated.emit()
def _activateRequested(self, active, pos):
self.activated.emit()
示例2: GlobalSysTray
# 需要导入模块: from PyQt4.QtGui import QSystemTrayIcon [as 别名]
# 或者: from PyQt4.QtGui.QSystemTrayIcon import setStatus [as 别名]
#.........这里部分代码省略.........
def isTrayAvailable(self):
if TrayEngine in ("KDE", "Qt"):
return QSystemTrayIcon.isSystemTrayAvailable()
elif TrayEngine == "AppIndicator":
# Ubuntu/Unity always has a systray
return True
else:
return False
def handleQtCloseEvent(self, event):
if self.isTrayAvailable() and self._parent.isVisible():
event.accept()
self.__hideShowCall()
return
self.close()
QMainWindow.closeEvent(self._parent, event)
# -------------------------------------------------------------------------------------------
def show(self):
if not self._quit_added:
self._quit_added = True
if TrayEngine != "KDE":
self.addSeparator("_quit")
self.addAction("show", self._parent.tr("Minimize"))
self.addAction("quit", self._parent.tr("Quit"))
self.setActionIcon("quit", "application-exit")
self.connect("show", self.__hideShowCall)
self.connect("quit", self.__quitCall)
if TrayEngine == "KDE":
self.tray.setStatus(KStatusNotifierItem.Active)
elif TrayEngine == "AppIndicator":
self.tray.set_status(AppIndicator.IndicatorStatus.ACTIVE)
elif TrayEngine == "Qt":
self.tray.show()
def hide(self):
if TrayEngine == "KDE":
self.tray.setStatus(KStatusNotifierItem.Passive)
elif TrayEngine == "AppIndicator":
self.tray.set_status(AppIndicator.IndicatorStatus.PASSIVE)
elif TrayEngine == "Qt":
self.tray.hide()
def close(self):
if TrayEngine == "KDE":
self.menu.close()
elif TrayEngine == "AppIndicator":
if self._gtk_running:
self._gtk_running = False
Gtk.main_quit()
elif TrayEngine == "Qt":
self.menu.close()
def exec_(self, app):
self._app = app
if TrayEngine == "AppIndicator":
self._gtk_running = True
return Gtk.main()
else:
return app.exec_()
# -------------------------------------------------------------------------------------------