1
# -*- coding: UTF-8 -*-
3
# Copyright (C) 2005 Canonical Ltd.
4
# Written by Tollef Fog Heen <tfheen@ubuntu.com>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
from espresso.filteredcommand import FilteredCommand
22
from gtk import ListStore
24
from subprocess import Popen
26
class KbdChooser(FilteredCommand):
29
# Always select from list.
30
self.debug("kbd-chooser prepare")
32
questions = [r'^kbd-chooser/method$',
33
r'^console-keymaps.*/keymap$',
36
self.keyboard_question = None
38
self.preseed('kbd-chooser/method', self.description("kbd-chooser/do_select"))
40
# self.frontend.set_keyboard_choices(self.choices_display_map("console-tools/archs"))
41
return (['/bin/sh', '-c', '. /usr/share/debconf/confmodule; exec /usr/lib/espresso/kbd-chooser/kbd-chooser'],
43
{'PATH': '/usr/lib/espresso/kbd-chooser:' + os.environ['PATH']})
46
def set(self, question, value):
47
if question.startswith('console-keymaps-') and question.endswith('/keymap'):
48
self.frontend.set_keyboard(value)
50
def run(self, priority, question):
54
if question.startswith('kbd-chooser/method'):
55
# self.preseed('kbd-chooser/method', "Select from full keyboard list")
56
self.preseed('kbd-chooser/method', self.description("kbd-chooser/do_select"))
59
elif question.startswith("console-keymaps-") and question.endswith("/keymap"):
60
self.frontend.set_keyboard_choices(self.choices_display_map(question))
61
self.frontend.set_keyboard(self.db.get(question))
62
self.debug("Display map: %s", self.choices_display_map(question))
63
self.debug("Untranslated choices: %s", self.choices_untranslated(question))
64
self.debug("Choices: %s", self.choices(question))
65
self.debug("%s db: %s", question, self.db.get(question))
67
self.keyboard_question = question
69
return super(KbdChooser, self).run(priority, question)
72
if self.keyboard_question is not None:
73
current_kbd = self.frontend.get_keyboard().lower().replace(" ", "_")
74
self.preseed(self.keyboard_question, current_kbd)
76
return super(KbdChooser, self).ok_handler()
79
def apply_keyboard(keyboard):
81
Takes a keyboard name from the frontend. This is mapped using the
82
same logic (hopefully) as X's configuration script and we get a
83
layout which we apply.
89
if keyboard.startswith("mac-usb-"):
90
keyboard = keyboard[len("mac-usb-"):]
92
if keyboard.endswith("-latin1"):
93
keyboard = keyboard[:-len("-latin1")]
125
if k == "de-latin1-nodeadkeys":
127
variant = "nodeadkeys"
199
# XXX should these be MODEL="macintosh"?
201
if k == "mac-us-std":
205
if k == "mac-de2-ext":
207
variant = "nodeadkeys"
210
if k == "mac-fr2-ext":
283
syslog.syslog(syslog.LOG_ERR, "kbd: %s" % keyboard)
284
syslog.syslog(syslog.LOG_ERR, "kbd: %s %s %s" % (xmap, model, variant))
287
if model is not None:
288
model = ["-model", model]
292
if variant is not None:
293
variant = ["-variant", variant]
297
Popen(["setxkbmap", xmap] + model + variant)