/
voteMajoriteGui.py
309 lines (245 loc) · 10.2 KB
/
voteMajoriteGui.py
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# -*- coding: utf-8 -*-
import logging
from PyQt4 import QtGui, QtCore
import voteMajoriteParams as pms
import voteMajoriteTexts as texts_VM
from voteMajoriteGuiSrc import VM_pol
from client.cltgui.cltguiwidgets import WExplication, WRadio, WListDrag, \
WTableview, WLineEdit
from client.cltgui.cltguitablemodels import TableModelHistorique
from util.utili18n import le2mtrans
from client.cltgui.cltguidialogs import DQuestFinal
logger = logging.getLogger("le2m")
class WPolitics(QtGui.QWidget):
def __init__(self, parent, profil, period):
super(WPolitics, self).__init__(parent)
self.ui = VM_pol.Ui_Form()
self.ui.setupUi(self)
stylesheet_normal = "border: 1px solid black; font-weight: bold; " \
"color: black; font-size:1.2em;"
stylesheet_period = "border: 1px solid blue; font-weight: bold; " \
"color: blue; font-size:1.2em;"
for i in range(1, 5):
getattr(self.ui, "label_pol_{}".format(i)).setText(
texts_VM.trans_VM(u"Policy") + u" {}".format(i))
getattr(self.ui, "label_val_{}".format(i)).setText(str(profil[i-1]))
if i == period:
getattr(self.ui, "label_pol_{}".format(i)).setStyleSheet(
stylesheet_period)
getattr(self.ui, "label_val_{}".format(i)).setStyleSheet(
stylesheet_period)
else:
getattr(self.ui, "label_pol_{}".format(i)).setStyleSheet(
stylesheet_normal)
getattr(self.ui, "label_val_{}".format(i)).setStyleSheet(
stylesheet_normal)
class GuiDecision(QtGui.QDialog):
def __init__(self, defered, automatique, parent, periode, profil):
"""
:param defered:
:param automatique:
:param parent:
:param periode:
:param profil: only the table
:return:
"""
super(GuiDecision, self).__init__(parent)
# variables
self._defered = defered
self._automatique = automatique
self._layout = QtGui.QVBoxLayout(self)
# Explanation
self._wexplanation = WExplication(
text=texts_VM.get_text_explanation(periode, profil), parent=self,
size=(450, 80))
self._layout.addWidget(self._wexplanation)
# Politics
self._wpolitics = WPolitics(self, profil, periode)
self._layout.addWidget(self._wpolitics)
# Vote
votes = tuple([v for k, v in sorted(texts_VM.VOTES.viewitems())])
self._wvote = WRadio(
label=texts_VM.trans_VM(u"You vote"), texts=votes,
automatique=self._automatique, parent=self)
self._layout.addWidget(self._wvote)
# buttons
self._buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
self._buttons.accepted.connect(self._accept)
self._layout.addWidget(self._buttons)
# title and size
self.setWindowTitle(le2mtrans(u"Decision"))
self.adjustSize()
self.setFixedSize(self.size())
# automatic
if self._automatique:
self._timer_automatique = QtCore.QTimer()
self._timer_automatique.timeout.connect(
self._buttons.button(QtGui.QDialogButtonBox.Ok).click)
self._timer_automatique.start(7000)
def reject(self):
pass
def _accept(self):
try:
self._timer_automatique.stop()
except AttributeError:
pass
try:
decision = self._wvote.get_checkedbutton()
except ValueError:
return QtGui.QMessageBox.warning(
self, le2mtrans(u"Warning"),
texts_VM.trans_VM(u"You must vote"))
if not self._automatique:
confirmation = QtGui.QMessageBox.question(
self, le2mtrans(u"Confirmation"),
le2mtrans(u"Do you confirm your choice?"),
QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)
if confirmation != QtGui.QMessageBox.Yes:
return
logger.info(u"Send back: {}".format(decision))
self.accept()
self._defered.callback(decision)
class DSummary(QtGui.QDialog):
def __init__(self, defered, automatique, parent, profile, text_summary,
list_summary):
super(DSummary, self).__init__(parent)
self._defered = defered
self._automatique = automatique
layout = QtGui.QVBoxLayout(self)
wexplanation = WExplication(
text=text_summary, parent=self, size=(600, 100))
layout.addWidget(wexplanation)
wprofiles = WPolitics(
parent=self, profil=profile, period=0)
layout.addWidget(wprofiles)
model_summary = TableModelHistorique(list_summary)
wsummary = WTableview(
parent=self, tablemodel=model_summary, size=(600, 160))
wsummary.ui.tableView.verticalHeader().setResizeMode(
QtGui.QHeaderView.Stretch)
layout.addWidget(wsummary)
buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
buttons.accepted.connect(self._accept)
layout.addWidget(buttons)
self.setWindowTitle(le2mtrans(u"Summary"))
self.adjustSize()
self.setFixedSize(self.size())
if self._automatique:
self._timerauto = QtCore.QTimer()
self._timerauto.timeout.connect(
buttons.button(QtGui.QDialogButtonBox.Ok).click)
self._timerauto.start(7000)
def _accept(self):
try:
self._timerauto.stop()
except AttributeError:
pass
self.accept()
self._defered.callback(True)
def reject(self):
pass
class DConfig(QtGui.QDialog):
def __init__(self, parent):
super(DConfig, self).__init__(parent)
layout = QtGui.QVBoxLayout(self)
self._wexplanation = WExplication(
text=texts_VM.trans_VM(
u"Select in the list on the left the profiles you want in "
u"the session and put it in the list on the right."),
parent=self, size=(400, 80))
layout.addWidget(self._wexplanation)
self._wlistdrag = WListDrag(
parent=self, size=(120, 150))
profils = sorted(pms.PROFILES.viewkeys())
self._wlistdrag.ui.listWidget_left.addItems(profils)
layout.addWidget(self._wlistdrag)
buttons = QtGui.QDialogButtonBox(
QtGui.QDialogButtonBox.Cancel |QtGui.QDialogButtonBox.Ok)
buttons.rejected.connect(self.reject)
buttons.accepted.connect(self.accept)
layout.addWidget(buttons)
self.setWindowTitle(le2mtrans(u"Configure"))
self.adjustSize()
self.setFixedSize(self.size())
def get_profiles(self):
return self._wlistdrag.get_rightitems()
class DEchelle(QtGui.QDialog):
def __init__(self, defered, automatique, parent, num_question):
super(DEchelle, self).__init__(parent)
self._defered = defered
self._automatique = automatique
layout = QtGui.QVBoxLayout(self)
self._radios = WRadio(
parent=self, automatique=self._automatique,
label=texts_VM.get_text_question(num_question),
texts=texts_VM.get_items_question(num_question))
layout.addWidget(self._radios)
buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
buttons.accepted.connect(self._accept)
layout.addWidget(buttons)
self.setWindowTitle(le2mtrans(u"Question"))
self.adjustSize()
self.setFixedSize(self.size())
if self._automatique:
self._timer_automatique = QtCore.QTimer()
self._timer_automatique.timeout.connect(
buttons.button(QtGui.QDialogButtonBox.Ok).click)
self._timer_automatique.start(7000)
def reject(self):
pass
def _accept(self):
try:
self._timer_automatique.stop()
except AttributeError:
pass
try:
checked = self._radios.get_checkedbutton()
except ValueError:
return QtGui.QMessageBox.warning(
self, le2mtrans(u"Warning"),
texts_VM.trans_VM(u"You must select one item"))
if not self._automatique:
confirm = QtGui.QMessageBox.question(
self, le2mtrans(u"Confirmation"),
le2mtrans(u"Do you confirm your choice?"),
QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)
if confirm != QtGui.QMessageBox.Yes:
return
logger.info(u"Send back: {}".format(checked))
self.accept()
self._defered.callback(checked)
class DQuestFinalVM(DQuestFinal):
def __init__(self, defered, automatique, parent):
DQuestFinal.__init__(self, defered, automatique, parent)
self._naissance_ville = WLineEdit(
parent=self, automatique=self._automatique,
label=texts_VM.trans_VM(u"Town of birth"),
list_of_possible_values=[u"Paris", u"Marseille", u"Lyon",
u"Montpellier"])
self._gridlayout.addWidget(self._naissance_ville, 0, 2)
self.adjustSize()
self.setFixedSize(self.size())
def _accept(self):
try:
self._timer_automatique.stop()
except AttributeError:
pass
inputs = self._get_inputs()
if type(inputs) is dict:
try:
inputs["naissance_ville"] = self._naissance_ville.get_text()
except ValueError:
return QtGui.QMessageBox.warning(
self, le2mtrans(u"Warning"),
le2mtrans(u"You must answer to all the questions"))
if not self._automatique:
if QtGui.QMessageBox.question(
self, le2mtrans(u"Confirmation"),
le2mtrans(u"Do you confirm your answers?"),
QtGui.QMessageBox.No | QtGui.QMessageBox.Yes) != \
QtGui.QMessageBox.Yes: return
logger.info(u"Send back: {}".format(inputs))
self.accept()
self._defered.callback(inputs)
else:
return