]>
Dogcows Code - chaz/openbox/blob - scripts/config.py
1 # Openbox's config system. Please use the defined functions instead of
2 # accessing the internal data structures directly, for the sake of us all.
6 def add(modulename
, name
, friendlyname
, description
, type, default
,
8 """Add a variable to the configuration system.
10 Add a variable to the configuration system for a module.
11 modulename - The name of the module, e.g. 'focus'
12 name - The name of the variable, e.g. 'my_variable'
13 friendlyname - The user-friendly name of the variable, e.g. 'My Variable'
14 description - The detailed destription of the variable, e.g. 'Does Things'
15 type - The type of the variable, one of:
23 default - The default value for the variable, e.g. 300
24 keywords - Extra keyword=value pairs to further define the variable. These
27 - options : A list of possible options for the variable.
28 This *must* be set for all enum variables.
29 - For 'integer' types:
30 - min : The minimum value for the variable.
31 - max : The maximum value for the variable.
33 modulename
= str(modulename
).lower()
34 name
= str(name
).lower()
35 friendlyname
= str(friendlyname
)
36 description
= str(description
)
37 type = str(type).lower()
39 # make sure the sub-dicts exist
43 _settings
[modulename
][name
]
45 _settings
[modulename
][name
] = {}
47 _settings
[modulename
] = {}
48 _settings
[modulename
][name
] = {}
50 # add the keywords first as they are used for the tests in set()
51 for key
,value
in zip(keywords
.keys(), keywords
.values()):
52 _settings
[modulename
][name
][key
] = value
54 _settings
[modulename
][name
]['name'] = friendlyname
55 _settings
[modulename
][name
]['description'] = description
56 _settings
[modulename
][name
]['type'] = type
57 _settings
[modulename
][name
]['default'] = default
59 # put it through the tests
61 set(modulename
, name
, default
)
63 del _settings
[modulename
][name
]
65 raise sys
.exc_info()[0], sys
.exc_info()[1] # re-raise it
67 def set(modulename
, name
, value
):
68 """Set a variable's value.
70 Sets the value for a variable of the specified module.
71 modulename - The name of the module, e.g. 'focus'
72 name - The name of the variable, e.g. 'my_variable'
73 value - The new value for the variable.
75 modulename
= str(modulename
).lower()
76 name
= str(name
).lower()
78 # proper value checking for 'boolean's
79 if _settings
[modulename
][name
]['type'] == 'boolean':
80 if not (value
== 0 or value
== 1):
81 raise ValueError, 'Attempted to set ' + name
+ ' to a value of '+\
82 str(value
) + ' but boolean variables can only contain 0 or'+\
85 # proper value checking for 'enum's
86 elif _settings
[modulename
][name
]['type'] == 'enum':
87 options
= _settings
[modulename
][name
]['options']
88 if not value
in options
:
89 raise ValueError, 'Attempted to set ' + name
+ ' to a value of '+\
90 str(value
) + ' but this is not one of the possible values '+\
91 'for this enum variable. Possible values are: ' +\
94 # min/max checking for 'integer's
95 elif _settings
[modulename
][name
]['type'] == 'integer':
97 min = _settings
[modulename
][name
]['min']
99 raise ValueError, 'Attempted to set ' + name
+ ' to a value '+\
100 ' of ' + str(value
) + ' but it has a minimum value ' +\
101 ' of ' + str(min) + '.'
102 except KeyError: pass
104 max = _settings
[modulename
][name
]['max']
106 raise ValueError, 'Attempted to set ' + name
+ ' to a value '+\
107 ' of ' + str(value
) + ' but it has a maximum value ' +\
108 ' of ' + str(min) + '.'
109 except KeyError: pass
111 _settings
[modulename
][name
]['value'] = value
113 def reset(modulename
, name
):
114 """Reset a variable to its default value.
116 Resets the value for a variable in the specified module back to its
117 original (default) value.
118 modulename - The name of the module, e.g. 'focus'
119 name - The name of the variable, e.g. 'my_variable'
121 modulename
= str(modulename
).lower()
122 name
= str(name
).lower()
123 _settings
[modulename
][name
]['value'] = \
124 _settings
[modulename
][name
]['default']
126 def get(modulename
, name
):
127 """Returns the value of a variable.
129 Returns the current value for a variable in the specified module.
130 modulename - The name of the module, e.g. 'focus'
131 name - The name of the variable, e.g. 'my variable'
133 modulename
= str(modulename
).lower()
134 name
= str(name
).lower()
135 return _settings
[modulename
][name
]['value']
137 #---------------------------- Internals ---------------------------
139 """The main configuration dictionary, which holds sub-dictionaries for each
142 The format for entries in here like this (for a string):
143 _settings['modulename']['varname']['name'] = 'Text Label'
144 _settings['modulename']['varname']['description'] = 'Does this'
145 _settings['modulename']['varname']['type'] = 'string'
146 _settings['modulename']['varname']['default'] = 'Foo'
147 _settings['modulename']['varname']['value'] = 'Foo'
148 # 'value' should always be initialized to the same
149 # value as the 'default' field!
151 Here's an example of an enum:
152 _settings['modulename']['varname']['name'] = 'My Enum Variable'
153 _settings['modulename']['varname']['description'] = 'Does Enum-like things.'
154 _settings['modulename']['varname']['type'] = 'enum'
155 _settings['modulename']['varname']['default'] = \
156 _settings['modulename']['varname']['value'] = [ 'Blue', 'Green', 'Pink' ]
158 And Here's an example of an integer with bounds:
159 _settings['modulename']['varname']['name'] = 'A Bounded Integer'
160 _settings['modulename']['varname']['description'] = 'A fierce party animal!'
161 _settings['modulename']['varname']['type'] = 'integer'
162 _settings['modulename']['varname']['default'] = \
163 _settings['modulename']['varname']['value'] = 0
164 _settings['modulename']['varname']['min'] = 0
165 _settings['modulename']['varname']['max'] = 49
167 Hopefully you get the idea.
171 """Valid values for a variable's type."""
172 _types
= [ 'boolean', # Boolean types can only hold a value of 0 or 1.
174 'enum', # Enum types hold a value from a list of possible values.
175 # An 'options' field *must* be provided for enums,
176 # containing a list of possible values for the variable.
178 'integer', # Integer types hold a single number, as well as a 'min'
179 # and 'max' property.
180 # If the 'min' or 'max' is ignore then bounds checking
181 # will not be performed in that direction.
183 'string', # String types hold a text string.
185 'file', # File types hold a file object.
187 'function',# Function types hold any callable object.
189 'object' # Object types can hold any python object.
208 #############################################################################
209 ### Options that can be changed to adjust the behavior of Openbox. ###
210 #############################################################################
212 THEME
= "/usr/local/share/openbox/styles/fieron2"
213 """The theme used to decorate everything."""
215 #TITLEBAR_LAYOUT = [ "icon", "title", "alldesktops", "iconify", "maximize", "close" ]
216 TITLEBAR_LAYOUT
= "DITMC"
217 """The layout of the buttons/label on client titlebars, can be made up of the
222 D - all-desktops button
224 If no 'L' is included in the string, one will be added to the end by
227 DOUBLE_CLICK_DELAY
= 300
228 """The number of milliseconds in which 2 clicks are perceived as a
232 """The amount of pixels that you have to drag the mouse before motion events
233 will start occuring."""
235 DESKTOP_NAMES
= ["one", "two", "three", "four", "five", "six", "seven", \
236 "eight", "nine", "ten", "eleven", "twelve"]
237 """The name of each desktop."""
239 NUMBER_OF_DESKTOPS
= 4
240 """The number of desktops/workspaces which can be scrolled between."""
242 #############################################################################
244 print "Loaded config.py"
This page took 0.044818 seconds and 4 git commands to generate.