From 7e64374b211261cbebad5d3bf21d48f8b51d780c Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 13 Dec 2003 13:54:17 +0000 Subject: [PATCH] Translate text in Options box. git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/ROX-Lib2@3262 66de3db3-b00d-0410-b41b-f4738ad19bea --- python/rox/OptionsBox.py | 84 ++++++++++++++++++++++++++++++++++++++++++++---- python/rox/applet.py | 2 +- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/python/rox/OptionsBox.py b/python/rox/OptionsBox.py index 0581607..1a697ee 100644 --- a/python/rox/OptionsBox.py +++ b/python/rox/OptionsBox.py @@ -32,7 +32,7 @@ class OptionsBox(g.Dialog): When the widget is modified, call self.check_widget(option) to update the stored values. """ - def __init__(self, options_group, options_xml): + def __init__(self, options_group, options_xml, translation = None): """options_xml is an XML file, usually /Options.xml, which defines the layout of the OptionsBox. @@ -58,6 +58,14 @@ class OptionsBox(g.Dialog): """ assert isinstance(options_group, options.OptionGroup) + if translation is None: + import __main__ + if hasattr(__main__.__builtins__, '_'): + translation = __main__.__builtins__._ + else: + translation = lambda x: x + self._ = translation + g.Dialog.__init__(self) self.tips = g.Tooltips() self.set_has_separator(False) @@ -251,6 +259,8 @@ class OptionsBox(g.Dialog): appropriate build_* function.""" label = node.getAttribute('label') name = node.getAttribute('name') + if label: + label = self._(label) option = None if name: @@ -279,7 +289,7 @@ class OptionsBox(g.Dialog): else: data = None if data: - self.tips.set_tip(widget, data) + self.tips.set_tip(widget, self._(data)) # Each type of widget has a method called 'build_NAME' where name is # the XML element name. This method is called as method(node, label, @@ -391,7 +401,7 @@ class OptionsBox(g.Dialog): self.handlers[option] = (button.get, button.set) return [hbox] - + def build_numentry(self, node, label, option): """Tooltip. Lets the user choose a number from min to max.""" @@ -402,7 +412,7 @@ class OptionsBox(g.Dialog): step = int(step) else: step = 1 - unit = node.getAttribute('unit') + unit = self._(node.getAttribute('unit')) hbox = g.HBox(False, 4) if label: @@ -425,7 +435,69 @@ class OptionsBox(g.Dialog): spin.connect('value-changed', lambda w: self.check_widget(option)) return [hbox] - + + def build_combo_group(self, node, label, option): + """Build a list combo entry widget, only one of which may be + selected. + + + + """ + + # List to be displayed in widget + labels = [] + # Dictionary to equate labels to values + combos = {} + + combo = g.Combo() + + if label: + box = g.HBox(False, 4) + label_wid = g.Label(label) + label_wid.set_alignment(1.0, 0.5) + box.pack_start(label_wid, False, True, 0) + box.pack_start(combo, True, True, 0) + else: + box = None + + #self.may_add_tip(combo, node) + + # Build combo list + for cmb_option in node.getElementsByTagName('combo'): + value = cmb_option.getAttribute('value') + label_item = cmb_option.getAttribute('label') or value + + labels.append(label_item) + combos[value] = label_item + + # Now, add the list to the combo box + combo.set_popdown_strings(labels) + + combo.entry.connect('changed', + lambda e: self.check_widget(option)) + + def get(): + cmb_label = combo.entry.get_text() + """Look for where the label that is selected equals a + value in the dictionary, then return the key""" + for key, item in combos.items(): + if item == cmb_label: + return key + + def set(): + """Paranoia check""" + #print combos[option.value] + try: + saved_value_label = combos[option.value] + combo.entry.set_text(saved_value_label) + except: + print "Value '%s' not in combo list" % option.value + + self.handlers[option] = (get, set) + + return [box or combo] + + def build_radio_group(self, node, label, option): """Build a list of radio buttons, only one of which may be selected. @@ -436,7 +508,7 @@ class OptionsBox(g.Dialog): values = [] button = None for radio in node.getElementsByTagName('radio'): - label = radio.getAttribute('label') + label = self._(radio.getAttribute('label')) button = g.RadioButton(button, label) self.may_add_tip(button, radio) radios.append(button) diff --git a/python/rox/applet.py b/python/rox/applet.py index c755a79..b259890 100644 --- a/python/rox/applet.py +++ b/python/rox/applet.py @@ -77,4 +77,4 @@ class Applet(g.Plug): x = limit(x, 4, width - 4 - req[0]) y = limit(y, 4, height - 4 - req[1]) - return (x, y, g.TRUE) + return (x, y, True) -- 2.11.4.GIT