def get_color(in_color): """ Convert a color name or rgb sequence to a wxColour """ if type(in_color) == type(''): color = wx.wxNamedColour(in_color) else: r,g,b = in_color ##color = wx.wxColour(r,g,b) # mod by GAP 26092003 color = wx.wxColour(int(r),int(g),int(b)) return color
class Polygon(HasTraits): line_color = Trait(wx.wxColour(0, 0, 0), editor=ColorEditor())
def draw(self, dc): # drawing rectangle! dc.SetBrush(wx.wxBrush(wx.wxColour(192, 192, 192), wx.wxSOLID)) dc.DrawRectangle(self._position[0], self._position[1], self._size[0], self._size[1])
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))
def draw(self, dc): # drawing rectangle! dc.SetBrush(wx.wxBrush(wx.wxColour(192,192,192), wx.wxSOLID)) dc.DrawRectangle(self._position[0], self._position[1], self._size[0], self._size[1])
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))