def group_box(title): box = QtWidgets.QGroupBox(title) box.setFlat(True) lay = QtWidgets.QVBoxLayout() lay.setContentsMargins(0, 0, 0, 0) box.setLayout(lay) return box
def __init__(self, parent: OWWidget = None, title=None, column_count=2, column_headers=["x", "y"]): QtWidgets.QWidget.__init__(self, parent) OWComponent.__init__(self, parent) # GUI self.table = gui.table(self, 0, column_count) # selection multiline and row self.table.setSelectionMode( QtWidgets.QAbstractItemView.SelectionMode.MultiSelection) self.table.setSelectionBehavior( QtWidgets.QAbstractItemView.SelectionBehavior.SelectRows) # set headers labels self.table.setHorizontalHeaderLabels(column_headers) # columns shapes self.table.horizontalHeader().setResizeMode( QtWidgets.QHeaderView.Stretch) vbox = QtWidgets.QVBoxLayout() if title is not None: vbox.addWidget(gui.label(self, parent, title)) vbox.addWidget(self.table) self.setLayout(vbox)
def __init__(self): super().__init__() self.imgs = {} self.selection = None self.result = None # GUI box = gui.widgetBox(self.controlArea, "Info", margin=3) self.infoa = gui.widgetLabel( box, 'No data on msk yet, waiting to get something.') gui.checkBox(self.buttonsArea, self, 'automatic_propagation', 'Automatic propagation', callback=self.commit) box2 = gui.widgetBox(self.mainArea, "Display") hb = gui.hBox(box2) self.display = SFigure(self) hb.layout().addWidget(self.display) self.lv_images = QtWidgets.QListWidget(self) self.lv_images.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self.lv_images.itemClicked.connect(self.on_selection) hb.layout().addWidget(self.lv_images)
def __init__(self): super().__init__() self.imgs = None self.result = None self.saved_config = [] # GUI self.infoa = gui.widgetLabel(self.box_info, 'No data yet, waiting to get something.') gui.checkBox(self.controlArea, self, 'auto_resize', 'Apply automatic settings', callback=self.do_auto_conf) self.box_custom = gui.widgetBox(self.controlArea, "Custom") self.info_shape = gui.widgetLabel(self.box_custom, 'Original shape: ') hl0 = gui.hBox(self.box_custom) gui.label(hl0, self, "Desired shape:") self.sp_w = QtWidgets.QSpinBox( self ) # gui.spin(hl0, self, 'desired_width', minv=1, maxv=5000, step=1) self.sp_h = QtWidgets.QSpinBox( self ) #self.sp_h = gui.spin(hl0, self, 'desired_height', minv=1, maxv=5000, step=1) self.sp_w.setMinimum(1) self.sp_h.setMinimum(1) #self.sp_w.valueChanged.connect(self.on_value_change) #self.sp_h.valueChanged.connect(self.on_value_change) hl0.layout().addWidget(self.sp_h) hl0.layout().addWidget(self.sp_w) gui.radioButtons(self.box_custom, self, 'selected_resize_type', ["Crop top left", "Crop center", "Resize"]) gui.toolButton(self.box_custom, self, "Apply and save current settings", callback=self.do_save_conf) gui.checkBox(self.buttonsArea, self, 'allow_propagation', 'Allow propagation', callback=self.commit)
def action(self, values): self.control.clear() if values: for value in values: if isinstance(value, tuple): text, icon = value if isinstance(icon, int): item = QtWidgets.QListWidgetItem(attributeIconDict[icon], text) else: item = QtWidgets.QListWidgetItem(icon, text) elif isinstance(value, Variable): item = QtWidgets.QListWidgetItem(*attributeItem(value)) else: item = QtWidgets.QListWidgetItem(value) item.setData(Qt.UserRole, value) self.control.addItem(item)
def main(): # pragma: no cover """Helper for running the widget without Orange.""" logging.basicConfig(level=logging.DEBUG) signal.signal(signal.SIGINT, signal.SIG_DFL) app = QtWidgets.QApplication(sys.argv) indicators_widget = OWWorldBankIndicators() indicators_widget.show() app.exec_() indicators_widget.saveSettings()
def initUIParent(self): parent = self.parent() if parent is None: return layout = parent.layout() if layout is None: layout = QtWidgets.QVBoxLayout() parent.setLayout(layout) layout.addWidget(self)
def initUI(self, margin=0, spacing=4): self.initUIParent() layout = QtWidgets.QFormLayout() layout.setContentsMargins(margin, margin, margin, margin) layout.setSpacing(spacing) policy = QtWidgets.QFormLayout.AllNonFixedFieldsGrow layout.setFieldGrowthPolicy(policy) #layout.setFormAlignment(Qt.AlignHCenter | Qt.AlignTop) layout.setLabelAlignment(Qt.AlignLeft) self.setLayout(layout)
def commit(self): """Send the outputs""" r = [] i = 0 for img in self.imgs: mean = np.mean(img) standart_deviation = np.std(img) variance = np.var(img) r.append([mean, standart_deviation, variance]) self.tw_results.setCellWidget( i, 0, QtWidgets.QLabel("{:.5f}".format(mean))) self.tw_results.setCellWidget( i, 1, QtWidgets.QLabel("{:.5f}".format(standart_deviation))) self.tw_results.setCellWidget( i, 2, QtWidgets.QLabel("{:.5f}".format(variance))) i += 1 r = np.array(r).T self.result = Orange.data.table.Table.from_numpy(None, r) self.Outputs.result.send(self.result)
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.__model = None self.__selectionMode = QtWidgets.QListView.ExtendedSelection self.__currentIndex = -1 self.__selections = {} layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) def group_box(title): box = QtWidgets.QGroupBox(title) box.setFlat(True) lay = QtWidgets.QVBoxLayout() lay.setContentsMargins(0, 0, 0, 0) box.setLayout(lay) return box self.labels_combo = QtWidgets.QComboBox() self.values_view = QtWidgets.QListView( selectionMode=self.__selectionMode) self.labels_combo.currentIndexChanged.connect( self.__onCurrentIndexChanged) l_box = group_box(self.tr("Label")) v_box = group_box(self.tr("Values")) l_box.layout().addWidget(self.labels_combo) v_box.layout().addWidget(self.values_view) layout.addWidget(l_box) layout.addWidget(v_box) self.setLayout(layout) self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
def contextMenuEvent(self, event): """ """ selection = self.table.selectionModel().selectedRows() #self.try_parse() contextMenu = QtWidgets.QMenu(self) addAct = contextMenu.addAction("Add a row") addAct.triggered.connect(self.add_row) if len(selection) > 0: removeAct = contextMenu.addAction("Remove selection") removeAct.triggered.connect(self.remove_selection) action = contextMenu.exec_(self.mapToGlobal(event.pos()))
def __init__(self): QtWidgets.QMainWindow.__init__(self) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle("application main window") self.main_widget = QtWidgets.QWidget(self) vbox = QtWidgets.QVBoxLayout(self.main_widget) self.canvas = MyMplCanvas(self.main_widget, width=5, height=4, dpi=100) # attention### vbox.addWidget(self.canvas) hbox = QtWidgets.QHBoxLayout(self.main_widget) self.start_button = QPushButton("start", self) self.stop_button = QPushButton("stop", self) self.exit_button = QPushButton("exit", self) self.start_button.clicked.connect(self.on_start) self.stop_button.clicked.connect(self.on_stop) self.exit_button.clicked.connect(self.on_exit) hbox.addWidget(self.start_button) hbox.addWidget(self.stop_button) hbox.addWidget(self.exit_button) vbox.addLayout(hbox) self.setLayout(vbox) self.main_widget.setFocus() self.setCentralWidget(self.main_widget) global n_drops global scat global rain_drops rain_drops = np.zeros(n_drops, dtype=[('position', float, 2)]) self.scat = self.canvas.axes.scatter(rain_drops['position'][:, 0], rain_drops['position'][:, 1], s=10, lw=0.5)
def addSetting(self, owner, name, label=None, updateCallback=None): """ :param owner: setting owner :type owner: OWWidget or OWComponent :param name: setting name :type name: str :param label: setting label :type label: str or None """ # Label if label is None: label = '{}:'.format(name) # Field value = getdeepattr(owner, name) if isinstance(value, str): field = QtWidgets.QLineEdit() field.setText(value) if updateCallback: field.textChanged.connect(updateCallback) elif isinstance(value, numbers.Number): if isinstance(value, numbers.Integral): field = QtWidgets.QSpinBox() ma = sys.maxsize field.setRange(-ma - 1, ma) else: field = QtWidgets.QDoubleSpinBox() field.setValue(value) if updateCallback: field.valueChanged.connect(updateCallback) else: raise ValueError('{} does not have a Qt widget'.format( repr(type(value).__qualname__))) # Append policy = QtWidgets.QSizePolicy.Expanding field.setSizePolicy(policy, policy) self.layout().addRow(label, field) return field
def __init__(self): super().__init__() self.result = None self.imgs = None # GUI box = gui.widgetBox(self.controlArea, "Info") self.infoa = gui.widgetLabel(box, 'No data yet, waiting to get something.') self.tw_results = QtWidgets.QTableWidget(self) self.tw_results.setColumnCount(3) self.tw_results.setHorizontalHeaderLabels( ["mean", "deviation", "variance"]) box.layout().addWidget(self.tw_results)
def __init__(self): super().__init__() self.imgs = None self.result = None #GUI box2 = gui.widgetBox(self.controlArea, "Display") hb = gui.hBox(box2) self.display = SFigure(self) hb.layout().addWidget(self.display) self.lv_images = QtWidgets.QListWidget(self) self.lv_images.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self.lv_images.itemClicked.connect(self.on_selection) hb.layout().addWidget(self.lv_images)
def __init__(self): super().__init__() self.imgs = None self.msk = None # GUI self.infoa = gui.widgetLabel(self.box_info, 'No data yet, waiting to get something.') optionsBox = gui.widgetBox(self.controlArea, "Mask center") hl0 = gui.hBox(optionsBox) gui.label(hl0, self, 'shift x') gui.spin(hl0, self, 'center_x', minv=0, maxv=20, step=1) hl1 = gui.hBox(optionsBox) gui.label(hl1, self, 'shift y') gui.spin(hl1, self, 'center_y', minv=0, maxv=20, step=1) spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) optionsBox.layout().addItem(spacerItem)
def _fill_values(self, data, parent=None): if not parent: parent = self tristate = QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsTristate twostate = QtCore.Qt.ItemIsUserCheckable defaults = self._selection_list for key, value in data.items(): name = countries.RENAME_MAP.get(key, value.get("name", key)) display_key = "" if name == key else key item = QtWidgets.QTreeWidgetItem(parent, [name, display_key]) item.key = value if isinstance(value, str) else key defaults[item.key] = defaults.get(item.key, self._default_select) item.setCheckState(0, defaults[item.key]) if isinstance(value, collections.OrderedDict): item.setFlags(item.flags() | tristate) self._fill_values(value, item) else: item.setFlags(item.flags() | twostate)
def _add_type_box(self): form = QtWidgets.QGridLayout() self.type_box = box = gui.radioButtonsInBox( self.controlArea, self, "svmtype", [], box="SVM Type", orientation=form, callback=self.settings_changed) self.c_radio = gui.appendRadioButton(box, "C-SVM", addToLayout=False) self.nu_radio = gui.appendRadioButton(box, "ν-SVM", addToLayout=False) self.c_spin = gui.doubleSpin(box, self, "C", 1e-3, 1000.0, 0.1, decimals=3, alignment=Qt.AlignRight, controlWidth=80, 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, controlWidth=80, addToLayout=False, callback=self.settings_changed) form.addWidget(self.c_radio, 0, 0, Qt.AlignLeft) form.addWidget(QLabel("Cost (C):"), 0, 1, Qt.AlignRight) form.addWidget(self.c_spin, 0, 2) form.addWidget(self.nu_radio, 1, 0, Qt.AlignLeft) form.addWidget(QLabel("Complexity (ν):"), 1, 1, Qt.AlignRight) form.addWidget(self.nu_spin, 1, 2)
def create_coef_table(classifier): i = classifier.intercept c = classifier.coefficients if c.shape[0] > 2: values = [ classifier.domain.class_var.values[int(i)] for i in classifier.used_vals[0] ] else: values = [ classifier.domain.class_var.values[int(classifier.used_vals[0][1])] ] domain = Domain( [ContinuousVariable(value, number_of_decimals=7) for value in values], metas=[StringVariable("name")]) coefs = np.vstack((i.reshape(1, len(i)), c.T)) names = [[attr.name] for attr in classifier.domain.attributes] names = [["intercept"]] + names names = np.array(names, dtype=object) coef_table = Table.from_numpy(domain, X=coefs, metas=names) coef_table.name = "coefficients" return coef_table if __name__ == "__main__": app = QtWidgets.QApplication([]) w = OWLogisticRegression() w.set_data(Table("zoo")) w.show() app.exec_()
self.class_treatment = class_treatment def __call__(self, data): treat = self.multinomial_treatment if isinstance(data, Orange.data.Domain): domain, data = data, None else: domain = data.domain if (treat == Continuize.ReportError and any(var.is_discrete and len(var.values) > 2 for var in domain)): raise ValueError("Domain has multinomial attributes") newdomain = continuize_domain(data or domain, self.multinomial_treatment, self.continuous_treatment, self.class_treatment, self.zero_based) return newdomain if __name__ == "__main__": import sys a = QtWidgets.QApplication(sys.argv) ow = OWContinuize() data = Table("lenses") ow.setData(data) ow.show() a.exec_() ow.saveSettings()
def _init_layout(self): """Initialize widget layout.""" # Control area info_box = gui.widgetBox(self.controlArea, "Info", addSpace=True) self._info_label = gui.widgetLabel(info_box, "Initializing\n\n") indicator_filter_box = gui.widgetBox(self.controlArea, "Indicators", addSpace=True) gui.radioButtonsInBox(indicator_filter_box, self, "indicator_list_selection", self.indicator_list_map.values(), "Rows", callback=self.indicator_list_selected) self.indicator_list_selection = 2 gui.separator(indicator_filter_box) output_box = gui.widgetBox(self.controlArea, "Output", addSpace=True) gui.radioButtonsInBox(output_box, self, "output_type", ["Countries", "Time Series"], "Rows", callback=self.output_type_selected) self.output_type = 0 gui.separator(output_box) # pylint: disable=duplicate-code gui.auto_commit(self.controlArea, self, "auto_commit", "Commit", box="Commit") gui.rubber(self.controlArea) # Main area gui.widgetLabel(self.mainArea, "Filter") self.filter_text = QtWidgets.QLineEdit( textChanged=self.filter_indicator_list) self.completer = QtWidgets.QCompleter( caseSensitivity=QtCore.Qt.CaseInsensitive) self.completer.setModel(QtCore.QStringListModel(self)) self.filter_text.setCompleter(self.completer) spliter_v = QtWidgets.QSplitter(QtCore.Qt.Vertical, self.mainArea) self.mainArea.layout().addWidget(self.filter_text) self.mainArea.layout().addWidget(spliter_v) self.indicator_widget = IndicatorsTreeView(spliter_v, main_widget=self) splitter_h = QtWidgets.QSplitter(QtCore.Qt.Horizontal, spliter_v) self.description_box = gui.widgetBox(splitter_h, "Description") self.indicator_description = QtWidgets.QTextEdit() self.indicator_description.setReadOnly(True) self.description_box.layout().addWidget(self.indicator_description) box = gui.widgetBox(splitter_h, "Countries and Regions") self.country_tree = CountryTreeWidget( splitter_h, self.country_selection, default_select=True, default_colapse=True, ) box.layout().addWidget(self.country_tree) self.country_tree.set_data(countries.get_countries_regions_dict()) self.splitters = spliter_v, splitter_h for splitter, setting in zip(self.splitters, self.splitterSettings): splitter.splitterMoved.connect(self._splitter_moved) splitter.restoreState(setting) # self.resize(2000, 600) # why does this not work self.progressBarInit()