本文整理汇总了Python中AnyQt.QtWidgets.QAction.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python QAction.setEnabled方法的具体用法?Python QAction.setEnabled怎么用?Python QAction.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QAction
的用法示例。
在下文中一共展示了QAction.setEnabled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VariableEditor
# 需要导入模块: from AnyQt.QtWidgets import QAction [as 别名]
# 或者: from AnyQt.QtWidgets.QAction import setEnabled [as 别名]
class VariableEditor(QWidget):
"""An editor widget for a variable.
Can edit the variable name, and its attributes dictionary.
"""
variable_changed = Signal()
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.var = None
self.setup_gui()
def setup_gui(self):
layout = QVBoxLayout()
self.setLayout(layout)
self.main_form = QFormLayout()
self.main_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
layout.addLayout(self.main_form)
self._setup_gui_name()
self._setup_gui_labels()
def _setup_gui_name(self):
self.name_edit = QLineEdit()
self.main_form.addRow("Name:", self.name_edit)
self.name_edit.editingFinished.connect(self.on_name_changed)
def _setup_gui_labels(self):
vlayout = QVBoxLayout()
vlayout.setContentsMargins(0, 0, 0, 0)
vlayout.setSpacing(1)
self.labels_edit = QTreeView()
self.labels_edit.setEditTriggers(QTreeView.CurrentChanged)
self.labels_edit.setRootIsDecorated(False)
self.labels_model = DictItemsModel()
self.labels_edit.setModel(self.labels_model)
self.labels_edit.selectionModel().selectionChanged.connect(
self.on_label_selection_changed)
# Necessary signals to know when the labels change
self.labels_model.dataChanged.connect(self.on_labels_changed)
self.labels_model.rowsInserted.connect(self.on_labels_changed)
self.labels_model.rowsRemoved.connect(self.on_labels_changed)
vlayout.addWidget(self.labels_edit)
hlayout = QHBoxLayout()
hlayout.setContentsMargins(0, 0, 0, 0)
hlayout.setSpacing(1)
self.add_label_action = QAction(
"+", self,
toolTip="Add a new label.",
triggered=self.on_add_label,
enabled=False,
shortcut=QKeySequence(QKeySequence.New))
self.remove_label_action = QAction(
unicodedata.lookup("MINUS SIGN"), self,
toolTip="Remove selected label.",
triggered=self.on_remove_label,
enabled=False,
shortcut=QKeySequence(QKeySequence.Delete))
button_size = gui.toolButtonSizeHint()
button_size = QSize(button_size, button_size)
button = QToolButton(self)
button.setFixedSize(button_size)
button.setDefaultAction(self.add_label_action)
hlayout.addWidget(button)
button = QToolButton(self)
button.setFixedSize(button_size)
button.setDefaultAction(self.remove_label_action)
hlayout.addWidget(button)
hlayout.addStretch(10)
vlayout.addLayout(hlayout)
self.main_form.addRow("Labels:", vlayout)
def set_data(self, var):
"""Set the variable to edit.
"""
self.clear()
self.var = var
if var is not None:
self.name_edit.setText(var.name)
self.labels_model.set_dict(dict(var.attributes))
self.add_label_action.setEnabled(True)
else:
self.add_label_action.setEnabled(False)
self.remove_label_action.setEnabled(False)
def get_data(self):
"""Retrieve the modified variable.
#.........这里部分代码省略.........
示例2: OWPaintData
# 需要导入模块: from AnyQt.QtWidgets import QAction [as 别名]
# 或者: from AnyQt.QtWidgets.QAction import setEnabled [as 别名]
#.........这里部分代码省略.........
command = SimpleUndoCommand(
lambda: self.class_model.append(newlabel),
lambda: self.class_model.__delitem__(-1)
)
if undoable:
self.undo_stack.push(command)
else:
command.redo()
def remove_selected_class_label(self):
index = self.selected_class_label()
if index is None:
return
label = self.class_model[index]
mask = self.data[:, 2] == index
move_mask = self.data[~mask][:, 2] > index
self.undo_stack.beginMacro("Delete class label")
self.undo_stack.push(UndoCommand(DeleteIndices(mask), self))
self.undo_stack.push(UndoCommand(Move((move_mask, 2), -1), self))
self.undo_stack.push(
SimpleUndoCommand(lambda: self.class_model.__delitem__(index),
lambda: self.class_model.insert(index, label)))
self.undo_stack.endMacro()
newindex = min(max(index - 1, 0), len(self.class_model) - 1)
itemmodels.select_row(self.classValuesView, newindex)
def _class_count_changed(self):
self.labels = list(self.class_model)
self.removeClassLabel.setEnabled(len(self.class_model) > 1)
self.addClassLabel.setEnabled(
len(self.class_model) < self.colors.number_of_colors)
if self.selected_class_label() is None:
itemmodels.select_row(self.classValuesView, 0)
def _class_value_changed(self, index, _):
index = index.row()
newvalue = self.class_model[index]
oldvalue = self.labels[index]
if newvalue != oldvalue:
self.labels[index] = newvalue
# command = Command(
# lambda: self.class_model.__setitem__(index, newvalue),
# lambda: self.class_model.__setitem__(index, oldvalue),
# )
# self.undo_stack.push(command)
def selected_class_label(self):
rows = self.classValuesView.selectedIndexes()
if rows:
return rows[0].row()
else:
return None
def set_current_tool(self, tool):
prev_tool = self.current_tool.__class__
if self.current_tool is not None:
self.current_tool.deactivate()
self.current_tool.editingStarted.disconnect(
self._on_editing_started)
self.current_tool.editingFinished.disconnect(
示例3: DiscreteVariableEditor
# 需要导入模块: from AnyQt.QtWidgets import QAction [as 别名]
# 或者: from AnyQt.QtWidgets.QAction import setEnabled [as 别名]
#.........这里部分代码省略.........
SourceNameRole: ci
}
elif ci is not None and cj is not None:
# rename or reorder
item = {
Qt.EditRole: cj,
EditStateRole: ItemEditState.NoState,
SourcePosRole: ci_index[ci],
SourceNameRole: ci
}
else:
assert False, "invalid mapping: {!r}".format(tr.mapping)
items.append(item)
elif var is not None:
items = [
{Qt.EditRole: c,
EditStateRole: ItemEditState.NoState,
SourcePosRole: i,
SourceNameRole: c}
for i, c in enumerate(var.categories)
]
else:
items = []
with disconnected(self.values_model.dataChanged,
self.on_values_changed):
self.values_model.clear()
self.values_model.insertRows(0, len(items))
for i, item in enumerate(items):
self.values_model.setItemData(
self.values_model.index(i, 0),
item
)
self.add_new_item.actionGroup().setEnabled(var is not None)
def __categories_mapping(self):
# type: () -> CategoriesMappingType
model = self.values_model
source = self.var.categories
res = []
for i in range(model.rowCount()):
midx = model.index(i, 0)
category = midx.data(Qt.EditRole)
source_pos = midx.data(SourcePosRole) # type: Optional[int]
if source_pos is not None:
source_name = source[source_pos]
else:
source_name = None
state = midx.data(EditStateRole)
if state == ItemEditState.Dropped:
res.append((source_name, None))
elif state == ItemEditState.Added:
res.append((None, category))
else:
res.append((source_name, category))
return res
def get_data(self):
"""Retrieve the modified variable
"""
var, tr = super().get_data()
if var is None:
return var, tr
mapping = self.__categories_mapping()
if any(_1 != _2 or _2 != _3
示例4: CanvasView
# 需要导入模块: from AnyQt.QtWidgets import QAction [as 别名]
# 或者: from AnyQt.QtWidgets.QAction import setEnabled [as 别名]
#.........这里部分代码省略.........
self.__setZoomLevel(self.__zoomLevel + 10 * delta / 120)
self.setTransformationAnchor(anchor)
event.accept()
else:
super().wheelEvent(event)
def zoomIn(self):
self.__setZoomLevel(self.__zoomLevel + 10)
def zoomOut(self):
self.__setZoomLevel(self.__zoomLevel - 10)
def zoomReset(self):
"""
Reset the zoom level.
"""
self.__setZoomLevel(100)
def zoomLevel(self):
# type: () -> float
"""
Return the current zoom level.
Level is expressed in percentages; 100 is unscaled, 50 is half size, ...
"""
return self.__effectiveZoomLevel
def setZoomLevel(self, level):
self.__setZoomLevel(level)
def __setZoomLevel(self, scale):
self.__zoomLevel = max(30, min(scale, 300))
scale = round(self.__zoomLevel)
self.__zoomOutAction.setEnabled(scale != 30)
self.__zoomInAction.setEnabled(scale != 300)
if self.__effectiveZoomLevel != scale:
self.__effectiveZoomLevel = scale
transform = QTransform()
transform.scale(scale / 100, scale / 100)
self.setTransform(transform)
self.zoomLevelChanged.emit(scale)
zoomLevelChanged = Signal(float)
zoomLevel_ = Property(
float, zoomLevel, setZoomLevel, notify=zoomLevelChanged
)
def __shouldAutoScroll(self, pos):
if self.__autoScroll:
margin = self.__autoScrollMargin
viewrect = self.contentsRect()
rect = viewrect.adjusted(margin, margin, -margin, -margin)
# only do auto scroll when on the viewport's margins
return not rect.contains(pos) and viewrect.contains(pos)
else:
return False
def __startAutoScroll(self):
self.__autoScrollTimer.start(10)
log.debug("Auto scroll timer started")
def __stopAutoScroll(self):
if self.__autoScrollTimer.isActive():
self.__autoScrollTimer.stop()
log.debug("Auto scroll timer stopped")
示例5: Frame
# 需要导入模块: from AnyQt.QtWidgets import QAction [as 别名]
# 或者: from AnyQt.QtWidgets.QAction import setEnabled [as 别名]
class Frame(QDockWidget):
"""
Widget frame with a handle.
"""
closeRequested = Signal()
def __init__(self, parent=None, widget=None, title=None, **kwargs):
super().__init__(parent, **kwargs)
self.setFeatures(QDockWidget.DockWidgetClosable)
self.setAllowedAreas(Qt.NoDockWidgetArea)
self.__title = ""
self.__icon = ""
self.__focusframe = None
self.__deleteaction = QAction(
"Remove", self, shortcut=QKeySequence.Delete,
enabled=False, triggered=self.closeRequested
)
self.addAction(self.__deleteaction)
if widget is not None:
self.setWidget(widget)
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
if title:
self.setTitle(title)
self.setFocusPolicy(Qt.ClickFocus | Qt.TabFocus)
def setTitle(self, title):
if self.__title != title:
self.__title = title
self.setWindowTitle(title)
self.update()
def setIcon(self, icon):
icon = QIcon(icon)
if self.__icon != icon:
self.__icon = icon
self.setWindowIcon(icon)
self.update()
def paintEvent(self, event):
super().paintEvent(event)
painter = QStylePainter(self)
opt = QStyleOptionFrame()
opt.initFrom(self)
painter.drawPrimitive(QStyle.PE_FrameDockWidget, opt)
painter.end()
def focusInEvent(self, event):
event.accept()
self.__focusframe = QFocusFrame(self)
self.__focusframe.setWidget(self)
self.__deleteaction.setEnabled(True)
def focusOutEvent(self, event):
event.accept()
if self.__focusframe is not None:
self.__focusframe.deleteLater()
self.__focusframe = None
self.__deleteaction.setEnabled(False)
def closeEvent(self, event):
super().closeEvent(event)
event.ignore()
self.closeRequested.emit()