-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterface.py
228 lines (195 loc) · 8.82 KB
/
interface.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
"""
Created on Fri Jul 5 00:01:09 2019
@author: Ramon Silva, Adlla Katarine, Daniel Alves
"""
from PyQt5 import QtCore, QtGui, QtWidgets
import base_superpower as bd
sp = bd.SuperPower()
#classe para fazer uma ComboBox ser uma Checkable
class CheckableComboBox(QtWidgets.QComboBox):
#transformando uma ComboBox normal em uma ComboBox de CheckList
def addItem(self, item):
super(CheckableComboBox, self).addItem(item)
item = self.model().item(self.count()-1,0)
item.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
item.setCheckState(QtCore.Qt.Unchecked)
#retorna true caso o a posição da CheckBox esteja selecionada
def itemChecked(self, index):
item = self.model().item(index)
if(index == 0):
if(item.checkState() == QtCore.Qt.Checked):
for i in range(0, 167):
self.allChecked(i)
if(item.checkState() == QtCore.Qt.Checked):
return True
return False
#caso o usuário queira selecionar todos os super-poderes
def allChecked(self, index2):
item2 = self.model().item(index2)
item2.setCheckState(QtCore.Qt.Checked)
class Main(object):
def setupUi(self, MainWindowd):
#criação da tela principal
MainWindowd.setObjectName("MainWindowd")
MainWindowd.resize(298, 201)
#criação de um layout para itens se adaptarem ao tamanho da tela
self.centralwidget = QtWidgets.QWidget(MainWindowd)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
#label com o nome do programa
self.label = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily("MV Boli")
font.setPointSize(22)
self.label.setFont(font)
self.label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.label.setObjectName("label")
#criação de um layout para itens se adaptarem ao tamanho da tela
self.verticalLayout.addWidget(self.label)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
#box dos herois
self.heroes = QtWidgets.QComboBox(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Nirmala UI")
font.setPointSize(12)
self.heroes.setFont(font)
self.heroes.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.heroes.setObjectName("heroes")
self.horizontalLayout.addWidget(self.heroes)
#box das features
self.feature = CheckableComboBox(MainWindowd)
font = QtGui.QFont()
font.setFamily("Nirmala UI")
font.setPointSize(12)
self.feature.setFont(font)
self.feature.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.feature.setObjectName("feature")
self.horizontalLayout.addWidget(self.feature)
#box dos métodos
self.method = QtWidgets.QComboBox(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Nirmala UI")
font.setPointSize(12)
self.method.setFont(font)
self.method.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.method.setObjectName("method")
self.horizontalLayout.addWidget(self.method)
self.verticalLayout.addLayout(self.horizontalLayout)
#botão para pesquisar
self.search = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Nirmala UI")
font.setPointSize(14)
self.search.setFont(font)
self.search.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.search.setObjectName("search")
self.verticalLayout.addWidget(self.search)
MainWindowd.setCentralWidget(self.centralwidget)
self.search.clicked.connect(self.exibir)
self.retranslateUi(MainWindowd)
QtCore.QMetaObject.connectSlotsByName(MainWindowd)
MainWindowd.setTabOrder(self.feature, self.method)
MainWindowd.setTabOrder(self.method, self.search)
#definindo as variáveis
def retranslateUi(self, MainWindowd):
_translate = QtCore.QCoreApplication.translate
MainWindowd.setWindowTitle(_translate("MainWindowd", "Clairvoyance Operation"))
self.label.setText(_translate("MainWindowd", "Clairvoyance Operation"))
#criando a exibição das listas
sp.criarListas()
lAUX = sp.retornarNames()
for i in range(0, len(lAUX)):
self.heroes.addItem(lAUX[i])
lAUX = sp.retornarSuperPower()
self.feature.addItem("Selecionar Todos")
for i in range(0, len(lAUX)):
self.feature.addItem(lAUX[i])
lAUX = sp.retornarDistancias()
for i in range(0, len(lAUX)):
self.method.addItem(lAUX[i])
self.search.setText(_translate("MainWindowd", "Pesquisar"))
#chama os métodos de distância e a tela para mostrar os resultados
def exibir(self):
list = [] #lista para salvar os índices dos super-poderes escolhidos pelo usuário
for i in range(0, 167):
if(self.feature.itemChecked(i)):
list.append(i)
#envia a lista com as posições dos super-poderes escolhidos
sp.escolherSuperPower(list)
sp.criarBaseDadosPoderes()
sp.escolherHeroi(self.heroes.currentText())
sp.escolherDistancia(self.method.currentIndex())
sp.calcularDistancia()
#chama a nova tela com o resultado
t = Resultado()
t.setupUi(MainWindowd)
MainWindowd.show()
#tela para exibir os resultados da busca
class Resultado(object):
def setupUi(self, MainWindowd):
#criação da tela principal
MainWindowd.setObjectName("MainWindowd")
MainWindowd.setEnabled(True)
MainWindowd.resize(298, 201)
#criação de um layout para itens se adaptarem ao tamanho da tela
self.centralwidget = QtWidgets.QWidget(MainWindowd)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
#label com o nome do programa
self.label = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily("MV Boli")
font.setPointSize(22)
self.label.setFont(font)
self.label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label)
self.backButton = QtWidgets.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Nirmala UI")
font.setPointSize(14)
self.backButton.setFont(font)
self.backButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.backButton.setObjectName("backButton")
self.verticalLayout.addWidget(self.backButton, 0, QtCore.Qt.AlignLeft)
MainWindowd.setCentralWidget(self.centralwidget)
self.backButton.clicked.connect(self.voltar)
#criação de uma listwidget para visualização dos resultados
self.listWidget = QtWidgets.QListWidget(self.centralwidget)
self.listWidget.setObjectName("listWidget")
lAUX = sp.rankingHerois()
for i in range(0, len(lAUX)):
string = str(lAUX[i])
string = string.replace("[","")
string = string.replace("]", "")
string = string.replace("'", "")
lAUX[i] = string
self.listWidget.addItems(lAUX)
#criação de um layout para itens se adaptarem ao tamanho da tela
self.verticalLayout.addWidget(self.listWidget)
MainWindowd.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindowd)
QtCore.QMetaObject.connectSlotsByName(MainWindowd)
MainWindowd.setTabOrder(self.backButton)
def retranslateUi(self, MainWindowd):
_translate = QtCore.QCoreApplication.translate
MainWindowd.setWindowTitle(_translate("MainWindowd", "Clairvoyance Operation"))
self.label.setText(_translate("MainWindowd", "Clairvoyance Operation"))
self.backButton.setText(_translate("MainWindowd", "Voltar"))
def voltar(self):
ui.setupUi(MainWindowd)
MainWindowd.show()
#iniciando o programa
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindowd = QtWidgets.QMainWindow()
mainWidget = QtWidgets.QWidget()
MainWindowd.setCentralWidget(mainWidget)
ui = Main()
ui.setupUi(MainWindowd)
MainWindowd.show()
sys.exit(app.exec_())