File: all_fields.py

package info (click to toggle)
python-gpyconf 0.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 416 kB
  • ctags: 590
  • sloc: python: 1,980; makefile: 87; sh: 4
file content (50 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from gpyconf import fields
from gpyconftest import Configuration
import gpyconf.frontends.gtk

MULTI_OPTION_FIELD_OPTIONS = (
    ('foo', 'Select me for foo'),
    ('bar', 'Select me for bar'),
    (42, 'Select me for the answer to Life, the Universe, and Everything')
)

def _all(module):
    from types import ModuleType
    for attr in dir(module):
        if attr == 'Field':
            continue
        if attr.startswith('_'):
            continue
        attr = getattr(module, attr)
        if isinstance(attr, ModuleType):
            # exclude modules:
            continue
        yield attr

def call(callable):
    if issubclass(callable, fields.MultiOptionField):
        # expects parameter, extra handling
        ins = callable(callable._class_name, options=(MULTI_OPTION_FIELD_OPTIONS))
    else:
        ins = callable()
    ins.label = ins._class_name
    return ins

_fields = [field for field in _all(fields) if issubclass(field, fields.Field) and not field.abstract]
_dict = dict((field._class_name.lower(), field) for field in map(call, _fields))
_dict['logging_level'] = 'info'
_dict['frontend'] = gpyconf.frontends.gtk.ConfigurationDialog.with_arguments(title='All Fields',
                                                                                 ignore_missing_widgets=True)

AllFieldsTest = type('AllFieldsTest', (Configuration,), _dict)
# generate the class

if __name__ == '__main__':
    #from gpyconf.backends.python import PythonModuleBackend as BACKEND
    #from gpyconf.backends._json import JSONBackend as BACKEND
    from gpyconf.backends._xml import XMLBackend as BACKEND
    #from gpyconf.backends.configparser import ConfigParserBackend as BACKEND

    test = AllFieldsTest(backend=BACKEND)
    test.get_frontend().dialog.set_size_request(800, 600)
    test.run_frontend()