1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| #!/usr/bin/python
# -*- coding: utf-8 -*-
# Python 3
import sys, os
from PyQt4 import QtCore, QtGui
#############################################################################
class Pano1(QtGui.QWidget):
"""QDateEdit seul"""
def __init__(self, parent=None):
super(Pano1,self).__init__(parent)
locale = QtCore.QLocale(QtCore.QLocale.Spanish, QtCore.QLocale.Spain)
self.datedit = QtGui.QDateEdit(self)
self.datedit.setDisplayFormat("d MMMM yyyy")
self.datedit.setLocale(locale)
self.datedit.setDate(QtCore.QDate.currentDate())
self.datedit.setFixedWidth(self.datedit.width())
posit = QtGui.QGridLayout()
posit.addWidget(self.datedit, 0, 0)
self.setLayout(posit)
#############################################################################
class Pano2(QtGui.QWidget):
"""QCalendarWidget seul"""
def __init__(self, parent=None):
super(Pano2,self).__init__(parent)
locale = QtCore.QLocale(QtCore.QLocale.Spanish, QtCore.QLocale.Spain)
self.calend = QtGui.QCalendarWidget()
self.calend.setLocale(locale)
self.calend.setSelectedDate(QtCore.QDate.currentDate())
posit = QtGui.QGridLayout()
posit.addWidget(self.calend, 0, 0)
self.setLayout(posit)
#############################################################################
class Pano3(QtGui.QWidget):
"""ensemble composé d'un QDateEdit et d'un QCalendarWidget liés"""
def __init__(self, parent=None):
super(Pano3,self).__init__(parent)
self.datedit = QtGui.QDateEdit(self)
self.datedit.setDisplayFormat("d MMMM yyyy")
locale = QtCore.QLocale(QtCore.QLocale.Spanish, QtCore.QLocale.Spain)
self.datedit.setLocale(locale)
self.datedit.setDate(QtCore.QDate.currentDate())
self.datedit.setCalendarPopup(True)
self.calend = self.datedit.calendarWidget()
self.calend.setLocale(locale)
posit = QtGui.QGridLayout()
posit.addWidget(self.datedit, 0, 0)
posit.addWidget(self.calend, 0, 1)
self.setLayout(posit)
#############################################################################
class Fenetre(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Fenetre,self).__init__(parent)
self.pano1 = Pano1()
self.pano2 = Pano2()
self.pano3 = Pano3()
# création de la pile des widgets
self.pile = QtGui.QStackedWidget()
self.pile.addWidget(self.pano1)
self.pile.addWidget(self.pano2)
self.pile.addWidget(self.pano3)
self.npilemax = self.pile.count() # nb de widgets de la pile
self.npile = 0
# bouton pour changer le panneau affiché
self.bouton = QtGui.QPushButton("Panneau suivant", self)
self.bouton.clicked.connect(self.boutonclic)
# positionnement de la pile et du bouton
self.setCentralWidget(QtGui.QFrame())
posit = QtGui.QGridLayout()
posit.addWidget(self.pile, 0, 0)
posit.addWidget(self.bouton, 1, 0)
self.centralWidget().setLayout(posit)
def boutonclic(self, b):
"""pour changer le widget affiché"""
self.npile += 1
if self.npile==self.npilemax:
self.npile = 0
self.pile.setCurrentIndex(self.npile)
#############################################################################
if __name__ == "__main__":
#
app = QtGui.QApplication(sys.argv)
# pour assurer la traduction des QMessageBox à la locale
locale = QtCore.QLocale.system().name()
translator = QtCore.QTranslator ()
reptrad = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)
translator.load("qt_" + locale, reptrad)
app.installTranslator(translator)
#
fen = Fenetre()
fen.setAttribute(QtCore.Qt.WA_DeleteOnClose)
fen.show()
sys.exit(app.exec_()) |
Partager