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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from sip import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
# Application principale
class QtAppli(
QApplication):
"Application principale"
# Constructeur fenêtre
def __init__(
self,
argv):
# Appel constructeur de l'objet hértié
super(QtAppli, self).__init__(argv)
# Widget principale
self.__mainWid=QtMainWindow()
self.__mainWid.show()
# __init__()
# class QtAppli
# Fenêtre principale
class QtMainWindow(
QMainWindow):
"Fenêtre principale"
# Constructeur fenêtre
def __init__(
self,
*args,
**kwargs):
# Appel constructeur de l'objet hértié
super(QtMainWindow, self).__init__(*args, **kwargs)
self.setCentralWidget(QWidget(self))
# Le titre
self.setWindowTitle(QString.fromUtf8("Qt %1").arg(QT_VERSION_STR))
# Le bouton
btn=QPushButton(QString.fromUtf8("Appel sous-fenêtre"))
QObject.connect(
btn,
SIGNAL("clicked()"),
self.__slotAction,
)
# btn.clicked.connect(self.__slotAction) # Jusque là ça va...
# Pour quitter
quit=QPushButton(QString.fromUtf8("Quitter"))
QObject.connect(
quit,
SIGNAL("clicked()"),
self,
SLOT("close()"),
)
# quit.clicked.connect(self.close) # Là aussi...
# Rangement principal
mainLayout=QVBoxLayout(self.centralWidget())
mainLayout.addWidget(btn, 0)
mainLayout.addWidget(quit, 0)
# Sous-fenêtre
self.__other=QtSubWindow(self.centralWidget())
QObject.connect(
self.__other,
SIGNAL("xxx"),
self.__slotOtherClose,
)
# Là je ne vois pas comment écrire ça en new-style...
# __init__()
# Slot qui affiche la sous-fenêtre
def __slotAction(
self):
print(u"%s.__slotAction" % self.__class__.__name__)
# Affichage sous-fenêtre
self.__other.show()
# __slotAction()
# A la fermeture de la sous-fenêtre
def __slotOtherClose(
self,
x):
print(
u"%s.__slotOtherClose(%s)" % (
self.__class__.__name__,
x,
)
)
# __slotOtherClose()
# class QtMainWindow
# Fenêtre subsidiaire
class QtSubWindow(
QDialog):
"Fenêtre subsidiaire"
# Constructeur fenêtre
def __init__(
self,
*args,
**kwargs):
# Appel constructeur de l'objet hértié
super(QtSubWindow, self).__init__(*args, **kwargs)
self.setModal(True)
# Le compteur
self.__cpt=0
# Bouton
btn=QPushButton(QString.fromUtf8("Fermer"))
QObject.connect(
btn,
SIGNAL("clicked()"),
self,
SLOT("close()"),
)
#btn.clicked.connect(self.close)
# Rangement principal
mainLayout=QVBoxLayout(self)
mainLayout.addWidget(btn)
# __init__()
# A la fermeture (méthode surchargée)
def closeEvent(
self,
event):
# Incrément compteur
self.__cpt+=1
# Emission compteur
self.emit(SIGNAL("xxx"), self.__cpt) # Pareil, je ne vois pas comment écrire ça en new-style...
# closeEvent()
# class QtSubWindow
if __name__ == "__main__":
# Lancement appli
QtAppli(sys.argv).exec_() |
Partager