def __init__(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()

        self.msg_warning = QMessageBox()
        self.msg_warning.setIcon(QMessageBox.Warning)
        self.msg_warning.setWindowTitle("MMUST NAVIGATOR")
示例#2
0
 def login(self):
     # self.hide()
     dbcon = DbCon()
     status = dbcon.getConnection()
     if status:
         username = self.txtusername.text()
         password = self.txtpassword.text()
         if username != '' and password != '':
             users = dbcon.authenticate_user(username, password)
             if users is not None:
                 # self.hide()
                 self.window = QtWidgets.QMainWindow()
                 self.ui = AdminPanel()
                 self.ui.AdminUi(self.window)
                 self.window.show()
             else:
                 self.msg_warning.setText("Invalid username or Password")
                 self.msg_warning.setStandardButtons(QMessageBox.Ok)
                 self.msg_warning.exec_()
                 self.txtusername.setText("")
                 self.txtpassword.setText("")
         else:
             self.msg_warning.setText("Fill all the values")
             self.msg_warning.setStandardButtons(QMessageBox.Ok)
             self.msg_warning.exec_()
             self.txtusername.setText("")
             self.txtpassword.setText("")
     else:
         self.msg_warning.setText(
             "Database Communication not established! ")
         self.msg_warning.setStandardButtons(QMessageBox.Ok)
         self.msg_warning.exec_()
示例#3
0
 def signup(self):
     dbcon = DbCon()
     status = dbcon.getConnection()
     if status:
         id = self.txt_userid.text()
         username = self.txt_username.text()
         password = self.txt_password.text()
         if id != "" and username != "" and password != "":
             if len(password) >= 8:
                 try:
                     dbcon.adduser(id, username, password)
                     self.txt_userid.setText("")
                     self.txt_username.setText("")
                     self.txt_password.setText("")
                     try:
                         self.window = QtWidgets.QMainWindow()
                         self.ui = Ui_Login()
                         self.ui.setupLogin(self.window)
                         self.window.show()
                     except Exception as e:
                         print(e)
                 except Error as e:
                     print(e)
             else:
                 print("password must be 8 or more characters")
         else:
             print("Fill all the fields")
     else:
         print("No database Connection Established")
示例#4
0
    def changeLoginDetails(self):
        username = self.txt_username.text()
        oldpass = self.txt_oldPass.text()
        newpass = self.txt_newPass.text()
        confirmpass = self.txt_confirmPass.text()
        try:
            self.dbcon = DbCon()
            self.status = self.dbcon.getConnection()
            if self.status:
                if username != "":
                    if newpass != "" and confirmpass != "":
                        if newpass == confirmpass:
                            try:
                                self.admin = self.dbcon.get_user(username)
                            except Error as e:
                                print(e)
                            print(self.admin[2])
                            if self.admin is not None:
                                if oldpass == self.admin[2]:
                                    print("Yes")
                                else:
                                    self.msg.setIcon(QMessageBox.Warning)
                                    self.msg.setText(
                                        "The oldpassword does not match")
                                    self.msg.setStandardButtons(QMessageBox.Ok)
                                    self.msg.exec_()
                            else:
                                self.msg.setIcon(QMessageBox.Warning)
                                self.msg.setText("The user does not exist")
                                self.msg.setStandardButtons(QMessageBox.Ok)
                                self.msg.exec_()
                        else:
                            self.msg.setIcon(QMessageBox.Warning)
                            self.msg.setText("Unmarching new password")
                            self.msg.setStandardButtons(QMessageBox.Ok)
                            self.msg.exec_()
                    else:
                        self.msg.setIcon(QMessageBox.Warning)
                        self.msg.setText(
                            "Ensure new password and confirm password are not empty"
                        )
                        self.msg.setStandardButtons(QMessageBox.Ok)
                        self.msg.exec_()
                else:
                    self.msg.setIcon(QMessageBox.Warning)
                    self.msg.setText("Please input the username")
                    self.msg.setStandardButtons(QMessageBox.Ok)
                    self.msg.exec_()
            else:
                self.msg.setIcon(QMessageBox.Warning)
                self.msg.setText("Database connection not established")
                self.msg.setStandardButtons(QMessageBox.Ok)
                self.msg.exec_()

        except Error as e:
            self.msg.setIcon(QMessageBox.Warning)
            self.msg.setText(str(e))
            self.msg.setStandardButtons(QMessageBox.Ok)
            self.msg.exec_()
示例#5
0
    def __init__(self, parent=None):
        super(ShortestPathController, self).__init__(parent=parent)
        self.setupShortestPath2(self)

        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()

        self.msg_warning = QMessageBox()
        self.msg_warning.setIcon(QMessageBox.Warning)
        self.msg_warning.setWindowTitle("MMUST NAVIGATOR")
示例#6
0
    def loadData(self):
        dbcon = DbCon()
        status = dbcon.getConnection()
        if status:
            rows = dbcon.get_vertices()
            self.tableWidget.setRowCount(0)
            horHeaders = ['ID','Name','Description']
            for row_number,row_data in enumerate(rows):
                self.tableWidget.insertRow(row_number)
                for column_number,column_data in enumerate(row_data):
                    self.tableWidget.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(column_data)))

            self.tableWidget.setHorizontalHeaderLabels(horHeaders)
        else:
            print("No connection!")
示例#7
0
 def addPath(self):
     self.dbcon = DbCon()
     self.status = self.dbcon.getConnection()
     if self.status:
         name = self.txtname.text()
         length = self.txt_length.text()
         startv = self.txt_from.text().upper()
         targetv = self.txt_to.text().upper()
         if name != "" and (startv != "" and targetv != ""):
             try:
                 length = int(length)
                 self.dbcon.add_edge(name, length, startv, targetv)
                 self.dbcon.add_edge(name, length, targetv, startv)
                 print("Path {} successfully added".format(name))
                 msg = QMessageBox()
                 msg.setIcon(QMessageBox.Information)
                 msg.setText(
                     "Path {} has been added to the databse".format(name))
                 msg.setWindowTitle("MMUST Navigator")
                 msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                 msg.exec()
                 self.txtname.setText("")
                 self.txt_length.setText("")
                 self.txt_from.setText("")
                 self.txt_to.setText("")
             except Error as e:
                 print(e)
                 msg.setIcon(QMessageBox.Information)
                 msg.setText(str(e))
                 msg.setWindowTitle("MMUST Navigator")
                 msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                 msg.exec()
             except Exception as ex:
                 print(ex)
                 msg.setIcon(QMessageBox.Information)
                 msg.setText(str(ex))
                 msg.setWindowTitle("MMUST Navigator")
                 msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                 msg.exec()
         else:
             print("fill all the values")
     else:
         print("No database connection")
示例#8
0
class Ui_PathView(object):
    def __init__(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()

    def setupPathView(self, PathView):
        PathView.setObjectName("PathView")
        PathView.resize(756, 533)
        self.centralwidget = QtWidgets.QWidget(PathView)
        self.centralwidget.setObjectName("centralwidget")
        self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
        self.tableWidget.setGeometry(QtCore.QRect(50, 10, 601, 431))
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(5)
        self.tableWidget.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(2, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(3, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(4, item)
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(310, 450, 75, 23))
        self.pushButton.setObjectName("pushButton")

        self.pushButton.clicked.connect(self.loadData)

        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(650, 460, 75, 23))
        self.pushButton_2.setObjectName("pushButton_2")

        self.pushButton_2.clicked.connect(self.cancell)

        PathView.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(PathView)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 756, 21))
        self.menubar.setObjectName("menubar")
        PathView.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(PathView)
        self.statusbar.setObjectName("statusbar")
        PathView.setStatusBar(self.statusbar)

        self.retranslateUi(PathView)
        QtCore.QMetaObject.connectSlotsByName(PathView)

        self.loadData()

    def retranslateUi(self, PathView):
        _translate = QtCore.QCoreApplication.translate
        PathView.setWindowTitle(_translate("PathView", "MainWindow"))
        item = self.tableWidget.horizontalHeaderItem(0)
        item.setText(_translate("PathView", "Path Id"))
        item = self.tableWidget.horizontalHeaderItem(1)
        item.setText(_translate("PathView", "Path name"))
        item = self.tableWidget.horizontalHeaderItem(2)
        item.setText(_translate("PathView", "Path length\n(metres)"))
        item = self.tableWidget.horizontalHeaderItem(3)
        item.setText(_translate("PathView", "To"))
        item = self.tableWidget.horizontalHeaderItem(4)
        item.setText(_translate("PathView", "From"))
        self.pushButton.setText(_translate("PathView", "Load Paths"))
        self.pushButton_2.setText(_translate("PathView", "Exit"))

    def loadData(self):
        if self.status:
            rows = self.dbcon.get_edges()
            self.tableWidget.setRowCount(0)
            # horHeaders = ['ID','Name','Description']
            for row_number, row_data in enumerate(rows):
                self.tableWidget.insertRow(row_number)
                for column_number, column_data in enumerate(row_data):
                    self.tableWidget.setItem(
                        row_number, column_number,
                        QtWidgets.QTableWidgetItem(str(column_data)))
        else:
            print("No connection!")

    def cancell(self):
        try:
            app1.quit()
        except Exception as e:
            print(e)
示例#9
0
class Ui_ShortestPath22(object):
    def __init__(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()

        self.msg_warning = QMessageBox()
        self.msg_warning.setIcon(QMessageBox.Warning)
        self.msg_warning.setWindowTitle("MMUST NAVIGATOR")

        self.textEdit = QtWidgets.QTextEdit()

    def setupShortestPath22(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(751, 510)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(170, 0, 391, 31))
        self.label.setObjectName("label")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(470, 440, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.txt_from = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_from.setGeometry(QtCore.QRect(230, 110, 231, 20))
        self.txt_from.setObjectName("txt_from")
        self.txt_to = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_to.setGeometry(QtCore.QRect(230, 170, 231, 20))
        self.txt_to.setObjectName("txt_to")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(140, 110, 71, 21))
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(140, 170, 51, 21))
        self.label_3.setObjectName("label_3")
        self.lblpath = QtWidgets.QLabel(self.centralwidget)
        self.lblpath.setGeometry(QtCore.QRect(130, 270, 441, 91))
        self.lblpath.setObjectName("lblpath")
        self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.textEdit.setEnabled(True)
        self.textEdit.setGeometry(QtCore.QRect(560, 40, 181, 421))
        self.textEdit.setReadOnly(True)
        self.textEdit.setObjectName("textEdit")
        self.lbl_buildingcodes = QtWidgets.QLabel(self.centralwidget)
        self.lbl_buildingcodes.setGeometry(QtCore.QRect(580, 20, 121, 16))
        self.lbl_buildingcodes.setObjectName("lbl_buildingcodes")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 751, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.pushButton.clicked.connect(self.calculate2)

        # self.loadVerticies()

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\"><span style=\" font-size:18pt; font-weight:600;\">SHORTEST PATH</span></p></body></html>"
            ))
        self.pushButton.setText(_translate("MainWindow", "Calculate"))
        self.label_2.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:12pt;\">From</span></p></body></html>"
            ))
        self.label_3.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:12pt;\">To</span></p></body></html>"
            ))
        self.lblpath.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\"><span style=\" font-size:11pt;\"><br/></span></p></body></html>"
            ))
        self.textEdit.setHtml(
            _translate(
                "MainWindow",
                "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
                "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
                "p, li { white-space: pre-wrap; }\n"
                "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
                "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"
            ))
        MainWindow.setWindowIcon(QIcon("pics\\icon"))
        self.lbl_buildingcodes.setText(
            _translate("MainWindow", "Building Codes to use"))
        self.loadVerticies()

    def calculate2(self):
        if self.status:

            from algorithms.Vertex import Vertex
            from algorithms.Edge import Edge
            from algorithms.Dijkstra import Dijkstra

            # db staff
            dbcon = DbCon()
            status = dbcon.getConnection()
            if status:
                dijkistra = Dijkstra()

                vertlist2 = []

                verts = dbcon.get_vertices()
                for vert in verts:
                    vertlist2.append(Vertex(vert[1]))
                edgelist = []
                edges = dbcon.get_edges()
                for edge in edges:

                    id = edge[0]
                    ename = edge[1]
                    w = edge[2]
                    sv = edge[3]
                    tv = edge[4]
                    b = edge[5]
                    for n in vertlist2:
                        if sv == n.name:
                            sn = n
                    for nn in vertlist2:
                        if tv == nn.name:
                            tn = nn
                    # p = Edge(id,ename,w,sv,tv)
                    if b == 0:
                        edgelist.append(Edge(id, ename, w, sn, tn, b))

                for edges in edgelist:
                    for sv in edges.startVertex:
                        # print(sv)
                        for n in vertlist2:
                            if sv == n.name:
                                sn = n
                        sn.adjacenciesList.append(edges)

                # print("--------------")
                # for edges in edgelist:
                #     for tv in edges.targetVertex:
                #         # print(tv)
                #         for nn in vertlist2:
                #             if tv == nn.name:
                #                 tn = nn
                #         tn.adjacenciesList.append(edges)
                # userinput1 = input("Enter startvertex: ").upper()
                # userinput2 = input("Enter targetvertex: ").upper()
                self.start_vertex = self.txt_from.text().upper()
                self.target_vertex = self.txt_to.text().upper()
                self.routes = ""
                self.bool1 = False
                self.bool2 = False

                if self.start_vertex != "" and self.target_vertex != "":
                    for vert in vertlist2:
                        if self.start_vertex == vert.name:
                            dijkistra.calculateShrtestPath(vertlist2, vert)
                            self.bool1 = True
                        # else:
                        #     self.msg_warning.setText("Vertex {} does not exist on the graph".format(self.start_vertex))
                        #     self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        #     self.msg_warning.exec_()
                    for vert in vertlist2:
                        if self.target_vertex == vert.name:
                            path = dijkistra.getShortestPathTo2(vert)
                            self.bool2 = True
                            path.reverse()
                            if vert.minDistance != sys.maxsize:
                                self.routes = "Traversing from {} to {}\n\tDistance ".format(
                                    self.start_vertex,
                                    self.target_vertex) + str(
                                        vert.minDistance) + "m\n\nPath is"
                                for nodes in path:
                                    self.routes += "-->" + nodes
                                self.lblpath.setText(self.routes)
                            else:
                                # self.lblpath.selectedText("")
                                self.lblpath.setText(
                                    "There is no effective path from {} to {}".
                                    format(self.start_vertex,
                                           self.target_vertex))
                                self.msg_warning.setText(
                                    "There is no effective path from {} to {}".
                                    format(self.start_vertex,
                                           self.target_vertex))
                                self.msg_warning.setStandardButtons(
                                    QMessageBox.Ok)
                                self.msg_warning.exec_()
                        # else:
                        #     self.msg_warning.setText("Vertex {} does not exist on the graph".format(self.start_vertex))
                        #     self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        #     self.msg_warning.exec_()
                    if self.bool1:
                        pass
                    else:
                        self.msg_warning.setText(
                            "Vertex {} does not exist on the graph".format(
                                self.start_vertex))
                        self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        self.msg_warning.exec_()
                    if self.bool2:
                        pass
                    else:
                        self.msg_warning.setText(
                            "Vertex {} does not exist on the graph".format(
                                self.target_vertex))
                        self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        self.msg_warning.exec_()
                else:
                    self.msg_warning.setText("Fill all the input values")
                    self.msg_warning.setStandardButtons(QMessageBox.Ok)
                    self.msg_warning.exec_()

        else:
            self.msg_warning.setText("No database Connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def loadVerticies(self):
        if self.status:
            from algorithms.Edge import Edge

            verts = self.dbcon.get_vertices()
            for vert in verts:
                self.textEdit.append(vert[1] + "--->" + vert[2] + "\n")
            self.textEdit.append("*****Blocked Paths*****\n")

            edgelist = []
            vertlist = []
            for vert in verts:
                vertlist.append(Vertex(vert[1]))
            edges = self.dbcon.get_edges()
            for edge in edges:

                id = edge[0]
                ename = edge[1]
                w = edge[2]
                sv = edge[3]
                tv = edge[4]
                b = edge[5]
                for n in vertlist:
                    if sv == n.name:
                        sn = n
                for nn in vertlist:
                    if tv == nn.name:
                        tn = nn
                # p = Edge(id,ename,w,sv,tv)
                edgelist.append(Edge(id, ename, w, sn, tn, b))

            edgelist2 = set(edgelist)
            for edge in edgelist2:
                if edge.blocked == 1:
                    self.textEdit.append(edge.edgename)
        else:
            self.textEdit.setText(
                """The Network connection is Offline at the Momment\n
                                    Please try again sometimes later""")
示例#10
0
    def calculate2(self):
        if self.status:

            from algorithms.Vertex import Vertex
            from algorithms.Edge import Edge
            from algorithms.Dijkstra import Dijkstra

            # db staff
            dbcon = DbCon()
            status = dbcon.getConnection()
            if status:
                dijkistra = Dijkstra()

                vertlist2 = []

                verts = dbcon.get_vertices()
                for vert in verts:
                    vertlist2.append(Vertex(vert[1]))
                edgelist = []
                edges = dbcon.get_edges()
                for edge in edges:

                    id = edge[0]
                    ename = edge[1]
                    w = edge[2]
                    sv = edge[3]
                    tv = edge[4]
                    b = edge[5]
                    for n in vertlist2:
                        if sv == n.name:
                            sn = n
                    for nn in vertlist2:
                        if tv == nn.name:
                            tn = nn
                    # p = Edge(id,ename,w,sv,tv)
                    if b == 0:
                        edgelist.append(Edge(id, ename, w, sn, tn, b))

                for edges in edgelist:
                    for sv in edges.startVertex:
                        # print(sv)
                        for n in vertlist2:
                            if sv == n.name:
                                sn = n
                        sn.adjacenciesList.append(edges)

                # print("--------------")
                # for edges in edgelist:
                #     for tv in edges.targetVertex:
                #         # print(tv)
                #         for nn in vertlist2:
                #             if tv == nn.name:
                #                 tn = nn
                #         tn.adjacenciesList.append(edges)
                # userinput1 = input("Enter startvertex: ").upper()
                # userinput2 = input("Enter targetvertex: ").upper()
                self.start_vertex = self.txt_from.text().upper()
                self.target_vertex = self.txt_to.text().upper()
                self.routes = ""
                self.bool1 = False
                self.bool2 = False

                if self.start_vertex != "" and self.target_vertex != "":
                    for vert in vertlist2:
                        if self.start_vertex == vert.name:
                            dijkistra.calculateShrtestPath(vertlist2, vert)
                            self.bool1 = True
                        # else:
                        #     self.msg_warning.setText("Vertex {} does not exist on the graph".format(self.start_vertex))
                        #     self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        #     self.msg_warning.exec_()
                    for vert in vertlist2:
                        if self.target_vertex == vert.name:
                            path = dijkistra.getShortestPathTo2(vert)
                            self.bool2 = True
                            path.reverse()
                            if vert.minDistance != sys.maxsize:
                                self.routes = "Traversing from {} to {}\n\tDistance ".format(
                                    self.start_vertex,
                                    self.target_vertex) + str(
                                        vert.minDistance) + "m\n\nPath is"
                                for nodes in path:
                                    self.routes += "-->" + nodes
                                self.lblpath.setText(self.routes)
                            else:
                                # self.lblpath.selectedText("")
                                self.lblpath.setText(
                                    "There is no effective path from {} to {}".
                                    format(self.start_vertex,
                                           self.target_vertex))
                                self.msg_warning.setText(
                                    "There is no effective path from {} to {}".
                                    format(self.start_vertex,
                                           self.target_vertex))
                                self.msg_warning.setStandardButtons(
                                    QMessageBox.Ok)
                                self.msg_warning.exec_()
                        # else:
                        #     self.msg_warning.setText("Vertex {} does not exist on the graph".format(self.start_vertex))
                        #     self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        #     self.msg_warning.exec_()
                    if self.bool1:
                        pass
                    else:
                        self.msg_warning.setText(
                            "Vertex {} does not exist on the graph".format(
                                self.start_vertex))
                        self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        self.msg_warning.exec_()
                    if self.bool2:
                        pass
                    else:
                        self.msg_warning.setText(
                            "Vertex {} does not exist on the graph".format(
                                self.target_vertex))
                        self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        self.msg_warning.exec_()
                else:
                    self.msg_warning.setText("Fill all the input values")
                    self.msg_warning.setStandardButtons(QMessageBox.Ok)
                    self.msg_warning.exec_()

        else:
            self.msg_warning.setText("No database Connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()
示例#11
0
class Ui_MainWindow(object):
    def __init__(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()
        self.msg_warning = QMessageBox()
        self.msg_warning.setIcon(QMessageBox.Warning)
        self.msg_warning.setWindowTitle("MMUST NAVIGATOR")

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(734, 523)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(180, 10, 251, 31))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(140, 110, 81, 21))
        self.label_2.setObjectName("label_2")
        self.txtid = QtWidgets.QLineEdit(self.centralwidget)
        self.txtid.setGeometry(QtCore.QRect(270, 110, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.txtid.setFont(font)
        self.txtid.setObjectName("txtid")
        self.txtname = QtWidgets.QLineEdit(self.centralwidget)
        self.txtname.setGeometry(QtCore.QRect(270, 169, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.txtname.setFont(font)
        self.txtname.setObjectName("txtname")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(140, 180, 81, 21))
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(140, 300, 81, 21))
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(140, 240, 111, 21))
        self.label_5.setObjectName("label_5")
        self.txtweight = QtWidgets.QLineEdit(self.centralwidget)
        self.txtweight.setGeometry(QtCore.QRect(270, 229, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.txtweight.setFont(font)
        self.txtweight.setObjectName("txtweight")
        self.txtfrom = QtWidgets.QLineEdit(self.centralwidget)
        self.txtfrom.setGeometry(QtCore.QRect(270, 289, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.txtfrom.setFont(font)
        self.txtfrom.setObjectName("txtfrom")
        self.txtto = QtWidgets.QLineEdit(self.centralwidget)
        self.txtto.setGeometry(QtCore.QRect(270, 349, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.txtto.setFont(font)
        self.txtto.setObjectName("txtto")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(140, 360, 81, 21))
        self.label_6.setObjectName("label_6")
        self.btnSave = QtWidgets.QPushButton(self.centralwidget)
        self.btnSave.setGeometry(QtCore.QRect(500, 450, 75, 31))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.btnSave.setFont(font)
        self.btnSave.setObjectName("btnSave")
        self.btnCancel = QtWidgets.QPushButton(self.centralwidget)
        self.btnCancel.setGeometry(QtCore.QRect(610, 450, 75, 31))
        font = QtGui.QFont()
        font.setPointSize(12)
        self.btnCancel.setFont(font)
        self.btnCancel.setObjectName("btnCancel")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 734, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        #event actions
        self.btnSave.clicked.connect(self.addPath)
        self.btnCancel.clicked.connect(self.cancel)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\"><span style=\" font-size:18pt; font-weight:600;\">Create Path</span></p></body></html>"
            ))
        self.label_2.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:12pt;\">Path id</span></p></body></html>"
            ))
        self.label_3.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:12pt;\">Path name</span></p></body></html>"
            ))
        self.label_4.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:12pt;\">From</span></p></body></html>"
            ))
        self.label_5.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:12pt;\">weight(length)</span></p></body></html>"
            ))
        self.label_6.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:12pt;\">To</span></p></body></html>"
            ))
        self.btnSave.setText(_translate("MainWindow", "Save"))
        self.btnCancel.setText(_translate("MainWindow", "Cancel"))
        MainWindow.setWindowIcon(QIcon('pics\\icon.png'))

    def addPath(self):
        if self.status:
            self.pathid = self.txtid.text()
            self.pathname = self.txtname.text()
            self.weight = self.txtweight.text()
            self.startVertex = self.txtfrom.text().upper()
            self.targetVertex = self.txtto.text().upper()

            vertList = []
            verticies = self.dbcon.get_vertices()
            if self.pathid != "":
                for vert in verticies:
                    vertList.append(vert[1])
                if self.startVertex not in vertList:
                    print("The vertex {} does not exist on the graph".format(
                        self.startVertex))
                    self.msg_warning.setText(
                        "The vertex {} does not exist on the graph".format(
                            self.startVertex))
                    self.msg.setStandardButtons(QMessageBox.Ok)
                    self.msg_warning.exec_()
                elif self.targetVertex not in vertList:
                    print("The vertex {} does not exist on the graph".format(
                        self.startVertex))
                    self.msg_warning.setText(
                        "The vertex {} does not exist on the graph".format(
                            self.startVertex))
                    self.msg_warning.setStandardButtons(QMessageBox.Ok)
                    self.msg_warning.exec_()
                else:
                    try:
                        self.dbcon.add_edge(self.pathid, self.pathname,
                                            self.weight, self.startVertex,
                                            self.targetVertex)
                    except Exception as ex:
                        print(ex)
                    msg = QMessageBox()
                    msg.setIcon(QMessageBox.Information)
                    msg.setText(
                        "Path {} {} has been added to the databse".format(
                            self.pathid, self.pathname))
                    # msg.setInformativeText("Are you sure want to delete path?")
                    msg.setWindowTitle("Delete")
                    # msg.setDetailedText("The details are as follows:")
                    msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                    # msg.buttonClicked.connect(self.msgbtn)

                    retval = msg.exec_()

                    print("Path {} {} has been added to the databse".format(
                        self.pathid, self.pathname))
                    self.txtid.setText('')
                    self.txtname.setText('')
                    self.txtweight.setText("")
                    self.txtfrom.setText("")
                    self.txtto.setText("")
            else:
                self.msg_warning.setText("The path id cannot be empty")
                self.msg_warning.setStandardButtons(QMessageBox.Ok)
                self.msg_warning.exec_()
        else:
            print('Path not saved')
            self.msg_warning.setText("Path has not been saved")
            self.msg.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def cancel(self):
        self.msg = QMessageBox()
        self.msg.setIcon(QMessageBox.Information)

        self.msg.setText("This is a message box")
        self.msg.setInformativeText("This is additional information")
        self.msg.setWindowTitle("MessageBox demo")
        self.msg.setDetailedText("The details are as follows:")
        self.msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
        self.msg.exec_()
class Ui_ManagePaths2(object):
    def __init__(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()

        self.msg_info = QMessageBox()
        self.msg_info.setIcon(QMessageBox.Information)
        self.msg_info.setWindowTitle("MMUST NAVIGATOR")

        self.msg_warning = QMessageBox()
        self.msg_warning.setIcon(QMessageBox.Warning)
        self.msg_warning.setWindowTitle("MMUST NAVIGATOR")

    def loadData(self):

        if self.status:
            rows = self.dbcon.get_edges()
            self.tableWidget.setRowCount(0)
            for row_number, row_data in enumerate(rows):
                self.tableWidget.insertRow(row_number)
                for column_number, column_data in enumerate(row_data):
                    self.tableWidget.setItem(
                        row_number, column_number,
                        QtWidgets.QTableWidgetItem(str(column_data)))

        else:
            print("No connection!")

    def loadBlockedPaths(self):

        if self.status:
            rows = self.dbcon.blockedPaths()
            self.tableWidget.setRowCount(0)
            for row_number, row_data in enumerate(rows):
                self.tableWidget.insertRow(row_number)
                for column_number, column_data in enumerate(row_data):
                    self.tableWidget.setItem(
                        row_number, column_number,
                        QtWidgets.QTableWidgetItem(str(column_data)))
        else:
            print("No connection!")

    def setupManagePaths2(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1007, 462)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.btn_load = QtWidgets.QPushButton(self.centralwidget)
        self.btn_load.setGeometry(QtCore.QRect(10, 60, 75, 23))
        self.btn_load.setObjectName("btn_load")
        self.btn_select = QtWidgets.QPushButton(self.centralwidget)
        self.btn_select.setGeometry(QtCore.QRect(10, 140, 75, 23))
        self.btn_select.setObjectName("btn_select")
        self.btn_addPath = QtWidgets.QPushButton(self.centralwidget)
        self.btn_addPath.setGeometry(QtCore.QRect(10, 190, 75, 23))
        self.btn_addPath.setObjectName("btn_addPath")
        self.btn_blockPath = QtWidgets.QPushButton(self.centralwidget)
        self.btn_blockPath.setGeometry(QtCore.QRect(780, 390, 71, 23))
        self.btn_blockPath.setObjectName("btn_blockPath")
        self.btn_delete = QtWidgets.QPushButton(self.centralwidget)
        self.btn_delete.setGeometry(QtCore.QRect(900, 390, 71, 23))
        self.btn_delete.setObjectName("btn_delete")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(180, 5, 281, 31))
        self.label.setObjectName("label")
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setGeometry(QtCore.QRect(640, 0, 20, 461))
        self.line.setFrameShape(QtWidgets.QFrame.VLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
        self.tableWidget.setGeometry(QtCore.QRect(100, 40, 531, 291))
        self.tableWidget.setColumnCount(5)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(2, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(3, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(4, item)
        self.txt_id = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_id.setGeometry(QtCore.QRect(780, 50, 201, 31))
        self.txt_id.setObjectName("txt_id")
        self.txt_weight = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_weight.setGeometry(QtCore.QRect(780, 170, 201, 31))
        self.txt_weight.setObjectName("txt_weight")
        self.txt_name = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_name.setGeometry(QtCore.QRect(780, 110, 201, 31))
        self.txt_name.setObjectName("txt_name")
        self.txt_startv = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_startv.setGeometry(QtCore.QRect(780, 230, 201, 31))
        self.txt_startv.setObjectName("txt_startv")
        self.btn_editPath = QtWidgets.QPushButton(self.centralwidget)
        self.btn_editPath.setGeometry(QtCore.QRect(780, 350, 71, 23))
        self.btn_editPath.setObjectName("btn_editPath")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(670, 52, 81, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(670, 110, 81, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(670, 170, 81, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_4.setFont(font)
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(670, 230, 91, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.txt_targetv = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_targetv.setGeometry(QtCore.QRect(780, 290, 201, 31))
        self.txt_targetv.setObjectName("txt_targetv")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(670, 290, 101, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
        self.btn_deleteAll = QtWidgets.QPushButton(self.centralwidget)
        self.btn_deleteAll.setGeometry(QtCore.QRect(510, 360, 111, 23))
        self.btn_deleteAll.setObjectName("btn_deleteAll")
        self.btn_blockedPath = QtWidgets.QPushButton(self.centralwidget)
        self.btn_blockedPath.setGeometry(QtCore.QRect(10, 100, 75, 23))
        self.btn_blockedPath.setObjectName("btn_blockedPath")
        self.btn_unblockPath = QtWidgets.QPushButton(self.centralwidget)
        self.btn_unblockPath.setGeometry(QtCore.QRect(900, 350, 75, 23))
        self.btn_unblockPath.setObjectName("btn_unblockPath")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1007, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.btn_load.clicked.connect(self.loadData)  #######
        self.btn_blockedPath.clicked.connect(self.loadBlockedPaths)
        self.btn_select.clicked.connect(self.tableSelection)
        self.btn_addPath.clicked.connect(self.open_addPath)  #########
        self.btn_deleteAll.clicked.connect(self.delete_all)  ########
        self.btn_editPath.clicked.connect(self.update_path)  #########
        self.btn_unblockPath.clicked.connect(self.unblockPath)
        self.btn_blockPath.clicked.connect(self.blockPath)  ######
        self.btn_delete.clicked.connect(self.delete_one)  #######

        try:
            self.loadData()
        except Error as e:
            self.msg_warning.setText("The database is offline")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.btn_load.setText(_translate("MainWindow", "Load Paths"))
        self.btn_select.setText(_translate("MainWindow", "Select >>"))
        self.btn_addPath.setText(_translate("MainWindow", "Add Path"))
        self.btn_blockPath.setText(_translate("MainWindow", "Block Path"))
        self.btn_delete.setText(_translate("MainWindow", "Delete Path"))
        self.label.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\"><span style=\" font-size:16pt; font-weight:600;\">PATHS PANEL</span></p></body></html>"
            ))
        item = self.tableWidget.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "ID"))
        item = self.tableWidget.horizontalHeaderItem(1)
        item.setText(_translate("MainWindow", "NAME"))
        item = self.tableWidget.horizontalHeaderItem(2)
        item.setText(_translate("MainWindow", "WEIGHT"))
        item = self.tableWidget.horizontalHeaderItem(3)
        item.setText(_translate("MainWindow", "START VERTEX"))
        item = self.tableWidget.horizontalHeaderItem(4)
        item.setText(_translate("MainWindow", "TARGET VERTEX"))
        self.btn_editPath.setText(_translate("MainWindow", "Edit Path"))
        self.label_2.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:12pt;\">ID</span></p></body></html>"
            ))
        self.label_3.setText(_translate("MainWindow", "NAME"))
        self.label_4.setText(_translate("MainWindow", "WEIGHT"))
        self.label_5.setText(_translate("MainWindow", "START VERTEX"))
        self.label_6.setText(_translate("MainWindow", "TARGET VERTEX"))
        self.btn_deleteAll.setText(_translate("MainWindow",
                                              "Delete All Paths"))
        self.btn_blockedPath.setText(_translate("MainWindow", "Blocked Paths"))
        self.btn_unblockPath.setText(_translate("MainWindow", "Unblock Path"))
        MainWindow.setWindowIcon(QIcon('pics\\icon.png'))

    def open_addPath(self):
        self.window = QtWidgets.QMainWindow()
        self.ui = Ui_AddPath2()
        self.ui.setupAddPath2(self.window)
        self.window.show()

    def tableSelection(self):
        indexes = self.tableWidget.selectionModel().selectedRows()
        for index in sorted(indexes):
            # print('Row %d is selected' % index.row())
            row = int(index.row())
            id = self.tableWidget.item(row, 0)
            name = self.tableWidget.item(row, 1)
            weight = self.tableWidget.item(row, 2)
            startv = self.tableWidget.item(row, 3)
            targetv = self.tableWidget.item(row, 4)

            self.txt_id.setText(id.text())
            self.txt_name.setText(name.text())
            self.txt_weight.setText(weight.text())
            self.txt_startv.setText(startv.text())
            self.txt_targetv.setText(targetv.text())

    def update_path(self):
        if self.status:
            id = self.txt_id.text()
            name = self.txt_name.text()
            weight = self.txt_weight.text()
            startv = self.txt_startv.text()
            targetv = self.txt_targetv.text()
            if id != "":
                self.msg_info.setText(
                    "Are you sure you want to update path {}?".format(name))
                self.msg_info.setWindowTitle("Path Update")
                self.msg_info.setStandardButtons(QMessageBox.Ok
                                                 | QMessageBox.Cancel)

                retval = self.msg_info.exec_()
                if retval == 1024:
                    self.dbcon.update_edge(id, name, weight, startv, targetv)
                    self.msg_info.setText(
                        "Path {} successfully updated!".format(id))
                    self.msg_info.setStandardButtons(QMessageBox.Ok)
                    self.msg_info.exec_()

                    self.txt_id.setText("")
                    self.txt_name.setText("")
                    self.txt_weight.setText("")
                    self.txt_startv.setText("")
                    self.txt_targetv.setText("")
            else:
                self.msg_warning.setText("Select a path to update it")
                self.msg_warning.setStandardButtons(QMessageBox.Ok)
                self.msg_warning.exec_()
        else:
            self.msg_warning.setText("No database connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def delete_one(self):
        if self.status:
            id = self.txt_id.text()
            if id != "":
                self.msg_info.setText(
                    "Are you sure want to delete path: {}?".format(id))
                self.msg_info.setWindowTitle("Delete")
                self.msg_info.setStandardButtons(QMessageBox.Ok
                                                 | QMessageBox.Cancel)

                retval = self.msg_info.exec_()
                if retval == 1024:
                    self.dbcon.delete_edge(id)

                    self.msg_info.setText(
                        "Edge {} successfully deleted!".format(id))
                    self.msg_info.setStandardButtons(QMessageBox.Ok)
                    self.msg_info.exec_()

                    self.txt_id.setText("")
                    self.txt_name.setText("")
                    self.txt_weight.setText("")
                    self.txt_startv.setText("")
                    self.txt_targetv.setText("")
            else:
                self.msg_warning.setText("Select a path first delete it")
                self.msg_warning.setStandardButtons(QMessageBox.Ok)
                self.msg_warning.exec_()
        else:
            self.msg_warning.setText("No database connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def delete_all(self):
        if self.status:
            # msg = QMessageBox()
            # msg.setIcon(QMessageBox.Warning)

            self.msg_info.setText(
                "Are you sure you want to delete all the paths?")
            # msg.setInformativeText("Are you sure you want to delete all the paths?")
            self.msg_info.setWindowTitle("Delete All")
            # msg.setDetailedText("The details are as follows:")
            self.msg_info.setStandardButtons(QMessageBox.Ok
                                             | QMessageBox.Cancel)
            # msg.buttonClicked.connect(self.msgbtn)

            retval = self.msg_info.exec_()
            # print("value of pressed message box button:", retval)
            if retval == 1024:
                self.dbcon.delete_edges()
                self.msg_info.setText("All the edges have been deleted!")
                self.msg_info.setStandardButtons(QMessageBox.Ok)
                self.msg_info.exec_()

                self.txt_id.setText("")
                self.txt_name.setText("")
                self.txt_weight.setText("")
                self.txt_startv.setText("")
                self.txt_targetv.setText("")

        else:
            self.msg_warning.setText("No database connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def blockPath(self):
        pathname = self.txt_name.text()
        sv = self.txt_startv.text()
        tv = self.txt_targetv.text()
        if pathname != "":
            try:
                self.dbcon.block_path2(pathname)
                print("Path " + pathname + " has been blocked")
                self.txt_id.setText("")
                self.txt_name.setText("")
                self.txt_weight.setText("")
                self.txt_startv.setText("")
                self.txt_targetv.setText("")
            except Error as e:
                print(e)
        else:
            self.msg_warning.setText("Please enter a path name")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def unblockPath(self):
        pathname = self.txt_name.text()
        sv = self.txt_startv.text()
        tv = self.txt_targetv.text()
        if pathname != "":
            try:
                self.dbcon.unblock_path2(pathname)
                print("Path " + pathname + " has been unblocked")
                self.txt_id.setText("")
                self.txt_name.setText("")
                self.txt_weight.setText("")
                self.txt_startv.setText("")
                self.txt_targetv.setText("")
            except Error as e:
                print(e)
        else:
            self.msg_warning.setText("Please enter a path name")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def get_PathId(self):
        self.pathid = self.txt_id.text()
        return self.pathid
示例#13
0
from algorithms.Vertex import Vertex
from algorithms.Edge2 import Edge2
from algorithms.Dijkstra import Dijkstra
import MySQLdb
from _mysql_exceptions import Error
from dbconnections.DbCon import DbCon

#db staff
print("Attempting database connection ........")
dbcon = DbCon()
status = dbcon.getConnection()
if status:
    # print("Enter Start Vertex id: ")
    # svertex = int(input())
    # print("Enter Target Vertex id: ")
    # svertex = int(input())

    dijkistra = Dijkstra()

    vertlist2 = []

    verts = dbcon.get_vertices()
    for vert in verts:
        vertlist2.append(Vertex(vert[1]))
    edgelist = []
    edges = dbcon.get_edges()
    for edge in edges:
        # id = edge[0]
        ename = edge[0]
        w = edge[1]
        sv = edge[2]
class Ui_ShortestPath2(object):
    def __init__(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()

        self.msg_warning = QMessageBox()
        self.msg_warning.setIcon(QMessageBox.Warning)
        self.msg_warning.setWindowTitle("MMUST NAVIGATOR")

    def setupShortestPath2(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(751, 510)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(170, 0, 391, 31))
        self.label.setObjectName("label")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(550, 440, 75, 23))
        self.pushButton.setObjectName("pushButton")

        self.pushButton.clicked.connect(self.calculate2)

        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(650, 440, 75, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.txt_from = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_from.setGeometry(QtCore.QRect(230, 110, 231, 20))
        self.txt_from.setObjectName("txt_from")
        self.txt_to = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_to.setGeometry(QtCore.QRect(230, 170, 231, 20))
        self.txt_to.setObjectName("txt_to")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(140, 110, 71, 21))
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(140, 170, 51, 21))
        self.label_3.setObjectName("label_3")
        self.lblpath = QtWidgets.QLabel(self.centralwidget)
        self.lblpath.setGeometry(QtCore.QRect(130, 270, 511, 51))
        self.lblpath.setObjectName("lblpath")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 751, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><span style=\" font-size:18pt; font-weight:600;\">SHORTEST PATH</span></p></body></html>"))
        self.pushButton.setText(_translate("MainWindow", "Calculate"))
        self.pushButton_2.setText(_translate("MainWindow", "Cancel"))
        self.label_2.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">From</span></p></body></html>"))
        self.label_3.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:12pt;\">To</span></p></body></html>"))
        self.lblpath.setText(_translate("MainWindow", "<html><head/><body><p align=\"center\"><br/></p></body></html>"))

    def calculate(self):
        if self.status:
            self.start_vertex = self.txt_from.text()
            self.target_vertex = self.txt_to.text()
            vertex = self.dbcon.get_vertex(self.start_vertex)
            self.lblpath.setText(vertex[2])
            print(str(vertex))
        else:
            print("Not connected")
    def calculate2(self):
        try:
            if self.status:

                from algorithms.Vertex import Vertex
                from algorithms.Edge import Edge
                from algorithms.Dijkstra import Dijkstra

                # db staff
                dbcon = DbCon()
                status = dbcon.getConnection()
                if status:
                    dijkistra = Dijkstra()

                    vertlist2 = []

                    verts = dbcon.get_vertices()
                    for vert in verts:
                        vertlist2.append(Vertex(vert[1]))
                    edgelist = []
                    edges = dbcon.get_edges()
                    for edge in edges:

                        id = edge[0]
                        ename = edge[1]
                        w = edge[2]
                        sv = edge[3]
                        tv = edge[4]
                        for n in vertlist2:
                            if sv == n.name:
                                sn = n
                        for nn in vertlist2:
                            if tv == nn.name:
                                tn = nn
                        # p = Edge(id,ename,w,sv,tv)
                        edgelist.append(Edge(id, ename, w, sn, tn))

                    for edges in edgelist:
                        for sv in edges.startVertex:
                            # print(sv)
                            for n in vertlist2:
                                if sv == n.name:
                                    sn = n
                            sn.adjacenciesList.append(edges)
                    # print("--------------")
                    # for edges in edgelist:
                    #     for tv in edges.targetVertex:
                    #         # print(tv)
                    #         for nn in vertlist2:
                    #             if tv == nn.name:
                    #                 tn = nn
                    #         tn.adjacenciesList.append(edges)
                    # userinput1 = input("Enter startvertex: ").upper()
                    # userinput2 = input("Enter targetvertex: ").upper()
                    self.start_vertex = self.txt_from.text().upper()
                    self.target_vertex = self.txt_to.text().upper()
                    self.routes = ""
                    self.bool1 = False
                    self.bool2 = False

                    if self.start_vertex !="" and self.target_vertex !="":
                        for vert in vertlist2:
                            if self.start_vertex == vert.name:
                                dijkistra.calculateShrtestPath(vertlist2, vert)
                                self.bool1 = True
                            # else:
                            #     self.msg_warning.setText("Vertex {} does not exist on the graph".format(self.start_vertex))
                            #     self.msg_warning.setStandardButtons(QMessageBox.Ok)
                            #     self.msg_warning.exec_()
                        for vert in vertlist2:
                            if self.target_vertex == vert.name:
                                path = dijkistra.getShortestPathTo2(vert)
                                self.bool2 = True
                                path.reverse()
                                if vert.minDistance != sys.maxsize:
                                    self.routes = "Traversing from {} to {}\n\tDistance ".format(self.start_vertex,self.target_vertex)+str(vert.minDistance)+"\n\nPath is"
                                    for nodes in path:
                                        self.routes += " "+nodes
                                    self.lblpath.setText(self.routes)
                                else:
                                    # self.lblpath.selectedText("")
                                    self.msg_warning.setText("There is no effective path to {}".format(self.target_vertex))
                                    self.msg_warning.setStandardButtons(QMessageBox.Ok)
                                    self.msg_warning.exec_()
                            # else:
                            #     self.msg_warning.setText("Vertex {} does not exist on the graph".format(self.start_vertex))
                            #     self.msg_warning.setStandardButtons(QMessageBox.Ok)
                            #     self.msg_warning.exec_()
                        if self.bool1:
                            pass
                        else:
                            self.msg_warning.setText("Vertex {} does not exist on the graph".format(self.start_vertex))
                            self.msg_warning.setStandardButtons(QMessageBox.Ok)
                            self.msg_warning.exec_()
                        if self.bool2:
                            pass
                        else:
                            self.msg_warning.setText("Vertex {} does not exist on the graph".format(self.target_vertex))
                            self.msg_warning.setStandardButtons(QMessageBox.Ok)
                            self.msg_warning.exec_()
                    else:
                        self.msg_warning.setText("Fill all the input values")
                        self.msg_warning.setStandardButtons(QMessageBox.Ok)
                        self.msg_warning.exec_()

            else:
                self.msg_warning.setText("No database Connection")
                self.msg_warning.setStandardButtons(QMessageBox.Ok)
                self.msg_warning.exec_()
        except Exception as e:
            print(e)
示例#15
0
from algorithms.Vertex import Vertex
from algorithms.Edge import Edge
from algorithms.Dijkstra import Dijkstra
import MySQLdb
from _mysql_exceptions import Error
from dbconnections.DbCon import DbCon

#db staff
print("Attempting database connection ........")
dbcon = DbCon()
status = dbcon.getConnection()
if status:
    # print("Enter Start Vertex id: ")
    # svertex = int(input())
    # print("Enter Target Vertex id: ")
    # svertex = int(input())

    n1 = dbcon.get_vertex(1)[1]
    n2 = dbcon.get_vertex(2)[1]
    n3 = dbcon.get_vertex(3)[1]
    e1 = dbcon.get_edge(1)
    e2 = dbcon.get_edge(2)
    e3 = dbcon.get_edge(34)

    # nv1 = Vertex(n1)
    # nv2 = Vertex(n2)
    # nv3 = Vertex(n3)
    nv1 = Vertex('SPD')
    nv2 = Vertex('LBB')
    nv3 = Vertex('MCU')
示例#16
0
from algorithms.Vertex import Vertex
from algorithms.Edge import Edge
from algorithms.Dijkstra import Dijkstra
import MySQLdb
from _mysql_exceptions import Error
from dbconnections.DbCon import DbCon

#db staff
print("Attempting database connection ........")
dbcon = DbCon()
status = dbcon.getConnection()
if status:
    dijkistra = Dijkstra()

    # vertlist2 = []
    #
    # verts = dbcon.get_vertices()
    # for vert in verts:
    #     vertlist2.append(Vertex(vert[1]))
    # edgelist = []
    # edges = dbcon.get_edges()
    # for edge in edges:
    #     id = edge[0]
    #     ename = edge[1]
    #     w = edge[2]
    #     sv = edge[3]
    #     tv = edge[4]
    #     for n in vertlist2:
    #         if sv == n.name:
    #             sn = n
    #     for nn in vertlist2:
示例#17
0
class Ui_Account(object):
    def __init__(self):
        self.msg = QMessageBox()
        self.msg.setWindowTitle("Login")

    def setupAccount(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(520, 396)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.txt_username = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_username.setGeometry(QtCore.QRect(130, 50, 251, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.txt_username.setFont(font)
        self.txt_username.setObjectName("txt_username")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(160, 10, 151, 21))
        self.label.setObjectName("label")
        self.txt_oldPass = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_oldPass.setGeometry(QtCore.QRect(130, 110, 251, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.txt_oldPass.setFont(font)
        self.txt_oldPass.setObjectName("txt_oldPass")
        self.txt_newPass = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_newPass.setGeometry(QtCore.QRect(130, 170, 251, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.txt_newPass.setFont(font)
        self.txt_newPass.setObjectName("txt_newPass")
        self.txt_confirmPass = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_confirmPass.setGeometry(QtCore.QRect(130, 240, 251, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.txt_confirmPass.setFont(font)
        self.txt_confirmPass.setObjectName("txt_confirmPass")
        self.btn_Save = QtWidgets.QPushButton(self.centralwidget)
        self.btn_Save.setGeometry(QtCore.QRect(300, 300, 81, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.btn_Save.setFont(font)
        self.btn_Save.setObjectName("btn_Save")
        self.btn_exit = QtWidgets.QPushButton(self.centralwidget)
        self.btn_exit.setGeometry(QtCore.QRect(410, 300, 81, 31))
        self.btn_exit.setObjectName("btn_exit")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 520, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.btn_Save.clicked.connect(self.changeLoginDetails)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.txt_username.setPlaceholderText(
            _translate("MainWindow", "username"))
        self.label.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt; font-weight:600;\">Login Details</span></p></body></html>"
            ))
        self.txt_oldPass.setPlaceholderText(
            _translate("MainWindow", "old_password"))
        self.txt_newPass.setPlaceholderText(
            _translate("MainWindow", "new_password"))
        self.txt_confirmPass.setPlaceholderText(
            _translate("MainWindow", "confirm_password"))
        self.btn_Save.setText(_translate("MainWindow", "Save"))
        self.btn_exit.setText(_translate("MainWindow", "Exit"))
        MainWindow.setWindowIcon(QIcon("pics\\icon"))

    def changeLoginDetails(self):
        username = self.txt_username.text()
        oldpass = self.txt_oldPass.text()
        newpass = self.txt_newPass.text()
        confirmpass = self.txt_confirmPass.text()
        try:
            self.dbcon = DbCon()
            self.status = self.dbcon.getConnection()
            if self.status:
                if username != "":
                    if newpass != "" and confirmpass != "":
                        if newpass == confirmpass:
                            try:
                                self.admin = self.dbcon.get_user(username)
                            except Error as e:
                                print(e)
                            print(self.admin[2])
                            if self.admin is not None:
                                if oldpass == self.admin[2]:
                                    print("Yes")
                                else:
                                    self.msg.setIcon(QMessageBox.Warning)
                                    self.msg.setText(
                                        "The oldpassword does not match")
                                    self.msg.setStandardButtons(QMessageBox.Ok)
                                    self.msg.exec_()
                            else:
                                self.msg.setIcon(QMessageBox.Warning)
                                self.msg.setText("The user does not exist")
                                self.msg.setStandardButtons(QMessageBox.Ok)
                                self.msg.exec_()
                        else:
                            self.msg.setIcon(QMessageBox.Warning)
                            self.msg.setText("Unmarching new password")
                            self.msg.setStandardButtons(QMessageBox.Ok)
                            self.msg.exec_()
                    else:
                        self.msg.setIcon(QMessageBox.Warning)
                        self.msg.setText(
                            "Ensure new password and confirm password are not empty"
                        )
                        self.msg.setStandardButtons(QMessageBox.Ok)
                        self.msg.exec_()
                else:
                    self.msg.setIcon(QMessageBox.Warning)
                    self.msg.setText("Please input the username")
                    self.msg.setStandardButtons(QMessageBox.Ok)
                    self.msg.exec_()
            else:
                self.msg.setIcon(QMessageBox.Warning)
                self.msg.setText("Database connection not established")
                self.msg.setStandardButtons(QMessageBox.Ok)
                self.msg.exec_()

        except Error as e:
            self.msg.setIcon(QMessageBox.Warning)
            self.msg.setText(str(e))
            self.msg.setStandardButtons(QMessageBox.Ok)
            self.msg.exec_()
示例#18
0
class Ui_ManageVertex(object):
    def __init__(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()
        self.msg_info = QMessageBox()
        self.msg_warning = QMessageBox()

        self.msg_info.setIcon(QMessageBox.Information)
        self.msg_info.setWindowTitle("MMUST NAVIGATOR")

        self.msg_warning.setWindowTitle("MMUST NAVIGATOR")
        self.msg_warning.setIcon(QMessageBox.Warning)

    def setupManageVertex(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(820, 479)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
        self.tableWidget.setGeometry(QtCore.QRect(110, 30, 461, 351))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.tableWidget.sizePolicy().hasHeightForWidth())
        self.tableWidget.setSizePolicy(sizePolicy)
        self.tableWidget.setAutoFillBackground(True)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(3)
        self.tableWidget.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        item.setFont(font)
        self.tableWidget.setHorizontalHeaderItem(2, item)
        self.btn_load = QtWidgets.QPushButton(self.centralwidget)
        self.btn_load.setGeometry(QtCore.QRect(14, 40, 81, 23))
        self.btn_load.setObjectName("btn_load")
        self.txt_id = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_id.setGeometry(QtCore.QRect(600, 60, 201, 31))
        self.txt_id.setObjectName("txt_id")
        self.txt_name = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_name.setGeometry(QtCore.QRect(600, 140, 201, 31))
        self.txt_name.setObjectName("txt_name")
        self.txt_description = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_description.setGeometry(QtCore.QRect(600, 220, 201, 31))
        self.txt_description.setObjectName("txt_description")
        self.btn_select = QtWidgets.QPushButton(self.centralwidget)
        self.btn_select.setGeometry(QtCore.QRect(10, 90, 81, 23))
        self.btn_select.setObjectName("btn_select")
        self.btn_edit = QtWidgets.QPushButton(self.centralwidget)
        self.btn_edit.setGeometry(QtCore.QRect(720, 300, 81, 23))
        self.btn_edit.setObjectName("btn_edit")
        self.btn_deleteAll = QtWidgets.QPushButton(self.centralwidget)
        self.btn_deleteAll.setGeometry(QtCore.QRect(700, 350, 101, 23))
        self.btn_deleteAll.setObjectName("btn_deleteAll")
        self.btn_save = QtWidgets.QPushButton(self.centralwidget)
        self.btn_save.setGeometry(QtCore.QRect(600, 300, 81, 23))
        self.btn_save.setObjectName("btn_save")
        self.btn_deleteOne = QtWidgets.QPushButton(self.centralwidget)
        self.btn_deleteOne.setGeometry(QtCore.QRect(600, 350, 81, 23))
        self.btn_deleteOne.setObjectName("btn_deleteOne")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 820, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.btn_load.clicked.connect(self.loadData)
        self.btn_select.clicked.connect(self.selectData)
        self.btn_save.clicked.connect(self.saveVertex)
        self.btn_edit.clicked.connect(self.editVertex)
        self.btn_deleteOne.clicked.connect(self.deleteVertex)
        self.btn_deleteAll.clicked.connect(self.deleteAllVertex)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.loadData()

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        item = self.tableWidget.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "Vertex ID"))
        item = self.tableWidget.horizontalHeaderItem(1)
        item.setText(_translate("MainWindow", "Vertex Name"))
        item = self.tableWidget.horizontalHeaderItem(2)
        item.setText(_translate("MainWindow", "Vertex Description"))
        self.btn_load.setText(_translate("MainWindow", "Load Verticies"))
        self.txt_id.setPlaceholderText(_translate("MainWindow", "vertex id"))
        self.txt_name.setPlaceholderText(
            _translate("MainWindow", "vertex name"))
        self.txt_description.setPlaceholderText(
            _translate("MainWindow", "vertex description"))
        self.btn_select.setText(_translate("MainWindow", "Select >>"))
        self.btn_edit.setText(_translate("MainWindow", "Edit Vertex"))
        self.btn_deleteAll.setText(
            _translate("MainWindow", "Delete All Verticies"))
        self.btn_save.setText(_translate("MainWindow", "Add Vertex"))
        self.btn_deleteOne.setText(_translate("MainWindow", "Delete Vertex"))
        MainWindow.setWindowIcon(QIcon("pics\\icon"))

    def loadData(self):
        self.msg_info.setWindowTitle("Load Verticies")
        if self.status:
            rows = self.dbcon.get_vertices()
            self.tableWidget.setRowCount(0)
            for row_number, row_data in enumerate(rows):
                self.tableWidget.insertRow(row_number)
                for column_number, column_data in enumerate(row_data):
                    self.tableWidget.setItem(
                        row_number, column_number,
                        QtWidgets.QTableWidgetItem(str(column_data)))
            self.txt_id.setText("")
            self.txt_name.setText("")
            self.txt_description.setText("")
        else:
            self.msg_warning.setText("No database Connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def selectData(self):
        self.msg_info.setWindowTitle("Select Data")
        if self.status:
            indexes = self.tableWidget.selectionModel().selectedRows()
            for index in sorted(indexes):
                row = int(index.row())
                id = self.tableWidget.item(row, 0)
                name = self.tableWidget.item(row, 1)
                desc = self.tableWidget.item(row, 2)

                self.txt_id.setText(id.text())
                self.txt_name.setText(name.text())
                self.txt_description.setText(desc.text())
        else:
            self.msg_warning.setText("No database Connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def saveVertex(self):
        self.msg_info.setWindowTitle("Save Vertex")
        if self.status:
            id = self.txt_id.text()
            name = self.txt_name.text().upper()
            desc = self.txt_description.text()
            if id != "" and name != "" and desc != "":
                try:
                    self.dbcon.add_vertex(id, name, desc)
                    self.msg_info.setText(
                        "Vertex {} has been successfully added".format(name))
                    self.msg_info.setStandardButtons(QMessageBox.Ok)
                    self.msg_info.exec_()
                    self.loadData()
                except Exception as e:
                    self.msg_warning.setText(str(e).strip("()"))
                    self.msg_warning.setStandardButtons(QMessageBox.Ok)
                    self.msg_warning.exec_()
            else:
                self.msg_warning.setText("Fill all the values")
                self.msg_warning.setStandardButtons(QMessageBox.Ok)
                self.msg_warning.exec_()
        else:
            self.msg_warning.setText("No database Connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def editVertex(self):
        self.msg_info.setWindowTitle("Edit Vertex")
        if self.status:
            id = self.txt_id.text()
            name = self.txt_name.text()
            desc = self.txt_description.text()
            if id != "":
                self.msg_info.setText(
                    "Are you sure you want to update vertaex {}?".format(name))
                self.msg_info.setStandardButtons(QMessageBox.Ok
                                                 | QMessageBox.Cancel)

                retval = self.msg_info.exec_()
                if retval == 1024:
                    self.dbcon.update_vertex(id, name, desc)
            else:
                self.msg_warning.setText("Select a path to update it")
                self.msg_warning.setStandardButtons(QMessageBox.Ok)
                self.msg_warning.exec_()
            self.loadData()
        else:
            self.msg_warning.setText("No database Connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def deleteVertex(self):
        self.msg_info.setWindowTitle("Delete Vertex")
        if self.status:
            id = self.txt_id.text()
            if id != "":
                self.msg_info.setText(
                    "Do you want to delete vertex {}".format(id))
                self.msg_info.setStandardButtons(QMessageBox.Ok
                                                 | QMessageBox.Cancel)
                retval = self.msg_info.exec_()
                if retval == 1024:
                    self.dbcon.delete_vertex(id)
                    self.txt_id.setText("")
                    self.txt_name.setText("")
                    self.txt_description.setText("")
            else:
                self.msg_warning.setText(
                    "Select a vertex or enter vertex id to delete it")
                self.msg_warning.setStandardButtons(QMessageBox.Ok)
                self.msg_warning.exec_()
            self.loadData()
        else:
            self.msg_warning.setText("No database Connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()

    def deleteAllVertex(self):
        self.msg_info.setWindowTitle("Delete Verticies")
        if self.status:
            self.msg_info.setText(
                "Are yousure you want to delete all verticies?")
            self.msg_info.setStandardButtons(QMessageBox.Ok
                                             | QMessageBox.Cancel)
            retval = self.msg_info.exec_()
            if retval == 1024:
                # self.dbcon.delete_verticies()
                self.msg_warning.setText(
                    "Sorry mate! We cannot allow you to to mess\nthis up!!")
                self.msg_warning.setStandardButtons(QMessageBox.Ok)
                self.msg_warning.exec_()
            self.loadData()
        else:
            self.msg_warning.setText("No database Connection")
            self.msg_warning.setStandardButtons(QMessageBox.Ok)
            self.msg_warning.exec_()
示例#19
0
class Ui_AddVertex(object):
    def __init__(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()

    def setupAddVertex(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(402, 306)
        self.lbl_id = QtWidgets.QLabel(Dialog)
        self.lbl_id.setGeometry(QtCore.QRect(20, 70, 47, 13))
        self.lbl_id.setObjectName("lbl_id")
        self.label_2 = QtWidgets.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(110, 0, 161, 31))
        self.label_2.setObjectName("label_2")
        self.lbl_name = QtWidgets.QLabel(Dialog)
        self.lbl_name.setGeometry(QtCore.QRect(20, 130, 71, 20))
        self.lbl_name.setObjectName("lbl_name")
        self.txtid = QtWidgets.QLineEdit(Dialog)
        self.txtid.setGeometry(QtCore.QRect(120, 70, 181, 20))
        self.txtid.setObjectName("txtid")
        self.txtname = QtWidgets.QLineEdit(Dialog)
        self.txtname.setGeometry(QtCore.QRect(120, 130, 181, 20))
        self.txtname.setObjectName("txtname")
        self.label_4 = QtWidgets.QLabel(Dialog)
        self.label_4.setGeometry(QtCore.QRect(350, 0, 31, 31))
        self.label_4.setText("")
        self.label_4.setPixmap(QtGui.QPixmap(":/new_icons/icons8-home-page-24.png"))
        self.label_4.setObjectName("label_4")
        self.txtdescription = QtWidgets.QLineEdit(Dialog)
        self.txtdescription.setGeometry(QtCore.QRect(120, 190, 181, 20))
        self.txtdescription.setObjectName("txtdescription")
        self.lbl_description = QtWidgets.QLabel(Dialog)
        self.lbl_description.setGeometry(QtCore.QRect(20, 190, 91, 20))
        self.lbl_description.setObjectName("lbl_description")
        self.btnok = QtWidgets.QPushButton(Dialog)
        self.btnok.setGeometry(QtCore.QRect(220, 260, 71, 23))
        self.btnok.setObjectName("btnok")

        self.btnok.clicked.connect(self.addVertex)

        self.btncancel = QtWidgets.QPushButton(Dialog)
        self.btncancel.setGeometry(QtCore.QRect(300, 260, 75, 23))
        self.btncancel.setObjectName("btncancel")

        self.btncancel.clicked.connect(self.cancel)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.lbl_id.setText(_translate("Dialog", "Vertex id"))
        self.label_2.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:18pt;\">ADD VERTEX</span></p></body></html>"))
        self.lbl_name.setText(_translate("Dialog", "Vertex name"))
        self.lbl_description.setText(_translate("Dialog", "Vertex description"))
        self.btnok.setText(_translate("Dialog", "Ok"))
        self.btncancel.setText(_translate("Dialog", "Cancel"))

    def addVertex(self):
        if self.status:#
            self.vertexid = self.txtid.text()
            self.vertexname = self.txtname.text()
            self.vertedescription = self.txtdescription.text()
            # self.cur = self.db.cursor()
            # print(self.cur)
            self.dbcon.add_vertex(self.vertexid,self.vertexname,self.vertedescription)
            print(self.vertexid, self.vertexname, self.vertedescription, 'has been saved')
            self.txtid.setText('')
            self.txtname.setText('')
            self.txtdescription.setText('')
        else:
            print("Data not saved")
            # print(self.message)

    def close_application(self):
        # choice = QMessageBox.question(self, 'Exit', "Are you sure?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
        choice = QMessageBox()
        choice.setText('Exit', "Are you sure?")
        choice.setStandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
        if choice == QtGui.QMessageBox.Yes:
            sys.exit()
            quit()
        else:
            pass

    def cancel(self):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Information)

        msg.setText("This is a message box")
        msg.setInformativeText("This is additional information")
        msg.setWindowTitle("MessageBox demo")
        msg.setDetailedText("The details are as follows:")
        msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
        msg.buttonClicked.connect(self.msgbtn)

        retval = msg.exec_()
        print("value of pressed message box button:", retval)
        if retval == 1024:
            sys.exit()

    def msgbtn(self,i):
        print("Button pressed is:", i.text())
示例#20
0
class Ui_AddPath2(object):
    def setupAddPath2(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(611, 424)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(190, 5, 231, 41))
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(90, 110, 81, 21))
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(90, 160, 81, 21))
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(90, 210, 71, 21))
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(90, 260, 71, 21))
        self.label_6.setObjectName("label_6")
        self.txtname = QtWidgets.QLineEdit(self.centralwidget)
        self.txtname.setGeometry(QtCore.QRect(200, 100, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.txtname.setFont(font)
        self.txtname.setObjectName("txtname")
        self.txt_length = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_length.setGeometry(QtCore.QRect(200, 150, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.txt_length.setFont(font)
        self.txt_length.setObjectName("txt_length")
        self.txt_from = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_from.setGeometry(QtCore.QRect(200, 200, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.txt_from.setFont(font)
        self.txt_from.setObjectName("txt_from")
        self.txt_to = QtWidgets.QLineEdit(self.centralwidget)
        self.txt_to.setGeometry(QtCore.QRect(200, 250, 201, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.txt_to.setFont(font)
        self.txt_to.setObjectName("txt_to")
        self.btn_save = QtWidgets.QPushButton(self.centralwidget)
        self.btn_save.setGeometry(QtCore.QRect(404, 352, 71, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.btn_save.setFont(font)
        self.btn_save.setObjectName("btn_save")
        self.btn_exit = QtWidgets.QPushButton(self.centralwidget)
        self.btn_exit.setGeometry(QtCore.QRect(510, 350, 71, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.btn_exit.setFont(font)
        self.btn_exit.setObjectName("btn_exit")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 611, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.btn_save.clicked.connect(self.addPath)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label_2.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p align=\"center\"><span style=\" font-size:18pt; font-weight:600;\">Create Path</span></p></body></html>"
            ))
        self.label_3.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:11pt;\">Path Name</span></p></body></html>"
            ))
        self.label_4.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:11pt;\">Path Length</span></p></body></html>"
            ))
        self.label_5.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:11pt;\">From</span></p></body></html>"
            ))
        self.label_6.setText(
            _translate(
                "MainWindow",
                "<html><head/><body><p><span style=\" font-size:11pt;\">To</span></p></body></html>"
            ))
        self.btn_save.setText(_translate("MainWindow", "Save"))
        self.btn_exit.setText(_translate("MainWindow", "Exit"))
        MainWindow.setWindowIcon(QIcon('pics\\icon.png'))

    def addPath(self):
        self.dbcon = DbCon()
        self.status = self.dbcon.getConnection()
        if self.status:
            name = self.txtname.text()
            length = self.txt_length.text()
            startv = self.txt_from.text().upper()
            targetv = self.txt_to.text().upper()
            if name != "" and (startv != "" and targetv != ""):
                try:
                    length = int(length)
                    self.dbcon.add_edge(name, length, startv, targetv)
                    self.dbcon.add_edge(name, length, targetv, startv)
                    print("Path {} successfully added".format(name))
                    msg = QMessageBox()
                    msg.setIcon(QMessageBox.Information)
                    msg.setText(
                        "Path {} has been added to the databse".format(name))
                    msg.setWindowTitle("MMUST Navigator")
                    msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                    msg.exec()
                    self.txtname.setText("")
                    self.txt_length.setText("")
                    self.txt_from.setText("")
                    self.txt_to.setText("")
                except Error as e:
                    print(e)
                    msg.setIcon(QMessageBox.Information)
                    msg.setText(str(e))
                    msg.setWindowTitle("MMUST Navigator")
                    msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                    msg.exec()
                except Exception as ex:
                    print(ex)
                    msg.setIcon(QMessageBox.Information)
                    msg.setText(str(ex))
                    msg.setWindowTitle("MMUST Navigator")
                    msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
                    msg.exec()
            else:
                print("fill all the values")
        else:
            print("No database connection")
示例#21
0
 def __init__(self):
     self.dbcon = DbCon()
     self.status = self.dbcon.getConnection()