def buildFacetNodeMenu(self, diagram, node): """ Build and return a QMenu instance for facet nodes. :type diagram: Diagram :type node: FacetNode :rtype: QMenu """ menu = self.buildGenericNodeMenu(diagram, node) menu.insertMenu(self.session.action('node_properties'), self.session.menu('facet')) menu.insertSeparator(self.session.action('node_properties')) ############################################# # BEGIN CONSTRAIN FACET SWITCH ################################# f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.type() is Item.DatatypeRestrictionNode f3 = lambda x: x.type() is Item.ValueDomainNode facet = node.facet admissible = [x for x in Facet] restriction = first(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) for action in self.session.action('facet').actions(): action.setChecked(action.data() is facet) action.setVisible(action.data() in admissible) ############################################# # END CONSTRAIN FACET SWITCH ################################# return menu
def buildFacetNodeMenu(self, diagram, node): """ Build and return a QMenu instance for facet nodes. :type diagram: Diagram :type node: FacetNode :rtype: QMenu """ menu = self.buildGenericNodeMenu(diagram, node) menu.insertMenu(self.session.action('node_properties'), self.session.menu('facet')) menu.insertSeparator(self.session.action('node_properties')) ############################################# # BEGIN CONSTRAIN FACET SWITCH ################################# f1 = lambda x: x.type() is Item.InputEdge f2 = lambda x: x.type() is Item.DatatypeRestrictionNode f3 = lambda x: x.type() is Item.ValueDomainNode facet = node.facet admissible = [x for x in Facet] restriction = first(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) for action in self.session.action('facet').actions(): action.setChecked(action.data() is facet) action.setVisible(action.data() in admissible) ############################################# # END CONSTRAIN FACET SWITCH ################################# return menu
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')
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')