Ver Mensaje Individual
  #7 (permalink)  
Antiguo 13/02/2013, 05:14
tecafede
 
Fecha de Ingreso: noviembre-2012
Mensajes: 111
Antigüedad: 11 años, 6 meses
Puntos: 6
Respuesta: wxPython - Duda sobre como "ensamblar" paneles

En el código que tú resolviste:

Código Python:
Ver original
  1. class RadioButtonFrame(wx.Frame):
  2.     def __init__(self):
  3.         wx.Frame.__init__(self, None, -1, 'User Admin', size=(200, 200))
  4.  
  5.         self.Bind(wx.EVT_CLOSE, self.OnClose)
  6.        
  7.         panel = wx.Panel(self, -1)
  8.         self.widgets = []
  9.         self.users = get_users()
  10.         for i, user in enumerate(self.users):
  11.             radio = wx.RadioButton(panel, -1, label=str(i+1), pos=(20, 50+(i*30)))
  12.             text = wx.TextCtrl(panel, -1, user.name, pos=(80, 50+(i*30)))
  13.             text.Enable(False)
  14.  
  15.             if user.is_active():
  16.                 radio.SetValue(True)
  17.                 text.Enable(True)
  18.  
  19.             def OnButton(event, radio_index=i):
  20.                 self.OnRadio(event, radio_index)
  21.             radio.Bind(wx.EVT_RADIOBUTTON, OnButton)
  22.  
  23.             widget = {'radio': radio, 'text': text}
  24.             self.widgets.append(widget)
  25.  
  26.     def OnRadio(self, event, index):
  27.         for widget in self.widgets:
  28.             widget['text'].Enable(False)
  29.         widget = self.widgets[index]
  30.         widget['text'].Enable(True)
  31.  
  32.     def OnClose(self, event):
  33.         dlg = wx.MessageDialog(self, "Guardar los cambios realizados?",  "Confirmar Salida", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
  34.         result = dlg.ShowModal()
  35.         dlg.Destroy()
  36.         if result == wx.ID_OK:
  37.             for user, widget in zip(self.users, self.widgets):
  38.                 user.set_active(widget['radio'].GetValue())
  39.                 user.name = widget['text'].GetValue()
  40.             save_users(self.users)
  41.         self.Destroy()

La duda que tengo es que esa clase incluye partes que podrían pertenecer a "CONTROLADOR" (def OnRadio y def OnClose) y otras que podrían pertenecer a "VISTAS" (def __init__)

En ese caso me complica un poco más como separarlas para que estén en sus respectivas áreas.

Incluyo el def __init__ en VISTAS y luego en CONTROLERS extiendo la clase para incluir def OnRadio y def OnClose?