Debian Codegraph @

wxgeometrie/GUI/animer.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 ##--------------------------------------#######
4 # Suites #
5 ##--------------------------------------#######
6 # WxGeometrie
7 # Dynamic geometry, graph plotter, and more for french mathematic teachers.
8 # Copyright (C) 2005-2013 Nicolas Pourcelot
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24 from operator import attrgetter
25
26 from PyQt5.QtWidgets import QDialog, QWidget, QLabel, QMenu, QLineEdit, \
27 QPushButton, QFrame, QVBoxLayout, QHBoxLayout
28 from PyQt5.QtCore import Qt, QCoreApplication
29
30 ##from .wxlib import MyMiniFrame
31 from ..geolib.variables import Variable, Objet
32
33
34 # Nécessaire pour que l'affichage soit rafraîchi au sein d'une boucle.
35 Objet.souffler = QCoreApplication.processEvents
36
37
38 class DialogueAnimation(QDialog):
39 def __init__(self, parent):
40 QDialog.__init__(self, parent)
41 self.setWindowTitle("Créer une animation")
42 self.parent = parent
43 self.feuille_actuelle = self.parent.onglet_actuel.feuille_actuelle
44
45 self.sizer = sizer = QVBoxLayout()
46
47 terme = QHBoxLayout()
48 terme.addWidget(QLabel("Variable :"))
49 self.var = var = QLineEdit()
50 var.setMinimumWidth(50)
51 var.setContextMenuPolicy(Qt.CustomContextMenu)
52 var.customContextMenuRequested.connect(self.propositions)
53 terme.addWidget(var)
54 sizer.addLayout(terme)
55
56 ##line = QFrame(self)
57 ##line.setFrameStyle(QFrame.HLine)
58 ##sizer.addWidget(line)
59
60 terme = QHBoxLayout()
61 terme.addWidget(QLabel("Début :"))
62 self.deb = QLineEdit()
63 self.deb.setText("0")
64 self.deb.setMinimumWidth(25)
65 terme.addWidget(self.deb)
66 terme.addWidget(QLabel("Fin :"))
67 self.fin = QLineEdit()
68 self.fin.setText("1")
69 self.fin.setMinimumWidth(25)
70 terme.addWidget(self.fin)
71 terme.addWidget(QLabel("Pas :"))
72 self.pas = QLineEdit()
73 self.pas.setText("0.05")
74 self.pas.setMinimumWidth(25)
75 terme.addWidget(self.pas)
76 sizer.addLayout(terme)
77
78 terme = QHBoxLayout()
79 terme.addWidget(QLabel("Période (s) :"))
80 self.periode = QLineEdit()
81 self.periode.setText("0.1")
82 self.periode.setMinimumWidth(50)
83 terme.addWidget(self.periode)
84 sizer.addLayout(terme)
85
86 ##line = QFrame(self)
87 ##line.setFrameStyle(QFrame.HLine)
88 ##sizer.addWidget(line)
89
90 boutons = QHBoxLayout()
91 self.btn_lancer = QPushButton("Animer", clicked=self.Animer)
92 boutons.addWidget(self.btn_lancer)
93 boutons.addStretch(1)
94 fermer = QPushButton("Fermer", clicked=self.close)
95 boutons.addWidget(fermer)
96 sizer.addLayout(boutons)
97
98 self.setLayout(sizer)
99
100 self.en_cours = False
101
102
103 def Animer(self):
104 if self.en_cours:
105 self.feuille_actuelle.stop()
106 else:
107 self.en_cours = True
108 self.btn_lancer.setText('Stop')
109 self.feuille_actuelle.animer(nom=self.var.text(),
110 debut=self.evaluer(self.deb), fin=self.evaluer(self.fin),
111 pas=self.evaluer(self.pas), periode=self.evaluer(self.periode))
112 self.en_cours = False
113 self.btn_lancer.setText('Animer')
114
115 def propositions(self):
116 "Liste des noms de variables de la feuille actuelle."
117 self.var.setFocus()
118 liste_objets = self.feuille_actuelle.objets.lister(False, type = Variable)
119 liste_objets.sort(key=attrgetter('nom')) # ordre alphabétique
120 if liste_objets:
121 menu = QMenu()
122 for obj in liste_objets:
123 action = menu.addAction(obj.nom_complet)
124 action.nom = obj.nom
125 action = menu.exec_()
126 if action:
127 self.var.setText(action.nom)
128
129 def evaluer(self, champ):
130 return eval(champ.text(), self.feuille_actuelle.objets)