class PaginaCrearRed(AeroPage): ''' Página para crear red ''' def __init__(self, parent, data): AeroPage.__init__(self, parent, u"Defina la red") instrucciones = AeroStaticText( self, -1, u"Indique la cantidad de nodos que tendrá la red y los arcos que hay entre ellos." ) self.content.Add(instrucciones, 0, wx.BOTTOM, 10) # cantidad de nodos hb = wx.BoxSizer(wx.HORIZONTAL) l = wx.StaticText(self, -1, u"Nodos:") hb.Add(l, 0, wx.ALIGN_CENTER_VERTICAL, 0) self.cantidad_nodos = wx.SpinCtrl(self, -1, "3") self.cantidad_nodos.SetRange(1, 50) self.Bind(wx.EVT_SPINCTRL, self.OnSpin, self.cantidad_nodos) hb.Add(self.cantidad_nodos) self.content.Add(hb, 0, wx.BOTTOM, 10) hb = wx.BoxSizer(wx.HORIZONTAL) # tabla de arcos box = wx.StaticBox(self, -1, u"Capacidad de los arcos") bsizer = wx.StaticBoxSizer(box, wx.VERTICAL) self.tabla_de_arcos = wx.grid.Grid(self, -1, (-1, -1), (400, 300)) self.datos_de_arcos = TablaDeArcos() self.tabla_de_arcos.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) self.tabla_de_arcos.SetDefaultColSize(36) self.tabla_de_arcos.SetDefaultRowSize(36) self.tabla_de_arcos.SetDefaultRenderer(Renderer()) self.tabla_de_arcos.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnCellChange) self.tabla_de_arcos.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnCellSelect) bsizer.Add(self.tabla_de_arcos, 1, wx.EXPAND) hb.Add(bsizer, 1, wx.EXPAND) hb.AddSpacer(10) # vista previa box = wx.StaticBox(self, -1, u"Vista previa") bsizer = wx.StaticBoxSizer(box, wx.VERTICAL) self.panel_vista_previa = scrolledpanel.ScrolledPanel(self, -1, size=(400, 300)) self.panel_vista_previa.SetBackgroundColour("#000000") self.bitmap_grafo = wx.StaticBitmap(self.panel_vista_previa, -1) self.panel_vista_previa.SetAutoLayout(1) self.panel_vista_previa.SetBackgroundColour(wx.WHITE) self.panel_vista_previa.SetSizer(wx.BoxSizer(wx.VERTICAL)) self.panel_vista_previa.GetSizer().Add( self.bitmap_grafo, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) self.graficador = GraficoDeRed(self.datos_de_arcos.GetRed()) bsizer.Add(self.panel_vista_previa, 0, wx.EXPAND) hb.Add(bsizer, 0, wx.EXPAND) self.content.Add(hb, 0, wx.BOTTOM, 20) def OnShow(self, event): if event.GetShow(): self.tabla_de_arcos.SetTable(self.datos_de_arcos) self.wizard.LayoutFitCenter() self.ActualizarVistaPrevia() def OnSpin(self, event): self.datos_de_arcos.SetSize(event.EventObject.GetValue()) self.tabla_de_arcos.Refresh() self.tabla_de_arcos.ForceRefresh() self.ActualizarVistaPrevia() def OnCellChange(self, event): self.ActualizarVistaPrevia() def OnCellSelect(self, event): if event.Selecting(): self.ActualizarVistaPrevia( (chr(65 + event.GetRow()), chr(65 + event.GetCol()))) event.Skip() def OnNext(self): data["red"] = self.datos_de_arcos.GetRed() return True def ActualizarVistaPrevia(self, seleccionados=None): self.graficador.graficar_red() if seleccionados != None: self.graficador.resaltar_activos(seleccionados[0], seleccionados[1]) image = self.graficador.get_wx_image() bitmap = wx.BitmapFromImage(image) self.bitmap_grafo.SetBitmap(bitmap) self.bitmap_grafo.GetParent().Refresh() self.panel_vista_previa.SetupScrolling()
class PaginaCrearRed(AeroPage): ''' Página para crear red ''' def __init__(self, parent, data): AeroPage.__init__(self, parent, u"Defina la red") instrucciones = AeroStaticText(self, -1, u"Indique la cantidad de nodos que tendrá la red y los arcos que hay entre ellos.") self.content.Add(instrucciones, 0, wx.BOTTOM, 10) # cantidad de nodos hb = wx.BoxSizer(wx.HORIZONTAL) l = wx.StaticText(self, -1, u"Nodos:") hb.Add(l, 0, wx.ALIGN_CENTER_VERTICAL, 0) self.cantidad_nodos = wx.SpinCtrl(self, -1, "3") self.cantidad_nodos.SetRange(1, 50) self.Bind(wx.EVT_SPINCTRL, self.OnSpin, self.cantidad_nodos) hb.Add(self.cantidad_nodos) self.content.Add(hb, 0, wx.BOTTOM, 10) hb = wx.BoxSizer(wx.HORIZONTAL) # tabla de arcos box = wx.StaticBox(self, -1, u"Capacidad de los arcos") bsizer = wx.StaticBoxSizer(box, wx.VERTICAL) self.tabla_de_arcos = wx.grid.Grid(self, -1, (-1, -1), (400, 300)) self.datos_de_arcos = TablaDeArcos() self.tabla_de_arcos.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER) self.tabla_de_arcos.SetDefaultColSize(36) self.tabla_de_arcos.SetDefaultRowSize(36) self.tabla_de_arcos.SetDefaultRenderer(Renderer()) self.tabla_de_arcos.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.OnCellChange) self.tabla_de_arcos.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.OnCellSelect) bsizer.Add(self.tabla_de_arcos, 1, wx.EXPAND) hb.Add(bsizer, 1, wx.EXPAND) hb.AddSpacer(10) # vista previa box = wx.StaticBox(self, -1, u"Vista previa") bsizer = wx.StaticBoxSizer(box, wx.VERTICAL) self.panel_vista_previa = scrolledpanel.ScrolledPanel(self, -1, size=(400,300)) self.panel_vista_previa.SetBackgroundColour("#000000") self.bitmap_grafo = wx.StaticBitmap(self.panel_vista_previa, -1) self.panel_vista_previa.SetAutoLayout(1) self.panel_vista_previa.SetBackgroundColour(wx.WHITE) self.panel_vista_previa.SetSizer(wx.BoxSizer(wx.VERTICAL)) self.panel_vista_previa.GetSizer().Add(self.bitmap_grafo, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL) self.graficador = GraficoDeRed(self.datos_de_arcos.GetRed()) bsizer.Add(self.panel_vista_previa, 0, wx.EXPAND) hb.Add(bsizer, 0, wx.EXPAND) self.content.Add(hb, 0, wx.BOTTOM, 20) def OnShow(self, event): if event.GetShow(): self.tabla_de_arcos.SetTable(self.datos_de_arcos) self.wizard.LayoutFitCenter() self.ActualizarVistaPrevia() def OnSpin(self, event): self.datos_de_arcos.SetSize(event.EventObject.GetValue()) self.tabla_de_arcos.Refresh() self.tabla_de_arcos.ForceRefresh() self.ActualizarVistaPrevia() def OnCellChange(self, event): self.ActualizarVistaPrevia() def OnCellSelect(self, event): if event.Selecting(): self.ActualizarVistaPrevia((chr(65 + event.GetRow()), chr(65 + event.GetCol()))) event.Skip() def OnNext(self): data["red"] = self.datos_de_arcos.GetRed() return True def ActualizarVistaPrevia(self, seleccionados = None): self.graficador.graficar_red() if seleccionados != None: self.graficador.resaltar_activos(seleccionados[0], seleccionados[1]) image = self.graficador.get_wx_image() bitmap = wx.BitmapFromImage(image) self.bitmap_grafo.SetBitmap(bitmap) self.bitmap_grafo.GetParent().Refresh() self.panel_vista_previa.SetupScrolling()