コード例 #1
0
ファイル: renderer.py プロジェクト: pingleewu/ShareRoot
    def createLinearGradientBrush(x1,y1,x2,y2, stops, spreadMethod='pad',
                                  transforms=None, units='userSpaceOnUse'):

        stops = numpy.transpose(stops)

        def convert_stop(stop):
            offset, red, green, blue, opacity = stop
            color = wx.Colour(red*255, green*255, blue*255, opacity*255)
            return offset, color

        if wx.VERSION > (2,9):        
            # wxPython 2.9+ supports a collection of stops
            wx_stops = wx.GraphicsGradientStops()
            for stop in stops:
                offset, color = convert_stop(stop)
                wx_stops.Add(color, offset)
        
            wx_renderer = wx.GraphicsRenderer.GetDefaultRenderer()
            return wx_renderer.CreateLinearGradientBrush(x1, y1, x2, y2, wx_stops)
        
        else:        
            if len(stops) > 2:
                warnings.warn("wxPython 2.8 only supports 2 gradient stops, but %d were specified" % len(stops))
    
            start_offset, start_color = convert_stop(stops[0])
            end_offset, end_color = convert_stop(stops[1])
    
            wx_renderer = wx.GraphicsRenderer.GetDefaultRenderer()
            return wx_renderer.CreateLinearGradientBrush(x1, y1, x2, y2,
                                                         start_color, end_color)
コード例 #2
0
ファイル: renderer.py プロジェクト: alexlib/enable
    def createRadialGradientBrush(cx,
                                  cy,
                                  r,
                                  stops,
                                  fx=None,
                                  fy=None,
                                  spreadMethod="pad",
                                  transforms=None,
                                  units="userSpaceOnUse"):

        stops = numpy.transpose(stops)

        def convert_stop(stop):
            offset, red, green, blue, opacity = stop
            color = wx.Colour(red * 255, green * 255, blue * 255,
                              opacity * 255)
            return offset, color

        wx_stops = wx.GraphicsGradientStops()
        for stop in stops:
            offset, color = convert_stop(stop)
            wx_stops.Add(color, offset)

        wx_renderer = wx.GraphicsRenderer.GetDefaultRenderer()
        return wx_renderer.CreateRadialGradientBrush(fx, fy, cx, cy, r,
                                                     wx_stops)
コード例 #3
0
    def __init__(self, parent):
        self.parent = parent
        wx.lib.scrolledpanel.ScrolledPanel.__init__(self,
                                                    parent,
                                                    -1,
                                                    style=wx.VSCROLL
                                                    | wx.SUNKEN_BORDER)

        ## Stops to use in fitmap drawing code.
        white_full = wx.Colour(255, 255, 255, 255)
        white_zero = wx.Colour(255, 255, 255, 0)
        #black_zero = wx.Colour(0,0,0,0)
        c = 255
        ucl = wx.Colour(c, c, c, 255)
        ucd = wx.Colour(c - 38, c - 40, c - 41, 255)

        lbrown = wx.Colour(238, 235, 234, 255)

        self.gstops = {
            "white_to_alpha":
            wx.GraphicsGradientStops(startCol=white_zero, endCol=white_full),
            "baptiste":
            wx.GraphicsGradientStops(startCol=lbrown, endCol=white_full),
            "underline":
            wx.GraphicsGradientStops(startCol=ucd, endCol=ucl)
        }
        self.gstops["white_to_alpha"].Add(wx.Colour(255, 255, 255, 128), 0.5)
        self.gstops["underline"].Add(ucd, 0.4)

        self.SetBackgroundColour(white_full)

        self.wheelValue = fpsys.config.points
        self.Bind(wx.EVT_MOUSEWHEEL, self.onWheel)

        ## July 2016
        ## Sep 2017. New hacks. Might not need this...
        #self.Bind(wx.EVT_SIZE, self.onSize)

        self.fitmap_sizer = wx.FlexGridSizer(cols=1, vgap=0, hgap=0)
        self.SetSizer(self.fitmap_sizer)
        #self.Fit()

        self.SetupScrolling(rate_y=5, scroll_x=False)

        ps.sub(reset_top_left_adjustments,
               self.ResetTopLeftAdjustFlag)  ##DND: class ScrolledFontView
コード例 #4
0
ファイル: __init__.py プロジェクト: vvs31415/Phoenix
 def _makeGradientStops(self, gradient):
     stops = [stop for stop in gradient.stops]
     first = stops[0]
     last = stops[-1]
     gcstops = wx.GraphicsGradientStops(wx.Colour(*first.color_rgba),
                                        wx.Colour(*last.color_rgba))
     for stop in stops:
         color = wx.Colour(*stop.color_rgba)
         gcstop = wx.GraphicsGradientStop(color, stop.offset)
         gcstops.Add(gcstop)
     return gcstops
コード例 #5
0
 def _PaintPreview(self, event: wx.PaintEvent):
     dc = wx.PaintDC(self._preview)
     gc = wx.GraphicsContext.Create(dc)
     if not gc: return
     gc.SetBrush(GetPatternBrush())
     it = wx.RegionIterator(self._preview.GetUpdateRegion())
     while it.HaveRects():
         rect = it.GetRect()
         gc.DrawRectangle(rect.x, rect.y, rect.width, rect.height)
         it.Next()
     rect = self._preview.GetClientRect()
     asStops = self.GetGradientAsStops()
     stops = wx.GraphicsGradientStops(asStops[0][0], asStops[-1][0])
     for col, pos in asStops[1:-1]:
         stops.Add(col, pos)
     brush = gc.CreateLinearGradientBrush(0, 0, rect.GetWidth() - 1, 0, stops)
     gc.SetBrush(brush)
     gc.DrawRectangle(0, 0, rect.GetWidth(), rect.GetHeight())
コード例 #6
0
    def test_gcGradientStops(self):
        gs1 = wx.GraphicsGradientStop('red', 0.25)
        gs2 = wx.GraphicsGradientStop('green', 0.50)
        gs3 = wx.GraphicsGradientStop('blue', 0.90)

        gs1.Colour
        gs1.Position

        stops = wx.GraphicsGradientStops()
        stops.Add(gs1)
        stops.Add(gs2)
        stops.Add('white', 0.75)
        stops.Add(gs3)

        self.assertEqual(len(stops), 6)  # 2 existing, plus 4 added
        gs = stops[2]
        self.assertTrue(gs.Position == 0.5)

        gc = wx.GraphicsContext.Create(self.frame)
        b = gc.CreateLinearGradientBrush(0, 0, 500, 100, stops)
コード例 #7
0
    def OnPaint(self, _):

        width, height = self._handler.size

        if width <= 0 or height <= 0:
            bmp = wx.EmptyBitmapRGBA(1, 1)
            pdc = wx.PaintDC(self)
            gcdc = wx.GCDC(pdc)
            gcdc.DrawBitmap(bmp, 0, 0)

            gcdc.Destroy()
            del gcdc

            self._startup = None
            return

        bmp = wx.EmptyBitmapRGBA(width, height)

        dc = wx.MemoryDC()
        dc.SelectObject(bmp)
        gc = wx.GraphicsContext.Create(dc)
        gcdc = wx.GCDC(gc)

        gcdc.SetBrush(wx.Brush(self.GetBackgroundColour()))
        gcdc.SetPen(wx.TRANSPARENT_PEN)

        gcdc.DrawRectangle(0, 0, width, height)

        def draw_circle(x, y, r, _gcdc):
            _gcdc.DrawEllipse(int(round(float(x) - r)),
                              int(round(float(y) - r)), int(round(r * 2.0)),
                              int(round(r * 2.0)))

        gcdc.SetBrush(wx.TRANSPARENT_BRUSH)
        x_center, y_center = self._handler.center

        gcdc.SetPen(wx.TRANSPARENT_PEN)
        radius = self._handler.radius

        if self._handler.shadow:
            # shadow
            stops = wx.GraphicsGradientStops()
            stops.Add(wx.GraphicsGradientStop(wx.TransparentColour, 0.45))
            stops.Add(wx.GraphicsGradientStop(wx.Colour(0, 0, 0, 255), 0.25))

            stops.SetStartColour(wx.Colour(0, 0, 0, 255))
            stops.SetEndColour(wx.TransparentColour)

            gc.SetBrush(
                gc.CreateRadialGradientBrush(x_center + (radius * 0.10),
                                             y_center + (radius * 0.10),
                                             x_center + (radius * 0.30),
                                             y_center + (radius * 0.30),
                                             radius * 2.3, stops))

            draw_circle(x_center + (radius * 0.10), y_center + (radius * 0.10),
                        radius * 2, gcdc)

            # eliminate any shadow under the knob just in case there is a color
            # used in the gradient of the knob that does not have an alpha level of 255

            gc.SetBrush(wx.Brush(self.GetBackgroundColour()))
            draw_circle(x_center, y_center, radius - 2, gcdc)

        if self._handler.glow:
            _ = self._handler.tick_list
            neon_colour = self._handler.neon_colour

            stops = wx.GraphicsGradientStops()

            stops.Add(wx.GraphicsGradientStop(wx.TransparentColour, 0.265))
            stops.Add(
                wx.GraphicsGradientStop(wx.Colour(*neon_colour + (255, )),
                                        0.25))
            stops.Add(wx.GraphicsGradientStop(wx.TransparentColour, 0.248))

            stops.SetStartColour(wx.TransparentColour)
            stops.SetEndColour(wx.TransparentColour)

            gc.SetBrush(
                gc.CreateRadialGradientBrush(x_center, y_center, x_center,
                                             y_center, radius * 4, stops))

            draw_circle(x_center, y_center, radius * 2, gcdc)

        # outside ring of volume knob

        gc.SetBrush(
            gc.CreateRadialGradientBrush(x_center - radius, y_center - radius,
                                         x_center, y_center - radius,
                                         radius * 2,
                                         self._handler.secondary_colour,
                                         self._handler.primary_colour))

        draw_circle(x_center, y_center, radius, gcdc)

        thumb_x, thumb_y = self._handler.thumb_position
        thumb_radius = self._handler.thumb_radius

        # inside of volume knob
        if self._handler.depression:
            center_radius = self._handler.center_radius
            gc.SetBrush(
                gc.CreateRadialGradientBrush(
                    x_center + center_radius, y_center + center_radius,
                    x_center, y_center + center_radius, center_radius * 2,
                    self._handler.secondary_colour,
                    self._handler.primary_colour))

            draw_circle(x_center, y_center, center_radius, gcdc)

        if self._last_degrees is None:
            self._last_degrees = _remap(self._handler.value,
                                        self._handler.min_value,
                                        self._handler.max_value, 135.0, 405.0)

        # handle of the volume knob
        gc.SetBrush(
            gc.CreateRadialGradientBrush(thumb_x + thumb_radius,
                                         thumb_y + thumb_radius, thumb_x,
                                         thumb_y + thumb_radius,
                                         thumb_radius * 2,
                                         self._handler.secondary_colour,
                                         self._handler.primary_colour))

        draw_circle(thumb_x, thumb_y, thumb_radius, gcdc)

        if self._handler.thumb_glow:
            _ = self._handler.tick_list
            neon_colour = self._handler.neon_colour

            stops = wx.GraphicsGradientStops()

            stops.Add(wx.GraphicsGradientStop(wx.TransparentColour, 0.355))
            stops.Add(
                wx.GraphicsGradientStop(wx.Colour(*neon_colour + (255, )),
                                        0.28))
            stops.Add(wx.GraphicsGradientStop(wx.TransparentColour, 0.258))

            stops.SetStartColour(wx.TransparentColour)
            stops.SetEndColour(wx.TransparentColour)

            gc.SetBrush(
                gc.CreateRadialGradientBrush(thumb_x, thumb_y, thumb_x,
                                             thumb_y, thumb_radius * 4, stops))

            draw_circle(thumb_x, thumb_y, thumb_radius * 2, gcdc)

        gcdc.SetBrush(wx.TRANSPARENT_BRUSH)

        # draw the tick marks
        if self._handler.ticks:
            ticks = []
            pens = []
            for _, pen, coords in self._handler.tick_list:
                ticks += [coords]
                pens += [pen]

            gcdc.DrawLineList(ticks, pens)

        dc.SelectObject(wx.EmptyBitmap(1, 1))
        gcdc.Destroy()
        del gcdc

        dc.Destroy()
        del dc

        # create a buffered paint dc to draw the bmp to the client area
        pdc = wx.PaintDC(self)
        gcdc = wx.GCDC(pdc)
        gcdc.DrawBitmap(bmp, 0, 0)

        gcdc.Destroy()
        del gcdc

        if self._startup is True:
            self._startup = None
            t = threading.Thread(target=self._run_startup)
            t.daemon = True
            t.start()
        else:
            self._startup = None