本文整理汇总了Python中PySide.QtGui.QMenu.addActions方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.addActions方法的具体用法?Python QMenu.addActions怎么用?Python QMenu.addActions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.addActions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ActivityStatus
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import addActions [as 别名]
class ActivityStatus(QMainWindow):
"""
Main application window, responsible for application lifecycle
"""
def __init__(self):
QMainWindow.__init__(self, None, Qt.FramelessWindowHint)
self.__settings = Settings()
self.__activityManager = ActivityManager(self.__settings)
self.__trayIcon = QSystemTrayIcon(self)
self.__managerController = ActivityManagerControl(self, self.__activityManager)
self.__appMenu = QMenu(self)
self.__closeAction = QAction(self.tr('Close'), self)
self.__appIcon = resources.getIcon('pomidor.png')
self._configureActions()
self._configureMenu()
self._setupTrayIcon()
self._configureMainWindow()
self._setupEventHooks()
logging.debug('Application started')
def _setupTrayIcon(self):
"""
Set initial image on tray icon
"""
self.__trayIcon.setIcon(self.__appIcon)
self.__trayIcon.show()
self.__trayIcon.activated.connect(self._trayIconClicked)
self.__trayIcon.setContextMenu(self.__appMenu)
def _configureMainWindow(self):
"""Configure main window contents"""
self.setCentralWidget(self.__managerController)
self.setWindowIcon(self.__appIcon)
def _setupEventHooks(self):
"""Connect to event hooks provided by the activity manager"""
self.__activityManager.activityStarted += self._hideMainWindow
self.__activityManager.workActivityEnded += self._notifyActivityEnding
self.__activityManager.breakActivityEnded += self._notifyActivityEnding
self.__activityManager.activityTimeChanged += self._showRemainingTime
def _configureMenu(self):
"""Configure application menu, add all actions and separators"""
self.__appMenu.addActions(self.__managerController.actionList)
self.__appMenu.addSeparator()
self.__appMenu.addAction(self.__closeAction)
def _configureActions(self):
"""Configure actions of the main controller"""
self.__closeAction.triggered.connect(_closeApplication)
def _trayIconClicked(self, reason):
"""
Process the click on the tray icon
@param reason: how the icon was clicked
"""
logging.debug('Tray icon clicked')
if reason == QSystemTrayIcon.Trigger:
if self.isVisible():
self._hideMainWindow()
else:
self._showMainWindw()
def closeEvent(self, event):
"""
Prevent main window from closing by clicking on close button
@param event: the event, which controls the operation
@type event: QCloseEvent
"""
event.ignore()
self._hideMainWindow()
def _hideMainWindow(self, _=''):
"""Hide main window from the screen"""
logging.debug('Main window is hidden')
self.setVisible(False)
def _showMainWindw(self):
"""Show main window near-by to the system tray icon"""
logging.debug('Main window is shown')
self.setVisible(True)
trayIconGeometry = self.__trayIcon.geometry()
screenGeometry = QApplication.desktop().screenGeometry(trayIconGeometry.topLeft())
self.move(_calculateWindowPosition(screenGeometry, trayIconGeometry, self.width(),
self.height()))
def _notifyActivityEnding(self):
"""Invoke activity ending action"""
logging.debug('Notifying user about action ending')
process = Process(target=_executeAction, args=(self.__settings.endActivityAction,))
process.start()
self.__trayIcon.setIcon(self.__appIcon)
def _showRemainingTime(self, seconds):
"""
Show remaining time to the user
@param seconds: remaining time
@type seconds: int
"""
#.........这里部分代码省略.........
示例2: MainWindow
# 需要导入模块: from PySide.QtGui import QMenu [as 别名]
# 或者: from PySide.QtGui.QMenu import addActions [as 别名]
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.current_profileid = ""
self.setupUi(self)
self.logger = get_logger('desuratools', 'desuratools.log')
self.logger.info('Logger Created')
boldfont = QApplication.font()
boldfont.setBold(True)
self.addToSteam_action = self.action_factory("Add to Steam", self.add_to_steam)
self.addToSteam_action.setFont(boldfont)
self.installGame_action = self.action_factory("Install", self.install_game)
self.installGame_action.setFont(boldfont)
self.desuraPage_action = self.action_factory("View Profile", self.open_desura_page)
self.uninstallGame_action = self.action_factory("Uninstall", self.uninstall_game)
self.verifyGame_action = self.action_factory("Verify", self.verify_game)
self.ownedGames_menu = QMenu(self)
self.ownedGames_menu.addActions([
self.installGame_action,
self.desuraPage_action
])
self.installedGames_menu = QMenu(self)
self.installedGames_menu.addActions([
self.addToSteam_action,
self.desuraPage_action,
self.uninstallGame_action,
self.verifyGame_action
])
self.selectAllButton.clicked.connect(self.select_all_games)
self.desuraAccountName_verify.clicked.connect(self.populate_owned_games)
self.installButton.clicked.connect(self.process_install_button)
self.generateDesuraReport_action.activated.connect(self.generate_report)
self.tabWidget.currentChanged.connect(self.swap_tabs)
self.ownedGames_list.itemSelectionChanged.connect(self.update_gameinfo)
self.installedGames_list.itemSelectionChanged.connect(self.update_gameinfo)
self.refreshButton.clicked.connect(self.refresh_list)
self.refreshLists_action.activated.connect(self.refresh_all)
self.installedGames_list.customContextMenuRequested.connect(self.show_game_context)
self.installedGames_list.doubleClicked.connect(self.add_to_steam)
self.installedGames_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.ownedGames_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.steamID_input.addItems(steamutils.get_customurls_on_machine())
self.ownedGames_list.addItem("Verify your Desura username to see your owned games")
QApplication.processEvents()
self.loading_dialog = ProgressBarDialog()
self.loading_dialog.show()
QApplication.processEvents()
self.populate_installed_games()
self.load_data()
self.loading_dialog.close()
self.raise_()
def verify_user(self, profileid=None):
if profileid is None:
profileid=self.current_profileid
if len(profileid) == 0:
return False
try:
username = gameslist.username_from_profile_id(profileid)
except gameslist.NoSuchProfileError:
return False
if windows.desura_running(username):
return True
verify_dialog = QMessageBox()
verify_dialog.setText("<b>Verify your identity</b><br />Sign in to Desura to continue with account <b>{0}</b> to confirm your identity".format(username))
verify_dialog.setInformativeText("<i>Waiting for Desura sign-in...</i>")
verify_dialog.setWindowTitle("Sign into Desura to continue")
verify_dialog.setStandardButtons(QMessageBox.Cancel)
verify_dialog.setIcon(QMessageBox.Information)
verify_dialog.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowTitleHint)
desurawaiter = DesuraWaiter(username)
desurawaiter.finished.connect(verify_dialog.close)
desurawaiter.start()
verify_dialog.exec_()
if windows.desura_running(username):
return True
else:
desurawaiter.terminate()
return False
def load_data(self):
try:
with open(os.path.join(windows.data_dir(), 'desuratools.json'), 'r') as savefile:
try:
data = json.loads(savefile.read())
except Exception:
self.desuraAccountName_input.setText("")
#.........这里部分代码省略.........