本文整理汇总了Python中PyQt5.QtWidgets.QSystemTrayIcon.isSystemTrayAvailable方法的典型用法代码示例。如果您正苦于以下问题:Python QSystemTrayIcon.isSystemTrayAvailable方法的具体用法?Python QSystemTrayIcon.isSystemTrayAvailable怎么用?Python QSystemTrayIcon.isSystemTrayAvailable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QSystemTrayIcon
的用法示例。
在下文中一共展示了QSystemTrayIcon.isSystemTrayAvailable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def start():
# Start logging all events
if '--drop' in sys.argv:
drop_db()
utils.start_app_logging()
if sys.platform == 'win32':
from server import SingleInstance
single_app = SingleInstance()
if single_app.already_running():
running_warning()
app = QApplication(sys.argv)
if not QSystemTrayIcon.isSystemTrayAvailable():
QMessageBox.critical(
None,
"Systray",
"Could not detect a system tray on this system"
)
sys.exit(1)
QApplication.setQuitOnLastWindowClosed(False)
osf = OSFApp()
osf.start()
osf.hide()
sys.exit(app.exec_())
示例2: start_qt_app
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def start_qt_app(config):
import sys
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMessageBox
from quamash import QEventLoop
from ui.main import Window
from ui.qt_gui_connection import qSignal
app = QApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
if not QSystemTrayIcon.isSystemTrayAvailable():
QMessageBox.critical(None, "Systray",
"I couldn't detect any system tray on this system.")
sys.exit(1)
QApplication.setQuitOnLastWindowClosed(False)
gui_connection = qSignal()
window = Window(gui_connection)
def closeApp():
print("Close app signal")
for task in asyncio.Task.all_tasks():
print(task)
task.cancel()
loop.stop()
gui_connection.closeApp.connect(closeApp)
with loop:
#asyncio.run_coroutine_threadsafe(timer(loop, config, gui_connection), loop)
try:
loop.run_until_complete(timer(loop, config, gui_connection))
except asyncio.CancelledError:
pass
示例3: run
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def run(manager, testing=False):
logger.info("Creating trayicon...")
# print(QIcon.themeSearchPaths())
app = QApplication(sys.argv)
# Without this, Ctrl+C will have no effect
signal.signal(signal.SIGINT, exit)
# Ensure cleanup happens on SIGTERM
signal.signal(signal.SIGTERM, exit)
timer = QtCore.QTimer()
timer.start(100) # You may change this if you wish.
timer.timeout.connect(lambda: None) # Let the interpreter run each 500 ms.
if not QSystemTrayIcon.isSystemTrayAvailable():
QMessageBox.critical(None, "Systray", "I couldn't detect any system tray on this system. Either get one or run the ActivityWatch modules from the console.")
sys.exit(1)
widget = QWidget()
icon = QIcon(":/logo.png")
trayIcon = TrayIcon(manager, icon, widget, testing=testing)
trayIcon.show()
trayIcon.showMessage("ActivityWatch", "ActivityWatch is starting up...")
QApplication.setQuitOnLastWindowClosed(False)
# Run the application, blocks until quit
return app.exec_()
示例4: update_tray_icon
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def update_tray_icon(self, use_monochrome_icon):
if not QSystemTrayIcon.isSystemTrayAvailable() or not self.tray_icon:
return
if use_monochrome_icon:
self.tray_icon.setIcon(QIcon(QPixmap(get_image_path('monochrome_tribler.png'))))
else:
self.tray_icon.setIcon(QIcon(QPixmap(get_image_path('tribler.png'))))
self.tray_icon.show()
示例5: create_tray_icon
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def create_tray_icon(self):
if QSystemTrayIcon.isSystemTrayAvailable():
logger.debug('System tray icon is available, showing')
self.tray_icon = QSystemTrayIcon(QIcon(':/i/xnova_logo_32.png'), self)
self.tray_icon.setToolTip(self.tr('XNova Commander'))
self.tray_icon.activated.connect(self.on_tray_icon_activated)
self.tray_icon.show()
else:
self.tray_icon = None
示例6: start
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def start():
start_logging()
# will end application if an instance is already running
singleton = SingleInstance(callback=running_warning)
min_version = None
# Then, if the current version is too old, close the program
try:
r = requests.get(settings.MIN_VERSION_URL, timeout=10)
except requests.exceptions.ConnectionError:
logger.warning('Check for minimum version requirements for OSF-Sync failed '
'because you have no Internet connection')
else:
try:
min_version = r.json()['min-version']
except KeyError as e:
logger.exception(e)
if min_version:
if StrictVersion(settings.VERSION) < StrictVersion(min_version):
# User error message
running_warning(message='You must update to a newer version. '
'You can find newest version at {}'
.format(settings.OFFLINE_PROJECT_ON_OSF),
critical=True)
sys.exit(1)
# Start logging all events
if '--drop' in sys.argv:
drop_db()
app = QApplication(sys.argv)
# connect QT to handle system shutdown signal from os correctly
app.aboutToQuit.connect(exit_gracefully)
if not QSystemTrayIcon.isSystemTrayAvailable():
QMessageBox.critical(None, 'Systray', 'Could not detect a system tray on this system')
sys.exit(1)
QApplication.setQuitOnLastWindowClosed(False)
if not OSFOfflineQT(app).start():
return sys.exit(1)
return sys.exit(app.exec_())
示例7: __init__
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def __init__(self):
super().__init__()
self._supported = QSystemTrayIcon.isSystemTrayAvailable()
self._context_menu = None
self._enabled = False
self._trayicon = None
self._state_icons = {}
for state in (
'disconnected',
'disabled',
'enabled',
):
icon = QIcon(':/state-%s.svg' % state)
if hasattr(icon, 'setIsMask'):
icon.setIsMask(True)
self._state_icons[state] = icon
self._machine = None
self._machine_state = 'disconnected'
self._is_running = False
self._update_state()
示例8: QAction
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
self.quitAction = QAction("&Quit", self,
triggered=QApplication.instance().quit)
def createTrayIcon(self):
self.trayIconMenu = QMenu(self)
self.trayIconMenu.addAction(self.minimizeAction)
self.trayIconMenu.addAction(self.maximizeAction)
self.trayIconMenu.addAction(self.restoreAction)
self.trayIconMenu.addSeparator()
self.trayIconMenu.addAction(self.quitAction)
self.trayIcon = QSystemTrayIcon(self)
self.trayIcon.setContextMenu(self.trayIconMenu)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
if not QSystemTrayIcon.isSystemTrayAvailable():
QMessageBox.critical(None, "Systray",
"I couldn't detect any system tray on this system.")
sys.exit(1)
QApplication.setQuitOnLastWindowClosed(False)
window = Window()
window.show()
sys.exit(app.exec_())
示例9: __init__
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def __init__(self, core_args=None, core_env=None, api_port=None):
QMainWindow.__init__(self)
QCoreApplication.setOrganizationDomain("nl")
QCoreApplication.setOrganizationName("TUDelft")
QCoreApplication.setApplicationName("Tribler")
QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
self.gui_settings = QSettings()
api_port = api_port or int(get_gui_setting(self.gui_settings, "api_port", DEFAULT_API_PORT))
dispatcher.update_worker_settings(port=api_port)
self.navigation_stack = []
self.tribler_started = False
self.tribler_settings = None
self.debug_window = None
self.core_manager = CoreManager(api_port)
self.pending_requests = {}
self.pending_uri_requests = []
self.download_uri = None
self.dialog = None
self.new_version_dialog = None
self.start_download_dialog_active = False
self.request_mgr = None
self.search_request_mgr = None
self.search_suggestion_mgr = None
self.selected_torrent_files = []
self.vlc_available = True
self.has_search_results = False
self.last_search_query = None
self.last_search_time = None
self.start_time = time.time()
self.exception_handler_called = False
self.token_refresh_timer = None
self.shutdown_timer = None
self.add_torrent_url_dialog_active = False
sys.excepthook = self.on_exception
uic.loadUi(get_ui_file_path('mainwindow.ui'), self)
TriblerRequestManager.window = self
self.tribler_status_bar.hide()
self.token_balance_widget.mouseReleaseEvent = self.on_token_balance_click
def on_state_update(new_state):
self.loading_text_label.setText(new_state)
self.core_manager.core_state_update.connect(on_state_update)
self.magnet_handler = MagnetHandler(self.window)
QDesktopServices.setUrlHandler("magnet", self.magnet_handler, "on_open_magnet_link")
self.debug_pane_shortcut = QShortcut(QKeySequence("Ctrl+d"), self)
self.debug_pane_shortcut.activated.connect(self.clicked_menu_button_debug)
self.import_torrent_shortcut = QShortcut(QKeySequence("Ctrl+o"), self)
self.import_torrent_shortcut.activated.connect(self.on_add_torrent_browse_file)
self.add_torrent_url_shortcut = QShortcut(QKeySequence("Ctrl+i"), self)
self.add_torrent_url_shortcut.activated.connect(self.on_add_torrent_from_url)
# Remove the focus rect on OS X
for widget in self.findChildren(QLineEdit) + self.findChildren(QListWidget) + self.findChildren(QTreeWidget):
widget.setAttribute(Qt.WA_MacShowFocusRect, 0)
self.menu_buttons = [self.left_menu_button_home, self.left_menu_button_search, self.left_menu_button_my_channel,
self.left_menu_button_subscriptions, self.left_menu_button_video_player,
self.left_menu_button_downloads, self.left_menu_button_discovered]
self.video_player_page.initialize_player()
self.search_results_page.initialize_search_results_page(self.gui_settings)
self.settings_page.initialize_settings_page()
self.subscribed_channels_page.initialize()
self.edit_channel_page.initialize_edit_channel_page(self.gui_settings)
self.downloads_page.initialize_downloads_page()
self.home_page.initialize_home_page()
self.loading_page.initialize_loading_page()
self.discovering_page.initialize_discovering_page()
self.discovered_page.initialize_discovered_page(self.gui_settings)
self.channel_page.initialize_channel_page(self.gui_settings)
self.trust_page.initialize_trust_page()
self.token_mining_page.initialize_token_mining_page()
self.stackedWidget.setCurrentIndex(PAGE_LOADING)
# Create the system tray icon
if QSystemTrayIcon.isSystemTrayAvailable():
self.tray_icon = QSystemTrayIcon()
use_monochrome_icon = get_gui_setting(self.gui_settings, "use_monochrome_icon", False, is_bool=True)
self.update_tray_icon(use_monochrome_icon)
# Create the tray icon menu
menu = self.create_add_torrent_menu()
show_downloads_action = QAction('Show downloads', self)
show_downloads_action.triggered.connect(self.clicked_menu_button_downloads)
token_balance_action = QAction('Show token balance', self)
token_balance_action.triggered.connect(lambda: self.on_token_balance_click(None))
quit_action = QAction('Quit Tribler', self)
quit_action.triggered.connect(self.close_tribler)
menu.addSeparator()
menu.addAction(show_downloads_action)
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: from PyQt5.QtWidgets import QSystemTrayIcon [as 别名]
# 或者: from PyQt5.QtWidgets.QSystemTrayIcon import isSystemTrayAvailable [as 别名]
def __init__(self, device_name=None, container_path=None, key_file=None, mount_point=None):
""" Command line arguments checks are done here to be able to display a graphical dialog with error messages .
If no arguments were supplied on the command line a setup dialog will be shown.
All commands will be executed from a separate worker process with administrator privileges that gets initialized here.
:param device_name: The device mapper name
:type device_name: str/unicode or None
:param container_path: The path of the container file
:type container_path: str/unicode or None
:param key_file: The path of an optional key file
:type key_file: str/unicode or None
:param mount_point: The path of an optional mount point
:type mount_point: str/unicode or None
"""
super(MainWindow, self).__init__()
self.luks_device_name = device_name
self.encrypted_container = container_path
self.key_file = key_file
self.mount_point = mount_point
self.worker = None
self.is_waiting_for_worker = False
self.is_unlocked = False
self.is_initialized = False
self.has_tray = QSystemTrayIcon.isSystemTrayAvailable()
# L10n: program name - translatable for startmenu titlebar etc
self.setWindowTitle(_('luckyLUKS'))
self.setWindowIcon(QIcon.fromTheme('dialog-password', QApplication.style().standardIcon(QStyle.SP_DriveHDIcon)))
# check if cryptsetup and sudo are installed
not_installed_msg = _('{program_name} executable not found!\nPlease install, eg for Debian/Ubuntu\n`apt-get install {program_name}`')
if not utils.is_installed('cryptsetup'):
show_alert(self, not_installed_msg.format(program_name='cryptsetup'), critical=True)
if not utils.is_installed('sudo'):
show_alert(self, not_installed_msg.format(program_name='sudo'), critical=True)
# quick sanity checks before asking for passwd
if os.getuid() == 0:
show_alert(self, _('Graphical programs should not be run as root!\nPlease call as normal user.'), critical=True)
if self.encrypted_container and not os.path.exists(self.encrypted_container):
show_alert(self, _('Container file not accessible\nor path does not exist:\n\n{file_path}').format(file_path=self.encrypted_container), critical=True)
# only either encrypted_container or luks_device_name supplied
if bool(self.encrypted_container) != bool(self.luks_device_name):
show_alert(self, _('Invalid arguments:\n'
'Please call without any arguments\n'
'or supply both container and name.\n\n'
'<b>{executable} -c CONTAINER -n NAME [-m MOUNTPOINT]</b>\n\n'
'CONTAINER = Path of the encrypted container file\n'
'NAME = A (unique) name to identify the unlocked container\n'
'Optional: MOUNTPOINT = where to mount the encrypted filesystem\n\n'
'If automatic mounting is configured on your system,\n'
'explicitly setting a mountpoint is not required\n\n'
'For more information, visit\n'
'<a href="{project_url}">{project_url}</a>'
).format(executable=os.path.basename(sys.argv[0]),
project_url=PROJECT_URL), critical=True)
# spawn worker process with root privileges
try:
self.worker = utils.WorkerMonitor(self)
# start communication thread
self.worker.start()
except utils.SudoException as se:
show_alert(self, format_exception(se), critical=True)
return
# if no arguments supplied, display dialog to gather this information
if self.encrypted_container is None and self.luks_device_name is None:
from luckyLUKS.setupUI import SetupDialog
sd = SetupDialog(self)
if sd.exec_() == QDialog.Accepted:
self.luks_device_name = sd.get_luks_device_name()
self.encrypted_container = sd.get_encrypted_container()
self.mount_point = sd.get_mount_point()
self.key_file = sd.get_keyfile()
self.is_unlocked = True # all checks in setup dialog -> skip initializing state
else:
# user closed dialog -> quit program
# and check if a keyfile create thread has to be stopped
# the worker process terminates itself when its parent dies
if hasattr(sd, 'create_thread') and sd.create_thread.isRunning():
sd.create_thread.terminate()
QApplication.instance().quit()
return
# center window on desktop
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
# widget content
main_grid = QGridLayout()
main_grid.setSpacing(10)
icon = QLabel()
icon.setPixmap(QIcon.fromTheme('dialog-password', QApplication.style().standardIcon(QStyle.SP_DriveHDIcon)).pixmap(32))
#.........这里部分代码省略.........