class ConstraintNodeKeyDlg(QDialog, Ui_ConstraintNodeKeyDlg): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super(ConstraintNodeKeyDlg, self).__init__(parent) self.setupUi(self) self.parent = parent self.schemaModel = self.parent.schemaModel self.helper = Helper() self.initUi() def initUi(self, ): aList = sorted(self.schemaModel.instanceList("Label")) self.cbLabel.addItem("") for indexName in aList: self.cbLabel.addItem(indexName) aList = sorted(self.schemaModel.instanceList("Property")) self.cbProperty.addItem("") for indexName in aList: self.cbProperty.addItem(indexName) def validate(self, ): # must enter or select a label if self.helper.NoTextValueError(self.cbLabel.currentText(), "You must enter or select a Label"): return False # must add at least one property to the list if self.helper.NoTextValueError( self.lstProperty, "You must have at least one property in the list."): return False return True def apply(self, ): """ Generate and run the create constraint statement """ propList = [ "p." + str(self.lstProperty.item(i).text()) for i in range(self.lstProperty.count()) ] propComma = ",".join(x for x in propList) label = self.cbLabel.currentText() self.cypherCommand = None ''' CREATE CONSTRAINT ON (p:Person) ASSERT (p.firstname, p.surname) IS NODE KEY ''' self.cypherCommand = "CREATE CONSTRAINT ON (p:{}) ASSERT ({}) IS NODE KEY".format( label, str(propComma)) if self.cypherCommand: QApplication.setOverrideCursor(Qt.WaitCursor) rc, msg = self.schemaModel.createConstraint(self.cypherCommand) QApplication.restoreOverrideCursor() self.helper.displayErrMsg("Create Node KeyConstraint", msg) else: self.helper.displayErrMsg( "Create Node Key Constraint", "Error Generating Node Key Constraint Statement.") @pyqtSlot() def on_buttonBox_accepted(self): """ Slot documentation goes here. """ if self.validate(): self.apply() QDialog.accept(self) @pyqtSlot() def on_buttonBox_rejected(self): """ Slot documentation goes here. """ QDialog.reject(self) @pyqtSlot() def on_pbAddToList_clicked(self): """ Get the property name in the combo box and add it to the list """ if len( self.lstProperty.findItems(self.cbProperty.currentText(), Qt.MatchFixedString)) == 0: self.lstProperty.addItem(self.cbProperty.currentText()) else: self.helper.displayErrMsg( "Create Node Key Constraint", "You can't use the same property twice.") @pyqtSlot() def on_pbRemoveList_clicked(self): """ Remove the selected property from the list """ self.lstProperty.takeItem(self.lstProperty.currentRow()) @pyqtSlot() def on_btnMoveUp_clicked(self): """ User clicks the Move Up button, move the selected property up on in the list """ self.helper.moveListItemUp(self.lstProperty) @pyqtSlot() def on_btnMoveDown_clicked(self): """ User clicks the Move Down button, move the selected property down on in the list """ self.helper.moveListItemDown(self.lstProperty)
class FrmPropList(QFrame, Ui_Frame): """ This frame provides a UI for selecting a set of properties from all properties and setting their order """ def __init__(self, parent=None, curVal=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super(FrmPropList, self).__init__(parent) self.setupUi(self) self.helper = Helper() self.curVal = curVal def addProps(self, propList): # load the list of all properties in the template for prop in propList: if len(prop) > 0: self.gridAllProps.addItem(prop) # load the list of selected properties if not self.curVal is None: selectedPropList = self.curVal.split(", ") for selectedProp in selectedPropList: if selectedProp in [ str(self.gridAllProps.item(i).text()) for i in range(self.gridAllProps.count()) ]: self.gridSelectedProps.addItem(selectedProp) self.setPropListDisplay() def genPropList(self, ): ''' generate a comma seperated list of properties from the selected properties list view ''' propComma = "" propList = [ str(self.gridSelectedProps.item(i).text()) for i in range(self.gridSelectedProps.count()) ] propComma = ", ".join(x for x in propList) return propComma def setPropListDisplay(self, ): ''' set the label with the generated property list ''' self.lblPropList.setText(self.genPropList()) @pyqtSlot() def on_btnAdd_clicked(self): """ User clicks >> button to add a prop to the prop list """ index = self.gridAllProps.currentRow() if (index is not None and index > -1): selProperty = self.gridAllProps.item(index).text() if selProperty in [ str(self.gridSelectedProps.item(i).text()) for i in range(self.gridSelectedProps.count()) ]: self.helper.displayErrMsg( "Add Property", "Property {} can only be selected once".format( selProperty)) else: self.gridSelectedProps.addItem( self.gridAllProps.item(index).text()) self.setPropListDisplay() else: self.helper.displayErrMsg("Add Property", "You must select a property to add.") @pyqtSlot() def on_btnRemove_clicked(self): """ user clicks the << button to remove a prop from the proplist """ self.gridSelectedProps.takeItem(self.gridSelectedProps.currentRow()) self.setPropListDisplay() @pyqtSlot() def on_btnMoveUp_clicked(self): """ User clicks the Move Up button, move the selected property up on in the list """ self.helper.moveListItemUp(self.gridSelectedProps) self.setPropListDisplay() @pyqtSlot() def on_btnMoveDown_clicked(self): """ User clicks the Move Down button, move the selected property up on in the list """ self.helper.moveListItemDown(self.gridSelectedProps) self.setPropListDisplay()
class CreateIndexDlg(QDialog, Ui_CreateIndexDlg): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super(CreateIndexDlg, self).__init__(parent) self.helper = Helper() self.setupUi(self) self.parent = parent self.schemaModel = self.parent.schemaModel self.initUi() def initUi(self, ): aList = self.schemaModel.instanceList("Label") self.cbLabel.addItem("") aSortedList = sorted(aList) for indexName in aSortedList: self.cbLabel.addItem(indexName) aList = sorted(self.schemaModel.instanceList("Property")) self.cbProperty.addItem("") for indexName in aList: self.cbProperty.addItem(indexName) return def validate(self, ): # must enter or select a label if self.helper.NoTextValueError(self.cbLabel.currentText(), "You must enter or select a Label"): return False # must add at least one property to the list if self.helper.NoTextValueError(self.lstProperty, "You must have at least one property in the list."): return False return True def apply(self, ): """ Generate the create index statement """ propList = [str(self.lstProperty.item(i).text()) for i in range(self.lstProperty.count())] propComma = ",".join(x for x in propList) self.cypherCommand = "CREATE INDEX ON :{}({})".format(self.cbLabel.currentText(), str(propComma)) if self.cypherCommand: QApplication.setOverrideCursor(Qt.WaitCursor) rc, msg = self.schemaModel.createIndex(self.cypherCommand) QApplication.restoreOverrideCursor() self.helper.displayErrMsg("Create Index", msg) else: self.helper.displayErrMsg("Create Index", "Error Generating Index Statement.") @pyqtSlot() def on_buttonBox_accepted(self): """ Slot documentation goes here. """ if self.validate(): self.apply() QDialog.accept(self) @pyqtSlot() def on_buttonBox_rejected(self): """ Slot documentation goes here. """ QDialog.reject(self) @pyqtSlot() def on_pbAddToList_clicked(self): """ Get the property name in the combo box and add it to the list """ self.lstProperty.addItem(self.cbProperty.currentText()) @pyqtSlot() def on_pbRemoveList_clicked(self): """ Remove the selected property from the list """ self.lstProperty.takeItem(self.lstProperty.currentRow()) @pyqtSlot() def on_btnMoveUp_clicked(self): """ User clicks the Move Up button, move the selected property up on in the list """ self.helper.moveListItemUp(self.lstProperty) @pyqtSlot() def on_btnMoveDown_clicked(self): """ User clicks the Move Down button, move the selected property up on in the list """ self.helper.moveListItemDown(self.lstProperty)