def on_changed(self, selection):
        """Método que captura la señal selection en el TreeView y carga los productos del cliente seleccionado.

            :param selection: Si se ha seleccionado algo en el TreeView.
            :return: No devuelve ningún parámetro.

        """
        (self.model, self.iter) = selection.get_selected()
        self.productosP.clear()
        productos = SQLiteMetodos.selectTablaProductos(
            self.model[self.iter][0])
        for producto in productos:
            self.productosP.append([
                producto[0], producto[1], producto[2],
                str(producto[3]) + " €/ud", producto[4]
            ])

        self.modeloP.clear()
        for elemento in self.productosP:
            self.modeloP.append(elemento)

        if (self.auxiliar):
            for i in range(len(self.columnasP)):
                celda = Gtk.CellRendererText()
                self.columnaP = Gtk.TreeViewColumn(self.columnasP[i],
                                                   celda,
                                                   text=i)
                self.vistaP.append_column(self.columnaP)
                self.auxiliar = False
    def on_buttonFactura_clicked(self, widget):
        """Metodo que crea una factura del cliente seeccionado en el treeview.

           :param widget: Widget botón.
           :return: No devuelve ningún parámetro.

        """
        # DATOS CLIENTE SELECCIONADO
        current_work_directory = os.getcwd(
        )  # Return a string representing the current working directory.
        dataC = []
        clientes = SQLiteMetodos.selectTablaClientesDni(
            self.model[self.iter][0])
        for cliente in clientes:
            dataC.append(['Datos Cliente ', '', '', '', ''])
            dataC.append(['Dni: ', cliente[0], '', '', ''])
            dataC.append(['Nombre: ', cliente[1], '', '', ''])
            dataC.append(['Apellidos: ', cliente[2], '', '', ''])
            dataC.append(['Sexo: ', cliente[3], '', '', ''])
            dataC.append(['Direccion: ', cliente[4], '', '', ''])
            dataC.append(['Teléfono: ', cliente[5], '', '', ''])
            dataC.append(['', '', '', '', ''])

            # PRODUCTOS DEL CLIENTE SELECCIONADO
            precioTotal = 0.0
            dataP = []
            productos = SQLiteMetodos.selectTablaProductos(
                self.model[self.iter][0])
            # Productos que pertenecen al cliente seleccionado
        try:
            dataP.append(["Id Producto", "Nombre", "Precio", "Cantidad"])
            for producto in productos:
                dataP.append([
                    producto[0], producto[2],
                    str(producto[3]) + " €/ud", producto[4]
                ])
                precioTotal = precioTotal + (producto[3] * producto[4])

            dataP.append(['', '', 'PRECIO TOTAL:', str(precioTotal) + " €"])
            rowNumb = len(dataP)

            # GENERAR PDF
            fileName = 'Factura' + dataC[1][1] + '.pdf'
            pdf = SimpleDocTemplate(current_work_directory + "/" + fileName,
                                    pagesize=letter)
            # DATOS CLIENTE

            table = Table(dataC, colWidths=80, rowHeights=30)
            table.setStyle(
                TableStyle([
                    ('TEXTCOLOR', (0, 0), (0, -1), colors.darkgreen),
                    ('ALIGN', (0, 0), (0, -1), 'LEFT'),
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                ]))

            # DATOS PRODUCTOS CLIENTE
            table2 = Table(dataP, colWidths=80, rowHeights=30)
            table2.getSpaceBefore()
            table2.setStyle(
                TableStyle([
                    ('TEXTCOLOR', (0, 0), (3, 0), colors.darkgreen),
                    ('TEXTCOLOR', (0, rowNumb - 1), (3, rowNumb - 1),
                     colors.darkred), ('ALIGN', (0, 0), (0, -1), 'LEFT'),
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('BOX', (0, 0), (-1, rowNumb - 2), 1, colors.black),
                    ('INNERGRID', (0, 0), (-1, rowNumb - 2), 0.5, colors.grey)
                ]))

            # Creación de las dtabla
            elementos = []
            elementos.append(table)
            elementos.append(table2)
            pdf.build(elementos)
            wb.open_new(current_work_directory + "/" + fileName)

        except IndexError as e:
            print('No hay productos para generar la factura.')