本文整理汇总了Python中AnyQt.QtWidgets.QListView.selectionModel方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.selectionModel方法的具体用法?Python QListView.selectionModel怎么用?Python QListView.selectionModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QListView
的用法示例。
在下文中一共展示了QListView.selectionModel方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OWEditDomain
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [as 别名]
class OWEditDomain(widget.OWWidget):
name = "Edit Domain"
description = "Rename features and their values."
icon = "icons/EditDomain.svg"
priority = 3125
inputs = [("Data", Orange.data.Table, "set_data")]
outputs = [("Data", Orange.data.Table)]
settingsHandler = settings.DomainContextHandler()
domain_change_hints = settings.ContextSetting({})
selected_index = settings.ContextSetting({})
autocommit = settings.Setting(False)
def __init__(self):
super().__init__()
self.data = None
self.input_vars = ()
self._invalidated = False
box = gui.vBox(self.controlArea, "Domain Features")
self.domain_model = itemmodels.VariableListModel()
self.domain_view = QListView(
selectionMode=QListView.SingleSelection
)
self.domain_view.setModel(self.domain_model)
self.domain_view.selectionModel().selectionChanged.connect(
self._on_selection_changed)
box.layout().addWidget(self.domain_view)
box = gui.hBox(self.controlArea)
gui.button(box, self, "Reset Selected", callback=self.reset_selected)
gui.button(box, self, "Reset All", callback=self.reset_all)
gui.auto_commit(self.controlArea, self, "autocommit", "Apply")
box = gui.vBox(self.mainArea, "Edit")
self.editor_stack = QStackedWidget()
self.editor_stack.addWidget(DiscreteVariableEditor())
self.editor_stack.addWidget(ContinuousVariableEditor())
self.editor_stack.addWidget(VariableEditor())
box.layout().addWidget(self.editor_stack)
@check_sql_input
def set_data(self, data):
"""Set input data set."""
self.closeContext()
self.clear()
self.data = data
if self.data is not None:
self._initialize()
self.openContext(self.data)
self._restore()
self.unconditional_commit()
def clear(self):
"""Clear the widget state."""
self.data = None
self.domain_model[:] = []
self.input_vars = []
self.domain_change_hints = {}
self.selected_index = -1
def reset_selected(self):
"""Reset the currently selected variable to its original state."""
ind = self.selected_var_index()
if ind >= 0:
var = self.input_vars[ind]
desc = variable_description(var, skip_attributes=True)
if desc in self.domain_change_hints:
del self.domain_change_hints[desc]
self.domain_model[ind] = var
self.editor_stack.currentWidget().set_data(var)
self._invalidate()
def reset_all(self):
"""Reset all variables to their original state."""
self.domain_change_hints = {}
if self.data is not None:
# To invalidate stored hints
self.domain_model[:] = self.input_vars
itemmodels.select_row(self.domain_view, self.selected_index)
self._invalidate()
def selected_var_index(self):
"""Return the selected row in 'Domain Features' view."""
rows = self.domain_view.selectedIndexes()
assert len(rows) <= 1
return rows[0].row() if rows else -1
def _initialize(self):
#.........这里部分代码省略.........
示例2: OWPythonScript
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [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: OWQualityControl
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [as 别名]
class OWQualityControl(widget.OWWidget):
name = "Quality Control"
description = "Experiment quality control"
icon = "../widgets/icons/QualityControl.svg"
priority = 5000
inputs = [("Experiment Data", Orange.data.Table, "set_data")]
outputs = []
DISTANCE_FUNCTIONS = [("Distance from Pearson correlation",
dist_pcorr),
("Euclidean distance",
dist_eucl),
("Distance from Spearman correlation",
dist_spearman)]
settingsHandler = SetContextHandler()
split_by_labels = settings.ContextSetting({})
sort_by_labels = settings.ContextSetting({})
selected_distance_index = settings.Setting(0)
def __init__(self, parent=None):
super().__init__(parent)
## Attributes
self.data = None
self.distances = None
self.groups = None
self.unique_pos = None
self.base_group_index = 0
## GUI
box = gui.widgetBox(self.controlArea, "Info")
self.info_box = gui.widgetLabel(box, "\n")
## Separate By box
box = gui.widgetBox(self.controlArea, "Separate By")
self.split_by_model = itemmodels.PyListModel(parent=self)
self.split_by_view = QListView()
self.split_by_view.setSelectionMode(QListView.ExtendedSelection)
self.split_by_view.setModel(self.split_by_model)
box.layout().addWidget(self.split_by_view)
self.split_by_view.selectionModel().selectionChanged.connect(
self.on_split_key_changed)
## Sort By box
box = gui.widgetBox(self.controlArea, "Sort By")
self.sort_by_model = itemmodels.PyListModel(parent=self)
self.sort_by_view = QListView()
self.sort_by_view.setSelectionMode(QListView.ExtendedSelection)
self.sort_by_view.setModel(self.sort_by_model)
box.layout().addWidget(self.sort_by_view)
self.sort_by_view.selectionModel().selectionChanged.connect(
self.on_sort_key_changed)
## Distance box
box = gui.widgetBox(self.controlArea, "Distance Measure")
gui.comboBox(box, self, "selected_distance_index",
items=[name for name, _ in self.DISTANCE_FUNCTIONS],
callback=self.on_distance_measure_changed)
self.scene = QGraphicsScene()
self.scene_view = QGraphicsView(self.scene)
self.scene_view.setRenderHints(QPainter.Antialiasing)
self.scene_view.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
self.mainArea.layout().addWidget(self.scene_view)
self.scene_view.installEventFilter(self)
self._disable_updates = False
self._cached_distances = {}
self._base_index_hints = {}
self.main_widget = None
self.resize(800, 600)
def clear(self):
"""Clear the widget state."""
self.data = None
self.distances = None
self.groups = None
self.unique_pos = None
with disable_updates(self):
self.split_by_model[:] = []
self.sort_by_model[:] = []
self.main_widget = None
self.scene.clear()
self.info_box.setText("\n")
self._cached_distances = {}
def set_data(self, data=None):
"""Set input experiment data."""
self.closeContext()
self.clear()
#.........这里部分代码省略.........
示例4: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [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: OWDiscretize
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [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")
#.........这里部分代码省略.........
示例6: OWFeatureConstructor
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [as 别名]
#.........这里部分代码省略.........
)
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)
else:
self.setCurrentIndex(-1)
示例7: OWDistributions
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [as 别名]
class OWDistributions(widget.OWWidget):
name = "Distributions"
description = "Display value distributions of a data feature in a graph."
icon = "icons/Distribution.svg"
priority = 120
class Inputs:
data = Input("Data", Orange.data.Table, doc="Set the input data set")
settingsHandler = settings.DomainContextHandler(
match_values=settings.DomainContextHandler.MATCH_VALUES_ALL)
#: Selected variable index
variable_idx = settings.ContextSetting(-1)
#: Selected group variable
groupvar_idx = settings.ContextSetting(0)
relative_freq = settings.Setting(False)
disc_cont = settings.Setting(False)
smoothing_index = settings.Setting(5)
show_prob = settings.ContextSetting(0)
graph_name = "plot"
ASH_HIST = 50
bins = [2, 3, 4, 5, 8, 10, 12, 15, 20, 30, 50]
smoothing_facs = list(reversed([0.1, 0.2, 0.4, 0.6, 0.8, 1, 1.5, 2, 4, 6, 10]))
def __init__(self):
super().__init__()
self.data = None
self.distributions = None
self.contingencies = None
self.var = self.cvar = None
varbox = gui.vBox(self.controlArea, "Variable")
self.varmodel = itemmodels.VariableListModel()
self.groupvarmodel = []
self.varview = QListView(
selectionMode=QListView.SingleSelection)
self.varview.setSizePolicy(
QSizePolicy.Minimum, QSizePolicy.Expanding)
self.varview.setModel(self.varmodel)
self.varview.setSelectionModel(
itemmodels.ListSingleSelectionModel(self.varmodel))
self.varview.selectionModel().selectionChanged.connect(
self._on_variable_idx_changed)
varbox.layout().addWidget(self.varview)
box = gui.vBox(self.controlArea, "Precision")
gui.separator(self.controlArea, 4, 4)
box2 = gui.hBox(box)
self.l_smoothing_l = gui.widgetLabel(box2, "Smooth")
gui.hSlider(box2, self, "smoothing_index",
minValue=0, maxValue=len(self.smoothing_facs) - 1,
callback=self._on_set_smoothing, createLabel=False)
self.l_smoothing_r = gui.widgetLabel(box2, "Precise")
self.cb_disc_cont = gui.checkBox(
gui.indentedBox(box, sep=4),
self, "disc_cont", "Bin numeric variables",
callback=self._on_groupvar_idx_changed,
tooltip="Show numeric variables as categorical.")
box = gui.vBox(self.controlArea, "Group by")
self.icons = gui.attributeIconDict
self.groupvarview = gui.comboBox(
box, self, "groupvar_idx",
callback=self._on_groupvar_idx_changed,
valueType=str, contentsLength=12)
box2 = gui.indentedBox(box, sep=4)
self.cb_rel_freq = gui.checkBox(
box2, self, "relative_freq", "Show relative frequencies",
callback=self._on_relative_freq_changed,
tooltip="Normalize probabilities so that probabilities "
"for each group-by value sum to 1.")
gui.separator(box2)
self.cb_prob = gui.comboBox(
box2, self, "show_prob", label="Show probabilities:",
orientation=Qt.Horizontal,
callback=self._on_relative_freq_changed,
tooltip="Show probabilities for a chosen group-by value "
"(at each point probabilities for all group-by values sum to 1).")
self.plotview = pg.PlotWidget(background=None)
self.plotview.setRenderHint(QPainter.Antialiasing)
self.mainArea.layout().addWidget(self.plotview)
w = QLabel()
w.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.mainArea.layout().addWidget(w, Qt.AlignCenter)
self.ploti = pg.PlotItem()
self.plot = self.ploti.vb
self.ploti.hideButtons()
self.plotview.setCentralItem(self.ploti)
#.........这里部分代码省略.........
示例8: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [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(
#.........这里部分代码省略.........
示例9: SelectionSetsWidget
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [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())
#.........这里部分代码省略.........
示例10: OWImpute
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [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)
#.........这里部分代码省略.........
示例11: OWPythonScript
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [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))
#.........这里部分代码省略.........
示例12: OWGenotypeDistances
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [as 别名]
#.........这里部分代码省略.........
def set_data(self, data=None):
"""Set the input data table.
"""
self.closeContext()
self.clear()
self.error(0)
self.warning(0)
if data and not self.get_suitable_keys(data):
self.error(0, "Data has no suitable column labels.")
data = None
self.data = data
if data:
self.info_box.setText("{0} genes\n{1} experiments"
.format(len(data), len(data.domain)))
self.update_control()
self.split_data()
else:
self.separate_view.setModel(itemmodels.PyListModel([]))
self.relevant_view.setModel(itemmodels.PyListModel([]))
self.groups_scroll_area.setWidget(QWidget())
self.info_box.setText("No data on input.\n")
self.commit()
def update_control(self):
"""Update the control area of the widget. Populate the list
views with keys from attribute labels.
"""
keys = self.get_suitable_keys(self.data)
model = itemmodels.PyListModel(keys)
self.separate_view.setModel(model)
self.separate_view.selectionModel().selectionChanged.connect(
self.on_separate_key_changed)
model = itemmodels.PyListModel(keys)
self.relevant_view.setModel(model)
self.relevant_view.selectionModel().selectionChanged.connect(
self.on_relevant_key_changed)
self.openContext(keys)
# Get the selected keys from the open context
separate_keys = self.separate_keys
relevant_keys = self.relevant_keys
def select(model, selection_model, selected_items):
all_items = list(model)
try:
indices = [all_items.index(item) for item in selected_items]
except:
indices = []
selection = QItemSelection()
for ind in indices:
index = model.index(ind)
selection.select(index, index)
selection_model.select(selection, QItemSelectionModel.Select)
self._disable_updates = True
try:
select(self.relevant_view.model(),
self.relevant_view.selectionModel(),
relevant_keys)
示例13: DiscreteVariableEditor
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [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)
#.........这里部分代码省略.........
示例14: OWSpiralogram
# 需要导入模块: from AnyQt.QtWidgets import QListView [as 别名]
# 或者: from AnyQt.QtWidgets.QListView import selectionModel [as 别名]
class OWSpiralogram(widget.OWWidget):
name = 'Spiralogram'
description = "Visualize time series' periodicity in a spiral heatmap."
icon = 'icons/Spiralogram.svg'
priority = 120
class Inputs:
time_series = Input("Time series", Table)
class Outputs:
time_series = Output("Time series", Timeseries)
settingsHandler = settings.DomainContextHandler()
ax1 = settings.ContextSetting('months of year')
ax2 = settings.ContextSetting('years')
agg_attr = settings.ContextSetting([])
agg_func = settings.ContextSetting(0)
invert_date_order = settings.Setting(False)
graph_name = 'chart'
def __init__(self):
self.data = None
self.indices = []
box = gui.vBox(self.controlArea, 'Axes')
self.combo_ax2_model = VariableListModel(parent=self)
self.combo_ax1_model = VariableListModel(parent=self)
for model in (self.combo_ax1_model, self.combo_ax2_model):
model[:] = [_enum_str(i) for i in Spiralogram.AxesCategories]
self.combo_ax2 = gui.comboBox(
box, self, 'ax2', label='Y axis:', callback=self.replot,
sendSelectedValue=True, orientation='horizontal',
model=self.combo_ax2_model)
self.combo_ax1 = gui.comboBox(
box, self, 'ax1', label='Radial:', callback=self.replot,
sendSelectedValue=True, orientation='horizontal',
model=self.combo_ax1_model)
gui.checkBox(box, self, 'invert_date_order', 'Invert Y axis order',
callback=self.replot)
box = gui.vBox(self.controlArea, 'Aggregation')
self.combo_func = gui.comboBox(
box, self, 'agg_func', label='Function:', orientation='horizontal',
callback=self.replot)
func_model = ListModel(AGG_FUNCTIONS, parent=self)
self.combo_func.setModel(func_model)
self.attrlist_model = VariableListModel(parent=self)
self.attrlist = QListView(selectionMode=QListView.SingleSelection)
self.attrlist.setModel(self.attrlist_model)
self.attrlist.selectionModel().selectionChanged.connect(
self.attrlist_selectionChanged)
box.layout().addWidget(self.attrlist)
gui.rubber(self.controlArea)
self.chart = chart = Spiralogram(self,
selection_callback=self.on_selection)
self.mainArea.layout().addWidget(chart)
def attrlist_selectionChanged(self):
self.agg_attr = [self.attrlist_model[i.row()]
for i in self.attrlist.selectionModel().selectedIndexes()]
self.replot()
@Inputs.time_series
def set_data(self, data):
self.data = data = None if data is None else Timeseries.from_data_table(data)
def init_combos():
for model in (self.combo_ax1_model, self.combo_ax2_model):
model.clear()
newmodel = []
if data is not None and data.time_variable is not None:
for model in (self.combo_ax1_model, self.combo_ax2_model):
model[:] = [_enum_str(i) for i in Spiralogram.AxesCategories]
for var in data.domain.variables if data is not None else []:
if (var.is_primitive() and
(var is not data.time_variable or
isinstance(var, TimeVariable) and data.time_delta is None)):
newmodel.append(var)
if var.is_discrete:
for model in (self.combo_ax1_model, self.combo_ax2_model):
model.append(var)
self.attrlist_model.wrap(newmodel)
init_combos()
self.chart.clear()
if data is None:
self.commit()
return
self.closeContext()
self.ax2 = next((self.combo_ax2.itemText(i)
for i in range(self.combo_ax2.count())), '')
self.ax1 = next((self.combo_ax1.itemText(i)
#.........这里部分代码省略.........