Juste un petit exemple d’application “lourde” en Python et QT, avec PySide. La fenêtre ci-dessous ne tient pas compte d’éventuels traitements asynchrones; dès que l’utilisateur aura cliqué sur le bouton d’action, la fenêtre sera figée le temps de l’exécution du processus.
from datetime import datetime
import sys
from PySide.QtGui import (
QApplication,
QWidget,
QGridLayout,
QLabel,
QLineEdit,
QPushButton
)
from plugins.comparingBalances import ComparingBalances
qt_app = QApplication(sys.argv)
class LayoutExample(QWidget):
''' An example of PySide/PyQt absolute positioning; the main window
inherits from QWidget, a convenient widget for an empty window. '''
def __init__(self):
# Initialize the object as a QWidget and
# set its title and minimum width
QWidget.__init__(self)
self.setWindowTitle("<Windows Title>")
self.setMinimumWidth(550)
# Create the QGridLayout that lays out the whole form
self.layout = QGridLayout()
# adds label fields.
self.qlabel_year = QLabel(self)
self.qlabel_year.setText('Annee de comparaison')
self.qlabel_start_date = QLabel(self)
self.qlabel_start_date.setText('Date de debut')
self.qlabel_end_date = QLabel(self)
self.qlabel_end_date.setText('Date de rupture')
# adds input fields
self.qtextbox_year = QLineEdit(self)
self.qtextbox_year.setPlaceholderText('Format: yyyy')
self.qtextbox_start_date = QLineEdit(self)
self.qtextbox_start_date.setPlaceholderText('Format: 01/12/2014')
self.qtextbox_end_date = QLineEdit(self)
self.qtextbox_end_date.setPlaceholderText('Format: 01/12/2014')
# configure the launch button
self.launchbutton = QPushButton(self)
self.launchbutton.setText('Demarrage')
self.launchbutton.setToolTip('Demarrage du module')
self.launchbutton.clicked.connect(self.buttonClicked)
# adds all widgets to the grid layout
self.layout.addWidget(self.qlabel_year, 0, 0)
self.layout.addWidget(self.qtextbox_year, 0, 1)
self.layout.addWidget(self.qlabel_start_date, 1, 0)
self.layout.addWidget(self.qtextbox_start_date, 1, 1)
self.layout.addWidget(self.qlabel_end_date, 2, 0)
self.layout.addWidget(self.qtextbox_end_date, 2, 1)
self.layout.addWidget(self.launchbutton, 3, 0, 2)
self.layout.addWidget(self.gardesbutton, 4, 0, 2)
self.setLayout(self.layout)
def buttonClicked(self):
year = int(self.qtextbox_year.text())
start_date = self.qtextbox_start_date.text()
end_date = self.qtextbox_end_date.text()
ComparingBalances().manualLaunch(year, start_date, end_date)
def run(self):
self.show()
qt_app.exec_()
if __name__ == '__main__':
# Create an instance of the application window and run it
app = LayoutExample()
app.run()