本文整理汇总了Python中PyQt5.QtWidgets.QSystemTrayIcon.setVisible方法的典型用法代码示例。如果您正苦于以下问题:Python QSystemTrayIcon.setVisible方法的具体用法?Python QSystemTrayIcon.setVisible怎么用?Python QSystemTrayIcon.setVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QSystemTrayIcon
的用法示例。
在下文中一共展示了QSystemTrayIcon.setVisible方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Systray
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import setVisible [as 别名]
class Systray(QObject):
trayIconMenu = None
def __init__(self, parent):
super().__init__(parent)
self.trayIconMenu = ContextMenu(None)
icon = QIcon(":/image/thunder.ico")
self.trayIcon = QSystemTrayIcon(self)
self.trayIcon.setIcon(icon)
self.trayIcon.setContextMenu(self.trayIconMenu)
self.trayIcon.setVisible(True)
self.trayIcon.activated.connect(self.slotSystrayActivated)
@pyqtSlot(QSystemTrayIcon.ActivationReason)
def slotSystrayActivated(self, reason):
if reason == QSystemTrayIcon.Context: # right
pass
elif reason == QSystemTrayIcon.MiddleClick: # middle
pass
elif reason == QSystemTrayIcon.DoubleClick: # double click
pass
elif reason == QSystemTrayIcon.Trigger: # left
if app.mainWin.isHidden() or app.mainWin.isMinimized():
app.mainWin.restore()
else:
app.mainWin.minimize()
示例2: Systray
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import setVisible [as 别名]
class Systray(QObject):
app = None
trayIconMenu = None
def __init__(self, app):
super().__init__()
self.app = app
self.mainWin = self.app.mainWin
self.trayIconMenu = QMenu(None)
icon = QIcon(":/image/thunder.ico")
self.trayIcon = QSystemTrayIcon(None)
self.trayIcon.setIcon(icon)
self.trayIcon.setContextMenu(self.trayIconMenu)
self.trayIcon.setVisible(True)
self.trayIcon.activated.connect(self.slotSystrayActivated)
self.app.lastWindowClosed.connect(self.slotTeardown)
self.trayIconMenu.addAction(self.mainWin.action_exit)
@pyqtSlot()
def slotTeardown(self):
print("teardown Systray")
# On Ubuntu 13.10, systrayicon won't destroy itself gracefully, stops the whole program from exiting.
del self.trayIcon
@pyqtSlot(QSystemTrayIcon.ActivationReason)
def slotSystrayActivated(self, reason):
if reason == QSystemTrayIcon.Context: # right
pass
elif reason == QSystemTrayIcon.MiddleClick: # middle
pass
elif reason == QSystemTrayIcon.DoubleClick: # double click
pass
elif reason == QSystemTrayIcon.Trigger: # left
if self.mainWin.isHidden() or self.mainWin.isMinimized():
self.mainWin.restore()
else:
self.mainWin.minimize()
示例3: QtApplication
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import setVisible [as 别名]
#.........这里部分代码省略.........
self._preferences_filename = Resources.getStoragePath(Resources.Preferences, self._app_name + ".cfg")
# FIXME: This is done here because we now use "plugins.json" to manage plugins instead of the Preferences file,
# but the PluginRegistry will still import data from the Preferences files if present, such as disabled plugins,
# so we need to reset those values AFTER the Preferences file is loaded.
self._plugin_registry.initializeAfterPluginsAreLoaded()
# Check if we have just updated from an older version
self._preferences.addPreference("general/last_run_version", "")
last_run_version_str = self._preferences.getValue("general/last_run_version")
if not last_run_version_str:
last_run_version_str = self._version
last_run_version = Version(last_run_version_str)
current_version = Version(self._version)
if last_run_version < current_version:
self._just_updated_from_old_version = True
self._preferences.setValue("general/last_run_version", str(current_version))
self._preferences.writeToFile(self._preferences_filename)
# Preferences: recent files
self._preferences.addPreference("%s/recent_files" % self._app_name, "")
file_names = self._preferences.getValue("%s/recent_files" % self._app_name).split(";")
for file_name in file_names:
if not os.path.isfile(file_name):
continue
self._recent_files.append(QUrl.fromLocalFile(file_name))
if not self.getIsHeadLess():
# Initialize System tray icon and make it invisible because it is used only to show pop up messages
self._tray_icon = None
if self._tray_icon_name:
self._tray_icon = QIcon(Resources.getPath(Resources.Images, self._tray_icon_name))
self._tray_icon_widget = QSystemTrayIcon(self._tray_icon)
self._tray_icon_widget.setVisible(False)
def initializeEngine(self) -> None:
# TODO: Document native/qml import trickery
self._qml_engine = QQmlApplicationEngine(self)
self._qml_engine.setOutputWarningsToStandardError(False)
self._qml_engine.warnings.connect(self.__onQmlWarning)
for path in self._qml_import_paths:
self._qml_engine.addImportPath(path)
if not hasattr(sys, "frozen"):
self._qml_engine.addImportPath(os.path.join(os.path.dirname(__file__), "qml"))
self._qml_engine.rootContext().setContextProperty("QT_VERSION_STR", QT_VERSION_STR)
self._qml_engine.rootContext().setContextProperty("screenScaleFactor", self._screenScaleFactor())
self.registerObjects(self._qml_engine)
Bindings.register()
self._qml_engine.load(self._main_qml)
self.engineCreatedSignal.emit()
recentFilesChanged = pyqtSignal()
@pyqtProperty("QVariantList", notify=recentFilesChanged)
def recentFiles(self) -> List[QUrl]:
return self._recent_files
def _onJobFinished(self, job: Job) -> None:
if isinstance(job, WriteFileJob):
if not job.getResult() or not job.getAddToRecentFiles():
# For a write file job, if it failed or it doesn't need to be added to the recent files list, we do not
示例4: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import setVisible [as 别名]
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.running = False
self.setWindowTitle('PySwicher v{}'.format(VERSION))
# Logging config
self.log_textbox = QPlainTextEditLogger(self)
logging.getLogger().addHandler(self.log_textbox)
self.log_textbox.setFormatter(logging.Formatter('[%(asctime)s][%(levelname)s]: %(message)s'))
self.log_textbox.setLevel(self.get_numeric_loglevel(options['log_level']))
self.log_to_file = False
# System tray configuration
self.tray_menu = QMenu(self)
self.systemTrayIcon = QSystemTrayIcon()
self.systemTrayIcon.setVisible(False)
self.systemTrayIcon.setIcon(QtGui.QIcon('C:\\Users\\Admin\\Pictures\\tray_stop.jpg'))
self.systemTrayIcon.activated.connect(self.sys_tray)
self.exit_action = self.tray_menu.addAction('Exit')
self.exit_action.triggered.connect(self.exit_app)
self.systemTrayIcon.setContextMenu(self.tray_menu)
self.click_tray_timer = QtCore.QTimer(self) # Fix for systemtray click trigger
self.click_tray_timer.setSingleShot(True)
self.click_tray_timer.timeout.connect(self.click_timeout)
self.main_window_ui()
self.starter()
def set_log_to_file(self, state):
logger = logging.getLogger(__name__)
file = logging.FileHandler(HOME + '\\switcher.log')
if state == QtCore.Qt.Checked:
self.log_to_file = True
file.setFormatter(
logging.Formatter('%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s] %(message)s'))
file.setLevel(self.get_numeric_loglevel(options['log_level']))
logger.addHandler(file)
else:
if 'file' in logger.handlers:
logger.removeHandler(file)
self.log_to_file = False
def starter(self):
if not self.running:
self.running = True
self.start_btn.setText('Stop switcher')
self.systemTrayIcon.setIcon(QtGui.QIcon('C:\\Users\\Admin\\Pictures\\tray_stop.jpg'))
start_app()
elif self.running:
self.running = False
self.start_btn.setText('Start switcher')
self.systemTrayIcon.setIcon(QtGui.QIcon('C:\\Users\\Admin\\Pictures\\tray_start.jpg'))
stop_app()
return
def main_window_ui(self):
grid = QGridLayout(self)
self.setLayout(grid)
grid.setSpacing(5)
# Here goes options layout
self.topleft = QFrame(self)
self.topleft.setFrameShape(QFrame.StyledPanel)
self.topleft_grid = QGridLayout(self)
self.topleft.setLayout(self.topleft_grid)
self.switch_comb_label = QLabel('Switch combination:')
self.switch_comb_text = QLineEdit()
self.switch_comb_text.setText(options['switch_combination'])
self.hotkey_label = QLabel('Hotkey:')
self.hotkey_comb_text = QLineEdit()
self.hotkey_comb_text.setText(options['hotkey'])
self.topleft_grid.addWidget(self.switch_comb_label, 0, 0)
self.topleft_grid.addWidget(self.switch_comb_text, 1, 0)
self.topleft_grid.addWidget(self.hotkey_label, 2, 0)
self.topleft_grid.addWidget(self.hotkey_comb_text, 3, 0)
grid.addWidget(self.topleft, 0, 0)
self.topright = QFrame(self)
self.topright.setFrameShape(QFrame.StyledPanel)
self.topright_grid = QGridLayout(self)
self.topright.setLayout(self.topright_grid)
self.info_label = QLabel('===INFO===')
self.info_label.setAlignment(QtCore.Qt.AlignHCenter)
self.info_author = QLabel('Author: Kurashov Sergey')
self.info_author.setAlignment(QtCore.Qt.AlignHCenter)
self.info_contacts = QLabel('Contacts: [email protected]')
self.info_contacts.setAlignment(QtCore.Qt.AlignHCenter)
self.info_sourcecode = QLabel('<a href="https://github.com/shimielder/win_switcher">Sourcecode on GitHub</a>')
self.info_sourcecode.setAlignment(QtCore.Qt.AlignHCenter)
self.info_sourcecode.setOpenExternalLinks(True)
#.........这里部分代码省略.........
示例5: Parse99
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import setVisible [as 别名]
#.........这里部分代码省略.........
elif self.settings.get_value('general', 'current_character') is None:
self._system_tray.showMessage(
"Parse99",
"No character has been selected. \
Please choose a character from the Character menu."
)
valid = False
return valid
def toggle(self, switch):
if switch == 'off':
if self._thread is not None:
self._timer.stop()
self._thread.stop()
self._thread.join()
elif switch == 'on':
if self._settings_valid():
characters = self.settings.get_value('characters', None)
log_file = characters[
self.settings.get_value('general', 'current_character')
]['log_file']
self._thread = FileReader(
log_file,
int(self.settings.get_value('general', 'parse_interval'))
)
self._thread.start()
self._timer.start(
1000 *
int(self.settings.get_value('general', 'parse_interval'))
)
def _parse(self):
for line in self._thread.get_new_lines():
for plugin in self._plugins.keys():
if self._plugins[plugin].is_active():
self._plugins[plugin].parse(line)
def _get_menu(self):
# main menu
menu = QMenu()
main_menu_action_group = QActionGroup(menu)
main_menu_action_group.setObjectName("main")
# character menu
map_action = QAction(menu)
map_action.setText("Toggle Map")
main_menu_action_group.addAction(map_action)
separator = QAction(menu)
separator.setSeparator(True)
main_menu_action_group.addAction(separator)
characters_action = QAction(menu)
characters_action.setText("Switch Characters")
main_menu_action_group.addAction(characters_action)
separator = QAction(menu)
separator.setSeparator(True)
main_menu_action_group.addAction(separator)
settings_action = QAction(menu)
settings_action.setText("Settings")
main_menu_action_group.addAction(settings_action)
quit_action = QAction(menu)
quit_action.setText("Quit")
main_menu_action_group.addAction(quit_action)
menu.addActions(main_menu_action_group.actions())
menu.triggered[QAction].connect(self._menu_actions)
return menu
def update_menu(self):
self._system_tray.contextMenu().disconnect()
self._system_tray.setContextMenu(self._get_menu())
def _menu_actions(self, action):
# ag = action group, at = action text
ag = action.actionGroup().objectName()
at = action.text().lower()
if ag == "main":
if at == "quit":
try:
self.toggle('off')
self._system_tray.setVisible(False)
for plugin in self._plugins.keys():
self._plugins[plugin].close()
self.quit()
except Exception as e:
print("menu actions, quit", e)
elif at == "settings":
self.edit_settings(tab="general")
elif at == "switch characters":
print("switch characters")
self.edit_settings(tab="characters")
elif at == "toggle map":
self._plugins['maps'].toggle()
def edit_settings(self, **kwargs):
try:
if not self.settings.gui.isVisible():
self.toggle('off')
self.settings.gui.set_show_tab(kwargs.get('tab', None))
self.settings.gui.exec()
self.toggle('on')
except Exception as e:
print("parse99.edit_settings():", e)