Permalink
Browse files

Refactores settings

 -the hole settings menu gets dynamicly generated from the content of the configspec file
 -the settings save method now also writes the data dynamicly in the config with the keys from configspec
  • Loading branch information...
spiderbit committed Jul 12, 2009
1 parent 93fe774 commit 3e6fc3881b1174f742002f7be6627f3294878f82
View
@@ -69,6 +69,7 @@ def _start(self):
# copy default config
spec_file = os.path.join(self.app_dir, 'misc', 'configspec')
self.config = ConfigObj(configspec=spec_file)
print self.config.configspec.keys()
self.config.filename = os.path.join(self.config_path, 'config')
if not os.access(os.path.join(self.config_path, 'config'), os.F_OK):
self.config.validate(vdt, copy=True)
@@ -78,8 +79,8 @@ def _start(self):
self.config.validate(vdt)
self.screen_res_x = self.config['screen'].as_int('resolution_x')
self.screen_res_y = self.config['screen'].as_int('resolution_y')
x, y = self.config['screen']['resolution'].split('x')
self.screen_res_x, self.screen_res_y = int (x), int(y)
self.theme_name = self.config['theme']['name']
@@ -204,8 +205,8 @@ def _init_game_engine(self):
RESIZEABLE = False
soya.init(title=self.window_title, \
width=self.config['screen'].as_int('resolution_x'),
height=self.config['screen'].as_int('resolution_y'), \
width=self.screen_res_x,
height=self.screen_res_y, \
fullscreen=int(self.config['screen'].as_bool('fullscreen')), \
resizeable=RESIZEABLE, sound=False)
@@ -254,8 +255,8 @@ def _init_widget_engine(self):
# Create a pudding root widget:
self.root_widget = pudding.core.RootWidget( \
width=self.config['screen'].as_int('resolution_x'),
height=self.config['screen'].as_int('resolution_y'), \
width=self.screen_res_x,
height=self.screen_res_y, \
top=0, left=0)
self.widget_properties['root_widget'] = self.root_widget
@@ -39,19 +39,16 @@ def get_langs(self):
def install(self, lang):
#lang = 'en_US'
#1. way
# application can set the wished language:
if lang == 'default':
if lang == 'System Setting':
self.install_default()
else:
lang = gettext.translation( 'canta', self.locale_path, languages=[lang])
lang.install(unicode=1)
def install_default(self):
# if you choose this way gettext looks what language ist set in env
# you can choose that with: export LANG=de_DE
gettext.install('canta', self.locale_path, unicode=1)
@@ -68,7 +68,7 @@ def __init__(self, song=Song(), song_data=0, player=None, config=None):
self.current_note = None
self.last_note = None
self.octave = config['misc'].as_bool('octave')
self.octave = config['misc'].as_bool('octave_adjusting')
self.tone_nr = None
self.line_nr = None
@@ -30,9 +30,9 @@ def __init__(self, widget_properties, line_diff=0):
parent = widget_properties['root_widget']
self.line_diff = line_diff
screen_res_x = int(widget_properties['config']['screen']['resolution'].split('x')[0])
screen_res_y = int(widget_properties['config']['screen']['resolution'].split('x')[1])
screen_res_x = widget_properties['config']['screen'].as_int('resolution_x')
screen_res_y = widget_properties['config']['screen'].as_int('resolution_y')
bc_top = widget_properties['pos_size']['top']
bc_left = int (0.02 * screen_res_x)
bc_width = screen_res_x * 0.9 # any number, we ANCHOR_ALL later
View
@@ -24,9 +24,9 @@ class Game:
that are needed to work with them
'''
def __init__(self, config):
self.octave = config['misc'].as_bool('octave')
self.octave = config['misc'].as_bool('octave_adjusting')
# if helper is set you only need to sing nearly the right tone
self.helper = config['misc'].as_bool('helper')
self.helper = config['misc'].as_bool('easier_tone_hitting')
self.allowed_difference = config['misc'].as_int('allowed_difference')
self.stats = {}
self.stats['normal'] = {'hits' : 0, 'misses' : 0, 'points' : 100}
View
@@ -28,13 +28,14 @@
from canta.menus.menu import ContentMenu
class MenuGroup(ContentMenu):
def __init__(self, widget_properties):
def __init__(self, widget_properties, key=""):
ContentMenu.__init__(self, widget_properties)
self.widget_properties = widget_properties
self.group_count = 0
self.heights = []
self.toggle_list = []
self.key = key
def add_group(self, items):
@@ -74,7 +75,7 @@ def add_group(self, items):
box_left = 10
box_width = self.screen_res_x - 40
box_height = len(items['items']) * 65
box_height = len(items) * 65
self.bg_box = pudding.control.Box(box_cont, \
left=box_left, \
width=box_width, \
@@ -86,14 +87,16 @@ def add_group(self, items):
for item in items['items']:
label_string = _('Choose a') + " " + item['info']
self.info_label = pudding.control.SimpleLabel(self.group_cont, \
label=item['info'], font=self.font_p, left=10, \
label=label_string, font=self.font_p, left=10, \
color=self.color_p)
if item['button_type'] == 'toggle':
selected_item = item['selected_item']
self.toggle_list.append(self.group_cont.add_child( \
MenuToggle(self.widget_properties, \
item['toggle_items'], selected_item)))
item['toggle_items'], selected_item, \
item['info'])))
elif item['button_type'] == 'button':
self.group_cont.add_child(MenuButton(item['label'], \
item['function'], item['args'], \
@@ -105,3 +108,7 @@ def add(self, button, align='left'):
self.nav_cont.add_child(button, pudding.EXPAND_BOTH)
button.root=self
def save(self):
for item in self.toggle_list:
item.save()
View
@@ -42,9 +42,13 @@ def __init__(self, widget_properties, config, theme_mgr, camera, core=None):
Menu.__init__(self, widget_properties)
self.core = core
self.config = config
self.locale = self.config['misc']['locale']
self.lm = LocaleManager(self.core.app_dir)
valid_languages = self.lm.get_langs()
self.lm.install(self.locale)
self.theme_mgr = theme_mgr
self.camera = camera
# Button labels:
View
@@ -29,8 +29,8 @@ def __init__(self, widget_properties):
top=0, left=0)
self.visible = 0
self.parent_world = widget_properties['root_world']
self.screen_res_x = widget_properties['config']['screen'].as_int('resolution_x')
self.screen_res_y = widget_properties['config']['screen'].as_int('resolution_y')
self.screen_res_x = int(widget_properties['config']['screen']['resolution'].split('x')[0])
self.screen_res_y = int(widget_properties['config']['screen']['resolution'].split('x')[1])
self.font_p = widget_properties['font']['p']['obj']
self.color_p = widget_properties['font']['p']['color']
self.font_h = widget_properties['font']['h1']['obj']
Oops, something went wrong.

0 comments on commit 3e6fc38

Please sign in to comment.