Ver Mensaje Individual
  #2 (permalink)  
Antiguo 19/10/2008, 15:27
iozk
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 16 años, 6 meses
Puntos: 1
Respuesta: un terco problema

Código python:
Ver original
  1. import wx
  2. class ControlPanel(wx.Panel):
  3.     BMP_SIZE = 16
  4.     BMP_BORDER = 3
  5.     NUM_COLS = 4
  6.     SPACING = 4
  7.     colorList = ('Black', 'Yellow', 'Red', 'Green', 'Blue', 'Purple', 'Brown', 'Aquamarine', 'Forest Green', 'Light Blue',
  8.                  'Goldenrod', 'Cyan', 'Orange', 'Navy', 'Dark Grey', 'Light Grey')
  9.     maxThickness = 16
  10.  
  11.     def __init__(self, parent, ID, sketch):
  12.         wx.Panel.__init__(self, parent, ID, style=wx.RAISED_BORDER)
  13.         self.sketch = sketch
  14.         buttonSize = (self.BMP_SIZE + 2 * self.BMP_BORDER, self.BMP_SIZE + 2 * self.BMP_BORDER)
  15.         colorGrid = self.createColorGrid(parent, buttonSize)
  16.         thicknessGrid = self.createThicknessGrid(buttonSize)
  17.         self.layout(colorGrid, thicknessGrid)
  18.  
  19.     def createColorGrid(self,  parent, buttons):
  20.         self.colorMap = {}
  21.         self.colorButtons = {}
  22.         colorGrid = wx.GridSizer(cols=self.NUM_COLS, hgap=2,vgap=2)
  23.         for eachColor in self.colorList:
  24.             bmp = parent.MakeBitmap(eachColor)
  25.             b = (buttons.GenBitmapToggleButton(self, -1, bmp, size=buttonSize))
  26.             b.SetBezelWidth(1)
  27.             b.SetUseFocusIndicator(False)
  28.             self.Bind(wx.EVT_BUTTON, self.OnSetColour, b)
  29.             colorGrid.Add(b, 0)
  30.             self.colorMap[b.GetId()] = eachColor
  31.             self.colorButtons[eachColor] = b
  32.             self.colorButtons[self.colorList[0]].SetToggle(True)
  33.             return colorGrid
  34.  
  35.     def createThicknessGrid(self, buttonSize):
  36.         self.thicknessIdMap = {}
  37.         self.thicknessButtons = {}
  38.         thicknessGrid = wx.GridSizer(cols=self.NUM_COLS, hgap=2, vgap=2)
  39.         for x in range(1, self.maxThickness + 1):
  40.             b = (buttons.GenToggleButton(self, -1, str(x),size=buttonSize))
  41.             b.SetBezelWidth(1)
  42.             b.SetUseFocusIndicator(False)
  43.             self.Bind(wx.EVT_BUTTON, self.OnSetThickness, b)
  44.             thicknessGrid.Add(b, 0)
  45.             self.thicknessIdMap[b.GetId()] = x
  46.             self.thicknessButtons[x] = b
  47.             self.thicknessButtons[1].SetToggle(True)
  48.             return thicknessGrid
  49.  
  50.     def layout(self, colorGrid, thicknessGrid):
  51.         box = wx.BoxSizer(wx.VERTICAL)
  52.         box.Add(colorGrid, 0, wx.ALL, self.SPACING)
  53.         box.Add(thicknessGrid, 0, wx.ALL, self.SPACING)
  54.         self.SetSizer(box)
  55.         box.Fit(self)
  56.  
  57.     def OnSetColour(self, event):
  58.         color = self.colorMap[event.GetId()]
  59.         if color != self.sketch.color:
  60.             self.colorButtons[self.sketch.color].SetToggle(False)
  61.             self.sketch.SetColor(color)
  62.  
  63.     def OnSetThickness(self, event):
  64.         thickness = self.thicknessIdMap[event.GetId()]
  65.         if thickness != self.sketch.thickness:
  66.             self.thicknessButtons[self.sketch.thickness].SetToggle(False)
  67.             self.sketch.SetThickness(thickness)

Última edición por iozk; 19/10/2008 a las 16:05