class ValueForm(QDialog): """ This class implements the form used to select the Literal value of an Individual node. """ def __init__(self, node, parent=None): """ Initialize the form dialog. :type node: IndividualNode :type parent: QWidget """ super().__init__(parent) # DATATYPE COMBO BOX self.datatypeField = ComboBox(self) for datatype in XsdDatatype: self.datatypeField.addItem(datatype.value, datatype) # VALUE STRING FIELD self.valueField = StringField(self) self.valueField.setFixedWidth(300) # FILL FIELDS WITH DATA if node.identity is Identity.Value: datatype = node.datatype for i in range(self.datatypeField.count()): if self.datatypeField.itemData(i) is datatype: self.datatypeField.setCurrentIndex(i) break self.valueField.setValue(node.value) else: self.datatypeField.setCurrentIndex(0) self.valueField.setValue('') # CONFIRMATION BOX self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.mainLayout = QFormLayout(self) self.mainLayout.addRow('Datatype', self.datatypeField) self.mainLayout.addRow('Value', self.valueField) self.mainLayout.addRow(self.buttonBox) self.setWindowTitle('Compose value') self.setWindowIcon(QIcon(':/images/eddy')) self.setFixedSize(self.sizeHint()) connect(self.buttonBox.accepted, self.accept) connect(self.buttonBox.rejected, self.reject)
class ValueForm(QtWidgets.QDialog): """ This class implements the form used to select the Value of an Individual node. """ def __init__(self, node, session): """ Initialize the form dialog. :type node: IndividualNode :type session: Session """ super().__init__(session) self.node = node ############################################# # FORM AREA ################################# self.datatypeLabel = QtWidgets.QLabel(self) self.datatypeLabel.setText('Datatype') self.datatypeField = ComboBox(self) self.datatypeField.setFixedWidth(300) for datatype in sorted(Datatype.forProfile( self.project.profile.type()), key=attrgetter('value')): self.datatypeField.addItem(datatype.value, datatype) self.valueLabel = QtWidgets.QLabel(self) self.valueLabel.setText('Value') self.valueField = StringField(self) self.valueField.setFixedWidth(300) if node.identity() is Identity.Value: self.valueField.setValue(node.value) datatype = node.datatype for i in range(self.datatypeField.count()): if self.datatypeField.itemData(i) is datatype: self.datatypeField.setCurrentIndex(i) break else: self.valueField.setValue('') self.datatypeField.setCurrentIndex(0) self.formWidget = QtWidgets.QWidget(self) self.formLayout = QtWidgets.QFormLayout(self.formWidget) self.formLayout.addRow(self.datatypeLabel, self.datatypeField) self.formLayout.addRow(self.valueLabel, self.valueField) ############################################# # 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.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.formWidget) self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight) self.setFixedSize(self.sizeHint()) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) self.setWindowTitle('Compose value') connect(self.confirmationBox.accepted, self.accept) connect(self.confirmationBox.rejected, self.reject) ############################################# # PROPERTIES ################################# @property def project(self): """ Returns the reference to the active project. :rtype: Project """ return self.session.project @property def session(self): """ Returns the reference to the active session (alias for RefactorNameForm.parent()). :rtype: Session """ return self.parent() ############################################# # SLOTS ################################# @QtCore.pyqtSlot() 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()
class ValueDomainNodeProperty(NodeProperty): """ This class implements the property dialog for value-domain nodes. """ def __init__(self, diagram, node, session): """ Initialize the node properties dialog. :type diagram: Diagram :type node: AbstractNode :type session: Session """ super().__init__(diagram, node, session) ############################################# # DATATYPE TAB ################################# self.datatypeLabel = QtWidgets.QLabel(self) self.datatypeLabel.setText('Datatype') self.datatypeField = ComboBox(self) self.datatypeField.setFixedWidth(200) self.datatypeField.setFocusPolicy(QtCore.Qt.StrongFocus) for datatype in Datatype: self.datatypeField.addItem(datatype.value, datatype) datatype = self.node.datatype for i in range(self.datatypeField.count()): if self.datatypeField.itemData(i) is datatype: self.datatypeField.setCurrentIndex(i) break else: self.datatypeField.setCurrentIndex(0) self.datatypeWidget = QtWidgets.QWidget() self.datatypeLayout = QtWidgets.QFormLayout(self.datatypeWidget) self.datatypeLayout.addRow(self.datatypeLabel, self.datatypeField) self.mainWidget.addTab(self.datatypeWidget, 'Datatype') ############################################# # SLOTS ################################# @QtCore.pyqtSlot() def complete(self): """ Executed when the dialog is accepted. """ commands = [self.positionChanged(), self.datatypeChanged()] if any(commands): self.session.undostack.beginMacro('edit {0} properties'.format( self.node.name)) for command in commands: if command: self.session.undostack.push(command) self.session.undostack.endMacro() super().accept() ############################################# # AUXILIARY METHODS ################################# 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
class FacetNodeProperty(NodeProperty): """ This class implements the property dialog for facet nodes. """ def __init__(self, diagram, node, session): """ Initialize the node properties dialog. :type diagram: Diagram :type node: AbstractNode :type session: Session """ super().__init__(diagram, node, session) ############################################# # FACET TAB ################################# f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.type() is Item.DatatypeRestrictionNode f3 = lambda x: x.type() is Item.ValueDomainNode admissible = [x for x in Facet] restriction = first( self.node.outgoingNodes(filter_on_edges=f1, filter_on_nodes=f2)) if restriction: valuedomain = first( restriction.incomingNodes(filter_on_edges=f1, filter_on_nodes=f3)) if valuedomain: admissible = Facet.forDatatype(valuedomain.datatype) self.facetLabel = QtWidgets.QLabel(self) self.facetLabel.setText('Facet') self.facetField = ComboBox(self) self.facetField.setFixedWidth(200) self.facetField.setFocusPolicy(QtCore.Qt.StrongFocus) for facet in admissible: self.facetField.addItem(facet.value, facet) facet = self.node.facet for i in range(self.facetField.count()): if self.facetField.itemData(i) is facet: self.facetField.setCurrentIndex(i) break else: self.facetField.setCurrentIndex(0) self.valueLabel = QtWidgets.QLabel(self) self.valueLabel.setText('Value') self.valueField = StringField(self) self.valueField.setFixedWidth(200) self.valueField.setValue(self.node.value) self.facetWidget = QtWidgets.QWidget() self.facetLayout = QtWidgets.QFormLayout(self.facetWidget) self.facetLayout.addRow(self.facetLabel, self.facetField) self.facetLayout.addRow(self.valueLabel, self.valueField) self.mainWidget.addTab(self.facetWidget, 'Facet') ############################################# # SLOTS ################################# @QtCore.pyqtSlot() def complete(self): """ Executed when the dialog is accepted. """ commands = [self.positionChanged(), self.facetChanged()] if any(commands): self.session.undostack.beginMacro('edit {0} properties'.format( self.node.name)) for command in commands: if command: self.session.undostack.push(command) self.session.undostack.endMacro() super().accept() ############################################# # AUXILIARY METHODS ################################# 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
class ValueNodeProperty(NodeProperty): """ This class implements the property dialog for value nodes. """ def __init__(self, diagram, node, session): """ Initialize the node properties dialog. :type diagram: Diagram :type node: AbstractNode :type session: Session """ super().__init__(diagram, node, session) self.node = node ############################################# # VALUE TAB ################################# self.datatypeLabel = QtWidgets.QLabel(self) self.datatypeLabel.setText('Datatype') self.datatypeField = ComboBox(self) self.datatypeField.setFixedWidth(200) self.datatypeField.setFocusPolicy(QtCore.Qt.StrongFocus) for datatype in Datatype: self.datatypeField.addItem(datatype.value, datatype) datatype = self.node.datatype for i in range(self.datatypeField.count()): if self.datatypeField.itemData(i) is datatype: self.datatypeField.setCurrentIndex(i) break else: self.datatypeField.setCurrentIndex(0) self.valueLabel = QtWidgets.QLabel(self) self.valueLabel.setText('Value') self.valueField = StringField(self) self.valueField.setFixedWidth(200) self.valueField.setValue(self.node.value) self.valueWidget = QtWidgets.QWidget() self.valueLayout = QtWidgets.QFormLayout(self.valueWidget) self.valueLayout.addRow(self.datatypeLabel, self.datatypeField) self.valueLayout.addRow(self.valueLabel, self.valueField) self.mainWidget.addTab(self.valueWidget, 'Datatype') ############################################# # SLOTS ################################# @QtCore.pyqtSlot() def complete(self): """ Executed when the dialog is accepted. """ commands = [self.positionChanged()] commands_value_changed = self.valueChanged() if commands_value_changed is not None: commands.extend(commands_value_changed) if any(commands): self.session.undostack.beginMacro('edit {0} properties'.format( self.node.name)) for command in commands: if command: self.session.undostack.push(command) self.session.undostack.endMacro() super().accept() ############################################# # AUXILIARY METHODS ################################# 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
class ValueForm(QtWidgets.QDialog): """ This class implements the form used to select the Value of an Individual node. """ def __init__(self, node, session): """ Initialize the form dialog. :type node: IndividualNode :type session: Session """ super().__init__(session) self.node = node ############################################# # FORM AREA ################################# self.datatypeLabel = QtWidgets.QLabel(self) self.datatypeLabel.setFont(Font('Roboto', 12)) self.datatypeLabel.setText('Datatype') self.datatypeField = ComboBox(self) self.datatypeField.setFont(Font('Roboto', 12)) self.datatypeField.setFixedWidth(300) for datatype in sorted(Datatype.forProfile(self.project.profile.type()), key=attrgetter('value')): self.datatypeField.addItem(datatype.value, datatype) self.valueLabel = QtWidgets.QLabel(self) self.valueLabel.setFont(Font('Roboto', 12)) self.valueLabel.setText('Value') self.valueField = StringField(self) self.valueField.setFixedWidth(300) if node.identity() is Identity.Value: self.valueField.setValue(node.value) datatype = node.datatype for i in range(self.datatypeField.count()): if self.datatypeField.itemData(i) is datatype: self.datatypeField.setCurrentIndex(i) break else: self.valueField.setValue('') self.datatypeField.setCurrentIndex(0) self.formWidget = QtWidgets.QWidget(self) self.formLayout = QtWidgets.QFormLayout(self.formWidget) self.formLayout.addRow(self.datatypeLabel, self.datatypeField) self.formLayout.addRow(self.valueLabel, self.valueField) ############################################# # 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) self.confirmationBox.setFont(Font('Roboto', 12)) ############################################# # SETUP DIALOG LAYOUT ################################# self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.formWidget) self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight) self.setFixedSize(self.sizeHint()) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) self.setWindowTitle('Compose value') connect(self.confirmationBox.accepted, self.accept) connect(self.confirmationBox.rejected, self.reject) ############################################# # PROPERTIES ################################# @property def project(self): """ Returns the reference to the active project. :rtype: Project """ return self.session.project @property def session(self): """ Returns the reference to the active session (alias for RefactorNameForm.parent()). :rtype: Session """ return self.parent() ############################################# # SLOTS ################################# @QtCore.pyqtSlot() 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()
class OWLTranslationForm(QDialog): """ This class implements the form used to perform Graphol -> OWL ontology translation. """ def __init__(self, scene, filepath, parent=None): """ Initialize the form dialog. :type scene: DiagramScene :type filepath: str :type parent: QWidget """ super().__init__(parent) self.scene = scene self.filepath = filepath self.worker = None self.workerThread = None self.iriField = StringField(self) self.iriField.setFixedWidth(300) self.iriField.setValidator(QRegExpValidator(QRegExp('[\w:\/\[\]=?%#~\.\-\+]*'), self)) self.prefixField = StringField(self) self.prefixField.setFixedWidth(300) self.prefixField.setValidator(QRegExpValidator(QRegExp('[\w]*'), self)) self.syntaxField = ComboBox(self) for syntax in OWLSyntax: self.syntaxField.addItem(syntax.value, syntax) self.syntaxField.setCurrentIndex(0) self.progressBar = QProgressBar(self) self.progressBar.setAlignment(Qt.AlignHCenter) self.progressBar.setRange(0, 100) self.progressBar.setValue(0) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.buttonBox.button(QDialogButtonBox.Ok).setDisabled(True) self.mainLayout = QFormLayout(self) self.mainLayout.addRow('IRI', self.iriField) self.mainLayout.addRow('Prefix', self.prefixField) self.mainLayout.addRow('Syntax', self.syntaxField) self.mainLayout.addRow(self.progressBar) self.mainLayout.addRow(self.buttonBox) self.setWindowTitle('OWL Translation') self.setWindowIcon(QIcon(':/images/eddy')) self.setFixedSize(self.sizeHint()) connect(self.buttonBox.accepted, self.run) connect(self.buttonBox.rejected, self.reject) connect(self.iriField.textChanged, self.iriChanged) #################################################################################################################### # # # SLOTS # # # #################################################################################################################### @pyqtSlot(Exception) def errored(self, exception): """ Executed whenever the translation errors. :type exception: Exception """ if isinstance(exception, MalformedDiagramError): msgbox = QMessageBox(self) msgbox.setIconPixmap(QPixmap(':/icons/warning')) msgbox.setWindowIcon(QIcon(':/images/eddy')) msgbox.setWindowTitle('Malformed Diagram') msgbox.setText('Malformed expression detected on {}: {}'.format(exception.item, exception)) msgbox.setInformativeText('Do you want to see the error in the diagram?') msgbox.setStandardButtons(QMessageBox.Yes|QMessageBox.No) S = QSpacerItem(400, 0, QSizePolicy.Minimum, QSizePolicy.Expanding) L = msgbox.layout() L.addItem(S, L.rowCount(), 0, 1, L.columnCount()) msgbox.exec_() if msgbox.result() == QMessageBox.Yes: for view in self.scene.views(): if isinstance(view, MainView): view.centerOn(exception.item) else: msgbox = QMessageBox(self) msgbox.setIconPixmap(QPixmap(':/icons/error')) msgbox.setWindowIcon(QIcon(':/images/eddy')) msgbox.setWindowTitle('Unhandled exception!') msgbox.setStandardButtons(QMessageBox.Close) msgbox.setText('Diagram translation could not be completed!') msgbox.setInformativeText('Please <a href="{}">submit a bug report</a> with detailed information.'.format(BUG_TRACKER)) msgbox.setDetailedText(''.join(traceback.format_exception(type(exception), exception, exception.__traceback__))) S = QSpacerItem(400, 0, QSizePolicy.Minimum, QSizePolicy.Expanding) L = msgbox.layout() L.addItem(S, L.rowCount(), 0, 1, L.columnCount()) msgbox.exec_() self.workerThread.quit() self.reject() @pyqtSlot() def completed(self): """ Executed whenever the translation completes. """ self.workerThread.quit() file = File(path=self.filepath) file.write(string=self.worker.export(syntax=self.syntaxField.currentData())) msgbox = QMessageBox(self) msgbox.setIconPixmap(QPixmap(':/icons/info')) msgbox.setWindowIcon(QIcon(':/images/eddy')) msgbox.setText('Translation completed!') msgbox.setInformativeText('Do you want to open the OWL ontology?') msgbox.setStandardButtons(QMessageBox.Yes|QMessageBox.No) S = QSpacerItem(400, 0, QSizePolicy.Minimum, QSizePolicy.Expanding) L = msgbox.layout() L.addItem(S, L.rowCount(), 0, 1, L.columnCount()) msgbox.exec_() if msgbox.result() == QMessageBox.Yes: openPath(self.filepath) self.accept() @pyqtSlot(int, int) def progress(self, current, total): """ Update the progress bar showing the translation advancement. :type current: int :type total: int """ self.progressBar.setRange(0, total) self.progressBar.setValue(current) @pyqtSlot() 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())) @pyqtSlot() def run(self): """ Perform the Graphol -> OWL translation in a separate thread. """ ontoIRI = self.iriField.value() ontoPrefix = self.prefixField.value() self.buttonBox.setEnabled(False) self.syntaxField.setEnabled(False) if not ontoIRI.endswith('#'): ontoIRI = '{0}#'.format(ontoIRI) self.workerThread = QThread() self.worker = OWLExporter(scene=self.scene, ontoIRI=ontoIRI, ontoPrefix=ontoPrefix) self.worker.moveToThread(self.workerThread) connect(self.worker.completed, self.completed) connect(self.worker.errored, self.errored) connect(self.worker.progress, self.progress) connect(self.workerThread.started, self.worker.work) self.workerThread.start()
class ValueRestrictionForm(QDialog): """ This class implements the form used to select the restriction of a datatype. """ # noinspection PyUnresolvedReferences def __init__(self, node, parent=None): """ Initialize the form dialog. :type node: ValueRestrictionNode :type parent: QWidget """ super().__init__(parent) # DATATYPE COMBO BOX self.datatypeField = ComboBox(self) for datatype in XsdDatatype: # hide unrestrictable elements. if Facet.forDatatype(datatype): self.datatypeField.addItem(datatype.value, datatype) datatype = node.datatype for i in range(self.datatypeField.count()): if self.datatypeField.itemData(i) is datatype: self.datatypeField.setCurrentIndex(i) break # FACET COMBO BOX self.facetField = ComboBox(self) for facet in Facet.forDatatype(datatype): self.facetField.addItem(facet.value, facet) facet = node.facet for i in range(self.facetField.count()): if self.facetField.itemData(i) is facet: self.facetField.setCurrentIndex(i) break # VALUE STRING FIELD self.valueField = StringField(self) self.valueField.setFixedWidth(300) self.valueField.setValue(node.value) # CONFIRMATION BOX self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.mainLayout = QFormLayout(self) self.mainLayout.addRow('Datatype', self.datatypeField) self.mainLayout.addRow('Facet', self.facetField) self.mainLayout.addRow('Value', self.valueField) self.mainLayout.addRow(self.buttonBox) self.setWindowTitle('Compose value restriction') self.setWindowIcon(QIcon(':/images/eddy')) self.setFixedSize(self.sizeHint()) connect(self.buttonBox.accepted, self.accept) connect(self.buttonBox.rejected, self.reject) connect(self.datatypeField.currentIndexChanged[int], self.datatypeFieldChanged) #################################################################################################################### # # # SLOTS # # # #################################################################################################################### @pyqtSlot(int) def datatypeFieldChanged(self, index): """ Executed whenever the index of the datatype field changes. :type index: int """ currentFacet = self.facetField.currentData() self.facetField.clear() for facet in Facet.forDatatype(self.datatypeField.itemData(index)): self.facetField.addItem(facet.value, facet) for i in range(self.facetField.count()): if self.facetField.itemData(i) is currentFacet: self.facetField.setCurrentIndex(i) break else: self.facetField.setCurrentIndex(0)
class ValueNodeProperty(NodeProperty): """ This class implements the property dialog for value nodes. """ def __init__(self, diagram, node, session): """ Initialize the node properties dialog. :type diagram: Diagram :type node: AbstractNode :type session: Session """ super().__init__(diagram, node, session) ############################################# # VALUE TAB ################################# self.datatypeLabel = QtWidgets.QLabel(self) self.datatypeLabel.setFont(Font('Roboto', 12)) self.datatypeLabel.setText('Datatype') self.datatypeField = ComboBox(self) self.datatypeField.setFixedWidth(200) self.datatypeField.setFocusPolicy(QtCore.Qt.StrongFocus) self.datatypeField.setFont(Font('Roboto', 12)) for datatype in Datatype: self.datatypeField.addItem(datatype.value, datatype) datatype = self.node.datatype for i in range(self.datatypeField.count()): if self.datatypeField.itemData(i) is datatype: self.datatypeField.setCurrentIndex(i) break else: self.datatypeField.setCurrentIndex(0) self.valueLabel = QtWidgets.QLabel(self) self.valueLabel.setFont(Font('Roboto', 12)) self.valueLabel.setText('Value') self.valueField = StringField(self) self.valueField.setFixedWidth(200) self.valueField.setFont(Font('Roboto', 12)) self.valueField.setValue(self.node.value) self.valueWidget = QtWidgets.QWidget() self.valueLayout = QtWidgets.QFormLayout(self.valueWidget) self.valueLayout.addRow(self.datatypeLabel, self.datatypeField) self.valueLayout.addRow(self.valueLabel, self.valueField) self.mainWidget.addTab(self.valueWidget, 'Datatype') ############################################# # SLOTS ################################# @QtCore.pyqtSlot() def complete(self): """ Executed when the dialog is accepted. """ commands = [self.positionChanged(), self.valueChanged()] if any(commands): self.session.undostack.beginMacro('edit {0} properties'.format(self.node.name)) for command in commands: if command: self.session.undostack.push(command) self.session.undostack.endMacro() super().accept() ############################################# # AUXILIARY METHODS ################################# 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
class FacetNodeProperty(NodeProperty): """ This class implements the property dialog for facet nodes. """ def __init__(self, diagram, node, session): """ Initialize the node properties dialog. :type diagram: Diagram :type node: AbstractNode :type session: Session """ super().__init__(diagram, node, session) ############################################# # FACET TAB ################################# f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.type() is Item.DatatypeRestrictionNode f3 = lambda x: x.type() is Item.ValueDomainNode admissible = [x for x in Facet] restriction = first(self.node.outgoingNodes(filter_on_edges=f1, filter_on_nodes=f2)) if restriction: valuedomain = first(restriction.incomingNodes(filter_on_edges=f1, filter_on_nodes=f3)) if valuedomain: admissible = Facet.forDatatype(valuedomain.datatype) self.facetLabel = QtWidgets.QLabel(self) self.facetLabel.setFont(Font('Roboto', 12)) self.facetLabel.setText('Facet') self.facetField = ComboBox(self) self.facetField.setFixedWidth(200) self.facetField.setFocusPolicy(QtCore.Qt.StrongFocus) self.facetField.setFont(Font('Roboto', 12)) for facet in admissible: self.facetField.addItem(facet.value, facet) facet = self.node.facet for i in range(self.facetField.count()): if self.facetField.itemData(i) is facet: self.facetField.setCurrentIndex(i) break else: self.facetField.setCurrentIndex(0) self.valueLabel = QtWidgets.QLabel(self) self.valueLabel.setFont(Font('Roboto', 12)) self.valueLabel.setText('Value') self.valueField = StringField(self) self.valueField.setFixedWidth(200) self.valueField.setFont(Font('Roboto', 12)) self.valueField.setValue(self.node.value) self.facetWidget = QtWidgets.QWidget() self.facetLayout = QtWidgets.QFormLayout(self.facetWidget) self.facetLayout.addRow(self.facetLabel, self.facetField) self.facetLayout.addRow(self.valueLabel, self.valueField) self.mainWidget.addTab(self.facetWidget, 'Facet') ############################################# # SLOTS ################################# @QtCore.pyqtSlot() def complete(self): """ Executed when the dialog is accepted. """ commands = [self.positionChanged(), self.facetChanged()] if any(commands): self.session.undostack.beginMacro('edit {0} properties'.format(self.node.name)) for command in commands: if command: self.session.undostack.push(command) self.session.undostack.endMacro() super().accept() ############################################# # AUXILIARY METHODS ################################# 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
class ValueForm(QtWidgets.QDialog): """ This class implements the form used to select the Value of an Individual node. """ def __init__(self, node, session): """ Initialize the form dialog. :type node: IndividualNode :type session: Session """ super().__init__(session) self.node = node ############################################# # FORM AREA ################################# self.datatypeLabel = QtWidgets.QLabel(self) self.datatypeLabel.setFont(Font('Roboto', 12)) self.datatypeLabel.setText('Datatype') self.datatypeField = ComboBox(self) self.datatypeField.setFont(Font('Roboto', 12)) self.datatypeField.setFixedWidth(300) for datatype in sorted(Datatype.forProfile( self.project.profile.type()), key=attrgetter('value')): self.datatypeField.addItem(datatype.value, datatype) self.valueLabel = QtWidgets.QLabel(self) self.valueLabel.setFont(Font('Roboto', 12)) self.valueLabel.setText('Value') self.valueField = StringField(self) self.valueField.setFixedWidth(300) if node.identity() is Identity.Value: self.valueField.setValue(node.value) datatype = node.datatype for i in range(self.datatypeField.count()): if self.datatypeField.itemData(i) is datatype: self.datatypeField.setCurrentIndex(i) break else: self.valueField.setValue('') self.datatypeField.setCurrentIndex(0) self.formWidget = QtWidgets.QWidget(self) self.formLayout = QtWidgets.QFormLayout(self.formWidget) self.formLayout.addRow(self.datatypeLabel, self.datatypeField) self.formLayout.addRow(self.valueLabel, self.valueField) ############################################# # 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) self.confirmationBox.setFont(Font('Roboto', 12)) ############################################# # SETUP DIALOG LAYOUT ################################# self.mainLayout = QtWidgets.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.addWidget(self.formWidget) self.mainLayout.addWidget(self.confirmationBox, 0, QtCore.Qt.AlignRight) self.setFixedSize(self.sizeHint()) self.setWindowIcon(QtGui.QIcon(':/icons/128/ic_eddy')) self.setWindowTitle('Compose value') connect(self.confirmationBox.accepted, self.accept) connect(self.confirmationBox.rejected, self.reject) ############################################# # PROPERTIES ################################# @property def project(self): """ Returns the reference to the active project. :rtype: Project """ return self.session.project @property def session(self): """ Returns the reference to the active session (alias for RefactorNameForm.parent()). :rtype: Session """ return self.parent() ############################################# # SLOTS ################################# @QtCore.pyqtSlot() 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()
def __init__(self, edge, session, annotation=None): """ Initialize the annotation builder dialog :type edge: AxiomEdge :type session: Session :type assertion: Annotation """ super().__init__(session) self.session = session self.project = session.project self.edge = edge self.annotation = annotation comboBoxLabel = QtWidgets.QLabel(self, objectName='property_combobox_label') comboBoxLabel.setText('Property') self.addWidget(comboBoxLabel) combobox = ComboBox(self, objectName='property_switch') combobox.setEditable(False) combobox.setFocusPolicy(QtCore.Qt.StrongFocus) combobox.setScrollEnabled(True) combobox.addItem(self.emptyString) sortedItems = sorted(self.project.getAnnotationPropertyIRIs(), key=str) combobox.addItems([str(x) for x in sortedItems]) # combobox.addItems([str(x) for x in self.project.getAnnotationPropertyIRIs()]) if not self.annotation: combobox.setCurrentText(self.emptyString) else: combobox.setCurrentText(str(self.annotation.assertionProperty)) self.addWidget(combobox) connect(combobox.currentIndexChanged, self.onPropertySwitched) textArea = QtWidgets.QTextEdit(self, objectName='valueTextArea') if self.annotation: if self.annotation.value: textArea.setText(str(self.annotation.value)) self.addWidget(textArea) comboBoxLabel = QtWidgets.QLabel(self, objectName='type_combobox_label') comboBoxLabel.setText('Type') self.addWidget(comboBoxLabel) combobox = ComboBox(self, objectName='type_switch') # combobox.palette().setColor(QtGui.QPalette.Button, QtGui.QColor(169, 169, 169)) combobox.setEditable(False) combobox.setFocusPolicy(QtCore.Qt.StrongFocus) combobox.setScrollEnabled(True) combobox.addItem(self.emptyString) sortedItems = sorted(self.project.getDatatypeIRIs(), key=str) combobox.addItems([str(x) for x in sortedItems]) # combobox.addItems([str(x) for x in self.project.getDatatypeIRIs()]) if not self.annotation: combobox.setCurrentText(self.emptyString) else: if self.annotation.datatype: combobox.setCurrentText(str(self.annotation.datatype)) else: combobox.setCurrentText(self.emptyString) self.addWidget(combobox) connect(combobox.currentIndexChanged, self.onTypeSwitched) comboBoxLabel = QtWidgets.QLabel(self, objectName='lang_combobox_label') comboBoxLabel.setText('Lang') self.addWidget(comboBoxLabel) combobox = ComboBox(self, objectName='lang_switch') combobox.setEditable(True) combobox.setFocusPolicy(QtCore.Qt.StrongFocus) combobox.setScrollEnabled(True) combobox.addItem(self.emptyString) combobox.addItems([x for x in self.project.getLanguages()]) if not self.annotation: combobox.setCurrentText(self.emptyString) else: if self.annotation.language: combobox.setCurrentText(str(self.annotation.language)) else: combobox.setCurrentText(self.emptyString) self.addWidget(combobox) ############################################# # CONFIRMATION BOX ################################# confirmation = QtWidgets.QDialogButtonBox( QtCore.Qt.Horizontal, self, objectName='confirmation_widget') confirmation.addButton(QtWidgets.QDialogButtonBox.Save) confirmation.addButton(QtWidgets.QDialogButtonBox.Cancel) confirmation.setContentsMargins(10, 0, 10, 10) if not annotation: confirmation.button( QtWidgets.QDialogButtonBox.Save).setEnabled(False) self.addWidget(confirmation) connect(confirmation.accepted, self.accept) connect(confirmation.rejected, self.reject) formlayout = QtWidgets.QFormLayout() formlayout.addRow(self.widget('property_combobox_label'), self.widget('property_switch')) formlayout.addRow(self.widget('valueTextArea')) formlayout.addRow(self.widget('type_combobox_label'), self.widget('type_switch')) formlayout.addRow(self.widget('lang_combobox_label'), self.widget('lang_switch')) formlayout.addRow(self.widget('confirmation_widget')) self.setLayout(formlayout) self.setMinimumSize(740, 380) self.setWindowTitle('Annotation builder <{}>'.format(str(edge))) self.redraw()
def __init__(self, iri, session, assertion=None): """ Initialize the annotation assertion builder dialog (subject IRI = iri). :type iri: IRI :type session: Session :type assertion: AnnotationAssertion """ super().__init__(session) self.session = session self.project = session.project self.iri = iri self.assertion = assertion ''' widget = AnnotationPropertyExplorerWidget(session) widget.setObjectName('annotation_property_explorer') #widget.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Maximum) self.addWidget(widget) self.setMinimumSize(740, 420) self.setWindowTitle('Annotation assertion builder') layout = QtWidgets.QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.widget('annotation_property_explorer')) self.setLayout(layout) ''' comboBoxLabel = QtWidgets.QLabel(self, objectName='property_combobox_label') comboBoxLabel.setText('Property') self.addWidget(comboBoxLabel) combobox = ComboBox(self, objectName='property_switch') combobox.setEditable(False) combobox.setFocusPolicy(QtCore.Qt.StrongFocus) combobox.setScrollEnabled(True) combobox.addItem(self.emptyString) sortedItems = sorted(self.project.getAnnotationPropertyIRIs(), key=str) combobox.addItems([str(x) for x in sortedItems]) # combobox.addItems([str(x) for x in self.project.getAnnotationPropertyIRIs()]) if not self.assertion: combobox.setCurrentText(self.emptyString) else: combobox.setCurrentText(str(self.assertion.assertionProperty)) self.addWidget(combobox) connect(combobox.currentIndexChanged, self.onPropertySwitched) ''' formlayout = QtWidgets.QFormLayout(self, objectName='property_layout') formlayout.addRow(self.widget('property_combobox_label'), self.widget('property_switch')) self.addWidget(formlayout) ''' textArea = QtWidgets.QTextEdit(self, objectName='valueTextArea') if self.assertion: if self.assertion.value: textArea.setText(str(self.assertion.value)) self.addWidget(textArea) comboBoxLabel = QtWidgets.QLabel(self, objectName='type_combobox_label') comboBoxLabel.setText('Type') self.addWidget(comboBoxLabel) combobox = ComboBox(self, objectName='type_switch') #combobox.palette().setColor(QtGui.QPalette.Button, QtGui.QColor(169, 169, 169)) combobox.setEditable(False) combobox.setFocusPolicy(QtCore.Qt.StrongFocus) combobox.setScrollEnabled(True) combobox.addItem(self.emptyString) sortedItems = sorted(self.project.getDatatypeIRIs(), key=str) combobox.addItems([str(x) for x in sortedItems]) #combobox.addItems([str(x) for x in self.project.getDatatypeIRIs()]) if not self.assertion: combobox.setCurrentText(self.emptyString) else: if self.assertion.datatype: combobox.setCurrentText(str(self.assertion.datatype)) else: combobox.setCurrentText(self.emptyString) self.addWidget(combobox) connect(combobox.currentIndexChanged, self.onTypeSwitched) ''' boxlayout = QtWidgets.QHBoxLayout(self, objectName='type_layout') boxlayout.setAlignment(QtCore.Qt.AlignLeft) boxlayout.addWidget(self.widget('type_combobox_label')) boxlayout.addWidget(self.widget('type_switch')) self.addWidget(boxlayout) ''' comboBoxLabel = QtWidgets.QLabel(self, objectName='lang_combobox_label') comboBoxLabel.setText('Lang') self.addWidget(comboBoxLabel) combobox = ComboBox(self, objectName='lang_switch') combobox.setEditable(True) combobox.setFocusPolicy(QtCore.Qt.StrongFocus) combobox.setScrollEnabled(True) combobox.addItem(self.emptyString) combobox.addItems([x for x in self.project.getLanguages()]) if not self.assertion: combobox.setCurrentText(self.emptyString) else: if self.assertion.language: combobox.setCurrentText(str(self.assertion.language)) else: combobox.setCurrentText(self.emptyString) self.addWidget(combobox) ''' boxlayout = QtWidgets.QHBoxLayout(self, objectName='lang_layout') boxlayout.setAlignment(QtCore.Qt.AlignLeft) boxlayout.addWidget(self.widget('lang_combobox_label')) boxlayout.addWidget(self.widget('lang_switch')) self.addWidget(boxlayout) boxlayout = QtWidgets.QHBoxLayout(self, objectName='type_lang_layout') boxlayout.setAlignment(QtCore.Qt.AlignLeft) boxlayout.addWidget(self.widget('type_layout')) boxlayout.addWidget(self.widget('lang_layout')) formlayout = QtWidgets.QFormLayout(self, objectName='type_lang_layout') formlayout.addRow(self.widget('type_layout')) formlayout.addRow(self.widget('lang_layout')) self.addWidget(formlayout) formlayout = QtWidgets.QFormLayout() formlayout.addRow(self.widget('valueTextArea')) formlayout.addRow(self.widget('type_lang_layout')) groupbox = QtWidgets.QGroupBox('Object resource', self, objectName='object_resource_widget') groupbox.setLayout(formlayout) self.addWidget(groupbox) ''' ############################################# # CONFIRMATION BOX ################################# confirmation = QtWidgets.QDialogButtonBox( QtCore.Qt.Horizontal, self, objectName='confirmation_widget') confirmation.addButton(QtWidgets.QDialogButtonBox.Save) confirmation.addButton(QtWidgets.QDialogButtonBox.Cancel) confirmation.setContentsMargins(10, 0, 10, 10) if not assertion: confirmation.button( QtWidgets.QDialogButtonBox.Save).setEnabled(False) self.addWidget(confirmation) connect(confirmation.accepted, self.accept) connect(confirmation.rejected, self.reject) formlayout = QtWidgets.QFormLayout() formlayout.addRow(self.widget('property_combobox_label'), self.widget('property_switch')) formlayout.addRow(self.widget('valueTextArea')) formlayout.addRow(self.widget('type_combobox_label'), self.widget('type_switch')) formlayout.addRow(self.widget('lang_combobox_label'), self.widget('lang_switch')) formlayout.addRow(self.widget('confirmation_widget')) self.setLayout(formlayout) self.setMinimumSize(740, 380) self.setWindowTitle('Annotation assertion builder <{}>'.format( str(iri))) self.redraw()