def __init__(self): super().__init__() #: widget's runtime state self.__state = State.NoState self.base_corpus = None self.corpus = None self.n_text_categories = 0 self.n_text_data = 0 self.skipped_documents = [] self.is_conllu = False self.tokens = None self.pos = None self.ner = None self.__invalidated = False self.__pendingTask = None layout = QGridLayout() layout.setSpacing(4) gui.widgetBox(self.controlArea, orientation=layout, box='Source') source_box = gui.radioButtons(None, self, "source", box=True, callback=self.start, addToLayout=False) rb_button = gui.appendRadioButton(source_box, "Folder:", addToLayout=False) layout.addWidget(rb_button, 0, 0, Qt.AlignVCenter) box = gui.hBox(None, addToLayout=False, margin=0) box.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.recent_cb = QComboBox( sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, minimumContentsLength=16, acceptDrops=True) self.recent_cb.installEventFilter(self) self.recent_cb.activated[int].connect(self.__onRecentActivated) browseaction = QAction( "Open/Load Documents", self, iconText="\N{HORIZONTAL ELLIPSIS}", icon=self.style().standardIcon(QStyle.SP_DirOpenIcon), toolTip="Select a folder from which to load the documents") browseaction.triggered.connect(self.__runOpenDialog) reloadaction = QAction("Reload", self, icon=self.style().standardIcon( QStyle.SP_BrowserReload), toolTip="Reload current document set") reloadaction.triggered.connect(self.reload) self.__actions = namespace( browse=browseaction, reload=reloadaction, ) browsebutton = QPushButton( browseaction.iconText(), icon=browseaction.icon(), toolTip=browseaction.toolTip(), clicked=browseaction.trigger, default=False, autoDefault=False, ) reloadbutton = QPushButton( reloadaction.iconText(), icon=reloadaction.icon(), clicked=reloadaction.trigger, default=False, autoDefault=False, ) box.layout().addWidget(self.recent_cb) layout.addWidget(box, 0, 1) layout.addWidget(browsebutton, 0, 2) layout.addWidget(reloadbutton, 0, 3) rb_button = gui.appendRadioButton(source_box, "URL:", addToLayout=False) layout.addWidget(rb_button, 3, 0, Qt.AlignVCenter) self.url_combo = url_combo = QComboBox() url_model = PyListModel() url_model.wrap(self.recent_urls) url_combo.setLineEdit(LineEditSelectOnFocus()) url_combo.setModel(url_model) url_combo.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed) url_combo.setEditable(True) url_combo.setInsertPolicy(url_combo.InsertAtTop) url_edit = url_combo.lineEdit() m = url_edit.textMargins() url_edit.setTextMargins(m.left() + 5, m.top(), m.right(), m.bottom()) layout.addWidget(url_combo, 3, 1, 1, 3) url_combo.activated.connect(self._url_set) # whit completer we set that combo box is case sensitive when # matching the history completer = QCompleter() completer.setCaseSensitivity(Qt.CaseSensitive) url_combo.setCompleter(completer) self.addActions([browseaction, reloadaction]) reloadaction.changed.connect( lambda: reloadbutton.setEnabled(reloadaction.isEnabled())) box = gui.hBox(self.controlArea, "Conllu import options") gui.checkBox(box, self, "lemma_cb", "Lemma", callback=self.commit) gui.checkBox(box, self, "pos_cb", "POS tags", callback=self.commit) gui.checkBox(box, self, "ner_cb", "NER", callback=self.commit) self.controlArea.layout().addWidget(box) box = gui.vBox(self.controlArea, "Info") self.infostack = QStackedWidget() self.info_area = QLabel(text="No document set selected", wordWrap=True) self.progress_widget = QProgressBar(minimum=0, maximum=100) self.cancel_button = QPushButton( "Cancel", icon=self.style().standardIcon(QStyle.SP_DialogCancelButton), default=False, autoDefault=False, ) self.cancel_button.clicked.connect(self.cancel) w = QWidget() vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.addWidget(self.progress_widget) hlayout.addWidget(self.cancel_button) vlayout.addLayout(hlayout) self.pathlabel = TextLabel() self.pathlabel.setTextElideMode(Qt.ElideMiddle) self.pathlabel.setAttribute(Qt.WA_MacSmallSize) vlayout.addWidget(self.pathlabel) w.setLayout(vlayout) self.infostack.addWidget(self.info_area) self.infostack.addWidget(w) box.layout().addWidget(self.infostack) self.__initRecentItemsModel() self.__invalidated = True self.__executor = ThreadExecutor(self) QApplication.postEvent(self, QEvent(RuntimeEvent.Init))
def __init__(self): super().__init__() self.controlArea = QWidget(self.controlArea) self.layout().addWidget(self.controlArea) layout = QGridLayout() self.controlArea.setLayout(layout) layout.setContentsMargins(4, 4, 4, 4) self.methods = [method for method in METHODS if method[-1] is not None] self.tab_index = 0 self.mutex = QMutex() self.graph = None self.items = None # items set by Items signal self.items_graph = None # items set by graph.items by Network signal self.items_analysis = None # items to output and merge with analysis result self.job_queue = [] self.job_working = [] self.analfeatures = [] self.analdata = {} for method in self.methods: setattr(self, method[0], method[0] in self.enabled_methods) setattr(self, "lbl_" + method[0], "") self.tabs = gui.tabWidget(self.controlArea) self.tabs.setMinimumWidth(450) self.graphIndices = gui.createTabPage(self.tabs, "Graph-level indices") self.nodeIndices = gui.createTabPage(self.tabs, "Node-level indices") self.tabs.setCurrentIndex(self.tab_index) self.tabs.currentChanged.connect( lambda index: setattr(self, 'tab_index', index)) a = {NODELEVEL: self.nodeIndices, GRAPHLEVEL: self.graphIndices} for name, _, label, type, algorithm in self.methods: box = gui.widgetBox(a[type], orientation="horizontal") gui.checkBox(box, self, name, label=label, callback=lambda n=name: self.method_clicked(n)) box.layout().addStretch(1) lbl = gui.label(box, self, "%(lbl_" + name + ")s") setattr(self, "tool_" + name, lbl) self.graphIndices.layout().addStretch(1) self.nodeIndices.layout().addStretch(1) autobox = gui.auto_commit(None, self, "auto_commit", "Commit", commit=self.analyze) layout.addWidget(autobox, 3, 0, 1, 1) cancel = gui.button(None, self, "Cancel", callback=lambda: self.stop_job(current=False)) autobox.layout().insertWidget(3, cancel) autobox.layout().insertSpacing(2, 10) cancel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
def __init__(self): super().__init__() self.scorers = OrderedDict() self.out_domain_desc = None self.data = None self.problem_type_mode = ProblemType.CLASSIFICATION if not self.selected_methods: self.selected_methods = { method.name for method in SCORES if method.is_default } # GUI self.ranksModel = model = TableModel(parent=self) # type: TableModel self.ranksView = view = TableView(self) # type: TableView self.mainArea.layout().addWidget(view) view.setModel(model) view.setColumnWidth(0, 30) view.selectionModel().selectionChanged.connect(self.on_select) def _set_select_manual(): self.setSelectionMethod(OWRank.SelectManual) view.pressed.connect(_set_select_manual) view.verticalHeader().sectionClicked.connect(_set_select_manual) view.horizontalHeader().sectionClicked.connect(self.headerClick) self.measuresStack = stacked = QStackedWidget(self) self.controlArea.layout().addWidget(stacked) for scoring_methods in (CLS_SCORES, REG_SCORES, []): box = gui.vBox(None, "Scoring Methods" if scoring_methods else None) stacked.addWidget(box) for method in scoring_methods: box.layout().addWidget( QCheckBox( method.name, self, objectName=method. shortname, # To be easily found in tests checked=method.name in self.selected_methods, stateChanged=partial(self.methodSelectionChanged, method_name=method.name))) gui.rubber(box) gui.rubber(self.controlArea) self.switchProblemType(ProblemType.CLASSIFICATION) selMethBox = gui.vBox(self.controlArea, "Select Attributes", addSpace=True) grid = QGridLayout() grid.setContentsMargins(6, 0, 6, 0) self.selectButtons = QButtonGroup() self.selectButtons.buttonClicked[int].connect(self.setSelectionMethod) def button(text, buttonid, toolTip=None): b = QRadioButton(text) self.selectButtons.addButton(b, buttonid) if toolTip is not None: b.setToolTip(toolTip) return b b1 = button(self.tr("None"), OWRank.SelectNone) b2 = button(self.tr("All"), OWRank.SelectAll) b3 = button(self.tr("Manual"), OWRank.SelectManual) b4 = button(self.tr("Best ranked:"), OWRank.SelectNBest) s = gui.spin( selMethBox, self, "nSelected", 1, 999, callback=lambda: self.setSelectionMethod(OWRank.SelectNBest)) grid.addWidget(b1, 0, 0) grid.addWidget(b2, 1, 0) grid.addWidget(b3, 2, 0) grid.addWidget(b4, 3, 0) grid.addWidget(s, 3, 1) self.selectButtons.button(self.selectionMethod).setChecked(True) selMethBox.layout().addLayout(grid) gui.auto_send(selMethBox, self, "auto_apply", box=False) self.info.set_input_summary(self.info.NoInput) self.info.set_output_summary(self.info.NoOutput) self.resize(690, 500)
def __init__(self): super().__init__() self.data = None # The following lists are of the same length as self.active_rules #: list of pairs with counts of matches for each patter when the # patterns are applied in order and when applied on the entire set, # disregarding the preceding patterns self.match_counts = [] #: list of list of QLineEdit: line edit pairs for each pattern self.line_edits = [] #: list of QPushButton: list of remove buttons self.remove_buttons = [] #: list of list of QLabel: pairs of labels with counts self.counts = [] combo = gui.comboBox(self.controlArea, self, "attribute", label="From column: ", box=True, orientation=Qt.Horizontal, callback=self.update_rules, model=DomainModel(valid_types=(StringVariable, DiscreteVariable))) # Don't use setSizePolicy keyword argument here: it applies to box, # not the combo combo.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) patternbox = gui.vBox(self.controlArea, box=True) #: QWidget: the box that contains the remove buttons, line edits and # count labels. The lines are added and removed dynamically. self.rules_box = rules_box = QGridLayout() patternbox.layout().addLayout(self.rules_box) box = gui.hBox(patternbox) gui.button(box, self, "+", callback=self.add_row, autoDefault=False, flat=True, minimumSize=(QSize(20, 20))) gui.rubber(box) self.rules_box.setColumnMinimumWidth(1, 70) self.rules_box.setColumnMinimumWidth(0, 10) self.rules_box.setColumnStretch(0, 1) self.rules_box.setColumnStretch(1, 1) self.rules_box.setColumnStretch(2, 100) rules_box.addWidget(QLabel("Name"), 0, 1) rules_box.addWidget(QLabel("Substring"), 0, 2) rules_box.addWidget(QLabel("#Instances"), 0, 3, 1, 2) self.update_rules() gui.lineEdit(self.controlArea, self, "class_name", label="Name for the new class:", box=True, orientation=Qt.Horizontal) optionsbox = gui.vBox(self.controlArea, box=True) gui.checkBox(optionsbox, self, "match_beginning", "Match only at the beginning", callback=self.options_changed) gui.checkBox(optionsbox, self, "case_sensitive", "Case sensitive", callback=self.options_changed) box = gui.hBox(self.controlArea) gui.rubber(box) gui.button(box, self, "Apply", autoDefault=False, width=180, callback=self.apply) # TODO: Resizing upon changing the number of rules does not work self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.api = None self.corpus = None self.api_dlg = self.APICredentialsDialog(self) self.api_dlg.accept(silent=True) # Set API key button gui.button(self.controlArea, self, 'Twitter API Key', callback=self.open_key_dialog, tooltip='Set the API key for this widget.', focusPolicy=Qt.NoFocus) # Query query_box = gui.hBox(self.controlArea, 'Query') layout = QGridLayout() layout.setVerticalSpacing(5) layout.setColumnStretch(2, 1) # stretch last columns layout.setColumnMinimumWidth(1, 15) # add some space for checkbox ROW = 0 COLUMNS = 3 def add_row(label, items): nonlocal ROW, COLUMNS layout.addWidget(QLabel(label), ROW, 0) if isinstance(items, tuple): for i, item in enumerate(items): layout.addWidget(item, ROW, 1 + i) else: layout.addWidget(items, ROW, 1, 1, COLUMNS - 1) ROW += 1 # Query input add_row( 'Query word list:', ListEdit(self, 'word_list', 'Multiple lines are joined with OR.', 80, self)) # Search mode add_row( 'Search by:', gui.comboBox(self, self, 'mode', items=self.MODES, callback=self.mode_toggle)) # Language self.language_combo = ComboBox(self, 'language', items=(('Any', None), ) + tuple(sorted(lang2code.items()))) add_row('Language:', self.language_combo) # Max tweets add_row( 'Max tweets:', gui.spin(self, self, 'max_tweets', minv=1, maxv=10000, checked='limited_search')) # Retweets self.retweets_checkbox = gui.checkBox(self, self, 'allow_retweets', '', minimumHeight=30) add_row('Allow retweets:', self.retweets_checkbox) # Collect Results add_row('Collect results:', gui.checkBox(self, self, 'collecting', '')) query_box.layout().addLayout(layout) self.controlArea.layout().addWidget( CheckListLayout('Text includes', self, 'text_includes', self.attributes, cols=2, callback=self.set_text_features)) self.tweets_info_label = gui.label(self.controlArea, self, self.tweets_info.format(0), box='Info') # Buttons self.button_box = gui.hBox(self.controlArea) self.button_box.layout().addWidget(self.report_button) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop, focusPolicy=Qt.NoFocus) self.mode_toggle() self.setFocus() # to widget itself to show placeholder for query_edit
def __init__(self): OWWidget.__init__(self) ConcurrentWidgetMixin.__init__(self) self.available_scales = sorted( MODELS.values(), key=lambda x: x["order"]) # create grid grid = QGridLayout() gui.widgetBox(self.controlArea, orientation=grid) # image attribute selection hbox_attr = gui.hBox(None) self.cb_image_attr = gui.comboBox( widget=hbox_attr, master=self, value='image_attr_current_index', label='Image attribute', orientation=Qt.Horizontal, callback=self.setting_changed ) grid.addWidget(hbox_attr, 1, 0, 1, 2) # Scale images option hbox_scale = gui.hBox(None) gui.checkBox( widget=hbox_scale, master=self, value="use_scale", label="Scale images to ", callback=self.setting_changed ) self.scale_combo = gui.comboBox( widget=hbox_scale, master=self, value="scale_index", items=["{} ({}×{})".format(v["name"], *v["target_image_size"]) for v in self.available_scales], callback=self.setting_changed ) grid.addWidget(hbox_scale, 3, 0, 1, 2) # file format hbox_format = gui.hBox(None) gui.comboBox( widget=hbox_format, master=self, value="file_format_index", label="File format", items=[x.upper() for x in SUPPORTED_FILE_FORMATS], orientation=Qt.Horizontal, callback=self.setting_changed ) grid.addWidget(hbox_format, 4, 0, 1, 2) # auto save grid.addWidget( gui.checkBox( widget=None, master=self, value="auto_save", label="Autosave when receiving new data or settings change", callback=self._update_messages), 5, 0, 1, 2) # buttons self.bt_save = gui.button(None, self, "Save", callback=self.save_file) grid.addWidget(self.bt_save, 7, 0) grid.addWidget( gui.button(None, self, "Save as ...", callback=self.save_file_as), 7, 1) grid.setRowMinimumHeight(5, 8) grid.setRowMinimumHeight(6, 20) self.scale_combo.setEnabled(self.use_scale) self.adjustSize() self._update_messages()
def __init__(self, parent): QWidget.__init__(self) OWComponent.__init__(self, parent) SelectionGroupMixin.__init__(self) ImageColorSettingMixin.__init__(self) ImageZoomMixin.__init__(self) ConcurrentMixin.__init__(self) self.parent = parent self.selection_type = SELECTMANY self.saving_enabled = True self.selection_enabled = True self.viewtype = INDIVIDUAL # required bt InteractiveViewBox self.highlighted = None self.data_points = None self.data_values = None self.data_imagepixels = None self.data_valid_positions = None self.plotview = pg.GraphicsLayoutWidget() self.plot = pg.PlotItem(background="w", viewBox=InteractiveViewBox(self)) self.plotview.addItem(self.plot) self.legend = ImageColorLegend() self.plotview.addItem(self.legend) self.plot.scene().installEventFilter( HelpEventDelegate(self.help_event, self)) layout = QVBoxLayout() self.setLayout(layout) self.layout().setContentsMargins(0, 0, 0, 0) self.layout().addWidget(self.plotview) self.img = ImageItemNan() self.img.setOpts(axisOrder='row-major') self.plot.addItem(self.img) self.vis_img = pg.ImageItem() self.vis_img.setOpts(axisOrder='row-major') self.plot.vb.setAspectLocked() self.plot.scene().sigMouseMoved.connect(self.plot.vb.mouseMovedEvent) layout = QGridLayout() self.plotview.setLayout(layout) self.button = QPushButton("Menu", self.plotview) self.button.setAutoDefault(False) layout.setRowStretch(1, 1) layout.setColumnStretch(1, 1) layout.addWidget(self.button, 0, 0) view_menu = MenuFocus(self) self.button.setMenu(view_menu) # prepare interface according to the new context self.parent.contextAboutToBeOpened.connect( lambda x: self.init_interface_data(x[0])) actions = [] self.add_zoom_actions(view_menu) select_square = QAction( "Select (square)", self, triggered=self.plot.vb.set_mode_select_square, ) select_square.setShortcuts([Qt.Key_S]) select_square.setShortcutContext(Qt.WidgetWithChildrenShortcut) actions.append(select_square) select_polygon = QAction( "Select (polygon)", self, triggered=self.plot.vb.set_mode_select_polygon, ) select_polygon.setShortcuts([Qt.Key_P]) select_polygon.setShortcutContext(Qt.WidgetWithChildrenShortcut) actions.append(select_polygon) if self.saving_enabled: save_graph = QAction( "Save graph", self, triggered=self.save_graph, ) save_graph.setShortcuts( [QKeySequence(Qt.ControlModifier | Qt.Key_I)]) actions.append(save_graph) view_menu.addActions(actions) self.addActions(actions) common_options = dict(labelWidth=50, orientation=Qt.Horizontal, sendSelectedValue=True) choose_xy = QWidgetAction(self) box = gui.vBox(self) box.setFocusPolicy(Qt.TabFocus) self.xy_model = DomainModel(DomainModel.METAS | DomainModel.CLASSES, valid_types=DomainModel.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) box.setFocusProxy(self.cb_attr_x) box.layout().addWidget(self.color_settings_box()) choose_xy.setDefaultWidget(box) view_menu.addAction(choose_xy) self.lsx = None # info about the X axis self.lsy = None # info about the Y axis self.data = None self.data_ids = {}
def __init__(self): super().__init__() self.corpus = None self.pp_corpus = None self.pos_file = None self.neg_file = None self.senti_dict = None self.form = QGridLayout() self.method_box = box = gui.radioButtonsInBox( self.controlArea, self, "method_idx", [], box="Method", orientation=self.form, callback=self._method_changed) self.liu_hu = gui.appendRadioButton(box, "Liu Hu", addToLayout=False) self.liu_lang = gui.comboBox(None, self, 'liu_language', sendSelectedValue=True, contentsLength=10, items=self.LANG, callback=self._method_changed) self.vader = gui.appendRadioButton(box, "Vader", addToLayout=False) self.multi_sent = gui.appendRadioButton(box, "Multilingual " "sentiment", addToLayout=False) self.multi_box = gui.comboBox(None, self, 'multi_language', sendSelectedValue=True, contentsLength=10, items=[''], callback=self._method_changed) self.senti_art = gui.appendRadioButton(box, "SentiArt", addToLayout=False) self.senti_box = gui.comboBox(None, self, 'senti_language', sendSelectedValue=True, contentsLength=10, items=[''], callback=self._method_changed) self.custom_list = gui.appendRadioButton(box, "Custom dictionary", addToLayout=False) self.__posfile_loader = FileLoader() self.__posfile_loader.set_file_list() self.__posfile_loader.activated.connect(self.__pos_loader_activated) self.__posfile_loader.file_loaded.connect(self.__pos_loader_activated) self.__negfile_loader = FileLoader() self.__negfile_loader.set_file_list() self.__negfile_loader.activated.connect(self.__neg_loader_activated) self.__negfile_loader.file_loaded.connect(self.__neg_loader_activated) self.form.addWidget(self.liu_hu, 0, 0, Qt.AlignLeft) self.form.addWidget(QLabel("Language:"), 0, 1, Qt.AlignRight) self.form.addWidget(self.liu_lang, 0, 2, Qt.AlignRight) self.form.addWidget(self.vader, 1, 0, Qt.AlignLeft) self.form.addWidget(self.multi_sent, 2, 0, Qt.AlignLeft) self.form.addWidget(QLabel("Language:"), 2, 1, Qt.AlignRight) self.form.addWidget(self.multi_box, 2, 2, Qt.AlignRight) self.form.addWidget(self.senti_art, 3, 0, Qt.AlignLeft) self.form.addWidget(QLabel("Language:"), 3, 1, Qt.AlignRight) self.form.addWidget(self.senti_box, 3, 2, Qt.AlignRight) self.form.addWidget(self.custom_list, 4, 0, Qt.AlignLeft) self.filegrid = QGridLayout() self.form.addLayout(self.filegrid, 5, 0, 1, 3) self.filegrid.addWidget(QLabel("Positive:"), 0, 0, Qt.AlignRight) self.filegrid.addWidget(self.__posfile_loader.file_combo, 0, 1) self.filegrid.addWidget(self.__posfile_loader.browse_btn, 0, 2) self.filegrid.addWidget(self.__posfile_loader.load_btn, 0, 3) self.filegrid.addWidget(QLabel("Negative:"), 1, 0, Qt.AlignRight) self.filegrid.addWidget(self.__negfile_loader.file_combo, 1, 1) self.filegrid.addWidget(self.__negfile_loader.browse_btn, 1, 2) self.filegrid.addWidget(self.__negfile_loader.load_btn, 1, 3) self.multi_dict = MultisentimentDictionaries() self.senti_dict = SentiArtDictionaries() self.update_box(self.multi_box, self.multi_dict, MultiSentiment) self.update_box(self.senti_box, self.senti_dict, SentiArt) self.online = self.multi_dict.online self.check_sentiment_online() ac = gui.auto_commit(self.controlArea, self, 'autocommit', 'Commit', 'Autocommit is on') ac.layout().insertSpacing(1, 8)
def _init_ui(self): namesBox = gui.vBox(self.controlArea, "Names") hbox = gui.hBox(namesBox, margin=0, spacing=0) gui.lineEdit(hbox, self, "attr1", "Variable X: ", controlWidth=80, orientation=Qt.Horizontal, callback=self._attr_name_changed) gui.separator(hbox, 21) hbox = gui.hBox(namesBox, margin=0, spacing=0) attr2 = gui.lineEdit(hbox, self, "attr2", "Variable Y: ", controlWidth=80, orientation=Qt.Horizontal, callback=self._attr_name_changed) gui.separator(hbox) gui.checkBox(hbox, self, "hasAttr2", '', disables=attr2, labelWidth=0, callback=self.set_dimensions) gui.separator(namesBox) gui.widgetLabel(namesBox, "Labels") self.classValuesView = listView = gui.ListViewWithSizeHint( preferred_size=(-1, 30)) listView.setModel(self.class_model) itemmodels.select_row(listView, 0) namesBox.layout().addWidget(listView) self.addClassLabel = QAction( "+", self, toolTip="Add new class label", triggered=self.add_new_class_label ) self.removeClassLabel = QAction( unicodedata.lookup("MINUS SIGN"), self, toolTip="Remove selected class label", triggered=self.remove_selected_class_label ) actionsWidget = itemmodels.ModelActionsWidget( [self.addClassLabel, self.removeClassLabel], self ) actionsWidget.layout().addStretch(10) actionsWidget.layout().setSpacing(1) namesBox.layout().addWidget(actionsWidget) tBox = gui.vBox(self.controlArea, "Tools", addSpace=True) buttonBox = gui.hBox(tBox) toolsBox = gui.widgetBox(buttonBox, orientation=QGridLayout()) self.toolActions = QActionGroup(self) self.toolActions.setExclusive(True) self.toolButtons = [] for i, (name, tooltip, tool, icon) in enumerate(self.TOOLS): action = QAction( name, self, toolTip=tooltip, checkable=tool.checkable, icon=QIcon(icon), ) action.triggered.connect(partial(self.set_current_tool, tool)) button = QToolButton( iconSize=QSize(24, 24), toolButtonStyle=Qt.ToolButtonTextUnderIcon, sizePolicy=QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) ) button.setDefaultAction(action) self.toolButtons.append((button, tool)) toolsBox.layout().addWidget(button, i / 3, i % 3) self.toolActions.addAction(action) for column in range(3): toolsBox.layout().setColumnMinimumWidth(column, 10) toolsBox.layout().setColumnStretch(column, 1) undo = self.undo_stack.createUndoAction(self) redo = self.undo_stack.createRedoAction(self) undo.setShortcut(QKeySequence.Undo) redo.setShortcut(QKeySequence.Redo) self.addActions([undo, redo]) self.undo_stack.indexChanged.connect(lambda _: self.invalidate()) gui.separator(tBox) indBox = gui.indentedBox(tBox, sep=8) form = QFormLayout( formAlignment=Qt.AlignLeft, labelAlignment=Qt.AlignLeft, fieldGrowthPolicy=QFormLayout.AllNonFixedFieldsGrow ) indBox.layout().addLayout(form) slider = gui.hSlider( indBox, self, "brushRadius", minValue=1, maxValue=100, createLabel=False ) form.addRow("Radius:", slider) slider = gui.hSlider( indBox, self, "density", None, minValue=1, maxValue=100, createLabel=False ) form.addRow("Intensity:", slider) self.btResetToInput = gui.button( tBox, self, "Reset to Input Data", self.reset_to_input) self.btResetToInput.setDisabled(True) gui.auto_commit(self.left_side, self, "autocommit", "Send") # main area GUI viewbox = PaintViewBox(enableMouse=False) self.plotview = pg.PlotWidget(background="w", viewBox=viewbox) self.plotview.sizeHint = lambda: QSize(200, 100) # Minimum size for 1-d painting self.plot = self.plotview.getPlotItem() axis_color = self.palette().color(QPalette.Text) axis_pen = QPen(axis_color) tickfont = QFont(self.font()) tickfont.setPixelSize(max(int(tickfont.pixelSize() * 2 // 3), 11)) axis = self.plot.getAxis("bottom") axis.setLabel(self.attr1) axis.setPen(axis_pen) axis.setTickFont(tickfont) axis = self.plot.getAxis("left") axis.setLabel(self.attr2) axis.setPen(axis_pen) axis.setTickFont(tickfont) if not self.hasAttr2: self.plot.hideAxis('left') self.plot.hideButtons() self.plot.setXRange(0, 1, padding=0.01) self.mainArea.layout().addWidget(self.plotview) # enable brush tool self.toolActions.actions()[0].setChecked(True) self.set_current_tool(self.TOOLS[0][2]) self.set_dimensions()
def __init__(self): super().__init__() self.data = None form = QGridLayout() self.row_type = "" gui.lineEdit(self.controlArea, self, "row_type", "Row Type", callback=self.send_output) self.col_type = "" gui.lineEdit(self.controlArea, self, "col_type", "Column Type", callback=self.send_output) methodbox = gui.radioButtonsInBox(self.controlArea, self, "method", [], box=self.tr("Sampling method"), orientation=form) rows = gui.appendRadioButton(methodbox, "Rows", addToLayout=False) form.addWidget(rows, 0, 0, Qt.AlignLeft) cols = gui.appendRadioButton(methodbox, "Columns", addToLayout=False) form.addWidget(cols, 0, 1, Qt.AlignLeft) rows_and_cols = gui.appendRadioButton(methodbox, "Rows and columns", addToLayout=False) form.addWidget(rows_and_cols, 1, 0, Qt.AlignLeft) entries = gui.appendRadioButton(methodbox, "Entries", addToLayout=False) form.addWidget(entries, 1, 1, Qt.AlignLeft) sample_size = gui.widgetBox(self.controlArea, "Proportion of data in the sample") gui.hSlider(sample_size, self, 'percent', minValue=1, maxValue=100, step=5, ticks=10, labelFormat=" %d%%") gui.button(self.controlArea, self, "&Apply", callback=self.send_output, default=True) self.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)) self.setMinimumWidth(250) self.send_output()
def __init__(self): super().__init__() self.data = None self.clusterings = {} layout = QGridLayout() bg = gui.radioButtonsInBox( self.controlArea, self, "optimize_k", orientation=layout, box="Number of Clusters", callback=self.invalidate) layout.addWidget( gui.appendRadioButton(bg, "Fixed:", addToLayout=False), 1, 1) sb = gui.hBox(None, margin=0) gui.spin( sb, self, "k", minv=2, maxv=30, controlWidth=60, alignment=Qt.AlignRight, callback=self.update_k) gui.rubber(sb) layout.addWidget(sb, 1, 2) layout.addWidget( gui.appendRadioButton(bg, "From", addToLayout=False), 2, 1) ftobox = gui.hBox(None) ftobox.layout().setContentsMargins(0, 0, 0, 0) layout.addWidget(ftobox, 2, 2) gui.spin( ftobox, self, "k_from", minv=2, maxv=29, controlWidth=60, alignment=Qt.AlignRight, callback=self.update_from) gui.widgetLabel(ftobox, "to") gui.spin( ftobox, self, "k_to", minv=3, maxv=30, controlWidth=60, alignment=Qt.AlignRight, callback=self.update_to) gui.rubber(ftobox) box = gui.vBox(self.controlArea, "Initialization") gui.comboBox( box, self, "smart_init", items=self.INIT_METHODS, callback=self.invalidate) layout = QGridLayout() gui.widgetBox(box, orientation=layout) layout.addWidget(gui.widgetLabel(None, "Re-runs: "), 0, 0, Qt.AlignLeft) sb = gui.hBox(None, margin=0) layout.addWidget(sb, 0, 1) gui.lineEdit( sb, self, "n_init", controlWidth=60, valueType=int, validator=QIntValidator(), callback=self.invalidate) layout.addWidget( gui.widgetLabel(None, "Maximum iterations: "), 1, 0, Qt.AlignLeft) sb = gui.hBox(None, margin=0) layout.addWidget(sb, 1, 1) gui.lineEdit( sb, self, "max_iterations", controlWidth=60, valueType=int, validator=QIntValidator(), callback=self.invalidate) self.apply_button = gui.auto_commit( self.buttonsArea, self, "auto_run", "Apply", box=None, commit=self.apply) self.buttonsArea.layout().addWidget(self.report_button) gui.rubber(self.controlArea) box = gui.vBox(self.mainArea, box="Silhouette Scores") table = self.table_view = QTableView(self.mainArea) table.setModel(ClusterTableModel(self)) table.setSelectionMode(QTableView.SingleSelection) table.setSelectionBehavior(QTableView.SelectRows) table.setItemDelegate(gui.ColoredBarItemDelegate(self, color=Qt.cyan)) table.selectionModel().selectionChanged.connect(self.select_row) table.setMaximumWidth(200) table.horizontalHeader().setStretchLastSection(True) table.horizontalHeader().hide() table.setShowGrid(False) box.layout().addWidget(table)
def _setup_control_area(self) -> None: box = gui.widgetBox(self.controlArea, "Word Scoring Methods") for value, (n, _, tt) in SCORING_METHODS.items(): b = gui.hBox(box, margin=0) gui.checkBox( b, self, value, label=n, callback=self.__setting_changed, tooltip=tt, ) if value in ADDITIONAL_OPTIONS: value, options = ADDITIONAL_OPTIONS[value] gui.comboBox( b, self, value, items=options, callback=self.__setting_changed, ) box = gui.widgetBox(self.controlArea, "Aggregation") gui.comboBox( box, self, "aggregation", items=[n for n in AGGREGATIONS], callback=self.__setting_changed, ) gui.rubber(self.controlArea) # select words box box = gui.vBox(self.buttonsArea, "Select Documents") grid = QGridLayout() grid.setContentsMargins(0, 0, 0, 0) self._sel_method_buttons = QButtonGroup() for method, label in enumerate(SelectionMethods.ITEMS): button = QRadioButton(label) button.setChecked(method == self.sel_method) grid.addWidget(button, method, 0) self._sel_method_buttons.addButton(button, method) self._sel_method_buttons.buttonClicked[int].connect( self.__set_selection_method) spin = gui.spin( box, self, "n_selected", 1, 999, addToLayout=False, callback=lambda: self.__set_selection_method(SelectionMethods. N_BEST), ) grid.addWidget(spin, 3, 1) box.layout().addLayout(grid) # autocommit gui.auto_send(self.buttonsArea, self, "auto_commit")
def __init__(self): super().__init__() self.data = None self.features = None # Schedule interface updates (enabled buttons) using a coalescing # single shot timer (complex interactions on selection and filtering # updates in the 'available_attrs_view') self.__interface_update_timer = QTimer(self, interval=0, singleShot=True) self.__interface_update_timer.timeout.connect( self.__update_interface_state) # The last view that has the selection for move operation's source self.__last_active_view = None # type: Optional[QListView] def update_on_change(view): # Schedule interface state update on selection change in `view` self.__last_active_view = view self.__interface_update_timer.start() new_control_area = QWidget(self.controlArea) self.controlArea.layout().addWidget(new_control_area) self.controlArea = new_control_area # init grid layout = QGridLayout() self.controlArea.setLayout(layout) layout.setContentsMargins(0, 0, 0, 0) box = gui.vBox(self.controlArea, "Ignored", addToLayout=False) self.available_attrs = VariablesListItemModel() filter_edit, self.available_attrs_view = variables_filter( parent=self, model=self.available_attrs) box.layout().addWidget(filter_edit) def dropcompleted(action): if action == Qt.MoveAction: self.commit.deferred() self.available_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.available_attrs_view)) self.available_attrs_view.dragDropActionDidComplete.connect( dropcompleted) box.layout().addWidget(self.available_attrs_view) layout.addWidget(box, 0, 0, 3, 1) # 3rd column box = gui.vBox(self.controlArea, "Features", addToLayout=False) self.used_attrs = VariablesListItemModel() filter_edit, self.used_attrs_view = variables_filter( parent=self, model=self.used_attrs, accepted_type=(Orange.data.DiscreteVariable, Orange.data.ContinuousVariable)) self.used_attrs.rowsInserted.connect(self.__used_attrs_changed) self.used_attrs.rowsRemoved.connect(self.__used_attrs_changed) self.used_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.used_attrs_view)) self.used_attrs_view.dragDropActionDidComplete.connect(dropcompleted) self.use_features_box = gui.auto_commit( self.controlArea, self, "use_input_features", "Use input features", "Always use input features", box=False, commit=self.__use_features_clicked, callback=self.__use_features_changed, addToLayout=False) self.enable_use_features_box() box.layout().addWidget(self.use_features_box) box.layout().addWidget(filter_edit) box.layout().addWidget(self.used_attrs_view) layout.addWidget(box, 0, 2, 1, 1) box = gui.vBox(self.controlArea, "Target", addToLayout=False) self.class_attrs = VariablesListItemModel() self.class_attrs_view = VariablesListItemView( acceptedType=(Orange.data.DiscreteVariable, Orange.data.ContinuousVariable)) self.class_attrs_view.setModel(self.class_attrs) self.class_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.class_attrs_view)) self.class_attrs_view.dragDropActionDidComplete.connect(dropcompleted) box.layout().addWidget(self.class_attrs_view) layout.addWidget(box, 1, 2, 1, 1) box = gui.vBox(self.controlArea, "Metas", addToLayout=False) self.meta_attrs = VariablesListItemModel() self.meta_attrs_view = VariablesListItemView( acceptedType=Orange.data.Variable) self.meta_attrs_view.setModel(self.meta_attrs) self.meta_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.meta_attrs_view)) self.meta_attrs_view.dragDropActionDidComplete.connect(dropcompleted) box.layout().addWidget(self.meta_attrs_view) layout.addWidget(box, 2, 2, 1, 1) # 2nd column bbox = gui.vBox(self.controlArea, addToLayout=False, margin=0) self.move_attr_button = gui.button(bbox, self, ">", callback=partial( self.move_selected, self.used_attrs_view)) layout.addWidget(bbox, 0, 1, 1, 1) bbox = gui.vBox(self.controlArea, addToLayout=False, margin=0) self.move_class_button = gui.button(bbox, self, ">", callback=partial( self.move_selected, self.class_attrs_view)) layout.addWidget(bbox, 1, 1, 1, 1) bbox = gui.vBox(self.controlArea, addToLayout=False) self.move_meta_button = gui.button(bbox, self, ">", callback=partial( self.move_selected, self.meta_attrs_view)) layout.addWidget(bbox, 2, 1, 1, 1) # footer gui.button(self.buttonsArea, self, "Reset", callback=self.reset) bbox = gui.vBox(self.buttonsArea) gui.checkBox( widget=bbox, master=self, value="ignore_new_features", label="Ignore new variables by default", tooltip="When the widget receives data with additional columns " "they are added to the available attributes column if " "<i>Ignore new variables by default</i> is checked.") gui.rubber(self.buttonsArea) gui.auto_send(self.buttonsArea, self, "auto_commit") layout.setRowStretch(0, 2) layout.setRowStretch(1, 0) layout.setRowStretch(2, 1) layout.setHorizontalSpacing(0) self.controlArea.setLayout(layout) self.output_data = None self.original_completer_items = [] self.resize(600, 600)
def __init__(self): widget.OWWidget.__init__(self) RelocatablePathsWidgetMixin.__init__(self) self.domain = None self.data = None self.loaded_file = "" self.sheets = [] self.lb = gui.listBox(self.controlArea, self, "file_idx", selectionMode=QListWidget.MultiSelection) self.default_foreground = None layout = QGridLayout() gui.widgetBox(self.controlArea, margin=0, orientation=layout) file_button = gui.button(None, self, ' ...', callback=self.browse_files, autoDefault=False) file_button.setIcon(self.style().standardIcon(QStyle.SP_DirOpenIcon)) file_button.setSizePolicy(Policy.Maximum, Policy.Fixed) layout.addWidget(file_button, 0, 0) remove_button = gui.button(None, self, 'Remove', callback=self.remove_item) clear_button = gui.button(None, self, 'Clear', callback=self.clear) layout.addWidget(remove_button, 0, 1) layout.addWidget(clear_button, 0, 2) reload_button = gui.button(None, self, "Reload", callback=self.load_data, autoDefault=False) reload_button.setIcon(self.style().standardIcon( QStyle.SP_BrowserReload)) reload_button.setSizePolicy(Policy.Fixed, Policy.Fixed) layout.addWidget(reload_button, 0, 7) self.sheet_box = gui.hBox(None, addToLayout=False, margin=0) self.sheet_index = 0 self.sheet_combo = gui.comboBox(None, self, "sheet_index", callback=self.select_sheet) self.sheet_combo.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed) self.sheet_label = QLabel() self.sheet_label.setText('Sheet') self.sheet_label.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed) self.sheet_box.layout().addWidget(self.sheet_label, Qt.AlignLeft) self.sheet_box.layout().addWidget(self.sheet_combo, Qt.AlignVCenter) layout.addWidget(self.sheet_box, 2, 1) self.sheet_box.hide() layout.addWidget(self.sheet_box, 0, 5) label_box = gui.hBox(None, addToLayout=False, margin=0) gui.lineEdit(label_box, self, "label", callback=self.set_label, label="Label", orientation=Qt.Horizontal) layout.addWidget(label_box, 0, 6) layout.setColumnStretch(3, 2) box = gui.widgetBox(self.controlArea, "Columns (Double click to edit)") self.domain_editor = DomainEditor(self) self.editor_model = self.domain_editor.model() box.layout().addWidget(self.domain_editor) for rp in self.recent_paths: self.lb.addItem(rp.abspath) box = gui.hBox(self.controlArea) gui.rubber(box) gui.button(box, self, "Reset", callback=self.reset_domain_edit) self.apply_button = gui.button(box, self, "Apply", callback=self.apply_domain_edit) self.apply_button.setEnabled(False) self.apply_button.setFixedWidth(170) self.editor_model.dataChanged.connect( lambda: self.apply_button.setEnabled(True)) self._update_sheet_combo() self.load_data()
def __init__(self): super().__init__() self.data = None self.features = None # Schedule interface updates (enabled buttons) using a coalescing # single shot timer (complex interactions on selection and filtering # updates in the 'available_attrs_view') self.__interface_update_timer = QTimer(self, interval=0, singleShot=True) self.__interface_update_timer.timeout.connect( self.__update_interface_state) # The last view that has the selection for move operation's source self.__last_active_view = None # type: Optional[QListView] def update_on_change(view): # Schedule interface state update on selection change in `view` self.__last_active_view = view self.__interface_update_timer.start() self.controlArea = QWidget(self.controlArea) self.layout().addWidget(self.controlArea) layout = QGridLayout() self.controlArea.setLayout(layout) layout.setContentsMargins(4, 4, 4, 4) box = gui.vBox(self.controlArea, "Available Variables", addToLayout=False) self.available_attrs = VariablesListItemModel() filter_edit, self.available_attrs_view = variables_filter( parent=self, model=self.available_attrs) box.layout().addWidget(filter_edit) def dropcompleted(action): if action == Qt.MoveAction: self.commit() self.available_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.available_attrs_view)) self.available_attrs_view.dragDropActionDidComplete.connect( dropcompleted) box.layout().addWidget(self.available_attrs_view) layout.addWidget(box, 0, 0, 3, 1) box = gui.vBox(self.controlArea, "Features", addToLayout=False) self.used_attrs = VariablesListItemModel() filter_edit, self.used_attrs_view = variables_filter( parent=self, model=self.used_attrs, accepted_type=(Orange.data.DiscreteVariable, Orange.data.ContinuousVariable)) self.used_attrs.rowsInserted.connect(self.__used_attrs_changed) self.used_attrs.rowsRemoved.connect(self.__used_attrs_changed) self.used_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.used_attrs_view)) self.used_attrs_view.dragDropActionDidComplete.connect(dropcompleted) self.use_features_box = gui.auto_commit( self.controlArea, self, "use_input_features", "Use input features", "Always use input features", box=False, commit=self.__use_features_clicked, callback=self.__use_features_changed, addToLayout=False) self.enable_use_features_box() box.layout().addWidget(self.use_features_box) box.layout().addWidget(filter_edit) box.layout().addWidget(self.used_attrs_view) layout.addWidget(box, 0, 2, 1, 1) box = gui.vBox(self.controlArea, "Target Variable", addToLayout=False) self.class_attrs = VariablesListItemModel() self.class_attrs_view = VariablesListItemView( acceptedType=(Orange.data.DiscreteVariable, Orange.data.ContinuousVariable)) self.class_attrs_view.setModel(self.class_attrs) self.class_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.class_attrs_view)) self.class_attrs_view.dragDropActionDidComplete.connect(dropcompleted) self.class_attrs_view.setMaximumHeight(72) box.layout().addWidget(self.class_attrs_view) layout.addWidget(box, 1, 2, 1, 1) box = gui.vBox(self.controlArea, "Meta Attributes", addToLayout=False) self.meta_attrs = VariablesListItemModel() self.meta_attrs_view = VariablesListItemView( acceptedType=Orange.data.Variable) self.meta_attrs_view.setModel(self.meta_attrs) self.meta_attrs_view.selectionModel().selectionChanged.connect( partial(update_on_change, self.meta_attrs_view)) self.meta_attrs_view.dragDropActionDidComplete.connect(dropcompleted) box.layout().addWidget(self.meta_attrs_view) layout.addWidget(box, 2, 2, 1, 1) bbox = gui.vBox(self.controlArea, addToLayout=False, margin=0) layout.addWidget(bbox, 0, 1, 1, 1) self.up_attr_button = gui.button(bbox, self, "Up", callback=partial( self.move_up, self.used_attrs_view)) self.move_attr_button = gui.button(bbox, self, ">", callback=partial( self.move_selected, self.used_attrs_view)) self.down_attr_button = gui.button(bbox, self, "Down", callback=partial( self.move_down, self.used_attrs_view)) bbox = gui.vBox(self.controlArea, addToLayout=False, margin=0) layout.addWidget(bbox, 1, 1, 1, 1) self.up_class_button = gui.button(bbox, self, "Up", callback=partial( self.move_up, self.class_attrs_view)) self.move_class_button = gui.button(bbox, self, ">", callback=partial( self.move_selected, self.class_attrs_view)) self.down_class_button = gui.button(bbox, self, "Down", callback=partial( self.move_down, self.class_attrs_view)) bbox = gui.vBox(self.controlArea, addToLayout=False, margin=0) layout.addWidget(bbox, 2, 1, 1, 1) self.up_meta_button = gui.button(bbox, self, "Up", callback=partial( self.move_up, self.meta_attrs_view)) self.move_meta_button = gui.button(bbox, self, ">", callback=partial( self.move_selected, self.meta_attrs_view)) self.down_meta_button = gui.button(bbox, self, "Down", callback=partial( self.move_down, self.meta_attrs_view)) autobox = gui.auto_send(None, self, "auto_commit") layout.addWidget(autobox, 3, 0, 1, 3) reset = gui.button(None, self, "Reset", callback=self.reset, width=120) autobox.layout().insertWidget(0, reset) autobox.layout().insertStretch(1, 20) layout.setRowStretch(0, 4) layout.setRowStretch(1, 0) layout.setRowStretch(2, 2) layout.setHorizontalSpacing(0) self.controlArea.setLayout(layout) self.output_data = None self.original_completer_items = [] self.info.set_input_summary(self.info.NoInput) self.info.set_output_summary(self.info.NoOutput) self.resize(600, 600)
def __init__(self): super().__init__() self.matrix = None self.items = None self.linkmatrix = None self.root = None self._displayed_root = None self.cutoff_height = 0.0 self._set_input_summary(None) self._set_output_summary(None) gui.comboBox( self.controlArea, self, "linkage", items=LINKAGE, box="Linkage", callback=self._invalidate_clustering) model = itemmodels.VariableListModel() model[:] = self.basic_annotations box = gui.widgetBox(self.controlArea, "Annotations") self.label_cb = cb = combobox.ComboBoxSearch( minimumContentsLength=14, sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon ) cb.setModel(model) cb.setCurrentIndex(cb.findData(self.annotation, Qt.EditRole)) def on_annotation_activated(): self.annotation = cb.currentData(Qt.EditRole) self._update_labels() cb.activated.connect(on_annotation_activated) def on_annotation_changed(value): cb.setCurrentIndex(cb.findData(value, Qt.EditRole)) self.connect_control("annotation", on_annotation_changed) box.layout().addWidget(self.label_cb) box = gui.radioButtons( self.controlArea, self, "pruning", box="Pruning", callback=self._invalidate_pruning) grid = QGridLayout() box.layout().addLayout(grid) grid.addWidget( gui.appendRadioButton(box, "None", addToLayout=False), 0, 0 ) self.max_depth_spin = gui.spin( box, self, "max_depth", minv=1, maxv=100, callback=self._invalidate_pruning, keyboardTracking=False, addToLayout=False ) grid.addWidget( gui.appendRadioButton(box, "Max depth:", addToLayout=False), 1, 0) grid.addWidget(self.max_depth_spin, 1, 1) self.selection_box = gui.radioButtons( self.controlArea, self, "selection_method", box="Selection", callback=self._selection_method_changed) grid = QGridLayout() self.selection_box.layout().addLayout(grid) grid.addWidget( gui.appendRadioButton( self.selection_box, "Manual", addToLayout=False), 0, 0 ) grid.addWidget( gui.appendRadioButton( self.selection_box, "Height ratio:", addToLayout=False), 1, 0 ) self.cut_ratio_spin = gui.spin( self.selection_box, self, "cut_ratio", 0, 100, step=1e-1, spinType=float, callback=self._selection_method_changed, addToLayout=False ) self.cut_ratio_spin.setSuffix("%") grid.addWidget(self.cut_ratio_spin, 1, 1) grid.addWidget( gui.appendRadioButton( self.selection_box, "Top N:", addToLayout=False), 2, 0 ) self.top_n_spin = gui.spin(self.selection_box, self, "top_n", 1, 20, callback=self._selection_method_changed, addToLayout=False) grid.addWidget(self.top_n_spin, 2, 1) self.zoom_slider = gui.hSlider( self.controlArea, self, "zoom_factor", box="Zoom", minValue=-6, maxValue=3, step=1, ticks=True, createLabel=False, callback=self.__update_font_scale) zoom_in = QAction( "Zoom in", self, shortcut=QKeySequence.ZoomIn, triggered=self.__zoom_in ) zoom_out = QAction( "Zoom out", self, shortcut=QKeySequence.ZoomOut, triggered=self.__zoom_out ) zoom_reset = QAction( "Reset zoom", self, shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_0), triggered=self.__zoom_reset ) self.addActions([zoom_in, zoom_out, zoom_reset]) self.controlArea.layout().addStretch() gui.auto_send(self.buttonsArea, self, "autocommit") self.scene = QGraphicsScene(self) self.view = StickyGraphicsView( self.scene, horizontalScrollBarPolicy=Qt.ScrollBarAlwaysOff, verticalScrollBarPolicy=Qt.ScrollBarAlwaysOn, alignment=Qt.AlignLeft | Qt.AlignVCenter ) self.mainArea.layout().setSpacing(1) self.mainArea.layout().addWidget(self.view) def axis_view(orientation): ax = AxisItem(orientation=orientation, maxTickLength=7) ax.mousePressed.connect(self._activate_cut_line) ax.mouseMoved.connect(self._activate_cut_line) ax.mouseReleased.connect(self._activate_cut_line) ax.setRange(1.0, 0.0) return ax self.top_axis = axis_view("top") self.bottom_axis = axis_view("bottom") self._main_graphics = QGraphicsWidget() scenelayout = QGraphicsGridLayout() scenelayout.setHorizontalSpacing(10) scenelayout.setVerticalSpacing(10) self._main_graphics.setLayout(scenelayout) self.scene.addItem(self._main_graphics) self.dendrogram = DendrogramWidget() self.dendrogram.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.dendrogram.selectionChanged.connect(self._invalidate_output) self.dendrogram.selectionEdited.connect(self._selection_edited) self.labels = TextListWidget() self.labels.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) self.labels.setAlignment(Qt.AlignLeft) self.labels.setMaximumWidth(200) scenelayout.addItem(self.top_axis, 0, 0, alignment=Qt.AlignLeft | Qt.AlignVCenter) scenelayout.addItem(self.dendrogram, 1, 0, alignment=Qt.AlignLeft | Qt.AlignVCenter) scenelayout.addItem(self.labels, 1, 1, alignment=Qt.AlignLeft | Qt.AlignVCenter) scenelayout.addItem(self.bottom_axis, 2, 0, alignment=Qt.AlignLeft | Qt.AlignVCenter) self.view.viewport().installEventFilter(self) self._main_graphics.installEventFilter(self) self.top_axis.setZValue(self.dendrogram.zValue() + 10) self.bottom_axis.setZValue(self.dendrogram.zValue() + 10) self.cut_line = SliderLine(self.top_axis, orientation=Qt.Horizontal) self.cut_line.valueChanged.connect(self._dendrogram_slider_changed) self.dendrogram.geometryChanged.connect(self._dendrogram_geom_changed) self._set_cut_line_visible(self.selection_method == 1) self.__update_font_scale()
def __init__(self): super().__init__() self.data = None # type: Optional[Table] self.__pending_selection = self.selection # type: Optional[int] self.clusterings = {} self.__executor = ThreadExecutor(parent=self) self.__task = None # type: Optional[Task] layout = QGridLayout() bg = gui.radioButtonsInBox( self.controlArea, self, "optimize_k", orientation=layout, box="Number of Clusters", callback=self.update_method, ) layout.addWidget( gui.appendRadioButton(bg, "Fixed:", addToLayout=False), 1, 1) sb = gui.hBox(None, margin=0) gui.spin(sb, self, "k", minv=2, maxv=30, controlWidth=60, alignment=Qt.AlignRight, callback=self.update_k) gui.rubber(sb) layout.addWidget(sb, 1, 2) layout.addWidget(gui.appendRadioButton(bg, "From", addToLayout=False), 2, 1) ftobox = gui.hBox(None) ftobox.layout().setContentsMargins(0, 0, 0, 0) layout.addWidget(ftobox, 2, 2) gui.spin(ftobox, self, "k_from", minv=2, maxv=29, controlWidth=60, alignment=Qt.AlignRight, callback=self.update_from) gui.widgetLabel(ftobox, "to") gui.spin(ftobox, self, "k_to", minv=3, maxv=30, controlWidth=60, alignment=Qt.AlignRight, callback=self.update_to) gui.rubber(ftobox) box = gui.vBox(self.controlArea, "Preprocessing") gui.checkBox(box, self, "normalize", "Normalize columns", callback=self.invalidate) box = gui.vBox(self.controlArea, "Initialization") gui.comboBox(box, self, "smart_init", items=[m[0] for m in self.INIT_METHODS], callback=self.invalidate) layout = QGridLayout() gui.widgetBox(box, orientation=layout) layout.addWidget(gui.widgetLabel(None, "Re-runs: "), 0, 0, Qt.AlignLeft) sb = gui.hBox(None, margin=0) layout.addWidget(sb, 0, 1) gui.lineEdit(sb, self, "n_init", controlWidth=60, valueType=int, validator=QIntValidator(), callback=self.invalidate) layout.addWidget(gui.widgetLabel(None, "Maximum iterations: "), 1, 0, Qt.AlignLeft) sb = gui.hBox(None, margin=0) layout.addWidget(sb, 1, 1) gui.lineEdit(sb, self, "max_iterations", controlWidth=60, valueType=int, validator=QIntValidator(), callback=self.invalidate) box = gui.vBox(self.mainArea, box="Silhouette Scores") if self.optimize_k: self.mainArea.setVisible(True) self.left_side.setContentsMargins(0, 0, 0, 0) else: self.mainArea.setVisible(False) self.left_side.setContentsMargins(0, 0, 4, 0) self.table_model = ClusterTableModel(self) table = self.table_view = QTableView(self.mainArea) table.setModel(self.table_model) table.setSelectionMode(QTableView.SingleSelection) table.setSelectionBehavior(QTableView.SelectRows) table.setItemDelegate(gui.ColoredBarItemDelegate(self, color=Qt.cyan)) table.selectionModel().selectionChanged.connect(self.select_row) table.setMaximumWidth(200) table.horizontalHeader().setStretchLastSection(True) table.horizontalHeader().hide() table.setShowGrid(False) box.layout().addWidget(table) self.apply_button = gui.auto_apply(self.buttonsArea, self, "auto_commit", commit=self.commit)
rect.y() + rect.height() - 2, strMax) else: painter.drawText(rect.x() + 1, x1 + height, strMin) painter.drawText(rect.x() + rect.width() - widthMax - 1, x2 - 2, strMax) def formatValues(self, valueMin, valueMax): """Format the int values into strings that are shown if showText is True.""" return str(valueMin), str(valueMax) if __name__ == "__main__": from AnyQt.QtWidgets import QApplication, QDialog, QGridLayout, QLabel app = QApplication([]) win = QDialog() grid = QGridLayout(win) win.setLayout(grid) kwargs = dict(minimum=0, maximum=100, tickInterval=5, minimumValue=20, maximumValue=80, slidersMoved=print) grid.addWidget(QLabel('RangeSlider:', win), 0, 0) grid.addWidget(RangeSlider(win, orientation=Qt.Horizontal, **kwargs), 0, 1) grid.addWidget(QLabel('RangeSlider:', win), 1, 0) grid.addWidget(RangeSlider(win, orientation=Qt.Vertical, **kwargs), 1, 1) grid.addWidget(QLabel('ViolinSlider:', win), 2, 0) slider = ViolinSlider(win, orientation=Qt.Horizontal, **kwargs)
def __init__(self): super().__init__() self.data = None # type: Optional[Orange.data.Table] self.learner = None # type: Optional[Learner] self.default_learner = SimpleTreeLearner(min_instances=10, max_depth=10) self.modified = False self.executor = qconcurrent.ThreadExecutor(self) self.__task = None main_layout = self.controlArea.layout() box = gui.vBox(self.controlArea, "Default Method") box_layout = QGridLayout() box_layout.setSpacing(8) box.layout().addLayout(box_layout) button_group = QButtonGroup() button_group.buttonClicked[int].connect(self.set_default_method) for i, (method, _) in enumerate(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, i % 3, i // 3) def set_default_time(datetime): datetime = datetime.toSecsSinceEpoch() if datetime != self.default_time: self.default_time = datetime if self.default_method_index == Method.Default: self._invalidate() hlayout = QHBoxLayout() box.layout().addLayout(hlayout) button = QRadioButton("Fixed values; numeric variables:") button_group.addButton(button, Method.Default) button.setChecked(Method.Default == self.default_method_index) hlayout.addWidget(button) self.numeric_value_widget = DoubleSpinBox( minimum=DBL_MIN, maximum=DBL_MAX, singleStep=.1, value=self.default_numeric_value, alignment=Qt.AlignRight, enabled=self.default_method_index == Method.Default, ) self.numeric_value_widget.editingFinished.connect( self.__on_default_numeric_value_edited) self.connect_control("default_numeric_value", self.numeric_value_widget.setValue) hlayout.addWidget(self.numeric_value_widget) hlayout.addWidget(QLabel(", time:")) self.time_widget = gui.DateTimeEditWCalendarTime(self) self.time_widget.setEnabled( self.default_method_index == Method.Default) self.time_widget.setKeyboardTracking(False) self.time_widget.setContentsMargins(0, 0, 0, 0) self.time_widget.set_datetime( QDateTime.fromSecsSinceEpoch(self.default_time)) self.connect_control( "default_time", lambda value: self.time_widget.set_datetime( QDateTime.fromSecsSinceEpoch(value))) self.time_widget.dateTimeChanged.connect(set_default_time) hlayout.addWidget(self.time_widget) self.default_button_group = button_group box = gui.hBox(self.controlArea, self.tr("Individual Attribute Settings"), flat=False) self.varview = ListViewSearch( 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() box.layout().addWidget(self.varview) vertical_layout = QVBoxLayout(margin=0) self.methods_container = QWidget(enabled=False) method_layout = QVBoxLayout(margin=0) self.methods_container.setLayout(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 = DoubleSpinBox( editingFinished=self._on_value_selected, minimum=DBL_MIN, maximum=DBL_MAX, singleStep=.1, ) 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( self.set_method_for_current_selection) self.reset_button = QPushButton( "Restore All to Default", enabled=False, default=False, autoDefault=False, clicked=self.reset_variable_state, ) vertical_layout.addWidget(self.methods_container) vertical_layout.addStretch(2) vertical_layout.addWidget(self.reset_button) box.layout().addLayout(vertical_layout) self.variable_button_group = button_group gui.auto_apply(self.buttonsArea, self, "autocommit")
def __init__(self): super().__init__() self.measure_scores = None self.update_scores = True self.usefulAttributes = [] self.learners = {} self.labels = [] self.out_domain_desc = None self.all_measures = SCORES self.selectedMeasures = dict([(m.name, True) for m in self.all_measures]) # Discrete (0) or continuous (1) class mode self.rankMode = 0 self.data = None self.discMeasures = [m for m in self.all_measures if issubclass(DiscreteVariable, m.score.class_type)] self.contMeasures = [m for m in self.all_measures if issubclass(ContinuousVariable, m.score.class_type)] self.score_checks = [] self.cls_scoring_box = gui.vBox(None, "Scoring for Classification") self.reg_scoring_box = gui.vBox(None, "Scoring for Regression") boxes = [self.cls_scoring_box] * 7 + [self.reg_scoring_box] * 2 for _score, var, box in zip(SCORES, self._score_vars, boxes): check = gui.checkBox( box, self, var, label=_score.name, callback=lambda val=_score: self.measuresSelectionChanged(val)) self.score_checks.append(check) self.score_stack = QStackedWidget(self) self.score_stack.addWidget(self.cls_scoring_box) self.score_stack.addWidget(self.reg_scoring_box) self.score_stack.addWidget(QWidget()) self.controlArea.layout().addWidget(self.score_stack) gui.rubber(self.controlArea) selMethBox = gui.vBox( self.controlArea, "Select Attributes", addSpace=True) grid = QGridLayout() grid.setContentsMargins(6, 0, 6, 0) self.selectButtons = QButtonGroup() self.selectButtons.buttonClicked[int].connect(self.setSelectMethod) def button(text, buttonid, toolTip=None): b = QRadioButton(text) self.selectButtons.addButton(b, buttonid) if toolTip is not None: b.setToolTip(toolTip) return b b1 = button(self.tr("None"), OWRank.SelectNone) b2 = button(self.tr("All"), OWRank.SelectAll) b3 = button(self.tr("Manual"), OWRank.SelectManual) b4 = button(self.tr("Best ranked:"), OWRank.SelectNBest) s = gui.spin(selMethBox, self, "nSelected", 1, 100, callback=self.nSelectedChanged) grid.addWidget(b1, 0, 0) grid.addWidget(b2, 1, 0) grid.addWidget(b3, 2, 0) grid.addWidget(b4, 3, 0) grid.addWidget(s, 3, 1) self.selectButtons.button(self.selectMethod).setChecked(True) selMethBox.layout().addLayout(grid) gui.auto_commit(selMethBox, self, "auto_apply", "Send", box=False) # Discrete, continuous and no_class table views are stacked self.ranksViewStack = QStackedLayout() self.mainArea.layout().addLayout(self.ranksViewStack) self.discRanksView = QTableView() self.ranksViewStack.addWidget(self.discRanksView) self.discRanksView.setSelectionBehavior(QTableView.SelectRows) self.discRanksView.setSelectionMode(QTableView.MultiSelection) self.discRanksView.setSortingEnabled(True) self.discRanksLabels = ["#"] + [m.shortname for m in self.discMeasures] self.discRanksModel = QStandardItemModel(self) self.discRanksModel.setHorizontalHeaderLabels(self.discRanksLabels) self.discRanksProxyModel = MySortProxyModel(self) self.discRanksProxyModel.setSourceModel(self.discRanksModel) self.discRanksView.setModel(self.discRanksProxyModel) self.discRanksView.setColumnWidth(0, 20) self.discRanksView.selectionModel().selectionChanged.connect( self.commit ) self.discRanksView.pressed.connect(self.onSelectItem) self.discRanksView.horizontalHeader().sectionClicked.connect( self.headerClick ) self.discRanksView.verticalHeader().sectionClicked.connect( self.onSelectItem ) if self.headerState[0] is not None: self.discRanksView.horizontalHeader().restoreState( self.headerState[0]) self.contRanksView = QTableView() self.ranksViewStack.addWidget(self.contRanksView) self.contRanksView.setSelectionBehavior(QTableView.SelectRows) self.contRanksView.setSelectionMode(QTableView.MultiSelection) self.contRanksView.setSortingEnabled(True) self.contRanksLabels = ["#"] + [m.shortname for m in self.contMeasures] self.contRanksModel = QStandardItemModel(self) self.contRanksModel.setHorizontalHeaderLabels(self.contRanksLabels) self.contRanksProxyModel = MySortProxyModel(self) self.contRanksProxyModel.setSourceModel(self.contRanksModel) self.contRanksView.setModel(self.contRanksProxyModel) self.contRanksView.setColumnWidth(0, 20) self.contRanksView.selectionModel().selectionChanged.connect( self.commit ) self.contRanksView.pressed.connect(self.onSelectItem) self.contRanksView.horizontalHeader().sectionClicked.connect( self.headerClick ) self.contRanksView.verticalHeader().sectionClicked.connect( self.onSelectItem ) if self.headerState[1] is not None: self.contRanksView.horizontalHeader().restoreState( self.headerState[1]) self.noClassRanksView = QTableView() self.ranksViewStack.addWidget(self.noClassRanksView) self.noClassRanksView.setSelectionBehavior(QTableView.SelectRows) self.noClassRanksView.setSelectionMode(QTableView.MultiSelection) self.noClassRanksView.setSortingEnabled(True) self.noClassRanksLabels = ["#"] self.noClassRanksModel = QStandardItemModel(self) self.noClassRanksModel.setHorizontalHeaderLabels(self.noClassRanksLabels) self.noClassRanksProxyModel = MySortProxyModel(self) self.noClassRanksProxyModel.setSourceModel(self.noClassRanksModel) self.noClassRanksView.setModel(self.noClassRanksProxyModel) self.noClassRanksView.setColumnWidth(0, 20) self.noClassRanksView.selectionModel().selectionChanged.connect( self.commit ) self.noClassRanksView.pressed.connect(self.onSelectItem) self.noClassRanksView.horizontalHeader().sectionClicked.connect( self.headerClick ) self.noClassRanksView.verticalHeader().sectionClicked.connect( self.onSelectItem ) if self.headerState[2] is not None: self.noClassRanksView.horizontalHeader().restoreState( self.headerState[2]) # Switch the current view to Discrete self.switchRanksMode(0) self.resetInternals() self.updateDelegates() self.updateVisibleScoreColumns() self.resize(690, 500) self.measure_scores = table((len(self.measures), 0), None)
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 query_edit = ListEdit(self, 'query_list', "Each line represents a separate query.", None, self) layout.addWidget(QLabel('Query word list:'), row, 0, 1, self.label_width) layout.addWidget(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.button_box.layout().addWidget(self.report_button) self.search_button = gui.button(self.button_box, self, 'Search', self.start_stop) self.search_button.setFocusPolicy(Qt.NoFocus)
def __init__(self): super().__init__() RecentPathsWComboMixin.__init__(self) self.domain = None self.data = None self.loaded_file = "" self.reader = None layout = QGridLayout() gui.widgetBox(self.controlArea, margin=0, orientation=layout) vbox = gui.radioButtons(None, self, "source", box=True, addSpace=True, callback=self.load_data, addToLayout=False) rb_button = gui.appendRadioButton(vbox, "文件:", addToLayout=False) layout.addWidget(rb_button, 0, 0, Qt.AlignVCenter) box = gui.hBox(None, addToLayout=False, margin=0) box.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed) self.file_combo.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed) self.file_combo.activated[int].connect(self.select_file) box.layout().addWidget(self.file_combo) layout.addWidget(box, 0, 1) file_button = gui.button(None, self, '...', callback=self.browse_file, autoDefault=False) file_button.setIcon(self.style().standardIcon(QStyle.SP_DirOpenIcon)) file_button.setSizePolicy(Policy.Maximum, Policy.Fixed) layout.addWidget(file_button, 0, 2) reload_button = gui.button(None, self, "重新加载", callback=self.load_data, autoDefault=False) reload_button.setIcon(self.style().standardIcon( QStyle.SP_BrowserReload)) reload_button.setSizePolicy(Policy.Fixed, Policy.Fixed) layout.addWidget(reload_button, 0, 3) self.sheet_box = gui.hBox(None, addToLayout=False, margin=0) self.sheet_combo = gui.comboBox( None, self, "xls_sheet", callback=self.select_sheet, sendSelectedValue=True, ) self.sheet_combo.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed) self.sheet_label = QLabel() self.sheet_label.setText('Sheet') self.sheet_label.setSizePolicy(Policy.MinimumExpanding, Policy.Fixed) self.sheet_box.layout().addWidget(self.sheet_label, Qt.AlignLeft) self.sheet_box.layout().addWidget(self.sheet_combo, Qt.AlignVCenter) layout.addWidget(self.sheet_box, 2, 1) self.sheet_box.hide() rb_button = gui.appendRadioButton(vbox, "URL:", addToLayout=False) layout.addWidget(rb_button, 3, 0, Qt.AlignVCenter) self.url_combo = url_combo = QComboBox() url_model = NamedURLModel(self.sheet_names) url_model.wrap(self.recent_urls) url_combo.setLineEdit(LineEditSelectOnFocus()) url_combo.setModel(url_model) url_combo.setSizePolicy(Policy.Ignored, Policy.Fixed) url_combo.setEditable(True) url_combo.setInsertPolicy(url_combo.InsertAtTop) url_edit = url_combo.lineEdit() l, t, r, b = url_edit.getTextMargins() url_edit.setTextMargins(l + 5, t, r, b) layout.addWidget(url_combo, 3, 1, 3, 3) url_combo.activated.connect(self._url_set) # whit completer we set that combo box is case sensitive when # matching the history completer = QCompleter() completer.setCaseSensitivity(Qt.CaseSensitive) url_combo.setCompleter(completer) box = gui.vBox(self.controlArea, "信息") self.infolabel = gui.widgetLabel(box, '未加载数据。') self.warnings = gui.widgetLabel(box, '') box = gui.widgetBox(self.controlArea, "列(双击编辑)") self.domain_editor = DomainEditor(self) self.editor_model = self.domain_editor.model() box.layout().addWidget(self.domain_editor) box = gui.hBox(self.controlArea) gui.button(box, self, "浏览文档数据集", callback=lambda: self.browse_file(True), autoDefault=False) gui.rubber(box) gui.button(box, self, "重置", callback=self.reset_domain_edit) self.apply_button = gui.button(box, self, "应用", callback=self.apply_domain_edit) self.apply_button.setEnabled(False) self.apply_button.setFixedWidth(170) self.editor_model.dataChanged.connect( lambda: self.apply_button.setEnabled(True)) self.set_file_list() # Must not call open_file from within __init__. open_file # explicitly re-enters the event loop (by a progress bar) self.setAcceptDrops(True) if self.source == self.LOCAL_FILE: last_path = self.last_path() if last_path and os.path.exists(last_path) and \ os.path.getsize(last_path) > self.SIZE_LIMIT: self.Warning.file_too_big() return QTimer.singleShot(0, self.load_data)
def __init__(self): super().__init__() self.data = None self.results = None self.learners = [] self.headers = [] box = gui.vBox(self.controlArea, "Learners") self.learners_box = gui.listBox(box, self, "selected_learner", "learners", callback=self._learner_changed) box = gui.vBox(self.controlArea, "Show") gui.comboBox(box, self, "selected_quantity", items=self.quantities, callback=self._update) box = gui.vBox(self.controlArea, "Select") gui.button(box, self, "Select Correct", callback=self.select_correct, autoDefault=False) gui.button(box, self, "Select Misclassified", callback=self.select_wrong, autoDefault=False) gui.button(box, self, "Clear Selection", callback=self.select_none, autoDefault=False) self.outputbox = box = gui.vBox(self.controlArea, "Output") gui.checkBox(box, self, "append_predictions", "Predictions", callback=self._invalidate) gui.checkBox(box, self, "append_probabilities", "Probabilities", callback=self._invalidate) gui.auto_commit(self.controlArea, self, "autocommit", "Send Selected", "Send Automatically") grid = QGridLayout() self.tablemodel = QStandardItemModel(self) view = self.tableview = QTableView( editTriggers=QTableView.NoEditTriggers) view.setModel(self.tablemodel) view.horizontalHeader().hide() view.verticalHeader().hide() view.horizontalHeader().setMinimumSectionSize(60) view.selectionModel().selectionChanged.connect(self._invalidate) view.setShowGrid(False) view.setItemDelegate(BorderedItemDelegate(Qt.white)) view.clicked.connect(self.cell_clicked) grid.addWidget(view, 0, 0) self.mainArea.layout().addLayout(grid)
def __init__(self): super().__init__() self.old_purge_classes = True self.conditions = [] self.last_output_conditions = None self.data = None self.data_desc = self.match_desc = self.nonmatch_desc = None box = gui.vBox(self.controlArea, 'Conditions', stretch=100) self.cond_list = QTableWidget( box, showGrid=False, selectionMode=QTableWidget.NoSelection) box.layout().addWidget(self.cond_list) self.cond_list.setColumnCount(4) self.cond_list.setRowCount(0) self.cond_list.verticalHeader().hide() self.cond_list.horizontalHeader().hide() for i in range(3): self.cond_list.horizontalHeader().setSectionResizeMode(i, QHeaderView.Stretch) self.cond_list.horizontalHeader().resizeSection(3, 30) self.cond_list.viewport().setBackgroundRole(QPalette.Window) box2 = gui.hBox(box) gui.rubber(box2) self.add_button = gui.button( box2, self, "Add Condition", callback=self.add_row) self.add_all_button = gui.button( box2, self, "Add All Variables", callback=self.add_all) self.remove_all_button = gui.button( box2, self, "Remove All", callback=self.remove_all) gui.rubber(box2) boxes = gui.widgetBox(self.controlArea, orientation=QGridLayout()) layout = boxes.layout() layout.setColumnStretch(0, 1) layout.setColumnStretch(1, 1) box_data = gui.vBox(boxes, 'Data', addToLayout=False) self.data_in_variables = gui.widgetLabel(box_data, " ") self.data_out_rows = gui.widgetLabel(box_data, " ") layout.addWidget(box_data, 0, 0) box_setting = gui.vBox(boxes, 'Purging', addToLayout=False) self.cb_pa = gui.checkBox( box_setting, self, "purge_attributes", "Remove unused features", callback=self.conditions_changed) gui.separator(box_setting, height=1) self.cb_pc = gui.checkBox( box_setting, self, "purge_classes", "Remove unused classes", callback=self.conditions_changed) layout.addWidget(box_setting, 0, 1) self.report_button.setFixedWidth(120) gui.rubber(self.buttonsArea.layout()) layout.addWidget(self.buttonsArea, 1, 0) acbox = gui.auto_commit( None, self, "auto_commit", label="Send", orientation=Qt.Horizontal, checkbox_label="Send automatically") layout.addWidget(acbox, 1, 1) self.set_data(None) self.resize(600, 400)
def _setup_gui(self): grid = QGridLayout() box = gui.widgetBox(self.controlArea, "Scoring Methods", grid) yake_cb = gui.comboBox(self.controlArea, self, "yake_lang_index", items=YAKE_LANGUAGES, callback=self.__on_yake_lang_changed) rake_cb = gui.comboBox(self.controlArea, self, "rake_lang_index", items=RAKE_LANGUAGES, callback=self.__on_rake_lang_changed) embedding_cb = gui.comboBox(self.controlArea, self, "embedding_lang_index", items=EMBEDDING_LANGUAGES, callback=self.__on_emb_lang_changed) for i, (method_name, _) in enumerate(ScoringMethods.ITEMS): check_box = QCheckBox(method_name, self) check_box.setChecked(method_name in self.selected_scoring_methods) check_box.stateChanged.connect( lambda state, name=method_name: self. __on_scoring_method_state_changed(state, name)) box.layout().addWidget(check_box, i, 0) if method_name == ScoringMethods.YAKE: box.layout().addWidget(yake_cb, i, 1) if method_name == ScoringMethods.RAKE: box.layout().addWidget(rake_cb, i, 1) if method_name == ScoringMethods.EMBEDDING: box.layout().addWidget(embedding_cb, i, 1) box = gui.vBox(self.controlArea, "Aggregation") gui.comboBox(box, self, "agg_method", items=AggregationMethods.ITEMS, callback=self.update_scores) box = gui.vBox(self.buttonsArea, "Select Words") grid = QGridLayout() grid.setContentsMargins(0, 0, 0, 0) box.layout().addLayout(grid) self.__sel_method_buttons = QButtonGroup() for method, label in enumerate(SelectionMethods.ITEMS): button = QRadioButton(label) button.setChecked(method == self.sel_method) grid.addWidget(button, method, 0) self.__sel_method_buttons.addButton(button, method) self.__sel_method_buttons.buttonClicked[int].connect( self._set_selection_method) spin = gui.spin(box, self, "n_selected", 1, 999, addToLayout=False, callback=lambda: self._set_selection_method( SelectionMethods.N_BEST)) grid.addWidget(spin, 3, 1) gui.rubber(self.controlArea) gui.auto_send(self.buttonsArea, self, "auto_apply") self.__filter_line_edit = QLineEdit( textChanged=self.__on_filter_changed, placeholderText="Filter...") self.mainArea.layout().addWidget(self.__filter_line_edit) def select_manual(): self._set_selection_method(SelectionMethods.MANUAL) self.view = KeywordsTableView() self.view.pressedAny.connect(select_manual) self.view.horizontalHeader().setSortIndicator(*self.DEFAULT_SORTING) self.view.horizontalHeader().sectionClicked.connect( self.__on_horizontal_header_clicked) self.mainArea.layout().addWidget(self.view) proxy = SortFilterProxyModel() proxy.setFilterKeyColumn(0) proxy.setFilterCaseSensitivity(False) self.view.setModel(proxy) self.view.model().setSourceModel(self.model) self.view.selectionModel().selectionChanged.connect( self.__on_selection_changed)
def __init__(self): super().__init__() self.results = None self.classifier_names = [] self.perf_line = None self.colors = [] self._curve_data = {} self._plot_curves = {} self._rocch = None self._perf_line = None self._tooltip_cache = None box = gui.vBox(self.controlArea, "绘制") tbox = gui.vBox(box, "目标类别") tbox.setFlat(True) self.target_cb = gui.comboBox(tbox, self, "target_index", callback=self._on_target_changed, contentsLength=8) cbox = gui.vBox(box, "分类器") cbox.setFlat(True) self.classifiers_list_box = gui.listBox( cbox, self, "selected_classifiers", "classifier_names", selectionMode=QListView.MultiSelection, callback=self._on_classifiers_changed) abox = gui.vBox(box, "从折叠(Folds)合并ROC曲线") abox.setFlat(True) gui.comboBox(abox, self, "roc_averaging", items=["从折叠合并预测", "平均真阳性率", "阈值处的平均真阳性率和假阳性率", "显示单个曲线"], callback=self._replot) hbox = gui.vBox(box, "ROC凸包") hbox.setFlat(True) gui.checkBox(hbox, self, "display_convex_curve", "显示凸ROC曲线", callback=self._replot) gui.checkBox(hbox, self, "display_convex_hull", "显示ROC凸包", callback=self._replot) box = gui.vBox(self.controlArea, "分析(Analysis)") gui.checkBox(box, self, "display_def_threshold", "默认阈值(0.5)点", callback=self._on_display_def_threshold_changed) gui.checkBox(box, self, "display_perf_line", "显示性能行", callback=self._on_display_perf_line_changed) grid = QGridLayout() gui.indentedBox(box, orientation=grid) sp = gui.spin(box, self, "fp_cost", 1, 1000, 10, alignment=Qt.AlignRight, callback=self._on_display_perf_line_changed) grid.addWidget(QLabel("假阳性率损失:"), 0, 0) grid.addWidget(sp, 0, 1) sp = gui.spin(box, self, "fn_cost", 1, 1000, 10, alignment=Qt.AlignRight, callback=self._on_display_perf_line_changed) grid.addWidget(QLabel("假阴性率损失:")) grid.addWidget(sp, 1, 1) self.target_prior_sp = gui.spin(box, self, "target_prior", 1, 99, alignment=Qt.AlignRight, callback=self._on_target_prior_changed) self.target_prior_sp.setSuffix(" %") self.target_prior_sp.addAction(QAction("Auto", sp)) grid.addWidget(QLabel("目标类先验概率:")) grid.addWidget(self.target_prior_sp, 2, 1) self.plotview = pg.GraphicsView(background="w") self.plotview.setFrameStyle(QFrame.StyledPanel) self.plotview.scene().sigMouseMoved.connect(self._on_mouse_moved) self.plot = pg.PlotItem(enableMenu=False) self.plot.setMouseEnabled(False, False) self.plot.hideButtons() pen = QPen(self.palette().color(QPalette.Text)) tickfont = QFont(self.font()) tickfont.setPixelSize(max(int(tickfont.pixelSize() * 2 // 3), 11)) axis = self.plot.getAxis("bottom") axis.setTickFont(tickfont) axis.setPen(pen) axis.setLabel("假阳性率损失 (1-特异度)") axis = self.plot.getAxis("left") axis.setTickFont(tickfont) axis.setPen(pen) axis.setLabel("真阳性率 (灵敏度)") self.plot.showGrid(True, True, alpha=0.1) self.plot.setRange(xRange=(0.0, 1.0), yRange=(0.0, 1.0), padding=0.05) self.plotview.setCentralItem(self.plot) self.mainArea.layout().addWidget(self.plotview)
def create_gui(self): """ create the GUI """ gui.label(self.controlArea, self, "All files in the selected directory and subsequent subdirectories will be included in the conversion," "\nand output in a single .tsv file") gui.separator(self.controlArea, height=16) statusBox = gui.widgetBox(self.controlArea, "Status") inputBox = gui.vBox(self.controlArea, "Input") outputBox = gui.widgetBox(self.controlArea, "Output") self.statusLabel = gui.label(statusBox, self, "Select directories, and press process to start") # input GUI layout = QGridLayout() gui.widgetBox(inputBox, margin=0, orientation=layout) label = QLabel("Directory:") lineEdit = gui.lineEdit(None, self, "input_directory", orientation=Qt.Horizontal, tooltip="Tooltip", placeholderText="input directory") layout.addWidget(label, 0, 1) layout.addWidget(lineEdit, 0, 2) if found_tkinter: button = gui.button(None, self, "Browse", callback=self.browse_folder_input) layout.addWidget(button, 0, 3) checkbox = gui.checkBox(None, self, 'enable_filter', "Enable filter") layout.addWidget(checkbox, 2, 1) layout.addWidget(QLabel("Only include files from the subdirectories:"), 2, 2) filter = gui.lineEdit(None, self, "filter_directories", orientation=Qt.AlignLeft, tooltip="Tooltip", placeholderText="filter directories") layout.addWidget(filter, 2, 3) # output GUI layout2 = QGridLayout() gui.widgetBox(outputBox, margin=0, orientation=layout2) label2 = QLabel("Output directory:") lineEdit2 = gui.lineEdit(None, self, "output_directory", orientation=Qt.AlignLeft, tooltip="Tooltip", placeholderText="input directory") label3 = QLabel("Output file:") lineEdit3 = gui.lineEdit(None, self, "output_file", orientation=Qt.Horizontal, tooltip="Tooltip", placeholderText="input directory") layout2.addWidget(label2, 0, 1) layout2.addWidget(lineEdit2, 0, 2) layout2.addWidget(label3, 1, 1) layout2.addWidget(lineEdit3, 1, 2) if found_tkinter: button2 = gui.button(None, self, "Browse", callback=self.browse_folder_output) layout2.addWidget(button2, 0, 3) # Process button layout3 = QGridLayout() gui.widgetBox(self.controlArea, margin=0, orientation=layout3) btn1 = gui.button(None, self, "Process", callback=self.process) btn2 = gui.button(None, self, "Output file > corpus", callback=self.output_corpus) layout3.addWidget(btn1, 0, 0) layout3.addWidget(btn2, 0, 1)
def __init__(self): super().__init__() self.instances = None self.domain = None self.data = None self.classifier = None self.align = OWNomogram.ALIGN_ZERO self.log_odds_ratios = [] self.log_reg_coeffs = [] self.log_reg_coeffs_orig = [] self.log_reg_cont_data_extremes = [] self.p = None self.b0 = None self.points = [] self.feature_items = {} self.feature_marker_values = [] self.scale_marker_values = lambda x: x self.nomogram_main = None self.vertical_line = None self.hidden_vertical_line = None self.old_target_class_index = self.target_class_index self.repaint = False # GUI box = gui.vBox(self.controlArea, "Target class") self.class_combo = gui.comboBox(box, self, "target_class_index", callback=self._class_combo_changed, contentsLength=12) self.norm_check = gui.checkBox( box, self, "normalize_probabilities", "Normalize probabilities", hidden=True, callback=self.update_scene, tooltip="For multiclass data 1 vs. all probabilities do not" " sum to 1 and therefore could be normalized.") self.scale_radio = gui.radioButtons(self.controlArea, self, "scale", ["Point scale", "Log odds ratios"], box="Scale", callback=self.update_scene) box = gui.vBox(self.controlArea, "Display features") grid = QGridLayout() radio_group = gui.radioButtonsInBox(box, self, "display_index", [], orientation=grid, callback=self.update_scene) radio_all = gui.appendRadioButton(radio_group, "All", addToLayout=False) radio_best = gui.appendRadioButton(radio_group, "Best ranked:", addToLayout=False) spin_box = gui.hBox(None, margin=0) self.n_spin = gui.spin(spin_box, self, "n_attributes", 1, self.MAX_N_ATTRS, label=" ", controlWidth=60, callback=self._n_spin_changed) grid.addWidget(radio_all, 1, 1) grid.addWidget(radio_best, 2, 1) grid.addWidget(spin_box, 2, 2) self.sort_combo = gui.comboBox(box, self, "sort_index", label="Rank by:", items=SortBy.items(), orientation=Qt.Horizontal, callback=self.update_scene) self.cont_feature_dim_combo = gui.comboBox( box, self, "cont_feature_dim_index", label="Numeric features: ", items=["1D projection", "2D curve"], orientation=Qt.Horizontal, callback=self.update_scene) gui.rubber(self.controlArea) class _GraphicsView(QGraphicsView): def __init__(self, scene, parent, **kwargs): for k, v in dict( verticalScrollBarPolicy=Qt.ScrollBarAlwaysOff, horizontalScrollBarPolicy=Qt.ScrollBarAlwaysOff, viewportUpdateMode=QGraphicsView. BoundingRectViewportUpdate, renderHints=(QPainter.Antialiasing | QPainter.TextAntialiasing | QPainter.SmoothPixmapTransform), alignment=(Qt.AlignTop | Qt.AlignLeft), sizePolicy=QSizePolicy( QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)).items(): kwargs.setdefault(k, v) super().__init__(scene, parent, **kwargs) class GraphicsView(_GraphicsView): def __init__(self, scene, parent): super().__init__( scene, parent, verticalScrollBarPolicy=Qt.ScrollBarAlwaysOn, styleSheet='QGraphicsView {background: white}') self.viewport().setMinimumWidth( 300) # XXX: This prevents some tests failing self._is_resizing = False w = self def resizeEvent(self, resizeEvent): # Recompute main scene on window width change if resizeEvent.size().width() != resizeEvent.oldSize().width(): self._is_resizing = True self.w.update_scene() self._is_resizing = False return super().resizeEvent(resizeEvent) def is_resizing(self): return self._is_resizing def sizeHint(self): return QSize(400, 200) class FixedSizeGraphicsView(_GraphicsView): def __init__(self, scene, parent): super().__init__(scene, parent, sizePolicy=QSizePolicy( QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)) def sizeHint(self): return QSize(400, 85) scene = self.scene = QGraphicsScene(self) top_view = self.top_view = FixedSizeGraphicsView(scene, self) mid_view = self.view = GraphicsView(scene, self) bottom_view = self.bottom_view = FixedSizeGraphicsView(scene, self) for view in (top_view, mid_view, bottom_view): self.mainArea.layout().addWidget(view)
def __init__(self): super().__init__() self.results = None self.classifier_names = [] self.perf_line = None self.colors = [] self._curve_data = {} self._plot_curves = {} self._rocch = None self._perf_line = None self._tooltip_cache = None box = gui.vBox(self.controlArea, "Plot") tbox = gui.vBox(box, "Target Class") tbox.setFlat(True) self.target_cb = gui.comboBox( tbox, self, "target_index", callback=self._on_target_changed, contentsLength=8) cbox = gui.vBox(box, "Classifiers") cbox.setFlat(True) self.classifiers_list_box = gui.listBox( cbox, self, "selected_classifiers", "classifier_names", selectionMode=QListView.MultiSelection, callback=self._on_classifiers_changed) abox = gui.vBox(box, "Combine ROC Curves From Folds") abox.setFlat(True) gui.comboBox(abox, self, "roc_averaging", items=["Merge Predictions from Folds", "Mean TP Rate", "Mean TP and FP at Threshold", "Show Individual Curves"], callback=self._replot) hbox = gui.vBox(box, "ROC Convex Hull") hbox.setFlat(True) gui.checkBox(hbox, self, "display_convex_curve", "Show convex ROC curves", callback=self._replot) gui.checkBox(hbox, self, "display_convex_hull", "Show ROC convex hull", callback=self._replot) box = gui.vBox(self.controlArea, "Analysis") gui.checkBox(box, self, "display_def_threshold", "Default threshold (0.5) point", callback=self._on_display_def_threshold_changed) gui.checkBox(box, self, "display_perf_line", "Show performance line", callback=self._on_display_perf_line_changed) grid = QGridLayout() gui.indentedBox(box, orientation=grid) sp = gui.spin(box, self, "fp_cost", 1, 1000, 10, callback=self._on_display_perf_line_changed) grid.addWidget(QLabel("FP Cost:"), 0, 0) grid.addWidget(sp, 0, 1) sp = gui.spin(box, self, "fn_cost", 1, 1000, 10, callback=self._on_display_perf_line_changed) grid.addWidget(QLabel("FN Cost:")) grid.addWidget(sp, 1, 1) sp = gui.spin(box, self, "target_prior", 1, 99, callback=self._on_display_perf_line_changed) sp.setSuffix("%") sp.addAction(QAction("Auto", sp)) grid.addWidget(QLabel("Prior target class probability:")) grid.addWidget(sp, 2, 1) self.plotview = pg.GraphicsView(background="w") self.plotview.setFrameStyle(QFrame.StyledPanel) self.plotview.scene().sigMouseMoved.connect(self._on_mouse_moved) self.plot = pg.PlotItem(enableMenu=False) self.plot.setMouseEnabled(False, False) self.plot.hideButtons() pen = QPen(self.palette().color(QPalette.Text)) tickfont = QFont(self.font()) tickfont.setPixelSize(max(int(tickfont.pixelSize() * 2 // 3), 11)) axis = self.plot.getAxis("bottom") axis.setTickFont(tickfont) axis.setPen(pen) axis.setLabel("FP Rate (1-Specificity)") axis = self.plot.getAxis("left") axis.setTickFont(tickfont) axis.setPen(pen) axis.setLabel("TP Rate (Sensitivity)") self.plot.showGrid(True, True, alpha=0.1) self.plot.setRange(xRange=(0.0, 1.0), yRange=(0.0, 1.0), padding=0.05) self.plotview.setCentralItem(self.plot) self.mainArea.layout().addWidget(self.plotview)
def _add_type_box(self): # this is part of init, pylint: disable=attribute-defined-outside-init form = QGridLayout() self.type_box = box = gui.radioButtonsInBox(self.controlArea, self, "svm_type", [], box="SVM Type", orientation=form, callback=self._update_type) self.epsilon_radio = gui.appendRadioButton(box, "SVM", addToLayout=False) self.c_spin = gui.doubleSpin(box, self, "C", 0.1, 512.0, 0.1, decimals=2, alignment=Qt.AlignRight, addToLayout=False, callback=self.settings_changed) self.epsilon_spin = gui.doubleSpin(box, self, "epsilon", 0.1, 512.0, 0.1, decimals=2, alignment=Qt.AlignRight, addToLayout=False, callback=self.settings_changed) form.addWidget(self.epsilon_radio, 0, 0, Qt.AlignLeft) form.addWidget(QLabel("Cost (C):"), 0, 1, Qt.AlignRight) form.addWidget(self.c_spin, 0, 2) form.addWidget(QLabel("Regression loss epsilon (ε):"), 1, 1, Qt.AlignRight) form.addWidget(self.epsilon_spin, 1, 2) self.nu_radio = gui.appendRadioButton(box, "ν-SVM", addToLayout=False) self.nu_C_spin = gui.doubleSpin(box, self, "nu_C", 0.1, 512.0, 0.1, decimals=2, alignment=Qt.AlignRight, addToLayout=False, callback=self.settings_changed) self.nu_spin = gui.doubleSpin(box, self, "nu", 0.05, 1.0, 0.05, decimals=2, alignment=Qt.AlignRight, addToLayout=False, callback=self.settings_changed) form.addWidget(self.nu_radio, 2, 0, Qt.AlignLeft) form.addWidget(QLabel("Regression cost (C):"), 2, 1, Qt.AlignRight) form.addWidget(self.nu_C_spin, 2, 2) form.addWidget(QLabel("Complexity bound (ν):"), 3, 1, Qt.AlignRight) form.addWidget(self.nu_spin, 3, 2) # Correctly enable/disable the appropriate boxes self._update_type()