def __init__(self, parent, styleToEdit, paramName): value = styleToEdit.parameterValue[paramName] csel.ColourSelect.__init__(self, parent, -1, colour=convertColour(value)) StyleEditTool.__init__(self, styleToEdit, paramName) self.Bind(csel.EVT_COLOURSELECT , self.modifyValue)
def truncColours(self, n): for i in range(n, len(self.cells)): self.cells[i].SetColour(convertColour(dummyColour))
def setColours(self, colours): for i, colour in enumerate(colours.colours): self.cells[i].SetColour(convertColour(colour)) self.truncColours(len(colours))
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 self.cells += [ csel.ColourSelect(panel, -1, colour=convertColour(dummyColour)) for x in range(nColours-len(self.cells)) ] nRows = len(self.cells) / nColumns # now we put the cells in a grid... gridSizer = wx.FlexGridSizer(cols=nColumns+1, vgap=3, hgap=3) gridSizer.Add(wx.StaticText(panel, -1, '')) for i in range(nColumns): gridSizer.Add(wx.StaticText(panel, -1, str(i)), -1, wx.ALIGN_CENTER) for i in range(nRows): gridSizer.Add(wx.StaticText(panel, -1, '+' + str(nColumns*i))) gridSizer.AddMany([ x#(x, 0, wx.EXPAND) for x in self.cells[i*nRows:i*nRows+nColumns] ]) panel.SetSizer(gridSizer) panel.SetAutoLayout(1) gridSizer.Fit(panel) panel.SetupScrolling() mainSizer.Add(panel, wx.EXPAND | wx.ALIGN_CENTER) # editing controls # first controls line: select number of colours padding = 10 mainSizer.Add((0, padding)) quantitySizer = wx.BoxSizer(wx.HORIZONTAL) # add control buttons quantitySizer.Add(wx.StaticText(self, label='number of colours: '), 0) quantitySpin = wx.SpinCtrl(self, -1, str(len(map)), style=wx.TE_PROCESS_ENTER) quantitySpin.SetRange(1, self.maxColours) quantitySizer.Add(quantitySpin, 0) mainSizer.Add(quantitySizer, 0, wx.ALIGN_CENTER) # second controls line: colour generation and modification mainSizer.Add((0, padding)) controlSizer = wx.BoxSizer(wx.HORIZONTAL) # a button to truncate colours truncButton = wx.Button(self, -1, 'Truncate') controlSizer.Add(truncButton, 0) truncButton.Bind(wx.EVT_BUTTON, lambda x: self.truncColours(quantitySpin.GetValue())) # another button to generate random colours randomButton = wx.Button(self, -1, 'Random') controlSizer.Add((20,0), 1) controlSizer.Add(randomButton, 0) randomButton.Bind(wx.EVT_BUTTON, lambda x: self.randomColours(quantitySpin.GetValue())) # another button to generate spread colours spreadButton = wx.Button(self, -1, 'Spread') controlSizer.Add((20,0), 1) controlSizer.Add(spreadButton, 0) spreadButton.Bind(wx.EVT_BUTTON, lambda x: self.spreadColours(quantitySpin.GetValue())) # another button to generate spread colours cleverSpreadButton = wx.Button(self, -1, 'Clever spread') controlSizer.Add((20,0), 1) controlSizer.Add(cleverSpreadButton, 0) cleverSpreadButton.Bind(wx.EVT_BUTTON, lambda x: \ self.cleverSpreadColours(quantitySpin.GetValue())) # now we can add standard buttons to validate/cancel mainSizer.Add(controlSizer, 0, wx.ALIGN_CENTER) mainSizer.Add((0,padding), 0) mainSizer.Add((0, padding)) buttonSizer = wx.BoxSizer(wx.HORIZONTAL) # add standard buttons okButton = wx.Button(self, wx.ID_OK) cancelButton = wx.Button(self, wx.ID_CANCEL) buttonSizer.Add(okButton, 0) buttonSizer.Add((20,0), 1) buttonSizer.Add(cancelButton, 0) mainSizer.Add(buttonSizer, 0, wx.ALIGN_CENTER) mainSizer.Add((0,padding), 0) # now we're ready self.SetSizer(mainSizer) self.Fit() self.CenterOnScreen()