def nameChanged(self): """ Executed whenever the text in the rename field changes. """ caption = '' enabled = True if isEmpty(self.renameField.value()): caption = "\'{0}\' is not a valid predicate name".format(self.renameField.value()) enabled = False self.caption.setText(caption) self.caption.setVisible(not isEmpty(caption)) self.confirmationBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(enabled) self.setFixedSize(self.sizeHint())
def importNodeFromShapeNode(self, item, element): """ Build a node using the given item type and QDomElement. :type item: Item :type element: QDomElement :rtype: AbstractNode """ data = element.firstChildElement('data') while not data.isNull(): if data.attribute('key', '') == self.keys['node_key']: shapeNode = data.firstChildElement('y:ShapeNode') geometry = shapeNode.firstChildElement('y:Geometry') h = float(geometry.attribute('height')) w = float(geometry.attribute('width')) kwargs = {'id': element.attribute('id'), 'height': h, 'width': w} node = self.diagram.factory.create(item, **kwargs) node.setPos(self.parsePos(geometry)) # For the following items we also import the label. # Other operator nodes have fixed label so it's pointless. if item in {Item.DomainRestrictionNode, Item.RangeRestrictionNode, Item.ValueDomainNode, Item.IndividualNode}: nodeLabel = shapeNode.firstChildElement('y:NodeLabel') node.setText(nodeLabel.text()) if not isEmpty(nodeLabel.text()): # If the node label is empty do not set the position. # This is needed because domain restriction and range restriction nodes # usually do not have any label in gephol documents built with yEd. node.setTextPos(self.parseLabelPos(geometry, nodeLabel)) return node data = data.nextSiblingElement('data') return None
def OWLFunctionalSyntaxDocumentFilter(content, **kwargs): """ Properly format the given OWL document for functional syntax serialization. :type content: str :type **kwargs: dict :rtype: str :Keyword Arguments: * *skipDefaultPrefix* (``bool``) -- If set to True, then remove the default prefix from the given OWL document. This is useful to deal with situations where the default prefix is automatically generated (e.g. by owlapi). Default: False """ # Protege 4.3 does not support comments being generated by owlapi-4 FunctionalSyntaxObjectRenderer, # so we need to strip them out of our document. result = [] extend = result.extend for row in (i for i in content.split('\n') if not i.startswith('#')): if not isEmpty(row): if RE_OWL_ONTOLOGY_FUNCTIONAL_TAG.search(row): extend(['\n', row, '\n', '\n']) else: extend([row, '\n']) # Remove the default prefix from the document if requested. See redmine issue 463 skipDefaultPrefix = kwargs.get('skipDefaultPrefix') if 'skipDefaultPrefix' in kwargs else False firstLine = 0 if not skipDefaultPrefix else 2 return ''.join(result[firstLine:]).rstrip('\n')
def textChanged(self): unprocessed_new_text = self.textField.value().strip() unprocessed_new_text = unprocessed_new_text if not isEmpty(unprocessed_new_text) else self.node.label.template exception_list = ['-', '_', '.', '~', '\n'] new_rc = '' flag = False for i, c in enumerate(unprocessed_new_text): if c == '': pass elif i < (len(unprocessed_new_text) - 1) and (c == '\\' and unprocessed_new_text[i + 1] == 'n'): new_rc = new_rc + '\n' elif i > 0 and (c == 'n' and unprocessed_new_text[i - 1] == '\\'): pass elif (not c.isalnum()) and (c not in exception_list): new_rc = new_rc + '_' flag = True else: new_rc = new_rc + c # new_rc = new_rc.replace('\n','') if flag is True: self.session.statusBar().showMessage( 'Spaces in between alphanumeric characters and special characters were replaced by an underscore character.', 15000) return_list = [] if (unprocessed_new_text != self.node.remaining_characters): # print('unprocessed_new_text',unprocessed_new_text) # print('self.node.remaining_characters',self.node.remaining_characters) # print(NewlineFeedInsensitive(new_rc, self.node.remaining_characters).result()) return_list.append(CommandProjectDisconnectSpecificSignals(self.project)) if self.refactorField.isChecked(): for n in self.project.nodes(): if n.text() == self.node.text(): return_list.append( CommandNodeSetRemainingCharacters(n.remaining_characters, new_rc, n, self.project, refactor=True)) else: # refactor_var = NewlineFeedInsensitive(new_rc, self.node.remaining_characters).result() # return_list.append( # CommandNodeSetRemainingCharacters(self.node.remaining_characters, new_rc, self.node, self.project, refactor=refactor_var)) return_list.append( CommandNodeSetRemainingCharacters(self.node.remaining_characters, new_rc, self.node, self.project)) return_list.append(CommandProjectConnectSpecificSignals(self.project)) return return_list return None
def nameChanged(self): """ Executed whenever the text in the rename field changes. """ caption = '' enabled = True if isEmpty(self.renameField.value()): caption = "\'{0}\' is not a valid predicate name".format( self.renameField.value()) enabled = False self.caption.setText(caption) self.caption.setVisible(not isEmpty(caption)) self.confirmationBox.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(enabled) self.setFixedSize(self.sizeHint())
def doAcceptForm(self): """ Validate project settings. """ caption = '' enabled = True ############################################# # CHECK NAME ################################# if not self.name(): caption = '' enabled = False ''' else: if isdir(self.path()): caption = "Project '{0}' already exists!".format(self.name()) enabled = False elif not isPathValid(self.path()): caption = "'{0}' is not a valid project name!".format(self.name()) enabled = False ''' ############################################# # CHECK PREFIX ################################# if enabled: if self.prefix() and not QtXmlPatterns.QXmlName.isNCName(str(self.prefix()).strip()): caption = 'Please insert a legal prefix' enabled = False ############################################# # CHECK IRI ################################# if enabled: if not self.iri(): caption = '' enabled = False else: try: iriObj = IRI(self.iri()) except IllegalNamespaceError: caption = 'Please insert a legal IRI' enabled = False self.caption.setText(caption) self.caption.setVisible(not isEmpty(caption)) self.confirmationBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(enabled) self.setFixedSize(self.sizeHint())
def addPlugin(self, plugin): """ Add a plugin to the set. :type plugin: AbstractPlugin :rtype: AbstractPlugin """ if isEmpty(plugin.objectName()): raise ValueError("missing objectName in %s" % plugin.__class__.__name__) if plugin.objectName() in self._pluginDict: raise ValueError("duplicate plugin found: %s" % plugin.objectName()) self._pluginList.append(plugin) self._pluginDict[plugin.objectName()] = plugin # LOGGER.debug("Added %s(%s)", plugin.__class__.__name__, plugin.objectName()) return plugin
def addWidget(self, widget): """ Add a QWidget to the set. :type widget: QWidget :rtype: QWidget """ if isEmpty(widget.objectName()): raise ValueError("missing objectName in %s" % widget.__class__.__name__) if widget.objectName() in self._widgetDict: raise ValueError("duplicate widget found: %s" % widget.objectName()) self._widgetList.append(widget) self._widgetDict[widget.objectName()] = widget # LOGGER.debug("Added %s(%s)", widget.__class__.__name__, widget.objectName()) return widget
def addMenu(self, menu): """ Add a QMenu to the set. :type menu: QMenu :rtype: QMenu """ if isEmpty(menu.objectName()): raise ValueError("missing objectName in %s" % menu.__class__.__name__) if menu.objectName() in self._menuDict: raise ValueError("duplicate menu found: %s" % menu.objectName()) self._menuList.append(menu) self._menuDict[menu.objectName()] = menu # LOGGER.debug("Added %s(%s)", menu.__class__.__name__, menu.objectName()) return menu
def addAction(self, action): """ Add a QAction or a QActionGroup to the set. :type action: T <= QAction|QActionGroup :rtype: T <= QAction|QActionGroup """ if isEmpty(action.objectName()): raise ValueError("missing objectName in %s" % action.__class__.__name__) if action.objectName() in self._actionDict: raise ValueError("duplicate action found: %s" % action.objectName()) self._actionList.append(action) self._actionDict[action.objectName()] = action # LOGGER.debug("Added %s(%s)", action.__class__.__name__, action.objectName()) return action
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]
def doAcceptForm(self): """ Validate project settings. """ caption = '' enabled = True ############################################# # CHECK NAME ################################# if not self.name(): caption = '' enabled = False else: if isdir(self.path()): caption = "Project '{0}' already exists!".format(self.name()) enabled = False elif not isPathValid(self.path()): caption = "'{0}' is not a valid project name!".format( self.name()) enabled = False ############################################# # CHECK PREFIX ################################# if enabled: #if not self.prefix(): if not self.prefixes(): caption = '' enabled = False ############################################# # CHECK IRI ################################# if enabled: if not self.iri(): caption = '' enabled = False self.caption.setText(caption) self.caption.setVisible(not isEmpty(caption)) self.confirmationBox.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(enabled) self.setFixedSize(self.sizeHint())
def doProjectPathValidate(self): """ Validate project settings. """ caption = '' enabled = True ############################################# # CHECK NAME ################################# name = self.nameField.value() path = self.pathField.value() if not name: caption = '' enabled = False else: if isdir(path): caption = "Project '{0}' already exists!".format(name) enabled = False elif not isPathValid(path): caption = "'{0}' is not a valid project name!".format(name) enabled = False ############################################# # CHECK PREFIX ################################# if enabled: if not self.prefixField.value(): caption = '' enabled = False ############################################# # CHECK IRI ################################# if enabled: if not self.iriField.value(): caption = '' enabled = False self.caption.setText(caption) self.caption.setVisible(not isEmpty(caption)) self.confirmationBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(enabled) self.setFixedSize(self.sizeHint())
def insertPlugin(self, widget, before): """ Insert the given plugin before the given one. :type widget: AbstractPlugin :type before: AbstractPlugin :rtype: AbstractPlugin """ if isEmpty(widget.objectName()): raise ValueError("missing objectName in %s" % widget.__class__.__name__) if widget.objectName() in self._pluginDict: raise ValueError("duplicate plugin found: %s" % widget.objectName()) self._pluginList.insert(self._pluginList.index(before), widget) self._pluginDict[widget.objectName()] = widget # LOGGER.debug("Added %s(%s) before %s(%s)", # plugin.__class__.__name__, plugin.objectName(), # before.__class__.__name__, before.objectName()) return widget
def insertWidget(self, widget, before): """ Insert the given QWidget before the given one. :type widget: QWidget :type before: QWidget :rtype: QWidget """ if isEmpty(widget.objectName()): raise ValueError("missing objectName in %s" % widget.__class__.__name__) if widget.objectName() in self._widgetDict: raise ValueError("duplicate widget found: %s" % widget.objectName()) self._widgetList.insert(self._widgetList.index(before), widget) self._widgetDict[widget.objectName()] = widget # LOGGER.debug("Added %s(%s) before %s(%s)", # widget.__class__.__name__, widget.objectName(), # before.__class__.__name__, before.objectName()) return widget
def accept(self): """ Accepts the conflict resolution form. """ source = self.widget('final_documentation') if isEmpty(source.value()): msgbox = QtWidgets.QMessageBox(self) msgbox.setIconPixmap(QtGui.QIcon(':/icons/48/ic_warning_black').pixmap(48)) msgbox.setStandardButtons(QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Yes) msgbox.setText("No documentation specified for {0} '{1}'. " "Do you want to continue?".format(self.item.shortName, self.name)) msgbox.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) msgbox.setWindowTitle('No documentation specified!') msgbox.exec_() if msgbox.result() == QtWidgets.QMessageBox.No: return super().accept()
def insertMenu(self, menu, before): """ Insert the given QMenu before the given one. :type menu: QMenu :type before: QMenu :rtype: QMenu """ if isEmpty(menu.objectName()): raise ValueError("missing objectName in %s" % menu.__class__.__name__) if menu.objectName() in self._menuDict: raise ValueError("duplicate menu found: %s" % menu.objectName()) self._menuList.insert(self._menuList.index(before), menu) self._menuDict[menu.objectName()] = menu # LOGGER.debug("Added %s(%s) before %s(%s)", # menu.__class__.__name__, menu.objectName(), # before.__class__.__name__, before.objectName()) return menu
def OWLFunctionalDocumentFilter(content): """ Properly format the given OWL document for Functional OWL serialization. This function is needed because Protege 4.3 does not support comments being generated by OWLapi 4 FunctionalSyntaxObjectRenderer, so we need to strip them out of our document. :type content: str :rtype: str """ result = [] extend = result.extend for row in (i for i in content.split('\n') if not i.startswith('#')): if not isEmpty(row): if RE_OWL_ONTOLOGY_FUNCTIONAL_TAG.search(row): extend(['\n', row, '\n', '\n']) else: extend([row, '\n']) return ''.join(result).rstrip('\n')
def insertAction(self, action, before): """ Insert the given QAction or QActionGroup before the given one. :type action: T <= QAction|QActionGroup :type before: T <= QAction|QActionGroup :rtype: T <= QAction|QActionGroup """ if isEmpty(action.objectName()): raise ValueError("missing objectName in %s" % action.__class__.__name__) if action.objectName() in self._actionDict: raise ValueError("duplicate action found: %s" % action.objectName()) self._actionList.insert(self._actionList.index(before), action) self._actionDict[action.objectName()] = action # LOGGER.debug("Added %s(%s) before %s(%s)", # action.__class__.__name__, action.objectName(), # before.__class__.__name__, before.objectName()) return action
def selectPlugin(self): """ Bring up a modal window that allows the user to choose a valid plugin archive. """ path = os.path.dirname(self.pluginField.value()) if not isPathValid(path): path = expandPath('~') dialog = QtWidgets.QFileDialog(self) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen) dialog.setDirectory(path) dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile) dialog.setViewMode(QtWidgets.QFileDialog.Detail) dialog.setNameFilters([File.Zip.value]) if dialog.exec_() == QtWidgets.QFileDialog.Accepted: self.pluginField.setValue(first(dialog.selectedFiles())) self.confirmationBox.setEnabled(not isEmpty(self.pluginField.value()))
def selectPlugin(self): """ Bring up a modal window that allows the user to choose a valid plugin archive. """ path = os.path.dirname(self.pluginField.value()) if not isPathValid(path): path = expandPath('~') dialog = QtWidgets.QFileDialog(self) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptOpen) dialog.setDirectory(path) dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile) dialog.setViewMode(QtWidgets.QFileDialog.Detail) dialog.setNameFilters([File.Zip.value]) if dialog.exec_() == QtWidgets.QFileDialog.Accepted: self.pluginField.setValue(first(dialog.selectedFiles())) self.confirmationBox.setEnabled( not isEmpty(self.pluginField.value()))
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)
def onNameFieldChanged(self, name): """ Executed when the content of the input field changes. :type name: str """ name = name.strip() if not name: caption = '' enabled = False else: for diagram in self.project.diagrams(): if diagram.name.upper() == name.upper(): caption = '' enabled = False break else: caption = '' enabled = True self.warnLabel.setText(caption) self.warnLabel.setVisible(not isEmpty(caption)) self.confirmationBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(enabled) self.setFixedSize(self.sizeHint())
def onNameFieldChanged(self, name): """ Executed when the content of the input field changes. :type name: str """ name = name.strip() if not name: caption = '' enabled = False else: for diagram in self.project.diagrams(): if diagram.name.upper() == name.upper(): caption = '' enabled = False break else: caption = '' enabled = True self.warnLabel.setText(caption) self.warnLabel.setVisible(not isEmpty(caption)) self.confirmationBox.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(enabled) self.setFixedSize(self.sizeHint())
def exportGenericNode(self, node, configuration): """ Export the given node into a QDomElement. :type node: AbstractNode :type configuration: str :rtype: QDomElement """ ############################################# # NODE GEOMETRY ################################# nodePos = self.translatePos(node) geometry = self.document.createElement('y:Geometry') geometry.setAttribute('height', node.height()) geometry.setAttribute('width', node.width()) geometry.setAttribute('x', nodePos.x()) geometry.setAttribute('y', nodePos.y()) ############################################# # NODE FILL ################################# fill = self.document.createElement('y:Fill') fill.setAttribute('color', node.brush().color().name()) fill.setAttribute('transparent', 'false') ############################################# # BORDER STYLE ################################# border = self.document.createElement('y:BorderStyle') border.setAttribute('color', '#000000') border.setAttribute('type', 'line') border.setAttribute('width', '1.0') ############################################# # NODE LABEL ################################# labelPos = self.translateLabelPos(node) label = self.document.createElement('y:NodeLabel') label.setAttribute('alignment', 'center') label.setAttribute('autoSizePolicy', 'content') label.setAttribute('fontFamily', 'Arial') label.setAttribute('fontSize', '12') label.setAttribute('fontStyle', 'plain') label.setAttribute('hasBackgroundColor', 'false') label.setAttribute('hasLineColor', 'false') label.setAttribute('height', node.label.height()) label.setAttribute('modelName', 'free') label.setAttribute('modelPosition', 'anywhere') label.setAttribute('textColor', '#000000') label.setAttribute('visible', 'true') label.setAttribute('width', node.label.width()) label.setAttribute('x', labelPos.x()) label.setAttribute('y', labelPos.y()) label.appendChild(self.document.createTextNode(node.text())) ############################################# # STYLE PROPERTIES ################################# prop = self.document.createElement('y:Property') prop.setAttribute('class', 'java.lang.Boolean') prop.setAttribute('name', 'y.view.ShadowNodePainter.SHADOW_PAINTING') prop.setAttribute('value', 'false') style = self.document.createElement('y:StyleProperties') style.appendChild(prop) ############################################# # GENERIC NODE ################################# genericNode = self.document.createElement('y:GenericNode') genericNode.setAttribute('configuration', configuration) genericNode.appendChild(geometry) genericNode.appendChild(fill) genericNode.appendChild(border) genericNode.appendChild(label) genericNode.appendChild(style) ############################################# # DATA [NODE] ################################# dataNode = self.document.createElement('data') dataNode.setAttribute('key', GraphMLDiagramExporter.KeyNode) dataNode.appendChild(genericNode) ############################################# # DATA [URL] ################################# meta = self.diagram.project.meta(node.type(), node.text()) wikiURL = '../wiki/{0}'.format(node.text()) if not isEmpty(meta.get('url', '')): wikiURL = meta.get('url', '') dataURL = self.document.createElement('data') dataURL.setAttribute('key', GraphMLDiagramExporter.KeyUrl) dataURL.appendChild(self.document.createTextNode(wikiURL)) ############################################# # DATA [DESCRIPTION] ################################# dataWIKI = self.document.createElement('data') dataWIKI.setAttribute('key', GraphMLDiagramExporter.KeyDescription) dataWIKI.appendChild(self.document.createTextNode(meta.get('description', ''))) ############################################# # NODE ################################# elem = self.document.createElement('node') elem.setAttribute('id', node.id) elem.appendChild(dataNode) elem.appendChild(dataURL) elem.appendChild(dataWIKI) return elem
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)
def test_empty(): assert isEmpty(None) assert isEmpty('') assert isEmpty(' ') assert not isEmpty('Hello World') assert not isEmpty(4)
def test_empty(self): self.assertTrue(isEmpty(None)) self.assertTrue(isEmpty('')) self.assertTrue(isEmpty(' ')) self.assertFalse(isEmpty('Hello World')) self.assertFalse(isEmpty(4))
def exportGenericNode(self, node, configuration): """ Export the given node into a QDomElement. :type node: AbstractNode :type configuration: str :rtype: QDomElement """ ############################################# # NODE GEOMETRY ################################# nodePos = self.translatePos(node) geometry = self.document.createElement('y:Geometry') geometry.setAttribute('height', node.height()) geometry.setAttribute('width', node.width()) geometry.setAttribute('x', nodePos.x()) geometry.setAttribute('y', nodePos.y()) ############################################# # NODE FILL ################################# fill = self.document.createElement('y:Fill') fill.setAttribute('color', node.brush().color().name()) fill.setAttribute('transparent', 'false') ############################################# # BORDER STYLE ################################# border = self.document.createElement('y:BorderStyle') border.setAttribute('color', '#000000') border.setAttribute('type', 'line') border.setAttribute('width', '1.0') ############################################# # NODE LABEL ################################# labelPos = self.translateLabelPos(node) label = self.document.createElement('y:NodeLabel') label.setAttribute('alignment', 'center') label.setAttribute('autoSizePolicy', 'content') label.setAttribute('fontFamily', 'Arial') label.setAttribute('fontSize', '12') label.setAttribute('fontStyle', 'plain') label.setAttribute('hasBackgroundColor', 'false') label.setAttribute('hasLineColor', 'false') label.setAttribute('height', node.label.height()) label.setAttribute('modelName', 'free') label.setAttribute('modelPosition', 'anywhere') label.setAttribute('textColor', '#000000') label.setAttribute('visible', 'true') label.setAttribute('width', node.label.width()) label.setAttribute('x', labelPos.x()) label.setAttribute('y', labelPos.y()) label.appendChild(self.document.createTextNode(node.text())) ############################################# # STYLE PROPERTIES ################################# prop = self.document.createElement('y:Property') prop.setAttribute('class', 'java.lang.Boolean') prop.setAttribute('name', 'y.view.ShadowNodePainter.SHADOW_PAINTING') prop.setAttribute('value', 'false') style = self.document.createElement('y:StyleProperties') style.appendChild(prop) ############################################# # GENERIC NODE ################################# genericNode = self.document.createElement('y:GenericNode') genericNode.setAttribute('configuration', configuration) genericNode.appendChild(geometry) genericNode.appendChild(fill) genericNode.appendChild(border) genericNode.appendChild(label) genericNode.appendChild(style) ############################################# # DATA [NODE] ################################# dataNode = self.document.createElement('data') dataNode.setAttribute('key', GraphMLDiagramExporter.KeyNode) dataNode.appendChild(genericNode) ############################################# # DATA [URL] ################################# meta = self.diagram.project.meta(node.type(), node.text()) wikiURL = '../wiki/{0}'.format(node.text()) if not isEmpty(meta.get(K_URL, '')): wikiURL = meta.get(K_URL, '') dataURL = self.document.createElement('data') dataURL.setAttribute('key', GraphMLDiagramExporter.KeyUrl) dataURL.appendChild(self.document.createTextNode(wikiURL)) ############################################# # DATA [DESCRIPTION] ################################# dataWIKI = self.document.createElement('data') dataWIKI.setAttribute('key', GraphMLDiagramExporter.KeyDescription) dataWIKI.appendChild( self.document.createTextNode(meta.get(K_DESCRIPTION, ''))) ############################################# # NODE ################################# elem = self.document.createElement('node') elem.setAttribute('id', node.id) elem.appendChild(dataNode) elem.appendChild(dataURL) elem.appendChild(dataWIKI) return elem