def add_row(self): def sync_combos(): combo = self.sender() index = combo.currentIndex() model = combo.model() other = ({row_items.left_combo, row_items.right_combo} - {combo}).pop() other_index = other.currentIndex() other_model = other.model() if 0 <= index < len(combo.model()): var = model[index] if isinstance(var, str): other.setCurrentText(model[index]) elif isinstance(other_model[other_index], str): for other_var in other_model: if isinstance(other_var, Variable) \ and var.name == other_var.name \ and (type(other_var) is type(var) or (not var.is_continuous and not other_var.is_continuous)): other.setCurrentText(var.name) break self.emit_list() def get_combo(model): combo = QComboBox(self) combo.setModel(model) # We use signal activated because it is triggered only on user # interaction, not programmatically. combo.activated.connect(sync_combos) return combo def get_button(label, callback): button = QPushButton(label, self) button.setFlat(True) button.setFixedWidth(12) button.clicked.connect(callback) return button row = self.layout().count() row_items = self.RowItems( QLabel("and" if row else self.pre_label), get_combo(self.model_left), QLabel(self.in_label), get_combo(self.model_right), get_button("×", self.on_remove_row), get_button("+", self.on_add_row) ) layout = QHBoxLayout() layout.setSpacing(10) self.layout().addLayout(layout) layout.addStretch(10) for item in row_items: layout.addWidget(item) self.rows.append(row_items) self._reset_buttons()
def _setup_gui_labels(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(1) self.labels_edit = QTreeView() self.labels_edit.setEditTriggers(QTreeView.CurrentChanged) self.labels_edit.setRootIsDecorated(False) self.labels_model = DictItemsModel() self.labels_edit.setModel(self.labels_model) self.labels_edit.selectionModel().selectionChanged.connect( self.on_label_selection_changed) # Necessary signals to know when the labels change self.labels_model.dataChanged.connect(self.on_labels_changed) self.labels_model.rowsInserted.connect(self.on_labels_changed) self.labels_model.rowsRemoved.connect(self.on_labels_changed) vlayout.addWidget(self.labels_edit) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.setSpacing(1) self.add_label_action = QAction( "+", self, toolTip="Add a new label.", triggered=self.on_add_label, enabled=False, shortcut=QKeySequence(QKeySequence.New), ) self.remove_label_action = QAction( unicodedata.lookup("MINUS SIGN"), self, toolTip="Remove selected label.", triggered=self.on_remove_label, enabled=False, shortcut=QKeySequence(QKeySequence.Delete), ) button_size = gui.toolButtonSizeHint() button_size = QSize(button_size, button_size) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.add_label_action) hlayout.addWidget(button) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.remove_label_action) hlayout.addWidget(button) hlayout.addStretch(10) vlayout.addLayout(hlayout) self.main_form.addRow("Labels:", vlayout)
def _setup_gui_labels(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(1) self.labels_edit = QTreeView() self.labels_edit.setEditTriggers(QTreeView.CurrentChanged) self.labels_edit.setRootIsDecorated(False) self.labels_model = DictItemsModel() self.labels_edit.setModel(self.labels_model) self.labels_edit.selectionModel().selectionChanged.connect( self.on_label_selection_changed) # Necessary signals to know when the labels change self.labels_model.dataChanged.connect(self.on_labels_changed) self.labels_model.rowsInserted.connect(self.on_labels_changed) self.labels_model.rowsRemoved.connect(self.on_labels_changed) vlayout.addWidget(self.labels_edit) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.setSpacing(1) self.add_label_action = QAction( "+", self, toolTip="Add a new label.", triggered=self.on_add_label, enabled=False, shortcut=QKeySequence(QKeySequence.New)) self.remove_label_action = QAction( unicodedata.lookup("MINUS SIGN"), self, toolTip="Remove selected label.", triggered=self.on_remove_label, enabled=False, shortcut=QKeySequence(QKeySequence.Delete)) button_size = gui.toolButtonSizeHint() button_size = QSize(button_size, button_size) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.add_label_action) hlayout.addWidget(button) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.remove_label_action) hlayout.addWidget(button) hlayout.addStretch(10) vlayout.addLayout(hlayout) self.main_form.addRow("Labels:", vlayout)
def setup_filter_area(self): h_layout = QHBoxLayout() h_layout.setSpacing(100) h_widget = widgetBox(self.mainArea, orientation=h_layout) spin( h_widget, self, 'min_count', 0, 100, label='Count', tooltip='Minimum genes count', checked='use_min_count', callback=self.filter_data_view, callbackOnReturn=True, checkCallback=self.filter_data_view, ) doubleSpin( h_widget, self, 'max_p_value', 0.0, 1.0, 0.0001, label='p-value', tooltip='Maximum p-value of the enrichment score', checked='use_p_value', callback=self.filter_data_view, callbackOnReturn=True, checkCallback=self.filter_data_view, ) doubleSpin( h_widget, self, 'max_fdr', 0.0, 1.0, 0.0001, label='FDR', tooltip='Maximum false discovery rate', checked='use_max_fdr', callback=self.filter_data_view, callbackOnReturn=True, checkCallback=self.filter_data_view, ) self.line_edit_filter = lineEdit(h_widget, self, 'search_pattern') self.line_edit_filter.setPlaceholderText('Filter gene sets ...') self.line_edit_filter.textChanged.connect(self.filter_data_view)
def _setup_gui_values(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) vlayout.setSpacing(1) self.values_edit = QListView() self.values_edit.setEditTriggers(QTreeView.CurrentChanged) self.values_model = itemmodels.PyListModel(flags=Qt.ItemIsSelectable | \ Qt.ItemIsEnabled | Qt.ItemIsEditable) self.values_edit.setModel(self.values_model) self.values_edit.selectionModel().selectionChanged.connect( self.on_value_selection_changed) self.values_model.dataChanged.connect(self.on_values_changed) vlayout.addWidget(self.values_edit) hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.setSpacing(1) self.move_value_up = QAction(unicodedata.lookup("UPWARDS ARROW"), self, toolTip="Move up.", triggered=self.move_up, enabled=False, shortcut=QKeySequence(QKeySequence.New)) self.move_value_down = QAction(unicodedata.lookup("DOWNWARDS ARROW"), self, toolTip="Move down.", triggered=self.move_down, enabled=False, shortcut=QKeySequence( QKeySequence.Delete)) button_size = gui.toolButtonSizeHint() button_size = QSize(button_size, button_size) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.move_value_up) hlayout.addWidget(button) button = QToolButton(self) button.setFixedSize(button_size) button.setDefaultAction(self.move_value_down) hlayout.addWidget(button) hlayout.addStretch(10) vlayout.addLayout(hlayout) self.main_form.addRow("Values:", vlayout)
def insertRow(self, index, actions, background="light-orange"): """Insert a row with `actions` at `index`. """ widget = QWidget(objectName="icon-row") layout = QHBoxLayout() layout.setContentsMargins(40, 0, 40, 0) layout.setSpacing(65) widget.setLayout(layout) self.__mainLayout.insertWidget(index, widget, stretch=10, alignment=Qt.AlignCenter) for i, action in enumerate(actions): self.insertAction(index, i, action, background)
def insertRow(self, index, actions, background="light-orange"): """Insert a row with `actions` at `index`. """ widget = QWidget(objectName="icon-row") layout = QHBoxLayout() layout.setContentsMargins(40, 0, 40, 0) layout.setSpacing(65) widget.setLayout(layout) self.__mainLayout.insertWidget( index, widget, stretch=10, alignment=Qt.AlignCenter ) for i, action in enumerate(actions): self.insertAction(index, i, action, background)
def __init__(self, state=AVAILABLE, parent=None): QWidget.__init__(self, parent) layout = QHBoxLayout() layout.setSpacing(1) layout.setContentsMargins(1, 1, 1, 1) self.checkButton = QCheckBox() layout.addWidget(self.checkButton) self.setLayout(layout) self.setMinimumHeight(20) self.setMaximumHeight(20) self.state = -1 self.setState(state)
def __init__(self, state=AVAILABLE, parent=None): QWidget.__init__(self, parent) layout = QHBoxLayout() layout.setSpacing(1) layout.setContentsMargins(1, 1, 1, 1) self.checkButton = QCheckBox() layout.addWidget(self.checkButton) self.setLayout(layout) self.setMinimumHeight(20) self.setMaximumHeight(20) self._state = state self._update()
def __init__(self, parent=None, **kwargs): QWidget.__init__(self, parent, **kwargs) self.__pages = [] self.__currentIndex = -1 layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(6) self.__tab = TabBarWidget(self) self.__tab.currentChanged.connect(self.setCurrentIndex) self.__tab.setChangeOnHover(True) self.__stack = MenuStackWidget(self) layout.addWidget(self.__tab, alignment=Qt.AlignTop) layout.addWidget(self.__stack) self.setLayout(layout)
def __init__(self, parent=None, **kwargs): # type: (Optional[QWidget], Any) -> None super().__init__(parent, **kwargs) self.__currentIndex = -1 layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(6) self.__tab = TabBarWidget(self) self.__tab.currentChanged.connect(self.setCurrentIndex) self.__tab.setChangeOnHover(True) self.__stack = MenuStackWidget(self) layout.addWidget(self.__tab, alignment=Qt.AlignTop) layout.addWidget(self.__stack) self.setLayout(layout)
def setup_filter_area(self): h_layout = QHBoxLayout() h_layout.setSpacing(100) h_widget = widgetBox(self.mainArea, orientation=h_layout) spin(h_widget, self, 'min_count', 0, 1000, label='Count', tooltip='Minimum genes count', checked='use_min_count', callback=self.filter_data_view, callbackOnReturn=True, checkCallback=self.filter_data_view) self.line_edit_filter = lineEdit(h_widget, self, 'search_pattern') self.line_edit_filter.setPlaceholderText('Filter gene sets ...') self.line_edit_filter.textChanged.connect(self.filter_data_view)
def __init__(self, parent, highlighting_scheme, font): super().__init__(parent, highlighting_scheme, font) self.indentation_level = 1 self.signal_labels = {} self._prefix = None layout = QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) # `return ` ret_lbl = QLabel('<b style="color: ' + \ highlighting_scheme[Keyword].split(' ')[-1] + \ ';">return </b>', self) ret_lbl.setFont(self.font()) ret_lbl.setContentsMargins(0, 0, 0, 0) layout.addWidget(ret_lbl) # `out_data[, ]` * 4 self.make_signal_labels('out_') layout.addStretch() self.setLayout(layout)
def __init__(self): super().__init__() # OWWidget.__init__(self) ConcurrentWidgetMixin.__init__(self) # Control area box = vBox(self.controlArea, True, margin=0) self.gs_selection_component: GeneSetSelection = GeneSetSelection(self, box) self.gs_selection_component.selection_changed.connect(self._on_selection_changed) self.reference_radio_box = radioButtonsInBox( self.controlArea, self, 'use_reference_data', ['Entire genome', 'Reference gene set (input)'], tooltips=['Use entire genome (for gene set enrichment)', 'Use reference set of genes'], box='Reference', callback=self._on_selection_changed, ) self.reference_radio_box.setEnabled(False) self.reference_genes: Optional[List[str]] = None # Main area self.filter_proxy_model = FilterProxyModel() self.filter_proxy_model.setFilterKeyColumn(Header.term) self.tree_view = QTreeView() self.tree_view.setAlternatingRowColors(True) self.tree_view.setSortingEnabled(True) self.tree_view.sortByColumn(Header.count, Qt.DescendingOrder) self.tree_view.setSelectionMode(QTreeView.ExtendedSelection) self.tree_view.setEditTriggers(QTreeView.NoEditTriggers) self.tree_view.viewport().setMouseTracking(True) self.tree_view.setItemDelegateForColumn(Header.term, LinkStyledItemDelegate(self.tree_view)) self.tree_view.setItemDelegateForColumn(Header.genes, NumericalColumnDelegate(self)) self.tree_view.setItemDelegateForColumn(Header.count, NumericalColumnDelegate(self)) self.tree_view.setItemDelegateForColumn(Header.p_val, NumericalColumnDelegate(self, precision=2, notation='e')) self.tree_view.setItemDelegateForColumn(Header.fdr, NumericalColumnDelegate(self, precision=2, notation='e')) self.tree_view.setItemDelegateForColumn(Header.enrichment, NumericalColumnDelegate(self, precision=1)) self.tree_view.setItemDelegateForColumn(Header.reference, NumericalColumnDelegate(self)) self.tree_view.setModel(self.filter_proxy_model) h_layout = QHBoxLayout() h_layout.setSpacing(100) h_widget = widgetBox(self.mainArea, orientation=h_layout) spin( h_widget, self, 'min_count', 0, 1000, label='Count', tooltip='Minimum genes count', checked='use_min_count', callback=self.filter_view, callbackOnReturn=True, checkCallback=self.filter_view, ) doubleSpin( h_widget, self, 'max_p_value', 0.0, 1.0, 0.0001, label='p-value', tooltip='Maximum p-value of the enrichment score', checked='use_p_value', callback=self.filter_view, callbackOnReturn=True, checkCallback=self.filter_view, ) doubleSpin( h_widget, self, 'max_fdr', 0.0, 1.0, 0.0001, label='FDR', tooltip='Maximum false discovery rate', checked='use_max_fdr', callback=self.filter_view, callbackOnReturn=True, checkCallback=self.filter_view, ) self.line_edit_filter = lineEdit(h_widget, self, 'search_pattern') self.line_edit_filter.setPlaceholderText('Filter gene sets ...') self.line_edit_filter.textChanged.connect(self.filter_view) self.mainArea.layout().addWidget(self.tree_view) self.tree_view.header().setSectionResizeMode(QHeaderView.ResizeToContents) self.commit_button = auto_commit(self.controlArea, self, 'auto_commit', '&Commit', box=False) self.input_data: Optional[Table] = None self.num_of_selected_genes: int = 0 self.gene_info: Optional[GeneInfo] = None
class PreprocessorModule(gui.OWComponent, QWidget): """The base widget for the pre-processing modules.""" change_signal = pyqtSignal() # Emitted when the settings are changed. title = NotImplemented attribute = NotImplemented methods = NotImplemented single_method = True toggle_enabled = True enabled = settings.Setting(True) disabled_value = None Layout = QGridLayout def __init__(self, master): QWidget.__init__(self) gui.OWComponent.__init__(self, master) self.master = master # Title bar. title_holder = QWidget() title_holder.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) title_holder.setStyleSheet(""" .QWidget { background: qlineargradient( x1:0 y1:0, x2:0 y2:1, stop:0 #F8F8F8, stop:1 #C8C8C8); border-bottom: 1px solid #B3B3B3; } """) self.titleArea = QHBoxLayout() self.titleArea.setContentsMargins(10, 5, 10, 5) self.titleArea.setSpacing(0) title_holder.setLayout(self.titleArea) self.title_label = QLabel(self.title) self.title_label.mouseDoubleClickEvent = self.on_toggle self.title_label.setStyleSheet( 'font-size: 12px; border: 2px solid red;') self.titleArea.addWidget(self.title_label) self.off_label = QLabel('[disabled]') self.off_label.setStyleSheet('color: #B0B0B0; margin-left: 5px;') self.titleArea.addWidget(self.off_label) self.off_label.hide() self.titleArea.addStretch() # Root. self.rootArea = QVBoxLayout() self.rootArea.setContentsMargins(0, 0, 0, 0) self.rootArea.setSpacing(0) self.setLayout(self.rootArea) self.rootArea.addWidget(title_holder) self.contents = QWidget() contentArea = QVBoxLayout() contentArea.setContentsMargins(15, 10, 15, 10) self.contents.setLayout(contentArea) self.rootArea.addWidget(self.contents) self.method_layout = self.Layout() self.setup_method_layout() self.contents.layout().addLayout(self.method_layout) if self.toggle_enabled: self.on_off_button = OnOffButton(enabled=self.enabled) self.on_off_button.stateChanged.connect(self.on_toggle) self.on_off_button.setContentsMargins(0, 0, 0, 0) self.titleArea.addWidget(self.on_off_button) self.display_widget() @staticmethod def get_tooltip(method): return ' '.join([l.strip() for l in method.__doc__.split('\n')]).strip('.') \ if method.__doc__ else None @staticmethod def textify(text): return text.replace('&', '&&') @property def value(self): if self.enabled: return self.get_value() return self.disabled_value def setup_method_layout(self): raise NotImplementedError def on_toggle(self, event=None): # Activated when the widget is enabled/disabled. self.enabled = not self.enabled self.display_widget() self.update_value() def display_widget(self): if self.enabled: self.off_label.hide() self.contents.show() self.title_label.setStyleSheet('color: #000000;') else: self.off_label.show() self.contents.hide() self.title_label.setStyleSheet('color: #B0B0B0;') def get_value(self): raise NotImplemented def update_value(self): self.change_signal.emit()
def __init__(self, parent=None, icon=QIcon(), title="", text="", wordWrap=False, textFormat=Qt.PlainText, standardButtons=NoButton, acceptLabel="Ok", rejectLabel="No", **kwargs): super().__init__(parent, **kwargs) self._title = title self._text = text self._icon = QIcon() self._wordWrap = wordWrap self._standardButtons = NotificationMessageWidget.NoButton self._buttons = [] self._acceptLabel = acceptLabel self._rejectLabel = rejectLabel self._iconlabel = QLabel(objectName="icon-label") self._titlelabel = QLabel(objectName="title-label", text=title, wordWrap=wordWrap, textFormat=textFormat) self._textlabel = QLabel(objectName="text-label", text=text, wordWrap=wordWrap, textFormat=textFormat) self._textlabel.setTextInteractionFlags(Qt.TextBrowserInteraction) self._textlabel.setOpenExternalLinks(True) if sys.platform == "darwin": self._titlelabel.setAttribute(Qt.WA_MacSmallSize) self._textlabel.setAttribute(Qt.WA_MacSmallSize) layout = QHBoxLayout() self._iconlabel.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) layout.addWidget(self._iconlabel) layout.setAlignment(self._iconlabel, Qt.AlignTop) message_layout = QVBoxLayout() self._titlelabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) if sys.platform == "darwin": self._titlelabel.setContentsMargins(0, 1, 0, 0) else: self._titlelabel.setContentsMargins(0, 0, 0, 0) message_layout.addWidget(self._titlelabel) self._textlabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) message_layout.addWidget(self._textlabel) self.button_layout = QHBoxLayout() self.button_layout.setAlignment(Qt.AlignLeft) message_layout.addLayout(self.button_layout) layout.addLayout(message_layout) layout.setSpacing(7) self.setLayout(layout) self.setIcon(icon) self.setStandardButtons(standardButtons)
class PreprocessorModule(gui.OWComponent, QWidget): """The base widget for the pre-processing modules.""" change_signal = pyqtSignal() # Emitted when the settings are changed. title = NotImplemented attribute = NotImplemented methods = NotImplemented single_method = True toggle_enabled = True enabled = settings.Setting(True) disabled_value = None Layout = QGridLayout def __init__(self, master): QWidget.__init__(self) gui.OWComponent.__init__(self, master) self.master = master # Title bar. title_holder = QWidget() title_holder.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) title_holder.setStyleSheet(""" .QWidget { background: qlineargradient( x1:0 y1:0, x2:0 y2:1, stop:0 #F8F8F8, stop:1 #C8C8C8); border-bottom: 1px solid #B3B3B3; } """) self.titleArea = QHBoxLayout() self.titleArea.setContentsMargins(10, 5, 10, 5) self.titleArea.setSpacing(0) title_holder.setLayout(self.titleArea) self.title_label = QLabel(self.title) self.title_label.mouseDoubleClickEvent = self.on_toggle self.title_label.setStyleSheet('font-size: 12px; border: 2px solid red;') self.titleArea.addWidget(self.title_label) self.off_label = QLabel('[disabled]') self.off_label.setStyleSheet('color: #B0B0B0; margin-left: 5px;') self.titleArea.addWidget(self.off_label) self.off_label.hide() self.titleArea.addStretch() # Root. self.rootArea = QVBoxLayout() self.rootArea.setContentsMargins(0, 0, 0, 0) self.rootArea.setSpacing(0) self.setLayout(self.rootArea) self.rootArea.addWidget(title_holder) self.contents = QWidget() contentArea = QVBoxLayout() contentArea.setContentsMargins(15, 10, 15, 10) self.contents.setLayout(contentArea) self.rootArea.addWidget(self.contents) self.method_layout = self.Layout() self.setup_method_layout() self.contents.layout().addLayout(self.method_layout) if self.toggle_enabled: self.on_off_button = OnOffButton(enabled=self.enabled) self.on_off_button.stateChanged.connect(self.on_toggle) self.on_off_button.setContentsMargins(0, 0, 0, 0) self.titleArea.addWidget(self.on_off_button) self.display_widget() @staticmethod def get_tooltip(method): return ' '.join([l.strip() for l in method.__doc__.split('\n')]).strip('.') \ if method.__doc__ else None @staticmethod def textify(text): return text.replace('&', '&&') @property def value(self): if self.enabled: return self.get_value() return self.disabled_value def setup_method_layout(self): raise NotImplementedError def on_toggle(self, event=None): # Activated when the widget is enabled/disabled. self.enabled = not self.enabled self.display_widget() self.update_value() def display_widget(self): if self.enabled: self.off_label.hide() self.contents.show() self.title_label.setStyleSheet('color: #000000;') else: self.off_label.show() self.contents.hide() self.title_label.setStyleSheet('color: #B0B0B0;') def get_value(self): raise NotImplemented def update_value(self): self.change_signal.emit()
def __init__(self, parent=None): super().__init__(parent) self.geneMatcherSettings = [False, False, True, False] self.data = None self.referenceData = None self.taxid_list = [] self.__genematcher = (None, fulfill(gene.matcher([]))) self.__invalidated = False self.currentAnnotatedCategories = [] self.state = None self.__state = OWSetEnrichment.Initializing box = gui.widgetBox(self.controlArea, "Info") self.infoBox = gui.widgetLabel(box, "Info") self.infoBox.setText("No data on input.\n") self.speciesComboBox = gui.comboBox( self.controlArea, self, "speciesIndex", "Species", callback=self.__on_speciesIndexChanged) box = gui.widgetBox(self.controlArea, "Entity names") self.geneAttrComboBox = gui.comboBox(box, self, "geneattr", "Entity feature", sendSelectedValue=0, callback=self.updateAnnotations) cb = gui.checkBox(box, self, "genesinrows", "Use feature names", callback=self.updateAnnotations, disables=[(-1, self.geneAttrComboBox)]) cb.makeConsistent() # gui.button(box, self, "Gene matcher settings", # callback=self.updateGeneMatcherSettings, # tooltip="Open gene matching settings dialog") self.referenceRadioBox = gui.radioButtonsInBox( self.controlArea, self, "useReferenceData", ["All entities", "Reference set (input)"], tooltips=[ "Use entire genome (for gene set enrichment) or all " + "available entities for reference", "Use entities from Reference Examples input signal " + "as reference" ], box="Reference", callback=self.updateAnnotations) box = gui.widgetBox(self.controlArea, "Entity Sets") self.groupsWidget = QTreeWidget(self) self.groupsWidget.setHeaderLabels(["Category"]) box.layout().addWidget(self.groupsWidget) hLayout = QHBoxLayout() hLayout.setSpacing(10) hWidget = gui.widgetBox(self.mainArea, orientation=hLayout) gui.spin(hWidget, self, "minClusterCount", 0, 100, label="Entities", tooltip="Minimum entity count", callback=self.filterAnnotationsChartView, callbackOnReturn=True, checked="useMinCountFilter", checkCallback=self.filterAnnotationsChartView) pvalfilterbox = gui.widgetBox(hWidget, orientation="horizontal") cb = gui.checkBox(pvalfilterbox, self, "useMaxPValFilter", "p-value", callback=self.filterAnnotationsChartView) sp = gui.doubleSpin( pvalfilterbox, self, "maxPValue", 0.0, 1.0, 0.0001, tooltip="Maximum p-value", callback=self.filterAnnotationsChartView, callbackOnReturn=True, ) sp.setEnabled(self.useMaxFDRFilter) cb.toggled[bool].connect(sp.setEnabled) pvalfilterbox.layout().setAlignment(cb, Qt.AlignRight) pvalfilterbox.layout().setAlignment(sp, Qt.AlignLeft) fdrfilterbox = gui.widgetBox(hWidget, orientation="horizontal") cb = gui.checkBox(fdrfilterbox, self, "useMaxFDRFilter", "FDR", callback=self.filterAnnotationsChartView) sp = gui.doubleSpin( fdrfilterbox, self, "maxFDR", 0.0, 1.0, 0.0001, tooltip="Maximum False discovery rate", callback=self.filterAnnotationsChartView, callbackOnReturn=True, ) sp.setEnabled(self.useMaxFDRFilter) cb.toggled[bool].connect(sp.setEnabled) fdrfilterbox.layout().setAlignment(cb, Qt.AlignRight) fdrfilterbox.layout().setAlignment(sp, Qt.AlignLeft) self.filterLineEdit = QLineEdit(self, placeholderText="Filter ...") self.filterCompleter = QCompleter(self.filterLineEdit) self.filterCompleter.setCaseSensitivity(Qt.CaseInsensitive) self.filterLineEdit.setCompleter(self.filterCompleter) hLayout.addWidget(self.filterLineEdit) self.mainArea.layout().addWidget(hWidget) self.filterLineEdit.textChanged.connect( self.filterAnnotationsChartView) self.annotationsChartView = QTreeView( alternatingRowColors=True, sortingEnabled=True, selectionMode=QTreeView.ExtendedSelection, rootIsDecorated=False, editTriggers=QTreeView.NoEditTriggers, ) self.annotationsChartView.viewport().setMouseTracking(True) self.mainArea.layout().addWidget(self.annotationsChartView) contextEventFilter = gui.VisibleHeaderSectionContextEventFilter( self.annotationsChartView) self.annotationsChartView.header().installEventFilter( contextEventFilter) self.groupsWidget.itemClicked.connect(self.subsetSelectionChanged) gui.auto_commit(self.controlArea, self, "autocommit", "Commit") self.setBlocking(True) task = EnsureDownloaded([(taxonomy.Taxonomy.DOMAIN, taxonomy.Taxonomy.FILENAME), (geneset.sfdomain, "index.pck")]) task.finished.connect(self.__initialize_finish) self.setStatusMessage("Initializing") self._executor = ThreadExecutor(parent=self, threadPool=QThreadPool(self)) self._executor.submit(task)
def __init__(self, parent=None): super().__init__(parent) self.geneMatcherSettings = [False, False, True, False] self.data = None self.referenceData = None self.taxid_list = [] self.__genematcher = (None, fulfill(gene.matcher([]))) self.__invalidated = False self.currentAnnotatedCategories = [] self.state = None self.__state = OWSetEnrichment.Initializing box = gui.widgetBox(self.controlArea, "Info") self.infoBox = gui.widgetLabel(box, "Info") self.infoBox.setText("No data on input.\n") self.speciesComboBox = gui.comboBox( self.controlArea, self, "speciesIndex", "Species", callback=self.__on_speciesIndexChanged) box = gui.widgetBox(self.controlArea, "Entity names") self.geneAttrComboBox = gui.comboBox( box, self, "geneattr", "Entity feature", sendSelectedValue=0, callback=self.updateAnnotations) cb = gui.checkBox( box, self, "genesinrows", "Use feature names", callback=self.updateAnnotations, disables=[(-1, self.geneAttrComboBox)]) cb.makeConsistent() # gui.button(box, self, "Gene matcher settings", # callback=self.updateGeneMatcherSettings, # tooltip="Open gene matching settings dialog") self.referenceRadioBox = gui.radioButtonsInBox( self.controlArea, self, "useReferenceData", ["All entities", "Reference set (input)"], tooltips=["Use entire genome (for gene set enrichment) or all " + "available entities for reference", "Use entities from Reference Examples input signal " + "as reference"], box="Reference", callback=self.updateAnnotations) box = gui.widgetBox(self.controlArea, "Entity Sets") self.groupsWidget = QTreeWidget(self) self.groupsWidget.setHeaderLabels(["Category"]) box.layout().addWidget(self.groupsWidget) hLayout = QHBoxLayout() hLayout.setSpacing(10) hWidget = gui.widgetBox(self.mainArea, orientation=hLayout) gui.spin(hWidget, self, "minClusterCount", 0, 100, label="Entities", tooltip="Minimum entity count", callback=self.filterAnnotationsChartView, callbackOnReturn=True, checked="useMinCountFilter", checkCallback=self.filterAnnotationsChartView) pvalfilterbox = gui.widgetBox(hWidget, orientation="horizontal") cb = gui.checkBox( pvalfilterbox, self, "useMaxPValFilter", "p-value", callback=self.filterAnnotationsChartView) sp = gui.doubleSpin( pvalfilterbox, self, "maxPValue", 0.0, 1.0, 0.0001, tooltip="Maximum p-value", callback=self.filterAnnotationsChartView, callbackOnReturn=True, ) sp.setEnabled(self.useMaxFDRFilter) cb.toggled[bool].connect(sp.setEnabled) pvalfilterbox.layout().setAlignment(cb, Qt.AlignRight) pvalfilterbox.layout().setAlignment(sp, Qt.AlignLeft) fdrfilterbox = gui.widgetBox(hWidget, orientation="horizontal") cb = gui.checkBox( fdrfilterbox, self, "useMaxFDRFilter", "FDR", callback=self.filterAnnotationsChartView) sp = gui.doubleSpin( fdrfilterbox, self, "maxFDR", 0.0, 1.0, 0.0001, tooltip="Maximum False discovery rate", callback=self.filterAnnotationsChartView, callbackOnReturn=True, ) sp.setEnabled(self.useMaxFDRFilter) cb.toggled[bool].connect(sp.setEnabled) fdrfilterbox.layout().setAlignment(cb, Qt.AlignRight) fdrfilterbox.layout().setAlignment(sp, Qt.AlignLeft) self.filterLineEdit = QLineEdit( self, placeholderText="Filter ...") self.filterCompleter = QCompleter(self.filterLineEdit) self.filterCompleter.setCaseSensitivity(Qt.CaseInsensitive) self.filterLineEdit.setCompleter(self.filterCompleter) hLayout.addWidget(self.filterLineEdit) self.mainArea.layout().addWidget(hWidget) self.filterLineEdit.textChanged.connect( self.filterAnnotationsChartView) self.annotationsChartView = QTreeView( alternatingRowColors=True, sortingEnabled=True, selectionMode=QTreeView.ExtendedSelection, rootIsDecorated=False, editTriggers=QTreeView.NoEditTriggers, ) self.annotationsChartView.viewport().setMouseTracking(True) self.mainArea.layout().addWidget(self.annotationsChartView) contextEventFilter = gui.VisibleHeaderSectionContextEventFilter( self.annotationsChartView) self.annotationsChartView.header().installEventFilter(contextEventFilter) self.groupsWidget.itemClicked.connect(self.subsetSelectionChanged) gui.auto_commit(self.controlArea, self, "autocommit", "Commit") self.setBlocking(True) task = EnsureDownloaded( [(taxonomy.Taxonomy.DOMAIN, taxonomy.Taxonomy.FILENAME), (geneset.sfdomain, "index.pck")] ) task.finished.connect(self.__initialize_finish) self.setStatusMessage("Initializing") self._executor = ThreadExecutor( parent=self, threadPool=QThreadPool(self)) self._executor.submit(task)
def __init__(self): super().__init__() # OWWidget.__init__(self) ConcurrentWidgetMixin.__init__(self) # Control area box = vBox(self.controlArea, True, margin=0) self.gs_selection_component: GeneSetSelection = GeneSetSelection( self, box) self.gs_selection_component.selection_changed.connect( self._on_selection_changed) # Main area self.filter_proxy_model = FilterProxyModel() self.filter_proxy_model.setFilterKeyColumn(Header.term) self.tree_view = QTreeView() self.tree_view.setAlternatingRowColors(True) self.tree_view.setSortingEnabled(True) self.tree_view.sortByColumn(Header.count, Qt.DescendingOrder) self.tree_view.setSelectionMode(QTreeView.ExtendedSelection) self.tree_view.setEditTriggers(QTreeView.NoEditTriggers) self.tree_view.viewport().setMouseTracking(True) self.tree_view.setItemDelegateForColumn( Header.term, LinkStyledItemDelegate(self.tree_view)) self.tree_view.setItemDelegateForColumn(Header.genes, NumericalColumnDelegate(self)) self.tree_view.setItemDelegateForColumn(Header.count, NumericalColumnDelegate(self)) self.tree_view.setModel(self.filter_proxy_model) h_layout = QHBoxLayout() h_layout.setSpacing(100) h_widget = widgetBox(self.mainArea, orientation=h_layout) spin( h_widget, self, 'min_count', 0, 1000, label='Count', tooltip='Minimum genes count', checked='use_min_count', callback=self.filter_view, callbackOnReturn=True, checkCallback=self.filter_view, ) self.line_edit_filter = lineEdit(h_widget, self, 'search_pattern') self.line_edit_filter.setPlaceholderText('Filter gene sets ...') self.line_edit_filter.textChanged.connect(self.filter_view) self.mainArea.layout().addWidget(self.tree_view) self.tree_view.header().setSectionResizeMode( QHeaderView.ResizeToContents) self.commit_button = auto_commit(self.controlArea, self, 'auto_commit', '&Commit', box=False) self.input_data: Optional[Table] = None self.num_of_selected_genes: int = 0
class Screenshot(QDialog): def __init__(self, parent=None): super().__init__(parent, Qt.CustomizeWindowHint | Qt.FramelessWindowHint | Qt.Window | Qt.WindowStaysOnTopHint | Qt.X11BypassWindowManagerHint) self.setAttribute(Qt.WA_DeleteOnClose) self.installEventFilter(self) self.setMouseTracking(True) self._band = QRubberBand(QRubberBand.Rectangle, self) self._resize_origin = None self._drag_mask = 0 self._origin = None self.selected_image = None # Window background desktop = QApplication.desktop() if is_qt5(): g = desktop.geometry() self._snapshot = QPixmap(g.width(), g.height()) painter = QPainter(self._snapshot) for screen in QApplication.screens(): g = screen.geometry() painter.drawPixmap(g, screen.grabWindow(0, g.x(), g.y(), g.width(), g.height())) painter.end() else: self._snapshot = QPixmap.grabWindow(desktop.winId(), 0, 0, desktop.width(), desktop.height()) self.setGeometry(desktop.geometry()) self._darken = self._snapshot.copy() painter = QPainter(self._darken) brush = QBrush(QColor(0, 0, 0, 128)) painter.setBrush(brush) painter.drawRect(self._darken.rect()) painter.end() # Buttons self._buttons = QWidget(self) self._button_layout = QHBoxLayout(self._buttons) self._button_layout.setSpacing(0) self._button_layout.setContentsMargins(0, 0, 0, 0) self._button_layout.setContentsMargins(0, 0, 0, 0) self.save_as = QPushButton(self.tr('Save As')) self.save_as.pressed.connect(self.save_image_as) self.save_as.setCursor(Qt.ArrowCursor) self._button_layout.addWidget(self.save_as) self.copy = QPushButton(self.tr('Copy')) self.copy.pressed.connect(self.copy_to_clipboard) self.copy.setCursor(Qt.ArrowCursor) self._button_layout.addWidget(self.copy) self.share = QPushButton(self.tr('Share')) self.share.pressed.connect(self.share_selection) self.share.setCursor(Qt.ArrowCursor) self._button_layout.addWidget(self.share) self._buttons.hide() def paintEvent(self, _): painter = QPainter(self) painter.drawPixmap(0, 0, self._darken) if self._band.isVisible(): br = self._band.geometry() r = QRect(br.topLeft(), br.bottomRight()) painter.drawPixmap(r, self._snapshot.copy(r)) def get_selection(self): return self._snapshot.copy(self._band.geometry()) def save_image_as(self): img = self.get_selection().toImage() if img.isNull(): QMessageBox.critical(self, self.tr('Error'), self.tr('No image was selected!')) return self.hide() formats = { self.tr('Portable Network Graphics (*.png)'): 'png', self.tr('Joint Photographic Experts Group (*.jpg *.jpeg)'): 'jpg', self.tr('Graphics Interchange Format (*.gif)'): 'gif', self.tr('Bitmap (*.bmp)'): 'bmp', self.tr('All Images (*.png *.jpg *.gif *.bmp)'): 'all' } file_format = None destination = QFileDialog.getSaveFileName(self, 'Save image', '', ';;'.join(formats.keys())) if isinstance(destination, tuple): destination, file_format = destination file_format = formats[file_format] if file_format == 'all': file_format = None if not file_format: file_format = destination.rsplit('.', 1)[-1] if destination: if file_format not in formats.values(): file_format = 'png' if not destination.endswith('.' + file_format): destination += '.' + file_format img.save(destination, file_format, 0 if file_format == 'png' else 90) self.reject() def copy_to_clipboard(self): img = self.get_selection() if img.isNull(): QMessageBox.critical(self, self.tr('Error'), self.tr('No image was selected!')) return QApplication.clipboard().setPixmap(img) self.reject() def share_selection(self): self.selected_image = self.get_selection() self.accept() def eventFilter(self, obj, e): if e.type() == QEvent.Enter: self.activateWindow() if e.type() == QEvent.KeyPress and e.key() == Qt.Key_Escape: self.reject() return True return super().eventFilter(obj, e) def mousePressEvent(self, event): if self.update_cursor_shape(event.pos(), event.button() == Qt.LeftButton): self._resize_origin = event.pos() else: self._origin = event.pos() if not self._band.isVisible(): self._band.setGeometry(QRect(self._origin, self._origin)) self._band.show() super().mousePressEvent(event) def mouseMoveEvent(self, event): p = event.pos() mouse_down = event.buttons() & Qt.LeftButton if mouse_down: m = self._drag_mask wr = self.rect() if m: g = self._band.geometry() d = p - self._resize_origin if d.x() or d.y(): if m == RESIZE_DRAG: g.translate(d) else: if m & RESIZE_LEFT: g.translate(d.x(), 0) g.setWidth(g.width() - d.x()) elif m & RESIZE_RIGHT: g.setWidth(g.width() + d.x()) if m & RESIZE_TOP: g.translate(0, d.y()) g.setHeight(g.height() - d.y()) elif m & RESIZE_BOTTOM: g.setHeight(g.height() + d.y()) self._resize_origin = p # Contain in the screen px = min(max(g.topLeft().x(), 0), wr.width() - g.width()) py = min(max(g.topLeft().y(), 0), wr.height() - g.height()) g.moveTo(px, py) else: g = QRect(self._origin, p).normalized() self._band.setGeometry(g) br = self._band.geometry() x = (br.width() / 2 - self._buttons.width() / 2) + br.left() # buttons at center of band x = max(0, min(x, wr.width() - self._buttons.width())) # prevent going off-screen if (wr.height() - br.bottom()) > self._buttons.height(): # if at bottom y = br.bottom() else: y = max(0, br.top() - self._buttons.height()) self._buttons.move(x, y) self._buttons.show() self.repaint() else: self.update_cursor_shape(p, mouse_down) self._drag_mask = self.get_drag_mask(p) super().mouseMoveEvent(event) def mouseReleaseEvent(self, event): self.update_cursor_shape(event.pos(), False) super().mouseReleaseEvent(event) def update_cursor_shape(self, p, mouse_down): m = self.get_drag_mask(p) if m == RESIZE_DRAG: self.setCursor(Qt.ClosedHandCursor if mouse_down else Qt.OpenHandCursor) elif (m & RESIZE_LEFT and m & RESIZE_TOP) or (m & RESIZE_RIGHT and m & RESIZE_BOTTOM): self.setCursor(Qt.SizeFDiagCursor) elif (m & RESIZE_LEFT and m & RESIZE_BOTTOM) or (m & RESIZE_RIGHT and m & RESIZE_TOP): self.setCursor(Qt.SizeBDiagCursor) elif m & RESIZE_LEFT or m & RESIZE_RIGHT: self.setCursor(Qt.SizeHorCursor) elif m & RESIZE_TOP or m & RESIZE_BOTTOM: self.setCursor(Qt.SizeVerCursor) else: self.setCursor(Qt.ArrowCursor) return False return True def get_drag_mask(self, p): br = self._band.geometry() if br.contains(p): def is_hovering(x): return 0 <= x <= 10 m = 0 m |= RESIZE_LEFT if is_hovering(p.x() - br.left()) else 0 m |= RESIZE_RIGHT if is_hovering(br.right() - p.x()) else 0 m |= RESIZE_BOTTOM if is_hovering(br.bottom() - p.y()) else 0 m |= RESIZE_TOP if is_hovering(p.y() - br.top()) else 0 if m: return m return RESIZE_DRAG return 0