def setTableContent(self): styles = self.catalog.get_styles() workspaces = self.catalog.get_workspaces() self.table.setRowCount(len(self.layers)) catlayers = [lyr.name for lyr in self.catalog.get_layers()] for idx, layer in enumerate(self.layers): lyritem = QtGui.QTableWidgetItem(layer.name()) lyritem.setToolTip(layer.name()) lyritem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) lyritem.setCheckState(QtCore.Qt.Unchecked) self.table.setItem(idx, self.getColumn(self.lyr), lyritem) nameBox = GSNameWidget(name=xmlNameFixUp(layer.name()), nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=catlayers, unique=False) self.table.setCellWidget(idx, self.getColumn(self.name), nameBox) nameBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) styleNames = ["[Use QGIS Style]"] self.nameBoxes.append(nameBox) overwriteBox = QtGui.QCheckBox() overwriteBox.setEnabled(False) overwriteBox.setToolTip("Overwrite existing layer") self.table.setCellWidget(idx, self.getColumn(self.ow), overwriteBox) nameBox.nameValidityChanged.connect(self.validateNames) nameBox.overwritingChanged[bool].connect(overwriteBox.setChecked) overwriteBox.setChecked( nameBox.overwritingName()) # initial update workspaceBox = QtGui.QComboBox() workspaceBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) try: defaultWorkspace = self.catalog.get_default_workspace() defaultWorkspace.fetch() defaultName = defaultWorkspace.dom.find('name').text except: defaultName = None workspaceNames = [w.name for w in workspaces] workspaceBox.addItems(workspaceNames) if defaultName is not None: workspaceBox.setCurrentIndex(workspaceNames.index(defaultName)) self.table.setCellWidget(idx, self.getColumn(self.wrksp), workspaceBox) stylesBox = QtGui.QComboBox() styleNames += [s.name for s in styles] stylesBox.addItems(styleNames) self.table.setCellWidget(idx, self.getColumn(self.style), stylesBox)
def setTableContent(self): styles = self.catalog.get_styles() workspaces = self.catalog.get_workspaces() self.table.setRowCount(len(self.layers)) catlayers = [lyr.name for lyr in self.catalog.get_layers()] for idx, layer in enumerate(self.layers): lyritem = QtGui.QTableWidgetItem(layer.name()) lyritem.setToolTip(layer.name()) lyritem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) lyritem.setCheckState(QtCore.Qt.Unchecked) self.table.setItem(idx, self.getColumn(self.lyr), lyritem) nameBox = GSNameWidget( name=xmlNameFixUp(layer.name()), nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=catlayers, unique=False) self.table.setCellWidget(idx, self.getColumn(self.name), nameBox) nameBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) styleNames = ["[Use QGIS Style]"] self.nameBoxes.append(nameBox) overwriteBox = QtGui.QCheckBox() overwriteBox.setEnabled(False) overwriteBox.setToolTip("Overwrite existing layer") self.table.setCellWidget(idx, self.getColumn(self.ow), overwriteBox) nameBox.nameValidityChanged.connect(self.validateNames) nameBox.overwritingChanged[bool].connect(overwriteBox.setChecked) overwriteBox.setChecked(nameBox.overwritingName()) # initial update workspaceBox = QtGui.QComboBox() workspaceBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) try: defaultWorkspace = self.catalog.get_default_workspace() defaultWorkspace.fetch() defaultName = defaultWorkspace.dom.find('name').text except: defaultName = None workspaceNames = [w.name for w in workspaces] workspaceBox.addItems(workspaceNames) if defaultName is not None: workspaceBox.setCurrentIndex(workspaceNames.index(defaultName)) self.table.setCellWidget(idx, self.getColumn(self.wrksp), workspaceBox) stylesBox = QtGui.QComboBox() styleNames += [s.name for s in styles] stylesBox.addItems(styleNames) self.table.setCellWidget(idx, self.getColumn(self.style), stylesBox)
def initGui(self): self.setWindowTitle('New workspace') verticalLayout = QtGui.QVBoxLayout() horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Workspace name') nameLabel.setMinimumWidth(150) self.nameBox = GSNameWidget(namemsg='', name='workspace', nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.workspaces, unique=True, maxlength=10) self.nameBox.setMinimumWidth(250) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) uriLabel = QtGui.QLabel('URI') uriLabel.setMinimumWidth(150) self.uriBox = QtGui.QLineEdit() self.uriBox.setText('') self.uriBox.setPlaceholderText('Required') self.uriBox.setMinimumWidth(250) horizontalLayout.addWidget(uriLabel) horizontalLayout.addWidget(self.uriBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) self.spacer = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) layout.addItem(self.spacer) self.buttonBox = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) self.okButton = self.buttonBox.button(QtGui.QDialogButtonBox.Ok) layout.addWidget(self.buttonBox) self.setLayout(layout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.nameBox.nameValidityChanged.connect(self.updateOkButton) self.uriBox.textChanged.connect(self.updateOkButton) self.updateOkButton()
def __init__(self, boxtitle='', boxmsg='', name='', namemsg='', nameregex='', nameregexmsg='', names=None, unique=False, maxlength=0, parent=None): super(GSNameDialog, self).__init__(parent) self.boxtitle = boxtitle self.boxmsg = boxmsg self.nameBox = GSNameWidget( name=name, namemsg=namemsg, nameregex=nameregex, nameregexmsg=nameregexmsg, names=names, unique=unique, maxlength=maxlength ) self.initGui()
def testGSNameWidgetInit(self): nw = GSNameWidget( namemsg='Sample is generated from PostgreSQL connection name', name=xmlNameFixUp('My PG connection'), nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=['name_one', 'name_two', 'name_three'], unique=False, maxlength=10) self.assertEqual(nw.nameBox.count(), 4) # name is prepended to list
def initGui(self): self.setWindowTitle('New workspace') verticalLayout = QVBoxLayout() horizontalLayout = QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) nameLabel = QLabel('Workspace name') nameLabel.setMinimumWidth(150) self.nameBox = GSNameWidget( namemsg='', name='workspace', nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.workspaces, unique=True, maxlength=10) self.nameBox.setMinimumWidth(250) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) uriLabel = QLabel('URI') uriLabel.setMinimumWidth(150) self.uriBox = QLineEdit() self.uriBox.setText('') self.uriBox.setPlaceholderText('Required') self.uriBox.setMinimumWidth(250) horizontalLayout.addWidget(uriLabel) horizontalLayout.addWidget(self.uriBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QGroupBox() self.groupBox.setLayout(verticalLayout) layout = QVBoxLayout() layout.addWidget(self.groupBox) self.spacer = QSpacerItem(20,20, QSizePolicy.Minimum, QSizePolicy.Expanding) layout.addItem(self.spacer) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) layout.addWidget(self.buttonBox) self.setLayout(layout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.nameBox.nameValidityChanged.connect(self.updateOkButton) self.uriBox.textChanged.connect(self.updateOkButton) self.updateOkButton()
def testGSNameWidgetValidName(self): nw = GSNameWidget(name='my_pg_connection') self.assertTrue(nw.isValid()) self.assertIsNotNone(nw.definedName()) self.assertEqual(nw.definedName(), 'my_pg_connection') nw.validateName('my_pg_connection') self.assertTrue(nw.isValid()) nw.highlightName() self.assertEqual(nw.nameBox.lineEdit().styleSheet(), '') validnames = ['name_8291', 'name.with.dots', 'name:with::colons', '_name_with_underscore'] # XML valid name nw.setNameRegex(xmlNameRegex(), xmlNameRegexMsg()) self.assertTrue(nw.isValid()) for vname in validnames: nw.setName(vname) self.assertTrue(nw.isValid()) # empty name regex nw.setName('') nw.setNameRegex(xmlNameEmptyRegex(), xmlNameRegexMsg()) self.assertTrue(nw.isValid()) nw.setAllowEmpty(True) self.assertTrue(nw.isValid()) self.assertEqual(nw.definedName(), '') for vname in validnames: nw.setName(vname) self.assertTrue(nw.isValid())
def testGSNameWidgetNames(self): nw = GSNameWidget(name='name_one', names=['name_one', 'name_two', 'name_three'], unique=True) self.assertFalse(nw.isValid()) nw.setNames(['name_four', 'name_five']) self.assertTrue(nw.isValid()) self.assertEqual(nw.nameBox.count(), 3) # 'name_one' prepended to list self.assertEqual(nw.definedName(), 'name_one') nw.setName('name_four') self.assertFalse(nw.isValid()) self.assertIsNone(nw.definedName()) nw.setName('name') nw.setNames(['name_one', 'name_two', 'name_three']) self.assertTrue(nw.isValid()) self.assertEqual(nw.nameBox.count(), 4) # 'name' is prepended to list self.assertEqual(nw.definedName(), 'name') nw.setNames([]) self.assertTrue(nw.isValid()) self.assertEqual(nw.nameBox.count(), 1) # 'name' is prepended to list self.assertEqual(nw.definedName(), 'name')
def testGSNameWidgetMaxLenName(self): nw = GSNameWidget(name='my_pg_connection', maxlength=10) self.assertFalse(nw.isValid()) nw.setName('my_pg_conn') self.assertTrue(nw.isValid()) nw.setMaxLength(5) self.assertFalse(nw.isValid()) nw.setMaxLength(10) self.assertTrue(nw.isValid())
def initGui(self): verticalLayout = QtGui.QVBoxLayout() buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Close) self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close) self.setWindowTitle('Publish style') horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) catalogLabel = QtGui.QLabel('Catalog') catalogLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.catalogBox = QtGui.QComboBox() self.catalogBox.addItems(self.catalognames) self.catalogBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) horizontalLayout.addWidget(catalogLabel) horizontalLayout.addWidget(self.catalogBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Name') nameLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.nameBox = GSNameWidget(namemsg='', name=xmlNameFixUp(self.layername), nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=[], unique=False) self.nameBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle("") self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.catalogBox.currentIndexChanged[str].connect( self.updateCatalogStyles) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.updateCatalogStyles(self.catalogBox.currentText()) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) self.resize(400, 200)
class DefineWorkspaceDialog(QtGui.QDialog): def __init__(self, workspaces=None, parent=None): super(DefineWorkspaceDialog, self).__init__(parent) self.workspaces = workspaces if workspaces is not None else [] self.uri = None self.name = None self.initGui() def initGui(self): self.setWindowTitle('New workspace') verticalLayout = QtGui.QVBoxLayout() horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Workspace name') nameLabel.setMinimumWidth(150) self.nameBox = GSNameWidget(namemsg='', name='workspace', nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.workspaces, unique=True, maxlength=10) self.nameBox.setMinimumWidth(250) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) uriLabel = QtGui.QLabel('URI') uriLabel.setMinimumWidth(150) self.uriBox = QtGui.QLineEdit() self.uriBox.setText('') self.uriBox.setPlaceholderText('Required') self.uriBox.setMinimumWidth(250) horizontalLayout.addWidget(uriLabel) horizontalLayout.addWidget(self.uriBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) self.spacer = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) layout.addItem(self.spacer) self.buttonBox = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) self.okButton = self.buttonBox.button(QtGui.QDialogButtonBox.Ok) layout.addWidget(self.buttonBox) self.setLayout(layout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.nameBox.nameValidityChanged.connect(self.updateOkButton) self.uriBox.textChanged.connect(self.updateOkButton) self.updateOkButton() def getWorkspace(self): return self.workspace def updateOkButton(self): ok = self.nameBox.isValid() and self.uriBox.text() != '' self.okButton.setEnabled(ok) def okPressed(self): self.uri = unicode(self.uriBox.text()) self.name = unicode(self.nameBox.definedName()) self.close() def cancelPressed(self): self.uri = None self.name = None self.close()
def testGSNameWidgetNames(self): nw = GSNameWidget( name='name_one', names=['name_one', 'name_two', 'name_three'], unique=True) self.assertFalse(nw.isValid()) nw.setNames(['name_four', 'name_five']) self.assertTrue(nw.isValid()) self.assertEqual(nw.nameBox.count(), 3) # 'name_one' prepended to list self.assertEqual(nw.definedName(), 'name_one') nw.setName('name_four') self.assertFalse(nw.isValid()) self.assertIsNone(nw.definedName()) nw.setName('name') nw.setNames(['name_one', 'name_two', 'name_three']) self.assertTrue(nw.isValid()) self.assertEqual(nw.nameBox.count(), 4) # 'name' is prepended to list self.assertEqual(nw.definedName(), 'name') nw.setNames([]) self.assertTrue(nw.isValid()) self.assertEqual(nw.nameBox.count(), 1) # 'name' is prepended to list self.assertEqual(nw.definedName(), 'name')
class StyleFromLayerDialog(QtGui.QDialog): def __init__(self, styles=None, parent=None): super(StyleFromLayerDialog, self).__init__(parent) self.styles = styles if styles is not None else [] self.layer = None self.name = None self.initGui() def initGui(self): verticalLayout = QtGui.QVBoxLayout() buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Close) self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close) self.setWindowTitle('Create style from layer') horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) layerLabel = QtGui.QLabel('Layer') layerLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.layerBox = QtGui.QComboBox() self.alllayers = [layer.name() for layer in layers.getAllLayers()] self.layerBox.addItems(self.alllayers) self.layerBox.setMinimumWidth(250) horizontalLayout.addWidget(layerLabel) horizontalLayout.addWidget(self.layerBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Name') nameLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) defaultname = '' if len(self.alllayers) > 0: defaultname = xmlNameFixUp(self.alllayers[0]) self.nameBox = GSNameWidget(namemsg='', name=defaultname, nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.styles, unique=False) self.nameBox.setMinimumWidth(250) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle("") self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.layerBox.currentIndexChanged[str].connect(self.updateNameBox) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) self.resize(400, 150) @QtCore.pyqtSlot(str) def updateNameBox(self, name): self.nameBox.setName(xmlNameFixUp(name)) @QtCore.pyqtSlot(bool) def updateButtons(self, overwriting): txt = "Overwrite" if overwriting else "OK" self.okButton.setText(txt) self.okButton.setDefault(not overwriting) self.cancelButton.setDefault(overwriting) def okPressed(self): self.layer = self.layerBox.currentText() self.name = unicode(self.nameBox.definedName()) self.close() def cancelPressed(self): self.layer = None self.name = None self.close()
class GSNameDialog(QtGui.QDialog): def __init__(self, boxtitle='', boxmsg='', name='', namemsg='', nameregex='', nameregexmsg='', names=None, unique=False, maxlength=0, parent=None): super(GSNameDialog, self).__init__(parent) self.boxtitle = boxtitle self.boxmsg = boxmsg self.nameBox = GSNameWidget( name=name, namemsg=namemsg, nameregex=nameregex, nameregexmsg=nameregexmsg, names=names, unique=unique, maxlength=maxlength ) self.initGui() def initGui(self): self.setWindowTitle('Define name') vertlayout = QtGui.QVBoxLayout() self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle(self.boxtitle) self.groupBox.setLayout(vertlayout) if self.boxmsg: self.groupBoxMsg = QtGui.QLabel(self.boxmsg) self.groupBoxMsg.setWordWrap(True) self.groupBox.layout().addWidget(self.groupBoxMsg) self.groupBox.layout().addWidget(self.nameBox) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) self.buttonBox = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) self.okButton = self.buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = self.buttonBox.button(QtGui.QDialogButtonBox.Cancel) layout.addWidget(self.buttonBox) self.setLayout(layout) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) # noinspection PyUnresolvedReferences self.buttonBox.accepted.connect(self.accept) # noinspection PyUnresolvedReferences self.buttonBox.rejected.connect(self.reject) self.setMinimumWidth(240) # respond to intial validation self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) def definedName(self): return self.nameBox.definedName() def overwritingName(self): return self.nameBox.overwritingName() @QtCore.pyqtSlot(bool) def updateButtons(self, overwriting): txt = "Overwrite" if overwriting else "OK" self.okButton.setText(txt) self.okButton.setDefault(not overwriting) self.cancelButton.setDefault(overwriting)
class LayerGroupDialog(QDialog): def __init__(self, catalog, previousgroup = None): self.previousgroup = previousgroup self.catalog = catalog QDialog.__init__(self) self.groups = catalog.get_layergroups() self.groupnames = [group.name for group in self.groups] self.layers = catalog.get_layers() self.layernames = [layer.name for layer in self.layers] self.styles = [style.name for style in catalog.get_styles()] self.setModal(True) self.setupUi() self.group = None def setupUi(self): self.resize(600, 350) self.setWindowTitle("Group definition") self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setSpacing(2) self.verticalLayout.setMargin(6) self.horizontalLayout = QHBoxLayout() # self.horizontalLayout.setSpacing(30) self.horizontalLayout.setMargin(0) self.nameLabel = QLabel("Group name") self.nameLabel.setSizePolicy( QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)) defaultname = "Group" if self.previousgroup: defaultname = self.previousgroup.name self.nameBox = GSNameWidget( namemsg='', name=defaultname, nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.groupnames, unique=False if self.previousgroup else True) if self.previousgroup: self.nameBox.setEnabled(False) self.nameBox.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)) self.horizontalLayout.addWidget(self.nameLabel) self.horizontalLayout.addWidget(self.nameBox) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setSpacing(6) self.horizontalLayout.setMargin(0) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Vertical) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) self.cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel) self.table = QTableWidget() self.table.setColumnCount(2) self.table.setColumnWidth(0,300) self.table.verticalHeader().setVisible(False) self.table.horizontalHeader().setVisible(True) self.table.setHorizontalHeaderLabels(["Layer", "Style"]) self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.selectAllButton = QPushButton() self.selectAllButton.setText("(de)Select all") self.setTableContent() self.buttonBox.addButton(self.selectAllButton, QDialogButtonBox.ActionRole) self.horizontalLayout.addWidget(self.table) self.horizontalLayout.addWidget(self.buttonBox) self.verticalLayout.addLayout(self.horizontalLayout) self.setLayout(self.verticalLayout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.selectAllButton.clicked.connect(self.selectAll) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) def setTableContent(self): self.table.setRowCount(len(self.layernames)) previouslayers = self.previousgroup.layers if self.previousgroup is not None else [] previousstyles = self.previousgroup.styles if self.previousgroup is not None else [] i = 0 for layer, style in zip(previouslayers, previousstyles): item = QCheckBox() item.setText(layer) item.setChecked(True) self.table.setCellWidget(i,0, item) item = QComboBox() item.addItems(self.styles) try: idx = self.styles.index(style) item.setCurrentIndex(idx) except ValueError: pass self.table.setCellWidget(i,1, item) i += 1 for layer in self.layers: if layer.name not in previouslayers: item = QCheckBox() item.setText(layer.name) self.table.setCellWidget(i,0, item) item = QComboBox() item.addItems(self.styles) try: idx = self.styles.index(layer.default_style.name) item.setCurrentIndex(idx) except: pass self.table.setCellWidget(i,1, item) i += 1 @pyqtSlot(bool) def updateButtons(self, overwriting): txt = "Overwrite" if overwriting else "OK" self.okButton.setText(txt) self.okButton.setDefault(not overwriting) self.cancelButton.setDefault(overwriting) def okPressed(self): self.name = str(self.nameBox.definedName()) layers = [] styles = [] for i in range(len(self.layernames)): widget = self.table.cellWidget(i, 0) if widget.isChecked(): layers.append(widget.text()) styleWidget = self.table.cellWidget(i, 1) styles.append(styleWidget.currentText()) if len(self.layernames) == 0: return #TODO show alert if self.previousgroup is not None: self.group = self.previousgroup self.group.dirty.update(layers = layers, styles = styles) else: #TODO compute bounds bbox = None self.group = UnsavedLayerGroup(self.catalog, self.name, layers, styles, bbox, "SINGLE", "", self.name) self.close() def cancelPressed(self): self.group = None self.close() def selectAll(self): checked = False for i in range(len(self.layernames)): widget = self.table.cellWidget(i, 0) if not widget.isChecked(): checked = True break for i in range(len(self.layernames)): widget = self.table.cellWidget(i, 0) widget.setChecked(checked)
class DefineWorkspaceDialog(QDialog): def __init__(self, workspaces=None, parent=None): super(DefineWorkspaceDialog, self).__init__(parent) self.workspaces = workspaces if workspaces is not None else [] self.uri = None self.name = None self.initGui() def initGui(self): self.setWindowTitle('New workspace') verticalLayout = QVBoxLayout() horizontalLayout = QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) nameLabel = QLabel('Workspace name') nameLabel.setMinimumWidth(150) self.nameBox = GSNameWidget( namemsg='', name='workspace', nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.workspaces, unique=True, maxlength=10) self.nameBox.setMinimumWidth(250) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QHBoxLayout() horizontalLayout.setSpacing(30) horizontalLayout.setMargin(0) uriLabel = QLabel('URI') uriLabel.setMinimumWidth(150) self.uriBox = QLineEdit() self.uriBox.setText('') self.uriBox.setPlaceholderText('Required') self.uriBox.setMinimumWidth(250) horizontalLayout.addWidget(uriLabel) horizontalLayout.addWidget(self.uriBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QGroupBox() self.groupBox.setLayout(verticalLayout) layout = QVBoxLayout() layout.addWidget(self.groupBox) self.spacer = QSpacerItem(20,20, QSizePolicy.Minimum, QSizePolicy.Expanding) layout.addItem(self.spacer) self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) layout.addWidget(self.buttonBox) self.setLayout(layout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.nameBox.nameValidityChanged.connect(self.updateOkButton) self.uriBox.textChanged.connect(self.updateOkButton) self.updateOkButton() def getWorkspace(self): return self.workspace def updateOkButton(self): ok = self.nameBox.isValid() and self.uriBox.text() != '' self.okButton.setEnabled(ok) def okPressed(self): self.uri = str(self.uriBox.text()) self.name = str(self.nameBox.definedName()) self.close() def cancelPressed(self): self.uri = None self.name = None self.close()
def initGui(self): verticalLayout = QtGui.QVBoxLayout() buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Close) self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close) self.setWindowTitle('Publish style') horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) catalogLabel = QtGui.QLabel('Catalog') catalogLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.catalogBox = QtGui.QComboBox() self.catalogBox.addItems(self.catalognames) self.catalogBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) horizontalLayout.addWidget(catalogLabel) horizontalLayout.addWidget(self.catalogBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Name') nameLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.nameBox = GSNameWidget( namemsg='', name=xmlNameFixUp(self.layername), nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=[], unique=False) self.nameBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle("") self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.catalogBox.currentIndexChanged[str].connect(self.updateCatalogStyles) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.updateCatalogStyles(self.catalogBox.currentText()) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) self.resize(400,200)
def setupUi(self): self.resize(600, 350) self.setWindowTitle("Group definition") self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setSpacing(2) self.verticalLayout.setMargin(6) self.horizontalLayout = QHBoxLayout() # self.horizontalLayout.setSpacing(30) self.horizontalLayout.setMargin(0) self.nameLabel = QLabel("Group name") self.nameLabel.setSizePolicy( QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)) defaultname = "Group" if self.previousgroup: defaultname = self.previousgroup.name self.nameBox = GSNameWidget( namemsg='', name=defaultname, nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.groupnames, unique=False if self.previousgroup else True) if self.previousgroup: self.nameBox.setEnabled(False) self.nameBox.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)) self.horizontalLayout.addWidget(self.nameLabel) self.horizontalLayout.addWidget(self.nameBox) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setSpacing(6) self.horizontalLayout.setMargin(0) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Vertical) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) self.cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel) self.table = QTableWidget() self.table.setColumnCount(2) self.table.setColumnWidth(0, 300) self.table.verticalHeader().setVisible(False) self.table.horizontalHeader().setVisible(True) self.table.setHorizontalHeaderLabels(["Layer", "Style"]) self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.selectAllButton = QPushButton() self.selectAllButton.setText("(de)Select all") self.setTableContent() self.buttonBox.addButton(self.selectAllButton, QDialogButtonBox.ActionRole) self.horizontalLayout.addWidget(self.table) self.horizontalLayout.addWidget(self.buttonBox) self.verticalLayout.addLayout(self.horizontalLayout) self.setLayout(self.verticalLayout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.selectAllButton.clicked.connect(self.selectAll) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName())
class LayerGroupDialog(QDialog): def __init__(self, catalog, previousgroup=None): self.previousgroup = previousgroup self.catalog = catalog QDialog.__init__(self) self.groups = catalog.get_layergroups() self.groupnames = [group.name for group in self.groups] self.layers = catalog.get_layers() self.layernames = [layer.name for layer in self.layers] self.styles = [style.name for style in catalog.get_styles()] self.setModal(True) self.setupUi() self.group = None def setupUi(self): self.resize(600, 350) self.setWindowTitle("Group definition") self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setSpacing(2) self.verticalLayout.setMargin(6) self.horizontalLayout = QHBoxLayout() # self.horizontalLayout.setSpacing(30) self.horizontalLayout.setMargin(0) self.nameLabel = QLabel("Group name") self.nameLabel.setSizePolicy( QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)) defaultname = "Group" if self.previousgroup: defaultname = self.previousgroup.name self.nameBox = GSNameWidget( namemsg='', name=defaultname, nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.groupnames, unique=False if self.previousgroup else True) if self.previousgroup: self.nameBox.setEnabled(False) self.nameBox.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)) self.horizontalLayout.addWidget(self.nameLabel) self.horizontalLayout.addWidget(self.nameBox) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setSpacing(6) self.horizontalLayout.setMargin(0) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Vertical) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) self.cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel) self.table = QTableWidget() self.table.setColumnCount(2) self.table.setColumnWidth(0, 300) self.table.verticalHeader().setVisible(False) self.table.horizontalHeader().setVisible(True) self.table.setHorizontalHeaderLabels(["Layer", "Style"]) self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.selectAllButton = QPushButton() self.selectAllButton.setText("(de)Select all") self.setTableContent() self.buttonBox.addButton(self.selectAllButton, QDialogButtonBox.ActionRole) self.horizontalLayout.addWidget(self.table) self.horizontalLayout.addWidget(self.buttonBox) self.verticalLayout.addLayout(self.horizontalLayout) self.setLayout(self.verticalLayout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.selectAllButton.clicked.connect(self.selectAll) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) def setTableContent(self): self.table.setRowCount(len(self.layernames)) previouslayers = self.previousgroup.layers if self.previousgroup is not None else [] previousstyles = self.previousgroup.styles if self.previousgroup is not None else [] i = 0 for layer, style in zip(previouslayers, previousstyles): item = QCheckBox() item.setText(layer) item.setChecked(True) self.table.setCellWidget(i, 0, item) item = QComboBox() item.addItems(self.styles) try: idx = self.styles.index(style) item.setCurrentIndex(idx) except ValueError: pass self.table.setCellWidget(i, 1, item) i += 1 for layer in self.layers: if layer.name not in previouslayers: item = QCheckBox() item.setText(layer.name) self.table.setCellWidget(i, 0, item) item = QComboBox() item.addItems(self.styles) try: idx = self.styles.index(layer.default_style.name) item.setCurrentIndex(idx) except: pass self.table.setCellWidget(i, 1, item) i += 1 @pyqtSlot(bool) def updateButtons(self, overwriting): txt = "Overwrite" if overwriting else "OK" self.okButton.setText(txt) self.okButton.setDefault(not overwriting) self.cancelButton.setDefault(overwriting) def okPressed(self): self.name = str(self.nameBox.definedName()) layers = [] styles = [] for i in range(len(self.layernames)): widget = self.table.cellWidget(i, 0) if widget.isChecked(): layers.append(widget.text()) styleWidget = self.table.cellWidget(i, 1) styles.append(styleWidget.currentText()) if len(self.layernames) == 0: return #TODO show alert if self.previousgroup is not None: self.group = self.previousgroup self.group.dirty.update(layers=layers, styles=styles) else: #TODO compute bounds bbox = None self.group = UnsavedLayerGroup(self.catalog, self.name, layers, styles, bbox, "SINGLE", "", self.name) self.close() def cancelPressed(self): self.group = None self.close() def selectAll(self): checked = False for i in range(len(self.layernames)): widget = self.table.cellWidget(i, 0) if not widget.isChecked(): checked = True break for i in range(len(self.layernames)): widget = self.table.cellWidget(i, 0) widget.setChecked(checked)
def initGui(self): verticalLayout = QtGui.QVBoxLayout() buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Close) self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close) self.setWindowTitle('Create style from layer') horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) layerLabel = QtGui.QLabel('Layer') layerLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.layerBox = QtGui.QComboBox() self.alllayers = [layer.name() for layer in layers.getAllLayers()] self.layerBox.addItems(self.alllayers) self.layerBox.setMinimumWidth(250) horizontalLayout.addWidget(layerLabel) horizontalLayout.addWidget(self.layerBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Name') nameLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) defaultname = '' if len(self.alllayers) > 0: defaultname = xmlNameFixUp(self.alllayers[0]) self.nameBox = GSNameWidget( namemsg='', name=defaultname, nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.styles, unique=False) self.nameBox.setMinimumWidth(250) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle("") self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.layerBox.currentIndexChanged[str].connect(self.updateNameBox) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) self.resize(400,150)
def testGSNameWidgetInvalidName(self): # base invalid name is empty nw = GSNameWidget(name='') self.assertFalse(nw.isValid()) nw.validateName('') self.assertFalse(nw.isValid()) nw.highlightName() self.assertNotEqual(nw.nameBox.lineEdit().styleSheet(), '') invalidnames = ['xMl_name', 'name with spaces', '9starts_with_number', ':starts_with_punctuation'] # XML invalid name nw.setNameRegex(xmlNameRegex(), xmlNameRegexMsg()) self.assertFalse(nw.isValid()) self.assertIsNone(nw.definedName()) for ivname in invalidnames: nw.setName(ivname) self.assertFalse(nw.isValid()) # empty name regex nw.setName('') nw.setNameRegex(xmlNameEmptyRegex(), xmlNameRegexMsg()) self.assertTrue(nw.isValid()) self.assertEqual(nw.definedName(), '') for ivname in invalidnames: nw.setName(ivname) self.assertFalse(nw.isValid()) # custom regex invalid name nw.setNameRegex(r'^(?!XML|\d|\W)[a-z](\S(?!::))*', 'regex message') nw.setName('my::name') self.assertFalse(nw.isValid())
class PublishStyleDialog(QtGui.QDialog): def __init__(self, catalogs, layername, parent = None): super(PublishStyleDialog, self).__init__(parent) self.catalogs = catalogs self.catalognames = catalogs.keys() self.layername = layername self.catalog = None self.name = None self.initGui() def initGui(self): verticalLayout = QtGui.QVBoxLayout() buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Close) self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close) self.setWindowTitle('Publish style') horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) catalogLabel = QtGui.QLabel('Catalog') catalogLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.catalogBox = QtGui.QComboBox() self.catalogBox.addItems(self.catalognames) self.catalogBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) horizontalLayout.addWidget(catalogLabel) horizontalLayout.addWidget(self.catalogBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Name') nameLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.nameBox = GSNameWidget( namemsg='', name=xmlNameFixUp(self.layername), nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=[], unique=False) self.nameBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle("") self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.catalogBox.currentIndexChanged[str].connect(self.updateCatalogStyles) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.updateCatalogStyles(self.catalogBox.currentText()) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) self.resize(400,200) @QtCore.pyqtSlot(bool) def updateButtons(self, overwriting): txt = "Overwrite" if overwriting else "OK" self.okButton.setText(txt) self.okButton.setDefault(not overwriting) self.cancelButton.setDefault(overwriting) @QtCore.pyqtSlot(str) def updateCatalogStyles(self, catname): catalog = self.catalogs[catname] styles = [style.name for style in catalog.get_styles()] self.nameBox.setNames(styles) def okPressed(self): self.name = unicode(self.nameBox.definedName()) self.catalog = unicode(self.catalogBox.currentText()) self.close() def cancelPressed(self): self.catalog = None self.name = None self.close()
def testGSNameWidgetUniqueName(self): nw = GSNameWidget( name='my_pg_connection', names=['name_one', 'name_two', 'name_three'], unique=False) self.assertTrue(nw.isValid()) nw.setName('name_one') self.assertTrue(nw.isValid()) self.assertTrue(nw.overwritingName()) nw.setUnique(True) self.assertFalse(nw.isValid()) self.assertFalse(nw.overwritingName()) nw.setUnique(False) self.assertTrue(nw.isValid()) self.assertTrue(nw.overwritingName())
def testGSNameWidgetValidName(self): nw = GSNameWidget(name='my_pg_connection') self.assertTrue(nw.isValid()) self.assertIsNotNone(nw.definedName()) self.assertEqual(nw.definedName(), 'my_pg_connection') nw.validateName('my_pg_connection') self.assertTrue(nw.isValid()) nw.highlightName() self.assertEqual(nw.nameBox.lineEdit().styleSheet(), '') validnames = [ 'name_8291', 'name.with.dots', 'name:with::colons', '_name_with_underscore' ] # XML valid name nw.setNameRegex(xmlNameRegex(), xmlNameRegexMsg()) self.assertTrue(nw.isValid()) for vname in validnames: nw.setName(vname) self.assertTrue(nw.isValid()) # empty name regex nw.setName('') nw.setNameRegex(xmlNameEmptyRegex(), xmlNameRegexMsg()) self.assertTrue(nw.isValid()) nw.setAllowEmpty(True) self.assertTrue(nw.isValid()) self.assertEqual(nw.definedName(), '') for vname in validnames: nw.setName(vname) self.assertTrue(nw.isValid())
def testGSNameWidgetMaxLenName(self): nw = GSNameWidget( name='my_pg_connection', maxlength=10) self.assertFalse(nw.isValid()) nw.setName('my_pg_conn') self.assertTrue(nw.isValid()) nw.setMaxLength(5) self.assertFalse(nw.isValid()) nw.setMaxLength(10) self.assertTrue(nw.isValid())
def testGSNameWidgetInvalidName(self): # base invalid name is empty nw = GSNameWidget(name='') self.assertFalse(nw.isValid()) nw.validateName('') self.assertFalse(nw.isValid()) nw.highlightName() self.assertNotEqual(nw.nameBox.lineEdit().styleSheet(), '') invalidnames = [ 'xMl_name', 'name with spaces', '9starts_with_number', ':starts_with_punctuation' ] # XML invalid name nw.setNameRegex(xmlNameRegex(), xmlNameRegexMsg()) self.assertFalse(nw.isValid()) self.assertIsNone(nw.definedName()) for ivname in invalidnames: nw.setName(ivname) self.assertFalse(nw.isValid()) # empty name regex nw.setName('') nw.setNameRegex(xmlNameEmptyRegex(), xmlNameRegexMsg()) self.assertTrue(nw.isValid()) self.assertEqual(nw.definedName(), '') for ivname in invalidnames: nw.setName(ivname) self.assertFalse(nw.isValid()) # custom regex invalid name nw.setNameRegex(r'^(?!XML|\d|\W)[a-z](\S(?!::))*', 'regex message') nw.setName('my::name') self.assertFalse(nw.isValid())
class PublishStyleDialog(QtGui.QDialog): def __init__(self, catalogs, layername, parent=None): super(PublishStyleDialog, self).__init__(parent) self.catalogs = catalogs self.catalognames = catalogs.keys() self.layername = layername self.catalog = None self.name = None self.initGui() def initGui(self): verticalLayout = QtGui.QVBoxLayout() buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Close) self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close) self.setWindowTitle('Publish style') horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) catalogLabel = QtGui.QLabel('Catalog') catalogLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.catalogBox = QtGui.QComboBox() self.catalogBox.addItems(self.catalognames) self.catalogBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) horizontalLayout.addWidget(catalogLabel) horizontalLayout.addWidget(self.catalogBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Name') nameLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.nameBox = GSNameWidget(namemsg='', name=xmlNameFixUp(self.layername), nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=[], unique=False) self.nameBox.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle("") self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.catalogBox.currentIndexChanged[str].connect( self.updateCatalogStyles) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.updateCatalogStyles(self.catalogBox.currentText()) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) self.resize(400, 200) @QtCore.pyqtSlot(bool) def updateButtons(self, overwriting): txt = "Overwrite" if overwriting else "OK" self.okButton.setText(txt) self.okButton.setDefault(not overwriting) self.cancelButton.setDefault(overwriting) @QtCore.pyqtSlot(str) def updateCatalogStyles(self, catname): catalog = self.catalogs[catname] styles = [style.name for style in catalog.get_styles()] self.nameBox.setNames(styles) def okPressed(self): self.name = unicode(self.nameBox.definedName()) self.catalog = unicode(self.catalogBox.currentText()) self.close() def cancelPressed(self): self.catalog = None self.name = None self.close()
def testGSNameWidgetUniqueName(self): nw = GSNameWidget(name='my_pg_connection', names=['name_one', 'name_two', 'name_three'], unique=False) self.assertTrue(nw.isValid()) nw.setName('name_one') self.assertTrue(nw.isValid()) self.assertTrue(nw.overwritingName()) nw.setUnique(True) self.assertFalse(nw.isValid()) self.assertFalse(nw.overwritingName()) nw.setUnique(False) self.assertTrue(nw.isValid()) self.assertTrue(nw.overwritingName())
def initGui(self): verticalLayout = QtGui.QVBoxLayout() buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Close) self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close) self.setWindowTitle('Create style from layer') horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) layerLabel = QtGui.QLabel('Layer') layerLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.layerBox = QtGui.QComboBox() self.alllayers = [layer.name() for layer in layers.getAllLayers()] self.layerBox.addItems(self.alllayers) self.layerBox.setMinimumWidth(250) horizontalLayout.addWidget(layerLabel) horizontalLayout.addWidget(self.layerBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Name') nameLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) defaultname = '' if len(self.alllayers) > 0: defaultname = xmlNameFixUp(self.alllayers[0]) self.nameBox = GSNameWidget(namemsg='', name=defaultname, nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.styles, unique=False) self.nameBox.setMinimumWidth(250) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle("") self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.layerBox.currentIndexChanged[str].connect(self.updateNameBox) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) self.resize(400, 150)
def setupUi(self): self.resize(600, 350) self.setWindowTitle("Group definition") self.verticalLayout = QVBoxLayout(self) self.verticalLayout.setSpacing(2) self.verticalLayout.setMargin(6) self.horizontalLayout = QHBoxLayout() # self.horizontalLayout.setSpacing(30) self.horizontalLayout.setMargin(0) self.nameLabel = QLabel("Group name") self.nameLabel.setSizePolicy( QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)) defaultname = "Group" if self.previousgroup: defaultname = self.previousgroup.name self.nameBox = GSNameWidget( namemsg='', name=defaultname, nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.groupnames, unique=False if self.previousgroup else True) if self.previousgroup: self.nameBox.setEnabled(False) self.nameBox.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)) self.horizontalLayout.addWidget(self.nameLabel) self.horizontalLayout.addWidget(self.nameBox) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setSpacing(6) self.horizontalLayout.setMargin(0) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Vertical) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) self.cancelButton = self.buttonBox.button(QDialogButtonBox.Cancel) self.table = QTableWidget() self.table.setColumnCount(2) self.table.setColumnWidth(0,300) self.table.verticalHeader().setVisible(False) self.table.horizontalHeader().setVisible(True) self.table.setHorizontalHeaderLabels(["Layer", "Style"]) self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.selectAllButton = QPushButton() self.selectAllButton.setText("(de)Select all") self.setTableContent() self.buttonBox.addButton(self.selectAllButton, QDialogButtonBox.ActionRole) self.horizontalLayout.addWidget(self.table) self.horizontalLayout.addWidget(self.buttonBox) self.verticalLayout.addLayout(self.horizontalLayout) self.setLayout(self.verticalLayout) self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.selectAllButton.clicked.connect(self.selectAll) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName())
class StyleFromLayerDialog(QtGui.QDialog): def __init__(self, styles=None, parent = None): super(StyleFromLayerDialog, self).__init__(parent) self.styles = styles if styles is not None else [] self.layer = None self.name = None self.initGui() def initGui(self): verticalLayout = QtGui.QVBoxLayout() buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Close) self.okButton = buttonBox.button(QtGui.QDialogButtonBox.Ok) self.cancelButton = buttonBox.button(QtGui.QDialogButtonBox.Close) self.setWindowTitle('Create style from layer') horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) layerLabel = QtGui.QLabel('Layer') layerLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) self.layerBox = QtGui.QComboBox() self.alllayers = [layer.name() for layer in layers.getAllLayers()] self.layerBox.addItems(self.alllayers) self.layerBox.setMinimumWidth(250) horizontalLayout.addWidget(layerLabel) horizontalLayout.addWidget(self.layerBox) verticalLayout.addLayout(horizontalLayout) horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) nameLabel = QtGui.QLabel('Name') nameLabel.setSizePolicy( QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Fixed)) defaultname = '' if len(self.alllayers) > 0: defaultname = xmlNameFixUp(self.alllayers[0]) self.nameBox = GSNameWidget( namemsg='', name=defaultname, nameregex=xmlNameRegex(), nameregexmsg=xmlNameRegexMsg(), names=self.styles, unique=False) self.nameBox.setMinimumWidth(250) horizontalLayout.addWidget(nameLabel) horizontalLayout.addWidget(self.nameBox) verticalLayout.addLayout(horizontalLayout) self.groupBox = QtGui.QGroupBox() self.groupBox.setTitle("") self.groupBox.setLayout(verticalLayout) layout = QtGui.QVBoxLayout() layout.addWidget(self.groupBox) layout.addWidget(buttonBox) self.setLayout(layout) buttonBox.accepted.connect(self.okPressed) buttonBox.rejected.connect(self.cancelPressed) self.layerBox.currentIndexChanged[str].connect(self.updateNameBox) self.nameBox.nameValidityChanged.connect(self.okButton.setEnabled) self.nameBox.overwritingChanged.connect(self.updateButtons) self.okButton.setEnabled(self.nameBox.isValid()) self.updateButtons(self.nameBox.overwritingName()) self.resize(400,150) @QtCore.pyqtSlot(str) def updateNameBox(self, name): self.nameBox.setName(xmlNameFixUp(name)) @QtCore.pyqtSlot(bool) def updateButtons(self, overwriting): txt = "Overwrite" if overwriting else "OK" self.okButton.setText(txt) self.okButton.setDefault(not overwriting) self.cancelButton.setDefault(overwriting) def okPressed(self): self.layer = self.layerBox.currentText() self.name = unicode(self.nameBox.definedName()) self.close() def cancelPressed(self): self.layer = None self.name = None self.close()