本文整理汇总了Python中AnyQt.QtWidgets.QListView.setItemDelegate方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.setItemDelegate方法的具体用法?Python QListView.setItemDelegate怎么用?Python QListView.setItemDelegate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QListView
的用法示例。
在下文中一共展示了QListView.setItemDelegate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OWDiscretize
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
class OWDiscretize(widget.OWWidget):
name = "Discretize"
description = "Discretize the numeric data features."
icon = "icons/Discretize.svg"
inputs = [InputSignal("Data", Orange.data.Table, "set_data",
doc="Input data table")]
outputs = [OutputSignal("Data", Orange.data.Table,
doc="Table with discretized features")]
settingsHandler = settings.DomainContextHandler()
saved_var_states = settings.ContextSetting({})
default_method = settings.Setting(2)
default_k = settings.Setting(3)
autosend = settings.Setting(True)
#: Discretization methods
Default, Leave, MDL, EqualFreq, EqualWidth, Remove, Custom = range(7)
want_main_area = False
resizing_enabled = False
def __init__(self):
super().__init__()
#: input data
self.data = None
#: Current variable discretization state
self.var_state = {}
#: Saved variable discretization settings (context setting)
self.saved_var_states = {}
self.method = 0
self.k = 5
box = gui.vBox(self.controlArea, self.tr("Default Discretization"))
self.default_bbox = rbox = gui.radioButtons(
box, self, "default_method", callback=self._default_disc_changed)
rb = gui.hBox(rbox)
self.left = gui.vBox(rb)
right = gui.vBox(rb)
rb.layout().setStretch(0, 1)
rb.layout().setStretch(1, 1)
options = self.options = [
self.tr("Default"),
self.tr("Leave numeric"),
self.tr("Entropy-MDL discretization"),
self.tr("Equal-frequency discretization"),
self.tr("Equal-width discretization"),
self.tr("Remove numeric variables")
]
for opt in options[1:]:
t = gui.appendRadioButton(rbox, opt)
# This condition is ugly, but it keeps the same order of
# options for backward compatibility of saved schemata
[right, self.left][opt.startswith("Equal")].layout().addWidget(t)
gui.separator(right, 18, 18)
def _intbox(widget, attr, callback):
box = gui.indentedBox(widget)
s = gui.spin(
box, self, attr, minv=2, maxv=10, label="Num. of intervals:",
callback=callback)
s.setMaximumWidth(60)
s.setAlignment(Qt.AlignRight)
gui.rubber(s.box)
return box.box
self.k_general = _intbox(self.left, "default_k",
self._default_disc_changed)
self.k_general.layout().setContentsMargins(0, 0, 0, 0)
vlayout = QHBoxLayout()
box = gui.widgetBox(
self.controlArea, "Individual Attribute Settings",
orientation=vlayout, spacing=8
)
# List view with all attributes
self.varview = QListView(selectionMode=QListView.ExtendedSelection)
self.varview.setItemDelegate(DiscDelegate())
self.varmodel = itemmodels.VariableListModel()
self.varview.setModel(self.varmodel)
self.varview.selectionModel().selectionChanged.connect(
self._var_selection_changed
)
vlayout.addWidget(self.varview)
# Controls for individual attr settings
self.bbox = controlbox = gui.radioButtons(
box, self, "method", callback=self._disc_method_changed
)
vlayout.addWidget(controlbox)
for opt in options[:5]:
gui.appendRadioButton(controlbox, opt)
self.k_specific = _intbox(controlbox, "k", self._disc_method_changed)
gui.appendRadioButton(controlbox, "Remove attribute")
#.........这里部分代码省略.........
示例2: OWPythonScript
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
class OWPythonScript(widget.OWWidget):
name = "Python Script"
description = "Write a Python script and run it on input data or models."
icon = "icons/PythonScript.svg"
priority = 3150
keywords = ["file", "program"]
class Inputs:
data = Input("Data", Table, replaces=["in_data"],
default=True, multiple=True)
learner = Input("Learner", Learner, replaces=["in_learner"],
default=True, multiple=True)
classifier = Input("Classifier", Model, replaces=["in_classifier"],
default=True, multiple=True)
object = Input("Object", object, replaces=["in_object"],
default=False, multiple=True)
class Outputs:
data = Output("Data", Table, replaces=["out_data"])
learner = Output("Learner", Learner, replaces=["out_learner"])
classifier = Output("Classifier", Model, replaces=["out_classifier"])
object = Output("Object", object, replaces=["out_object"])
signal_names = ("data", "learner", "classifier", "object")
settingsHandler = PrepareSavingSettingsHandler()
libraryListSource = \
Setting([Script("Hello world", "print('Hello world')\n")])
currentScriptIndex = Setting(0)
scriptText = Setting(None, schema_only=True)
splitterState = Setting(None)
class Error(OWWidget.Error):
pass
def __init__(self):
super().__init__()
for name in self.signal_names:
setattr(self, name, {})
for s in self.libraryListSource:
s.flags = 0
self._cachedDocuments = {}
self.infoBox = gui.vBox(self.controlArea, 'Info')
gui.label(
self.infoBox, self,
"<p>Execute python script.</p><p>Input variables:<ul><li> " +
"<li>".join(map("in_{0}, in_{0}s".format, self.signal_names)) +
"</ul></p><p>Output variables:<ul><li>" +
"<li>".join(map("out_{0}".format, self.signal_names)) +
"</ul></p>"
)
self.libraryList = itemmodels.PyListModel(
[], self,
flags=Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable)
self.libraryList.wrap(self.libraryListSource)
self.controlBox = gui.vBox(self.controlArea, 'Library')
self.controlBox.layout().setSpacing(1)
self.libraryView = QListView(
editTriggers=QListView.DoubleClicked |
QListView.EditKeyPressed,
sizePolicy=QSizePolicy(QSizePolicy.Ignored,
QSizePolicy.Preferred)
)
self.libraryView.setItemDelegate(ScriptItemDelegate(self))
self.libraryView.setModel(self.libraryList)
self.libraryView.selectionModel().selectionChanged.connect(
self.onSelectedScriptChanged
)
self.controlBox.layout().addWidget(self.libraryView)
w = itemmodels.ModelActionsWidget()
self.addNewScriptAction = action = QAction("+", self)
action.setToolTip("Add a new script to the library")
action.triggered.connect(self.onAddScript)
w.addAction(action)
action = QAction(unicodedata.lookup("MINUS SIGN"), self)
action.setToolTip("Remove script from library")
action.triggered.connect(self.onRemoveScript)
w.addAction(action)
action = QAction("Update", self)
action.setToolTip("Save changes in the editor to library")
action.setShortcut(QKeySequence(QKeySequence.Save))
action.triggered.connect(self.commitChangesToLibrary)
w.addAction(action)
action = QAction("More", self, toolTip="More actions")
#.........这里部分代码省略.........
示例3: OWFeatureConstructor
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
#.........这里部分代码省略.........
lambda: self.addFeature(
StringDescriptor(generate_newname("S{}"), ""))
)
menu.addSeparator()
self.duplicateaction = menu.addAction("Duplicate Selected Variable")
self.duplicateaction.triggered.connect(self.duplicateFeature)
self.duplicateaction.setEnabled(False)
self.addbutton.setMenu(menu)
self.removebutton = QPushButton(
"Remove", toolTip="Remove selected variable",
minimumWidth=120,
shortcut=QKeySequence.Delete
)
self.removebutton.clicked.connect(self.removeSelectedFeature)
buttonlayout.addWidget(self.addbutton)
buttonlayout.addWidget(self.removebutton)
buttonlayout.addStretch(10)
toplayout.addLayout(buttonlayout, 0)
toplayout.addWidget(self.editorstack, 10)
# Layout for the list view
layout = QVBoxLayout(spacing=1, margin=0)
self.featuremodel = DescriptorModel(parent=self)
self.featureview = QListView(
minimumWidth=200,
sizePolicy=QSizePolicy(QSizePolicy.Minimum,
QSizePolicy.MinimumExpanding)
)
self.featureview.setItemDelegate(FeatureItemDelegate(self))
self.featureview.setModel(self.featuremodel)
self.featureview.selectionModel().selectionChanged.connect(
self._on_selectedVariableChanged
)
layout.addWidget(self.featureview)
box.layout().addLayout(layout, 1)
box = gui.hBox(self.controlArea)
gui.rubber(box)
commit = gui.button(box, self, "Send", callback=self.apply,
default=True)
commit.setMinimumWidth(180)
def setCurrentIndex(self, index):
index = min(index, len(self.featuremodel) - 1)
self.currentIndex = index
if index >= 0:
itemmodels.select_row(self.featureview, index)
desc = self.featuremodel[min(index, len(self.featuremodel) - 1)]
editor = self.editors[type(desc)]
self.editorstack.setCurrentWidget(editor)
editor.setEditorData(desc, self.data.domain if self.data else None)
self.editorstack.setEnabled(index >= 0)
self.duplicateaction.setEnabled(index >= 0)
self.removebutton.setEnabled(index >= 0)
def _on_selectedVariableChanged(self, selected, *_):
index = selected_row(self.featureview)
if index is not None:
self.setCurrentIndex(index)
示例4: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
class OWImpute(OWWidget):
name = "Impute"
description = "Impute missing values in the data table."
icon = "icons/Impute.svg"
priority = 2130
inputs = [("Data", Orange.data.Table, "set_data"),
("Learner", Learner, "set_learner")]
outputs = [("Data", Orange.data.Table)]
DEFAULT_LEARNER = SimpleTreeLearner()
METHODS = [AsDefault(), impute.DoNotImpute(), impute.Average(),
impute.AsValue(), impute.Model(DEFAULT_LEARNER), impute.Random(),
impute.DropInstances(), impute.Default()]
DEFAULT, DO_NOT_IMPUTE, MODEL_BASED_IMPUTER, AS_INPUT = 0, 1, 4, 7
settingsHandler = settings.DomainContextHandler()
_default_method_index = settings.Setting(DO_NOT_IMPUTE)
variable_methods = settings.ContextSetting({})
autocommit = settings.Setting(False)
default_value = settings.Setting(0.)
want_main_area = False
resizing_enabled = False
def __init__(self):
super().__init__()
main_layout = QVBoxLayout()
main_layout.setContentsMargins(10, 10, 10, 10)
self.controlArea.layout().addLayout(main_layout)
box = QGroupBox(title=self.tr("Default Method"), flat=False)
box_layout = QVBoxLayout(box)
main_layout.addWidget(box)
button_group = QButtonGroup()
button_group.buttonClicked[int].connect(self.set_default_method)
for i, method in enumerate(self.METHODS):
if not method.columns_only:
button = QRadioButton(method.name)
button.setChecked(i == self.default_method_index)
button_group.addButton(button, i)
box_layout.addWidget(button)
self.default_button_group = button_group
box = QGroupBox(title=self.tr("Individual Attribute Settings"),
flat=False)
main_layout.addWidget(box)
horizontal_layout = QHBoxLayout(box)
main_layout.addWidget(box)
self.varview = QListView(
selectionMode=QListView.ExtendedSelection
)
self.varview.setItemDelegate(DisplayFormatDelegate())
self.varmodel = itemmodels.VariableListModel()
self.varview.setModel(self.varmodel)
self.varview.selectionModel().selectionChanged.connect(
self._on_var_selection_changed
)
self.selection = self.varview.selectionModel()
horizontal_layout.addWidget(self.varview)
method_layout = QVBoxLayout()
horizontal_layout.addLayout(method_layout)
button_group = QButtonGroup()
for i, method in enumerate(self.METHODS):
button = QRadioButton(text=method.name)
button_group.addButton(button, i)
method_layout.addWidget(button)
self.value_combo = QComboBox(
minimumContentsLength=8,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLength,
activated=self._on_value_selected
)
self.value_combo.currentIndexChanged.connect(self._on_value_changed)
self.value_double = QDoubleSpinBox(
editingFinished=self._on_value_selected,
minimum=-1000., maximum=1000., singleStep=.1, decimals=3,
value=self.default_value
)
self.value_stack = value_stack = QStackedLayout()
value_stack.addWidget(self.value_combo)
value_stack.addWidget(self.value_double)
method_layout.addLayout(value_stack)
button_group.buttonClicked[int].connect(
self.set_method_for_current_selection
)
method_layout.addStretch(2)
reset_button = QPushButton(
"Restore All to Default", checked=False, checkable=False,
#.........这里部分代码省略.........
示例5: SelectionSetsWidget
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
class SelectionSetsWidget(QFrame):
"""
Widget for managing multiple stored item selections
"""
selectionModified = Signal(bool)
def __init__(self, parent):
QFrame.__init__(self, parent)
self.setContentsMargins(0, 0, 0, 0)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(1)
self._setNameLineEdit = QLineEdit(self)
layout.addWidget(self._setNameLineEdit)
self._setListView = QListView(self)
self._listModel = QStandardItemModel(self)
self._proxyModel = QSortFilterProxyModel(self)
self._proxyModel.setSourceModel(self._listModel)
self._setListView.setModel(self._proxyModel)
self._setListView.setItemDelegate(ListItemDelegate(self))
self._setNameLineEdit.textChanged.connect(
self._proxyModel.setFilterFixedString)
self._completer = QCompleter(self._listModel, self)
self._setNameLineEdit.setCompleter(self._completer)
self._listModel.itemChanged.connect(self._onSetNameChange)
layout.addWidget(self._setListView)
buttonLayout = QHBoxLayout()
self._addAction = QAction(
"+", self, toolTip="Add a new sort key")
self._updateAction = QAction(
"Update", self, toolTip="Update/save current selection")
self._removeAction = QAction(
"\u2212", self, toolTip="Remove selected sort key.")
self._addToolButton = QToolButton(self)
self._updateToolButton = QToolButton(self)
self._removeToolButton = QToolButton(self)
self._updateToolButton.setSizePolicy(
QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
self._addToolButton.setDefaultAction(self._addAction)
self._updateToolButton.setDefaultAction(self._updateAction)
self._removeToolButton.setDefaultAction(self._removeAction)
buttonLayout.addWidget(self._addToolButton)
buttonLayout.addWidget(self._updateToolButton)
buttonLayout.addWidget(self._removeToolButton)
layout.addLayout(buttonLayout)
self.setLayout(layout)
self._addAction.triggered.connect(self.addCurrentSelection)
self._updateAction.triggered.connect(self.updateSelectedSelection)
self._removeAction.triggered.connect(self.removeSelectedSelection)
self._setListView.selectionModel().selectionChanged.connect(
self._onListViewSelectionChanged)
self.selectionModel = None
self._selections = []
def sizeHint(self):
size = QFrame.sizeHint(self)
return QSize(size.width(), 150)
def _onSelectionChanged(self, selected, deselected):
self.setSelectionModified(True)
def _onListViewSelectionChanged(self, selected, deselected):
try:
index = self._setListView.selectedIndexes()[0]
except IndexError:
return
self.commitSelection(self._proxyModel.mapToSource(index).row())
def _onSetNameChange(self, item):
self.selections[item.row()].name = str(item.text())
def _setButtonStates(self, val):
self._updateToolButton.setEnabled(val)
def setSelectionModel(self, selectionModel):
if self.selectionModel:
self.selectionModel.selectionChanged.disconnect(
self._onSelectionChanged)
self.selectionModel = selectionModel
self.selectionModel.selectionChanged.connect(self._onSelectionChanged)
def addCurrentSelection(self):
item = self.addSelection(
SelectionByKey(self.selectionModel.selection(),
name="New selection",
key=(1, 2, 3, 10)))
index = self._proxyModel.mapFromSource(item.index())
#.........这里部分代码省略.........
示例6: SortedListWidget
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
#.........这里部分代码省略.........
self._upButton = QToolButton(self)
self._upButton.setDefaultAction(self._upAction)
self._upButton.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
self._downAction = QAction(
"\u2193", self, toolTip="Move down")
self._downButton = QToolButton(self)
self._downButton.setDefaultAction(self._downAction)
self._downButton.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
vButtonLayout.addWidget(self._upButton)
vButtonLayout.addWidget(self._downButton)
gridLayout.addLayout(vButtonLayout, 0, 2, 2, 1)
hButtonLayout = QHBoxLayout()
self._addAction = QAction("+", self)
self._addButton = QToolButton(self)
self._addButton.setDefaultAction(self._addAction)
self._removeAction = QAction("-", self)
self._removeButton = QToolButton(self)
self._removeButton.setDefaultAction(self._removeAction)
hButtonLayout.addWidget(self._addButton)
hButtonLayout.addWidget(self._removeButton)
hButtonLayout.addStretch(10)
gridLayout.addLayout(hButtonLayout, 2, 0, 1, 2)
self.setLayout(gridLayout)
self._addAction.triggered.connect(self._onAddAction)
self._removeAction.triggered.connect(self._onRemoveAction)
self._upAction.triggered.connect(self._onUpAction)
self._downAction.triggered.connect(self._onDownAction)
def sizeHint(self):
size = QWidget.sizeHint(self)
return QSize(size.width(), 100)
def _onAddAction(self):
item = QStandardItem("")
item.setFlags(item.flags() ^ Qt.ItemIsDropEnabled)
self._listView.model().appendRow(item)
self._listView.setCurrentIndex(item.index())
self._listView.edit(item.index())
def _onRemoveAction(self):
current = self._listView.currentIndex()
self._listView.model().takeRow(current.row())
def _onUpAction(self):
row = self._listView.currentIndex().row()
model = self._listView.model()
if row > 0:
items = model.takeRow(row)
model.insertRow(row - 1, items)
self._listView.setCurrentIndex(model.index(row - 1, 0))
def _onDownAction(self):
row = self._listView.currentIndex().row()
model = self._listView.model()
if row < model.rowCount() and row >= 0:
items = model.takeRow(row)
if row == model.rowCount():
model.appendRow(items)
else:
model.insertRow(row + 1, items)
self._listView.setCurrentIndex(model.index(row + 1, 0))
def setModel(self, model):
""" Set a model to select items from
"""
self._model = model
self._listView.setItemDelegate(self._MyItemDelegate(self._model, self))
def addItem(self, *args):
""" Add a new entry in the list
"""
item = QStandardItem(*args)
item.setFlags(item.flags() ^ Qt.ItemIsDropEnabled)
self._listView.model().appendRow(item)
def setItems(self, items):
self._listView.model().clear()
for item in items:
self.addItem(item)
def items(self):
order = []
for row in range(self._listView.model().rowCount()):
order.append(str(self._listView.model().item(row, 0).text()))
return order
def __changed(self):
self.sortingOrderChanged.emit()
sortingOrder = property(items, setItems)
示例7: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
class OWImpute(OWWidget):
name = "Impute"
description = "Impute missing values in the data table."
icon = "icons/Impute.svg"
priority = 2130
class Inputs:
data = Input("Data", Orange.data.Table)
learner = Input("Learner", Learner)
class Outputs:
data = Output("Data", Orange.data.Table)
class Error(OWWidget.Error):
imputation_failed = Msg("Imputation failed for '{}'")
model_based_imputer_sparse = Msg("Model based imputer does not work for sparse data")
DEFAULT_LEARNER = SimpleTreeLearner()
METHODS = [AsDefault(), impute.DoNotImpute(), impute.Average(),
impute.AsValue(), impute.Model(DEFAULT_LEARNER), impute.Random(),
impute.DropInstances(), impute.Default()]
DEFAULT, DO_NOT_IMPUTE, MODEL_BASED_IMPUTER, AS_INPUT = 0, 1, 4, 7
settingsHandler = settings.DomainContextHandler()
_default_method_index = settings.Setting(DO_NOT_IMPUTE)
variable_methods = settings.ContextSetting({})
autocommit = settings.Setting(True)
want_main_area = False
resizing_enabled = False
def __init__(self):
super().__init__()
# copy METHODS (some are modified by the widget)
self.methods = copy.deepcopy(OWImpute.METHODS)
main_layout = QVBoxLayout()
main_layout.setContentsMargins(10, 10, 10, 10)
self.controlArea.layout().addLayout(main_layout)
box = QGroupBox(title=self.tr("Default Method"), flat=False)
box_layout = QVBoxLayout(box)
main_layout.addWidget(box)
button_group = QButtonGroup()
button_group.buttonClicked[int].connect(self.set_default_method)
for i, method in enumerate(self.methods):
if not method.columns_only:
button = QRadioButton(method.name)
button.setChecked(i == self.default_method_index)
button_group.addButton(button, i)
box_layout.addWidget(button)
self.default_button_group = button_group
box = QGroupBox(title=self.tr("Individual Attribute Settings"),
flat=False)
main_layout.addWidget(box)
horizontal_layout = QHBoxLayout(box)
main_layout.addWidget(box)
self.varview = QListView(
selectionMode=QListView.ExtendedSelection
)
self.varview.setItemDelegate(DisplayFormatDelegate())
self.varmodel = itemmodels.VariableListModel()
self.varview.setModel(self.varmodel)
self.varview.selectionModel().selectionChanged.connect(
self._on_var_selection_changed
)
self.selection = self.varview.selectionModel()
horizontal_layout.addWidget(self.varview)
method_layout = QVBoxLayout()
horizontal_layout.addLayout(method_layout)
button_group = QButtonGroup()
for i, method in enumerate(self.methods):
button = QRadioButton(text=method.name)
button_group.addButton(button, i)
method_layout.addWidget(button)
self.value_combo = QComboBox(
minimumContentsLength=8,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLength,
activated=self._on_value_selected
)
self.value_double = QDoubleSpinBox(
editingFinished=self._on_value_selected,
minimum=-1000., maximum=1000., singleStep=.1, decimals=3,
)
self.value_stack = value_stack = QStackedWidget()
value_stack.addWidget(self.value_combo)
value_stack.addWidget(self.value_double)
method_layout.addWidget(value_stack)
button_group.buttonClicked[int].connect(
#.........这里部分代码省略.........
示例8: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
class OWImpute(OWWidget):
name = "Impute"
description = "Impute missing values in the data table."
icon = "icons/Impute.svg"
priority = 2130
class Inputs:
data = Input("Data", Orange.data.Table)
learner = Input("Learner", Learner)
class Outputs:
data = Output("Data", Orange.data.Table)
class Error(OWWidget.Error):
imputation_failed = Msg("Imputation failed for '{}'")
model_based_imputer_sparse = Msg("Model based imputer does not work for sparse data")
settingsHandler = settings.DomainContextHandler()
_default_method_index = settings.Setting(int(Method.Leave)) # type: int
# Per-variable imputation state (synced in storeSpecificSettings)
_variable_imputation_state = settings.ContextSetting({}) # type: VariableState
autocommit = settings.Setting(True)
want_main_area = False
resizing_enabled = False
def __init__(self):
super().__init__()
self.data = None # type: Optional[Orange.data.Table]
self.learner = None # type: Optional[Learner]
self.default_learner = SimpleTreeLearner()
self.modified = False
self.executor = qconcurrent.ThreadExecutor(self)
self.__task = None
main_layout = QVBoxLayout()
main_layout.setContentsMargins(10, 10, 10, 10)
self.controlArea.layout().addLayout(main_layout)
box = QGroupBox(title=self.tr("Default Method"), flat=False)
box_layout = QVBoxLayout(box)
main_layout.addWidget(box)
button_group = QButtonGroup()
button_group.buttonClicked[int].connect(self.set_default_method)
for method, _ in list(METHODS.items())[1:-1]:
imputer = self.create_imputer(method)
button = QRadioButton(imputer.name)
button.setChecked(method == self.default_method_index)
button_group.addButton(button, method)
box_layout.addWidget(button)
self.default_button_group = button_group
box = QGroupBox(title=self.tr("Individual Attribute Settings"),
flat=False)
main_layout.addWidget(box)
horizontal_layout = QHBoxLayout(box)
main_layout.addWidget(box)
self.varview = QListView(
selectionMode=QListView.ExtendedSelection,
uniformItemSizes=True
)
self.varview.setItemDelegate(DisplayFormatDelegate())
self.varmodel = itemmodels.VariableListModel()
self.varview.setModel(self.varmodel)
self.varview.selectionModel().selectionChanged.connect(
self._on_var_selection_changed
)
self.selection = self.varview.selectionModel()
horizontal_layout.addWidget(self.varview)
method_layout = QVBoxLayout()
horizontal_layout.addLayout(method_layout)
button_group = QButtonGroup()
for method in Method:
imputer = self.create_imputer(method)
button = QRadioButton(text=imputer.name)
button_group.addButton(button, method)
method_layout.addWidget(button)
self.value_combo = QComboBox(
minimumContentsLength=8,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLength,
activated=self._on_value_selected
)
self.value_double = QDoubleSpinBox(
editingFinished=self._on_value_selected,
minimum=-1000., maximum=1000., singleStep=.1, decimals=3,
)
self.value_stack = value_stack = QStackedWidget()
value_stack.addWidget(self.value_combo)
value_stack.addWidget(self.value_double)
#.........这里部分代码省略.........
示例9: OWPythonScript
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
class OWPythonScript(widget.OWWidget):
name = "Python Script"
description = "Write a Python script and run it on input data or models."
icon = "icons/PythonScript.svg"
priority = 3150
inputs = [("in_data", Orange.data.Table, "setExampleTable",
widget.Default),
# ("in_distance", Orange.misc.SymMatrix, "setDistanceMatrix",
# widget.Default),
("in_learner", Learner, "setLearner",
widget.Default),
("in_classifier", Model, "setClassifier",
widget.Default),
("in_object", object, "setObject")]
outputs = [("out_data", Orange.data.Table, ),
# ("out_distance", Orange.misc.SymMatrix, ),
("out_learner", Learner, ),
("out_classifier", Model, widget.Dynamic),
("out_object", object, widget.Dynamic)]
libraryListSource = \
Setting([Script("Hello world", "print('Hello world')\n")])
currentScriptIndex = Setting(0)
splitterState = Setting(None)
auto_execute = Setting(False)
def __init__(self):
super().__init__()
self.in_data = None
self.in_distance = None
self.in_learner = None
self.in_classifier = None
self.in_object = None
self.auto_execute = False
for s in self.libraryListSource:
s.flags = 0
self._cachedDocuments = {}
self.infoBox = gui.vBox(self.controlArea, 'Info')
gui.label(
self.infoBox, self,
"<p>Execute python script.</p><p>Input variables:<ul><li> " + \
"<li>".join(t.name for t in self.inputs) + \
"</ul></p><p>Output variables:<ul><li>" + \
"<li>".join(t.name for t in self.outputs) + \
"</ul></p>"
)
self.libraryList = itemmodels.PyListModel(
[], self,
flags=Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable)
self.libraryList.wrap(self.libraryListSource)
self.controlBox = gui.vBox(self.controlArea, 'Library')
self.controlBox.layout().setSpacing(1)
self.libraryView = QListView(
editTriggers=QListView.DoubleClicked |
QListView.EditKeyPressed,
sizePolicy=QSizePolicy(QSizePolicy.Ignored,
QSizePolicy.Preferred)
)
self.libraryView.setItemDelegate(ScriptItemDelegate(self))
self.libraryView.setModel(self.libraryList)
self.libraryView.selectionModel().selectionChanged.connect(
self.onSelectedScriptChanged
)
self.controlBox.layout().addWidget(self.libraryView)
w = itemmodels.ModelActionsWidget()
self.addNewScriptAction = action = QAction("+", self)
action.setToolTip("Add a new script to the library")
action.triggered.connect(self.onAddScript)
w.addAction(action)
action = QAction(unicodedata.lookup("MINUS SIGN"), self)
action.setToolTip("Remove script from library")
action.triggered.connect(self.onRemoveScript)
w.addAction(action)
action = QAction("Update", self)
action.setToolTip("Save changes in the editor to library")
action.setShortcut(QKeySequence(QKeySequence.Save))
action.triggered.connect(self.commitChangesToLibrary)
w.addAction(action)
action = QAction("More", self, toolTip="More actions")
new_from_file = QAction("Import Script from File", self)
save_to_file = QAction("Save Selected Script to File", self)
save_to_file.setShortcut(QKeySequence(QKeySequence.SaveAs))
#.........这里部分代码省略.........
示例10: DiscreteVariableEditor
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
class DiscreteVariableEditor(VariableEditor):
"""An editor widget for editing a discrete variable.
Extends the :class:`VariableEditor` to enable editing of
variables values.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
form = self.layout().itemAt(0)
assert isinstance(form, QFormLayout)
#: A list model of discrete variable's values.
self.values_model = itemmodels.PyListModel(
flags=Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
)
vlayout = QVBoxLayout(spacing=1, margin=0)
self.values_edit = QListView(
editTriggers=QListView.DoubleClicked | QListView.EditKeyPressed
)
self.values_edit.setItemDelegate(CategoriesEditDelegate(self))
self.values_edit.setModel(self.values_model)
self.values_model.dataChanged.connect(self.on_values_changed)
self.values_edit.selectionModel().selectionChanged.connect(
self.on_value_selection_changed)
self.values_model.layoutChanged.connect(self.on_value_selection_changed)
self.values_model.rowsMoved.connect(self.on_value_selection_changed)
vlayout.addWidget(self.values_edit)
hlayout = QHBoxLayout(spacing=1, margin=0)
self.categories_action_group = group = QActionGroup(
self, objectName="action-group-categories", enabled=False
)
self.move_value_up = QAction(
"\N{UPWARDS ARROW}", group,
toolTip="Move the selected item up.",
shortcut=QKeySequence(Qt.ControlModifier | Qt.AltModifier |
Qt.Key_BracketLeft),
shortcutContext=Qt.WidgetShortcut,
)
self.move_value_up.triggered.connect(self.move_up)
self.move_value_down = QAction(
"\N{DOWNWARDS ARROW}", group,
toolTip="Move the selected item down.",
shortcut=QKeySequence(Qt.ControlModifier | Qt.AltModifier |
Qt.Key_BracketRight),
shortcutContext=Qt.WidgetShortcut,
)
self.move_value_down.triggered.connect(self.move_down)
self.add_new_item = QAction(
"+", group,
objectName="action-add-item",
toolTip="Append a new item.",
shortcut=QKeySequence(QKeySequence.New),
shortcutContext=Qt.WidgetShortcut,
)
self.remove_item = QAction(
"\N{MINUS SIGN}", group,
objectName="action-remove-item",
toolTip="Delete the selected item.",
shortcut=QKeySequence(QKeySequence.Delete),
shortcutContext=Qt.WidgetShortcut,
)
self.add_new_item.triggered.connect(self._add_category)
self.remove_item.triggered.connect(self._remove_category)
button1 = FixedSizeButton(
self, defaultAction=self.move_value_up,
accessibleName="Move up"
)
button2 = FixedSizeButton(
self, defaultAction=self.move_value_down,
accessibleName="Move down"
)
button3 = FixedSizeButton(
self, defaultAction=self.add_new_item,
accessibleName="Add"
)
button4 = FixedSizeButton(
self, defaultAction=self.remove_item,
accessibleName="Remove"
)
self.values_edit.addActions([self.move_value_up, self.move_value_down,
self.add_new_item, self.remove_item])
hlayout.addWidget(button1)
hlayout.addWidget(button2)
hlayout.addSpacing(3)
hlayout.addWidget(button3)
hlayout.addWidget(button4)
hlayout.addStretch(10)
vlayout.addLayout(hlayout)
form.insertRow(1, "Values:", vlayout)
#.........这里部分代码省略.........
示例11: showPopup
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import setItemDelegate [as 别名]
def showPopup(self):
# type: () -> None
"""
Reimplemented from QComboBox.showPopup
Popup up a customized view and filter edit line.
Note
----
The .popup(), .lineEdit(), .completer() of the base class are not used.
"""
if self.__popup is not None:
# We have user entered state that cannot be disturbed
# (entered filter text, scroll offset, ...)
return # pragma: no cover
if self.count() == 0:
return
opt = QStyleOptionComboBox()
self.initStyleOption(opt)
popup = QListView(
uniformItemSizes=True,
horizontalScrollBarPolicy=Qt.ScrollBarAlwaysOff,
verticalScrollBarPolicy=Qt.ScrollBarAsNeeded,
iconSize=self.iconSize(),
)
popup.setFocusProxy(self.__searchline)
popup.setParent(self, Qt.Popup | Qt.FramelessWindowHint)
popup.setItemDelegate(_ComboBoxListDelegate(popup))
proxy = QSortFilterProxyModel(
popup, filterCaseSensitivity=Qt.CaseInsensitive
)
proxy.setFilterKeyColumn(self.modelColumn())
proxy.setSourceModel(self.model())
popup.setModel(proxy)
root = proxy.mapFromSource(self.rootModelIndex())
popup.setRootIndex(root)
self.__popup = popup
self.__proxy = proxy
self.__searchline.setText("")
self.__searchline.setPlaceholderText("Filter...")
self.__searchline.setVisible(True)
self.__searchline.textEdited.connect(proxy.setFilterFixedString)
style = self.style() # type: QStyle
popuprect_origin = style.subControlRect(
QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxListBoxPopup, self
) # type: QRect
popuprect_origin = QRect(
self.mapToGlobal(popuprect_origin.topLeft()),
popuprect_origin.size()
)
editrect = style.subControlRect(
QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxEditField, self
) # type: QRect
self.__searchline.setGeometry(editrect)
desktop = QApplication.desktop()
screenrect = desktop.availableGeometry(self) # type: QRect
# get the height for the view
listrect = QRect()
for i in range(min(proxy.rowCount(root), self.maxVisibleItems())):
index = proxy.index(i, self.modelColumn(), root)
if index.isValid():
listrect = listrect.united(popup.visualRect(index))
if listrect.height() >= screenrect.height():
break
window = popup.window() # type: QWidget
window.ensurePolished()
if window.layout() is not None:
window.layout().activate()
else:
QApplication.sendEvent(window, QEvent(QEvent.LayoutRequest))
margins = qwidget_margin_within(popup.viewport(), window)
height = (listrect.height() + 2 * popup.spacing() +
margins.top() + margins.bottom())
popup_size = (QSize(popuprect_origin.width(), height)
.expandedTo(window.minimumSize())
.boundedTo(window.maximumSize())
.boundedTo(screenrect.size()))
popuprect = QRect(popuprect_origin.bottomLeft(), popup_size)
popuprect = dropdown_popup_geometry(
popuprect, popuprect_origin, screenrect)
popup.setGeometry(popuprect)
current = proxy.mapFromSource(
self.model().index(self.currentIndex(), self.modelColumn(),
self.rootModelIndex()))
popup.setCurrentIndex(current)
popup.scrollTo(current, QAbstractItemView.EnsureVisible)
popup.show()
popup.setFocus(Qt.PopupFocusReason)
popup.installEventFilter(self)
popup.viewport().installEventFilter(self)
#.........这里部分代码省略.........