#!C:\usr\Python\python # -*- coding: utf-8 -*- import sys from PyQt4 import uic from PyQt4.QtCore import * from PyQt4.QtGui import * from TxtToPDF import PDF def selectFile(): window.File.setText(QFileDialog.getOpenFileName()) def ConvertTxtToPDF(File): window.ConvertTxtToPDFButton.setText(u"Конвертация...") window.ConvertTxtToPDFButton.setCheckable(True) window.ConvertTxtToPDFButton.setChecked(True) pdf = PDF() pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True) pdf.print_chapter(2, 'THE PROS AND CONS', File) pdf.output(File[:-3]+'pdf', 'F') QMessageBox.information(window, u"Info",u"Convert files in "+File[:-3]+u"pdf",buttons=QMessageBox.Close,defaultButton=QMessageBox.Close) window.ConvertTxtToPDFButton.setText(u"Конвертировать") window.ConvertTxtToPDFButton.setChecked(False) app = QApplication(sys.argv) window = uic.loadUi("ui.ui") window.show() QObject.connect(window.SelectTxtFile, SIGNAL('clicked()'), selectFile) QObject.connect(window.ConvertTxtToPDFButton, SIGNAL('clicked()'), lambda : ConvertTxtToPDF(unicode(window.File.text()))) sys.exit(app.exec_()) The problem is that the code is first executed:
pdf = PDF() pdf.add_font('DejaVu', '', 'DejaVuSansCondensed.ttf', uni=True) pdf.print_chapter(2, 'THE PROS AND CONS', File) pdf.output(File[:-3]+'pdf', 'F') , and then
window.ConvertTxtToPDFButton.setText(u"Конвертация...") window.ConvertTxtToPDFButton.setCheckable(True) window.ConvertTxtToPDFButton.setChecked(True) I tried to use multi-threading, but the button changes only after saving the PDF.
ConvertTxtToPDFexecuted in the correct order. The fact is that theQApplicationloop is responsible for drawing and changing the state of graphic objects, and control is returned to it only after theConvertTxtToPDFfunctionConvertTxtToPDF. Therefore, the interface is updated after exiting the function. - mkkik