class StockAdmin( wx.Dialog ): def __init__(self, parent, id, title): wx.Dialog.__init__(self, parent, id, title) self.SetSize((800,600)) self.SetMinSize((800,600)) self.list_ctrl = wx.ListCtrl(self, style=wx.LC_REPORT) image1 = wx.Image('images/search10.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.btn_cal = wx.BitmapButton(self, id = -1, bitmap = image1, size = (24,24)) image2 = wx.Image('images/add.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.btn_add = wx.BitmapButton(self, id = -1, bitmap = image2, size = (24,24)) image3 = wx.Image('images/print.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.btn_prt = wx.BitmapButton(self, id = -1, bitmap = image3, size = (24,24)) image4 = wx.Image('images/edit.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.btn_mod = wx.BitmapButton(self, id = -1, bitmap = image4, size = (24,24)) image5 = wx.Image('images/delete.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.btn_del = wx.BitmapButton(self, id = -1, bitmap = image5, size = (24,24)) self.DBM = DBManager() self.__generateContent() def __generateContent( self, myfilter=None ): rows = list() try: for row in self.DBM.getProductos(myfilter): rows.append( (row[1], row[3], row[2], str(row[4]), str(row[6]), str(row[5])) ) except TypeError: rows.append( ('Vacio', '', '', '', '', '') ) self.list_ctrl.InsertColumn(0, "Codigo") self.list_ctrl.InsertColumn(1, "Marca") self.list_ctrl.InsertColumn(2, "Descripcion") self.list_ctrl.InsertColumn(3, "Precio") self.list_ctrl.InsertColumn(4, "Stock") self.list_ctrl.InsertColumn(5, "P-Pedido") index = 0 for row in rows: if row[0] != '1000': self.list_ctrl.InsertStringItem(index, row[0]) self.list_ctrl.SetStringItem(index, 1, row[1]) self.list_ctrl.SetStringItem(index, 2, row[2]) self.list_ctrl.SetStringItem(index, 3, row[3]) self.list_ctrl.SetStringItem(index, 4, row[4]) self.list_ctrl.SetStringItem(index, 5, row[5]) if int( row[4] ) <= int( row[5] ): self.list_ctrl.SetItemBackgroundColour(index, "red") else: if index % 2: self.list_ctrl.SetItemBackgroundColour(index, "white") else: self.list_ctrl.SetItemBackgroundColour(index, "gray") index += 1 self.Bind(wx.EVT_BUTTON, self.onSearch, self.btn_cal) self.Bind(wx.EVT_BUTTON, self.onAdd, self.btn_add) self.Bind(wx.EVT_BUTTON, self.onPrint, self.btn_prt) self.Bind(wx.EVT_BUTTON, self.onDel, self.btn_del) sizer = wx.BoxSizer(wx.VERTICAL) sizer2 = wx.BoxSizer(wx.HORIZONTAL) sizer2.Add(self.btn_cal, 0, wx.ALL, 1) sizer2.Add(self.btn_add, 0, wx.ALL, 1) sizer2.Add(self.btn_del, 0, wx.ALL, 1) sizer2.Add(self.btn_mod, 0, wx.ALL, 1) sizer2.Add(self.btn_prt, 0, wx.ALL, 1) sizer.Add(sizer2, 0, wx.ALL, 1) sizer.Add(self.list_ctrl, 1, wx.EXPAND) self.SetSizer(sizer) self.Show(True) Publisher().subscribe(self.onSearch, ("producto_buscado")) Publisher().subscribe(self.refreshAfterAdd, ("producto_agregado")) def onSearch( self, evt ): self.list_ctrl.ClearAll() search_stock = SearchStock(self, -1, "Buscar") self.__generateContent(evt.data) def onAdd( self, evt ): add_stock = AddStock(self, -1, "Agregar producto") def onDel( self, evt ): item = self.list_ctrl.GetItem( self.list_ctrl.GetFirstSelected() ) product = item.GetText() result = self.DBM.deleteProductByCode( product ) self.Destroy() def onPrint( self, evt ): dlg = wx.FileDialog( self, message="Choose a file", defaultFile="reporte-tifosi.pdf", wildcard="*.pdf", style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR ) if dlg.ShowModal() == wx.ID_OK: paths = dlg.GetPaths() path = None for path in paths: path = path dlg.Destroy() RPTR = Reporter( path, self.DBM.getProductos(), "stock" ) RPTR.doReport() def refreshAfterAdd( self, evt ): self.list_ctrl.ClearAll() self.__generateContent()