Skip to content

My program in pyside6 doesn´t recognized if the QDialog was accept or reject #2

@jonnybotijas

Description

@jonnybotijas

This is the class entrega, supposedly if the product was withdrawn it should make the Qdialog accept

class Entrega(QDialog):
 def __init__(self, source_table_widget):
    QDialog.__init__(self)
    self.ui = Ui_Dialog()
    self.ui.setupUi(self)
 def commit(self):
    con = psycopg2.connect(host="aaaa",database="aaaa",user="aaaa",password="aaaa",port="aaaa")
    cursor = con.cursor()
    for self.description in self.descriptions:
        root = ET.Element('Produtos')
        Guia = ET.SubElement(root, 'Guia')
        Descricao = ET.SubElement(Guia, 'Descricao')
        Quantidade_Pedida = ET.SubElement(Guia, 'QuantidadePedida')
        Quantidade_Disponivel = ET.SubElement(Guia, 'QuantidadeDisponivel')
        Quantidade_para_envio = ET.SubElement(Guia, 'QuantidadeparaEnvio')

        

        Descricao.text= self.description
        Quantidade_Pedida.text= self.quantidade.text()
        Quantidade_Disponivel.text= self.quantidade2.text()
        Quantidade_para_envio.text = self.quantidade3.text()

        xml_content = ET.tostring(root, encoding='utf-8', method='xml').decode('utf-8')

        xml_with_declaration = f'<?xml version="1.0" encoding="utf-8"?>\n{xml_content}'

       

        sql ="""INSERT INTO "Guia"("Data","IdProjeto","Conteudo","NomeCli","enderecoCli","ContactoCli") VALUES (%s,%s,%s,%s,%s,%s)"""
        dados=(self.data, self.idproj,xml_with_declaration, self.nomeCli, self.endereco,self.contacto)
        cursor.execute(sql,dados)        
        con.commit()
        numofrows = cursor.rowcount
   
    

    if numofrows <= 0:
        QMessageBox.critical(self,"Erro","Ocorreu um erro")
        self.reject()
    else:
        QMessageBox.information(self,"Sucesso",f"Produtos retirados com sucesso")
        self.ui.lineEdit_2.clear()
        self.ui.lineEdit_3.clear()
        self.ui.lineEdit_4.clear()
        self.ui.comboBoxProjeto.setCurrentIndex(self.default_item_index)
        self.tableLinhaNova.setRowCount(0)
        self.accept()

        
    cursor.close()


And this is the other class

class Menu(QMainWindow):
    logginuser= None
    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
    def switch_windows(self):

        self.entrega2 = Entrega(self.tableLinhaNova)
        self.entrega2.closeEvent = self.CloseEvent
        self.entrega2.show()

     def CloseEvent(self, event):
        if self.entrega2.accept():
            print("accepted")
        if self.entrega2.reject():
            print("rejected")
        

But it doesn´t work, because the class Menu should see if the QDialog was accpet or reject, i probably did something wrong, but i don´t know how to correct it can anyone help please!!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions