Ver Mensaje Individual
  #5 (permalink)  
Antiguo 15/01/2010, 12:42
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: problemita con wx.EVT_PAINT

Claro que si con un simple sizer:
Código Python:
Ver original
  1. #coding: utf-8
  2. import wx
  3.  
  4. ID_GRILLA2 = 2
  5. ID_GRILLA3 = 3
  6. ID_GRILLA4 = 4
  7. ID_GRILLA5 = 5
  8. ID_GRILLA6 = 6
  9. ID_GRILLA7 = 7
  10.  
  11. class MyFrame(wx.Frame):
  12.     def __init__(self, *args, **kargs):
  13.         wx.Frame.__init__(self, *args, **kargs)
  14.  
  15.         #Creamos un Panel dibujable y el MenuBar
  16.         self.Panel = DrawPanel(self)
  17.         self.ButtonExample = wx.Button(self, -1, "Botton Example")
  18.         menuBar = wx.MenuBar()
  19.         sizer = wx.BoxSizer(wx.VERTICAL)
  20.         sizer.Add(self.Panel, 1, wx.EXPAND, 0)
  21.         sizer.Add(self.ButtonExample, 0, 0, 0)
  22.  
  23.         #Añadimos menus
  24.         filemenu = wx.Menu()
  25.         grillamenu = wx.Menu()
  26.  
  27.         #Añadimos elementos a esos menus
  28.         filemenu.Append(wx.ID_EXIT, "&Close", "Close the program")
  29.         for i in range(2, 7 + 1):
  30.             grillamenu.Append(i, "%dx%d"%(i, i), "Crear grilla %dx%d" % (i, i), wx.ITEM_RADIO)
  31.  
  32.         #Añadimos los menus a la barra de menus
  33.         menuBar.Append(filemenu, "&File")
  34.         menuBar.Append(grillamenu, "&Grill")
  35.  
  36.         #Por ultimo ajustamos la barra de menu
  37.         self.SetMenuBar(menuBar)
  38.  
  39.         #Ajutes del sizer
  40.         self.SetSizer(sizer)
  41.         self.Layout()
  42.  
  43.         #Linkeamos los eventos a funciones con su respectiva ID
  44.         self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
  45.         for i in range(2, 7 +1):
  46.             self.Bind(wx.EVT_MENU, self.SET_ID, id=i)
  47.  
  48.     def SET_ID(self, event):
  49.         #Ajustamos el numero de cuadritos a dibujar
  50.         self.Panel.n = event.GetId()
  51.         self.Panel.Refresh() #Importante redibuja todo el frame
  52.    
  53.     def OnExit(self, event):
  54.         self.Close(True)
  55.  
  56. class DrawPanel(wx.Panel):
  57.     """Draw a line to a panel."""
  58.     def __init__(self, *args, **kwargs):
  59.         wx.Panel.__init__(self, *args, **kwargs)
  60.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  61.         #Por defecto son 2
  62.         self.n = 2
  63.  
  64.     def OnPaint(self, event):
  65.         dc = wx.PaintDC(self)
  66.         #dc.Clear() #Prueba
  67.         dc.SetPen(wx.Pen("BLACK", 4))
  68.         n = self.n #Acortamos el nombre
  69.         z = 30 #Tamaño de los cuadritos
  70.         for i in range(n):
  71.             for j in range(n):
  72.                 dc.DrawRectangle(i * z, j * z, z, z)
  73.  
  74. app = wx.PySimpleApp(False)
  75. frame = MyFrame(None, title="Draw on Panel!!!")
  76. frame.SetSizeHints(640, 480)
  77. frame.Show(True)
  78. app.MainLoop()