Skip to content

Commit

Permalink
Scatterplot: Add drag selection tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Mar 3, 2017
1 parent b161f9d commit e27ddd1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import itertools
from xml.sax.saxutils import escape
from math import log10, floor, ceil
Expand All @@ -7,7 +8,8 @@
from AnyQt.QtCore import Qt, QObject, QEvent, QRectF, QPointF, QSize
from AnyQt.QtGui import (
QStaticText, QColor, QPen, QBrush, QPainterPath, QTransform, QPainter)
from AnyQt.QtWidgets import QApplication, QToolTip, QPinchGesture
from AnyQt.QtWidgets import QApplication, QToolTip, QPinchGesture, \
QGraphicsTextItem, QGraphicsRectItem

import pyqtgraph as pg
from pyqtgraph.graphicsItems.ViewBox import ViewBox
Expand Down Expand Up @@ -354,12 +356,17 @@ def mouseDragEvent(self, ev, axis=None):
pos = ev.pos()
if ev.button() == Qt.LeftButton:
self.safe_update_scale_box(ev.buttonDownPos(), ev.pos())
scene = self.scene()
dragtip = scene.drag_tooltip
if ev.isFinish():
dragtip.hide()
self.rbScaleBox.hide()
pixel_rect = QRectF(ev.buttonDownPos(ev.button()), pos)
value_rect = self.childGroup.mapRectFromParent(pixel_rect)
self.graph.select_by_rectangle(value_rect)
else:
dragtip.setPos(10, self.height() + 3)
dragtip.show() # although possibly already shown
self.safe_update_scale_box(ev.buttonDownPos(), ev.pos())
elif self.graph.state == ZOOMING or self.graph.state == PANNING:
ev.ignore()
Expand Down Expand Up @@ -489,6 +496,19 @@ def __init__(self, scatter_widget, parent=None, _="None"):
self.plot_widget.getPlotItem().buttonsHidden = True
self.plot_widget.setAntialiasing(True)
self.plot_widget.sizeHint = lambda: QSize(500, 500)
scene = self.plot_widget.scene()

text = QGraphicsTextItem(
"Shift: add group, Shift-{0}: append to group, "
"Alt: remove, {0}: switch".
format("Cmd" if sys.platform == "darwin" else "Ctrl"))
text.setPos(4, 2)
r = text.boundingRect()
rect = QGraphicsRectItem(0, 0, r.width() + 8, r.height() + 4)
rect.setBrush(QColor(192, 192, 192, 128))
rect.setPen(QPen(Qt.NoPen))
scene.drag_tooltip = scene.createItemGroup([rect, text])
scene.drag_tooltip.hide()

self.replot = self.plot_widget.replot
ScaleScatterPlotData.__init__(self)
Expand Down

0 comments on commit e27ddd1

Please sign in to comment.