-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
243 lines (208 loc) · 10.6 KB
/
gui.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
# -*- coding: utf-8 -*-
#
# Developer
# Ismail AKBUDAK
# ismailakbudak.com
# Election algorithm on graph
from PyQt4 import QtCore, QtGui
from graph import *
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
# Application UI
class Ui_MainWindow():
def __init__(self):
self.graph = Graph()
self.graph.traceGrowth = False
self.graph.traceLog = True
self.graph.traceElection = True
self.graph.traceElectionVisual = True
self.graph.readFiles()
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(400, 400)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
MainWindow.setWindowTitle(_translate("MainWindow", "Election algorithm on graph - Ismail AKBUDAK", None))
font = QtGui.QFont()
font.setStrikeOut(False)
font.setPointSize(13)
MainWindow.setFont(font)
# Tabs initialized
self.tabWidget = QtGui.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(0, 0, 2000, 2000))
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
# Tab main initialized
self.tabMain = QtGui.QWidget()
self.tabMain.setObjectName(_fromUtf8("tabMain"))
# Main - Nodes count label title
self.labelNodesCount = QtGui.QLabel(self.tabMain)
self.labelNodesCount.setGeometry(QtCore.QRect(85, 10, 350, 30))
self.labelNodesCount.setObjectName(_fromUtf8("labelNodesCount"))
self.labelNodesCount.setText(_translate("MainWindow", "Number of Nodes : ", None))
# Main - Draw Graph button
self.pushButtonDraw = QtGui.QPushButton(self.tabMain)
self.pushButtonDraw.setGeometry(QtCore.QRect(85, 90, 200, 30))
self.pushButtonDraw.setObjectName(_fromUtf8("pushButtonDraw"))
self.pushButtonDraw.setText(_translate("MainWindow", "Draw Graph", None))
self.pushButtonDraw.clicked.connect(self.draw)
# Main - Read Files button
self.pushButtonReadFiles = QtGui.QPushButton(self.tabMain)
self.pushButtonReadFiles.setGeometry(QtCore.QRect(85, 130, 200, 30))
self.pushButtonReadFiles.setObjectName(_fromUtf8("pushButtonReadFiles"))
self.pushButtonReadFiles.setText(_translate("MainWindow", "Read Files", None))
self.pushButtonReadFiles.clicked.connect(self.readFiles)
# Main - Close figure button
self.pushButtonClearGraph = QtGui.QPushButton(self.tabMain)
self.pushButtonClearGraph.setGeometry(QtCore.QRect(85, 170, 200, 30))
self.pushButtonClearGraph.setObjectName(_fromUtf8("pushButtonClearGraph"))
self.pushButtonClearGraph.setText(_translate("MainWindow", "Clear Graph", None))
self.pushButtonClearGraph.clicked.connect(self.clearGraph)
# Main - Start election algorithm button
self.pushButtonStartElection = QtGui.QPushButton(self.tabMain)
self.pushButtonStartElection.setGeometry(QtCore.QRect(85, 210, 200, 30))
self.pushButtonStartElection.setObjectName(_fromUtf8("pushButtonStartElection"))
self.pushButtonStartElection.setText(_translate("MainWindow", "Start Election Algorithm", None))
self.pushButtonStartElection.clicked.connect(self.startElection)
# Tab settings initialized
self.tabSettings = QtGui.QWidget()
self.tabSettings.setObjectName(_fromUtf8("tabSettings"))
settingUp = 30
settingSpace = 30
# settings - traceGrowth
self.checkBoxUseRandomCapacity = QtGui.QCheckBox(self.tabSettings)
self.checkBoxUseRandomCapacity.setGeometry(QtCore.QRect(85, settingUp, 300, 30))
self.checkBoxUseRandomCapacity.setObjectName(_fromUtf8("checkBoxUseRandomCapacity"))
self.checkBoxUseRandomCapacity.setText(_translate("MainWindow", "Use Random Capacity", None))
self.checkBoxUseRandomCapacity.setChecked(False)
# settings - traceLog
self.checkBoxTraceLog = QtGui.QCheckBox(self.tabSettings)
self.checkBoxTraceLog.setGeometry(QtCore.QRect(85, settingUp + settingSpace, 300 , 30))
self.checkBoxTraceLog.setObjectName(_fromUtf8("checkBoxTraceLog"))
self.checkBoxTraceLog.setText(_translate("MainWindow", "Graph Log", None))
self.checkBoxTraceLog.setChecked(False)
# settings - traceElection
self.checkBoxTraceElection = QtGui.QCheckBox(self.tabSettings)
self.checkBoxTraceElection.setGeometry(QtCore.QRect(85, settingUp + 2*settingSpace, 300, 30))
self.checkBoxTraceElection.setObjectName(_fromUtf8("checkBoxTraceElection"))
self.checkBoxTraceElection.setText(_translate("MainWindow", "Election Log", None))
self.checkBoxTraceElection.setChecked(False)
# settings - traceElectionVisual
self.checkBoxTraceElectionVisual = QtGui.QCheckBox(self.tabSettings)
self.checkBoxTraceElectionVisual.setGeometry(QtCore.QRect(85, settingUp + 3*settingSpace, 300, 30))
self.checkBoxTraceElectionVisual.setObjectName(_fromUtf8("checkBoxTraceElectionVisual"))
self.checkBoxTraceElectionVisual.setText(_translate("MainWindow", "Election Result Display", None))
self.checkBoxTraceElectionVisual.setChecked(False)
# settings - Coordinator Count label title
self.labelCoordinatorCount = QtGui.QLabel(self.tabSettings)
self.labelCoordinatorCount.setGeometry(QtCore.QRect(10, settingUp + 4*settingSpace, 170, 30))
self.labelCoordinatorCount.setObjectName(_fromUtf8("labelCoordinatorCount"))
self.labelCoordinatorCount.setText(_translate("MainWindow", "Coordinator Count: ", None))
# settings - labelCoordinatorCount label title
self.textEditlabelCoordinatorCount = QtGui.QLineEdit(self.tabSettings)
self.textEditlabelCoordinatorCount.setGeometry(QtCore.QRect(180, settingUp + 4*settingSpace, 200, 30))
self.textEditlabelCoordinatorCount.setObjectName(_fromUtf8("textEditlabelCoordinatorCount"))
# settings - label Weight Value label title
self.labelWeightValue = QtGui.QLabel(self.tabSettings)
self.labelWeightValue.setGeometry(QtCore.QRect(10, settingUp + 5*settingSpace, 170, 30))
self.labelWeightValue.setObjectName(_fromUtf8("labelWeightValue"))
self.labelWeightValue.setText(_translate("MainWindow", "Weight value: ", None))
# settings - textEditlabelWeightValue label title
self.textEditlabelWeightValue = QtGui.QLineEdit(self.tabSettings)
self.textEditlabelWeightValue.setGeometry(QtCore.QRect(180, settingUp + 5*settingSpace, 200, 30))
self.textEditlabelWeightValue.setObjectName(_fromUtf8("textEditlabelWeightValue"))
# Tab main initialized
self.tabNode = QtGui.QWidget()
self.tabNode.setObjectName(_fromUtf8("tabNode"))
# Main window
# Because of dialog exception
# MainWindow.setCentralWidget(self.centralwidget)
self.tabWidget.setCurrentIndex(0)
self.tabWidget.addTab(self.tabMain, _fromUtf8(""))
self.tabWidget.addTab(self.tabSettings, _fromUtf8(""))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabMain), _translate("MainWindow", "Main Menu", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabSettings), _translate("MainWindow", "Settings ", None))
QtCore.QMetaObject.connectSlotsByName(MainWindow)
# Fill with data
self.fill_fields()
self.set_check_box()
def startElection(self):
self.set_graph_trace()
self.graph.findCoordinates()
def draw(self):
self.set_graph_trace()
self.graph.draw()
def clearGraph(self):
self.set_graph_trace()
self.graph.removeAll()
self.fill_fields()
def readFiles(self):
self.set_graph_trace()
self.graph.removeAll()
self.graph.readFiles()
self.fill_fields()
self.graph.findCoordinates()
def fill_fields(self):
self.set_labels()
def set_labels(self):
num = len(self.graph.nodes.keys())
self.labelNodesCount.setText( "Number of Nodes : %s" % ( str(num) ) )
self.textEditlabelCoordinatorCount.setText( str(self.graph.cordinatorCount) )
self.textEditlabelWeightValue.setText( str(self.graph.weightValue) )
def set_graph_trace(self):
if self.checkBoxTraceLog.isChecked():
self.graph.traceLog = True
else:
self.graph.traceLog = False
if self.checkBoxUseRandomCapacity.isChecked():
self.graph.useRandomCapacity = True
else:
self.graph.useRandomCapacity = False
if self.checkBoxTraceElection.isChecked():
self.graph.traceElection = True
else:
self.graph.traceElection = False
if self.checkBoxTraceElectionVisual.isChecked():
self.graph.traceElectionVisual = True
else:
self.graph.traceElectionVisual = False
self.graph.cordinatorCount = int( self.textEditlabelCoordinatorCount.text())
self.graph.weightValue = float( self.textEditlabelWeightValue.text())
def set_check_box(self):
if self.graph.traceLog:
self.checkBoxTraceLog.setChecked(True)
else:
self.checkBoxTraceLog.setChecked(False)
if self.graph.useRandomCapacity:
self.checkBoxUseRandomCapacity.setChecked(True)
else:
self.checkBoxUseRandomCapacity.setChecked(False)
if self.graph.traceElection:
self.checkBoxTraceElection.setChecked(True)
else:
self.checkBoxTraceElection.setChecked(False)
if self.graph.traceElectionVisual:
self.checkBoxTraceElectionVisual.setChecked(True)
else:
self.checkBoxTraceElectionVisual.setChecked(False)
class Win(QtGui.QDialog,Ui_MainWindow):
def __init__(self):
Ui_MainWindow.__init__(self)
QtGui.QDialog.__init__(self)
self.setupUi(self)
# Main application
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MWindow = Win()
MWindow.show()
sys.exit(app.exec_())