def drawBorder(self): tmpStyle = style.DrawingStyle(lineColour=style.Colour(150, 150, 150), fillColour=None, lineThickness=2, lineStyle='solid') self.setDrawingStyle(tmpStyle) self.dc.DrawRectangle(0, 0, self.width, self.height)
def process(self): # pre-compute differences between consecutive colours self.colourDifference = [ style.Colour(c2.red - c1.red, c2.green - c1.green, c2.blue - c1.blue, c2.alpha - c1.alpha) for c1, c2 in zip(self.colours[:-1], self.colours[1:]) ] # map input values to some index in the list of colours self.mapping = util.intervalMapping(min(self.values), max(self.values), 0, float(len(self.colours) - 1))
def setDrawingStyle(self, thisStyle): pen = self.dc.GetPen() if thisStyle.lineStyle is None or thisStyle.lineStyle == 'solid': pen.SetStyle(wx.SOLID) # elif thisStyle.lineStyle == 'dashed': # pen.SetStyle(wx.SHORT_DASH) if not thisStyle.lineColour is None: # make the line look thinner for the thumbnail, by adding some alpha # component r, g, b, a = thisStyle.lineColour.getRGBA() thumbnailLineColour = style.Colour(r, g, b, max(0, a - 100)) pen.SetColour(convertColour(thumbnailLineColour)) if not thisStyle.fillColour is None: self.dc.SetBrush(wx.Brush(convertColour(thisStyle.fillColour))) # we paint on a thumbnail so we use a thin line pen.SetWidth(1) self.dc.SetPen(pen)
def getColour(self, value): mappedValue = self.mapping(value) index = int(mappedValue) # now we have a float value for the index so we must compute the # ratio colour between its ceil and floor # special case: last colour if index == len(self.colours) - 1: return self.colours[-1] # regular case else: offset = mappedValue % 1.0 red = self.colours[index].red + \ offset * self.colourDifference[index].red green = self.colours[index].green + \ offset * self.colourDifference[index].green blue = self.colours[index].blue + \ offset * self.colourDifference[index].blue alpha = self.colours[index].alpha + \ offset * self.colourDifference[index].alpha return style.Colour(red, green, blue, alpha)
def wxColourToColour(colour): return style.Colour(colour.Red(), colour.Green(), colour.Blue(), colour.Alpha())
self.map = styleToEdit.parameterValue[paramName] # def editMap(self, event): mapEditor = ColourMapEditor(self, self.map) if mapEditor.ShowModal() == wx.ID_OK: self.map = mapEditor.getMap() mapEditor.Destroy() self.modifyValue() # def getValue(self): return self.map # dialog used to edit a ColourMap object import wx.lib.scrolledpanel as scrolled dummyColour = style.Colour(0,0,0,0) class ColourMapEditor(wx.Dialog): maxColours = 100 # arbitrary def __init__(self, parent, map): wx.Dialog.__init__(self, parent, -1, title='Colour map editor') # main sizer for this dialog mainSizer = wx.BoxSizer(wx.VERTICAL) # window with the grid... panel = scrolled.ScrolledPanel(self, -1, size=(400, 200)) # colour cells: initialization nColours = max(len(map), self.maxColours) nColumns = 10 # arbitrary too self.cells = [ csel.ColourSelect(panel, -1, colour=convertColour(x)) for x in map.colours ] # complete cells with transparent elements