summaryrefslogtreecommitdiffstats
path: root/iw/keyboard_gui.py
blob: a871968e5589ff76fa530a504adfce4826100e25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from gtk import *
from iw_gui import *
import xkb
import string
from translate import _
from kbd import Keyboard
import iutil
import isys
from log import log

class KeyboardWindow (InstallWindow):

    def __init__ (self, ics):
	InstallWindow.__init__ (self, ics)

        ics.setTitle (_("Keyboard Configuration"))
        ics.readHTML ("kybd")
        ics.setNextEnabled (TRUE)
	self.kb = xkb.XKB ()
	self.rules = self.kb.getRules ()
	rules = self.kb.getRulesBase ()
	self.rulesbase = rules[string.rfind (rules, "/")+1:]
        self.model = "pc101"
        self.layout = "en_US"
	if self.todo.keyboard.type == "Sun":
	    self.model = self.todo.keyboard.model
	    self.layout = self.todo.keyboard.layout
        self.variant = ""
        self.hasrun = 0

    def getNext (self):
        if self.hasrun:
            self.todo.x.setKeyboard (self.rulesbase, self.model,
                                     self.layout, self.variant, "")
            self.todo.keyboard.setfromx (self.model, self.layout)
	    try:
	    	isys.loadKeymap(self.todo.keyboard.get())
	    except:
		log("failed to load keymap")
        return None

    def select_row (self, clist, row, col, event):
	self.model = self.modelList.get_row_data (self.modelList.selection[0])
	self.layout = self.layoutList.get_row_data (self.layoutList.selection[0])
	self.variant = self.variantList.get_row_data (self.variantList.selection[0])
        
	self.kb.setRule (self.model, self.layout, self.variant, "complete")

    def getScreen (self):
        if not self.hasrun:
            default = iutil.defaultKeyboard()
            if Keyboard.console2x.has_key (default):
                self.model = Keyboard.console2x[default][0]
                self.layout = Keyboard.console2x[default][1]
                self.kb.setRule (self.model, self.layout, self.variant, "complete")

	box = GtkVBox (FALSE, 5)
        im = self.ics.readPixmap ("gnome-keyboard.png")
        if im:
            im.render ()
            pix = im.make_pixmap ()
            a = GtkAlignment ()
            a.add (pix)
            a.set (0.0, 0.0, 0.0, 0.0)
            box.pack_start (a, FALSE)

	def moveto (widget, *args):
            widget.moveto (widget.selection[0], 0, 0.5, 0.5)

	box.pack_start (GtkLabel (_("Model")), FALSE)
        sw = GtkScrolledWindow ()
        sw.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC)
        self.modelList = GtkCList ()
	self.modelList.freeze ()
        self.modelList.set_selection_mode (SELECTION_BROWSE)
        for (key, model) in self.rules[0].items ():
            loc = self.modelList.append ((model,))
	    self.modelList.set_row_data (loc, key)
            if key == self.model:
                self.modelList.select_row (loc, 0)
        self.modelList.sort ()
        self.modelList.connect ("select_row", self.select_row)
        self.modelList.columns_autosize ()
        self.modelList.connect_after ("draw", moveto)
	self.modelList.thaw ()
        sw.add (self.modelList)
	box.pack_start (sw, TRUE)

	box.pack_start (GtkLabel (_("Layout")), FALSE)
        sw = GtkScrolledWindow ()
        sw.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC)
        self.layoutList = GtkCList ()
	self.layoutList.freeze ()
        self.layoutList.set_selection_mode (SELECTION_BROWSE)
        for (key, layout) in self.rules[1].items ():
            loc = self.layoutList.append ((layout,))
	    self.layoutList.set_row_data (loc, key)
            if key == self.layout:
                self.layoutList.select_row (loc, 0)
        self.layoutList.sort ()
        self.layoutList.connect ("select_row", self.select_row)
        self.layoutList.columns_autosize ()
	self.layoutList.connect_after ("draw", moveto)
	self.layoutList.thaw ()
        sw.add (self.layoutList)
	box.pack_start (sw, TRUE)

	box.pack_start (GtkLabel (_("Dead Keys")), FALSE)
        sw = GtkScrolledWindow ()
        sw.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC)
        self.variantList = GtkCList ()
        self.variantList.set_selection_mode (SELECTION_BROWSE)
#  For now, the only variant is deadkeys, so we'll just handle that
#  as special case, so the text can be less confusing.
#        self.variantList.append (("None",))
#        for (key, variant) in self.rules[2].items ():
        for (key, variant) in ((None, (_("Enable dead keys"))),
                               ("nodeadkeys", (_("Disable dead keys")))):
            loc = self.variantList.append ((variant,))
	    self.variantList.set_row_data (loc, key)
        self.variantList.sort ()
        self.variantList.connect ("select_row", self.select_row)
        self.variantList.columns_autosize ()
        sw.add (self.variantList)
	box.pack_start (sw, FALSE)

        label = GtkLabel (_("Test your selection here:"))
        label.set_alignment (0.0, 0.5)
        box.pack_start (label, FALSE)

        entry = GtkEntry ()
        box.pack_start (entry, FALSE)

        box.set_border_width (5)
        self.hasrun = 1
        return box