def __autoScrollAdvance(self): """Advance the auto scroll """ pos = QCursor.pos() pos = self.mapFromGlobal(pos) margin = self.__autoScrollMargin vvalue = self.verticalScrollBar().value() hvalue = self.horizontalScrollBar().value() vrect = QRect(0, 0, self.width(), self.height()) # What should be the speed advance = 10 # We only do auto scroll if the mouse is inside the view. if vrect.contains(pos): if pos.x() < vrect.left() + margin: self.horizontalScrollBar().setValue(hvalue - advance) if pos.y() < vrect.top() + margin: self.verticalScrollBar().setValue(vvalue - advance) if pos.x() > vrect.right() - margin: self.horizontalScrollBar().setValue(hvalue + advance) if pos.y() > vrect.bottom() - margin: self.verticalScrollBar().setValue(vvalue + advance) if self.verticalScrollBar().value() == vvalue and \ self.horizontalScrollBar().value() == hvalue: self.__stopAutoScroll() else: self.__stopAutoScroll() log.debug("Auto scroll advance")
def __autoScrollAdvance(self): """Advance the auto scroll """ pos = QCursor.pos() pos = self.mapFromGlobal(pos) margin = self.__autoScrollMargin vvalue = self.verticalScrollBar().value() hvalue = self.horizontalScrollBar().value() vrect = QRect(0, 0, self.width(), self.height()) # What should be the speed advance = 10 # We only do auto scroll if the mouse is inside the view. if vrect.contains(pos): if pos.x() < vrect.left() + margin: self.horizontalScrollBar().setValue(hvalue - advance) if pos.y() < vrect.top() + margin: self.verticalScrollBar().setValue(vvalue - advance) if pos.x() > vrect.right() - margin: self.horizontalScrollBar().setValue(hvalue + advance) if pos.y() > vrect.bottom() - margin: self.verticalScrollBar().setValue(vvalue + advance) if self.verticalScrollBar().value() == vvalue and \ self.horizontalScrollBar().value() == hvalue: self.__stopAutoScroll() else: self.__stopAutoScroll() log.debug("Auto scroll advance")
def dropEvent(self, event): """Reimplemented.""" layout = self.__flowlayout index = self.__insertIndexAt(self.mapFromGlobal(QCursor.pos())) if event.mimeData().hasFormat("application/x-internal-move") and \ event.source() is self: # Complete the internal move frame, oldindex, _ = self.__dragstart # Remove the drop indicator spacer item before re-inserting # the frame self.__setDropIndicatorAt(None) if index > oldindex: index = index - 1 if index != oldindex: item = layout.takeAt(oldindex) assert item.widget() is frame layout.insertWidget(index, frame) self.widgetMoved.emit(oldindex, index) event.accept() self.__dragstart = None, None, None
def dropEvent(self, event): """Reimplemented.""" layout = self.__flowlayout index = self.__insertIndexAt(self.mapFromGlobal(QCursor.pos())) if event.mimeData().hasFormat("application/x-internal-move") and \ event.source() is self: # Complete the internal move frame, oldindex, _ = self.__dragstart # Remove the drop indicator spacer item before re-inserting # the frame self.__setDropIndicatorAt(None) if index > oldindex: index = index - 1 if index != oldindex: item = layout.takeAt(oldindex) assert item.widget() is frame layout.insertWidget(index, frame) self.widgetMoved.emit(oldindex, index) event.accept() self.__dragstart = None, None, None
def _on_mouse_moved(self, pos): target = self.target_index selected = self.selected_classifiers curves = [(clf_idx, self.plot_curves(target, clf_idx)) for clf_idx in selected ] # type: List[Tuple[int, PlotCurves]] valid_thresh, valid_clf = [], [] pt, ave_mode = None, self.roc_averaging for clf_idx, crv in curves: if self.roc_averaging == OWROCAnalysis.Merge: curve = crv.merge() elif self.roc_averaging == OWROCAnalysis.Vertical: curve = crv.avg_vertical() elif self.roc_averaging == OWROCAnalysis.Threshold: curve = crv.avg_threshold() else: # currently not implemented for 'Show Individual Curves' return sp = curve.curve_item.childItems()[0] # type: pg.ScatterPlotItem act_pos = sp.mapFromScene(pos) pts = sp.pointsAt(act_pos) if pts: mouse_pt = pts[0].pos() if self._tooltip_cache: cache_pt, cache_thresh, cache_clf, cache_ave = self._tooltip_cache curr_thresh, curr_clf = [], [] if np.linalg.norm(mouse_pt - cache_pt) < 10e-6 \ and cache_ave == self.roc_averaging: mask = np.equal(cache_clf, clf_idx) curr_thresh = np.compress(mask, cache_thresh).tolist() curr_clf = np.compress(mask, cache_clf).tolist() else: QToolTip.showText(QCursor.pos(), "") self._tooltip_cache = None if curr_thresh: valid_thresh.append(*curr_thresh) valid_clf.append(*curr_clf) pt = cache_pt continue curve_pts = curve.curve.points roc_points = np.column_stack((curve_pts.fpr, curve_pts.tpr)) diff = np.subtract(roc_points, mouse_pt) # Find closest point on curve and save the corresponding threshold idx_closest = np.argmin(np.linalg.norm(diff, axis=1)) thresh = curve_pts.thresholds[idx_closest] if not np.isnan(thresh): valid_thresh.append(thresh) valid_clf.append(clf_idx) pt = [ curve_pts.fpr[idx_closest], curve_pts.tpr[idx_closest] ] if valid_thresh: clf_names = self.classifier_names msg = "Thresholds:\n" + "\n".join([ "({:s}) {:.3f}".format(clf_names[i], thresh) for i, thresh in zip(valid_clf, valid_thresh) ]) QToolTip.showText(QCursor.pos(), msg) self._tooltip_cache = (pt, valid_thresh, valid_clf, ave_mode)
def initStyleOptionForIndex(self, option: QStyleOptionHeader, logicalIndex: int) -> None: """ Similar to initStyleOptionForIndex in Qt 6.0 with the difference that `isSectionSelected` is not used, only `sectionIntersectsSelection` is used (isSectionSelected will scan the entire model column/row when the whole column/row is selected). """ hover = self.logicalIndexAt(self.mapFromGlobal(QCursor.pos())) pressed = self.__pressed if self.highlightSections(): is_selected = self.__sectionIntersectsSelection else: is_selected = lambda _: False state = QStyle.State_None if self.isEnabled(): state |= QStyle.State_Enabled if self.window().isActiveWindow(): state |= QStyle.State_Active if self.sectionsClickable(): if logicalIndex == hover: state |= QStyle.State_MouseOver if logicalIndex == pressed: state |= QStyle.State_Sunken if self.highlightSections(): if is_selected(logicalIndex): state |= QStyle.State_On if self.isSortIndicatorShown() and \ self.sortIndicatorSection() == logicalIndex: option.sortIndicator = ( QStyleOptionHeader.SortDown if self.sortIndicatorOrder() == Qt.AscendingOrder else QStyleOptionHeader.SortUp) style = self.style() model = self.model() orientation = self.orientation() textAlignment = model.headerData(logicalIndex, self.orientation(), Qt.TextAlignmentRole) defaultAlignment = self.defaultAlignment() textAlignment = (textAlignment if isinstance(textAlignment, int) else defaultAlignment) option.section = logicalIndex option.state = QStyle.State(int(option.state) | int(state)) option.textAlignment = Qt.Alignment(int(textAlignment)) option.iconAlignment = Qt.AlignVCenter text = model.headerData(logicalIndex, self.orientation(), Qt.DisplayRole) text = str(text) if text is not None else "" option.text = text icon = model.headerData(logicalIndex, self.orientation(), Qt.DecorationRole) try: option.icon = QIcon(icon) except (TypeError, ValueError): # pragma: no cover pass margin = 2 * style.pixelMetric(QStyle.PM_HeaderMargin, None, self) headerArrowAlignment = style.styleHint(QStyle.SH_Header_ArrowAlignment, None, self) isHeaderArrowOnTheSide = headerArrowAlignment & Qt.AlignVCenter if self.isSortIndicatorShown() and \ self.sortIndicatorSection() == logicalIndex \ and isHeaderArrowOnTheSide: margin += style.pixelMetric(QStyle.PM_HeaderMarkSize, None, self) if not option.icon.isNull(): margin += style.pixelMetric(QStyle.PM_SmallIconSize, None, self) margin += style.pixelMetric(QStyle.PM_HeaderMargin, None, self) if self.textElideMode() != Qt.ElideNone: elideMode = self.textElideMode() if hasattr(option, 'textElideMode'): # Qt 6.0 option.textElideMode = elideMode # pragma: no cover else: option.text = option.fontMetrics.elidedText( option.text, elideMode, option.rect.width() - margin) foregroundBrush = model.headerData(logicalIndex, orientation, Qt.ForegroundRole) try: foregroundBrush = QBrush(foregroundBrush) except (TypeError, ValueError): pass else: option.palette.setBrush(QPalette.ButtonText, foregroundBrush) backgroundBrush = model.headerData(logicalIndex, orientation, Qt.BackgroundRole) try: backgroundBrush = QBrush(backgroundBrush) except (TypeError, ValueError): pass else: option.palette.setBrush(QPalette.Button, backgroundBrush) option.palette.setBrush(QPalette.Window, backgroundBrush) # the section position visual = self.visualIndex(logicalIndex) assert visual != -1 first = self.__isFirstVisibleSection(visual) last = self.__isLastVisibleSection(visual) if first and last: option.position = QStyleOptionHeader.OnlyOneSection elif first: option.position = QStyleOptionHeader.Beginning elif last: option.position = QStyleOptionHeader.End else: option.position = QStyleOptionHeader.Middle option.orientation = orientation # the selected position (in QHeaderView this is always computed even if # highlightSections is False). if self.highlightSections(): previousSelected = is_selected(self.logicalIndex(visual - 1)) nextSelected = is_selected(self.logicalIndex(visual + 1)) else: previousSelected = nextSelected = False if previousSelected and nextSelected: option.selectedPosition = QStyleOptionHeader.NextAndPreviousAreSelected elif previousSelected: option.selectedPosition = QStyleOptionHeader.PreviousIsSelected elif nextSelected: option.selectedPosition = QStyleOptionHeader.NextIsSelected else: option.selectedPosition = QStyleOptionHeader.NotAdjacent
def dragMoveEvent(self, event): """Reimplemented.""" pos = self.mapFromGlobal(QCursor.pos()) self.__setDropIndicatorAt(pos)
def position(self): return QPointF(self.view.mapFromGlobal(QCursor.pos()))
def show_tray_menu(self): self._menu.popup(QCursor.pos())
def _on_mouse_moved(self, pos): target = self.target_index selected = self.selected_classifiers curves = [(clf_idx, self.plot_curves(target, clf_idx)) for clf_idx in selected] # type: List[Tuple[int, plot_curves]] valid_thresh, valid_clf = [], [] pt, ave_mode = None, self.roc_averaging for clf_idx, crv in curves: if self.roc_averaging == OWROCAnalysis.Merge: curve = crv.merge() elif self.roc_averaging == OWROCAnalysis.Vertical: curve = crv.avg_vertical() elif self.roc_averaging == OWROCAnalysis.Threshold: curve = crv.avg_threshold() else: # currently not implemented for 'Show Individual Curves' return sp = curve.curve_item.childItems()[0] # type: pg.ScatterPlotItem act_pos = sp.mapFromScene(pos) pts = sp.pointsAt(act_pos) if len(pts) > 0: mouse_pt = pts[0].pos() if self._tooltip_cache: cache_pt, cache_thresh, cache_clf, cache_ave = self._tooltip_cache curr_thresh, curr_clf = [], [] if numpy.linalg.norm(mouse_pt - cache_pt) < 10e-6 \ and cache_ave == self.roc_averaging: mask = numpy.equal(cache_clf, clf_idx) curr_thresh = numpy.compress(mask, cache_thresh).tolist() curr_clf = numpy.compress(mask, cache_clf).tolist() else: QToolTip.showText(QCursor.pos(), "") self._tooltip_cache = None if curr_thresh: valid_thresh.append(*curr_thresh) valid_clf.append(*curr_clf) pt = cache_pt continue curve_pts = curve.curve.points roc_points = numpy.column_stack((curve_pts.fpr, curve_pts.tpr)) diff = numpy.subtract(roc_points, mouse_pt) # Find closest point on curve and save the corresponding threshold idx_closest = numpy.argmin(numpy.linalg.norm(diff, axis=1)) thresh = curve_pts.thresholds[idx_closest] if not numpy.isnan(thresh): valid_thresh.append(thresh) valid_clf.append(clf_idx) pt = [curve_pts.fpr[idx_closest], curve_pts.tpr[idx_closest]] if valid_thresh: clf_names = self.classifier_names msg = "Thresholds:\n" + "\n".join(["({:s}) {:.3f}".format(clf_names[i], thresh) for i, thresh in zip(valid_clf, valid_thresh)]) QToolTip.showText(QCursor.pos(), msg) self._tooltip_cache = (pt, valid_thresh, valid_clf, ave_mode)
def dragMoveEvent(self, event): """Reimplemented.""" pos = self.mapFromGlobal(QCursor.pos()) self.__setDropIndicatorAt(pos)