Foros del Web » Programando para Internet » Python »

un terco problema

Estas en el tema de un terco problema en el foro de Python en Foros del Web. este problema me sale cada vez que intento ponerle o acomodarle el codigo Traceback (most recent call last): File "C:\pnt.py", line 303, in ? frame=SketchFrame(None) ...
  #1 (permalink)  
Antiguo 19/10/2008, 15:26
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 15 años, 11 meses
Puntos: 1
Exclamación un terco problema

este problema me sale cada vez que intento ponerle o acomodarle el codigo

Traceback (most recent call last):
File "C:\pnt.py", line 303, in ?
frame=SketchFrame(None)
File "C:\pnt.py", line 168, in __init__
self.createPanel()
File "C:\pnt.py", line 172, in createPanel
controlPanel = ControlPanel(self, -1, self.sketch)
File "C:\pnt.py", line 15, in __init__
colorGrid = self.createColorGrid(parent, buttonSize)
File "C:\pnt.py", line 25, in createColorGrid
b = (buttons.GenBitmapToggleButton(self, -1, bmp, size=buttonSize))
AttributeError: 'tuple' object has no attribute 'GenBitmapToggleButton'

no veo que pueda ser del codigo siguiente

Última edición por iozk; 19/10/2008 a las 16:05
  #2 (permalink)  
Antiguo 19/10/2008, 15:27
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 15 años, 11 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
  #3 (permalink)  
Antiguo 19/10/2008, 17:50
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: un terco problema

En la línea 19, al tercer parámetro de createColorGrid, en lugar de llamarlo buttonSize, lo has llamado buttons.

Mal:
Código python:
Ver original
  1. def createColorGrid(self,  parent, buttons):

Bien:
Código python:
Ver original
  1. def createColorGrid(self,  parent, buttonSize):

El error básicamente lo que te estaba diciendo es que en la línea 25 buttons era una tupla y no tenía ningún método llamado GenBitmapToggleButton. Y el problema es que en la línea 25 buttons debería hacer referencia a wx.lib.buttons (*), pero con el error de la línea 19 entonces buttons era la tupla que le pasabas con el tamaño del botón.





(*) Que por cierto necesitarás importar con un import wx.lib.buttons as buttons.

Última edición por venkman; 19/10/2008 a las 17:56
  #4 (permalink)  
Antiguo 20/10/2008, 21:23
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 15 años, 11 meses
Puntos: 1
Respuesta: un terco problema

ya ahora si quizo esque en el manual wxpython in action no tiene esos 'import' y no viene mucho de los paquetes 'wx'
  #5 (permalink)  
Antiguo 20/10/2008, 21:31
 
Fecha de Ingreso: mayo-2008
Mensajes: 499
Antigüedad: 15 años, 11 meses
Puntos: 1
Respuesta: un terco problema

oigan ya le puse este wx.MAXIMIZE


def __init__(self, parent, ID, sketch):
wx.Panel.__init__(self, parent, ID, style=wx.MAXIMIZE)
y no sale maximisada
  #6 (permalink)  
Antiguo 21/10/2008, 15:12
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: un terco problema

No sé muy bien qué es lo que estás intentando hacer, pero si lo que intentas con ese MAXIMIZE es que la ventana salga maximizada, entonces lo estás haciendo mal.

Eso es un wx.Panel, no es la ventana. La ventana es un wx.Frame.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:48.