Oct-20-2020, 07:05 PM
Hi
I want to update a html file containing element such as :
<auteur id="Alc" auteur="Alcée" origine="Mytilène" genre="poète lyrique" title="vers 610 avant J.-C."><a href="Alcée_de_Mytilène"></a></auteur>
I'm writing a code to create within a loop several QLabel and QLineEdit whithout naming them. Here is the code
Arbiel
I want to update a html file containing element such as :
<auteur id="Alc" auteur="Alcée" origine="Mytilène" genre="poète lyrique" title="vers 610 avant J.-C."><a href="Alcée_de_Mytilène"></a></auteur>
I'm writing a code to create within a loop several QLabel and QLineEdit whithout naming them. Here is the code
#!/usr/bin/env python # -*- coding: utf-8 -*- # # from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtCore import QMetaObject, pyqtSlot from PyQt5.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit, QPushButton, QApplication from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QMessageBox from bs4 import BeautifulSoup as btfs class Auteur(QMainWindow): def __init__(auto): super(Auteur,auto).__init__() print("Auteur.__init__",type(auto)) def init(auto): print("Auteur.init",type(auto)) auto.setGeometry(250,200,800,300) auto.setWindowTitle('Auteur') auto.Fenster=QWidget() auto.setCentralWidget(auto.Fenster) zs=QHBoxLayout() libellés=QVBoxLayout() ligneXml=QVBoxLayout() zs.addLayout(libellés) zs.addLayout(ligneXml) l=QLabel('Identifiant') libellés.addWidget(l) auto.id=QLineEdit() # creating the html arguments of <auteur> to be updated for tpl in [('Nom','auteur'), ('Origine', 'origine'), ('Période', 'title'), ('Genres littéraires', 'genre'), ('Œuvres', 'œuvres'),('wikipedia', 'href') ]: l=QLabel(tpl[0]) libellés.addWidget(l) argXml=QLineEdit() argXml.setObjectName(tpl[1]) ligneXml.addWidget(argXml) zc=QHBoxLayout() zc.addStretch() for tpl in [('Quitter','quit', True), ('Wikipédia', 'wiki', False), ('Mémoriser', 'memo', False), ('Abandonner', 'abandon', False), ('Réinitialiser', 'reinit', False)]: btn=QPushButton(tpl[0], auto.Fenster) btn.setObjectName(tpl[1]) btn.setEnabled(tpl[2]) zc.addWidget(btn) zc.addStretch() vbl=QVBoxLayout(auto.Fenster) vbl.addLayout(zs) vbl.addStretch() vbl.addLayout(zc) QMetaObject.connectSlotsByName(auto) @pyqtSlot() def on_quit_clicked(auto): print("on_quitter_clicked",type(auto)) auto.close() @pyqtSlot() def on_id_editingFinished(auto): try: # recherche de l'auteur dans le fichier html et affichage des informations auto.état='initial' # print(lauteur) except: auto.état='nouveau' # réinitialisation des rubriques de l'auteur pass return 0 @pyqtSlot() def on_auteur_editingFinished(auto): print ('on_auteur_editingFinished') @pyqtSlot() def on_origine_editingFinished(auto): print ('on_origine_editingFinished') def main(args): app = QtWidgets.QApplication(args) auteur=Auteur() auteur.init() auteur.show() app.exec() return 0 if __name__ == '__main__': import sys sys.exit(main(sys.argv))How is it possible to retrieve each QEditLine by its name, to match it with the html argument with the same name ?
Arbiel