本文整理汇总了Python中Orange.widgets.utils.itemmodels.VariableListModel.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python VariableListModel.wrap方法的具体用法?Python VariableListModel.wrap怎么用?Python VariableListModel.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.widgets.utils.itemmodels.VariableListModel
的用法示例。
在下文中一共展示了VariableListModel.wrap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Orange.widgets.utils.itemmodels import VariableListModel [as 别名]
# 或者: from Orange.widgets.utils.itemmodels.VariableListModel import wrap [as 别名]
def __init__(self):
super().__init__()
self.data = None
self.input_features = None
self.attrs = []
self.attr_box = gui.hBox(self.mainArea)
model = VariableListModel()
model.wrap(self.attrs)
self.attrXCombo = gui.comboBox(
self.attr_box, self, value="attrX", contentsLength=12,
callback=self.change_attr, sendSelectedValue=True, valueType=str)
self.attrXCombo.setModel(model)
gui.widgetLabel(self.attr_box, "\u2715").\
setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.attrYCombo = gui.comboBox(
self.attr_box, self, value="attrY", contentsLength=12,
callback=self.change_attr, sendSelectedValue=True, valueType=str)
self.attrYCombo.setModel(model)
self.canvas = QGraphicsScene()
self.canvasView = ViewWithPress(self.canvas, self.mainArea,
handler=self.reset_selection)
self.mainArea.layout().addWidget(self.canvasView)
self.canvasView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.canvasView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
box = gui.hBox(self.mainArea)
box.layout().addWidget(self.graphButton)
box.layout().addWidget(self.report_button)
示例2: OWGeoMap
# 需要导入模块: from Orange.widgets.utils.itemmodels import VariableListModel [as 别名]
# 或者: from Orange.widgets.utils.itemmodels.VariableListModel import wrap [as 别名]
class OWGeoMap(widget.OWWidget):
name = "GeoMap"
priority = 20000
icon = "icons/GeoMap.svg"
inputs = [("Data", Table, "on_data")]
outputs = [('Corpus', Corpus)]
want_main_area = False
selected_attr = settings.Setting('')
selected_map = settings.Setting(0)
regions = settings.Setting([])
def __init__(self):
super().__init__()
self.data = None
self._create_layout()
@pyqtSlot(str)
def region_selected(self, regions):
"""Called from JavaScript"""
if not regions:
self.regions = []
if not regions or self.data is None:
return self.send('Corpus', None)
self.regions = regions.split(',')
attr = self.data.domain[self.selected_attr]
if attr.is_discrete: return # TODO, FIXME: make this work for discrete attrs also
from Orange.data.filter import FilterRegex
filter = FilterRegex(attr, r'\b{}\b'.format(r'\b|\b'.join(self.regions)), re.IGNORECASE)
self.send('Corpus', self.data._filter_values(filter))
def _create_layout(self):
box = gui.widgetBox(self.controlArea,
orientation='horizontal')
self.varmodel = VariableListModel(parent=self)
self.attr_combo = gui.comboBox(box, self, 'selected_attr',
orientation=Qt.Horizontal,
label='Region attribute:',
callback=self.on_attr_change,
sendSelectedValue=True)
self.attr_combo.setModel(self.varmodel)
self.map_combo = gui.comboBox(box, self, 'selected_map',
orientation=Qt.Horizontal,
label='Map type:',
callback=self.on_map_change,
items=Map.all)
hexpand = QSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Fixed)
self.attr_combo.setSizePolicy(hexpand)
self.map_combo.setSizePolicy(hexpand)
url = urljoin('file:',
pathname2url(os.path.join(
os.path.dirname(__file__),
'resources',
'owgeomap.html')))
self.webview = gui.WebviewWidget(self.controlArea, self, url=QUrl(url))
self.controlArea.layout().addWidget(self.webview)
QTimer.singleShot(
0, lambda: self.webview.evalJS('REGIONS = {};'.format({Map.WORLD: CC_WORLD,
Map.EUROPE: CC_EUROPE,
Map.USA: CC_USA})))
def _repopulate_attr_combo(self, data):
vars = [a for a in chain(data.domain.metas,
data.domain.attributes,
data.domain.class_vars)
if a.is_string] if data else []
self.varmodel.wrap(vars)
# Select default attribute
self.selected_attr = next((var.name
for var in vars
if var.name.lower().startswith(('country', 'location', 'region'))),
vars[0].name if vars else '')
def on_data(self, data):
if data and not isinstance(data, Corpus):
data = Corpus.from_table(data.domain, data)
self.data = data
self._repopulate_attr_combo(data)
if not data:
self.region_selected('')
QTimer.singleShot(0, lambda: self.webview.evalJS('DATA = {}; renderMap();'))
else:
QTimer.singleShot(0, self.on_attr_change)
def on_map_change(self, map_code=''):
if map_code:
self.map_combo.setCurrentIndex(self.map_combo.findData(map_code))
else:
map_code = self.map_combo.itemData(self.selected_map)
inv_cc_map, cc_map = {Map.USA: (INV_CC_USA, CC_USA),
Map.WORLD: (INV_CC_WORLD, CC_WORLD),
Map.EUROPE: (INV_CC_EUROPE, CC_EUROPE)}[map_code]
# Set country counts for JS
data = defaultdict(int)
for locations in self._iter_locations():
#.........这里部分代码省略.........
示例3: OWSpiralogram
# 需要导入模块: from Orange.widgets.utils.itemmodels import VariableListModel [as 别名]
# 或者: from Orange.widgets.utils.itemmodels.VariableListModel import wrap [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)
#.........这里部分代码省略.........
示例4: OWLineChart
# 需要导入模块: from Orange.widgets.utils.itemmodels import VariableListModel [as 别名]
# 或者: from Orange.widgets.utils.itemmodels.VariableListModel import wrap [as 别名]
class OWLineChart(widget.OWWidget):
name = 'Line Chart'
description = "Visualize time series' sequence and progression."
icon = 'icons/LineChart.svg'
priority = 90
class Inputs:
time_series = Input("Time series", Table)
forecast = Input("Forecast", Timeseries, multiple=True)
attrs = settings.Setting({}) # Maps data.name -> [attrs]
graph_name = 'chart'
def __init__(self):
self.data = None
self.plots = []
self.configs = []
self.forecasts = OrderedDict()
self.varmodel = VariableListModel(parent=self)
icon = QIcon(join(dirname(__file__), 'icons', 'LineChart-plus.png'))
self.add_button = button = QPushButton(icon, ' &Add plot', self)
button.clicked.connect(self.add_plot)
self.controlArea.layout().addWidget(button)
self.configsArea = gui.vBox(self.controlArea)
self.controlArea.layout().addStretch(1)
# TODO: allow selecting ranges that are sent to output as subset table
self.chart = highstock = Highstock(self, highchart='StockChart')
self.mainArea.layout().addWidget(highstock)
# highstock.evalJS('Highcharts.setOptions({navigator: {enabled:false}});')
highstock.chart(
# For some reason, these options don't work as global opts applied at Highstock init time
# Disable top range selector
rangeSelector_enabled=False,
rangeSelector_inputEnabled=False,
# Disable bottom miniview navigator (it doesn't update)
navigator_enabled=False, )
QTimer.singleShot(0, self.add_plot)
def add_plot(self):
ax = self.chart.addAxis()
config = PlotConfigWidget(self, ax, self.varmodel)
# Connect the signals
config.sigSelection.connect(self.chart.setSeries)
config.sigLogarithmic.connect(self.chart.setLogarithmic)
config.sigType.connect(self.chart.setType)
config.sigClosed.connect(self.chart.removeAxis)
config.sigClosed.connect(lambda ax, widget: widget.setParent(None))
config.sigClosed.connect(lambda ax, widget:
self.add_button.setDisabled(False))
self.configs.append(config)
self.add_button.setDisabled(len(self.configs) >= 5)
self.configsArea.layout().addWidget(config)
@Inputs.time_series
def set_data(self, data):
# TODO: set xAxis resolution and tooltip time contents depending on
# data.time_delta. See: http://imgur.com/yrnlgQz
# If the same data is updated, short circuit to just updating the chart,
# retaining all panels and list view selections ...
if data is not None and self.data is not None and data.domain == self.data.domain:
self.data = Timeseries.from_data_table(data)
for config in self.configs:
config.selection_changed()
return
self.data = data = None if data is None else Timeseries.from_data_table(data)
if data is None:
self.varmodel.clear()
self.chart.clear()
return
if getattr(data.time_variable, 'utc_offset', False):
offset_minutes = data.time_variable.utc_offset.total_seconds() / 60
self.chart.evalJS('Highcharts.setOptions({global: {timezoneOffset: %d}});' % -offset_minutes) # Why is this negative? It works.
self.chart.chart()
self.chart.setXAxisType(
'datetime'
if (data.time_variable and
(getattr(data.time_variable, 'have_date', False) or
getattr(data.time_variable, 'have_time', False))) else
'linear')
self.varmodel.wrap([var for var in data.domain.variables
if var.is_continuous and var != data.time_variable])
@Inputs.forecast
def set_forecast(self, forecast, id):
if forecast is not None:
self.forecasts[id] = forecast
else:
self.forecasts.pop(id, None)
示例5: OWGeoMap
# 需要导入模块: from Orange.widgets.utils.itemmodels import VariableListModel [as 别名]
# 或者: from Orange.widgets.utils.itemmodels.VariableListModel import wrap [as 别名]
class OWGeoMap(widget.OWWidget):
name = "GeoMap"
priority = 20000
icon = "icons/GeoMap.svg"
inputs = [("Data", Table, "on_data")]
outputs = [('Corpus', Corpus)]
want_main_area = False
selected_attr = settings.Setting('')
selected_map = settings.Setting(0)
regions = settings.Setting([])
def __init__(self):
super().__init__()
self.data = None
self._create_layout()
@QtCore.pyqtSlot(str, result=str)
def region_selected(self, regions):
"""Called from JavaScript"""
if not regions:
self.regions = []
if not regions or self.data is None:
return self.send('Corpus', None)
self.regions = regions.split(',')
attr = self.data.domain[self.selected_attr]
if attr.is_discrete: return # TODO, FIXME: make this work for discrete attrs also
from Orange.data.filter import FilterRegex
filter = FilterRegex(attr, r'\b{}\b'.format(r'\b|\b'.join(self.regions)), re.IGNORECASE)
self.send('Corpus', self.data._filter_values(filter))
def _create_layout(self):
box = gui.widgetBox(self.controlArea,
orientation='horizontal')
self.varmodel = VariableListModel(parent=self)
self.attr_combo = gui.comboBox(box, self, 'selected_attr',
orientation=Qt.Horizontal,
label='Region attribute:',
callback=self.on_attr_change,
sendSelectedValue=True)
self.attr_combo.setModel(self.varmodel)
self.map_combo = gui.comboBox(box, self, 'selected_map',
orientation=Qt.Horizontal,
label='Map type:',
callback=self.on_map_change,
items=Map.all)
hexpand = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Fixed)
self.attr_combo.setSizePolicy(hexpand)
self.map_combo.setSizePolicy(hexpand)
html = '''
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="{}/"/>
<style>
html, body, #map {{margin:0px;padding:0px;width:100%;height:100%;}}
</style>
<link href="resources/jquery-jvectormap-2.0.2.css" rel="stylesheet">
<script src="resources/jquery-2.1.4.min.js"></script>
<script src="resources/jquery-jvectormap-2.0.2.min.js"></script>
<script src="resources/jquery-jvectormap-world-mill-en.js"></script>
<script src="resources/jquery-jvectormap-europe-mill-en.js"></script>
<script src="resources/jquery-jvectormap-us-aea-en.js"></script>
<script src="resources/geomap-script.js"></script>
</head>
<body>
<div id="map"></div>
</body>
</html>'''.format(urljoin('file:', pathname2url(path.abspath(path.dirname(__file__)))))
self.webview = gui.WebviewWidget(self.controlArea, self, debug=False)
self.controlArea.layout().addWidget(self.webview)
self.webview.setHtml(html)
QTimer.singleShot(
0, lambda: self.webview.evalJS('REGIONS = {};'.format({Map.WORLD: CC_WORLD,
Map.EUROPE: CC_EUROPE,
Map.USA: CC_USA})))
def _repopulate_attr_combo(self, data):
vars = [a for a in chain(data.domain.metas,
data.domain.attributes,
data.domain.class_vars)
if a.is_string] if data else []
self.varmodel.wrap(vars)
# Select default attribute
self.selected_attr = next((var.name
for var in vars
if var.name.lower().startswith(('country', 'location', 'region'))),
vars[0].name if vars else '')
def on_data(self, data):
if data and not isinstance(data, Corpus):
data = Corpus.from_table(data.domain, data)
self.data = data
self._repopulate_attr_combo(data)
if not data:
self.region_selected('')
QTimer.singleShot(0, lambda: self.webview.evalJS('DATA = {}; renderMap();'))
#.........这里部分代码省略.........
示例6: OWMovingTransform
# 需要导入模块: from Orange.widgets.utils.itemmodels import VariableListModel [as 别名]
# 或者: from Orange.widgets.utils.itemmodels.VariableListModel import wrap [as 别名]
#.........这里部分代码省略.........
combo.setModel(self._combo_model)
return combo
def setEditorData(self, combo, index):
var = index.model().data(index, Qt.EditRole)
combo.setCurrentIndex(self._combo_model.indexOf(var))
def setModelData(self, combo, model, index):
var = self._combo_model[combo.currentIndex()]
model.setData(index, var, Qt.EditRole)
class VariableDelegate(ComboDelegate):
@property
def _combo_model(self):
return self._parent.var_model
class SpinDelegate(_ItemDelegate):
def paint(self, painter, option, index):
# Don't paint window length if non-overlapping windows set
if not self.parent().non_overlapping:
super().paint(painter, option, index)
def createEditor(self, parent, _QStyleOptionViewItem, _index):
# Don't edit window length if non-overlapping windows set
if self.parent().non_overlapping:
return None
spin = QSpinBox(parent, minimum=1, maximum=1000)
return spin
def setEditorData(self, spin, index):
spin.setValue(index.model().data(index, Qt.EditRole))
def setModelData(self, spin, model, index):
spin.interpretText()
model.setData(index, spin.value(), Qt.EditRole)
self.var_model = VariableListModel(parent=self)
self.table_model = model = PyTableModel(self.transformations,
parent=self, editable=True)
model.setHorizontalHeaderLabels(['Series', 'Window width', 'Aggregation function'])
model.dataChanged.connect(self.on_changed)
self.view = view = TableView(self)
view.setModel(model)
box.layout().addWidget(view)
hbox = gui.hBox(box)
from os.path import dirname, join
self.add_button = button = gui.button(
hbox, self, 'Add &Transform',
callback=self.on_add_transform)
button.setIcon(QIcon(join(dirname(__file__), 'icons', 'LineChart-plus.png')))
self.del_button = button = gui.button(
hbox, self, '&Delete Selected',
callback=self.on_del_transform)
QIcon.setThemeName('gnome') # Works for me
button.setIcon(QIcon.fromTheme('edit-delete'))
gui.auto_commit(box, self, 'autocommit', '&Apply')
def sizeHint(self):
return QSize(450, 600)
def on_add_transform(self):
if self.data is not None:
self.table_model.append([self.var_model[0], self.last_win_width, AGG_FUNCTIONS[0]])
self.commit()
def on_del_transform(self):
for row in sorted([mi.row() for mi in self.view.selectionModel().selectedRows(0)],
reverse=True):
del self.table_model[row]
if len(self.table_model):
selection_model = self.view.selectionModel()
selection_model.select(self.table_model.index(len(self.table_model) - 1, 0),
selection_model.Select | selection_model.Rows)
self.commit()
def set_data(self, data):
self.data = data = None if data is None else Timeseries.from_data_table(data)
self.add_button.setDisabled(not len(getattr(data, 'domain', ())))
self.table_model.clear()
if data is not None:
self.var_model.wrap([var for var in data.domain
if var.is_continuous and var is not data.time_variable])
self.on_changed()
def on_changed(self):
self.commit()
def commit(self):
data = self.data
if not data:
self.send(Output.TIMESERIES, None)
return
ts = moving_transform(data, self.table_model, self.non_overlapping and self.fixed_wlen)
self.send(Output.TIMESERIES, ts)
示例7: OWMap
# 需要导入模块: from Orange.widgets.utils.itemmodels import VariableListModel [as 别名]
# 或者: from Orange.widgets.utils.itemmodels.VariableListModel import wrap [as 别名]
#.........这里部分代码省略.........
gui.rubber(self.controlArea)
gui.auto_commit(self.controlArea, self, 'autocommit', 'Send Selection')
QTimer.singleShot(0, _set_map_provider)
QTimer.singleShot(0, _toggle_legend)
QTimer.singleShot(0, _set_opacity)
QTimer.singleShot(0, _set_zoom)
QTimer.singleShot(0, _set_jittering)
QTimer.singleShot(0, _set_clustering)
autocommit = settings.Setting(True)
def __del__(self):
self.progressBarFinished(None)
self.map = None
def commit(self):
self.send('Selected Data', self.selection)
self.send(ANNOTATED_DATA_SIGNAL_NAME,
create_annotated_table(self.data, self._indices))
def set_data(self, data):
self.data = data
self.closeContext()
if data is None:
return self.clear()
all_vars = list(chain(self.data.domain, self.data.domain.metas))
continuous_vars = [var for var in all_vars if var.is_continuous]
discrete_vars = [var for var in all_vars if var.is_discrete]
primitive_vars = [var for var in all_vars if var.is_primitive()]
self._latlon_model.wrap(continuous_vars)
self._class_model.wrap(['(None)'] + primitive_vars)
self._color_model.wrap(['(Same color)'] + primitive_vars)
self._shape_model.wrap(['(Same shape)'] + discrete_vars)
self._size_model.wrap(['(Same size)'] + continuous_vars)
self._label_model.wrap(['(No labels)'] + all_vars)
def _find_lat_lon():
lat_attr = next(
(attr for attr in data.domain.variables + data.domain.metas
if attr.is_continuous and
attr.name.lower().startswith(('latitude', 'lat'))), None)
lon_attr = next(
(attr for attr in data.domain.variables + data.domain.metas
if attr.is_continuous and
attr.name.lower().startswith(('longitude', 'lng', 'long', 'lon'))), None)
def _is_between(vals, min, max):
return np.all((min <= vals) & (vals <= max))
if not lat_attr:
for attr in data.domain:
if attr.is_continuous:
values = np.nan_to_num(data.get_column_view(attr)[0])
if _is_between(values, -90, 90):
lat_attr = attr
if not lon_attr:
for attr in data.domain:
if attr.is_continuous:
values = np.nan_to_num(data.get_column_view(attr)[0])
if _is_between(values, -180, 180):
lon_attr = attr