# coding: UTF8 # Copyright 2009 Thomas Jourdan # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import gtk import gtk.glade import os import sys import traceback from gettext import gettext as _ import ka_controller import ka_debug class KandidWidget(object): """ inv: self._widget_tree is not None """ def __init__(self, main_view): # Create GUI and attach that widget to our window # Load Glade XML self._widget_tree = gtk.glade.XML("kandid.glade") # Get Window kandidWindow = self._widget_tree.get_widget('kandidWindow') # Get Windows child kandidWindow_child = kandidWindow.get_child() # Remove the widget's parent if kandidWindow_child.parent: kandidWindow_child.parent.remove(kandidWindow_child) # self.widget will be attached to the Activity # This can be any GTK widget except a window main_view.pack_start(kandidWindow_child) self._localizePopulation() # Display everything def getWidget_tree(self): return self._widget_tree widget_tree = property(getWidget_tree) def _localizePopulation(self): try: local = {'breedGenerationButton' : _('Breed'), 'randomGenerationButton' : _('Random'), 'flurryLabel' : _('Flurry rate:'), 'populationLabel' : _('Population'), 'zoomLabel' : _('Zoom'), 'introLabel' : _('Introduction'), 'statusLabel' : _('Status'), } for key, label in local.iteritems(): self._widget_tree.get_widget(key).set_label(label) # ka_debug.info('localize "%s" to "%s"' % (key, label)) for cell_index in range(ka_controller.POPULATION_CAPACITY): local = {'favorite_menuitem_#' : _('My favorite'), 'awfull_menuitem_#' : _('Awful bore, replace it'), 'publishprotozoon_menuitem_#' : _('Publish to my friends'), 'zoomprotozoon_menuitem_#' : _('Zoom'), } self._set_localized_child_text(local, cell_index) for cell_index in range(ka_controller.INCOMMING_CAPACITY): local = {'accept_menuitem_#' : _('Accept protozoon'), 'decline_menuitem_#' : _('Decline protozoon'), } self._set_localized_child_text(local, cell_index) except: ka_debug.err('localize population failed [%s] [%s]' % \ (sys.exc_info()[0], sys.exc_info()[1])) traceback.print_exc(file=sys.__stderr__) def _set_localized_child_text(self, local, cell_index): strix = str(cell_index) for key, label in local.iteritems(): ikey = key if cell_index < 0 else key.replace('#', strix) self._widget_tree.get_widget(ikey).get_child().set_text(label) # ka_debug.info('localize "%s" to "%s"' % (ikey, label)) @staticmethod def get_localization(): """ returns localization and territory post: len(__return__[0]) >= 2 """ languages = [] territory, locale= '', '' for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): val = os.environ.get(envar) if val: languages = val.split(':') for lang in languages: pos = lang.find('.') if pos >= 0: lang = lang[:pos] pos = lang.find('_') if pos >= 0: locale = lang[:pos] territory = lang[pos+1:] else: locale = lang break ka_debug.info('languages: %s "%s" "%s"' % (languages, locale, territory)) return locale, territory