def on_buttonLista_clicked(self, widget): """ Metodo que crea un pdf con una tabla de lista de clientes. :param widget: Widget butón. """ data = [] data.append( ["Dni", "Nombre", "Apellidos", "Sexo", "Direccion", "Telefono"]) clientes = SQLiteMetodos.selectTablaClientes() for cliente in clientes: data.append([ cliente[0], cliente[1], cliente[2], cliente[3], cliente[4], cliente[5] ]) # Creacion pedf fileName = 'listaClientes.pdf' current_work_directory = os.getcwd( ) # Return a string representing the current working directory. print("Current work directory: {}".format(current_work_directory)) abs_work_directory = os.path.abspath(current_work_directory) print(os.pathsep) print() pdf = SimpleDocTemplate(current_work_directory + "/" + fileName, pagesize=letter) # Creación de la tabla table = Table(data) elementos = [] elementos.append(table) # Añadiendo style a la tabla style = TableStyle([ ('BACKGROUND', (0, 0), (-1, 0), colors.lightslategray), ('BACKGROUND', (0, 1), (-1, -1), colors.beige), ('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke), ('ALIGN', (0, 0), (-1, -1), 'CENTER'), ('FONTNAME', (0, 0), (-1, 0), 'Courier-Bold'), ('FONTSIZE', (0, 0), (-1, 0), 14), ('BOTTOMPADDING', (0, 0), (-1, 0), 12), ]) table.setStyle(style) # Alternar color de las filas rowNumb = len(data) for i in range(1, rowNumb): if i % 2 == 0: bc = colors.lightgreen else: bc = colors.lightskyblue ts = TableStyle([('BACKGROUND', (0, i), (-1, i), bc)]) table.setStyle(ts) # Añadimos bordes a la tabla ts2 = TableStyle([ ('BOX', (0, 0), (-1, -1), 2, colors.black), ('LINEBEFORE', (0, 0), (-1, rowNumb), 2, colors.black), ('LINEABOVE', (0, 0), (-1, rowNumb), 2, colors.black) ]) table.setStyle(ts2) pdf.build(elementos) wb.open_new(current_work_directory + "/" + fileName)
def __init__(self): """ Inicializa la ventana de Albaranes con la interfaz. """ # Interfaz Principal Gtk.Window.__init__(self, title="Albaranes") self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.set_border_width(10) self.set_default_size(300, 300) self.set_resizable(False) self.connect("destroy", Gtk.main_quit) self.boxPrincipal = Gtk.Box(spacing=20) self.boxPrincipal.set_orientation(Gtk.Orientation.VERTICAL) self.add(self.boxPrincipal) """TABLA CLIENTES""" self.columnasC = [ "Dni", "Nombre", "Apellidos", "Sexo", "Direccion", "Telefono" ] self.modeloC = Gtk.ListStore(str, str, str, str, str, str) self.clientes = [] self.vista = Gtk.TreeView(model=self.modeloC) self.vista.get_selection().connect("changed", self.on_changed) self.labelClientes = Gtk.Label("Clientes") """TABLA PRODUCTOS""" self.columnasP = ["Id", "Dni", "Nombre", "Precio", "Cantidad"] self.modeloP = Gtk.ListStore(int, str, str, str, int) self.productosP = [] self.vistaP = Gtk.TreeView(model=self.modeloP) self.vistaP.get_selection().connect("changed", self.on_changedP) self.auxiliar = True self.labelProductos = Gtk.Label("Productos") self.boxPrincipal.add(self.labelClientes) self.boxPrincipal.add(self.vista) self.boxPrincipal.add(self.labelProductos) self.boxPrincipal.add(self.vistaP) self.boxAux = Gtk.Box(spacing=20) self.boxAux.set_orientation(Gtk.Orientation.HORIZONTAL) self.boxPrincipal.add(self.boxAux) self.buttonVolver = Gtk.Button(label="Volver") self.buttonVolver.connect("clicked", self.on_buttonVolver_clicked) self.boxAux.pack_start(self.buttonVolver, True, True, 0) self.buttonFactura = Gtk.Button(label="Factura") self.buttonFactura.connect("clicked", self.on_buttonFactura_clicked) self.boxAux.pack_start(self.buttonFactura, True, True, 0) self.buttonLista = Gtk.Button(label="Lista Clientes") self.buttonLista.connect("clicked", self.on_buttonLista_clicked) self.boxAux.pack_start(self.buttonLista, True, True, 0) clientes = SQLiteMetodos.selectTablaClientes() for cliente in clientes: self.clientes.append([ cliente[0], cliente[1], cliente[2], cliente[3], cliente[4], cliente[5] ]) for elemento in self.clientes: self.modeloC.append(elemento) for i in range(len(self.columnasC)): celda = Gtk.CellRendererText() self.columna = Gtk.TreeViewColumn(self.columnasC[i], celda, text=i) self.vista.append_column(self.columna) self.show_all()