Viewing file: language_tui.py (4.36 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
## language_tui.py: text mode language selection dialog ## Copyright 2002, 2003 Red Hat, Inc. ## Copyright (C) 2002, 2003 Brent Fox <bfox@redhat.com> ## ## 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 2 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., 675 Mass Ave, Cambridge, MA 02139, USA.
from snack import * from rhpl.translate import _, textdomain_codeset import os import locale import language_backend
locale.setlocale(locale.LC_ALL, "") textdomain_codeset("system-config-language", locale.nl_langinfo(locale.CODESET))
languageBackend = language_backend.LanguageBackend()
class LanguageWindow: def __call__(self, screen):
defaultLang, self.installedLangs = languageBackend.getInstalledLangs() self.langDict = {}
bb = ButtonBar(screen, [_("OK"), _("Cancel")]) textBox = TextboxReflowed(40, _("Select the language for the system."))
list = self.populateListBox(defaultLang) g = GridFormHelp(screen, _("Language Selection"), "kbdtype", 1, 4) g.add(textBox, 0, 0) g.add(list, 0, 1, padding = (0, 1, 0, 1)) g.add(bb, 0, 3, growx = 1)
rc = g.runOnce()
button = bb.buttonPressed(rc)
if button == "cancel": return -1
choice = list.current() defaultLang, sysfontacm, sysfont = self.langDict[choice]
if self.installedLangs == None: languageBackend.writeI18N(defaultLang, "", sysfont, sysfontacm) else: modules = self.installedLangs[0] for lang in self.installedLangs[1:]: modules = modules + ":" + lang
languageBackend.writeI18N(defaultLang, modules, sysfont, sysfontacm)
def populateListBox(self, defaultLang): list = Listbox(8, scroll = 1, returnExit = 0)
lines = languageBackend.readTable()
if defaultLang == None: list.append('English (USA)', 'en_US.UTF-8') self.installedLangs = ['en_US.UTF-8:en'] list.setCurrent("en_US.UTF-8") return list
default = "" for line in lines: tokens = string.split(line)
if self.installedLangs == None: langBase = languageBackend.removeEncoding(tokens[0]) name = "" for token in tokens[3:]: name = name + " " + token
if languageBackend.removeEncoding(defaultLang) == langBase: default = tokens[0]
list.append(name, tokens[0]) self.langDict[tokens[0]] = (tokens[0], tokens[1], tokens[2])
else: if '.' in tokens[0]: #Chop encoding off so we can compare to self.installedLangs langBase = languageBackend.removeEncoding(tokens[0]) if langBase in self.installedLangs: name = "" for token in tokens[3:]: name = name + " " + token
if languageBackend.removeEncoding(defaultLang) == langBase: default = tokens[0]
list.append(name, tokens[0]) self.langDict[tokens[0]] = (tokens[0], tokens[1], tokens[2])
list.setCurrent(default) return list
class childWindow: def __init__(self): screen = SnackScreen() screen.drawRootText (0, 0, "system-config-language - (C) 2004 Red Hat, Inc.");
DONE = 0
while not DONE:
rc = LanguageWindow()(screen) if rc == -1: screen.finish() DONE = 1 else: screen.finish() self.runConfig(rc) DONE = 1 def runConfig(self, rc): pass
|