示例#1
0
    def __init__(self, parent=None):
        super(self.__class__, self).__init__()
        self.parent = parent
        self.setupUi(self)
        self.setWindowTitle("OPC Test Client- Create Group")
        connected_server = connections.server()
        opc.connect(connected_server)
        self.comboData = ['None']
        self.comboBox.addItem(" Select")
        self.treeWidget.setHeaderHidden(True)

        connected_server = connections.server()
        data = connections.read_from_db(connected_server)
        for con1 in data:
            group_list.append(con1[0])
        s_ind = 0
        Tag_list = opc.list('*', recursive=True)
        for x in Tag_list:
            str_list = x.split('.')
            tag = str_list[0]
            if tag in Main_Tags:
                print "Exist"
            else:
                ind = Tag_list.index(x)
                array = Tag_list[s_ind:ind]
                if not array:
                    print "do nothing"
                else:
                    Sub_Tags.append([array])
                Main_Tags.append(tag)
                s_ind = ind
        for y in Main_Tags:
            self.comboBox.addItem(y)
        edit = self.lineEdit_searchTag
        completer = QCompleter()
        edit.setCompleter(completer)
        model = QStringListModel()
        completer.setModel(model)
        self.get_data(model, Tag_list)

        line_g = self.lineEdit_GroupName
        regex = QtCore.QRegExp("[a-z-A-Z-0-9-@-#-$_]+")
        validator = QtGui.QRegExpValidator(regex)
        line_g.setValidator(validator)

        line_update = self.lineEdit_UpdateRate
        regex2 = QtCore.QRegExp("[0-9]+")
        validator2 = QtGui.QRegExpValidator(regex2)
        line_update.setValidator(validator2)

        self.comboBox.activated[str].connect(self.onActivate)
        self.button_cancel.clicked.connect(
            QtCore.QCoreApplication.instance().quit)
        self.button_createGroup.clicked.connect(self.load_tree)
        self.button_searchTag.clicked.connect(self.search)
        self.button_deleteTag.clicked.connect(self.delete_Tag)
        self.connect(self.treeWidget,
                     QtCore.SIGNAL("itemDoubleClicked(QTreeWidgetItem *,int)"),
                     self.check_condition)
示例#2
0
 def edit_group(self):
     server = connections.server()
     if not server:
         QMessageBox.information(None, 'Error', ' Connect to Server First.', QMessageBox.Ok, QMessageBox.Ok)
     else:
         self._new_window1 = Edit_Group1(self)                                     # Calling the other module (Edit Group)
         self._new_window1.show()
示例#3
0
    def load_tree(self):
        group = self.lineEdit_GroupName.text()
        rate = self.lineEdit_UpdateRate.text()
        group = str(group)
        if not group or not Tarray:
            QMessageBox.Warning(None, 'Error', ' Check the Group name / Tags !!', QMessageBox.Ok, QMessageBox.Ok)
        else:
            if group not in group_list:
                if not rate:
                    QMessageBox.information(None, 'Message', ' Update rate is seconds !!', QMessageBox.Ok, QMessageBox.Ok)
                    rate = "5"
                    self.create_group(group, rate)
                else:
                    try:
                        val = int(rate)
                        if type(val) == int:
                            self.create_group(group, rate)
                    except ValueError:
                        QMessageBox.Warning(None, 'Error', ' Enter the a Integer for Update Rate!!', QMessageBox.Ok, QMessageBox.Ok)

            else:
                result = QMessageBox.question(None, 'Message', "The group Name Exist!! \n Do you want to change it ?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
                if result == QMessageBox.Yes:
                    if not rate:
                        QMessageBox.information(None, 'Message', ' Update rate is seconds !!', QMessageBox.Ok, QMessageBox.Ok)
                        rate = "5"
                        connected_server = connections.server()
                        group = str(group)
                        connections.edit_group(connected_server, Tarray, group, rate)
                        del Tarray[:]
                        self.parent.refresh();
                        self.close()
                    else:
                        try:
                            val = int(rate)
                            if type(val) == int:
                                connected_server = connections.server()
                                group = str(group)
                                connections.edit_group(connected_server, Tarray, group, rate)
                                del Tarray[:]
                                self.parent.refresh();
                                self.close()
                        except ValueError:
                            QMessageBox.Warning(None, 'Error', ' Enter the a Integer for Update Rate !!', QMessageBox.Ok, QMessageBox.Ok)
        return 0
示例#4
0
 def create_group(self, group, rate):
         tags = str(Tarray)
         connected_server = connections.server()
         connected_server = str(connected_server)
         QMessageBox.about(None, "Success", "Group has been created ")
         connections.create_new(connected_server, group, tags, rate)
         del Tarray[:]
         self.parent.refresh();
         self.close()
示例#5
0
    def delete_group(self):
        clicked = self.treeWidget.currentItem()
        column = self.treeWidget.currentColumn()
        if clicked == None:
            QMessageBox.information(None, 'Error', ' Select a Group !!', QMessageBox.Ok, QMessageBox.Ok)
        else:
            item = clicked.text(column)
            if item in group:
                result = QMessageBox.question(self, 'Message', "Do you want to delete the group?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
                if result == QMessageBox.Yes:
                    item = str(item)
                    opc.remove(item)
                    connected_server = connections.server()
                    connections.delete_G(connected_server, item)
                    root = self.treeWidget.invisibleRootItem()
                    for item in self.treeWidget.selectedItems():
                        (item.parent() or root).removeChild(item)
                    indx = 0
                    if item in group:
                        indx = group.index(item)
                        group.remove(item)
                    connected_server = connections.server()
                    data = connections.read_from_db(connected_server)                 #Read groups and tags from DB
                    del group[:]
                    for x in data:
                        group.append(x[0])
                    self.server_groups.setText(str(len(group)))                      #update group number

                    QMessageBox.question(self, 'Message', "Deleting the Tag from Table?")
                    for x in tags[indx]:
                        if x in TableTags:                                           #delete tag from table when group is deleted
                            indx_table = TableTags.index(x)
                            del TableTags[indx_table]
                            self.tableWidget.removeRow(indx_table)
                    del tags[indx]                                                  #delete the tags of the group from array

                else:
                    QMessageBox.information(None, 'Error', ' Select a Group !!', QMessageBox.Ok, QMessageBox.Ok)
            else:
                    QMessageBox.information(None, 'Error', ' Select a Group !!', QMessageBox.Ok, QMessageBox.Ok)
示例#6
0
    def load_tree(self):
        group = self.lineEdit_GroupName.text()
        rate = self.lineEdit_UpdateRate.text()
        group = str(group)
        if not group or not Tarray:
            QMessageBox.about(self, "Error", "Check the Group name / Tags !!")
        else:
            if group not in group_list:
                if not rate:
                    QMessageBox.about(self, "Error",
                                      " Update rate is 5 seconds!!")
                    rate = "5"
                else:
                    try:
                        val = int(rate)
                        if type(val) == int:
                            self.create_group(group, rate)
                    except ValueError:
                        QMessageBox.about(
                            self, "Error",
                            "Enter the a Integer for Update Rate!!")

            else:
                result = QMessageBox.question(
                    self, 'Message',
                    "The group Name Exist!! \n Do you want to over write it ?",
                    QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
                if result == QMessageBox.Yes:
                    if not rate:
                        QMessageBox.about(self, "Error",
                                          " Update rate is 5 seconds!!")
                        rate = "5"
                    else:
                        try:
                            val = int(rate)
                            if type(val) == int:
                                connected_server = connections.server()
                                group = str(group)
                                connections.edit_group(connected_server,
                                                       Tarray, group, rate)
                                del Tarray[:]
                                self.parent.refresh()
                                self.close()
                        except ValueError:
                            QMessageBox.about(
                                self, "Error",
                                "Enter the a Integer for Update Rate!!")
        return 0
示例#7
0
    def onActivate(self, text):
        connected_server = connections.server()
        self.comboBox.clear()  # delete all items from comboBox
        self.comboData = [text]
        self.comboBox.addItems(self.comboData)
        self.treeWidget.setHeaderHidden(True)

        for y in Main_Tags:
            self.comboBox.addItem(y)
        self.comboBox.activated[str].connect(self.onActivate)
        self.treeWidget.clear()
        indx = Main_Tags.index(text)
        item = QtGui.QTreeWidgetItem(["Tags"])
        list = Sub_Tags[indx]
        temp = np.array(list)
        list = temp.ravel()
        for x in list:
            item2 = QtGui.QTreeWidgetItem(item, [x])
        self.treeWidget.addTopLevelItem(item)
示例#8
0
 def create_tree(self, selected_text, row):
     server = opc.servers()
     item = QtGui.QTreeWidgetItem(["Servers"])
     self.treeWidget.addTopLevelItem(item)
     for x in server:
        item1 = QtGui.QTreeWidgetItem(item, [x])
        if x == selected_text:
             self.server_name.setText(selected_text)
             self.server_status.setText("Online")
             item5 = QtGui.QTreeWidgetItem(item1, ["Add New Group"])
             self.treeWidget.insertTopLevelItem(row, item1)
             opc.connect(selected_text)
             connections.connect()
             connected_server = connections.server()
             data = connections.read_from_db(connected_server)                   #Passing server name to conn DB
             for con1 in data:
                 update_rate.append(con1[2])
                 group.append(con1[0])
                 temp1 = str(con1[1])
                 temp2 = con1[1]
                 temp2 = str(temp2)
                 temp2 = temp2.replace("'", "")
                 temp2 = temp2.replace("[", "")
                 temp2 = temp2.replace("]", "")
                 temp2 = ''.join(temp2)
                 temp1 = re.split("; |, |' ", temp2)
                 tags.append(temp1)
             i = 0
             for con2 in group:
                 item2 = QtGui.QTreeWidgetItem(item1, [con2])
                 tags_list = tags[i]
                 tags_ = tags[i]
                 g_name = group[i]
                 u_rate = update_rate[i]
                 opc.read(tags_, group=g_name, update=u_rate)
                 for con3 in tags_list:
                     item3 = QtGui.QTreeWidgetItem(item2, [con3])
                 i += 1
             self.server_groups.setText(str(len(group)))
     self.treeWidget.expandToDepth(row)
示例#9
0
    def delete_tag(self):
        selected_row = self.tableWidget.currentRow()
        if selected_row >= 0:
            temp = connections.group()                              #index of the group which tag is
            cell = self.tableWidget.item(selected_row, 0).text()     #tag name from table
            indx = tags[temp].index(cell)                           #index of tag in group[num]
            current_server = connections.server()
            group_name = group[temp]
            new_tags = tags[temp]
            QMessageBox.question(None, 'Message', ' Remove the tag? !!', QMessageBox.Ok, QMessageBox.Ok)
            self.tableWidget.removeRow(selected_row)
            del new_tags[indx]
            connections.delete_tag(current_server,new_tags,group_name)
            del TableTags[selected_row]
            opc.remove(group_name)
            tags_ = tags[temp]
            g_name = group_name
            u_rate = update_rate[temp]
            opc.read(tags_, group=g_name, update=u_rate)
            self.refresh()

        else:
            QMessageBox.about(None, 'Error', ' Select a Tag in table !! !!', QMessageBox.Ok, QMessageBox.Ok)
示例#10
0
    def __init__(self, parent=None):
        super(self.__class__, self).__init__()
        self.parent = parent;
        self.setupUi(self)
        self.setWindowTitle("OPC Test Client- Create Group")
        connected_server = connections.server()
        opc.connect(connected_server)
        self.comboData = ['None']
        self.comboBox.addItem(" Select")
        self.treeWidget.setHeaderHidden(True)
        self.comboBox_2.comboData = ("--- Select a Group ---")
        self.comboBox_2.addItem("--- Select a Group ---")
        s_ind = 0
        tag_list = opc.list('*', recursive=True)
        for x in tag_list:
            str_list = x.split('.')
            tag = str_list[0]
            if tag not in Main_Tags:
                ind = tag_list. index(x)
                array = tag_list[s_ind:ind]
                if not array:
                    print "do nothing"
                else:
                    Sub_Tags.append([array])
                Main_Tags.append(tag)
                s_ind = ind
        for y in Main_Tags:
            self.comboBox.addItem(y)

        connected_server = connections.server()
        data = connections.read_from_db(connected_server)                   #Passing server name to conn DB
        for con1 in data:
            update_rate.append(con1[2])
            self.comboBox_2.addItem(con1[0])
            group_list.append(con1[0])
            temp2 = con1[1]
            temp2 = str(temp2)
            temp2 = temp2.replace("'", "")
            temp2 = temp2.replace("[", "")
            temp2 = temp2.replace("]", "")
            temp2 = ''.join(temp2)
            temp1 = re.split("; |, |' ", temp2)
            Tags_db.append(temp1)

        edit = self.lineEdit_searchTag
        completer = QCompleter()
        edit.setCompleter(completer)
        model = QStringListModel()
        completer.setModel(model)
        self.get_data(model, tag_list)

        line_g = self.lineEdit_GroupName
        regex = QtCore.QRegExp("[a-z-A-Z-0-9-@-#-$_]+")
        validator = QtGui.QRegExpValidator(regex)
        line_g.setValidator(validator)

        line_update = self.lineEdit_UpdateRate
        regex2 = QtCore.QRegExp("[0-9]+")
        validator2 = QtGui.QRegExpValidator(regex2)
        line_update.setValidator(validator2)

        self.comboBox.activated[str].connect(self.onActivate)
        self.comboBox_2.activated[str].connect(self.load_data)
        self.button_cancel.clicked.connect(QtCore.QCoreApplication.instance().quit)
        self.button_createGroup.clicked.connect(self.load_tree)
        self.button_searchTag.clicked.connect(self.search)
        self.button_deleteTag.clicked.connect(self.delete_Tag)
        self.pushButton.clicked.connect(self.refresh_screen)
        self.connect(self.treeWidget, QtCore.SIGNAL("itemDoubleClicked(QTreeWidgetItem *,int)"), self.check_condition)