Ejemplo n.º 1
0
    def cb_mouse_motion(self, event):
        """
        Callback to process a mouse movement event.

        If the group selection option is enabled, then any points with
        Y-coordinate less than the cursor's Y-coordinate will be marked in a
        different opacity level, but not highlighted. If the user clicks with
        the mouse, then the points will be highlighted, but this event is
        processed in another method.

        This method also processes tooltip-related events when the group
        selection is disabled. If the user hovers the mouse cursor over a data
        point, then the name associated to that point will be shown in a
        tooltip.

        Parameters
        ----------
        event: matplotlib.backend_bases.MouseEvent
            Data about the event.
        """
        # We remove the horizonal line here (if any), regardless of the mouse
        # cursor position. We also restore the lines colors.
        if self._hthresh_line:
            for i, l in enumerate(self.axes.lines):
                if l == self._hthresh_line:
                    del self.axes.lines[i]
                    break
            self._hthresh_line = None

            for i, line in enumerate(self.axes.lines):
                if self._is_normal_curve_idx(i):
                    line.set_color(self._curves_colors[i])

        if self._ts_line:
            for i, l in enumerate(self.axes.lines):
                if l == self._ts_line:
                    del self.axes.lines[i]
                    break

        # Restoring the lines' widths.
        if self._plotted_series:
            for art in self._plotted_series:
                if not art:
                    continue
                art[0].set_linewidth(self._plot_params['linewidth'])

        self.draw()

        if event.xdata is None or event.ydata is None or self._rank_series is None:
            return True

        self._ts_line = self.axes.axvline(x=event.xdata, c='b', ls='--')

        # If the group selection is enabled, we show a preview of all curves
        # that will be highlighted should the user click the mouse button.
        if self.group_selection_enabled:
            ts = int(event.xdata - self.time_range[0] + 0.5)
            if self.rank_inverted:
                for i, series in enumerate(self._rank_series):
                    if series[ts] < event.ydata and self._is_normal_curve_idx(
                            i):
                        self.axes.lines[i].set_color(cm.gray(200))
            else:
                for i, series in enumerate(self._rank_series):
                    if series[ts] > event.ydata and self._is_normal_curve_idx(
                            i):
                        self.axes.lines[i].set_color(cm.gray(200))

            self._hthresh_line = self.axes.axhline(y=event.ydata,
                                                   c='b',
                                                   linewidth=2)
        else:
            hover_idx = None
            for i, art in enumerate(self._plotted_series):
                if not art:
                    continue
                contains, _ = art[0].contains(event)
                if contains:
                    art[0].set_linewidth(self._plot_params['linewidth'] * 2)
                    if not self.curvenames or i > len(self.curvenames):
                        return False
                    hover_idx = i
                    break

            if hover_idx is not None:
                palette = QPalette()
                palette.setColor(QPalette.ToolTipBase, QColor(252, 243, 207))
                palette.setColor(QPalette.ToolTipText, QColor(0, 0, 0))
                QToolTip.setPalette(palette)
                QToolTip.setFont(QFont('Arial', 14, QFont.Bold))
                pos = self.mapToGlobal(QPoint(event.x,
                                              self.height() - event.y))
                QToolTip.showText(pos, '{}'.format(self.curvenames[hover_idx]))
            else:
                QToolTip.hideText()
                self.update()

            if self._cb_notify_tooltip:
                self._cb_notify_tooltip(self.name, hover_idx)

        self.draw()
    def cb_mouse_motion(self, event):
        """
        Callback to process a mouse movement event.

        If the group selection option is enabled, then any points with
        Y-coordinate less than the cursor's Y-coordinate will be marked in a
        different opacity level, but not highlighted. If the user clicks with
        the mouse, then the points will be highlighted, but this event is
        processed in another method.

        This method also processes tooltip-related events when the group
        selection is disabled. If the user hovers the mouse cursor over a data
        point, then the name associated to that point will be shown in a
        tooltip.

        Parameters
        ----------
        event: matplotlib.backend_bases.MouseEvent
            Data about the event.
        """
        # We remove the horizonal line here (if any), regardless of the mouse
        # cursor position. We also restore the points colors.
        if self._hthresh_line:
            lines = self.axes.get_lines()
            for l in lines:
                self.axes.lines.remove(l)
                del l

            self._hthresh_line = None

            for i, p in enumerate(self.axes.collections):
                if i not in self._reference_idx:
                    p.set_facecolor(self._points_colors[i])
            self.draw()

        # Restoring the points' original size.
        if self._point_artists:
            for art in self._point_artists:
                if art is None:
                    continue
                art.set_sizes([self._plot_params['s']])

        if event.xdata is None or event.ydata is None or self._points is None:
            return False
        if self.group_selection_enabled:
            # We must get only the points above the cursor.
            diff = self._points - event.ydata
            above = []
            above = [i for i in reversed(self._yidx_points) if diff[i] >= 0]

            for a in above:
                if a in self._reference_idx:
                    continue
                self.axes.collections[a].set_facecolor(cm.gray(200))

                self._hthresh_line = self.axes.axhline(y=event.ydata,
                                                       c='b',
                                                       linewidth=2)
        else:
            # Testing if the cursor is over a point. If it is, we plot the
            # tooltip and notify this event by calling the registered
            # callback, if any.
            if not self.curvenames:
                return False
            else:
                hover_idx = None
                for i, art in enumerate(self._point_artists):
                    if not art:
                        continue
                    contains, _ = art.contains(event)
                    if contains:
                        art.set_sizes([self._plot_params['s'] * 3])
                        if i > len(self.curvenames):
                            return False
                        hover_idx = i
                        break

                if hover_idx is not None:
                    palette = QPalette()
                    palette.setColor(QPalette.ToolTipBase,
                                     QColor(252, 243, 207))
                    palette.setColor(QPalette.ToolTipText, QColor(0, 0, 0))
                    QToolTip.setPalette(palette)
                    QToolTip.setFont(QFont('Arial', 14, QFont.Bold))
                    pos = self.mapToGlobal(
                        QPoint(event.x,
                               self.height() - event.y))
                    QToolTip.showText(pos,
                                      '{}'.format(self.curvenames[hover_idx]))
                else:
                    QToolTip.hideText()

                if self._cb_notify_tooltip:
                    self._cb_notify_tooltip(self.name, hover_idx)

        self.draw()
Ejemplo n.º 3
0
    def cb_mouse_motion(self, event):
        """
        Callback to process a mouse movement event.

        If a point is hit by the mouse cursor, we query its index and notify
        the parent object. The parent object must then notify the fanchart (or
        any plot with a time based X axis) in order to highlight the time.

        Parameters
        ----------
        event: matplotlib.backend_bases.MouseEvent
            Data about the event.
        """
        # Restoting the original parameters.
        if self.plot_points:
            for art in self.axes.collections:
                art.set_sizes([self.point_plot_params['s']])
        if self.plot_lines:
            for art in self.axes.lines:
                art.set_linewidth(self.line_plot_params['linewidth'])

        # If the event is outside the axes, we call the timestep callback to
        # notify anyone.
        if event.xdata is None or event.ydata is None:
            if self._cb_notify_timestep:
                self._cb_notify_timestep(self.name, None)
            return False

        if not self._tree:
            return False

        _, idx = self._tree.query(np.array([event.xdata, event.ydata]))

        # Since we need only the time-step, we just take the remainder of the
        # index / number_of_curves, which gives us the timestep selected.
        pidx = math.ceil(idx / self.curves.shape[1]) - 1
        timestep = idx % self.curves.shape[1]

        art = None
        if self.plot_lines:
            art = self.axes.lines
        elif self.plot_points:
            art = self.axes.collections
        if not art:
            return True

        contains, _ = art[pidx].contains(event)

        if contains:
            if self.curvenames:
                if self.plot_points:
                    art = self.axes.collections[pidx]
                    art.set_sizes([self.point_plot_params['s'] * 3])
                if self.plot_lines:
                    art = self.axes.lines[pidx]
                    art.set_linewidth(self.line_plot_params['linewidth'] * 2)

                palette = QPalette()
                palette.setColor(QPalette.ToolTipBase, QColor(252, 243, 207))
                palette.setColor(QPalette.ToolTipText, QColor(0, 0, 0))
                QToolTip.setPalette(palette)
                QToolTip.setFont(QFont('Arial', 14, QFont.Bold))
                pos = self.mapToGlobal(QPoint(event.x,
                                              self.height() - event.y))
                QToolTip.showText(pos, '{}'.format(self.curvenames[pidx]))

                if self._cb_notify_tooltip:
                    self._cb_notify_tooltip(self.name, pidx)

            if self._cb_notify_timestep:
                self._cb_notify_timestep(self.name, timestep + 1)
        else:
            if self._cb_notify_tooltip:
                self._cb_notify_tooltip(self.name, None)
            if self._cb_notify_timestep:
                self._cb_notify_timestep(self.name, None)
            QToolTip.hideText()

        self.draw()
Ejemplo n.º 4
0
    def updateAppearance(self):
        fonts = ["Crimson Pro", "Fontawesome"]
        for font in fonts:
            for file in Hilfsmethoden.listdir(os.path.join("Data", "Fonts", font)):
                if file.endswith(".ttf"):
                    QtGui.QFontDatabase.addApplicationFont(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data", "Fonts", font, file))

        fontSize = Wolke.Settings['FontSize']
        fontFamily = Wolke.Settings['Font']
        if fontFamily:
            font = QtGui.QFontDatabase().font(fontFamily, "Regular", fontSize)
            self.app.setFont(font)
        else:
            font = self.app.font()
            font.setPointSize(fontSize)
            self.app.setFont(font)

        Wolke.FontHeadingSizeL1 = Wolke.Settings["FontHeadingSize"] + 1
        Wolke.FontHeadingSizeL3 = Wolke.Settings["FontSize"] + 2

        style = Wolke.Settings['Theme']
        if style == "Windows Vista":
            self.app.setStyle("windowsvista")
            palette = self.app.style().standardPalette()
            self.app.setPalette(palette)
            QToolTip.setPalette(self.app.style().standardPalette())
            Wolke.HeadingColor = "#000000"
            Wolke.BorderColor = "rgba(0,0,0,0.2)"
            self.buildStylesheet("#ffffff", Wolke.HeadingColor, Wolke.BorderColor)
        elif style == "Fusion Light":
            self.app.setStyle('fusion')
            palette = self.app.style().standardPalette()
            palette.setColor(QPalette.ToolTipBase, QtCore.Qt.white)
            palette.setColor(QPalette.ToolTipText, QtCore.Qt.black)
            self.app.setPalette(palette)
            QToolTip.setPalette(palette)
            Wolke.HeadingColor = "#000000"
            Wolke.BorderColor = "rgba(0,0,0,0.2)"
            self.buildStylesheet("#ffffff", Wolke.HeadingColor, Wolke.BorderColor)
        elif style == "Fusion Dark":
            self.app.setStyle('fusion')
            palette = QPalette()
            palette.setColor(QPalette.Window, QColor(53, 53, 53))
            palette.setColor(QPalette.WindowText, QtCore.Qt.white)
            palette.setColor(QPalette.Base, QColor(25, 25, 25))
            palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
            palette.setColor(QPalette.ToolTipBase, QtCore.Qt.black)
            palette.setColor(QPalette.ToolTipText, QtCore.Qt.white)
            palette.setColor(QPalette.Text, QtCore.Qt.white)
            palette.setColor(QPalette.Button, QColor(53, 53, 53))
            palette.setColor(QPalette.ButtonText, QtCore.Qt.white)
            palette.setColor(QPalette.BrightText, QtCore.Qt.white)
            palette.setColor(QPalette.Link, QColor(42, 130, 218))
            palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
            palette.setColor(QPalette.HighlightedText, QtCore.Qt.black)
            palette.setColor(QPalette.Active, QPalette.Button, QColor(53, 53, 53))
            palette.setColor(QPalette.Disabled, QPalette.ButtonText, QtCore.Qt.darkGray)
            palette.setColor(QPalette.Disabled, QPalette.WindowText, QtCore.Qt.darkGray)
            palette.setColor(QPalette.Disabled, QPalette.Text, QtCore.Qt.darkGray)
            palette.setColor(QPalette.Disabled, QPalette.HighlightedText, QtCore.Qt.darkGray)
            palette.setColor(QPalette.Disabled, QPalette.Base, QColor(53, 53, 53))
            self.app.setPalette(palette)
            QToolTip.setPalette(palette)
            Wolke.HeadingColor = "#ffffff"
            Wolke.BorderColor = "rgba(255,255,255,0.2)"
            self.buildStylesheet("#434343", Wolke.HeadingColor, Wolke.BorderColor)
        elif style == "Ilaris":
            self.app.setStyle('fusion')

            palette = QPalette()
            colors = {
                "box" : QColor("#d1be9d"),
                "bg": QColor("#f1e6ce"),
                "heading" : QColor("#4A000B"),
                "text": QColor("#221E1F"),
                "table": QColor("#e8c5a9"),
                "bg_bestiarium" : QColor("#f7e5cd"),
                "bg_dark" : QColor("#e4d0a5"),
                "text_dark": QColor("#7a561c")
            }

            palette.setColor(QPalette.Window, colors["bg"])
            palette.setColor(QPalette.WindowText, colors["text"])
            palette.setColor(QPalette.Base, colors["bg"])
            palette.setColor(QPalette.AlternateBase, colors["table"])
            palette.setColor(QPalette.ToolTipBase, colors["bg"])
            palette.setColor(QPalette.ToolTipText, colors["text"])
            palette.setColor(QPalette.Text, colors["text"])
            palette.setColor(QPalette.Button, colors["bg_dark"])
            palette.setColor(QPalette.ButtonText, colors["text"])
            palette.setColor(QPalette.BrightText, colors["text"])
            palette.setColor(QPalette.Link, colors["heading"])
            palette.setColor(QPalette.Highlight, colors["box"])
            palette.setColor(QPalette.HighlightedText, colors["text"])
            #palette.setColor(QPalette.Active, QPalette.Button, colors["box"])
            palette.setColor(QPalette.Disabled, QPalette.ButtonText, colors["text_dark"])
            palette.setColor(QPalette.Disabled, QPalette.WindowText, colors["text_dark"])
            palette.setColor(QPalette.Disabled, QPalette.Text, colors["text_dark"])
            palette.setColor(QPalette.Disabled, QPalette.HighlightedText, colors["text_dark"])
            palette.setColor(QPalette.Disabled, QPalette.Base, colors["bg_dark"])
            self.app.setPalette(palette)
            QToolTip.setPalette(palette)
            Wolke.HeadingColor = "#4A000B"
            Wolke.BorderColor = "rgba(0,0,0,0.2)"
            self.buildStylesheet("#e4d0a5", Wolke.HeadingColor, Wolke.BorderColor, "#d1bd94")
        elif style == "DSA Forum":
            self.app.setStyle('fusion')
            palette = QPalette()
            # DSA-Forum colors (picked from screenshot)
            colors = {
                "bg_light": QColor("#f6efe2"),
                "bg": QColor("#f1e2c3"),
                "bg_dark": QColor("#cdad74"),  # bg braun (hover tabs) 
                "button": QColor("#dcc484"),  # tabs buttons rahmen
                "text": QColor("#000000"),
                "text_dark": QColor("#7a561c"),
                "alert": QColor("#ae0007"),  # text rot
            }
            palette.setColor(QPalette.Window, colors["bg"])
            palette.setColor(QPalette.WindowText, colors["text"])
            palette.setColor(QPalette.Base, colors["bg"])
            palette.setColor(QPalette.AlternateBase, colors["bg_light"])
            palette.setColor(QPalette.ToolTipBase, colors["bg"])
            palette.setColor(QPalette.ToolTipText, colors["text"])
            palette.setColor(QPalette.Text, colors["text"])
            palette.setColor(QPalette.Button, colors["button"])
            palette.setColor(QPalette.ButtonText, colors["text"])
            palette.setColor(QPalette.BrightText, colors["text"])
            palette.setColor(QPalette.Link, colors["text_dark"])
            palette.setColor(QPalette.Highlight, colors["bg_dark"])
            palette.setColor(QPalette.HighlightedText, colors["text"])
            #palette.setColor(QPalette.Active, QPalette.Button, colors["alert"])
            palette.setColor(QPalette.Disabled, QPalette.ButtonText, colors["text_dark"])
            palette.setColor(QPalette.Disabled, QPalette.WindowText, colors["text_dark"])
            palette.setColor(QPalette.Disabled, QPalette.Text, colors["text_dark"])
            palette.setColor(QPalette.Disabled, QPalette.HighlightedText, colors["text_dark"])
            palette.setColor(QPalette.Disabled, QPalette.Base, colors["bg_dark"])
            self.app.setPalette(palette)
            QToolTip.setPalette(palette)
            Wolke.HeadingColor = "#000000"
            Wolke.BorderColor = "rgba(0,0,0,0.2)"
            self.buildStylesheet("#dcc484", Wolke.HeadingColor, Wolke.BorderColor)