def buildValueDomainNodeMenu(self, diagram, node): """ Build and return a QMenu instance for value domain nodes. :type diagram: Diagram :type node: ValueDomainNode :rtype: QMenu """ menu = self.buildGenericNodeMenu(diagram, node) # CREATE A NEW MENU FOR DATATYPE SELECTION NOT TO OVERWRITE THE PRE-DEFINED ONE self.customMenu['datatype'] = QtWidgets.QMenu('Select type') self.customMenu['datatype'].setIcon( self.session.menu('datatype').icon()) # CREATE NEW CUSTOM ACTION SET FOR THE DATATYPES SUPPORTED BY THE CURRENT PROFILE self.customAction['datatype'] = [] for datatype in sorted(Datatype.forProfile( self.project.profile.type()), key=attrgetter('value')): action = QtWidgets.QAction(self.session) action.setCheckable(True) action.setData(datatype) action.setText(datatype.value) connect(action.triggered, self.session.doSetDatatype) self.customAction['datatype'].append(action) self.customMenu['datatype'].addAction(action) # INSERT THE CUSTOM MENU IN THE NODE CONTEXTUAL MENU menu.insertMenu(self.session.action('node_properties'), self.customMenu['datatype']) menu.insertSeparator(self.session.action('node_properties')) for action in self.customAction['datatype']: action.setChecked(node.datatype == action.data()) return menu
def buildValueDomainNodeMenu(self, diagram, node): """ Build and return a QMenu instance for value domain nodes. :type diagram: Diagram :type node: ValueDomainNode :rtype: QMenu """ menu = self.buildGenericNodeMenu(diagram, node) # CREATE A NEW MENU FOR DATATYPE SELECTION NOT TO OVERWRITE THE PRE-DEFINED ONE self.customMenu['datatype'] = QtWidgets.QMenu('Select type') self.customMenu['datatype'].setIcon(self.session.menu('datatype').icon()) # CREATE NEW CUSTOM ACTION SET FOR THE DATATYPES SUPPORTED BY THE CURRENT PROFILE self.customAction['datatype'] = [] for datatype in sorted(Datatype.forProfile(self.project.profile.type()), key=attrgetter('value')): action = QtWidgets.QAction(self.session) action.setCheckable(True) action.setData(datatype) action.setText(datatype.value) connect(action.triggered, self.session.doSetDatatype) self.customAction['datatype'].append(action) self.customMenu['datatype'].addAction(action) # INSERT THE CUSTOM MENU IN THE NODE CONTEXTUAL MENU menu.insertMenu(self.session.action('node_properties'), self.customMenu['datatype']) menu.insertSeparator(self.session.action('node_properties')) for action in self.customAction['datatype']: action.setChecked(node.datatype == action.data()) return menu
def setText(self, text): """ Set the label text. :type text: str """ datatype = Datatype.valueOf(text) or Datatype.string self.label.setText(datatype.value) self.updateNode()
def setText(self, text): """ Set the label text. :type text: str """ datatype = Datatype.forValue(text) or Datatype.string self.label.setText(datatype.value) self.updateNode()
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 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 __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)
def __call__(self, node): if node.type() is Item.ValueDomainNode: if node.datatype not in Datatype.forProfile(OWLProfile.OWL2QL): raise ProfileError( 'Datatype {} is forbidden in OWL 2 QL'.format( node.datatype.value))
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)
def datatype(self): """ Returns the datatype associated with this node. :rtype: Datatype """ return Datatype.valueOf(self.text())
def __call__(self, node): if node.type() is Item.ValueDomainNode: if node.datatype not in Datatype.forProfile(OWLProfile.OWL2QL): raise ProfileError('Datatype {} is forbidden in OWL 2 QL'.format(node.datatype.value))
def datatype(self): """ Returns the datatype associated with this node. :rtype: Datatype """ return Datatype.forValue(self.text())