本文整理汇总了Python中qtpy.QtWidgets.QMenu.setDisabled方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.setDisabled方法的具体用法?Python QMenu.setDisabled怎么用?Python QMenu.setDisabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QMenu
的用法示例。
在下文中一共展示了QMenu.setDisabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: context_menu_requested
# 需要导入模块: from qtpy.QtWidgets import QMenu [as 别名]
# 或者: from qtpy.QtWidgets.QMenu import setDisabled [as 别名]
def context_menu_requested(self, event, right_click=False):
"""
Custom context menu.
"""
if self.proxy_model is None:
return
self._menu = QMenu(self)
index = self.currentIndex()
model_index = self.proxy_model.mapToSource(index)
row_data = self.source_model.row(model_index.row())
column = model_index.column()
name = row_data[const.COL_NAME]
# package_type = row_data[const.COL_PACKAGE_TYPE]
versions = self.source_model.get_package_versions(name)
current_version = self.source_model.get_package_version(name)
# if column in [const.COL_ACTION, const.COL_VERSION, const.COL_NAME]:
if column in [const.COL_ACTION] and not right_click:
is_installable = self.source_model.is_installable(model_index)
is_removable = self.source_model.is_removable(model_index)
is_upgradable = self.source_model.is_upgradable(model_index)
action_status = self.source_model.action_status(model_index)
actions = []
action_unmark = create_action(
self,
_('Unmark'),
triggered=lambda: self.set_action_status(model_index,
const.ACTION_NONE,
current_version))
action_install = create_action(
self,
_('Mark for installation'),
triggered=lambda: self.set_action_status(model_index,
const.ACTION_INSTALL,
versions[-1]))
action_upgrade = create_action(
self,
_('Mark for upgrade'),
triggered=lambda: self.set_action_status(model_index,
const.ACTION_UPGRADE,
versions[-1]))
action_remove = create_action(
self,
_('Mark for removal'),
triggered=lambda: self.set_action_status(model_index,
const.ACTION_REMOVE,
current_version))
version_actions = []
for version in reversed(versions):
def trigger(model_index=model_index,
action=const.ACTION_INSTALL,
version=version):
return lambda: self.set_action_status(model_index,
status=action,
version=version)
if version == current_version:
version_action = create_action(
self,
version,
icon=QIcon(),
triggered=trigger(model_index,
const.ACTION_INSTALL,
version))
if not is_installable:
version_action.setCheckable(True)
version_action.setChecked(True)
version_action.setDisabled(True)
elif version != current_version:
if ((version in versions and versions.index(version)) >
(current_version in versions and
versions.index(current_version))):
upgrade_or_downgrade_action = const.ACTION_UPGRADE
else:
upgrade_or_downgrade_action = const.ACTION_DOWNGRADE
if is_installable:
upgrade_or_downgrade_action = const.ACTION_INSTALL
version_action = create_action(
self,
version,
icon=QIcon(),
triggered=trigger(model_index,
upgrade_or_downgrade_action,
version))
version_actions.append(version_action)
install_versions_menu = QMenu('Mark for specific version '
'installation', self)
add_actions(install_versions_menu, version_actions)
actions = [action_unmark, action_install, action_upgrade,
action_remove]
actions += [None, install_versions_menu]
install_versions_menu.setEnabled(len(version_actions) > 1)
if action_status is const.ACTION_NONE:
#.........这里部分代码省略.........