예제 #1
0
    def _draw_gradient(self, dc, rect):
        """ Draw a vertical gradient background, using the background colour as a starting point
        """

        if rect.height < 1 or rect.width < 1:
            return

        dc.SetPen(wx.TRANSPARENT_PEN)

        # calculate gradient coefficients

        bck_col = wxcol_to_frgb(self.Parent.GetBackgroundColour())
        if self._mouse_hovering:
            col1 = change_brightness(bck_col, 0.15)
            col2 = change_brightness(bck_col, 0.10)
        else:
            col1 = change_brightness(bck_col, 0.10)
            col2 = bck_col

        r1, g1, b1 = col1
        r2, g2, b2 = col2
        rstep = (r2 - r1) / rect.height
        gstep = (g2 - g1) / rect.height
        bstep = (b2 - b1) / rect.height

        rf, gf, bf = col1
        for y in range(rect.y, rect.y + rect.height):
            cur_col = (rf * 255, gf * 255, bf * 255)
            dc.SetBrush(wx.Brush(cur_col, wx.BRUSHSTYLE_SOLID))
            dc.DrawRectangle(rect.x, rect.y + (y - rect.y), rect.width, rect.height)
            rf = rf + rstep
            gf = gf + gstep
            bf = bf + bstep
예제 #2
0
    def _draw_gradient(self, dc, rect):
        """ Draw a vertical gradient background, using the background colour as a starting point
        """

        if rect.height < 1 or rect.width < 1:
            return

        dc.SetPen(wx.TRANSPARENT_PEN)

        # calculate gradient coefficients

        bck_col = wxcol_to_frgb(self.Parent.GetBackgroundColour())
        if self._mouse_hovering:
            col1 = change_brightness(bck_col, 0.15)
            col2 = change_brightness(bck_col, 0.10)
        else:
            col1 = change_brightness(bck_col, 0.10)
            col2 = bck_col

        r1, g1, b1 = col1
        r2, g2, b2 = col2
        rstep = (r2 - r1) / rect.height
        gstep = (g2 - g1) / rect.height
        bstep = (b2 - b1) / rect.height

        rf, gf, bf = col1
        for y in range(rect.y, rect.y + rect.height):
            cur_col = (rf * 255, gf * 255, bf * 255)
            dc.SetBrush(wx.Brush(cur_col, wx.BRUSHSTYLE_SOLID))
            dc.DrawRectangle(rect.x, rect.y + (y - rect.y), rect.width,
                             rect.height)
            rf = rf + rstep
            gf = gf + gstep
            bf = bf + bstep
예제 #3
0
    def test_change_brightness(self):
        # no change
        col = (0.2, 0.5, 1.0, 0.8)
        ncol = conversion.change_brightness(col, 0)
        self.assertEqual(col, ncol)

        # brighten
        col = (0.2, 0.5, 1.0, 0.8)
        ncol = conversion.change_brightness(col, 0.3)
        self.assertTrue(all(n >= o for o, n in zip(col, ncol)))

        # darken
        col = (0.2, 0.5, 1.0)
        ncol = conversion.change_brightness(col, -0.6)
        self.assertTrue(all(n < o for o, n in zip(col, ncol)))

        # full black
        col = (0.2, 0.5, 1.0, 1.0)
        ncol = conversion.change_brightness(col, -1)
        self.assertTrue(ncol, (0, 0, 0, 1))
예제 #4
0
    def test_change_brightness(self):
        # no change
        col = (0.2, 0.5, 1.0, 0.8)
        ncol = conversion.change_brightness(col, 0)
        self.assertEqual(col, ncol)

        # brighten
        col = (0.2, 0.5, 1.0, 0.8)
        ncol = conversion.change_brightness(col, 0.3)
        self.assertTrue(all(n >= o for o, n in zip(col, ncol)))

        # darken
        col = (0.2, 0.5, 1.0)
        ncol = conversion.change_brightness(col, -0.6)
        self.assertTrue(all(n < o for o, n in zip(col, ncol)))

        # full black
        col = (0.2, 0.5, 1.0, 1.0)
        ncol = conversion.change_brightness(col, -1)
        self.assertTrue(ncol, (0, 0, 0, 1))
예제 #5
0
파일: slider.py 프로젝트: delmic/odemis
    def OnPaint(self, event=None):
        """ This paint event handler draws the actual control """
        dc = wx.BufferedPaintDC(self)
        width, height = self.GetWidth(), self.GetHeight()
        half_height = height // 2

        bgc = self.Parent.GetBackgroundColour()
        dc.SetBackground(wx.Brush(bgc, wx.BRUSHSTYLE_SOLID))
        dc.Clear()

        fgc = self.Parent.GetForegroundColour()

        if not self.Enabled:
            fgc = change_brightness(fgc, -0.5)

        dc.SetPen(wx.Pen(fgc, 1))

        # Main line
        dc.DrawLine(self.half_h_width, half_height, width - self.half_h_width, half_height)

        # ticks
        steps = [v / 10 for v in range(1, 10)]
        range_span = self.max_value - self.min_value
        for s in steps:
            v = (range_span * s) + self.min_value
            pix_x = self._val_to_pixel(v) + self.half_h_width
            dc.DrawLine(pix_x, half_height - 1,
                        pix_x, half_height + 2)

        if self.Enabled:
            dc.DrawBitmap(self.bitmap,
                          self.handlePos,
                          half_height - self.half_h_height,
                          True)
        else:
            dc.DrawBitmap(self.bitmap_dis,
                          self.handlePos,
                          half_height - self.half_h_height,
                          True)

        event.Skip()
예제 #6
0
    def OnPaint(self, event=None):
        """ This paint event handler draws the actual control """
        dc = wx.BufferedPaintDC(self)
        width, height = self.GetWidth(), self.GetHeight()
        half_height = height // 2

        bgc = self.Parent.GetBackgroundColour()
        dc.SetBackground(wx.Brush(bgc, wx.BRUSHSTYLE_SOLID))
        dc.Clear()

        fgc = self.Parent.GetForegroundColour()

        if not self.Enabled:
            fgc = change_brightness(fgc, -0.5)

        dc.SetPen(wx.Pen(fgc, 1))

        # Main line
        dc.DrawLine(self.half_h_width, half_height, width - self.half_h_width, half_height)

        # ticks
        steps = [v / 10 for v in range(1, 10)]
        range_span = self.max_value - self.min_value
        for s in steps:
            v = (range_span * s) + self.min_value
            pix_x = self._val_to_pixel(v) + self.half_h_width
            dc.DrawLine(pix_x, half_height - 1,
                        pix_x, half_height + 2)

        if self.Enabled:
            dc.DrawBitmap(self.bitmap,
                          self.handlePos,
                          half_height - self.half_h_height,
                          True)
        else:
            dc.DrawBitmap(self.bitmap_dis,
                          self.handlePos,
                          half_height - self.half_h_height,
                          True)

        event.Skip()