コード例 #1
0
    def mouseMoved(self, evt):
        pos = evt[0]
        if self.plot.sceneBoundingRect().contains(pos):
            mousePoint = self.plot.vb.mapSceneToView(pos)
            posx, posy = mousePoint.x(), mousePoint.y()

            labels = []
            for a, vs in sorted(self.reports.items()):
                for v in vs:
                    if isinstance(v, tuple) and len(v) == 2:
                        if v[0] == "x":
                            labels.append(
                                ("%0." + str(self.important_decimals[0]) + "f")
                                % v[1])
                            continue
                    labels.append(str(v))
            labels = " ".join(labels)
            self.crosshair_hidden = bool(labels)

            if self.location and not labels:
                fs = "%0." + str(self.important_decimals[0]) + "f %0." + str(
                    self.important_decimals[1]) + "f"
                labels = fs % (posx, posy)
            self.label.setText(labels, color=(0, 0, 0))

            if self.curves and len(self.curves[0][0]):  # need non-zero x axis!
                cache = {}
                bd = None
                if self.markclosest and self.plot.vb.action != ZOOMING:
                    xpixel, ypixel = self.plot.vb.viewPixelSize()
                    distances = distancetocurves(self.curves[0],
                                                 posx,
                                                 posy,
                                                 xpixel,
                                                 ypixel,
                                                 r=self.MOUSE_RADIUS,
                                                 cache=cache)
                    try:
                        mindi = np.nanargmin(distances)
                        if distances[mindi] < self.MOUSE_RADIUS:
                            bd = mindi
                    except ValueError:  # if all distances are NaN
                        pass
                if self.highlighted != bd:
                    QToolTip.hideText()
                if self.highlighted is not None and bd is None:
                    self.highlighted = None
                    self.highlighted_curve.hide()
                if bd is not None:
                    self.highlighted = bd
                    x = self.curves[0][0]
                    y = self.curves[0][1][self.highlighted]
                    self.highlighted_curve.setData(x=x, y=y)
                    self.highlighted_curve.show()

            self.vLine.setPos(posx)
            self.hLine.setPos(posy)
            self.viewhelpers_show()
        else:
            self.viewhelpers_hide()
コード例 #2
0
ファイル: completer.py プロジェクト: szzyiit/orange3
    def hide(self):
        """Override Qt method."""
        self.completion_position = None
        self.completion_list = None
        self.clear()
        self.textedit.setFocus()
        tooltip = getattr(self.textedit, 'tooltip_widget', None)
        if tooltip:
            tooltip.hide()

        QListWidget.hide(self)
        QToolTip.hideText()
コード例 #3
0
 def event(self, event):
     # type: (QEvent) -> bool
     if event.type() == QEvent.ToolTip and self.toolTip():
         action = self.defaultAction()
         if action is not None:
             text = "<span>{}</span>&nbsp;&nbsp;<kbd>{}</kbd>".format(
                 action.toolTip(),
                 action.shortcut().toString(QKeySequence.NativeText))
             QToolTip.showText(event.globalPos(), text)
         else:
             QToolTip.hideText()
         return True
     else:
         return super().event(event)
コード例 #4
0
ファイル: oweditdomain.py プロジェクト: lanzagar/orange3
 def event(self, event):
     # type: (QEvent) -> bool
     if event.type() == QEvent.ToolTip and self.toolTip():
         action = self.defaultAction()
         if action is not None:
             text = "<span>{}</span>&nbsp;&nbsp;<kbd>{}</kbd>".format(
                 action.toolTip(),
                 action.shortcut().toString(QKeySequence.NativeText)
             )
             QToolTip.showText(event.globalPos(), text)
         else:
             QToolTip.hideText()
         return True
     else:
         return super().event(event)
コード例 #5
0
 def test_tool_tips(self):
     scene = GraphicsScene()
     view = QGraphicsView(scene)
     w = TextListWidget()
     text = "A" * 10
     w.setItems([text, text])
     scene.addItem(w)
     view.grab()  # ensure w is laid out
     wrect = view.mapFromScene(w.mapToScene(
         w.contentsRect())).boundingRect()
     p = QPoint(wrect.topLeft() + QPoint(5, 5))
     ev = QHelpEvent(QHelpEvent.ToolTip, p, view.viewport().mapToGlobal(p))
     try:
         QApplication.sendEvent(view.viewport(), ev)
         self.assertEqual(QToolTip.text(), text)
     finally:
         QToolTip.hideText()
コード例 #6
0
    def event(self, ev):
        if ev.type() == QEvent.ToolTip:
            x = self.inv_transform(xBottom, ev.pos().x())
            y = self.inv_transform(yLeft, ev.pos().y())

            canvas_position = self.mapToScene(ev.pos())
            x_float = self.inv_transform(xBottom, canvas_position.x())
            contact, (index,
                      pos) = self.testArrowContact(int(round(x_float)),
                                                   canvas_position.x(),
                                                   canvas_position.y())
            if contact:
                attr = self.domain[self.attributes[index]]
                if attr.is_continuous:
                    condition = self.selection_conditions.get(
                        attr.name, [0, 1])
                    val = self.attr_values[attr][0] + condition[pos] * (
                        self.attr_values[attr][1] - self.attr_values[attr][0])
                    str_val = attr.name + "= %%.%df" % attr.number_of_decimals % val
                    QToolTip.showText(ev.globalPos(), str_val)
            else:
                for curve in self.items():
                    if type(curve) == PolygonCurve and \
                            curve.boundingRect().contains(x, y) and \
                            getattr(curve, "tooltip", None):
                        (name, value, total, dist) = curve.tooltip
                        count = sum([v[1] for v in dist])
                        if count == 0:
                            continue
                        tooltip_text = "Attribute: <b>%s</b><br>Value: <b>%s</b><br>" \
                                       "Total instances: <b>%i</b> (%.1f%%)<br>" \
                                       "Class distribution:<br>" % (
                                           name, value, count, 100.0 * count / float(total))
                        for (val, n) in dist:
                            tooltip_text += "&nbsp; &nbsp; <b>%s</b> : <b>%i</b> (%.1f%%)<br>" % (
                                val, n, 100.0 * float(n) / float(count))
                        QToolTip.showText(ev.globalPos(), tooltip_text[:-4])

        elif ev.type() == QEvent.MouseMove:
            QToolTip.hideText()

        return OWPlot.event(self, ev)
コード例 #7
0
    def event(self, ev):
        if ev.type() == QEvent.ToolTip:
            x = self.inv_transform(xBottom, ev.pos().x())
            y = self.inv_transform(yLeft, ev.pos().y())

            canvas_position = self.mapToScene(ev.pos())
            x_float = self.inv_transform(xBottom, canvas_position.x())
            contact, (index, pos) = self.testArrowContact(int(round(x_float)), canvas_position.x(),
                                                          canvas_position.y())
            if contact:
                attr = self.domain[self.attributes[index]]
                if attr.is_continuous:
                    condition = self.selection_conditions.get(attr.name, [0, 1])
                    val = self.attr_values[attr][0] + condition[pos] * (
                        self.attr_values[attr][1] - self.attr_values[attr][0])
                    str_val = attr.name + "= %%.%df" % attr.number_of_decimals % val
                    QToolTip.showText(ev.globalPos(), str_val)
            else:
                for curve in self.items():
                    if type(curve) == PolygonCurve and \
                            curve.boundingRect().contains(x, y) and \
                            getattr(curve, "tooltip", None):
                        (name, value, total, dist) = curve.tooltip
                        count = sum([v[1] for v in dist])
                        if count == 0:
                            continue
                        tooltip_text = "Attribute: <b>%s</b><br>Value: <b>%s</b><br>" \
                                       "Total instances: <b>%i</b> (%.1f%%)<br>" \
                                       "Class distribution:<br>" % (
                                           name, value, count, 100.0 * count / float(total))
                        for (val, n) in dist:
                            tooltip_text += "&nbsp; &nbsp; <b>%s</b> : <b>%i</b> (%.1f%%)<br>" % (
                                val, n, 100.0 * float(n) / float(count))
                        QToolTip.showText(ev.globalPos(), tooltip_text[:-4])

        elif ev.type() == QEvent.MouseMove:
            QToolTip.hideText()

        return OWPlot.event(self, ev)