def buildfromauto(formconfig): widgetsconfig = formconfig['widgets'] outlayout = QFormLayout() outwidget = QWidget() outwidget.setLayout(outlayout) for config in widgetsconfig: widgettype = config['widget'] field = config['field'] name = config.get('name', field) label = QLabel(name) label.setObjectName(field + "_label") widgetwrapper = WidgetsRegistry.createwidget(widgettype, layer=None, field=field, widget=None, label=label, config=None) widget = widgetwrapper.widget widget.setObjectName(field) layoutwidget = QWidget() layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight)) layoutwidget.layout().addWidget(widget) if config.get('rememberlastvalue', False): savebutton = QToolButton() savebutton.setObjectName('{}_save'.format(field)) layoutwidget.layout().addWidget(savebutton) hidden = config.get('hidden', False) if not hidden: outlayout.addRow(label, layoutwidget) outlayout.addItem(QSpacerItem(10,10)) return outwidget
def buildfromauto(formconfig, base): widgetsconfig = formconfig['widgets'] outlayout = QFormLayout() outlayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow) outwidget = base outwidget.setLayout(outlayout) for config in widgetsconfig: widgettype = config['widget'] field = config['field'] name = config.get('name', field) label = QLabel(name) label.setObjectName(field + "_label") widget = WidgetsRegistry.createwidget(widgettype, parent=base) widget.setObjectName(field) layoutwidget = QWidget() layoutwidget.setLayout(QBoxLayout(QBoxLayout.LeftToRight)) layoutwidget.layout().addWidget(widget) if config.get('rememberlastvalue', False): savebutton = QToolButton() savebutton.setObjectName('{}_save'.format(field)) layoutwidget.layout().addWidget(savebutton) outlayout.addRow(label, layoutwidget) outlayout.addItem(QSpacerItem(10, 10)) installflickcharm(outwidget) return outwidget
def bind(self): """ Binds the given feature to the to the feature form. :param feature: :param defaults: The lookup containing the default values. Note: This is only used to toggle the save buttons. Default values should be set before the feature is given to the bind function. :return: """ widgetsconfig = self.formconfig['widgets'] for config in widgetsconfig: widgettype = config['widget'] print widgettype field = config['field'] widget = self.widget.findChild(QWidget, field) label = self.widget.findChild(QLabel, "{}_label".format(field)) widgetconfig = config.get('config', {}) widgetwrapper = WidgetsRegistry.createwidget(widgettype, self.form.QGISLayer, field, widget, label, widgetconfig) print widgetwrapper if widgetwrapper is None: print("No widget found for {}".format(widgettype)) continue readonlyrules = config.get('read-only-rules', []) if self.editingmode and 'editing' in readonlyrules: widgetwrapper.readonly = True elif 'insert' in readonlyrules: widgetwrapper.readonly = True if 'always' in readonlyrules: widgetwrapper.readonly = True widgetwrapper.hidden = config.get('hidden', False) if config.get('required', False) and not widgetwrapper.hidden: # All widgets state off as false unless told otherwise self.requiredfields[field] = False widgetwrapper.setrequired() widgetwrapper.validationupdate.connect(self.updaterequired) try: print "Null Check" print self.feature.fields().toList() value = nullcheck(self.feature[field]) print value except KeyError: utils.warning("Can't find field {}".format(field)) value = None widgetwrapper.setvalue(value) self._bindsavebutton(field) self.boundwidgets.append(widgetwrapper) self.validateall(self.boundwidgets)
def setupui(self): """ Setup the widget in the form """ widgetsconfig = self.formconfig['widgets'] layer = self.form.QGISLayer # Crash in QGIS if you lookup a field that isn't found. # We just make a dict with all fields lower because QgsFields is case sensitive. fields = {field.name().lower():field for field in layer.pendingFields().toList()} for config in widgetsconfig: widgettype = config['widget'] field = config['field'].lower() if field in self.boundwidgets: utils.warning("Sorry you can't bind the same field ({}) twice.".format(field)) utils.warning("{} for field {} has been ignored in setup".format(widget, field)) continue widget = self.findcontrol(field) if widget is None: utils.warning("No widget named {} found".format(field)) continue label = self.findcontrol("{}_label".format(field)) if label is None: utils.warning("Not label found for {}".format(field)) widgetconfig = config.get('config', {}) qgsfield = fields[field] try: widgetwrapper = WidgetsRegistry.widgetwrapper(widgettype=widgettype, layer=self.form.QGISLayer, field=qgsfield, widget=widget, label=label, config=widgetconfig) except EditorWidgetException as ex: utils.warning(ex.message) continue # Connect the if hasattr(widgetwrapper, "openimage"): widgetwrapper.openimage.connect(self.openimage.emit) readonlyrules = config.get('read-only-rules', []) if self.editingmode and 'editing' in readonlyrules: widgetwrapper.readonly = True elif 'insert' in readonlyrules or 'always' in readonlyrules: widgetwrapper.readonly = True widgetwrapper.hidden = config.get('hidden', False) if config.get('required', False) and not widgetwrapper.hidden: # All widgets state off as false unless told otherwise self.requiredfields[field] = False widgetwrapper.setrequired() widgetwrapper.validationupdate.connect(self.updaterequired) self._bindsavebutton(field) self.boundwidgets[field] = widgetwrapper
__author__ = 'nathan.woodrow' import sys import os # We have to add this to PATH because the ui builder # can't seem to find them :S uipath = os.path.join(os.path.dirname(__file__), 'uifiles') sys.path.append(uipath) from roam.editorwidgets.listwidget import ListWidget from roam.editorwidgets.checkboxwidget import CheckboxWidget from roam.editorwidgets.datewidget import DateWidget from roam.editorwidgets.textwidget import TextBlockWidget, TextWidget from roam.editorwidgets.imagewidget import ImageWidget from roam.editorwidgets.core import WidgetsRegistry widgets = [ListWidget, CheckboxWidget, DateWidget, TextBlockWidget, TextWidget, ImageWidget] WidgetsRegistry.registerwidgets(widgets)
__author__ = 'nathan.woodrow' import sys import os # We have to add this to PATH because the ui builder # can't seem to find them :S uipath = os.path.join(os.path.dirname(__file__), 'uifiles') sys.path.append(uipath) from roam.editorwidgets.listwidget import ListWidget from roam.editorwidgets.checkboxwidget import CheckboxWidget from roam.editorwidgets.datewidget import DateWidget from roam.editorwidgets.textwidget import TextBlockWidget, TextWidget from roam.editorwidgets.imagewidget import ImageWidget from roam.editorwidgets.numberwidget import NumberWidget from roam.editorwidgets.core import WidgetsRegistry supportedwidgets = [ListWidget, CheckboxWidget, DateWidget, TextBlockWidget, TextWidget, ImageWidget, NumberWidget] WidgetsRegistry.registerwidgets(supportedwidgets)