def validate(self): """ Validate the form and trigger accept() if the form is valid. """ if not isEmpty(self.minCardinalityField.text()) and not isEmpty(self.maxCardinalityField.text()): v1 = int(self.minCardinalityField.text()) v2 = int(self.maxCardinalityField.text()) if v1 > v2: msgbox = QMessageBox(self) msgbox.setIconPixmap(QPixmap(':/icons/warning')) msgbox.setWindowIcon(QIcon(':/images/eddy')) msgbox.setWindowTitle('Invalid range specified') msgbox.setText('Minimum cardinality {} must be lower or equal than Maximum cardinality {}'.format(v1, v2)) msgbox.setStandardButtons(QMessageBox.Ok) msgbox.exec_() return if not isEmpty(self.minCardinalityField.text()): self.minCardinalityValue = int(self.minCardinalityField.text()) if not isEmpty(self.maxCardinalityField.text()): self.maxCardinalityValue = int(self.maxCardinalityField.text()) self.accept()
def editingFinished(self): """ Executed when the finish in editing the predicate name of the node label """ if self.node: try: node = self.node sender = self.sender() data = sender.value() data = data if not isEmpty(data) else node.label.template if data != node.text(): scene = node.scene() if sender is self.nameField: commands = [] for n in scene.index.predicates( node.item, node.text()): commands.append( CommandNodeLabelChange(scene, n, n.text(), data)) name = 'change predicate "{}" name to "{}"'.format( node.text(), data) scene.undostack.push( CommandRefactor(name, scene, commands)) else: scene.undostack.push( CommandNodeLabelChange(scene, node, node.text(), data)) except RuntimeError: pass
def readyRead(self): """ Executed whenever we need to read a message. """ while True: message = self.inStream.readLine() if isEmpty(message): break self.messageReceived.emit(message)
def nameChanged(self): """ Executed whenever the text in the rename field changes. """ button = self.buttonBox.button(QDialogButtonBox.Ok) empty = isEmpty(self.renameField.value()) button.setDisabled(empty) self.invalidName.setVisible(empty) self.setFixedSize(self.sizeHint())
def readyRead(self): """ Executed whenever we need to read a message. """ while True: message = self.inStream.readLine() if isEmpty(message): break self.messageReceived.emit(message)
def test_pizza_graphol_to_owl(self): # GIVEN self.init('@examples/Pizza.graphol') # WHEN exporter = OWLExporter(scene=self.scene, ontoIRI='IRI', ontoPrefix='PREFIX') exporter.work() # THEN translation = exporter.export(OWLSyntax.Functional) self.assertIsInstance(translation, str) self.assertFalse(isEmpty(translation))
def test_lubm_graphol_to_graphol(self): # GIVEN self.init('@examples/LUBM.graphol') # WHEN exporter = GrapholExporter(scene=self.scene) exporter.run() # THEN translation = exporter.export(indent=2) self.assertIsInstance(translation, str) self.assertFalse(isEmpty(translation))
def test_lubm_graphol_to_graphol(self): # GIVEN self.init('@examples/LUBM.graphol') # WHEN exporter = GrapholExporter(scene=self.scene) exporter.run() # THEN translation = exporter.export(indent=2) self.assertIsInstance(translation, str) self.assertFalse(isEmpty(translation))
def labelEdited(self): """ Change the label of the node. """ data = self.textField.value().strip() data = data if not isEmpty(data) else self.node.label.template if self.node.text() != data: command = CommandNodeLabelChange(self.scene, self.node, self.node.text(), data) self.scene.undostack.push(command)
def openFile(self, filepath): """ Open the given file in the activation window. :type filepath: str :rtype: bool """ if self.mainwindow: if not isEmpty(filepath) and os.path.isfile(filepath) and filepath.endswith(Filetype.Graphol.extension): self.mainwindow.openFile(filepath) return True return False
def test_pizza_graphol_to_owl(self): # GIVEN self.init('@examples/Pizza.graphol') # WHEN exporter = OWLExporter(scene=self.scene, ontoIRI='IRI', ontoPrefix='PREFIX') exporter.work() # THEN translation = exporter.export(OWLSyntax.Functional) self.assertIsInstance(translation, str) self.assertFalse(isEmpty(translation))
def openFile(self, filepath): """ Open the given file in the activation window. :type filepath: str :rtype: bool """ if self.mainwindow: if not isEmpty(filepath) and os.path.isfile( filepath) and filepath.endswith( Filetype.Graphol.extension): self.mainwindow.openFile(filepath) return True return False
def validate(self): """ Validate the form and trigger accept() if the form is valid. """ if isEmpty(self.renameField.value()): msgbox = QMessageBox(self) msgbox.setIconPixmap(QPixmap(':/icons/warning')) msgbox.setWindowIcon(QIcon(':/images/eddy')) msgbox.setWindowTitle('Invalid predicate') msgbox.setText('You specified an invalid predicate name!') msgbox.setStandardButtons(QMessageBox.Ok) msgbox.exec_() return # This will strip out leading/trailing whitespaces. self.renameField.setValue(self.renameField.value()) self.accept()
def focusOutEvent(self, focusEvent): """ Executed when the text item lose the focus. :type focusEvent: QFocusEvent """ scene = self.scene() if scene.mode is DiagramMode.EditText: # Make sure we have something in the label. if isEmpty(self.text()): self.setText(self.template) focusInData = self.focusInData currentData = self.text() if focusInData and focusInData != currentData: # The code below is a bit tricky: to be able to properly update the node index in # the diagram scene we need to force the value of the label to it's previous one # and let the undo command implementation update the index by applying the redo. # We won't notice any glitch since the back and forth change is going to happen # within a frame and Qt will only draw the new text. This is the only place where # this trick is necessary since both the refactor name dialog and the node properties # tab perform the edit on an external QTextField and oly later they will push the # change in the label, while here we have realtime edit of the label. self.setText(focusInData) node = self.parentItem() command = CommandNodeLabelChange(scene, node, focusInData, currentData) scene.undostack.push(command) cursor = self.textCursor() cursor.clearSelection() self.focusInData = None self.setTextCursor(cursor) self.setTextInteractionFlags(Qt.NoTextInteraction) scene.setMode(DiagramMode.Idle) scene.sgnUpdated.emit() super().focusOutEvent(focusEvent)
def focusOutEvent(self, focusEvent): """ Executed when the text item lose the focus. :type focusEvent: QFocusEvent """ scene = self.scene() if scene.mode is DiagramMode.EditText: # Make sure we have something in the label. if isEmpty(self.text()): self.setText(self.template) focusInData = self.focusInData currentData = self.text() if focusInData and focusInData != currentData: # The code below is a bit tricky: to be able to properly update the node index in # the diagram scene we need to force the value of the label to it's previous one # and let the undo command implementation update the index by applying the redo. # We won't notice any glitch since the back and forth change is going to happen # within a frame and Qt will only draw the new text. This is the only place where # this trick is necessary since both the refactor name dialog and the node properties # tab perform the edit on an external QTextField and oly later they will push the # change in the label, while here we have realtime edit of the label. self.setText(focusInData) node = self.parentItem() command = CommandNodeLabelChange(scene, node, focusInData, currentData) scene.undostack.push(command) cursor = self.textCursor() cursor.clearSelection() self.focusInData = None self.setTextCursor(cursor) self.setTextInteractionFlags(Qt.NoTextInteraction) scene.setMode(DiagramMode.Idle) scene.sgnUpdated.emit() super().focusOutEvent(focusEvent)
def editingFinished(self): """ Executed when the finish in editing the predicate name of the node label """ if self.node: try: node = self.node sender = self.sender() data = sender.value() data = data if not isEmpty(data) else node.label.template if data != node.text(): scene = node.scene() if sender is self.nameField: commands = [] for n in scene.index.predicates(node.item, node.text()): commands.append(CommandNodeLabelChange(scene, n, n.text(), data)) name = 'change predicate "{}" name to "{}"'.format(node.text(), data) scene.undostack.push(CommandRefactor(name, scene, commands)) else: scene.undostack.push(CommandNodeLabelChange(scene, node, node.text(), data)) except RuntimeError: pass
def __bool__(self): """ Boolean operator implementation. :rtype: bool """ return not isEmpty(self.description) or not isEmpty(self.url)
def iriChanged(self): """ Executed whenever the value of the prefix field changes. """ button = self.buttonBox.button(QDialogButtonBox.Ok) button.setEnabled(not isEmpty(self.iriField.value()))
def __bool__(self): """ Boolean operator implementation. :rtype: bool """ return not isEmpty(self.description) or not isEmpty(self.url)