Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/01/2010, 12:42
IamEdo
 
Fecha de Ingreso: enero-2010
Mensajes: 21
Antigüedad: 14 años, 3 meses
Puntos: 0
problemita con wx.EVT_PAINT

wenas:
les cuento que llevo algo asi como una semana introduciéndome en python, de a poco le voy agarrando el ritmo al lenguaje en conjunto con wxPython lo cual es totalmente nuevo para mi

ahora el problema que me trae aquí seria el siguiente
tengo que dibujar en pantalla una matriz o grilla pero definiendo su dimencion
se me ocurrio resolverlo con un menu, y a cada evento asignarle una ID que concuerde con la dimencion de la matriz
el problema aparece una vez que se agranda o reduce la ventana y el dibujo desaparece ya que el wx.EVT_PAINT(self, self.dibuja) cuando se ejecuta lo hace con una ID diferente y finalmente no hace lo que debiera hacer

haber si alguien se le ocurre algo, o un metodo distinto

Código Python:
Ver original
  1. import wx
  2.  
  3. ID_ABOUT=101
  4. ID_OPEN=102
  5. ID_BUTTON1=110
  6. ID_RESET=222
  7. ID_UP=111
  8. ID_DOWN=112
  9. ID_LEFT=113
  10. ID_RIGHT=114
  11. ID_START=103
  12. ID_EXIT=999
  13. ID_GRILLA2=2
  14. ID_GRILLA3=3
  15. ID_GRILLA4=4
  16. ID_GRILLA5=5
  17. ID_GRILLA6=6
  18. ID_GRILLA7=7
  19.  
  20. class MyFrame(wx.Frame):
  21.     def __init__(self, parent, mytitle, mysize):
  22.         wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=(800,600))
  23.        
  24.         self.SetBackgroundColour('light grey')
  25.         self.initialize()
  26.        
  27.     def OnAbout(self,e):
  28.         d= wx.MessageDialog( self, " A sample editor \n"
  29.                             " in wxPython","About Sample Editor", wx.OK)                
  30.         d.ShowModal()
  31.         d.Destroy()
  32.        
  33.     def OnExit(self,e):
  34.         self.Close(True)  
  35.        
  36.        
  37.     def OnOpen(self,e):
  38.         """ Open a file"""
  39.         dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
  40.         if dlg.ShowModal() == wx.ID_OK:
  41.             self.filename=dlg.GetFilename()
  42.             self.dirname=dlg.GetDirectory()
  43.             f=open(os.path.join(self.dirname, self.filename),'r')
  44.             self.control.SetValue(f.read())
  45.             f.close()
  46.         dlg.Destroy()
  47.        
  48.        
  49.     def dibuja(self, event):
  50.         z = event.GetId()
  51.         print z
  52.         if z > 0:
  53.             dc = wx.PaintDC(self)
  54.             dc.SetPen(wx.Pen('black', 4))
  55.             dc.SetBrush(wx.WHITE_BRUSH)
  56.             x = 400
  57.             if z > 4:
  58.                 hw=80
  59.                 f=z*hw+400
  60.                 k=z*hw+50
  61.             elif z > 5:
  62.                 hw=60
  63.                 f=z*hw+400
  64.                 k=z*hw+50
  65.             else:
  66.                 hw=100
  67.                 f=z*hw+400
  68.                 k=z*hw+50
  69.             while x < f: #maximo de col
  70.                 y = 50 #pos fila
  71.                 while y < k: #max fila
  72.                     dc.DrawRectangle(x, y, hw, hw)
  73.                     y = y+hw
  74.                 x=x+hw
  75.            
  76.             wx.EVT_PAINT(self, self.dibuja) # bind the frame to the paint event    
  77.  
  78.        
  79.     def initialize(self):
  80.         grilla = wx.GridBagSizer()
  81.         self.CreateStatusBar()
  82.        
  83.         filemenu= wx.Menu()
  84.         filemenu1= wx.Menu()
  85.         filemenu.Append(ID_OPEN, "&Open"," Open a file to edit")
  86.         filemenu.AppendSeparator()
  87.         filemenu.Append(ID_ABOUT, "&About"," Information about this program")
  88.         filemenu.AppendSeparator()
  89.         filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
  90.         filemenu1.Append(ID_GRILLA2, "2x2", "Crear grilla 2x2" ,wx.ITEM_RADIO)
  91.         filemenu1.Append(ID_GRILLA3, "3x3", "Crear grilla 3x3" ,wx.ITEM_RADIO)
  92.         filemenu1.Append(ID_GRILLA4, "4x4", "Crear grilla 4x4" ,wx.ITEM_RADIO)
  93.         filemenu1.Append(ID_GRILLA5, "5x5", "Crear grilla 5x5" ,wx.ITEM_RADIO)
  94.         filemenu1.Append(ID_GRILLA6, "6x6", "Crear grilla 6x6" ,wx.ITEM_RADIO)
  95.         filemenu1.Append(ID_GRILLA7, "7x7", "Crear grilla 7x7" ,wx.ITEM_RADIO)
  96.         # Creating the menubar.
  97.         menuBar = wx.MenuBar()
  98.         menuBar.Append(filemenu,"&File")
  99.         menuBar.Append(filemenu1,"Grilla")
  100.         self.SetMenuBar(menuBar)  .
  101.         wx.EVT_MENU(self, ID_ABOUT, self.OnAbout)
  102.         wx.EVT_MENU(self, ID_EXIT, self.OnExit)
  103.         wx.EVT_MENU(self, ID_OPEN, self.OnOpen)
  104.         wx.EVT_MENU(self, ID_GRILLA2, self.dibuja)
  105.         wx.EVT_MENU(self, ID_GRILLA3, self.dibuja)
  106.         wx.EVT_MENU(self, ID_GRILLA4, self.dibuja)
  107.         wx.EVT_MENU(self, ID_GRILLA5, self.dibuja)
  108.         wx.EVT_MENU(self, ID_GRILLA6, self.dibuja)
  109.         wx.EVT_MENU(self, ID_GRILLA7, self.dibuja)
  110.        
  111.  
  112.         self.SetSizeHints(1024, 720)
  113.         self.Show(True)
  114.  
  115.  
  116. app = wx.App()
  117. mytitle = "Tests"
  118. width = 640
  119. height = 480
  120. MyFrame(None, mytitle, (width, height)).Show()
  121. app.MainLoop()

de antemano
gracias