Buenos días: Tengo una duda el código anexo no me genera bien el GriBagSizer, pero si la función la realizo en la función __init__ si, alguna solución: Gracias.
#!/usr/bin/env python # -*- coding: cp1252 -*- import os import wx import new_user import about import data # News Identifiers ID_NUEVO = wx.NewId() ID_ABRIR = wx.NewId() ID_CERRAR = wx.NewId() ID_GUARDAR = wx.NewId() ID_GUARDAR_COMO = wx.NewId() ID_IMPRIMIR = wx.NewId() ID_SALIR = wx.NewId() ID_DESHACER = wx.NewId() ID_REHACER = wx.NewId() ID_CORTAR = wx.NewId() ID_COPIAR = wx.NewId() ID_PEGAR = wx.NewId() ID_MESES = wx.NewId() ID_ENERO = wx.NewId() ID_AYUDA = wx.NewId() ID_ACERCA_DE = wx.NewId() class Aplicacion(wx.App): def OnInit(self): self.frame = Ventana(None, -1, title = "Control Horario") self.SetTopWindow(self.frame) self.frame.Show() return True class Pagina(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) self.carga = data.TimeData() self.month = self.carga.month def InitUI(self): font = wx.Font(15, family = wx.FONTFAMILY_DEFAULT, style = wx.FONTSTYLE_NORMAL, weight = wx.FONTWEIGHT_BOLD, encoding = wx.FONTENCODING_CP1252) # Layout self.sizer = wx.BoxSizer(wx.HORIZONTAL) self.gbsizer = wx.GridBagSizer(0, 0) self.sizer.Add(self.gbsizer, 1, wx.ALL, border = 5) self.SetSizer(self.sizer) # Column's Labels sem = {0 : ("Lunes", 169), 1 : ("Martes", 266), 2 : ("Miercoles" , 359), 3 : ("Jueves", 478), 4 : ("Viernes", 578), 5: ("Sabado", 686), 6 : ("Domingo", 783)} for num in range(0,7): self.cont = sem[num] dia = self.cont[0] y = num + 1 self.collab = wx.StaticText(self, -1, label = dia, size = wx.Size (105, 25), style = wx.ALIGN_CENTER | wx.SIMPLE_BORDER) self.collab.SetFont(font) if y < 6: self.collab.SetBackgroundColour(wx.Colour(255, 255, 255)) else: self.collab.SetBackgroundColour(wx.Colour(255, 0, 0)) self.gbsizer.Add(self.collab, pos = wx.GBPosition(0, y), flag = wx.ALIGN_CENTER_VERTICAL, border = 5) # Month's Label self.mes = self.carga.month_dict[self.month] self.monlab = wx.StaticText(self, -1, label = self.mes, size = wx.Size(140, 25), style = wx.ALIGN_CENTER) self.monlab.SetFont(font) self.monlab.SetForegroundColour(wx.Colour(255, 0, 255)) self.gbsizer.Add(self.monlab, pos = wx.GBPosition(0, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 5) # Row's Labels self.month_name = self.carga.month_tup[self.month - 1] num_month = self.carga.nweek_dict[self.month_name] numero = str(num_month) for num in range(0, 5): x = num + 1 self.rowlab = wx.StaticText(self, -1, label = numero, size = wx.Size (140, 25), style = wx.ALIGN_CENTER | wx.SIMPLE_BORDER) self.rowlab.SetFont(font) self.rowlab.SetForegroundColour(wx.Colour(0, 0, 255)) self.rowlab.SetBackgroundColour(wx.Colour(255, 255, 255)) self.rowlab.Wrap(-1) self.gbsizer.Add(self.rowlab, pos = wx.GBPosition(x, 0), flag = wx.ALIGN_CENTER_VERTICAL, border = 5) number = int(numero) + 1 numero = str(number) # Day's Labels day = self.carga.week_dict[self.month_name] end_dict = self.carga.num_dict[self.month_name] self.daylab_dict = {} if day == "Mon": y = 1 self.coor_x = 145 elif day == "Tue": y = 2 elif day == "Wed": y = 3 elif day == "Thu": y = 4 elif day == "Fri": y = 5 elif day == "Sat": y = 6 else: y = 7 x = 1 for cont in range (0, end_dict): contador = str(cont+1) if y > 7: x = x + 1 y = 1 self.daylab = wx.StaticText(self, label = contador, size = wx.Size (105, 25), style = wx.ALIGN_CENTRE | wx.SIMPLE_BORDER) self.daylab.SetFont(font) self.daylab.SetBackgroundColour(wx.Colour(255, 255, 255)) if y > 5: self.daylab.SetBackgroundColour(wx.Colour(255, 0, 0)) self.daylab_dict [(x, y)] = contador self.gbsizer.Add(self.daylab, pos = wx.GBPosition(x, y), flag = wx.ALIGN_CENTER_VERTICAL, border = 5) self.daylab.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) y = y + 1 # Blank's Labels resto = 35 - end_dict for cont in range (0, resto): self.blalab = wx.StaticText(self, label = "", size = wx.Size(105, 25 ), style = wx.ALIGN_CENTER | wx.SIMPLE_BORDER) self.blalab.SetFont(font) self.blalab.SetBackgroundColour(wx.Colour(255, 255, 255)) if y > 5: self.blalab.SetBackgroundColour(wx.Colour(255, 0, 0)) self.gbsizer.Add(self.blalab, pos = wx.GBPosition(x, y), flag = wx.ALIGN_CENTER_VERTICAL, border = 5) y = y + 1 def OnLeftDown(self, event): mou_pos = wx.GetMousePosition() scr_pos = self.GetScreenPosition() abs_x = mou_pos.x - scr_pos.x abs_y = mou_pos.y - scr_pos.y if abs_x < 250: coor_x = 1 elif abs_x >= 250 and abs_x < 355: coor_x = 2 elif abs_x >= 355 and abs_x < 460: coor_x = 3 elif abs_x >= 460 and abs_x < 565: coor_x = 4 elif abs_x >= 565 and abs_x < 670: coor_x = 5 elif abs_x >= 670 and abs_x < 775: coor_x = 6 else: coor_x = 7 if abs_y < 55: coor_y = 1 elif abs_y >= 55 and abs_y < 80: coor_y = 2 elif abs_y >= 80 and abs_y < 105: coor_y = 3 elif abs_y >= 105 and abs_y < 130: coor_y = 4 else: coor_y = 5 data_day = self.daylab_dict[(coor_y, coor_x)] event.Skip() class Ventana(wx.Frame): """Constructor""" def __init__(self, parent, id, title): super(Ventana, self).__init__(parent, id, title, size = (895, 275)) # Attributes self.panel = Pagina(self) # Setup Menu menubar = wx.MenuBar() # File's Menu arcm = wx.Menu() aami = wx.MenuItem(arcm, ID_ABRIR, "&Abrir...\tCtrl+A") arcm.AppendItem(aami) menubar.Append(arcm, '&Archivo') self.SetMenuBar(menubar) # Event Handlers self.Bind(wx.EVT_MENU, self.OnMenu) """Do menu events""" def OnMenu(self, event): self.evt_id = event.GetId () if self.evt_id == ID_ABRIR: self.month = 2 event.Skip() if __name__ == "__main__": app = Aplicacion(False) app.MainLoop()
_______________________________________________ Python-es mailing list Python-es@python.org http://mail.python.org/mailman/listinfo/python-es FAQ: http://python-es-faq.wikidot.com/