def setText(self, text): """ Set the label text: will additionally block label editing if a literal is being. :type text: str """ self.label.editable = RE_VALUE.match(text) is None self.label.setText(text)
def setText(self, text): """ Set the label text: will additionally block label editing if a literal is being. :type text: str """ self.label.setEditable(RE_VALUE.match(text) is None) self.label.setText(text) self.label.setAlignment(QtCore.Qt.AlignCenter)
def identity(self): """ Returns the identity of the current node. :rtype: Identity """ match = RE_VALUE.match(self.text()) if match: return Identity.Value return Identity.Individual
def value(self): """ Returns the value value associated with this node. :rtype: str """ match = RE_VALUE.match(self.text()) if match: return match.group('value') return None
def datatype(self): """ Returns the datatype associated with this node. :rtype: Datatype """ match = RE_VALUE.match(self.text()) if match: return Datatype.valueOf(match.group('datatype')) return None
def value(self): """ Returns the value value associated with this node. :rtype: str """ match = RE_VALUE.match(self.text()) if match: return match.group("value") return None
def datatype(self): """ Returns the datatype associated with this node. :rtype: Datatype """ match = RE_VALUE.match(self.text()) if match: return Datatype.forValue(match.group("datatype")) return None
def setText(self, text): """ Set the label text: will additionally block label editing if a literal is being. :type text: str """ #print('Individial >> def setText >> ') #print('text',text) #print('RE_VALUE.match(text)',RE_VALUE.match(text)) self.label.setEditable(RE_VALUE.match(text) is None) self.label.setText(text) self.label.setAlignment(QtCore.Qt.AlignCenter)
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()
def __init__(self, node, session): """ Initialize the form dialog. :type node: AbstractNode :type session: Session """ super().__init__(session) self.node = node ############################################# # FORM AREA ################################# self.renameLabel = QtWidgets.QLabel(self) self.renameLabel.setText('IRI label') self.renameField = StringField(self) self.renameField.setFixedWidth(200) self.renameLabel.setWordWrap(True) match = RE_VALUE.match(self.node.text()) if match: self.renameField.setValue(self.node.text()) else: self.renameField.setValue(self.node.remaining_characters) self.old_text = self.node.text() connect(self.renameField.textChanged, self.nameChanged) self.formWidget = QtWidgets.QWidget(self) self.formLayout = QtWidgets.QFormLayout(self.formWidget) self.formLayout.addRow(self.renameLabel, self.renameField) ############################################# # CONFIRMATION AREA ################################# self.confirmationBox = QtWidgets.QDialogButtonBox( QtCore.Qt.Horizontal, self) self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Ok) self.confirmationBox.addButton(QtWidgets.QDialogButtonBox.Cancel) self.confirmationBox.setContentsMargins(10, 0, 10, 10) ############################################# # SETUP DIALOG LAYOUT ################################# self.caption = QtWidgets.QLabel(self) self.caption.setContentsMargins(8, 0, 8, 0) self.caption.setProperty('class', 'invalid') self.caption.setVisible(False) self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.formWidget) self.mainLayout.addWidget(self.caption) self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight) self.setFixedSize(self.sizeHint()) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) self.setWindowTitle('Rename') connect(self.confirmationBox.accepted, self.accept) connect(self.confirmationBox.rejected, self.reject)
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)