~xubuntu-dev/ubiquity/lp1437180_feh

« back to all changes in this revision

Viewing changes to espresso/components/kbd_chooser.py

  • Committer: Colin Watson
  • Date: 2006-04-05 13:14:56 UTC
  • Revision ID: colin.watson@canonical.com-20060405131456-53786dee285d816a
* Reorganise component packaging. Instead of having to modify each d-i
  component to produce an espresso-* binary package (in most cases) and
  having to do coordinated uploads of that package and espresso all the
  time, we now include all the relevant d-i source packages in this one
  (under d-i/source/), build them as part of our build process, and
  include all the components in the espresso binary package. 'debian/rules
  update' can be used to do automatic updates of these copied source
  packages. This should ultimately simplify maintenance work as well as
  making it much easier for third parties to make local changes to this
  installer.
* All FilteredCommand implementations for components now belong to
  espresso rather than to the component (because they were quite tightly
  bound to espresso's UI frontends anyway) and will be removed from
  component packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
 
2
 
 
3
# Copyright (C) 2005 Canonical Ltd.
 
4
# Written by Tollef Fog Heen <tfheen@ubuntu.com>
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
 
 
20
import os
 
21
from espresso.filteredcommand import FilteredCommand
 
22
from gtk import ListStore
 
23
import gobject
 
24
from subprocess import Popen
 
25
 
 
26
class KbdChooser(FilteredCommand):
 
27
 
 
28
    def prepare(self):
 
29
        # Always select from list.
 
30
        self.debug("kbd-chooser prepare")
 
31
 
 
32
        questions = [r'^kbd-chooser/method$',
 
33
                     r'^console-keymaps.*/keymap$',
 
34
                     'ERROR']
 
35
 
 
36
        self.keyboard_question = None
 
37
 
 
38
        self.preseed('kbd-chooser/method', self.description("kbd-chooser/do_select"))
 
39
 
 
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'],
 
42
                questions,
 
43
                {'PATH': '/usr/lib/espresso/kbd-chooser:' + os.environ['PATH']})
 
44
 
 
45
 
 
46
    def set(self, question, value):
 
47
        if question.startswith('console-keymaps-') and question.endswith('/keymap'):
 
48
            self.frontend.set_keyboard(value)
 
49
 
 
50
    def run(self, priority, question):
 
51
        if self.done:
 
52
            return self.succeeded
 
53
 
 
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"))
 
57
            return True
 
58
 
 
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))
 
66
 
 
67
            self.keyboard_question = question
 
68
 
 
69
        return super(KbdChooser, self).run(priority, question)
 
70
 
 
71
    def ok_handler(self):
 
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)
 
75
 
 
76
        return super(KbdChooser, self).ok_handler()
 
77
 
 
78
 
 
79
def apply_keyboard(keyboard):
 
80
    """
 
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.
 
84
    """
 
85
    xmap = None
 
86
    variant = None
 
87
    model = None
 
88
 
 
89
    if keyboard.startswith("mac-usb-"):
 
90
        keyboard = keyboard[len("mac-usb-"):]
 
91
 
 
92
    if keyboard.endswith("-latin1"):
 
93
        keyboard = keyboard[:-len("-latin1")]
 
94
 
 
95
    for k in [keyboard]: 
 
96
        if k == "be2":
 
97
            xmap = "be"
 
98
            break
 
99
 
 
100
        if k == "bg":
 
101
            xmap = "bg"
 
102
            variant = "bds"
 
103
            break
 
104
 
 
105
        if k == "br":
 
106
            xmap = "us"
 
107
            variant = "intl"
 
108
            model = "pc104"
 
109
            break
 
110
 
 
111
        if k == "br-abnt2":
 
112
            xmap = "br"
 
113
            variant = "abnt2"
 
114
            model = "abnt2"
 
115
            break
 
116
 
 
117
        if k == "by":
 
118
            xmap = "by"
 
119
            break
 
120
 
 
121
        if k == "cz-lat2":
 
122
            xmap = "cz"
 
123
            break
 
124
 
 
125
        if k == "de-latin1-nodeadkeys":
 
126
            xmap = "de"
 
127
            variant = "nodeadkeys"
 
128
            break
 
129
 
 
130
        if k == "de":
 
131
            xmap = "de"
 
132
            break
 
133
 
 
134
        if k == "dvorak":
 
135
            xmap = "us"
 
136
            variant = "dvorak"
 
137
            model = "pc104"
 
138
            break
 
139
 
 
140
        if k == "dk":
 
141
            xmap = "dk"
 
142
            break
 
143
 
 
144
        if k == "es":
 
145
            xmap = "es"
 
146
            break
 
147
 
 
148
        if k == "fr_CH":
 
149
            xmap = "ch"
 
150
            variant = "fr"
 
151
            break
 
152
 
 
153
        if k == "fr":
 
154
            xmap = "fr"
 
155
            break
 
156
 
 
157
        if k == "fr-latin9":
 
158
            xmap = "fr"
 
159
            variant = "latin9"
 
160
            break
 
161
 
 
162
        if k == "fi":
 
163
            xmap = "fi"
 
164
            break
 
165
 
 
166
        if k == "gb":
 
167
            xmap = "gb"
 
168
            break
 
169
 
 
170
        if k == "hebrew":
 
171
            xmap = "il"
 
172
            break
 
173
 
 
174
        if k == "hu":
 
175
            xmap = "hu"
 
176
            break
 
177
 
 
178
        if k == "is":
 
179
            xmap = "is"
 
180
            break
 
181
 
 
182
        if k == "it":
 
183
            xmap = "it"
 
184
            break
 
185
 
 
186
        if k == "jp106":
 
187
            xmap = "jp"
 
188
            variant = "jp106"
 
189
            break
 
190
 
 
191
        if k == "la":
 
192
            xmap = "latam"
 
193
            break
 
194
 
 
195
        if k == "lt":
 
196
            xmap = "lt"
 
197
            break
 
198
        
 
199
        # XXX should these be MODEL="macintosh"?
 
200
 
 
201
        if k == "mac-us-std":
 
202
            xmap = "us"
 
203
            break
 
204
 
 
205
        if k == "mac-de2-ext":
 
206
            xmap = "de"
 
207
            variant = "nodeadkeys"
 
208
            break
 
209
 
 
210
        if k == "mac-fr2-ext":
 
211
            xmap = "fr"
 
212
            break
 
213
 
 
214
        if k == "mac-fr3":
 
215
            xmap = "fr"
 
216
            break
 
217
 
 
218
        if k == "mac-es":
 
219
            xmap = "es"
 
220
            break
 
221
 
 
222
        if k == "no":
 
223
            xmap = "no"
 
224
            break
 
225
 
 
226
        if k == "pl":
 
227
            xmap = "pl"
 
228
            break
 
229
 
 
230
        if k == "pt":
 
231
            xmap = "pt"
 
232
            break
 
233
 
 
234
        if k == "uk":
 
235
            xmap = "gb"
 
236
            break
 
237
 
 
238
        if k == "lv-latin4":
 
239
            xmap = "lv"
 
240
            break
 
241
 
 
242
        if k == "se":
 
243
            xmap = "se"
 
244
            break
 
245
 
 
246
        if k == "sg":
 
247
            xmap = "ch"
 
248
            variant = "de"
 
249
            break
 
250
 
 
251
        if k == "sk-qwerty":
 
252
            xmap = "sk"
 
253
            variant = "qwerty"
 
254
            break
 
255
 
 
256
        if k == "sr-cy":
 
257
            xmap = "sr"
 
258
            break
 
259
 
 
260
        if k == "trf":
 
261
            xmap = "tr"
 
262
            variant = "f"
 
263
            break
 
264
 
 
265
        if k == "sr-cy":
 
266
            xmap = "sr"
 
267
            break
 
268
 
 
269
        if k == "trq":
 
270
            xmap = "tr"
 
271
            break
 
272
 
 
273
        if k == "ua":
 
274
            xmap = "ua"
 
275
            break
 
276
 
 
277
        if k == "us":
 
278
            xmap = "us"
 
279
            model = "pc104"
 
280
            break
 
281
    
 
282
    import syslog
 
283
    syslog.syslog(syslog.LOG_ERR, "kbd: %s" % keyboard)
 
284
    syslog.syslog(syslog.LOG_ERR, "kbd: %s %s %s" % (xmap, model, variant))
 
285
    if xmap is not None:
 
286
 
 
287
        if model is not None:
 
288
            model = ["-model", model]
 
289
        else:
 
290
            model = []
 
291
 
 
292
        if variant is not None:
 
293
            variant = ["-variant", variant]
 
294
        else:
 
295
            variant = []
 
296
 
 
297
        Popen(["setxkbmap", xmap] + model + variant)