Example #1
0
 def draw(self, dc):
     if self.visible in ['on','yes']:
         color = get_color(self.color)
         style = line_style_map[self.style]
         dc.SetPen(wx.wxPen(color, self.weight,style))
         try:
             dc.DrawLines(self.scaled)
         except:
             dc.DrawLines(map(tuple,self.scaled))
         dc.SetPen(wx.wxNullPen)
Example #2
0
 def draw_ticks(self,dc):
     if self.ticks_visible in ['yes','on']:
         style = line_style_map[self.tick_style]
         color = get_color(self.tick_color)
         pen = wx.wxPen(color, self.tick_weight, style)
         draw_point_list(self.tick_start,self.tick_stop,pen,dc)
         #dc.DrawLines(self.single_tick_line)
     # draw axis line here also
     pt1 = self.tick_points[0]
     pt2 = self.tick_points[-1]
     draw_point_list([pt1],[pt2],pen,dc)
Example #3
0
 def draw(self,dc):
     if self.visible in ['on','yes']:
         color = get_color(self.outline_color)
         weight = self.outline_weight
         size = self.size
         fill_color = get_color(self.fill_color)
         fill_style = fill_style_map[self.fill_style]
         symbol = self.symbol
         dc.SetPen(wx.wxPen(color,weight))
         dc.SetBrush(wx.wxBrush(fill_color,fill_style))
         self._drawmarkers(dc, self.scaled, symbol, size)
         dc.SetPen(wx.wxNullPen)
         dc.SetBrush(wx.wxNullBrush)
Example #4
0
 def draw_fast(self,dc):
     """ This approach uses wxPythons DrawLines to draw
         the entire border in one call instead of drawing
         each tick individually.  It is 5-10 times faster,
         but draws the border and ticks all in the same style.
         (not a big draw back...)
     """
     style = line_style_map[self.style]
     color = get_color(self.color)
     pen = wx.wxPen(color, self.weight, style)
     dc.SetPen(pen)
     dc.DrawLines(self.single_line)
     dc.SetPen(wx.wxNullPen)
Example #5
0
    def draw(self,dc):
        vis = self.visible in ['yes','on']
        tick_vis = self.ticks_visible in ['yes','on']

        #if vis and tick_vis:
        if 0:
            # Really should check styles etc. here to make
            # sure the are the same.
            self.draw_fast(dc)
        else:
            #draw border
            if vis:
                style = line_style_map[self.style]
                color = get_color(self.color)
                pen = wx.wxPen(color, self.weight, style)
                draw_point_list(self.border_start,self.border_stop,pen,dc)
            #draw ticks
            if tick_vis:
                style = line_style_map[self.tick_style]
                color = get_color(self.tick_color)
                pen = wx.wxPen(color, self.tick_weight, style)
                draw_point_list(self.tick_start,self.tick_stop,pen,dc)
Example #6
0
    def draw(self, dc):
        # lines are 2 pixels thick
        dc.SetPen(wx.wxPen(self.lineColourName, 2, wx.wxSOLID))

        # simple mode: just the lines thanks.
        #dc.DrawLines(self._linePoints)

        # spline mode for N points:
        # 1. Only 4 points: drawlines.  DONE
        # 2. Draw line from 0 to 1
        # 3. Draw line from N-2 to N-1 (second last to last)
        # 4. Draw spline from 1 to N-2 (second to second last)
        #         if len(self._linePoints) > 4:
        #             dc.DrawLines(self._linePoints[0:2]) # 0 - 1
        #             dc.DrawLines(self._linePoints[-2:]) # second last to last
        #             dc.DrawSpline(self._linePoints[1:-1])
        #         else:
        #             dc.DrawLines(self._linePoints)

        dc.SetPen(wx.wxPen('BLACK', 4, wx.wxSOLID))
        dc.DrawSpline(self._linePoints)
        dc.SetPen(wx.wxPen(self.lineColourName, 2, wx.wxSOLID))
        dc.DrawSpline(self._linePoints)
Example #7
0
    def draw(self, dc):
        # lines are 2 pixels thick
        dc.SetPen(wx.wxPen(self.lineColourName, 2, wx.wxSOLID))

        # simple mode: just the lines thanks.
        #dc.DrawLines(self._linePoints)

        # spline mode for N points:
        # 1. Only 4 points: drawlines.  DONE
        # 2. Draw line from 0 to 1
        # 3. Draw line from N-2 to N-1 (second last to last)
        # 4. Draw spline from 1 to N-2 (second to second last)
#         if len(self._linePoints) > 4:
#             dc.DrawLines(self._linePoints[0:2]) # 0 - 1
#             dc.DrawLines(self._linePoints[-2:]) # second last to last
#             dc.DrawSpline(self._linePoints[1:-1])
#         else:
#             dc.DrawLines(self._linePoints)

        dc.SetPen(wx.wxPen('BLACK', 4, wx.wxSOLID))
        dc.DrawSpline(self._linePoints)
        dc.SetPen(wx.wxPen(self.lineColourName, 2, wx.wxSOLID))
        dc.DrawSpline(self._linePoints)
Example #8
0
 def save(self,path,image_type):
     w,h = self.GetSizeTuple()
     bitmap = wx.wxEmptyBitmap(w,h)
     dc = wx.wxMemoryDC()
     dc.SelectObject(bitmap)
     #self.update()
     # The background isn't drawn right without this cluge.
     #fill_color = get_color(self.background_color)
     fill_color = get_color('white')
     dc.SetPen(wx.wxPen(fill_color))
     dc.SetBrush(wx.wxBrush(fill_color)) #how to handle transparency???
     dc.DrawRectangle(0,0,w,h)
     dc.SetPen(wx.wxNullPen)
     dc.SetBrush(wx.wxNullBrush)
     # end cluge
     self.draw(dc)
     image = wx.wxImageFromBitmap(bitmap)
     wx.wxInitAllImageHandlers()
     image.SaveFile(path,image_type_map[image_type])
Example #9
0
    def draw_graph_area(self,dc=None):
        if not dc: dc = wx.wxClientDC(self)
        self.layout_data() # just to check how real time plot would go...

        gb = self.graph_box
        #clear the plot area
        # SHOULD SET PEN HERE TO FILL BACKGROUND WITH CORRECT COLOR
        fill_color = get_color('white')
        dc.SetPen(wx.wxPen(fill_color))
        dc.SetBrush(wx.wxBrush(fill_color))
        # NEEDED FOR REAL-TIME PLOTTING
        dc.DrawRectangle(gb.left(),gb.top(),
                         gb.width()+1,gb.height()+1)
        #needed to make sure images stay within bounds
        ##dc.SetClippingRegion(gb.left()-1,gb.top()-1,
        ##                     gb.width()+2,gb.height()+2)  # mod by GAP 26092003
        dc.SetClippingRegion(int(gb.left()-1),int(gb.top()-1),
                             int(gb.width()+2),int(gb.height()+2))
        # draw images
        self.image_list.draw(dc)
        dc.DestroyClippingRegion()
        # draw axes lines and tick marks
        t1 = time.clock()
        for axis in self.axes:
            axis.draw_lines(dc)
        #for axis in self.axes:
        #    axis.draw_grid_lines(dc)
        #for axis in self.axes:
        #    axis.draw_ticks(dc)
        t2 = time.clock()
        #print 'lines:', t2 - t1
        #draw border
        t1 = time.clock(); self.border.draw(dc); t2 = time.clock()
        #print 'border:', t2 - t1
        # slightly larger clipping area so that marks
        # aren't clipped on edges
        # should really clip markers and lines separately
        # draw lines
        self.line_list.clip_box(self.graph_box)
        self.line_list.draw(dc)
Example #10
0
 def draw_grid_lines(self,dc):
     if self.grid_visible in ['yes','on']:
         style = line_style_map[self.grid_style]
         color = get_color(self.grid_color)
         pen = wx.wxPen(color,self.grid_weight, style)
         draw_point_list(self.grid_start,self.grid_stop,pen,dc)
Example #11
0
    def draw(self, dc):
        normal_colour = (192, 192, 192)
        selected_colour = (255, 0, 246)
        blocked_colour = (16, 16, 16)

        colour = normal_colour

        if self.selected:
            colour = [
                selected_colour[i] * 0.5 + colour[i] * 0.5 for i in range(3)
            ]

        if self.blocked:
            colour = [
                blocked_colour[i] * 0.5 + colour[i] * 0.5 for i in range(3)
            ]

        colour = tuple([int(i) for i in colour])

        blockFillColour = wx.wxColour(*colour)

        #         # we're going to alpha blend a purplish sheen if this glyph is active
        #         if self.selected:
        #             # sheen: 255, 0, 246
        #             # alpha-blend with 192, 192, 192 with alpha 0.5 yields
        #             #  224, 96, 219
        #             blockFillColour = wx.wxColour(224, 96, 219)
        #         else:
        #             blockFillColour = wx.wxColour(192, 192, 192)

        # default pen and font
        dc.SetBrush(wx.wxBrush(blockFillColour, wx.wxSOLID))
        dc.SetPen(wx.wxPen('BLACK', 1, wx.wxSOLID))
        dc.SetFont(wx.wxNORMAL_FONT)

        # calculate our size
        # the width is the maximum(textWidth + twice the horizontal border,
        # all ports, horizontal borders and inter-port borders added up)
        maxPorts = max(self._numInputs, self._numOutputs)
        portsWidth = 2 * coGlyph._horizBorder + \
                     maxPorts * coGlyph._pWidth + \
                     (maxPorts - 1 ) * coGlyph._horizSpacing

        # determine maximum textwidth and height
        tex = 0
        tey = 0

        for l in self._labelList:
            temptx, tempty = dc.GetTextExtent(l)

            if temptx > tex:
                tex = temptx

            if tempty > tey:
                tey = tempty

        # this will be calculated with the max width, so fine
        textWidth = tex + 2 * coGlyph._horizBorder

        self._size = (max(textWidth, portsWidth),
                      tey * len(self._labelList) + 2 * coGlyph._vertBorder)

        # draw the main rectangle
        dc.DrawRectangle(self._position[0], self._position[1], self._size[0],
                         self._size[1])

        #dc.DrawRoundedRectangle(self._position[0], self._position[1],
        #                        self._size[0], self._size[1], radius=5)

        initY = self._position[1] + coGlyph._vertBorder
        for l in self._labelList:
            dc.DrawText(l, self._position[0] + coGlyph._horizSpacing, initY)
            initY += tey

        # then the inputs
        horizOffset = self._position[0] + coGlyph._horizBorder
        horizStep = coGlyph._pWidth + coGlyph._horizSpacing
        connBrush = wx.wxBrush("GREEN")
        disconnBrush = wx.wxBrush("RED")

        for i in range(self._numInputs):
            brush = [disconnBrush, connBrush][bool(self.inputLines[i])]
            self.drawPort(dc, brush,
                          (horizOffset + i * horizStep, self._position[1]))

        lx = self._position[1] + self._size[1] - coGlyph._pHeight
        for i in range(self._numOutputs):
            brush = [disconnBrush, connBrush][bool(self.outputLines[i])]
            self.drawPort(dc, brush, (horizOffset + i * horizStep, lx))
Example #12
0
    def draw(self, dc):
        normal_colour = (192, 192, 192)
        selected_colour = (255, 0, 246)
        blocked_colour = (16, 16, 16)

        colour = normal_colour

        if self.selected:
            colour = [selected_colour[i] * 0.5 + colour[i] * 0.5
                      for i in range(3)]

        if self.blocked:
            colour = [blocked_colour[i] * 0.5 + colour[i] * 0.5
                      for i in range(3)]

        colour = tuple([int(i) for i in colour])

        blockFillColour = wx.wxColour(*colour)

        
#         # we're going to alpha blend a purplish sheen if this glyph is active
#         if self.selected:
#             # sheen: 255, 0, 246
#             # alpha-blend with 192, 192, 192 with alpha 0.5 yields
#             #  224, 96, 219
#             blockFillColour = wx.wxColour(224, 96, 219)
#         else:
#             blockFillColour = wx.wxColour(192, 192, 192)
        
        # default pen and font
        dc.SetBrush(wx.wxBrush(blockFillColour, wx.wxSOLID))
        dc.SetPen(wx.wxPen('BLACK', 1, wx.wxSOLID))
        dc.SetFont(wx.wxNORMAL_FONT)
        
        # calculate our size
        # the width is the maximum(textWidth + twice the horizontal border,
        # all ports, horizontal borders and inter-port borders added up)
        maxPorts = max(self._numInputs, self._numOutputs)
        portsWidth = 2 * coGlyph._horizBorder + \
                     maxPorts * coGlyph._pWidth + \
                     (maxPorts - 1 ) * coGlyph._horizSpacing

        # determine maximum textwidth and height
        tex = 0
        tey = 0

        for l in self._labelList:
            temptx, tempty = dc.GetTextExtent(l)

            if temptx > tex:
                tex = temptx

            if tempty > tey:
                tey = tempty
        
        # this will be calculated with the max width, so fine
        textWidth = tex + 2 * coGlyph._horizBorder
        
        self._size = (max(textWidth, portsWidth),
                      tey * len(self._labelList) + 2 * coGlyph._vertBorder)

        # draw the main rectangle
        dc.DrawRectangle(self._position[0], self._position[1],
                         self._size[0], self._size[1])

        #dc.DrawRoundedRectangle(self._position[0], self._position[1],
        #                        self._size[0], self._size[1], radius=5)

        initY = self._position[1] + coGlyph._vertBorder
        for l in self._labelList:
            dc.DrawText(l,
                        self._position[0] + coGlyph._horizSpacing,
                        initY)
            initY += tey

        # then the inputs
        horizOffset = self._position[0] + coGlyph._horizBorder
        horizStep = coGlyph._pWidth + coGlyph._horizSpacing
        connBrush = wx.wxBrush("GREEN")
        disconnBrush = wx.wxBrush("RED")
        
        for i in range(self._numInputs):
            brush = [disconnBrush, connBrush][bool(self.inputLines[i])]
            self.drawPort(dc, brush,
                          (horizOffset + i * horizStep,
                           self._position[1]))

        lx = self._position[1] + self._size[1] - coGlyph._pHeight
        for i in range(self._numOutputs):
            brush = [disconnBrush, connBrush][bool(self.outputLines[i])]
            self.drawPort(dc, brush,
                          (horizOffset + i * horizStep,
                           lx))