Exemple #1
0
    def OnPaint(self, event):
        rect = self.GetClientRect()
        dc = wx.BufferedPaintDC(self)
        dc.SetBackground(wx.Brush(self.bkColor))
        dc.Clear()

        value = float(self.value)
        if self.percS >= 100:
            w = rect.width
        else:
            w = rect.width * (float(value) / 100)
        r = copy.copy(rect)
        r.width = w

        color = colorUtils.CalculateTransitionColor(self.colorS, self.colorE,
                                                    float(value) / 100)
        if self.gradientStart > 0:
            gcolor = colorUtils.BrightenColor(color,
                                              float(self.gradientStart) / 100)
            gMid = colorUtils.BrightenColor(
                color,
                float(self.gradientStart / 2) / 100)
        else:
            gcolor = colorUtils.DarkenColor(color,
                                            float(-self.gradientStart) / 100)
            gMid = colorUtils.DarkenColor(color,
                                          float(-self.gradientStart / 2) / 100)

        gBmp = drawUtils.DrawGradientBar(r.width, r.height, gMid, color,
                                         gcolor)
        dc.DrawBitmap(gBmp, 0, 0)
        dc.SetFont(self.font)

        r = copy.copy(rect)
        r.left += 1
        r.top += 1

        formatStr = "{0:." + str(self._fractionDigits) + "f}%"
        value = (self.percE - self.percS) * value / (self.percE - self.percS)
        value = self.percS + (self.percE - self.percS) * value / 100

        dc.SetTextForeground(wx.Colour(80, 80, 80))
        dc.DrawLabel(formatStr.format(value), r, wx.ALIGN_CENTER)

        dc.SetTextForeground(wx.Colour(255, 255, 255))
        dc.DrawLabel(formatStr.format(value), rect, wx.ALIGN_CENTER)
Exemple #2
0
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for L{PyGauge}.

        :param event: a `wx.PaintEvent` event to be processed.
        """

        dc = wx.BufferedPaintDC(self)
        rect = self.GetClientRect()

        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()

        colour = self.GetBackgroundColour()

        dc.SetBrush(wx.Brush(colour))
        dc.SetPen(wx.Pen(colour))

        dc.DrawRectangleRect(rect)

        value = self._percentage
        if self._timer:
            if self._timer.IsRunning():
                value = self._animValue

        if self._border_colour:
            dc.SetPen(wx.Pen(self.GetBorderColour()))
            dc.DrawRectangleRect(rect)
            pad = 1 + self.GetBorderPadding()
            rect.Deflate(pad, pad)

        if self.GetBarGradient():

            if value > 100:
                w = rect.width
            else:
                w = rect.width * (float(value) / 100)
            r = copy.copy(rect)
            r.width = w

            if r.width > 0:
                # If we draw it with zero width, GTK throws errors. This way,
                # only draw it if the gauge will actually show something.
                # We stick other calculations in this block to avoid wasting
                # time on them if not needed. See GH issue #282

                pv = value

                if pv <= 100:
                    xv = pv / 100
                    transition = 0

                elif pv <= 101:
                    xv = pv - 100
                    transition = 1

                elif pv <= 103:
                    xv = (pv - 101) / 2
                    transition = 2

                elif pv <= 105:
                    xv = (pv - 103) / 2
                    transition = 3

                else:
                    pv = 106
                    xv = pv - 100
                    transition = -1

                if transition != -1:
                    colorS, colorE = self.transitionsColors[transition]
                    color = colorUtils.CalculateTransitionColor(
                        colorS, colorE, xv)
                else:
                    color = wx.Colour(191, 48, 48)

                if self.gradientEffect > 0:
                    gcolor = colorUtils.BrightenColor(
                        color,
                        float(self.gradientEffect) / 100)
                    gMid = colorUtils.BrightenColor(
                        color,
                        float(self.gradientEffect / 2) / 100)
                else:
                    gcolor = colorUtils.DarkenColor(
                        color,
                        float(-self.gradientEffect) / 100)
                    gMid = colorUtils.DarkenColor(
                        color,
                        float(-self.gradientEffect / 2) / 100)

                gBmp = drawUtils.DrawGradientBar(r.width, r.height, gMid,
                                                 color, gcolor)
                dc.DrawBitmap(gBmp, r.left, r.top)

        else:
            colour = self.GetBarColour()
            dc.SetBrush(wx.Brush(colour))
            dc.SetPen(wx.Pen(colour))
            if value > 100:
                w = rect.width
            else:
                w = rect.width * (float(value) / 100)
            r = copy.copy(rect)
            r.width = w
            dc.DrawRectangleRect(r)

        dc.SetFont(self.font)

        r = copy.copy(rect)
        r.left += 1
        r.top += 1
        if self._range == 0.01 and self._value > 0:
            formatStr = u'\u221e'
            dc.SetTextForeground(wx.Colour(80, 80, 80))
            dc.DrawLabel(formatStr, r, wx.ALIGN_CENTER)

            dc.SetTextForeground(wx.Colour(255, 255, 255))
            dc.DrawLabel(formatStr, rect, wx.ALIGN_CENTER)
        else:
            if self.GetBarGradient() and self._showRemaining:
                range = self._range if self._range > 0.01 else 0
                value = range - self._value
                if value < 0:
                    label = "over"
                    value = -value
                else:
                    label = "left"
                formatStr = "{0:." + str(self._fractionDigits) + "f} " + label

            else:
                formatStr = "{0:." + str(self._fractionDigits) + "f}%"

            dc.SetTextForeground(wx.Colour(80, 80, 80))
            dc.DrawLabel(formatStr.format(value), r, wx.ALIGN_CENTER)

            dc.SetTextForeground(wx.Colour(255, 255, 255))
            dc.DrawLabel(formatStr.format(value), rect, wx.ALIGN_CENTER)
Exemple #3
0
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for L{PyGauge}.

        :param `event`: a `wx.PaintEvent` event to be processed.
        """

        dc = wx.BufferedPaintDC(self)
        rect = self.GetClientRect()

        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()

        colour = self.GetBackgroundColour()

        dc.SetBrush(wx.Brush(colour))
        dc.SetPen(wx.Pen(colour))

        dc.DrawRectangleRect(rect)

        value = self._percentage
        if self._timer:
            if self._timer.IsRunning():
                value = self._animValue

        if self._border_colour:
            dc.SetPen(wx.Pen(self.GetBorderColour()))
            dc.DrawRectangleRect(rect)
            pad = 1 + self.GetBorderPadding()
            rect.Deflate(pad, pad)

        if self.GetBarGradient():

            if value > 100:
                w = rect.width
            else:
                w = rect.width * (float(value) / 100)
            r = copy.copy(rect)
            r.width = w

            pv = value
            xv = 1
            transition = 0

            if pv <= 100:
                xv = pv / 100
                transition = 0

            elif pv <= 101:
                xv = pv - 100
                transition = 1

            elif pv <= 103:
                xv = (pv - 101) / 2
                transition = 2

            elif pv <= 105:
                xv = (pv - 103) / 2
                transition = 3

            else:
                pv = 106
                xv = pv - 100
                transition = -1

            if transition != -1:
                colorS, colorE = self.transitionsColors[transition]
                color = colorUtils.CalculateTransitionColor(colorS, colorE, xv)
            else:
                color = wx.Colour(191, 48, 48)

            if self.gradientEffect > 0:
                gcolor = colorUtils.BrightenColor(
                    color,
                    float(self.gradientEffect) / 100)
                gMid = colorUtils.BrightenColor(
                    color,
                    float(self.gradientEffect / 2) / 100)
            else:
                gcolor = colorUtils.DarkenColor(
                    color,
                    float(-self.gradientEffect) / 100)
                gMid = colorUtils.DarkenColor(
                    color,
                    float(-self.gradientEffect / 2) / 100)

            gBmp = drawUtils.DrawGradientBar(r.width, r.height, gMid, color,
                                             gcolor)
            dc.DrawBitmap(gBmp, r.left, r.top)
        else:
            colour = self.GetBarColour()
            dc.SetBrush(wx.Brush(colour))
            dc.SetPen(wx.Pen(colour))
            if value > 100:
                w = rect.width
            else:
                w = rect.width * (float(value) / 100)
            r = copy.copy(rect)
            r.width = w
            dc.DrawRectangleRect(r)

        dc.SetFont(self.font)

        r = copy.copy(rect)
        r.left += 1
        r.top += 1
        if self._range == 0.01 and self._value > 0:
            formatStr = u'\u221e'
            dc.SetTextForeground(wx.Colour(80, 80, 80))
            dc.DrawLabel(formatStr, r, wx.ALIGN_CENTER)

            dc.SetTextForeground(wx.Colour(255, 255, 255))
            dc.DrawLabel(formatStr, rect, wx.ALIGN_CENTER)
        else:
            if self.GetBarGradient() and self._showRemaining:
                formatStr = "{0:." + str(self._fractionDigits) + "f} left"
                range = self._range if self._range > 0.01 else 0
                value = max(range - self._value, 0)
            else:
                formatStr = "{0:." + str(self._fractionDigits) + "f}%"

            dc.SetTextForeground(wx.Colour(80, 80, 80))
            dc.DrawLabel(formatStr.format(value), r, wx.ALIGN_CENTER)

            dc.SetTextForeground(wx.Colour(255, 255, 255))
            dc.DrawLabel(formatStr.format(value), rect, wx.ALIGN_CENTER)