def _populate(self, group_name: str): group = find_child_by_name(self._cfg_def, group_name) if group is None: return self._active_group = group_name for entry in group['children']: name = entry['name'] value = self._cfg[self._active_group][name] p = None tooltip = '' if 'brief' in entry: tooltip = '<span><p>%s</p>' % entry['brief'] if 'detail' in entry: tooltip += '<p>%s</p>' % entry['detail'] tooltip += '</span>' if entry['type'] == 'str' and 'options' in entry: options = [x['name'] for x in entry['options']] p = guiparams.Enum(name, value, options, tooltip=tooltip) elif entry['type'] == 'bool': if isinstance(value, str): value = value.lower() value = value in [True, 'true', 'on'] p = guiparams.Bool(name, value, tooltip=tooltip) elif entry['type'] == 'path': attributes = entry.get('attributes', []) if 'dir' in attributes: p = guiparams.Directory(name, value, tooltip=tooltip) elif 'exists' in attributes: p = guiparams.FileOpen(name, value, tooltip=tooltip) else: p = guiparams.FileSave(name, value, tooltip=tooltip) if p is not None: p.populate(self.ui.targetWidget) self._params.append(p)
def widget_factory(cmdp, topic, profile=None): value = cmdp.preferences.get(topic, profile=profile) entry = cmdp.preferences.definition_get(topic) name = topic.split('/')[-1] p = None tooltip = '' dtype = entry.get('dtype', 'str') if 'brief' in entry and entry['brief'] is not None: tooltip = '<span><p>%s</p>' % entry['brief'] if 'detail' in entry and entry['detail'] is not None: tooltip += '<p>%s</p>' % entry['detail'] tooltip += '</span>' if dtype == 'str': p = _str_factory(entry, name, value, tooltip) elif dtype == 'int': p = _int_factory(entry, name, value, tooltip) elif dtype == 'bool': if isinstance(value, str): value = value.lower() value = value in [True, 'true', 'on'] p = guiparams.Bool(name, value, tooltip=tooltip) elif dtype == 'path': attributes = entry.get('attributes', []) if 'dir' in attributes: p = guiparams.Directory(name, value, tooltip=tooltip) elif 'exists' in attributes: p = guiparams.FileOpen(name, value, tooltip=tooltip) else: p = guiparams.FileSave(name, value, tooltip=tooltip) elif dtype == 'color': p = guiparams.Color(name, value, tooltip=tooltip) elif dtype == 'font': p = guiparams.Font(name, value, tooltip=tooltip) else: log.info('%s: unsupported dtype %s', entry['name'], dtype) if p is None: return None def cbk(value): log.info('widget set %s, %s, %s', topic, value.value, profile) cmdp.invoke('!preferences/preference/set', (topic, value.value, profile)) p.callback = cbk cmdp.subscribe(topic, p.update_as_topic_subscriber) return p