Debian Codegraph @

wxgeometrie/GUI/contact.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # 1/2 == .5 (par defaut, 1/2 == 0)
3
4
5
6
7 ##--------------------------------------#######
8 # Contact #
9 ##--------------------------------------#######
10 # WxGeometrie
11 # Dynamic geometry, graph plotter, and more for french mathematic teachers.
12 # Copyright (C) 2005-2013 Nicolas Pourcelot
13 #
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
28 import sys
29 from webbrowser import open_new_tab
30 from urllib.parse import urlencode
31
32 from PyQt5.QtCore import pyqtSignal
33 from PyQt5.QtWidgets import QCheckBox, QPushButton, QDialog, QTextEdit, \
34 QLineEdit, QLabel, QComboBox, QGroupBox, QMessageBox, QWidget,\
35 QHBoxLayout, QVBoxLayout
36
37
38 from .. import param
39 from ..pylib import path2
40 from ..pylib.bugs_report import rapporter
41 from ..API.sauvegarde import FichierGEO
42 from .app import white_palette
43 from .qtlib import GenericThread
44 from ..pylib.infos import informations_configuration
45
46
47 class Contact(QDialog):
48 "Formulaire utilisé pour contacter l'auteur et rapporter les bogues."
49
50 sent = pyqtSignal(bool, str)
51
52 def __init__(self, parent):
53 QDialog.__init__(self, parent)
54 self.setWindowTitle("Contacter l'auteur")
55 self.setPalette(white_palette)
56
57 self.parent = parent
58
59 panel = QWidget(self)
60
61 panelSizer = QVBoxLayout()
62
63 avant_propos = QLabel("""<i>Afin d'améliorer le fonctionnement de WxGéométrie,
64 vous êtes invités à signaler tout problème rencontré.</i>""", panel)
65 panelSizer.addWidget(avant_propos)
66 panelSizer.addSpacing(5)
67
68 rapport = QVBoxLayout()
69 rapport_box = QGroupBox("Rapport d'incident", panel)
70 rapport_box.setLayout(rapport)
71 self.titre = titre = QLineEdit(panel)
72 titre.setMinimumWidth(200)
73 titre.setText("Résumé")
74 titre.selectAll()
75 rapport.addWidget(titre)
76
77 sizer= QHBoxLayout()
78 self.modules = modules = QComboBox(panel)
79 modules.addItems([parent.onglet(md).titre for md in param.modules if hasattr(self.parent.onglet(md), "titre")])
80 modules.setCurrentIndex(self.parent.currentIndex())
81 sizer.addWidget(QLabel("Module concerné :", panel))
82 sizer.addWidget(modules)
83 rapport.addLayout(sizer)
84
85 rapport.addWidget(QLabel("Description du problème :", panel))
86 self.commentaire = commentaire = QTextEdit(panel)
87 commentaire.setMinimumSize(200, 150)
88 rapport.addWidget(commentaire)
89
90 panelSizer.addWidget(rapport_box)
91
92 sizer = QHBoxLayout()
93 coordonnees_box = QGroupBox("Vos coordonnées (recommandées)", panel)
94 coordonnees_box.setLayout(sizer)
95 sizer.addWidget(QLabel("Nom :", panel))
96 self.nom = nom = QLineEdit(panel)
97 nom.setMinimumWidth(100)
98 sizer.addWidget(nom)
99 sizer.addWidget(QLabel(" E-mail :"))
100 self.mail = mail = QLineEdit(panel)
101 mail.setMinimumWidth(100)
102 sizer.addWidget(mail)
103
104 panelSizer.addWidget(coordonnees_box)
105
106 btnOK = QPushButton("Envoyer", panel)
107 btnOK.setToolTip("Envoyer les informations.")
108 btnCancel = QPushButton("Annuler", panel)
109 btnCancel.setToolTip("Quitter sans rien envoyer.")
110
111 sizer = QHBoxLayout()
112 sizer.addWidget(btnOK)
113 sizer.addStretch()
114 sizer.addWidget(btnCancel)
115 panelSizer.addLayout(sizer)
116
117 panel.setLayout(panelSizer)
118
119 topSizer = QHBoxLayout()
120 topSizer.addWidget(panel)
121
122 self.setLayout(topSizer)
123
124 self.sent.connect(self.termine)
125 btnOK.clicked.connect(self.rapporter)
126 btnCancel.clicked.connect(self.close)
127
128
129
130 def rapporter(self):
131 module = self.parent.onglet(self.modules.currentIndex())
132
133 try:
134 histo = module.log.contenu()
135 except Exception as e:
136 histo = "Impossible de recuperer l'historique du module (%s)." % e
137
138 sys.stdout.flush()
139 filename = path2(param.emplacements['log'] + "/messages.log")
140 try:
141 file = open(filename, 'r')
142 msg = file.read()
143 except Exception as e:
144 msg = "Impossible de recuperer le journal (%s)." % e
145 finally:
146 file.close()
147
148 try:
149 fgeo = FichierGEO(module=module.nom)
150 module._sauvegarder(fgeo)
151 fichier_courant = fgeo.data
152 except Exception as e:
153 fichier_courant = "Impossible de recuperer le fichier courant (%s)." % e
154
155 self.hide()
156 kw = {'titre': self.titre.text(), 'auteur': self.nom.text(),
157 'email': self.mail.text(), 'description': self.commentaire.toPlainText(),
158 'historique': histo, 'log': msg, 'config': informations_configuration(),
159 'fichier': fichier_courant
160 }
161 self.thread = GenericThread(self._rapporter, **kw)
162 self.thread.start()
163 # XXX: Qt complains here: "QObject::connect: Cannot queue arguments of type 'QTextBlock'"
164
165
166 def _rapporter(self, **kw):
167 # /!\ Ne **JAMAIS** utiliser `print()` depuis une autre thread que la principale !
168 self.sent.emit(*rapporter(**kw))
169
170
171
172 def termine(self, success, msg):
173 if param.debug:
174 print(' ** Remote site report **\n' + msg)
175 if 'mail()' in msg:
176 # Fonction mail() de PHP très probablement bloquée par Free.
177 success = False
178 if success:
179 QMessageBox.information(self, "Message envoyé", "Le message a été envoyé avec succès. Merci !")
180 self.close()
181 else:
182 QMessageBox.warning(self, "Connexion impossible.",
183 "Impossible d'envoyer le message !\nVous allez être redirigé vers le tracker de bug.")
184 self.show()
185 # On tente de se connecter directement au tracker.
186 # (Le navigateur par défaut est susceptible d'avoir des paramètres proxy correctement renseignés).
187
188 data = urlencode({'item_summary': self.titre.text(),
189 'detailed_desc': self.commentaire.toPlainText(),
190 'anon_email': self.mail.text()},
191 encoding='utf8')
192 open_new_tab("http://wxgeo.free.fr/tracker/?do=newtask&project=1&" + data)
193