Example #1
0
    def valueChanged(self):
        """
        Change the value of the node.
        :rtype: QUndoCommand
        """
        datatype = self.datatypeField.currentData()
        value = self.valueField.value()
        data = self.node.compose(value, datatype)
        if self.node.text() != data:

            new_prefix = datatype.value[0:datatype.value.index(':')]
            new_remaining_characters = datatype.value[datatype.value.index(':'
                                                                           ) +
                                                      1:len(datatype.value)]

            new_iri = None

            for std_iri in OWLStandardIRIPrefixPairsDict.std_IRI_prefix_dict.keys(
            ):
                std_prefix = OWLStandardIRIPrefixPairsDict.std_IRI_prefix_dict[
                    std_iri]
                if std_prefix == new_prefix:
                    new_iri = std_iri

            Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                self.project.IRI_prefixes_nodes_dict, dict())
            Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                self.project.IRI_prefixes_nodes_dict, dict())

            old_iri = self.project.get_iri_of_node(self.node)

            Duplicate_dict_1[old_iri][1].remove(self.node)
            Duplicate_dict_1[new_iri][1].add(self.node)

            commands = []

            commands.append(
                CommandLabelChange(self.diagram, self.node, self.node.text(),
                                   data))
            commands.append(
                CommandProjetSetIRIPrefixesNodesDict(self.project,
                                                     Duplicate_dict_2,
                                                     Duplicate_dict_1,
                                                     [old_iri, new_iri],
                                                     [self.node]))
            commands.append(CommandNodeSetRemainingCharacters(self.node.remaining_characters,\
                                                              new_remaining_characters,self.node,self.project))
            commands.append(
                CommandLabelChange(self.diagram, self.node, self.node.text(),
                                   data))

            return commands

        return None
Example #2
0
 def textChanged(self):
     """
     Change the label of the node.
     :rtype: list
     """
     data = self.textField.value().strip()
     data = data if not isEmpty(data) else self.node.label.template
     if self.node.text() != data:
         if self.refactorField.isChecked():
             item = self.node.type()
             name = self.node.text()
             project = self.diagram.project
             return [CommandLabelChange(n.diagram, n, n.text(), data) for n in project.predicates(item, name)]
         return [CommandLabelChange(self.diagram, self.node, self.node.text(), data)]
     return [None]
Example #3
0
 def facetChanged(self):
     """
     Change the facet value of the node of the node.
     :rtype: QUndoCommand
     """
     data = self.node.compose(self.facetField.currentData(), self.valueField.value())
     if self.node.text() != data:
         return CommandLabelChange(self.diagram, self.node, self.node.text(), data)
     return None
Example #4
0
 def datatypeChanged(self):
     """
     Change the datatype of the node.
     :rtype: QUndoCommand
     """
     datatype = self.datatypeField.currentData()
     data = datatype.value
     if self.node.text() != data:
         return CommandLabelChange(self.diagram, self.node, self.node.text(), data)
     return None
Example #5
0
    def valueChanged(self):
        """
        Change the value of the node.
        :rtype: QUndoCommand
        """
        datatype = self.datatypeField.currentData()
        value = self.valueField.value()
        data = self.node.compose(value, datatype)
        if self.node.text() != data:
            new_prefix = datatype.value[0:datatype.value.index(':')]
            new_remaining_characters = datatype.value[datatype.value.index(':'
                                                                           ) +
                                                      1:len(datatype.value)]
            new_iri = None

            for namespace in Namespace:
                if namespace.name.lower() == new_prefix:
                    new_iri = namespace.value

            Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                self.project.IRI_prefixes_nodes_dict, dict())
            Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                self.project.IRI_prefixes_nodes_dict, dict())

            old_iri = self.project.get_iri_of_node(self.node)

            Duplicate_dict_1[old_iri][1].remove(self.node)
            Duplicate_dict_1[new_iri][1].add(self.node)

            commands = [
                CommandLabelChange(self.diagram, self.node, self.node.text(),
                                   data),
                CommandNodeSetRemainingCharacters(
                    self.node.remaining_characters, new_remaining_characters,
                    self.node, self.project),
                CommandLabelChange(self.diagram, self.node, self.node.text(),
                                   data)
            ]

            return commands

        return None
Example #6
0
 def valueChanged(self):
     """
     Change the value of the node.
     :rtype: QUndoCommand
     """
     datatype = self.datatypeField.currentData()
     value = self.valueField.value()
     data = self.node.compose(value, datatype)
     if self.node.text() != data:
         return CommandLabelChange(self.diagram, self.node, self.node.text(), data)
     return None
Example #7
0
    def undo(self):
        """undo the command"""
        self.node.remaining_characters = self.rc_undo.replace('\n', '')

        if self.regenerate_label is True:
            #new_text = self.node.text()
            #old_text = GenerateNewLabel(self.project, self.node, remaining_characters=self.rc_undo).return_label()

            CommandLabelChange(self.node.diagram,
                               self.node,
                               self.old_text,
                               self.new_text,
                               refactor=self.refactor).undo()
Example #8
0
 def accept(self):
     """
     Accepts the form and set the new value.
     """
     node = self.node
     diagram = node.diagram
     datatype = self.datatypeField.currentData()
     value = self.valueField.value()
     data = node.compose(value, datatype)
     if node.text() != data:
         name = 'change {0} to {1}'.format(node.text(), data)
         self.session.undostack.push(
             CommandLabelChange(diagram, node, node.text(), data,
                                name=name))
     super().accept()
Example #9
0
 def accept_2(self):
     """
     Accepts the rename form and perform refactoring.
     """
     name = self.renameField.value()
     self.session.undostack.beginMacro(
         'change predicate "{0}" to "{1}"'.format(self.node.text(), name))
     for node in self.project.predicates(self.node.type(),
                                         self.node.text()):
         command = CommandLabelChange(node.diagram,
                                      node,
                                      node.text(),
                                      name,
                                      refactor=True)
         self.session.undostack.push(command)
     self.session.undostack.endMacro()
     super().accept()
Example #10
0
    def focusOutEvent(self, focusEvent):
        """
        Executed when the text item lose the focus.
        :type focusEvent: QFocusEvent
        """
        if self.diagram.mode is DiagramMode.LabelEdit:

            if isEmpty(self.text()):
                self.setText(self.template)

            focusInData = self.focusInData
            currentData = '"{0}"'.format(self.text().strip('"'))

            ###########################################################
            # IMPORTANT!                                              #
            # ####################################################### #
            # The code below is a bit tricky: to be able to properly  #
            # update the node in the project index we need to force   #
            # the value of the label to it's previous one and let the #
            # command implementation update the index.                #
            ###########################################################

            self.setText(focusInData)

            if focusInData and focusInData != currentData:
                item = self.parentItem()
                undo = item.compose(self.focusInFacet, focusInData)
                redo = item.compose(self.focusInFacet, currentData)
                command = CommandLabelChange(self.diagram, self.parentItem(),
                                             undo, redo)
                self.session.undostack.push(command)

            self.focusInData = None
            self.focusInFacet = None
            self.setSelectedText(False)
            self.setAlignment(self.alignment())
            self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
            self.diagram.setMode(DiagramMode.Idle)
            self.diagram.sgnUpdated.emit()

        super(AbstractLabel, self).focusOutEvent(focusEvent)
Example #11
0
    def accept(self):
        """
        Accepts the form and set the new value.
        """
        # print('>>>          ValueForm (accept)')
        node = self.node
        diagram = node.diagram
        datatype = self.datatypeField.currentData()
        value = self.valueField.value()
        data = node.compose(value, datatype)

        if node.text() != data:
            name = 'change {0} to {1}'.format(node.text(), data)

            new_prefix = datatype.value[0:datatype.value.index(':')]
            new_remaining_characters = datatype.value[datatype.value.index(':'
                                                                           ) +
                                                      1:len(datatype.value)]
            new_iri = None

            for namespace in Namespace:
                if namespace.name.lower() == new_prefix:
                    new_iri = namespace.value

            if new_iri is None:
                LOGGER.error(
                    '*****************   failed to assign iri to node   *******************'
                )
                return

            Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                self.project.IRI_prefixes_nodes_dict, dict())
            Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                self.project.IRI_prefixes_nodes_dict, dict())

            old_iri = self.project.get_iri_of_node(node)

            Duplicate_dict_1[old_iri][1].remove(node)
            Duplicate_dict_1[new_iri][1].add(node)

            commands = []

            commands.append(
                CommandProjectDisconnectSpecificSignals(self.project))
            commands.append(
                CommandLabelChange(diagram, self.node, self.node.text(), data))
            commands.append(
                CommandNodeSetRemainingCharacters(node.remaining_characters,
                                                  new_remaining_characters,
                                                  node, self.project))
            commands.append(
                CommandLabelChange(diagram, self.node, self.node.text(), data))
            commands.append(CommandProjectConnectSpecificSignals(self.project))

            if any(commands):
                self.session.undostack.beginMacro(
                    'edit Forms >> accept() {0}'.format(node))
                for command in commands:
                    if command:
                        self.session.undostack.push(command)
                self.session.undostack.endMacro()

        super().accept()
Example #12
0
    def accept(self):
        """
        Accepts the rename form and perform refactoring.
        """
        currentData = self.renameField.value()

        if currentData and currentData != self.old_text:

            match = RE_VALUE.match(currentData)
            match_old = RE_VALUE.match(self.old_text)

            commands = []

            if match:
                new_prefix = match.group(
                    'datatype')[0:match.group('datatype').index(':')]
                new_remaining_characters = match.group(
                    'datatype')[match.group('datatype').index(':') +
                                1:len(match.group('datatype'))]
                new_iri = None

                for namespace in Namespace:
                    if namespace.name.lower() == new_prefix:
                        new_iri = namespace.value

                Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                    self.project.IRI_prefixes_nodes_dict, dict())
                Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                    self.project.IRI_prefixes_nodes_dict, dict())

                old_iri = self.project.get_iri_of_node(self.node)

                list_of_nodes_to_process = []

                commands_label_change_list_1 = []
                commands_label_change_list_2 = []
                commands_rc_change = []

                for node in self.project.predicates(self.node.type(),
                                                    self.node.text()):
                    list_of_nodes_to_process.append(node)

                    Duplicate_dict_1[old_iri][1].remove(node)
                    Duplicate_dict_1[new_iri][1].add(node)

                    commands_label_change_list_1.append(
                        CommandLabelChange(node.diagram,
                                           node,
                                           self.old_text,
                                           currentData,
                                           refactor=True))
                    commands_rc_change.append(
                        CommandNodeSetRemainingCharacters(
                            node.remaining_characters,
                            new_remaining_characters,
                            node,
                            self.project,
                            refactor=True))
                    commands_label_change_list_2.append(
                        CommandLabelChange(node.diagram,
                                           node,
                                           self.old_text,
                                           currentData,
                                           refactor=True))

                commands.append(
                    CommandProjectDisconnectSpecificSignals(self.project))

                commands.extend(commands_label_change_list_1)
                commands.extend(commands_rc_change)
                commands.extend(commands_label_change_list_2)

                commands.append(
                    CommandProjectConnectSpecificSignals(self.project))

            else:
                exception_list = ['-', '_', '.', '~', '\n']
                currentData_processed = ''
                flag = False

                for i, c in enumerate(currentData):
                    if c == '':
                        pass
                    elif i < (len(currentData) - 1) and (
                            c == '\\' and currentData[i + 1] == 'n'):
                        currentData_processed = currentData_processed + '\n'
                    elif i > 0 and (c == 'n' and currentData[i - 1] == '\\'):
                        pass
                    elif (not c.isalnum()) and (c not in exception_list):
                        currentData_processed = currentData_processed + '_'
                        flag = True
                    else:
                        currentData_processed = currentData_processed + c

                if flag is True:
                    self.session.statusBar().showMessage(
                        'Spaces in between alphanumeric characters and special characters were replaced by an '
                        'underscore character.', 15000)

                if match_old:
                    new_remaining_characters = currentData_processed
                    new_iri = self.project.ontologyIRIString

                    Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                        self.project.IRI_prefixes_nodes_dict, dict())
                    Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                        self.project.IRI_prefixes_nodes_dict, dict())

                    old_iri = self.project.get_iri_of_node(self.node)

                    list_of_nodes_to_process = []

                    commands_label_change_list_1 = []
                    commands_label_change_list_2 = []
                    commands_rc_change = []

                    for node in self.project.predicates(
                            self.node.type(), self.node.text()):
                        list_of_nodes_to_process.append(node)

                        Duplicate_dict_1[old_iri][1].remove(node)
                        Duplicate_dict_1[new_iri][1].add(node)

                        if len(Duplicate_dict_1[new_iri][0]) == 0:
                            new_label = self.project.get_full_IRI(
                                new_iri, None, new_remaining_characters)
                        else:
                            new_label = str(Duplicate_dict_1[new_iri][0][
                                len(Duplicate_dict_1[new_iri][0]) - 1] + ':' +
                                            new_remaining_characters)

                        commands_label_change_list_1.append(
                            CommandLabelChange(node.diagram,
                                               node,
                                               self.old_text,
                                               new_label,
                                               refactor=True))
                        commands_rc_change.append(
                            CommandNodeSetRemainingCharacters(
                                node.remaining_characters,
                                new_remaining_characters,
                                node,
                                self.project,
                                refactor=True))
                        commands_label_change_list_2.append(
                            CommandLabelChange(node.diagram,
                                               node,
                                               self.old_text,
                                               new_label,
                                               refactor=True))

                    command_dict_change = CommandProjetSetIRIPrefixesNodesDict(
                        self.project, Duplicate_dict_2, Duplicate_dict_1,
                        [old_iri, new_iri], list_of_nodes_to_process)

                    commands.append(
                        CommandProjectDisconnectSpecificSignals(self.project))

                    commands.extend(commands_label_change_list_1)
                    commands.append(command_dict_change)
                    commands.extend(commands_rc_change)
                    commands.extend(commands_label_change_list_2)

                    commands.append(
                        CommandProjectConnectSpecificSignals(self.project))

                else:

                    commands.append(
                        CommandProjectDisconnectSpecificSignals(self.project))

                    for node in self.project.predicates(
                            self.node.type(), self.node.text()):
                        commands.append(
                            CommandNodeSetRemainingCharacters(
                                node.remaining_characters,
                                currentData_processed,
                                node,
                                self.project,
                                refactor=True))

                    commands.append(
                        CommandProjectConnectSpecificSignals(self.project))

            if any(commands):
                self.session.undostack.beginMacro(
                    'change predicate "{0}" to "{1}"'.format(
                        self.node.text(), currentData))
                for command in commands:
                    if command:
                        self.session.undostack.push(command)
                self.session.undostack.endMacro()

        else:
            pass

        super().accept()
Example #13
0
    def IRIChanged(self):
        # Change the iri of the node.
        #:rtype: Command

        IRI_valid = self.project.check_validity_of_IRI(self.iriField.value())

        if IRI_valid is False:
            self.session.statusBar().showMessage('Invalid IRI.', 15000)
            return None
        else:

            old_iri = self.project.get_iri_of_node(self.node)
            new_iri = self.iriField.value()

            # if (self.iriField.value() != self.project.get_iri_of_node(node)) or (self.iriversionField.value() != self.node.IRI_version(self.project)):
            if new_iri != old_iri:
                connect(self.project.sgnIRINodeEntryAdded,
                        self.metaDataChanged_ADD_OK)
                connect(self.project.sgnIRINodeEntryRemoved,
                        self.metaDataChanged_REMOVE_OK)
                connect(self.project.sgnIRINodeEntryIgnored,
                        self.metaDataChanged_IGNORE)

                # check for conflict in prefixes
                # transaction = remove(old) + add(new)
                # perform transaction on duplicate dict.
                # if successful, original_dict = duplicate_dict
                # else duplicate_dict = original_dict

                Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                    self.project.IRI_prefixes_nodes_dict, dict())
                Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                    self.project.IRI_prefixes_nodes_dict, dict())

                list_of_nodes_to_process = []

                if self.refactorField.isChecked():
                    for n in self.project.nodes():
                        if (('AttributeNode' in str(type(n)))
                                or ('ConceptNode' in str(type(n)))
                                or ('IndividualNode' in str(type(n)))
                                or ('RoleNode' in str(type(n)))):

                            if (self.project.get_iri_of_node(n) == old_iri
                                ) and (n.remaining_characters
                                       == self.node.remaining_characters):
                                list_of_nodes_to_process.append(n)
                else:
                    list_of_nodes_to_process.append(self.node)

                commands = []

                for nd in list_of_nodes_to_process:

                    self.project.removeIRINodeEntry(Duplicate_dict_1, old_iri,
                                                    nd)
                    self.project.addIRINodeEntry(Duplicate_dict_1, new_iri, nd)

                    if (self.metaDataChanged_REMOVE_OK_var is True) and (
                            self.metaDataChanged_ADD_OK_var is True):
                        self.metaDataChanged_REMOVE_OK_var = False
                        self.metaDataChanged_ADD_OK_var = False
                        self.metaDataChanged_IGNORE_var = False
                    else:
                        LOGGER.warning(
                            'redo != undo but transaction was not executed correctly'
                        )
                        self.metaDataChanged_REMOVE_OK_var = False
                        self.metaDataChanged_ADD_OK_var = False
                        self.metaDataChanged_IGNORE_var = False
                        return str('Error in ' + str(nd))

                if len(Duplicate_dict_1[new_iri][0]) == 0:
                    ###
                    if 'display_in_widget' in Duplicate_dict_1[new_iri][2]:
                        new_label = ':' + self.node.remaining_characters
                    else:
                        new_label = self.project.get_full_IRI(
                            new_iri, None, self.node.remaining_characters)
                else:
                    new_label = str(Duplicate_dict_1[new_iri][0][
                        len(Duplicate_dict_1[new_iri][0]) - 1] + ':' +
                                    self.node.remaining_characters)

                commands.append(
                    CommandProjectDisconnectSpecificSignals(self.project))

                for nd in list_of_nodes_to_process:
                    commands.append(
                        CommandLabelChange(nd.diagram, nd, nd.text(),
                                           new_label))

                for nd in list_of_nodes_to_process:
                    commands.append(
                        CommandLabelChange(nd.diagram, nd, nd.text(),
                                           new_label))

                commands.append(
                    CommandProjectConnectSpecificSignals(self.project))

                return commands

            self.metaDataChanged_REMOVE_OK_var = False
            self.metaDataChanged_ADD_OK_var = False
            self.metaDataChanged_IGNORE_var = False

            return None
Example #14
0
File: common.py Project: Njrob/eddy
    def focusOutEvent(self, focusEvent):
        """
        Executed when the text item loses the focus.
        :type focusEvent: QFocusEvent
        """
        if self.diagram.mode is DiagramMode.LabelEdit:

            if isEmpty(self.text()):
                self.setText(self.template)

            focusInData = self.focusInData
            #currentData = self.text()
            currentData = self.toPlainText()

            #print('self.text()',self.text())
            #print('self.toHtml()',self.toHtml())
            #print('self.toPlainText()',self.toPlainText())

            ###########################################################
            # IMPORTANT!                                              #
            # ####################################################### #
            # The code below is a bit tricky: to be able to properly  #
            # update the node in the project index we need to force   #
            # the value of the label to it's previous one and let the #
            # command implementation update the index.                #
            ###########################################################

            self.setText(focusInData)

            if focusInData and focusInData != currentData:

                """
                reasoner_active = self.project.check_if_reasoner_was_active()
                if (reasoner_active == 'was_unsatisfiable') or (reasoner_active == 'was_inconsistent'):
                    reasoner_variables = FetchReasonerVariables(self.project)
                else:
                    reasoner_variables = 'empty'
                """
                node = self.parentItem()
                match = RE_VALUE.match(currentData)

                commands = []

                if match:
                    new_prefix = match.group('datatype')[0:match.group('datatype').index(':')]
                    new_remaining_characters = match.group('datatype')[match.group('datatype').index(':') + 1:len(match.group('datatype'))]

                    new_iri = None

                    for std_iri in OWLStandardIRIPrefixPairsDict.std_IRI_prefix_dict.keys():
                        std_prefix = OWLStandardIRIPrefixPairsDict.std_IRI_prefix_dict[std_iri]
                        if std_prefix == new_prefix:
                            new_iri = std_iri

                    Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                        self.project.IRI_prefixes_nodes_dict, dict())
                    Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                        self.project.IRI_prefixes_nodes_dict, dict())

                    old_iri = self.project.get_iri_of_node(node)

                    Duplicate_dict_1[old_iri][1].remove(node)
                    Duplicate_dict_1[new_iri][1].add(node)

                    self.setText(self.old_text)

                    commands.append(CommandProjectDisconnectSpecificSignals(self.project))
                    commands.append(CommandLabelChange(self.diagram, node, self.old_text, currentData))

                    #commands.append(CommandNodeSetRemainingCharacters(node.remaining_characters, new_remaining_characters, node, self.project, regenerate_label=False))
                    commands.append(CommandProjetSetIRIPrefixesNodesDict(self.project, Duplicate_dict_2, Duplicate_dict_1, [old_iri, new_iri], [node]))
                    commands.append(CommandNodeSetRemainingCharacters(node.remaining_characters, new_remaining_characters, node, self.project, regenerate_label=False))
                    #commands.append(CommandProjetSetIRIPrefixesNodesDict(self.project, Duplicate_dict_2, Duplicate_dict_1, [old_iri, new_iri], [node]))

                    commands.append(CommandLabelChange(self.diagram, node, self.old_text, currentData))
                    commands.append(CommandProjectConnectSpecificSignals(self.project))

                else:
                    self.setText(self.old_text)

                    exception_list = ['-', '_', '.', '~', '\n']
                    currentData_processed = ''

                    flag = False

                    for i,c in enumerate(currentData):

                        if c == '':
                            pass
                        elif i < (len(currentData) - 1) and (c == '\\' and currentData[i + 1] == 'n'):
                            currentData_processed = currentData_processed + '\n'
                        elif i > 0 and (c == 'n' and currentData[i - 1] == '\\'):
                            pass
                        elif (not c.isalnum()) and (c not in exception_list):
                            currentData_processed = currentData_processed + '_'
                            flag = True
                        else:
                            currentData_processed = currentData_processed + c

                    if flag is True:
                        self.session.statusBar().showMessage('Spaces in between alphanumeric characters and special characters were replaced by an underscore character.', 15000)

                    #print('self.old_text',self.old_text)
                    #print('currentData', currentData)
                    #print('currentData_processed',currentData_processed)

                    commands.append(CommandProjectDisconnectSpecificSignals(self.project))

                    commands.append(CommandNodeSetRemainingCharacters(node.remaining_characters, currentData_processed, node, self.project))
                    """
                    if NewlineFeedInsensitive(node.remaining_characters,currentData_processed).result() is True:
                        commands.append(
                            CommandNodeSetRemainingCharacters(node.remaining_characters, currentData_processed, node, self.project, refactor=True))
                    else:
                        commands.append(CommandNodeSetRemainingCharacters(node.remaining_characters, currentData_processed, node, self.project))
                    """
                    commands.append(CommandProjectConnectSpecificSignals(self.project))

                if any(commands):
                    self.session.undostack.beginMacro('edit {0} AbstractLabel >> focusOutEvent'.format(node.name))
                    for command in commands:
                        if command:
                            self.session.undostack.push(command)
                    self.session.undostack.endMacro()
            else:
                self.setText(self.old_text)
                self.old_text = None

            self.focusInData = None
            self.setSelectedText(False)
            self.setAlignment(self.alignment())
            self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
            self.diagram.setMode(DiagramMode.Idle)
            self.diagram.sgnUpdated.emit()

        super().focusOutEvent(focusEvent)
Example #15
0
File: forms.py Project: Njrob/eddy
    def accept(self):
        """
        Accepts the form and set the new value.
        """
        #print('>>>          ValueForm (accept)')
        node = self.node
        diagram = node.diagram
        datatype = self.datatypeField.currentData()
        value = self.valueField.value()
        data = node.compose(value, datatype)
        #print('data',data)
        if node.text() != data:
            name = 'change {0} to {1}'.format(node.text(), data)

            new_prefix = datatype.value[0:datatype.value.index(':')]
            new_remaining_characters = datatype.value[datatype.value.index(':'
                                                                           ) +
                                                      1:len(datatype.value)]
            new_iri = None

            for std_iri in OWLStandardIRIPrefixPairsDict.std_IRI_prefix_dict.keys(
            ):
                std_prefix = OWLStandardIRIPrefixPairsDict.std_IRI_prefix_dict[
                    std_iri]
                if std_prefix == new_prefix:
                    new_iri = std_iri

            if new_iri is None:
                LOGGER.error(
                    '*****************   failed to assign iri to node   *******************'
                )
                return

            #print('self.project.get_prefix_of_node(node) - new_prefix',self.project.get_prefix_of_node(node),'-',new_prefix)
            #print('self.project.get_iri_of_node(node) - new_iri',self.project.get_iri_of_node(node),'-',new_iri)
            #print('node.remaining_characters - new_remaining_characters',node.remaining_characters,'-',new_remaining_characters)
            #print('data=',data)

            Duplicate_dict_1 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                self.project.IRI_prefixes_nodes_dict, dict())
            Duplicate_dict_2 = self.project.copy_IRI_prefixes_nodes_dictionaries(
                self.project.IRI_prefixes_nodes_dict, dict())

            old_iri = self.project.get_iri_of_node(node)

            Duplicate_dict_1[old_iri][1].remove(node)
            Duplicate_dict_1[new_iri][1].add(node)

            commands = []

            commands.append(
                CommandProjectDisconnectSpecificSignals(self.project))
            commands.append(
                CommandLabelChange(diagram, self.node, self.node.text(), data))
            commands.append(
                CommandProjetSetIRIPrefixesNodesDict(self.project,
                                                     Duplicate_dict_2,
                                                     Duplicate_dict_1,
                                                     [old_iri, new_iri],
                                                     [node]))
            commands.append(
                CommandNodeSetRemainingCharacters(node.remaining_characters,
                                                  new_remaining_characters,
                                                  node, self.project))
            commands.append(
                CommandLabelChange(diagram, self.node, self.node.text(), data))
            commands.append(CommandProjectConnectSpecificSignals(self.project))

            if any(commands):
                self.session.undostack.beginMacro(
                    'edit Forms >> accept() {0}'.format(node))
                for command in commands:
                    if command:
                        self.session.undostack.push(command)
                self.session.undostack.endMacro()

        super().accept()