| 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 |
from PyQt5.QtWidgets import QDialog, QPushButton, QVBoxLayout, QHBoxLayout |
| 26 |
from PyQt5.QtCore import Qt |
| 27 |
|
| 28 |
from .pythonSTC import PythonSTC |
| 29 |
|
| 30 |
class EditeurPython(PythonSTC): |
| 31 |
def __init__(self, parent): |
| 32 |
super(EditeurPython, self).__init__(parent) |
| 33 |
self.parent = parent |
| 34 |
|
| 35 |
def keyPressEvent(self, event): |
| 36 |
print("test!!!") |
| 37 |
key = event.key() |
| 38 |
if key == Qt.Key_Escape: |
| 39 |
self.parent.close() |
| 40 |
elif key == Qt.Key_F5: |
| 41 |
self.parent.executer() |
| 42 |
else: |
| 43 |
super(EditeurPython, self).keyPressEvent(event) |
| 44 |
|
| 45 |
|
| 46 |
class FenCode(QDialog): |
| 47 |
"""Permet d'éditer du code Python. |
| 48 |
|
| 49 |
En particulier, permet d'éditer le code de la feuille actuelle.""" |
| 50 |
def __init__(self, parent, titre, contenu, fonction_modif): |
| 51 |
QDialog.__init__(self, parent) |
| 52 |
self.setWindowTitle(titre) |
| 53 |
sizer = QVBoxLayout() |
| 54 |
self.parent = parent |
| 55 |
self.fonction_modif = fonction_modif |
| 56 |
self.texte = EditeurPython(self) |
| 57 |
|
| 58 |
self.texte.setText(contenu) |
| 59 |
|
| 60 |
sizer.addWidget(self.texte) |
| 61 |
|
| 62 |
boutons = QHBoxLayout() |
| 63 |
self.btn_modif = QPushButton("Modifier - F5") |
| 64 |
boutons.addWidget(self.btn_modif) |
| 65 |
self.btn_esc = QPushButton("Annuler - ESC") |
| 66 |
boutons.addStretch() |
| 67 |
boutons.addWidget(self.btn_esc) |
| 68 |
sizer.addLayout(boutons) |
| 69 |
self.setLayout(sizer) |
| 70 |
|
| 71 |
self.btn_modif.clicked.connect(self.executer) |
| 72 |
self.btn_esc.clicked.connect(self.close) |
| 73 |
|
| 74 |
self.setMinimumSize(400, 500) |
| 75 |
self.texte.setFocus() |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
def executer(self, event = None): |
| 81 |
ié |
| 82 |
self.fonction_modif(self.texte.text()) |
| 83 |
self.close() |