1
from ConfigDialog import ConfigDialog
2
from StateSaver import StateSaver
3
from utils.datatypes import *
6
class DisplayConfigger(ConfigDialog):
8
Configuration Dialog for the displays. This class handles loading / saving
12
def __init__(self, ident, path):
15
self.__backend = StateSaver(ident + "CONFIG")
17
# may we save already, or is it too early?
18
self.__may_save = False
20
# ID for storing the configuration
23
# the scripting environment with which the config interacts
24
self.__scripting_environment = None
26
ConfigDialog.__init__(self, path)
27
self.set_property("title", _("Configuration"))
32
# Sets the scripting environment to be used.
34
def set_scripting_environment(self, script):
36
self.__scripting_environment = script
37
self._set_setter(self.__setter_wrapper)
38
self._set_getter(self.__scripting_environment.get_value)
39
self._set_caller(self.__scripting_environment.call_function)
44
# Wraps the config setter handler to include saving config.
46
def __setter_wrapper(self, key, value, datatype):
49
self.__scripting_environment.set_value(key, value)
51
# save config, but not too early
53
rep = dtype_repr(datatype, value)
54
self.__backend.set_key(key, (rep, dtype_name(datatype)))
59
# Build preferences and put elements into the scripting environment
61
def build(self, items):
63
ConfigDialog.build(self, items)
65
for c in self.get_config_items():
66
ident = c.get_prop("id")
68
self.__scripting_environment.add_element("Prefs", ident, c)
73
# Loads the initial configuration.
75
def load_config(self):
77
# read stored configuration
78
for key in self.__backend.list():
79
if (key.endswith("_TYPE")): continue
81
rep, dtype = self.__backend.get_key(key)
82
datatype = dtype_get_type(dtype)
83
value = dtype_build(datatype, rep)
86
self.__setter_wrapper(key, value, None)
88
log("Couldn't pass arguments (%s, %s) to setter."
91
# have the children update themselves
92
for c in self.get_config_items(): c.update()
97
# Removes the configuration.
99
def remove_config(self):
101
self.__backend.remove()
107
self.__may_save = True
108
ConfigDialog.show(self)