def _create_layout(self): self._new_webview() box = gui.widgetBox(self.controlArea, 'Info') gui.label(box, self, '%(n_words)s words') gui.label(box, self, 'Mean weight: %(mean_weight).3f ± %(std_weight).3f') box = gui.widgetBox(self.controlArea, 'Cloud preferences') gui.checkBox(box, self, 'words_color', 'Color words', callback=self.on_cloud_pref_change) TILT_VALUES = ('no', 'slight', 'more', 'full') gui.valueSlider(box, self, 'words_tilt', label='Words tilt:', values=list(range(len(TILT_VALUES))), callback=self.on_cloud_pref_change, labelFormat=lambda x: TILT_VALUES[x]) gui.button(box, None, 'Regenerate word cloud', callback=self.on_cloud_pref_change) box = gui.widgetBox(self.controlArea, 'Words && weights') self.table = gui.TableWidget(box, col_labels=['Weight', 'Word'], multi_selection=True, select_rows=True) def _selection_changed(selected, deselected): for index in deselected.indexes(): data = self.table.rowData(index.row()) self.selected_words.remove(data) for index in selected.indexes(): data = self.table.rowData(index.row()) self.selected_words.add(data) self.cloud_reselect() self.table.selectionChanged = _selection_changed
def _create_layout(self): self._new_webview() box = gui.widgetBox(self.controlArea, 'Info') self.topic_info = gui.label(box, self, '%(n_topic_words)d words in a topic') gui.label(box, self, '%(documents_info_str)s') box = gui.widgetBox(self.controlArea, 'Cloud preferences') gui.checkBox(box, self, 'words_color', 'Color words', callback=self.on_cloud_pref_change) TILT_VALUES = ('no', 'slight', 'more', 'full') gui.valueSlider(box, self, 'words_tilt', label='Words tilt:', values=list(range(len(TILT_VALUES))), callback=self.on_cloud_pref_change, labelFormat=lambda x: TILT_VALUES[x]) gui.button(box, None, 'Regenerate word cloud', callback=self.on_cloud_pref_change) box = gui.widgetBox(self.controlArea, 'Words && weights') self.table = gui.TableWidget(box, col_labels=['Weight', 'Word'], multi_selection=True, select_rows=True) def _selection_changed(selected, deselected): for index in deselected.indexes(): data = self.table.rowData(index.row()) self.selected_words.remove(data) for index in selected.indexes(): data = self.table.rowData(index.row()) self.selected_words.add(data) self.cloud_reselect() self.table.selectionChanged = _selection_changed
def jitter_size_slider(self, widget): values = getattr(self._plot.master, "jitter_sizes", self.JITTER_SIZES) gui.valueSlider(widget=widget, master=self._plot, value='jitter_size', label="Jittering: ", values=values, callback=self._plot.master.reset_graph_data, labelFormat=lambda x: "None" if x == 0 else ("%.1f %%" if x < 1 else "%d %%") % x)
def _create_layout(self): self._new_webview() box = gui.widgetBox(self.controlArea, 'Info') self.topic_info = gui.label(box, self, '%(n_topic_words)d words in a topic') gui.label(box, self, '%(documents_info_str)s') box = gui.widgetBox(self.controlArea, 'Cloud preferences') gui.checkBox(box, self, 'words_color', 'Color words', callback=self.on_cloud_pref_change) TILT_VALUES = ('no', 'slight', 'more', 'full') gui.valueSlider(box, self, 'words_tilt', label='Words tilt:', values=list(range(len(TILT_VALUES))), callback=self.on_cloud_pref_change, labelFormat=lambda x: TILT_VALUES[x]) gui.button(box, None, 'Regenerate word cloud', callback=self.on_cloud_pref_change) box = gui.widgetBox(self.controlArea, 'Words && weights') class TableView(gui.TableView): def __init__(self, parent): super().__init__(parent) self._parent = parent def selectionChanged(self, selected, deselected): super().selectionChanged(selected, deselected) parent = self._parent for index in deselected.indexes(): data = parent.tablemodel[index.row()][1] self._parent.selected_words.remove(data) for index in selected.indexes(): data = parent.tablemodel[index.row()][1] self._parent.selected_words.add(data) parent.cloud_reselect() view = self.tableview = TableView(self) model = self.tablemodel = PyTableModel() model.setHorizontalHeaderLabels(['Weight', 'Word']) view.setModel(model) box.layout().addWidget(view)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api = WikipediaAPI(on_error=self.Error.api_error) self.result = None query_box = gui.hBox(self.controlArea, 'Query') # Queries configuration layout = QGridLayout() layout.setSpacing(7) row = 0 self.query_edit = ListEdit(self, 'query_list', "Each line represents a " "separate query.", 100, self) layout.addWidget(QLabel('Query word list:'), row, 0, 1, self.label_width) layout.addWidget(self.query_edit, row, self.label_width, 1, self.widgets_width) # Language row += 1 language_edit = ComboBox(self, 'language', tuple(sorted(lang2code.items()))) layout.addWidget(QLabel('Language:'), row, 0, 1, self.label_width) layout.addWidget(language_edit, row, self.label_width, 1, self.widgets_width) # Articles per query row += 1 layout.addWidget(QLabel('Articles per query:'), row, 0, 1, self.label_width) slider = gui.valueSlider(query_box, self, 'articles_per_query', box='', values=[1, 3, 5, 10, 25]) layout.addWidget(slider.box, row, 1, 1, self.widgets_width) query_box.layout().addLayout(layout) self.controlArea.layout().addWidget(query_box) self.controlArea.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.info_box = gui.hBox(self.controlArea, 'Info') self.result_label = gui.label(self.info_box, self, self.info_label.format(0)) self.button_box = gui.hBox(self.controlArea) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop) self.search_button.setFocusPolicy(Qt.NoFocus)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api = WikipediaAPI(on_error=self.Error.api_error) self.result = None query_box = gui.hBox(self.controlArea, '查询') # Queries configuration layout = QGridLayout() layout.setSpacing(7) row = 0 self.query_edit = ListEdit(self, 'query_list', "每一行表示一个不同的查询", 100, self) layout.addWidget(QLabel('查询词:'), row, 0, 1, self.label_width) layout.addWidget(self.query_edit, row, self.label_width, 1, self.widgets_width) # Articles per query row += 1 layout.addWidget(QLabel('每次查询文章数量:'), row, 0, 1, self.label_width) slider = gui.valueSlider(query_box, self, 'articles_per_query', box='', values=[10, 30, 50, 80, 100]) layout.addWidget(slider.box, row, 1, 1, self.widgets_width) query_box.layout().addLayout(layout) self.controlArea.layout().addWidget(query_box) self.controlArea.layout().addWidget( CheckListLayout('包含的内容', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.info_box = gui.hBox(self.controlArea, '基本信息') self.result_label = gui.label(self.info_box, self, self.info_label.format(0)) self.button_box = gui.hBox(self.controlArea) self.search_button = gui.button(self.button_box, self, '查询', self.start_stop) self.search_button.setFocusPolicy(Qt.NoFocus)
def __init__(self): super().__init__() self.map = map = LeafletMap(self) # type: LeafletMap self.mainArea.layout().addWidget(map) self.selection = None self.data = None self.learner = None def selectionChanged(indices): self.selection = self.data[indices] if self.data is not None and indices else None self._indices = indices self.commit() map.selectionChanged.connect(selectionChanged) def _set_map_provider(): map.set_map_provider(self.TILE_PROVIDERS[self.tile_provider]) box = gui.vBox(self.controlArea, 'Map') gui.comboBox(box, self, 'tile_provider', orientation=Qt.Horizontal, label='Map:', items=tuple(self.TILE_PROVIDERS.keys()), sendSelectedValue=True, callback=_set_map_provider) self._latlon_model = DomainModel( parent=self, valid_types=ContinuousVariable) self._class_model = DomainModel( parent=self, placeholder='(None)', valid_types=DomainModel.PRIMITIVE) self._color_model = DomainModel( parent=self, placeholder='(Same color)', valid_types=DomainModel.PRIMITIVE) self._shape_model = DomainModel( parent=self, placeholder='(Same shape)', valid_types=DiscreteVariable) self._size_model = DomainModel( parent=self, placeholder='(Same size)', valid_types=ContinuousVariable) self._label_model = DomainModel( parent=self, placeholder='(No labels)') def _set_lat_long(): self.map.set_data(self.data, self.lat_attr, self.lon_attr) self.train_model() self._combo_lat = combo = gui.comboBox( box, self, 'lat_attr', orientation=Qt.Horizontal, label='Latitude:', sendSelectedValue=True, callback=_set_lat_long) combo.setModel(self._latlon_model) self._combo_lon = combo = gui.comboBox( box, self, 'lon_attr', orientation=Qt.Horizontal, label='Longitude:', sendSelectedValue=True, callback=_set_lat_long) combo.setModel(self._latlon_model) def _toggle_legend(): self.map.toggle_legend(self.show_legend) gui.checkBox(box, self, 'show_legend', label='Show legend', callback=_toggle_legend) box = gui.vBox(self.controlArea, 'Overlay') self._combo_class = combo = gui.comboBox( box, self, 'class_attr', orientation=Qt.Horizontal, label='Target:', sendSelectedValue=True, callback=self.train_model ) self.controls.class_attr.setModel(self._class_model) self.set_learner(self.learner) box = gui.vBox(self.controlArea, 'Points') self._combo_color = combo = gui.comboBox( box, self, 'color_attr', orientation=Qt.Horizontal, label='Color:', sendSelectedValue=True, callback=lambda: self.map.set_marker_color(self.color_attr)) combo.setModel(self._color_model) self._combo_label = combo = gui.comboBox( box, self, 'label_attr', orientation=Qt.Horizontal, label='Label:', sendSelectedValue=True, callback=lambda: self.map.set_marker_label(self.label_attr)) combo.setModel(self._label_model) self._combo_shape = combo = gui.comboBox( box, self, 'shape_attr', orientation=Qt.Horizontal, label='Shape:', sendSelectedValue=True, callback=lambda: self.map.set_marker_shape(self.shape_attr)) combo.setModel(self._shape_model) self._combo_size = combo = gui.comboBox( box, self, 'size_attr', orientation=Qt.Horizontal, label='Size:', sendSelectedValue=True, callback=lambda: self.map.set_marker_size(self.size_attr)) combo.setModel(self._size_model) def _set_opacity(): map.set_marker_opacity(self.opacity) def _set_zoom(): map.set_marker_size_coefficient(self.zoom) def _set_jittering(): map.set_jittering(self.jittering) def _set_clustering(): map.set_clustering(self.cluster_points) self._opacity_slider = gui.hSlider( box, self, 'opacity', None, 1, 100, 5, label='Opacity:', labelFormat=' %d%%', callback=_set_opacity) self._zoom_slider = gui.valueSlider( box, self, 'zoom', None, values=(20, 50, 100, 200, 300, 400, 500, 700, 1000), label='Symbol size:', labelFormat=' %d%%', callback=_set_zoom) self._jittering = gui.valueSlider( box, self, 'jittering', label='Jittering:', values=(0, .5, 1, 2, 5), labelFormat=' %.1f%%', ticks=True, callback=_set_jittering) self._clustering_check = gui.checkBox( box, self, 'cluster_points', label='Cluster points', callback=_set_clustering) 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)
def __init__(self): super().__init__() box = gui.widgetBox(self.mainArea, True, margin=0) self.graph = OWScatterPlotGraph(self, box, "ScatterPlot") box.layout().addWidget(self.graph.plot_widget) plot = self.graph.plot_widget axisfont = font_resize(self.font(), 0.8, minsize=11) axispen = QtGui.QPen(self.palette().color(QtGui.QPalette.Text)) axis = plot.getAxis("bottom") axis.setTickFont(axisfont) axis.setPen(axispen) axis = plot.getAxis("left") axis.setTickFont(axisfont) axis.setPen(axispen) self.data = None # Orange.data.Table self.subset_data = None # Orange.data.Table self.attribute_selection_list = None # list of Orange.data.Variable self.selection_dirty = False common_options = { "labelWidth": 50, "orientation": "horizontal", "sendSelectedValue": True, "valueType": str } box = gui.widgetBox(self.controlArea, "Axis Data") self.cb_attr_x = gui.comboBox(box, self, "attr_x", label="Axis x:", callback=self.major_graph_update, **common_options) self.cb_attr_y = gui.comboBox(box, self, "attr_y", label="Axis y:", callback=self.major_graph_update, **common_options) gui.valueSlider(box, self, value='graph.jitter_size', label='Jittering: ', values=self.jitter_sizes, callback=self.reset_graph_data, labelFormat=lambda x: "None" if x == 0 else ("%.1f %%" if x < 1 else "%d %%") % x) gui.checkBox(gui.indentedBox(box), self, 'graph.jitter_continuous', 'Jitter continuous values', callback=self.reset_graph_data) box = gui.widgetBox(self.controlArea, "Points") self.cb_attr_color = gui.comboBox(box, self, "graph.attr_color", label="Color:", emptyString="(Same color)", callback=self.graph.update_colors, **common_options) self.cb_attr_label = gui.comboBox(box, self, "graph.attr_label", label="Label:", emptyString="(No labels)", callback=self.graph.update_labels, **common_options) self.cb_attr_shape = gui.comboBox(box, self, "graph.attr_shape", label="Shape:", emptyString="(Same shape)", callback=self.graph.update_shapes, **common_options) self.cb_attr_size = gui.comboBox(box, self, "graph.attr_size", label="Size:", emptyString="(Same size)", callback=self.graph.update_sizes, **common_options) g = self.graph.gui box2 = g.point_properties_box(self.controlArea, box) gui.button(box2, self, "Set Colors", self.set_colors) box = gui.widgetBox(self.controlArea, "Plot Properties") g.add_widgets([g.ShowLegend, g.ShowGridLines], box) gui.checkBox(box, self, value='graph.tooltip_shows_all', label='Show all data on mouse hover') gui.separator(self.controlArea, 8, 8) self.zoom_select_toolbar = g.zoom_select_toolbar( self.controlArea, nomargin=True, buttons=[ g.StateButtonsBegin, g.SimpleSelect, g.Pan, g.Zoom, g.StateButtonsEnd, g.ZoomReset, g.Spacing, g.SendSelection ]) buttons = self.zoom_select_toolbar.buttons buttons[g.SendSelection].clicked.connect(self.send_selection) buttons[g.Zoom].clicked.connect(self.graph.zoom_button_clicked) buttons[g.Pan].clicked.connect(self.graph.pan_button_clicked) buttons[g.SimpleSelect].clicked.connect( self.graph.select_button_clicked) buttons[g.ZoomReset].clicked.connect(self.graph.reset_button_clicked) cb_auto_send = gui.checkBox(box, self, 'auto_send_selection', 'Send selection on change') gui.setStopper(self, buttons[g.SendSelection], cb_auto_send, "selection_dirty", self.send_selection) self.controlArea.layout().addStretch(100) self.icons = gui.attributeIconDict dlg = self.create_color_dialog() self.graph.continuous_palette = dlg.getContinuousPalette("contPalette") self.graph.discrete_palette = dlg.getDiscretePalette("discPalette") dlg.deleteLater() p = self.graph.plot_widget.palette() self.graph.set_palette(p) self.zoom_select_toolbar.buttons[OWPlotGUI.SendSelection].setEnabled( not self.auto_send_selection) def zoom(s): """Zoom in/out by factor `s`.""" viewbox = plot.getViewBox() # scaleBy scales the view's bounds (the axis range) viewbox.scaleBy((1 / s, 1 / s)) def fit_to_view(): viewbox = plot.getViewBox() viewbox.autoRange() zoom_in = QtGui.QAction("Zoom in", self, triggered=lambda: zoom(1.25)) zoom_in.setShortcuts([ QtGui.QKeySequence(QtGui.QKeySequence.ZoomIn), QtGui.QKeySequence(self.tr("Ctrl+=")) ]) zoom_out = QtGui.QAction("Zoom out", self, shortcut=QtGui.QKeySequence.ZoomOut, triggered=lambda: zoom(1 / 1.25)) zoom_fit = QtGui.QAction("Fit in view", self, shortcut=QtGui.QKeySequence(Qt.ControlModifier | Qt.Key_0), triggered=fit_to_view) self.addActions([zoom_in, zoom_out, zoom_fit])
def __init__(self): super().__init__() self.map = map = LeafletMap(self) self.mainArea.layout().addWidget(map) self.selection = None self.data = None self.learner = None def selectionChanged(indices): self.selection = self.data[indices] if self.data is not None and indices else None self._indices = indices self.commit() map.selectionChanged.connect(selectionChanged) def _set_map_provider(): map.set_map_provider(self.TILE_PROVIDERS[self.tile_provider]) box = gui.vBox(self.controlArea, 'Map') gui.comboBox(box, self, 'tile_provider', orientation=Qt.Horizontal, label='Map:', items=tuple(self.TILE_PROVIDERS.keys()), sendSelectedValue=True, callback=_set_map_provider) self._latlon_model = DomainModel( parent=self, valid_types=ContinuousVariable) self._class_model = DomainModel( parent=self, placeholder='(None)', valid_types=DomainModel.PRIMITIVE) self._color_model = DomainModel( parent=self, placeholder='(Same color)', valid_types=DomainModel.PRIMITIVE) self._shape_model = DomainModel( parent=self, placeholder='(Same shape)', valid_types=DiscreteVariable) self._size_model = DomainModel( parent=self, placeholder='(Same size)', valid_types=ContinuousVariable) self._label_model = DomainModel( parent=self, placeholder='(No labels)') def _set_lat_long(): self.map.set_data(self.data, self.lat_attr, self.lon_attr) self.train_model() self._combo_lat = combo = gui.comboBox( box, self, 'lat_attr', orientation=Qt.Horizontal, label='Latitude:', sendSelectedValue=True, callback=_set_lat_long) combo.setModel(self._latlon_model) self._combo_lon = combo = gui.comboBox( box, self, 'lon_attr', orientation=Qt.Horizontal, label='Longitude:', sendSelectedValue=True, callback=_set_lat_long) combo.setModel(self._latlon_model) def _toggle_legend(): self.map.toggle_legend(self.show_legend) gui.checkBox(box, self, 'show_legend', label='Show legend', callback=_toggle_legend) box = gui.vBox(self.controlArea, 'Overlay') self._combo_class = combo = gui.comboBox( box, self, 'class_attr', orientation=Qt.Horizontal, label='Target:', sendSelectedValue=True, callback=self.train_model ) self.controls.class_attr.setModel(self._class_model) self.set_learner(self.learner) box = gui.vBox(self.controlArea, 'Points') self._combo_color = combo = gui.comboBox( box, self, 'color_attr', orientation=Qt.Horizontal, label='Color:', sendSelectedValue=True, callback=lambda: self.map.set_marker_color(self.color_attr)) combo.setModel(self._color_model) self._combo_label = combo = gui.comboBox( box, self, 'label_attr', orientation=Qt.Horizontal, label='Label:', sendSelectedValue=True, callback=lambda: self.map.set_marker_label(self.label_attr)) combo.setModel(self._label_model) self._combo_shape = combo = gui.comboBox( box, self, 'shape_attr', orientation=Qt.Horizontal, label='Shape:', sendSelectedValue=True, callback=lambda: self.map.set_marker_shape(self.shape_attr)) combo.setModel(self._shape_model) self._combo_size = combo = gui.comboBox( box, self, 'size_attr', orientation=Qt.Horizontal, label='Size:', sendSelectedValue=True, callback=lambda: self.map.set_marker_size(self.size_attr)) combo.setModel(self._size_model) def _set_opacity(): map.set_marker_opacity(self.opacity) def _set_zoom(): map.set_marker_size_coefficient(self.zoom) def _set_jittering(): map.set_jittering(self.jittering) def _set_clustering(): map.set_clustering(self.cluster_points) self._opacity_slider = gui.hSlider( box, self, 'opacity', None, 1, 100, 5, label='Opacity:', labelFormat=' %d%%', callback=_set_opacity) self._zoom_slider = gui.valueSlider( box, self, 'zoom', None, values=(20, 50, 100, 200, 300, 400, 500, 700, 1000), label='Symbol size:', labelFormat=' %d%%', callback=_set_zoom) self._jittering = gui.valueSlider( box, self, 'jittering', label='Jittering:', values=(0, .5, 1, 2, 5), labelFormat=' %.1f%%', ticks=True, callback=_set_jittering) self._clustering_check = gui.checkBox( box, self, 'cluster_points', label='Cluster points', callback=_set_clustering) 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)
def __init__(self): super().__init__() box = gui.widgetBox(self.mainArea, True, margin=0) self.graph = OWScatterPlotGraph(self, box, "ScatterPlot") box.layout().addWidget(self.graph.plot_widget) plot = self.graph.plot_widget axispen = QtGui.QPen(self.palette().color(QtGui.QPalette.Text)) axis = plot.getAxis("bottom") axis.setPen(axispen) axis = plot.getAxis("left") axis.setPen(axispen) self.data = None # Orange.data.Table self.subset_data = None # Orange.data.Table self.data_metas_X = None # self.data, where primitive metas are moved to X self.attribute_selection_list = None # list of Orange.data.Variable common_options = {"labelWidth": 50, "orientation": "horizontal", "sendSelectedValue": True, "valueType": str} box = gui.widgetBox(self.controlArea, "Axis Data") self.cb_attr_x = gui.comboBox(box, self, "attr_x", label="Axis x:", callback=self.update_attr, **common_options) self.cb_attr_y = gui.comboBox(box, self, "attr_y", label="Axis y:", callback=self.update_attr, **common_options) self.vizrank = self.VizRank(self) vizrank_box = gui.widgetBox(box, None, orientation='horizontal') gui.separator(vizrank_box, width=common_options["labelWidth"]) self.vizrank_button = gui.button( vizrank_box, self, "Rank projections", callback=self.vizrank.reshow, tooltip="Find projections with good class separation") self.vizrank_button.setEnabled(False) gui.separator(box) gui.valueSlider( box, self, value='graph.jitter_size', label='Jittering: ', values=self.jitter_sizes, callback=self.reset_graph_data, labelFormat=lambda x: "None" if x == 0 else ("%.1f %%" if x < 1 else "%d %%") % x) gui.checkBox( gui.indentedBox(box), self, 'graph.jitter_continuous', 'Jitter continuous values', callback=self.reset_graph_data) box = gui.widgetBox(self.controlArea, "Points") self.cb_attr_color = gui.comboBox( box, self, "graph.attr_color", label="Color:", emptyString="(Same color)", callback=self.update_colors, **common_options) self.cb_attr_label = gui.comboBox( box, self, "graph.attr_label", label="Label:", emptyString="(No labels)", callback=self.graph.update_labels, **common_options) self.cb_attr_shape = gui.comboBox( box, self, "graph.attr_shape", label="Shape:", emptyString="(Same shape)", callback=self.graph.update_shapes, **common_options) self.cb_attr_size = gui.comboBox( box, self, "graph.attr_size", label="Size:", emptyString="(Same size)", callback=self.graph.update_sizes, **common_options) g = self.graph.gui box2 = g.point_properties_box(self.controlArea, box) gui.button(box2, self, "Set Colors", self.set_colors) box = gui.widgetBox(self.controlArea, "Plot Properties") g.add_widgets([g.ShowLegend, g.ShowGridLines], box) gui.checkBox(box, self, value='graph.tooltip_shows_all', label='Show all data on mouse hover') self.cb_class_density = gui.checkBox( box, self, value='graph.class_density', label='Show class density', callback=self.update_density) self.zoom_select_toolbar = g.zoom_select_toolbar( gui.widgetBox(self.controlArea, "Zoom/Select"), nomargin=True, buttons=[g.StateButtonsBegin, g.SimpleSelect, g.Pan, g.Zoom, g.StateButtonsEnd, g.ZoomReset] ) buttons = self.zoom_select_toolbar.buttons buttons[g.Zoom].clicked.connect(self.graph.zoom_button_clicked) buttons[g.Pan].clicked.connect(self.graph.pan_button_clicked) buttons[g.SimpleSelect].clicked.connect(self.graph.select_button_clicked) buttons[g.ZoomReset].clicked.connect(self.graph.reset_button_clicked) self.controlArea.layout().addStretch(100) self.icons = gui.attributeIconDict dlg = self.create_color_dialog() self.graph.continuous_palette = dlg.getContinuousPalette("contPalette") self.graph.discrete_palette = dlg.getDiscretePalette("discPalette") dlg.deleteLater() p = self.graph.plot_widget.palette() self.graph.set_palette(p) gui.auto_commit(self.controlArea, self, "auto_send_selection", "Send Selection") def zoom(s): """Zoom in/out by factor `s`.""" viewbox = plot.getViewBox() # scaleBy scales the view's bounds (the axis range) viewbox.scaleBy((1 / s, 1 / s)) def fit_to_view(): viewbox = plot.getViewBox() viewbox.autoRange() zoom_in = QtGui.QAction( "Zoom in", self, triggered=lambda: zoom(1.25) ) zoom_in.setShortcuts([QtGui.QKeySequence(QtGui.QKeySequence.ZoomIn), QtGui.QKeySequence(self.tr("Ctrl+="))]) zoom_out = QtGui.QAction( "Zoom out", self, shortcut=QtGui.QKeySequence.ZoomOut, triggered=lambda: zoom(1 / 1.25) ) zoom_fit = QtGui.QAction( "Fit in view", self, shortcut=QtGui.QKeySequence(Qt.ControlModifier | Qt.Key_0), triggered=fit_to_view ) self.addActions([zoom_in, zoom_out, zoom_fit]) self.graphButton.clicked.connect(self.save_graph)
def __init__(self): super().__init__() self._delta = 0 self.play_timer = QTimer(self, interval=1000 * self.playback_interval, timeout=self.play_single_step) slider = self.slider = Slider(Qt.Horizontal, self, minimum=0, maximum=self.MAX_SLIDER_VALUE, tracking=True, playbackInterval=1000 * self.playback_interval, valuesChanged=self.sliderValuesChanged, minimumValue=self.slider_values[0], maximumValue=self.slider_values[1]) slider.setShowText(False) selectBox = gui.vBox(self.controlArea, 'Select a Time Range') selectBox.layout().addWidget(slider) dtBox = gui.hBox(selectBox) kwargs = dict(calendarPopup=True, displayFormat=' '.join(self.DATE_FORMATS), timeSpec=Qt.UTC) date_from = self.date_from = QDateTimeEdit(self, **kwargs) date_to = self.date_to = QDateTimeEdit(self, **kwargs) def datetime_edited(dt_edit): minTime = self.date_from.dateTime().toMSecsSinceEpoch() / 1000 maxTime = self.date_to.dateTime().toMSecsSinceEpoch() / 1000 if minTime > maxTime: minTime = maxTime = minTime if dt_edit == self.date_from else maxTime other = self.date_to if dt_edit == self.date_from else self.date_from with blockSignals(other): other.setDateTime(dt_edit.dateTime()) self.dteditValuesChanged(minTime, maxTime) date_from.dateTimeChanged.connect(lambda: datetime_edited(date_from)) date_to.dateTimeChanged.connect(lambda: datetime_edited(date_to)) # hotfix, does not repaint on click of arrow date_from.calendarWidget().currentPageChanged.connect( lambda: date_from.calendarWidget().repaint()) date_to.calendarWidget().currentPageChanged.connect( lambda: date_to.calendarWidget().repaint()) dtBox.layout().addStretch(100) dtBox.layout().addWidget(date_from) dtBox.layout().addWidget(QLabel(' – ')) dtBox.layout().addWidget(date_to) dtBox.layout().addStretch(100) hCenterBox = gui.hBox(self.controlArea) gui.rubber(hCenterBox) vControlsBox = gui.vBox(hCenterBox) stepThroughBox = gui.vBox(vControlsBox, 'Step/Play Through') gui.rubber(stepThroughBox) gui.checkBox(stepThroughBox, self, 'loop_playback', label='Loop playback') customStepBox = gui.hBox(stepThroughBox) gui.checkBox( customStepBox, self, 'custom_step_size', label='Custom step size: ', toolTip='If not chosen, the active interval moves forward ' '(backward), stepping in increments of its own size.') self.stepsize_combobox = gui.comboBox(customStepBox, self, 'step_size', items=tuple( self.STEP_SIZES.keys()), sendSelectedValue=True) playBox = gui.hBox(stepThroughBox) gui.rubber(playBox) gui.rubber(stepThroughBox) if self.icons_font is None: self.icons_font = load_icons_font() self.step_backward = gui.button( playBox, self, '⏪', callback=lambda: self.play_single_step(backward=True), autoDefault=False) self.step_backward.setFont(self.icons_font) self.play_button = gui.button(playBox, self, '▶️', callback=self.playthrough, toggleButton=True, default=True) self.play_button.setFont(self.icons_font) self.step_forward = gui.button(playBox, self, '⏩', callback=self.play_single_step, autoDefault=False) self.step_forward.setFont(self.icons_font) gui.rubber(playBox) intervalBox = gui.vBox(vControlsBox, 'Playback/Tracking interval') intervalBox.setToolTip( 'In milliseconds, set the delay for playback and ' 'for sending data upon manually moving the interval.') def set_intervals(): self.play_timer.setInterval(1000 * self.playback_interval) self.slider.tracking_timer.setInterval(1000 * self.playback_interval) gui.valueSlider(intervalBox, self, 'playback_interval', label='Delay:', labelFormat='%.2g sec', values=self.DELAY_VALUES, callback=set_intervals) gui.rubber(hCenterBox) gui.rubber(self.controlArea) self._set_disabled(True)
def __init__(self): self._is_running = False self.isRegexMatch = lambda x: True self.tree = QTreeWidget( self.mainArea, columnCount=2, allColumnsShowFocus=True, alternatingRowColors=True, selectionMode=QTreeWidget.ExtendedSelection, uniformRowHeights=True, ) self.tree.setHeaderLabels(["Itemsets", "Support", "%"]) self.tree.header().setStretchLastSection(True) self.tree.itemSelectionChanged.connect(self.selectionChanged) self.mainArea.layout().addWidget(self.tree) box = gui.widgetBox(self.controlArea, "Info") self.nItemsets = self.nSelectedExamples = self.nSelectedItemsets = "" gui.label(box, self, "Number of itemsets: %(nItemsets)s") gui.label(box, self, "Selected itemsets: %(nSelectedItemsets)s") gui.label(box, self, "Selected examples: %(nSelectedExamples)s") hbox = gui.widgetBox(box, orientation="horizontal") gui.button(hbox, self, "Expand all", callback=self.tree.expandAll) gui.button(hbox, self, "Collapse all", callback=self.tree.collapseAll) box = gui.widgetBox(self.controlArea, "Find itemsets") gui.valueSlider( box, self, "minSupport", values=[0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1, 0.5] + list(range(1, 101)), label="Minimal support:", labelFormat="%g%%", callback=lambda: self.find_itemsets(), ) gui.hSlider( box, self, "maxItemsets", minValue=10000, maxValue=100000, step=10000, label="Max. number of itemsets:", labelFormat="%d", callback=lambda: self.find_itemsets(), ) self.button = gui.auto_commit(box, self, "autoFind", "Find itemsets", commit=self.find_itemsets) box = gui.widgetBox(self.controlArea, "Filter itemsets") gui.lineEdit( box, self, "filterKeywords", "Contains:", callback=self.filter_change, orientation="horizontal", tooltip="A comma or space-separated list of regular " "expressions.", ) hbox = gui.widgetBox(box, orientation="horizontal") gui.spin(hbox, self, "filterMinItems", 1, 998, label="Min. items:", callback=self.filter_change) gui.spin(hbox, self, "filterMaxItems", 2, 999, label="Max. items:", callback=self.filter_change) gui.checkBox( box, self, "filterSearch", label="Apply these filters in search", tooltip="If checked, the itemsets are filtered according " "to these filter conditions already in the search " "phase. \nIf unchecked, the only filters applied " "during search are the ones above, " "and the itemsets are \nfiltered afterwards only for " "display, i.e. only the matching itemsets are shown.", ) gui.rubber(hbox) gui.rubber(self.controlArea) gui.auto_commit(self.controlArea, self, "autoSend", "Send selection") self.filter_change()
def _create_layout(self): box = gui.widgetBox(self.controlArea, "Cloud preferences") gui.checkBox( box, self, "words_color", "Color words", callback=self.on_cloud_pref_change, ) gui.valueSlider( box, self, "words_tilt", label="Words tilt:", values=list(range(len(TILT_VALUES))), callback=self.on_cloud_pref_change, labelFormat=lambda x: TILT_VALUES[x], ) box = gui.widgetBox(self.controlArea, "Words && weights") class TableView(gui.TableView): def __init__(self, parent): super().__init__(parent) self._parent = parent self.__nope = False def setModel(self, model): """Otherwise QTableView.setModel() calls QAbstractItemView.setSelectionModel() which resets selection, calling selectionChanged() and overwriting any selected_words setting that may have been saved.""" self.__nope = True super().setModel(model) self.__nope = False def selectionChanged(self, selected, deselected): nonlocal model, proxymodel super().selectionChanged(selected, deselected) if not self.__nope: words = { model[proxymodel.mapToSource(index).row()][1] for index in self.selectionModel().selectedIndexes() } self._parent.update_selection(words, self) def update_selection(self, words): nonlocal model, proxymodel selection = QItemSelection() for i, (_, word) in enumerate(model): if word in words: index = proxymodel.mapFromSource(model.index(i, 1)) selection.select(index, index) self.__nope = True self.clearSelection() self.selectionModel().select( selection, QItemSelectionModel.Select | QItemSelectionModel.Rows, ) self.__nope = False view = self.tableview = TableView(self) model = self.tablemodel = TableModel(2, parent=self) proxymodel = QSortFilterProxyModel( self, dynamicSortFilter=True, sortCaseSensitivity=Qt.CaseInsensitive, sortRole=Qt.EditRole, ) proxymodel.setSourceModel(model) model.setHorizontalHeaderLabels(["Weight", "Word"]) view.setModel(proxymodel) box.layout().addWidget(view)
def __init__(self): super().__init__() box = gui.widgetBox(self.mainArea, True, margin=0) self.graph = OWScatterPlotGraph(self, box, "ScatterPlot") box.layout().addWidget(self.graph.plot_widget) plot = self.graph.plot_widget axispen = QtGui.QPen(self.palette().color(QtGui.QPalette.Text)) axis = plot.getAxis("bottom") axis.setPen(axispen) axis = plot.getAxis("left") axis.setPen(axispen) self.data = None # Orange.data.Table self.subset_data = None # Orange.data.Table self.data_metas_X = None # self.data, where primitive metas are moved to X self.sql_data = None # Orange.data.sql.table.SqlTable self.attribute_selection_list = None # list of Orange.data.Variable self.__timer = QTimer(self, interval=1200) self.__timer.timeout.connect(self.add_data) common_options = { "labelWidth": 50, "orientation": "horizontal", "sendSelectedValue": True, "valueType": str } box = gui.widgetBox(self.controlArea, "Axis Data") self.cb_attr_x = gui.comboBox(box, self, "attr_x", label="Axis x:", callback=self.update_attr, **common_options) self.cb_attr_y = gui.comboBox(box, self, "attr_y", label="Axis y:", callback=self.update_attr, **common_options) self.vizrank = self.VizRank(self) vizrank_box = gui.widgetBox(box, None, orientation='horizontal') gui.separator(vizrank_box, width=common_options["labelWidth"]) self.vizrank_button = gui.button( vizrank_box, self, "Rank projections", callback=self.vizrank.reshow, tooltip="Find projections with good class separation") self.vizrank_button.setEnabled(False) gui.separator(box) gui.valueSlider(box, self, value='graph.jitter_size', label='Jittering: ', values=self.jitter_sizes, callback=self.reset_graph_data, labelFormat=lambda x: "None" if x == 0 else ("%.1f %%" if x < 1 else "%d %%") % x) gui.checkBox(gui.indentedBox(box), self, 'graph.jitter_continuous', 'Jitter continuous values', callback=self.reset_graph_data) self.sampling = gui.auto_commit(self.controlArea, self, "auto_sample", "Sample", box="Sampling", callback=self.switch_sampling, commit=lambda: self.add_data(1)) self.sampling.setVisible(False) box = gui.widgetBox(self.controlArea, "Points") self.cb_attr_color = gui.comboBox(box, self, "graph.attr_color", label="Color:", emptyString="(Same color)", callback=self.update_colors, **common_options) self.cb_attr_label = gui.comboBox(box, self, "graph.attr_label", label="Label:", emptyString="(No labels)", callback=self.graph.update_labels, **common_options) self.cb_attr_shape = gui.comboBox(box, self, "graph.attr_shape", label="Shape:", emptyString="(Same shape)", callback=self.graph.update_shapes, **common_options) self.cb_attr_size = gui.comboBox(box, self, "graph.attr_size", label="Size:", emptyString="(Same size)", callback=self.graph.update_sizes, **common_options) g = self.graph.gui box2 = g.point_properties_box(self.controlArea, box) box = gui.widgetBox(self.controlArea, "Plot Properties") g.add_widgets([g.ShowLegend, g.ShowGridLines], box) gui.checkBox(box, self, value='graph.tooltip_shows_all', label='Show all data on mouse hover') self.cb_class_density = gui.checkBox(box, self, value='graph.class_density', label='Show class density', callback=self.update_density) self.zoom_select_toolbar = g.zoom_select_toolbar( gui.widgetBox(self.controlArea, "Zoom/Select"), nomargin=True, buttons=[ g.StateButtonsBegin, g.SimpleSelect, g.Pan, g.Zoom, g.StateButtonsEnd, g.ZoomReset ]) buttons = self.zoom_select_toolbar.buttons buttons[g.Zoom].clicked.connect(self.graph.zoom_button_clicked) buttons[g.Pan].clicked.connect(self.graph.pan_button_clicked) buttons[g.SimpleSelect].clicked.connect( self.graph.select_button_clicked) buttons[g.ZoomReset].clicked.connect(self.graph.reset_button_clicked) self.controlArea.layout().addStretch(100) self.icons = gui.attributeIconDict p = self.graph.plot_widget.palette() self.graph.set_palette(p) gui.auto_commit(self.controlArea, self, "auto_send_selection", "Send Selection") self.inline_graph_report() def zoom(s): """Zoom in/out by factor `s`.""" viewbox = plot.getViewBox() # scaleBy scales the view's bounds (the axis range) viewbox.scaleBy((1 / s, 1 / s)) def fit_to_view(): viewbox = plot.getViewBox() viewbox.autoRange() zoom_in = QtGui.QAction("Zoom in", self, triggered=lambda: zoom(1.25)) zoom_in.setShortcuts([ QtGui.QKeySequence(QtGui.QKeySequence.ZoomIn), QtGui.QKeySequence(self.tr("Ctrl+=")) ]) zoom_out = QtGui.QAction("Zoom out", self, shortcut=QtGui.QKeySequence.ZoomOut, triggered=lambda: zoom(1 / 1.25)) zoom_fit = QtGui.QAction("Fit in view", self, shortcut=QtGui.QKeySequence(Qt.ControlModifier | Qt.Key_0), triggered=fit_to_view) self.addActions([zoom_in, zoom_out, zoom_fit])
def __init__(self): self.data = None self._is_running = False self._antecedentMatch = self._consequentMatch = lambda x: True self.proxy_model = self.ProxyModel(self) table = self.table = QTableView( self, showGrid=False, sortingEnabled=True, alternatingRowColors=True, selectionBehavior=QTableView.SelectRows, selectionMode=QTableView.ExtendedSelection, horizontalScrollMode=QTableView.ScrollPerPixel, verticalScrollMode=QTableView.ScrollPerPixel, editTriggers=QTableView.NoEditTriggers) table.verticalHeader().setVisible(False) table.verticalHeader().setDefaultSectionSize( table.verticalHeader().minimumSectionSize()) table.horizontalHeader().setStretchLastSection(True) table.setModel(QStandardItemModel(table)) table.selectionChanged = self.selectionChanged self.mainArea.layout().addWidget(table) box = gui.widgetBox(self.controlArea, "Info") self.nRules = self.nFilteredRules = self.nSelectedExamples = self.nSelectedRules = '' gui.label(box, self, "Number of rules: %(nRules)s") gui.label(box, self, "Filtered rules: %(nFilteredRules)s") gui.label(box, self, "Selected rules: %(nSelectedRules)s") gui.label(box, self, "Selected examples: %(nSelectedExamples)s") box = gui.widgetBox(self.controlArea, 'Find association rules') gui.valueSlider(box, self, 'minSupport', values=[.0001, .0005, .001, .005, .01, .05, .1, .5] + list(range(1, 101)), label='Minimal support:', labelFormat="%g%%", callback=lambda: self.find_rules()) gui.hSlider(box, self, 'minConfidence', minValue=1, maxValue=100, label='Minimal confidence:', labelFormat="%g%%", callback=lambda: self.find_rules()) gui.hSlider(box, self, 'maxRules', minValue=10000, maxValue=100000, step=10000, label='Max. number of rules:', callback=lambda: self.find_rules()) self.cb_classify = gui.checkBox( box, self, 'classify', label='Induce classification (itemset → class) rules') self.button = gui.auto_commit(box, self, 'autoFind', 'Find rules', commit=self.find_rules) vbox = gui.widgetBox(self.controlArea, 'Filter rules') ## This is disabled because it's hard to make a scatter plot with ## selectable spots. Options: ## * PyQtGraph, which doesn't support selection OOTB (+is poorly ## contrived and under-documented); ## * Orange.widgets.visualize.ScatterPlotGraph, which comes without ## any documentation or comprehensible examples of use whatsoever; ## * QGraphicsView, which would work, but lacks graphing features, ## namely labels, axes, ticks. ## ## I don't feel like pursuing any of those right now, so I am letting ## it to be figured out at a later date. #~ button = self.scatter_button = gui.button(vbox, self, 'Scatter plot', #~ callback=self.show_scatter, #~ autoDefault=False) #~ button.setDisabled(True) #~ self.scatter = self.ScatterPlotWindow(self) box = gui.widgetBox(vbox, 'Antecedent') gui.lineEdit(box, self, 'filterKeywordsAntecedent', 'Contains:', callback=self.filter_change, orientation='horizontal', tooltip='A comma or space-separated list of regular ' 'expressions.') hbox = gui.widgetBox(box, orientation='horizontal') gui.spin(hbox, self, 'filterAntecedentMin', 1, 998, label='Min. items:', callback=self.filter_change) gui.spin(hbox, self, 'filterAntecedentMax', 2, 999, label='Max. items:', callback=self.filter_change) gui.rubber(hbox) box = gui.widgetBox(vbox, 'Consequent') gui.lineEdit(box, self, 'filterKeywordsConsequent', 'Contains:', callback=self.filter_change, orientation='horizontal', tooltip='A comma or space-separated list of regular ' 'expressions.') hbox = gui.widgetBox(box, orientation='horizontal') gui.spin(hbox, self, 'filterConsequentMin', 1, 998, label='Min. items:', callback=self.filter_change) gui.spin(hbox, self, 'filterConsequentMax', 2, 999, label='Max. items:', callback=self.filter_change) gui.checkBox(box, self, 'filterSearch', label='Apply these filters in search', tooltip='If checked, the rules are filtered according ' 'to these filter conditions already in the search ' 'phase. \nIf unchecked, the only filters applied ' 'during search are the ones above, ' 'and the generated rules \nare filtered afterwards ' 'only for display, i.e. only the matching association ' 'rules are shown.') gui.rubber(hbox) gui.rubber(self.controlArea) gui.auto_commit(self.controlArea, self, 'autoSend', 'Send selection') self.filter_change()
def _create_layout(self): self._new_webview() box = gui.widgetBox(self.controlArea, 'Info') self.topic_info = gui.label(box, self, '%(n_topic_words)d words in a topic') gui.label(box, self, '%(documents_info_str)s') box = gui.widgetBox(self.controlArea, 'Cloud preferences') gui.checkBox(box, self, 'words_color', 'Color words', callback=self.on_cloud_pref_change) TILT_VALUES = ('no', '30°', '45°', '60°') gui.valueSlider(box, self, 'words_tilt', label='Words tilt:', values=list(range(len(TILT_VALUES))), callback=self.on_cloud_pref_change, labelFormat=lambda x: TILT_VALUES[x]) gui.button(box, None, 'Regenerate word cloud', callback=self.on_cloud_pref_change) box = gui.widgetBox(self.controlArea, 'Words && weights') class TableView(gui.TableView): def __init__(self, parent): super().__init__(parent) self._parent = parent self.__nope = False def setModel(self, model): """Otherwise QTableView.setModel() calls QAbstractItemView.setSelectionModel() which resets selection, calling selectionChanged() and overwriting any selected_words setting that may have been saved.""" self.__nope = True super().setModel(model) self.__nope = False def selectionChanged(self, selected, deselected): nonlocal model, proxymodel super().selectionChanged(selected, deselected) if not self.__nope: words = {model[proxymodel.mapToSource(index).row()][1] for index in self.selectionModel().selectedIndexes()} self._parent.update_selection(words, self) def update_selection(self, words): nonlocal model, proxymodel selection = QItemSelection() for i, (_, word) in enumerate(model): if word in words: index = proxymodel.mapFromSource(model.index(i, 1)) selection.select(index, index) self.__nope = True self.clearSelection() self.selectionModel().select( selection, QItemSelectionModel.Select | QItemSelectionModel.Rows) self.__nope = False view = self.tableview = TableView(self) model = self.tablemodel = PyTableModel(parent=self) proxymodel = QSortFilterProxyModel(self, dynamicSortFilter=True, sortCaseSensitivity=Qt.CaseInsensitive, sortRole=Qt.EditRole) proxymodel.setSourceModel(model) model.setHorizontalHeaderLabels(['Weight', 'Word']) view.setModel(proxymodel) box.layout().addWidget(view)
def __init__(self): super().__init__() box = gui.widgetBox(self.mainArea, True, margin=0) self.graph = OWScatterPlotGraph(self, box, "ScatterPlot") box.layout().addWidget(self.graph.plot_widget) self.data = None # Orange.data.Table self.subset_data = None # Orange.data.Table self.attribute_selection_list = None # list of Orange.data.Variable self.selection_dirty = False common_options = { "labelWidth": 50, "orientation": "horizontal", "sendSelectedValue": True, "valueType": str } box = gui.widgetBox(self.controlArea, "Axis Data") self.cb_attr_x = gui.comboBox(box, self, "attr_x", label="Axis x:", callback=self.major_graph_update, **common_options) self.cb_attr_y = gui.comboBox(box, self, "attr_y", label="Axis y:", callback=self.major_graph_update, **common_options) gui.valueSlider(box, self, value='graph.jitter_size', label='Jittering: ', values=self.jitter_sizes, callback=self.reset_graph_data, labelFormat=lambda x: "None" if x == 0 else ("%.1f %%" if x < 1 else "%d %%") % x) gui.checkBox(gui.indentedBox(box), self, 'graph.jitter_continuous', 'Jitter continuous values', callback=self.reset_graph_data) box = gui.widgetBox(self.controlArea, "Points") self.cb_attr_color = gui.comboBox(box, self, "graph.attr_color", label="Color:", emptyString="(Same color)", callback=self.graph.update_colors, **common_options) self.cb_attr_label = gui.comboBox(box, self, "graph.attr_label", label="Label:", emptyString="(No labels)", callback=self.graph.update_labels, **common_options) self.cb_attr_shape = gui.comboBox(box, self, "graph.attr_shape", label="Shape:", emptyString="(Same shape)", callback=self.graph.update_shapes, **common_options) self.cb_attr_size = gui.comboBox(box, self, "graph.attr_size", label="Size:", emptyString="(Same size)", callback=self.graph.update_sizes, **common_options) g = self.graph.gui box2 = g.point_properties_box(self.controlArea, box) gui.button(box2, self, "Set Colors", self.set_colors) box = gui.widgetBox(self.controlArea, "Plot Properties") g.add_widgets([g.ShowLegend, g.ShowGridLines], box) gui.checkBox(box, self, value='graph.tooltip_shows_all', label='Show all data on mouse hover') gui.separator(self.controlArea, 8, 8) self.zoom_select_toolbar = g.zoom_select_toolbar( self.controlArea, nomargin=True, buttons=[ g.StateButtonsBegin, g.SimpleSelect, g.Pan, g.Zoom, g.StateButtonsEnd, g.ZoomReset, g.Spacing, g.SendSelection ]) buttons = self.zoom_select_toolbar.buttons buttons[g.SendSelection].clicked.connect(self.send_selection) buttons[g.Zoom].clicked.connect(self.graph.zoom_button_clicked) buttons[g.Pan].clicked.connect(self.graph.pan_button_clicked) buttons[g.SimpleSelect].clicked.connect( self.graph.select_button_clicked) buttons[g.ZoomReset].clicked.connect(self.graph.reset_button_clicked) cb_auto_send = gui.checkBox(box, self, 'auto_send_selection', 'Send selection on change') gui.setStopper(self, buttons[g.SendSelection], cb_auto_send, "selection_dirty", self.send_selection) self.controlArea.layout().addStretch(100) self.icons = gui.attributeIconDict dlg = self.create_color_dialog() self.graph.continuous_palette = dlg.getContinuousPalette("contPalette") self.graph.discrete_palette = dlg.getDiscretePalette("discPalette") p = self.graph.plot_widget.palette() self.graph.set_palette(p) self.zoom_select_toolbar.buttons[OWPlotGUI.SendSelection].setEnabled( not self.auto_send_selection) self.mainArea.setMinimumWidth(700) self.mainArea.setMinimumHeight(550)
def jitter_size_slider(self, widget): values = getattr(self._plot.master, "jitter_sizes", self.JITTER_SIZES) gui.valueSlider( widget=widget, master=self._plot, value='jitter_size', label="Jittering: ", values=values, callback=self._plot.master.reset_graph_data, labelFormat=lambda x: "None" if x == 0 else ("%.1f %%" if x < 1 else "%d %%") % x)
def _create_layout(self): self._new_webview() box = gui.widgetBox(self.controlArea, 'Info') self.topic_info = gui.label(box, self, '%(n_topic_words)d words in a topic') gui.label(box, self, '%(documents_info_str)s') box = gui.widgetBox(self.controlArea, 'Cloud preferences') gui.checkBox(box, self, 'words_color', 'Color words', callback=self.on_cloud_pref_change) TILT_VALUES = ('no', '30°', '45°', '60°') gui.valueSlider(box, self, 'words_tilt', label='Words tilt:', values=list(range(len(TILT_VALUES))), callback=self.on_cloud_pref_change, labelFormat=lambda x: TILT_VALUES[x]) gui.button(box, None, 'Regenerate word cloud', callback=self.on_cloud_pref_change) box = gui.widgetBox(self.controlArea, 'Words && weights') class TableView(gui.TableView): def __init__(self, parent): super().__init__(parent) self._parent = parent self.__nope = False def setModel(self, model): """Otherwise QTableView.setModel() calls QAbstractItemView.setSelectionModel() which resets selection, calling selectionChanged() and overwriting any selected_words setting that may have been saved.""" self.__nope = True super().setModel(model) self.__nope = False def selectionChanged(self, selected, deselected): nonlocal model, proxymodel super().selectionChanged(selected, deselected) if not self.__nope: words = { model[proxymodel.mapToSource(index).row()][1] for index in self.selectionModel().selectedIndexes() } self._parent.update_selection(words, self) def update_selection(self, words): nonlocal model, proxymodel selection = QItemSelection() for i, (_, word) in enumerate(model): if word in words: index = proxymodel.mapFromSource(model.index(i, 1)) selection.select(index, index) self.__nope = True self.clearSelection() self.selectionModel().select( selection, QItemSelectionModel.Select | QItemSelectionModel.Rows) self.__nope = False view = self.tableview = TableView(self) model = self.tablemodel = PyTableModel(parent=self) proxymodel = QSortFilterProxyModel( self, dynamicSortFilter=True, sortCaseSensitivity=Qt.CaseInsensitive, sortRole=Qt.EditRole) proxymodel.setSourceModel(model) model.setHorizontalHeaderLabels(['Weight', 'Word']) view.setModel(proxymodel) box.layout().addWidget(view)
def __init__(self): super().__init__() box = gui.widgetBox(self.mainArea, True, margin=0) self.graph = OWScatterPlotGraph(self, box, "ScatterPlot") box.layout().addWidget(self.graph.plot_widget) self.data = None # Orange.data.Table self.subset_data = None # Orange.data.Table self.attribute_selection_list = None # list of Orange.data.Variable self.selection_dirty = False common_options = {"labelWidth": 50, "orientation": "horizontal", "sendSelectedValue": True, "valueType": str} box = gui.widgetBox(self.controlArea, "Axis Data") self.cb_attr_x = gui.comboBox(box, self, "attr_x", label="Axis x:", callback=self.major_graph_update, **common_options) self.cb_attr_y = gui.comboBox(box, self, "attr_y", label="Axis y:", callback=self.major_graph_update, **common_options) gui.valueSlider( box, self, value='graph.jitter_size', label='Jittering: ', values=self.jitter_sizes, callback=self.reset_graph_data, labelFormat=lambda x: "None" if x == 0 else ("%.1f %%" if x < 1 else "%d %%") % x) gui.checkBox( gui.indentedBox(box), self, 'graph.jitter_continuous', 'Jitter continuous values', callback=self.reset_graph_data) box = gui.widgetBox(self.controlArea, "Points") self.cb_attr_color = gui.comboBox( box, self, "graph.attr_color", label="Color:", emptyString="(Same color)", callback=self.graph.update_colors, **common_options) self.cb_attr_label = gui.comboBox( box, self, "graph.attr_label", label="Label:", emptyString="(No labels)", callback=self.graph.update_labels, **common_options) self.cb_attr_shape = gui.comboBox( box, self, "graph.attr_shape", label="Shape:", emptyString="(Same shape)", callback=self.graph.update_shapes, **common_options) self.cb_attr_size = gui.comboBox( box, self, "graph.attr_size", label="Size:", emptyString="(Same size)", callback=self.graph.update_sizes, **common_options) g = self.graph.gui box2 = g.point_properties_box(self.controlArea, box) gui.button(box2, self, "Set Colors", self.set_colors) box = gui.widgetBox(self.controlArea, "Plot Properties") g.add_widgets([g.ShowLegend, g.ShowGridLines], box) gui.checkBox(box, self, value='graph.tooltip_shows_all', label='Show all data on mouse hover') gui.separator(self.controlArea, 8, 8) self.zoom_select_toolbar = g.zoom_select_toolbar( self.controlArea, nomargin=True, buttons=[g.StateButtonsBegin, g.SimpleSelect, g.Pan, g.Zoom, g.StateButtonsEnd, g.ZoomReset, g.Spacing, g.SendSelection] ) buttons = self.zoom_select_toolbar.buttons buttons[g.SendSelection].clicked.connect(self.send_selection) buttons[g.Zoom].clicked.connect(self.graph.zoom_button_clicked) buttons[g.Pan].clicked.connect(self.graph.pan_button_clicked) buttons[g.SimpleSelect].clicked.connect(self.graph.select_button_clicked) buttons[g.ZoomReset].clicked.connect(self.graph.reset_button_clicked) cb_auto_send = gui.checkBox( box, self, 'auto_send_selection', 'Send selection on change') gui.setStopper(self, buttons[g.SendSelection], cb_auto_send, "selection_dirty", self.send_selection) self.controlArea.layout().addStretch(100) self.icons = gui.attributeIconDict dlg = self.create_color_dialog() self.graph.continuous_palette = dlg.getContinuousPalette("contPalette") self.graph.discrete_palette = dlg.getDiscretePalette("discPalette") p = self.graph.plot_widget.palette() self.graph.set_palette(p) self.zoom_select_toolbar.buttons[OWPlotGUI.SendSelection].setEnabled( not self.auto_send_selection) self.mainArea.setMinimumWidth(700) self.mainArea.setMinimumHeight(550)
def __init__(self): super().__init__() box = gui.vBox(self.mainArea, True, margin=0) self.graph = OWScatterPlotGraph(self, box, "ScatterPlot") box.layout().addWidget(self.graph.plot_widget) plot = self.graph.plot_widget axispen = QPen(self.palette().color(QPalette.Text)) axis = plot.getAxis("bottom") axis.setPen(axispen) axis = plot.getAxis("left") axis.setPen(axispen) self.data = None # Orange.data.Table self.subset_data = None # Orange.data.Table self.data_metas_X = None # self.data, where primitive metas are moved to X self.sql_data = None # Orange.data.sql.table.SqlTable self.attribute_selection_list = None # list of Orange.data.Variable self.__timer = QTimer(self, interval=1200) self.__timer.timeout.connect(self.add_data) common_options = dict( labelWidth=50, orientation=Qt.Horizontal, sendSelectedValue=True, valueType=str) box = gui.vBox(self.controlArea, "Axis Data") dmod = DomainModel self.xy_model = DomainModel(dmod.MIXED, valid_types=dmod.PRIMITIVE) self.cb_attr_x = gui.comboBox( box, self, "attr_x", label="Axis x:", callback=self.update_attr, model=self.xy_model, **common_options) self.cb_attr_y = gui.comboBox( box, self, "attr_y", label="Axis y:", callback=self.update_attr, model=self.xy_model, **common_options) vizrank_box = gui.hBox(box) gui.separator(vizrank_box, width=common_options["labelWidth"]) self.vizrank, self.vizrank_button = ScatterPlotVizRank.add_vizrank( vizrank_box, self, "Find Informative Projections", self.set_attr) gui.separator(box) gui.valueSlider( box, self, value='graph.jitter_size', label='Jittering: ', values=self.jitter_sizes, callback=self.reset_graph_data, labelFormat=lambda x: "None" if x == 0 else ("%.1f %%" if x < 1 else "%d %%") % x) gui.checkBox( gui.indentedBox(box), self, 'graph.jitter_continuous', 'Jitter numeric values', callback=self.reset_graph_data) self.sampling = gui.auto_commit( self.controlArea, self, "auto_sample", "Sample", box="Sampling", callback=self.switch_sampling, commit=lambda: self.add_data(1)) self.sampling.setVisible(False) g = self.graph.gui g.point_properties_box(self.controlArea) self.models = [self.xy_model] + g.points_models box = gui.vBox(self.controlArea, "Plot Properties") g.add_widgets([g.ShowLegend, g.ShowGridLines], box) gui.checkBox( box, self, value='graph.tooltip_shows_all', label='Show all data on mouse hover') self.cb_class_density = gui.checkBox( box, self, value='graph.class_density', label='Show class density', callback=self.update_density) self.cb_reg_line = gui.checkBox( box, self, value='graph.show_reg_line', label='Show regression line', callback=self.update_regression_line) gui.checkBox( box, self, 'graph.label_only_selected', 'Label only selected points', callback=self.graph.update_labels) self.zoom_select_toolbar = g.zoom_select_toolbar( gui.vBox(self.controlArea, "Zoom/Select"), nomargin=True, buttons=[g.StateButtonsBegin, g.SimpleSelect, g.Pan, g.Zoom, g.StateButtonsEnd, g.ZoomReset] ) buttons = self.zoom_select_toolbar.buttons buttons[g.Zoom].clicked.connect(self.graph.zoom_button_clicked) buttons[g.Pan].clicked.connect(self.graph.pan_button_clicked) buttons[g.SimpleSelect].clicked.connect(self.graph.select_button_clicked) buttons[g.ZoomReset].clicked.connect(self.graph.reset_button_clicked) self.controlArea.layout().addStretch(100) self.icons = gui.attributeIconDict p = self.graph.plot_widget.palette() self.graph.set_palette(p) gui.auto_commit(self.controlArea, self, "auto_send_selection", "Send Selection", "Send Automatically") def zoom(s): """Zoom in/out by factor `s`.""" viewbox = plot.getViewBox() # scaleBy scales the view's bounds (the axis range) viewbox.scaleBy((1 / s, 1 / s)) def fit_to_view(): viewbox = plot.getViewBox() viewbox.autoRange() zoom_in = QAction( "Zoom in", self, triggered=lambda: zoom(1.25) ) zoom_in.setShortcuts([QKeySequence(QKeySequence.ZoomIn), QKeySequence(self.tr("Ctrl+="))]) zoom_out = QAction( "Zoom out", self, shortcut=QKeySequence.ZoomOut, triggered=lambda: zoom(1 / 1.25) ) zoom_fit = QAction( "Fit in view", self, shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_0), triggered=fit_to_view ) self.addActions([zoom_in, zoom_out, zoom_fit])
def __init__(self): self._is_running = False self.isRegexMatch = lambda x: True self.tree = QTreeWidget(self.mainArea, columnCount=2, allColumnsShowFocus=True, alternatingRowColors=True, selectionMode=QTreeWidget.ExtendedSelection, uniformRowHeights=True) self.tree.setHeaderLabels(["Itemsets", "Support", "%"]) self.tree.header().setStretchLastSection(True) self.tree.itemSelectionChanged.connect(self.selectionChanged) self.mainArea.layout().addWidget(self.tree) box = gui.widgetBox(self.controlArea, "Info") self.nItemsets = self.nSelectedExamples = self.nSelectedItemsets = '' gui.label(box, self, "Number of itemsets: %(nItemsets)s") gui.label(box, self, "Selected itemsets: %(nSelectedItemsets)s") gui.label(box, self, "Selected examples: %(nSelectedExamples)s") hbox = gui.widgetBox(box, orientation='horizontal') gui.button(hbox, self, "Expand all", callback=self.tree.expandAll) gui.button(hbox, self, "Collapse all", callback=self.tree.collapseAll) box = gui.widgetBox(self.controlArea, 'Find itemsets') gui.valueSlider(box, self, 'minSupport', values=[.0001, .0005, .001, .005, .01, .05, .1, .5] + list(range(1, 101)), label='Minimal support:', labelFormat="%g%%", callback=lambda: self.find_itemsets()) gui.hSlider(box, self, 'maxItemsets', minValue=10000, maxValue=100000, step=10000, label='Max. number of itemsets:', labelFormat="%d", callback=lambda: self.find_itemsets()) self.button = gui.auto_commit(box, self, 'autoFind', 'Find itemsets', commit=self.find_itemsets) box = gui.widgetBox(self.controlArea, 'Filter itemsets') gui.lineEdit(box, self, 'filterKeywords', 'Contains:', callback=self.filter_change, orientation='horizontal', tooltip='A comma or space-separated list of regular ' 'expressions.') hbox = gui.widgetBox(box, orientation='horizontal') gui.spin(hbox, self, 'filterMinItems', 1, 998, label='Min. items:', callback=self.filter_change) gui.spin(hbox, self, 'filterMaxItems', 2, 999, label='Max. items:', callback=self.filter_change) gui.checkBox(box, self, 'filterSearch', label='Apply these filters in search', tooltip='If checked, the itemsets are filtered according ' 'to these filter conditions already in the search ' 'phase. \nIf unchecked, the only filters applied ' 'during search are the ones above, ' 'and the itemsets are \nfiltered afterwards only for ' 'display, i.e. only the matching itemsets are shown.') gui.rubber(hbox) gui.rubber(self.controlArea) gui.auto_commit(self.controlArea, self, 'autoSend', 'Send selection') self.filter_change()
def __init__(self): self.data = None self._is_running = False self._antecedentMatch = self._consequentMatch = lambda x: True self.proxy_model = self.ProxyModel(self) table = self.table = QTableView( self, showGrid=False, sortingEnabled=True, alternatingRowColors=True, selectionBehavior=QTableView.SelectRows, selectionMode=QTableView.ExtendedSelection, horizontalScrollMode=QTableView.ScrollPerPixel, verticalScrollMode=QTableView.ScrollPerPixel, editTriggers=QTableView.NoEditTriggers) table.verticalHeader().setVisible(False) table.verticalHeader().setDefaultSectionSize(table.verticalHeader().minimumSectionSize()) table.horizontalHeader().setStretchLastSection(True) table.setModel(QStandardItemModel(table)) table.selectionChanged = self.selectionChanged self.mainArea.layout().addWidget(table) box = gui.widgetBox(self.controlArea, "Info") self.nRules = self.nFilteredRules = self.nSelectedExamples = self.nSelectedRules = '' gui.label(box, self, "Number of rules: %(nRules)s") gui.label(box, self, "Filtered rules: %(nFilteredRules)s") gui.label(box, self, "Selected rules: %(nSelectedRules)s") gui.label(box, self, "Selected examples: %(nSelectedExamples)s") box = gui.widgetBox(self.controlArea, 'Find association rules') gui.valueSlider(box, self, 'minSupport', values=[.0001, .0005, .001, .005, .01, .05, .1, .5] + list(range(1, 101)), label='Minimal support:', labelFormat="%g%%", callback=lambda: self.find_rules()) gui.hSlider(box, self, 'minConfidence', minValue=1, maxValue=100, label='Minimal confidence:', labelFormat="%g%%", callback=lambda: self.find_rules()) gui.hSlider(box, self, 'maxRules', minValue=10000, maxValue=100000, step=10000, label='Max. number of rules:', callback=lambda: self.find_rules()) self.cb_classify = gui.checkBox( box, self, 'classify', label='Induce classification (itemset → class) rules') self.button = gui.auto_commit( box, self, 'autoFind', 'Find rules', commit=self.find_rules) vbox = gui.widgetBox(self.controlArea, 'Filter rules') ## This is disabled because it's hard to make a scatter plot with ## selectable spots. Options: ## * PyQtGraph, which doesn't support selection OOTB (+is poorly ## contrived and under-documented); ## * Orange.widgets.visualize.ScatterPlotGraph, which comes without ## any documentation or comprehensible examples of use whatsoever; ## * QGraphicsView, which would work, but lacks graphing features, ## namely labels, axes, ticks. ## ## I don't feel like pursuing any of those right now, so I am letting ## it to be figured out at a later date. #~ button = self.scatter_button = gui.button(vbox, self, 'Scatter plot', #~ callback=self.show_scatter, #~ autoDefault=False) #~ button.setDisabled(True) #~ self.scatter = self.ScatterPlotWindow(self) box = gui.widgetBox(vbox, 'Antecedent') gui.lineEdit(box, self, 'filterKeywordsAntecedent', 'Contains:', callback=self.filter_change, orientation='horizontal', tooltip='A comma or space-separated list of regular ' 'expressions.') hbox = gui.widgetBox(box, orientation='horizontal') gui.spin(hbox, self, 'filterAntecedentMin', 1, 998, label='Min. items:', callback=self.filter_change) gui.spin(hbox, self, 'filterAntecedentMax', 2, 999, label='Max. items:', callback=self.filter_change) gui.rubber(hbox) box = gui.widgetBox(vbox, 'Consequent') gui.lineEdit(box, self, 'filterKeywordsConsequent', 'Contains:', callback=self.filter_change, orientation='horizontal', tooltip='A comma or space-separated list of regular ' 'expressions.') hbox = gui.widgetBox(box, orientation='horizontal') gui.spin(hbox, self, 'filterConsequentMin', 1, 998, label='Min. items:', callback=self.filter_change) gui.spin(hbox, self, 'filterConsequentMax', 2, 999, label='Max. items:', callback=self.filter_change) gui.checkBox(box, self, 'filterSearch', label='Apply these filters in search', tooltip='If checked, the rules are filtered according ' 'to these filter conditions already in the search ' 'phase. \nIf unchecked, the only filters applied ' 'during search are the ones above, ' 'and the generated rules \nare filtered afterwards ' 'only for display, i.e. only the matching association ' 'rules are shown.') gui.rubber(hbox) gui.rubber(self.controlArea) gui.auto_commit(self.controlArea, self, 'autoSend', 'Send selection') self.filter_change()
def __init__(self): self.data = None self.output = None self.onehot_mapping = {} self._is_running = False self._antecedentMatch = self._consequentMatch = lambda x: True self.proxy_model = self.ProxyModel(self) owwidget = self class TableView(QTableView): def selectionChanged(self, selected, deselected): nonlocal owwidget super().selectionChanged(selected, deselected) mapping = owwidget.onehot_mapping if not mapping: return where = np.where X, Y = owwidget.X, owwidget.data.Y instances = set() selected_rows = self.selectionModel().selectedRows(0) for model_index in selected_rows: itemset, class_item = model_index.data( owwidget.ROW_DATA_ROLE) cols, vals = zip(*(mapping[i] for i in itemset)) if issparse(X): matching = (len(cols) == np.bincount( (X[:, cols] != 0).indices, minlength=X.shape[0])).nonzero()[0] else: matching = set( where((X[:, cols] == vals).all(axis=1))[0]) if class_item: matching &= set(where(Y == mapping[class_item][1])[0]) instances.update(matching) owwidget.nSelectedExamples = len(instances) owwidget.nSelectedRules = len(selected_rows) owwidget.output = owwidget.data[sorted(instances)] or None owwidget.commit() table = self.table = TableView( self, showGrid=False, sortingEnabled=True, alternatingRowColors=True, selectionBehavior=QTableView.SelectRows, selectionMode=QTableView.ExtendedSelection, horizontalScrollMode=QTableView.ScrollPerPixel, verticalScrollMode=QTableView.ScrollPerPixel, editTriggers=QTableView.NoEditTriggers) table.verticalHeader().setVisible(False) table.verticalHeader().setDefaultSectionSize( table.verticalHeader().minimumSectionSize()) table.horizontalHeader().setStretchLastSection(True) table.setModel(QStandardItemModel(table)) self.mainArea.layout().addWidget(table) box = gui.widgetBox(self.controlArea, "Info") self.nRules = self.nFilteredRules = self.nSelectedExamples = self.nSelectedRules = '' gui.label(box, self, "Number of rules: %(nRules)s") gui.label(box, self, "Filtered rules: %(nFilteredRules)s") gui.label(box, self, "Selected rules: %(nSelectedRules)s") gui.label(box, self, "Selected examples: %(nSelectedExamples)s") box = gui.widgetBox(self.controlArea, 'Find association rules') gui.valueSlider(box, self, 'minSupport', values=[.0001, .0005, .001, .005, .01, .05, .1, .5] + list(range(1, 101)), label='Minimal support:', labelFormat="%g%%", callback=lambda: self.find_rules()) gui.hSlider(box, self, 'minConfidence', minValue=1, maxValue=100, label='Minimal confidence:', labelFormat="%g%%", callback=lambda: self.find_rules()) gui.hSlider(box, self, 'maxRules', minValue=10000, maxValue=100000, step=10000, label='Max. number of rules:', callback=lambda: self.find_rules()) self.cb_classify = gui.checkBox( box, self, 'classify', label='Induce classification (itemset → class) rules') self.button = gui.auto_commit( box, self, 'autoFind', 'Find Rules', commit=self.find_rules, callback=lambda: self.autoFind and self.find_rules()) vbox = gui.widgetBox(self.controlArea, 'Filter rules') box = gui.widgetBox(vbox, 'Antecedent') gui.lineEdit(box, self, 'filterKeywordsAntecedent', 'Contains:', callback=self.filter_change, orientation='horizontal', tooltip='A comma or space-separated list of regular ' 'expressions.') hbox = gui.widgetBox(box, orientation='horizontal') gui.spin(hbox, self, 'filterAntecedentMin', 1, 998, label='Min. items:', callback=self.filter_change) gui.spin(hbox, self, 'filterAntecedentMax', 2, 999, label='Max. items:', callback=self.filter_change) gui.rubber(hbox) box = gui.widgetBox(vbox, 'Consequent') gui.lineEdit(box, self, 'filterKeywordsConsequent', 'Contains:', callback=self.filter_change, orientation='horizontal', tooltip='A comma or space-separated list of regular ' 'expressions.') hbox = gui.widgetBox(box, orientation='horizontal') gui.spin(hbox, self, 'filterConsequentMin', 1, 998, label='Min. items:', callback=self.filter_change) gui.spin(hbox, self, 'filterConsequentMax', 2, 999, label='Max. items:', callback=self.filter_change) gui.checkBox(box, self, 'filterSearch', label='Apply these filters in search', tooltip='If checked, the rules are filtered according ' 'to these filter conditions already in the search ' 'phase. \nIf unchecked, the only filters applied ' 'during search are the ones above, ' 'and the generated rules \nare filtered afterwards ' 'only for display, i.e. only the matching association ' 'rules are shown.') gui.rubber(hbox) gui.rubber(self.controlArea) gui.auto_commit(self.controlArea, self, 'autoSend', 'Send selection') self.filter_change()