class PCA(BaseEditor): def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.n_components = 10 form = QFormLayout() self.cspin = QSpinBox(minimum=1, value=self.n_components) self.cspin.valueChanged[int].connect(self.setC) self.cspin.editingFinished.connect(self.edited) form.addRow("Components:", self.cspin) self.layout().addLayout(form) def setParameters(self, params): self.n_components = params.get("n_components", 10) def parameters(self): return {"n_components": self.n_components} def setC(self, n_components): if self.n_components != n_components: self.n_components = n_components self.cspin.setValue(n_components) self.changed.emit() @staticmethod def createinstance(params): n_components = params.get("n_components", 10) return ProjectPCA(n_components=n_components) def __repr__(self): return "Components: {}".format(self.cspin.value())
class RemoveSparseEditor(BaseEditor): def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.sparse_thresh = 5 form = QFormLayout() self.cspin = QSpinBox(minimum=1, maximum=100, value=self.sparse_thresh) self.cspin.valueChanged[int].connect(self.setThresh) self.cspin.editingFinished.connect(self.edited) form.addRow("Min % of nonzero values:", self.cspin) self.layout().addLayout(form) def setThresh(self, thresh): if self.sparse_thresh != thresh: self.sparse_thresh = thresh self.cspin.setValue(thresh) self.changed.emit() def parameters(self): return {'sparse_thresh': self.sparse_thresh} def setParameters(self, params): self.setThresh(params.get('sparse_thresh', 5)) @staticmethod def createinstance(params): params = dict(params) threshold = params.pop('sparse_thresh', 5) return RemoveSparse(threshold=threshold / 100)
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self._lower_bound = self.DEFAULT_LOWER_BOUND self._upper_bound = self.DEFAULT_UPPER_BOUND self.setLayout(QVBoxLayout()) box = QGroupBox(title="Clipping", flat=True) form = QFormLayout() self.lower_check = QCheckBox("Lower Bound: ") self.lower_check.clicked.connect(self.edited) self.lower_spin = QSpinBox(minimum=-99, maximum=0, value=self._lower_bound) self.lower_spin.valueChanged[int].connect(self._set_lower_bound) self.lower_spin.editingFinished.connect(self.edited) self.upper_check = QCheckBox("Upper Bound: ") self.upper_check.clicked.connect(self.edited) self.upper_spin = QSpinBox(value=self._upper_bound) self.upper_spin.valueChanged[int].connect(self._set_upper_bound) self.upper_spin.editingFinished.connect(self.edited) form.addRow(self.lower_check, self.lower_spin) form.addRow(self.upper_check, self.upper_spin) box.setLayout(form) self.layout().addWidget(box)
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.sparse_thresh = 5 form = QFormLayout() self.cspin = QSpinBox(minimum=1, maximum=100, value=self.sparse_thresh) self.cspin.valueChanged[int].connect(self.setThresh) self.cspin.editingFinished.connect(self.edited) form.addRow("Min % of nonzero values:", self.cspin) self.layout().addLayout(form)
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self._n_genes = self.DEFAULT_N_GENES form = QFormLayout() self.n_genes_spin = QSpinBox(minimum=1, maximum=10**6, value=self._n_genes) self.n_genes_spin.valueChanged[int].connect(self._set_n_genes) self.n_genes_spin.editingFinished.connect(self.edited) form.addRow("Number of genes:", self.n_genes_spin) self.layout().addLayout(form)
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.n_components = 10 form = QFormLayout() self.cspin = QSpinBox(minimum=1, value=self.n_components) self.cspin.valueChanged[int].connect(self.setC) self.cspin.editingFinished.connect(self.edited) form.addRow("Components:", self.cspin) self.layout().addLayout(form)
class CUR(BaseEditor): def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.rank = 10 self.max_error = 1 form = QFormLayout() self.rspin = QSpinBox(minimum=2, value=self.rank) self.rspin.valueChanged[int].connect(self.setR) self.rspin.editingFinished.connect(self.edited) self.espin = QDoubleSpinBox( minimum=0.1, maximum=100.0, singleStep=0.1, value=self.max_error) self.espin.valueChanged[float].connect(self.setE) self.espin.editingFinished.connect(self.edited) form.addRow("Rank:", self.rspin) form.addRow("Relative error:", self.espin) self.layout().addLayout(form) def setParameters(self, params): self.setR(params.get("rank", 10)) self.setE(params.get("max_error", 1)) def parameters(self): return {"rank": self.rank, "max_error": self.max_error} def setR(self, rank): if self.rank != rank: self.rank = rank self.rspin.setValue(rank) self.changed.emit() def setE(self, max_error): if self.max_error != max_error: self.max_error = max_error self.espin.setValue(max_error) self.changed.emit() @staticmethod def createinstance(params): rank = params.get("rank", 10) max_error = params.get("max_error", 1) return ProjectCUR(rank=rank, max_error=max_error) def __repr__(self): return "Rank: {}, Relative error: {}".format(self.rspin.value(), self.espin.value())
class CUR(BaseEditor): def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.rank = 10 self.max_error = 1 form = QFormLayout() self.rspin = QSpinBox(minimum=2, maximum=1000000, value=self.rank) self.rspin.valueChanged[int].connect(self.setR) self.rspin.editingFinished.connect(self.edited) self.espin = QDoubleSpinBox(minimum=0.1, maximum=100.0, singleStep=0.1, value=self.max_error) self.espin.valueChanged[float].connect(self.setE) self.espin.editingFinished.connect(self.edited) form.addRow("Rank:", self.rspin) form.addRow("Relative error:", self.espin) self.layout().addLayout(form) def setParameters(self, params): self.setR(params.get("rank", 10)) self.setE(params.get("max_error", 1)) def parameters(self): return {"rank": self.rank, "max_error": self.max_error} def setR(self, rank): if self.rank != rank: self.rank = rank self.rspin.setValue(rank) self.changed.emit() def setE(self, max_error): if self.max_error != max_error: self.max_error = max_error self.espin.setValue(max_error) self.changed.emit() @staticmethod def createinstance(params): rank = params.get("rank", 10) max_error = params.get("max_error", 1) return ProjectCUR(rank=rank, max_error=max_error) def __repr__(self): return "Rank: {}, Relative error: {}".format(self.rspin.value(), self.espin.value())
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.fixedThresh = 50 self.percThresh = 5 self.useFixedThreshold = False self.filter0 = True self.setLayout(QVBoxLayout()) self.layout().addWidget(QLabel("Remove features with too many")) options = ["missing values", "zeros"] self.filter_buttons = QButtonGroup(exclusive=True) self.filter_buttons.buttonClicked.connect(self.filterByClicked) for idx, option, in enumerate(options): btn = QRadioButton(self, text=option, checked=idx == 0) self.filter_buttons.addButton(btn, id=idx) self.layout().addWidget(btn) self.layout().addSpacing(20) filter_settings = QGroupBox(title='Threshold:', flat=True) filter_settings.setLayout(QFormLayout()) self.settings_buttons = QButtonGroup(exclusive=True) self.settings_buttons.buttonClicked.connect(self.filterSettingsClicked) btn_perc = QRadioButton(self, text='Percentage', checked=not self.useFixedThreshold) self.settings_buttons.addButton(btn_perc, id=0) self.percSpin = QSpinBox(minimum=0, maximum=100, value=self.percThresh, enabled=not self.useFixedThreshold) self.percSpin.valueChanged[int].connect(self.setPercThresh) self.percSpin.editingFinished.connect(self.edited) btn_fix = QRadioButton(self, text='Fixed', checked=self.useFixedThreshold) self.settings_buttons.addButton(btn_fix, id=1) self.fixedSpin = QSpinBox(minimum=0, maximum=1000000, value=self.fixedThresh, enabled=self.useFixedThreshold) self.fixedSpin.valueChanged[int].connect(self.setFixedThresh) self.fixedSpin.editingFinished.connect(self.edited) filter_settings.layout().addRow(btn_fix, self.fixedSpin) filter_settings.layout().addRow(btn_perc, self.percSpin) self.layout().addWidget(filter_settings)
def init_form(self): self._boundingbox = GaugeWidgetHorizontal() if self._horizontal else GaugeWidgetVertical() self._boundingbox.changed_event = self.__update if self._show_spinboxes: self._form = hwidget = QWidget() if self._horizontal: hlayout = QHBoxLayout() else: hlayout = QVBoxLayout() if _api.USED_API == _api.QT_API_PYQT5: hlayout.setContentsMargins(0,0,0,0) elif _api.USED_API == _api.QT_API_PYQT4: hlayout.setMargin(0) if self._label is not None: self._controllabel = QLabel(self.form) hlayout.addWidget(self._controllabel) self._controllabel.setAccessibleName('ControlBoundingSlider-label') self.label = self._label else: self._controllabel = None hwidget.setLayout(hlayout) self._min_spinbox = QSpinBox() self._min_spinbox.valueChanged.connect(self.__min_spinbox_changed) self._min_spinbox.setMaximumWidth(95) self._max_spinbox = QSpinBox() self._max_spinbox.valueChanged.connect(self.__max_spinbox_changed) self._max_spinbox.setMaximumWidth(95) if self._horizontal: hlayout.addWidget(self._min_spinbox) else: hlayout.addWidget(self._max_spinbox) hlayout.addWidget(self._boundingbox) if self._horizontal: hlayout.addWidget(self._max_spinbox) else: hlayout.addWidget(self._min_spinbox) else: self._form = self._boundingbox super(ControlBoundingSlider, self).init_form()
def __init__(self, *args, **kwargs): super().__init__(*args) layout = QStackedLayout(self) self.double_spin = QDoubleSpinBox() self.double_spin.valueChanged.connect(self.double_value_changed) self.double_spin.editingFinished.connect(self.double_editing_finished) layout.addWidget(self.double_spin) self.int_spin = QSpinBox() self.int_spin.setMaximum(10**4) self.int_spin.valueChanged.connect(self.int_value_changed) self.int_spin.editingFinished.connect(self.int_editing_finished) layout.addWidget(self.int_spin) self.setValue(kwargs.get('value', 0.))
def _(value: int, values: Iterable[int], parent: QGroupBox, key: KeyType, signal: Callable) -> QSpinBox: spin = QSpinBox(minimum=values.start, maximum=values.stop, singleStep=values.step, value=value) parent.layout().addWidget(spin) spin.valueChanged.connect(lambda val: signal.emit(key, val)) return spin
def main(argv=[]): app = QApplication(argv) w = ToolBox() style = app.style() icon = QIcon(style.standardIcon(QStyle.SP_FileIcon)) p1 = QLabel("A Label") p2 = QListView() p3 = QLabel("Another\nlabel") p4 = QSpinBox() i1 = w.addItem(p1, "Tab 1", icon) i2 = w.addItem(p2, "Tab 2", icon, "The second tab") i3 = w.addItem(p3, "Tab 3") i4 = w.addItem(p4, "Tab 4") p6 = QTextBrowser() p6.setHtml( "<h1>Hello Visitor</h1>" "<p>Are you interested in some of our wares?</p>" ) w.insertItem(2, p6, "Dear friend") w.show() return app.exec_()
def __init__(self): super().__init__() rb = self.radios = gui.radioButtons(self.controlArea, self, "graph_type", box="Graph type", callback=self.on_type_changed) self.arg_spins = {} for name, _, arguments, post, *_ in self.GRAPH_TYPES: argbox = gui.hBox(rb) gui.appendRadioButton(rb, name, argbox) self.arg_spins[name] = box = [] min_max = self.mins_maxs.get(name, ((1, 100), ) * len(arguments)) for arg, (minv, maxv) in zip(arguments, min_max): box.append(gui.widgetLabel(argbox, arg)) spin = QSpinBox(value=self.arguments[_ctrl_name(name, arg)], minimum=minv, maximum=maxv) argbox.layout().addWidget(spin) spin.valueChanged.connect(lambda value, name=name, arg=arg: self.update_arg(value, name, arg)) box.append(spin) if post: box.append(gui.widgetLabel(gui.hBox(argbox), post)) self.bt_generate = gui.button(self.controlArea, self, "Regenerate Network", callback=self.generate) self.on_type_changed()
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.__scoreidx = 0 self.__strategy = UnivariateFeatureSelect.Fixed self.__k = 10 self.__p = 75.0 box = QGroupBox(title="Score", flat=True) box.setLayout(QVBoxLayout()) self.__cb = cb = QComboBox(self, ) self.__cb.currentIndexChanged.connect(self.setScoreIndex) self.__cb.activated.connect(self.edited) box.layout().addWidget(cb) self.layout().addWidget(box) box = QGroupBox(title="Strategy", flat=True) self.__group = group = QButtonGroup(self, exclusive=True) self.__spins = {} form = QFormLayout() fixedrb = QRadioButton("Fixed:", checked=True) group.addButton(fixedrb, UnivariateFeatureSelect.Fixed) kspin = QSpinBox( minimum=1, value=self.__k, enabled=self.__strategy == UnivariateFeatureSelect.Fixed) kspin.valueChanged[int].connect(self.setK) kspin.editingFinished.connect(self.edited) self.__spins[UnivariateFeatureSelect.Fixed] = kspin form.addRow(fixedrb, kspin) percrb = QRadioButton("Percentile:") group.addButton(percrb, UnivariateFeatureSelect.Percentile) pspin = QDoubleSpinBox( minimum=0.0, maximum=100.0, singleStep=0.5, value=self.__p, suffix="%", enabled=self.__strategy == UnivariateFeatureSelect.Percentile) pspin.valueChanged[float].connect(self.setP) pspin.editingFinished.connect(self.edited) self.__spins[UnivariateFeatureSelect.Percentile] = pspin # Percentile controls disabled for now. pspin.setEnabled(False) percrb.setEnabled(False) form.addRow(percrb, pspin) # form.addRow(QRadioButton("FDR"), QDoubleSpinBox()) # form.addRow(QRadioButton("FPR"), QDoubleSpinBox()) # form.addRow(QRadioButton("FWE"), QDoubleSpinBox()) self.__group.buttonClicked.connect(self.__on_buttonClicked) box.setLayout(form) self.layout().addWidget(box)
def _(values: Iterable[int], value: int, key: KeyType, signal: Callable) \ -> QSpinBox: spin = QSpinBox(minimum=values.start, maximum=values.stop, singleStep=values.step, value=value) spin.valueChanged.connect(lambda val: signal.emit(key, val)) return spin
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.rank = 10 self.max_error = 1 form = QFormLayout() self.rspin = QSpinBox(minimum=2, maximum=1000000, value=self.rank) self.rspin.valueChanged[int].connect(self.setR) self.rspin.editingFinished.connect(self.edited) self.espin = QDoubleSpinBox( minimum=0.1, maximum=100.0, singleStep=0.1, value=self.max_error) self.espin.valueChanged[float].connect(self.setE) self.espin.editingFinished.connect(self.edited) form.addRow("Rank:", self.rspin) form.addRow("Relative error:", self.espin) self.layout().addLayout(form)
def init_form(self): self._boundingbox = GaugeWidgetHorizontal( ) if self._horizontal else GaugeWidgetVertical() self._boundingbox.changed_event = self.__update if self._show_spinboxes: self._form = hwidget = QWidget() if self._horizontal: hlayout = QHBoxLayout() else: hlayout = QVBoxLayout() if conf.PYFORMS_USE_QT5: hlayout.setContentsMargins(0, 0, 0, 0) else: hlayout.setMargin(0) hwidget.setLayout(hlayout) self._min_spinbox = QSpinBox() self._min_spinbox.valueChanged.connect(self.__min_spinbox_changed) self._min_spinbox.setMaximumWidth(95) self._max_spinbox = QSpinBox() self._max_spinbox.valueChanged.connect(self.__max_spinbox_changed) self._max_spinbox.setMaximumWidth(95) if self._horizontal: hlayout.addWidget(self._min_spinbox) else: hlayout.addWidget(self._max_spinbox) hlayout.addWidget(self._boundingbox) if self._horizontal: hlayout.addWidget(self._max_spinbox) else: hlayout.addWidget(self._min_spinbox) else: self._form = self._boundingbox super(ControlBoundingSlider, self).init_form()
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self._n_genes = self.DEFAULT_N_GENS self._n_groups = self.DEFAULT_N_GROUPS form = QFormLayout() self.n_genes_spin = QSpinBox(minimum=1, maximum=10**6, value=self._n_genes) self.n_genes_spin.valueChanged[int].connect(self._set_n_genes) self.n_genes_spin.editingFinished.connect(self.edited) form.addRow("Number of genes:", self.n_genes_spin) self.layout().addLayout(form) disp_b = QRadioButton("Dispersion", checked=True) vari_b = QRadioButton("Variance") mean_b = QRadioButton("Mean") self.group = QButtonGroup() self.group.buttonClicked.connect(self._on_button_clicked) for i, button in enumerate([disp_b, vari_b, mean_b]): index = index_to_enum(SelectMostVariableGenes.Method, i).value self.group.addButton(button, index - 1) form.addRow(button) self.stats_check = QCheckBox("Compute statistics for", checked=self.DEFAULT_COMPUTE_STATS) self.stats_check.clicked.connect(self.edited) self.n_groups_spin = QSpinBox(minimum=1, value=self._n_groups) self.n_groups_spin.valueChanged[int].connect(self._set_n_groups) self.n_groups_spin.editingFinished.connect(self.edited) box = QHBoxLayout() box.addWidget(self.stats_check) box.addWidget(self.n_groups_spin) box.addWidget(QLabel("gene groups.")) box.addStretch() self.layout().addLayout(box)
def __init__(self): def space(a, b): if not isinstance(a, str) or a[-1] in string.ascii_letters \ and not isinstance(b, str) or b[0] in string.ascii_letters: return " " else: return "" super().__init__() rb = self.radios = gui.radioButtons(self.controlArea, self, "graph_type", box=True, callback=self.on_type_changed) rb.layout().setSpacing(6) self.arg_spins = {} for (_1, name, _2, *arguments), defaults \ in zip(self.GRAPH_TYPES, self.arguments.values()): argbox = gui.hBox(rb) argbox.layout().setSpacing(0) rbb = gui.appendRadioButton(rb, name, argbox) rbb.setAttribute(Qt.WA_LayoutUsesWidgetRect) argbox.setAttribute(Qt.WA_LayoutUsesWidgetRect) self.arg_spins[name] = box = [] values = iter(defaults) argno = 0 for prev, arg, post in \ zip([""] + arguments, arguments, arguments + [""]): if isinstance(arg, str): label = space(prev, arg) + arg + space(arg, post) box.append(gui.widgetLabel(argbox, label)) else: assert isinstance(arg, tuple) _value, minv, maxv = arg spin = QSpinBox(value=next(values), minimum=minv, maximum=maxv) argbox.layout().addWidget(spin) spin.valueChanged.connect( lambda value, name=name, argidx=argno: self.update_arg( value, name, argidx)) argno += 1 box.append(spin) self.bt_generate = gui.button(self.controlArea, self, "Regenerate Network", callback=self.generate) self.on_type_changed()
class DropoutEditor(ScBaseEditor): DEFAULT_N_GENES = 1000 def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self._n_genes = self.DEFAULT_N_GENES form = QFormLayout() self.n_genes_spin = QSpinBox(minimum=1, maximum=10**6, value=self._n_genes) self.n_genes_spin.valueChanged[int].connect(self._set_n_genes) self.n_genes_spin.editingFinished.connect(self.edited) form.addRow("Number of genes:", self.n_genes_spin) self.layout().addLayout(form) def _set_n_genes(self, n): if self._n_genes != n: self._n_genes = n self.n_genes_spin.setValue(n) self.changed.emit() def setParameters(self, params): self._set_n_genes(params.get("n_genes", self.DEFAULT_N_GENES)) def parameters(self): return {"n_genes": self._n_genes} @staticmethod def createinstance(params): n_genes = params.get("n_genes", DropoutEditor.DEFAULT_N_GENES) return DropoutGeneSelection(n_genes) def __repr__(self): return "Number of Genes: {}".format(self._n_genes)
def __init__(self, *args, **kwargs): super().__init__(*args) layout = QStackedLayout(self) self.double_spin = QDoubleSpinBox() self.double_spin.valueChanged.connect(self.double_value_changed) self.double_spin.editingFinished.connect(self.double_editing_finished) layout.addWidget(self.double_spin) self.int_spin = QSpinBox() self.int_spin.setMaximum(10 ** 4) self.int_spin.valueChanged.connect(self.int_value_changed) self.int_spin.editingFinished.connect(self.int_editing_finished) layout.addWidget(self.int_spin) self.setValue(kwargs.get('value', 0.))
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.__strategy = RandomFeatureSelectEditor.Fixed self.__k = 10 self.__p = 75.0 box = QGroupBox(title="Strategy", flat=True) self.__group = group = QButtonGroup(self, exclusive=True) self.__spins = {} form = QFormLayout() fixedrb = QRadioButton("Fixed", checked=True) group.addButton(fixedrb, RandomFeatureSelectEditor.Fixed) kspin = QSpinBox( minimum=1, value=self.__k, enabled=self.__strategy == RandomFeatureSelectEditor.Fixed, ) kspin.valueChanged[int].connect(self.setK) kspin.editingFinished.connect(self.edited) self.__spins[RandomFeatureSelectEditor.Fixed] = kspin form.addRow(fixedrb, kspin) percrb = QRadioButton("Percentage") group.addButton(percrb, RandomFeatureSelectEditor.Percentage) pspin = QDoubleSpinBox( minimum=0.0, maximum=100.0, singleStep=0.5, value=self.__p, suffix="%", enabled=self.__strategy == RandomFeatureSelectEditor.Percentage, ) pspin.valueChanged[float].connect(self.setP) pspin.editingFinished.connect(self.edited) self.__spins[RandomFeatureSelectEditor.Percentage] = pspin form.addRow(percrb, pspin) self.__group.buttonClicked.connect(self.__on_buttonClicked) box.setLayout(form) self.layout().addWidget(box)
def test_prop(self): w = QWidget() layout = QVBoxLayout() cb = QCheckBox("Check", w) sp = QSpinBox(w) le = QLineEdit(w) textw = QTextEdit(w, readOnly=True) textw.setProperty("checked_", False) textw.setProperty("spin_", 0) textw.setProperty("line_", "") textexpr = PropertyBindingExpr( r""" ("Check box is {0}\n" "Spin has value {1}\n" "Line contains {2}").format( "checked" if checked else "unchecked", spin, line) """, dict( checked=binding_for(cb, "checked"), spin=binding_for(sp, "value"), line=binding_for(le, "text"), ), ) layout.addWidget(cb) layout.addWidget(sp) layout.addWidget(le) layout.addWidget(textw) manager = BindingManager(submitPolicy=BindingManager.AutoSubmit) manager.bind(PropertyBinding(textw, "plainText", "textChanged"), textexpr) w.setLayout(layout) w.show() self.app.exec_()
def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.setLayout(QVBoxLayout()) self.rank = 10 self.max_error = 1 form = QFormLayout() self.rspin = QSpinBox(minimum=2, value=self.rank) self.rspin.valueChanged[int].connect(self.setR) self.rspin.editingFinished.connect(self.edited) self.espin = QDoubleSpinBox( minimum=0.1, maximum=100.0, singleStep=0.1, value=self.max_error) self.espin.valueChanged[float].connect(self.setE) self.espin.editingFinished.connect(self.edited) form.addRow("Rank:", self.rspin) form.addRow("Relative error:", self.espin) self.layout().addLayout(form)
def test_tool_box(self): w = toolbox.ToolBox() style = self.app.style() icon = QIcon(style.standardPixmap(style.SP_FileIcon)) p1 = QLabel("A Label") p2 = QListView() p3 = QLabel("Another\nlabel") p4 = QSpinBox() i1 = w.addItem(p1, "T1", icon) i2 = w.addItem(p2, "Tab " * 10, icon, "a tab") i3 = w.addItem(p3, "t3") i4 = w.addItem(p4, "t4") self.assertSequenceEqual([i1, i2, i3, i4], range(4)) self.assertEqual(w.count(), 4) for i, item in enumerate([p1, p2, p3, p4]): self.assertIs(item, w.widget(i)) b = w.tabButton(i) a = w.tabAction(i) self.assertIsInstance(b, QAbstractButton) self.assertIs(b.defaultAction(), a) w.show() w.removeItem(2) self.assertEqual(w.count(), 3) self.assertIs(w.widget(2), p4) p3 = QLabel("Once More Unto the Breach") w.insertItem(2, p3, "Dear friend") self.assertEqual(w.count(), 4) self.assertIs(w.widget(1), p2) self.assertIs(w.widget(2), p3) self.assertIs(w.widget(3), p4) self.app.exec_()
class ControlBoundingSlider(ControlBase): def __init__(self, label="", default=[20, 40], min=0, max=100, horizontal=False, helptext=None, show_spinboxes=True): self._horizontal = horizontal self._show_spinboxes = show_spinboxes ControlBase.__init__(self, label, default, helptext=helptext) self.min = min self.max = max self.value = default self.__update() def init_form(self): self._boundingbox = GaugeWidgetHorizontal( ) if self._horizontal else GaugeWidgetVertical() self._boundingbox.changed_event = self.__update if self._show_spinboxes: self._form = hwidget = QWidget() if self._horizontal: hlayout = QHBoxLayout() else: hlayout = QVBoxLayout() if conf.PYFORMS_USE_QT5: hlayout.setContentsMargins(0, 0, 0, 0) else: hlayout.setMargin(0) hwidget.setLayout(hlayout) self._min_spinbox = QSpinBox() self._min_spinbox.valueChanged.connect(self.__min_spinbox_changed) self._min_spinbox.setMaximumWidth(95) self._max_spinbox = QSpinBox() self._max_spinbox.valueChanged.connect(self.__max_spinbox_changed) self._max_spinbox.setMaximumWidth(95) if self._horizontal: hlayout.addWidget(self._min_spinbox) else: hlayout.addWidget(self._max_spinbox) hlayout.addWidget(self._boundingbox) if self._horizontal: hlayout.addWidget(self._max_spinbox) else: hlayout.addWidget(self._min_spinbox) else: self._form = self._boundingbox super(ControlBoundingSlider, self).init_form() def __max_spinbox_changed(self, value): if value < self._boundingbox._minVal: return if hasattr(self, '_is_updating_spinboxes'): return self.scale = self.__find_scale_factor(value) self._boundingbox._maxVal = value self._boundingbox.repaint() self.changed_event() def __min_spinbox_changed(self, value): if value > self._boundingbox._maxVal: return if hasattr(self, '_is_updating_spinboxes'): return self.scale = self.__find_scale_factor(value) self._boundingbox._minVal = value self._boundingbox.repaint() self.changed_event() def __update(self): l, h = self._boundingbox._minVal, self._boundingbox._maxVal self._is_updating_spinboxes = True self._min_spinbox.setValue(l) self._max_spinbox.setValue(h) del self._is_updating_spinboxes self.changed_event() def changed_event(self): pass def __find_scale_factor(self, value): scale = 1.0 new_value = value while abs(new_value) < 0.0: scale *= 10.0 new_value = value * scale return scale ########################################################################## ############ Properties ################################################## ########################################################################## @property def value(self): return self._boundingbox._minVal, self._boundingbox._maxVal @value.setter def value(self, value): ControlBase.value.fset(self, value) self.scale = self.__find_scale_factor(value[0]) self._boundingbox._minVal, self._boundingbox._maxVal = value[0], value[ 1] if hasattr(self, '_min_spinbox'): self._min_spinbox.setValue(value[0]) if hasattr(self, '_max_spinbox'): self._max_spinbox.setValue(value[1]) self._boundingbox.repaint() @property def min(self): return self._boundingbox._lower @min.setter def min(self, value): self._boundingbox._lower = value self._boundingbox.repaint() if hasattr(self, '_min_spinbox'): self._min_spinbox.setMinimum(value) if hasattr(self, '_max_spinbox'): self._max_spinbox.setMinimum(value) @property def max(self): return self._boundingbox._higher @max.setter def max(self, value): self._boundingbox._higher = value self._boundingbox.repaint() if hasattr(self, '_min_spinbox'): self._min_spinbox.setMaximum(value) if hasattr(self, '_max_spinbox'): self._max_spinbox.setMaximum(value) @property def scale(self): return self._boundingbox.scale @scale.setter def scale(self, value): self._boundingbox.scale = value @property def convert_2_int(self): return not self._boundingbox._use_float @convert_2_int.setter def convert_2_int(self, value): self._boundingbox._use_float = not value
class AbsoluteRelativeSpinBox(QWidget): editingFinished = pyqtSignal() valueChanged = pyqtSignal() def __init__(self, *args, **kwargs): super().__init__(*args) layout = QStackedLayout(self) self.double_spin = QDoubleSpinBox() self.double_spin.valueChanged.connect(self.double_value_changed) self.double_spin.editingFinished.connect(self.double_editing_finished) layout.addWidget(self.double_spin) self.int_spin = QSpinBox() self.int_spin.setMaximum(10 ** 4) self.int_spin.valueChanged.connect(self.int_value_changed) self.int_spin.editingFinished.connect(self.int_editing_finished) layout.addWidget(self.int_spin) self.setValue(kwargs.get('value', 0.)) def double_value_changed(self): if self.double_spin.value() > 1: self.layout().setCurrentIndex(1) self.int_spin.setValue(self.double_spin.value()) self.valueChanged.emit() def double_editing_finished(self): if self.double_spin.value() <= 1.: self.editingFinished.emit() def int_value_changed(self): if self.int_spin.value() == 0: self.layout().setCurrentIndex(0) self.double_spin.setValue(1. - self.double_spin.singleStep()) # There is no need to emit valueChanged signal. def int_editing_finished(self): if self.int_spin.value() > 0: self.editingFinished.emit() def value(self): return self.int_spin.value() or self.double_spin.value() def setValue(self, value): if isinstance(value, int): self.layout().setCurrentIndex(1) self.int_spin.setValue(value) else: self.layout().setCurrentIndex(0) self.double_spin.setValue(value) def setSingleStep(self, step): if isinstance(step, float): self.double_spin.setSingleStep(step) else: self.int_spin.setSingleStep(step)
class RemoveSparseEditor(BaseEditor): options = ["missing", "zeros"] def __init__(self, parent=None, **kwargs): super().__init__(parent, **kwargs) self.fixedThresh = 50 self.percThresh = 5 self.useFixedThreshold = False self.filter0 = True self.setLayout(QVBoxLayout()) self.layout().addWidget(QLabel("Remove features with too many")) options = ["missing values", "zeros"] self.filter_buttons = QButtonGroup(exclusive=True) self.filter_buttons.buttonClicked.connect(self.filterByClicked) for idx, option, in enumerate(options): btn = QRadioButton(self, text=option, checked=idx == 0) self.filter_buttons.addButton(btn, id=idx) self.layout().addWidget(btn) self.layout().addSpacing(20) filter_settings = QGroupBox(title='Threshold:', flat=True) filter_settings.setLayout(QFormLayout()) self.settings_buttons = QButtonGroup(exclusive=True) self.settings_buttons.buttonClicked.connect(self.filterSettingsClicked) btn_perc = QRadioButton(self, text='Percentage', checked=not self.useFixedThreshold) self.settings_buttons.addButton(btn_perc, id=0) self.percSpin = QSpinBox(minimum=0, maximum=100, value=self.percThresh, enabled=not self.useFixedThreshold) self.percSpin.valueChanged[int].connect(self.setPercThresh) self.percSpin.editingFinished.connect(self.edited) btn_fix = QRadioButton(self, text='Fixed', checked=self.useFixedThreshold) self.settings_buttons.addButton(btn_fix, id=1) self.fixedSpin = QSpinBox(minimum=0, maximum=1000000, value=self.fixedThresh, enabled=self.useFixedThreshold) self.fixedSpin.valueChanged[int].connect(self.setFixedThresh) self.fixedSpin.editingFinished.connect(self.edited) filter_settings.layout().addRow(btn_fix, self.fixedSpin) filter_settings.layout().addRow(btn_perc, self.percSpin) self.layout().addWidget(filter_settings) def filterSettingsClicked(self): self.setUseFixedThreshold(self.settings_buttons.checkedId()) self.percSpin.setEnabled(not self.useFixedThreshold) self.fixedSpin.setEnabled(self.useFixedThreshold) self.edited.emit() def filterByClicked(self): self.setFilter0(self.filter_buttons.checkedId()) def setFilter0(self, id_): if self.filter0 != id_: self.filter0 = id_ self.edited.emit() def setFixedThresh(self, thresh): if self.fixedThresh != thresh: self.fixedThresh = thresh self.fixedSpin.setValue(thresh) self.edited.emit() def setPercThresh(self, thresh): if self.percThresh != thresh: self.percThresh = thresh self.percSpin.setValue(thresh) self.edited.emit() def setUseFixedThreshold(self, val): if self.useFixedThreshold != val: self.useFixedThreshold = val self.edited.emit() def parameters(self): return { 'fixedThresh': self.fixedThresh, 'percThresh': self.percThresh, 'useFixedThreshold': self.useFixedThreshold, 'filter0': self.filter0 } def setParameters(self, params): self.setPercThresh(params.get('percThresh', 5)) self.setFixedThresh(params.get('fixedThresh', 50)) self.setUseFixedThreshold(params.get('useFixedThreshold', False)) self.setFilter0(params.get('filter0', True)) @staticmethod def createinstance(params): params = dict(params) filter0 = params.pop('filter0', True) useFixedThreshold = params.pop('useFixedThreshold', True) if useFixedThreshold: threshold = params.pop('fixedThresh', 50) else: threshold = params.pop('percThresh', 5) / 100 return RemoveSparse(threshold, filter0)
def __init__(self): super().__init__() self._current_path = "" icon_open_dir = self.style().standardIcon(QStyle.SP_DirOpenIcon) # Top grid with file selection combo box grid = QGridLayout() lb = QLabel("File:") lb.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.recent_combo = cb = QComboBox( sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, minimumContentsLength=20, toolTip="Select a recent file") self.recent_model = cb.model() # type: QStandardItemModel self.recent_combo.activated[int].connect(self._select_recent) browse = QPushButton("...", autoDefault=False, icon=icon_open_dir, clicked=self.browse) # reload = QPushButton("Reload", autoDefault=False, icon=icon_reload) grid.addWidget(lb, 0, 0, Qt.AlignVCenter) grid.addWidget(cb, 0, 1) grid.addWidget(browse, 0, 2) # grid.addWidget(reload, 0, 3) self.summary_label = label = QLabel("", self) label.ensurePolished() f = label.font() if f.pointSizeF() != -1: f.setPointSizeF(f.pointSizeF() * 5 / 6) else: f.setPixelSize(f.pixelSize() * 5 / 6) label.setFont(f) grid.addWidget(label, 1, 1, 1, 3) self.controlArea.layout().addLayout(grid) box = gui.widgetBox(self.controlArea, "Headers and Row Labels", spacing=-1) hl = QHBoxLayout() hl.setContentsMargins(0, 0, 0, 0) self.header_rows_spin = spin = QSpinBox(box, minimum=0, maximum=3, value=self._header_rows_count, keyboardTracking=False) spin.valueChanged.connect(self.set_header_rows_count) hl.addWidget(QLabel("Data starts with", box)) hl.addWidget(self.header_rows_spin) hl.addWidget(QLabel("header row(s)", box)) hl.addStretch(10) box.layout().addLayout(hl) hl = QHBoxLayout() hl.setContentsMargins(0, 0, 0, 0) self.header_cols_spin = spin = QSpinBox(box, minimum=0, maximum=3, value=self._header_cols_count, keyboardTracking=False) spin.valueChanged.connect(self.set_header_cols_count) hl.addWidget(QLabel("First", box)) hl.addWidget(self.header_cols_spin) hl.addWidget(QLabel("column(s) are row labels", box)) hl.addStretch(10) box.layout().addLayout(hl) self.data_struct_box = box = gui.widgetBox(self.controlArea, "Input Data Structure") gui.radioButtons(box, self, "_cells_in_rows", [ "Genes in rows, samples in columns", "Samples in rows, genes in columns" ], callback=self._invalidate) box = gui.widgetBox(self.controlArea, "Sample Data", spacing=-1) grid = QGridLayout() grid.setContentsMargins(0, 0, 0, 0) box.layout().addLayout(grid) self.sample_rows_cb = cb = QCheckBox(checked=self._sample_rows_enabled) spin = QSpinBox(minimum=0, maximum=100, value=self._sample_rows_p, enabled=self._sample_rows_enabled) spin.valueChanged.connect(self.set_sample_rows_p) suffix = QLabel("% of Samples", enabled=self._sample_rows_enabled) cb.toggled.connect(self.set_sample_rows_enabled) cb.toggled.connect(spin.setEnabled) cb.toggled.connect(suffix.setEnabled) grid.addWidget(cb, 0, 0) grid.addWidget(spin, 0, 1) grid.addWidget(suffix, 0, 2) self.sample_cols_cb = cb = QCheckBox(checked=self._sample_cols_enabled) spin = QSpinBox(minimum=0, maximum=100, value=self._sample_cols_p, enabled=self._sample_cols_enabled) spin.valueChanged.connect(self.set_sample_cols_p) suffix = QLabel("% of genes", enabled=self._sample_cols_enabled) cb.toggled.connect(self.set_sample_cols_enabled) cb.toggled.connect(spin.setEnabled) cb.toggled.connect(suffix.setEnabled) grid.addWidget(cb, 1, 0) grid.addWidget(spin, 1, 1) grid.addWidget(suffix, 1, 2) grid.setColumnStretch(3, 10) self.annotation_files_box = box = gui.widgetBox( self.controlArea, "Cell && Gene Annotation Files") form = QFormLayout( formAlignment=Qt.AlignLeft, rowWrapPolicy=QFormLayout.WrapAllRows, ) box.layout().addLayout(form) self.row_annotations_cb = cb = QCheckBox( "Cell annotations", checked=self._row_annotations_enabled) self._row_annotations_w = w = QWidget( enabled=self._row_annotations_enabled) cb.toggled.connect(self.set_row_annotations_enabled) cb.toggled.connect(w.setEnabled) hl = QHBoxLayout() hl.setContentsMargins(0, 0, 0, 0) w.setLayout(hl) self.row_annotations_combo = QComboBox( sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, minimumContentsLength=18) self.row_annotations_combo.activated.connect(self._invalidate) hl.addWidget(self.row_annotations_combo) hl.addWidget( QPushButton("...", box, autoDefault=False, icon=icon_open_dir, clicked=self.browse_row_annotations)) # hl.addWidget(QPushButton("Reload", box, autoDefault=False, # icon=icon_reload)) form.addRow(cb, w) self.col_annotations_cb = cb = QCheckBox( "Gene annotations", checked=self._col_annotations_enabled) self._col_annotations_w = w = QWidget( enabled=self._col_annotations_enabled) cb.toggled.connect(self.set_col_annotations_enabled) cb.toggled.connect(w.setEnabled) hl = QHBoxLayout() hl.setContentsMargins(0, 0, 0, 0) w.setLayout(hl) self.col_annotations_combo = QComboBox( sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon, minimumContentsLength=18) self.col_annotations_combo.activated.connect(self._invalidate) hl.addWidget(self.col_annotations_combo) hl.addWidget( QPushButton("...", box, autoDefault=False, icon=icon_open_dir, clicked=self.browse_col_annotations)) # hl.addWidget(QPushButton("Reload", box, autoDefault=False, # icon=icon_reload)) form.addRow(cb, w) self.controlArea.layout().addStretch(10) self.load_data_button = button = VariableTextPushButton( "Load data", autoDefault=True, textChoiceList=["Load data", "Reload"]) self.load_data_button.setAutoDefault(True) button.clicked.connect(self.commit, Qt.QueuedConnection) self.controlArea.layout().addWidget(button, alignment=Qt.AlignRight) init_recent_paths_model( self.recent_model, [RecentPath.create(p, []) for p in self._recent], ) init_recent_paths_model( self.row_annotations_combo.model(), [RecentPath.create(p, []) for p in self._recent_row_annotations]) init_recent_paths_model( self.col_annotations_combo.model(), [RecentPath.create(p, []) for p in self._recent_col_annotations]) self._update_summary() self._update_warning() if self._last_path != "" and os.path.exists(self._last_path): self.set_current_path(self._last_path) else: self.recent_combo.setCurrentIndex(-1)
class AbsoluteRelativeSpinBox(QWidget): editingFinished = pyqtSignal() valueChanged = pyqtSignal() def __init__(self, *args, **kwargs): super().__init__(*args) layout = QStackedLayout(self) self.double_spin = QDoubleSpinBox() self.double_spin.valueChanged.connect(self.double_value_changed) self.double_spin.editingFinished.connect(self.double_editing_finished) layout.addWidget(self.double_spin) self.int_spin = QSpinBox() self.int_spin.setMaximum(10**4) self.int_spin.valueChanged.connect(self.int_value_changed) self.int_spin.editingFinished.connect(self.int_editing_finished) layout.addWidget(self.int_spin) self.setValue(kwargs.get('value', 0.)) def double_value_changed(self): if self.double_spin.value() > 1: self.layout().setCurrentIndex(1) self.int_spin.setValue(self.double_spin.value()) self.valueChanged.emit() def double_editing_finished(self): if self.double_spin.value() <= 1.: self.editingFinished.emit() def int_value_changed(self): if self.int_spin.value() == 0: self.layout().setCurrentIndex(0) self.double_spin.setValue(1. - self.double_spin.singleStep()) # There is no need to emit valueChanged signal. def int_editing_finished(self): if self.int_spin.value() > 0: self.editingFinished.emit() def value(self): return self.int_spin.value() or self.double_spin.value() def setValue(self, value): if isinstance(value, int): self.layout().setCurrentIndex(1) self.int_spin.setValue(value) else: self.layout().setCurrentIndex(0) self.double_spin.setValue(value) def setSingleStep(self, step): if isinstance(step, float): self.double_spin.setSingleStep(step) else: self.int_spin.setSingleStep(step)
def _(spin: QSpinBox, value: int): spin.setValue(value)
class ControlBoundingSlider(ControlBase): def __init__(self, *args, **kwargs): self._horizontal = kwargs.get('horizontal', True) self._show_spinboxes = kwargs.get('show_spinboxes', True) ControlBase.__init__(self, *args, **kwargs) self.min = kwargs.get('min', kwargs.get('minimum', 0)) self.max = kwargs.get('max', kwargs.get('maximum', 100)) self.value = kwargs.get('default', [10,20]) self.__update() def init_form(self): self._boundingbox = GaugeWidgetHorizontal() if self._horizontal else GaugeWidgetVertical() self._boundingbox.changed_event = self.__update if self._show_spinboxes: self._form = hwidget = QWidget() if self._horizontal: hlayout = QHBoxLayout() else: hlayout = QVBoxLayout() if _api.USED_API == _api.QT_API_PYQT5: hlayout.setContentsMargins(0,0,0,0) elif _api.USED_API == _api.QT_API_PYQT4: hlayout.setMargin(0) hwidget.setLayout(hlayout) self._min_spinbox = QSpinBox() self._min_spinbox.valueChanged.connect(self.__min_spinbox_changed) self._min_spinbox.setMaximumWidth(95) self._max_spinbox = QSpinBox() self._max_spinbox.valueChanged.connect(self.__max_spinbox_changed) self._max_spinbox.setMaximumWidth(95) if self._horizontal: hlayout.addWidget(self._min_spinbox) else: hlayout.addWidget(self._max_spinbox) hlayout.addWidget(self._boundingbox) if self._horizontal: hlayout.addWidget(self._max_spinbox) else: hlayout.addWidget(self._min_spinbox) else: self._form = self._boundingbox super(ControlBoundingSlider, self).init_form() def __max_spinbox_changed(self, value): if value < self._boundingbox._minVal: return if hasattr(self, '_is_updating_spinboxes'): return self.scale = self.__find_scale_factor(value) self._boundingbox._maxVal = value self._boundingbox.repaint() self.changed_event() def __min_spinbox_changed(self, value): if value > self._boundingbox._maxVal: return if hasattr(self, '_is_updating_spinboxes'): return self.scale = self.__find_scale_factor(value) self._boundingbox._minVal = value self._boundingbox.repaint() self.changed_event() def __update(self): l, h = self._boundingbox._minVal, self._boundingbox._maxVal self._is_updating_spinboxes = True self._min_spinbox.setValue(l) self._max_spinbox.setValue(h) del self._is_updating_spinboxes self.changed_event() def changed_event(self): pass def __find_scale_factor(self, value): scale = 1.0 new_value = value while abs(new_value) < 0.0: scale *= 10.0 new_value = value * scale return scale def load_form(self, data, path=None): """ Load a value from the dict variable @param data: dictionary with the value of the Control """ self.convert_2_int = data.get('convert-int', self.convert_2_int) self.scale = data.get('scale', self.scale) self.max = data.get('max', self.max) self.min = data.get('min', self.min) self.value = data.get('value', self.value) def save_form(self, data, path=None): """ Save a value to dict variable @param data: dictionary with to where the value of the Control will be added """ data['value'] = self.value data['max'] = self.max data['min'] = self.min data['scale'] = self.scale data['convert-int'] = self.convert_2_int return data ########################################################################## ############ Properties ################################################## ########################################################################## @property def value(self): return self._boundingbox._minVal, self._boundingbox._maxVal @value.setter def value(self, value): self.scale = self.__find_scale_factor(value[0]) self._boundingbox._minVal, self._boundingbox._maxVal = value[0], value[1] if hasattr(self, '_min_spinbox'): self._min_spinbox.setValue(value[0]) if hasattr(self, '_max_spinbox'): self._max_spinbox.setValue(value[1]) ControlBase.value.fset(self, value) self._boundingbox.repaint() @property def min(self): return self._boundingbox._lower @min.setter def min(self, value): self._boundingbox._lower = value self._boundingbox.repaint() if hasattr(self, '_min_spinbox'): self._min_spinbox.setMinimum(value) if hasattr(self, '_max_spinbox'): self._max_spinbox.setMinimum(value) @property def max(self): return self._boundingbox._higher @max.setter def max(self, value): self._boundingbox._higher = value self._boundingbox.repaint() if hasattr(self, '_min_spinbox'): self._min_spinbox.setMaximum(value) if hasattr(self, '_max_spinbox'): self._max_spinbox.setMaximum(value) @property def scale(self): return self._boundingbox.scale @scale.setter def scale(self, value): self._boundingbox.scale = value @property def convert_2_int(self): return not self._boundingbox._use_float @convert_2_int.setter def convert_2_int(self, value): self._boundingbox._use_float = not value
def createEditor(self, parent, _QStyleOptionViewItem, _index): # Don't edit window length if non-overlapping windows set if self.parent().non_overlapping: return None spin = QSpinBox(parent, minimum=1, maximum=1000) return spin