summaryrefslogtreecommitdiffstats
path: root/iw/mouse_gui.py
blob: 911f1d6af0a6a2d77518d3305e0074b606e8e009 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#
# mouse_gui.py: gui mouse configuration.
#
# Copyright 2000-2002 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import gtk
import string
import gobject
import gui
from iw_gui import *
from re import *
from rhpl.translate import _, N_
from flags import flags

class MouseWindow(InstallWindow):
    windowTitle = N_("Mouse Configuration")
    htmlTag = "mouse"

    def getNext(self):
        self.mouse.set(self.currentMouse, self.emulate3.get_active())

        mouse = self.availableMice[self.currentMouse]
        gpm, xdev, device, emulate, shortname = mouse

        if device == "ttyS":
            self.mouse.setDevice(self.serialDevice)
        else:
            self.mouse.setDevice(device)

	if self.flags.setupFilesystems:
	    self.mouse.setXProtocol()

        return None
    
    def selectDeviceType(self, selection, *args):
        if self.ignoreEvents:
            return
        (model, iter) = selection.get_selected()
        if iter:
            self.serialDevice = model.get_value(iter, 1)
            self.ics.setNextEnabled(gtk.TRUE)
        else:
            self.serialDevice = None

    def selectMouseType(self, selection, *args):
        if self.ignoreEvents:
            return
        (model, iter) = selection.get_selected()
        if iter is None:
            return

        if model.iter_has_child(iter):
	    self.devview.get_selection().unselect_all()
	    self.devview.set_sensitive(gtk.FALSE)
            self.emulate3.set_sensitive(gtk.FALSE)
            self.ics.setNextEnabled(gtk.FALSE)
	    return

	cur = model.get_value(iter, 1)

	self.emulate3.set_sensitive(gtk.TRUE)
	(gpm, xdev, device, emulate, shortname) = self.availableMice[cur]

	if device == "ttyS":
	    self.setCurrent(self.serialDevice, cur, emulate, recenter=0)
	else:
	    self.setCurrent(device, cur, emulate, recenter=0)

    def setupDeviceList(self):
	deviceList = ((_("/dev/ttyS0 (COM1 under DOS)"), "ttyS0" ),
                      (_("/dev/ttyS1 (COM2 under DOS)"), "ttyS1" ),
                      (_("/dev/ttyS2 (COM3 under DOS)"), "ttyS2" ),
                      (_("/dev/ttyS3 (COM4 under DOS)"), "ttyS3" ))
        
        self.devstore = gtk.ListStore(gobject.TYPE_STRING,
                                      gobject.TYPE_STRING)
	for descrip, dev in deviceList:
            iter = self.devstore.append()
            self.devstore.set_value(iter, 0, descrip)
            self.devstore.set_value(iter, 1, dev)
        self.devstore.set_sort_column_id(0, gtk.SORT_ASCENDING)
        self.devview = gtk.TreeView(self.devstore)
        col = gtk.TreeViewColumn(_("_Device"), gtk.CellRendererText(), text=0)
        self.devview.append_column(col)
        selection = self.devview.get_selection()
        selection.connect("changed", self.selectDeviceType)

    def setupMice(self):
        self.mousestore = gtk.TreeStore(gobject.TYPE_STRING,
                                        gobject.TYPE_STRING)
        # go though and find all the makes that have more than 1 mouse
        toplevels = {}
        for key, value in self.availableMice.items():
            make = string.split(_(key), ' - ')[0]
            if toplevels.has_key(make):
                toplevels[make] = toplevels[make] + 1
            else:
                toplevels[make] = 1

        # for each toplevel that has more than one mouse, make a parent
        # node for it.
        for make, count in toplevels.items():
            if count > 1:
                parent = self.mousestore.append(None)
                self.mousestore.set_value(parent, 0, make)
                toplevels[make] = parent
            else:
                del toplevels[make]
                
        # now go and add each child node
        for key, value in self.availableMice.items():
            fields = string.split(_(key), ' - ')
            make = fields[0]
            model = fields[1]
            parent = toplevels.get(make)
            iter = self.mousestore.append(parent)
            # if there is a parent, put only the model in the tree
            if parent:
                self.mousestore.set_value(iter, 0, model)
            else:
                # otherwise, put the full device there.
                self.mousestore.set_value(iter, 0, "%s %s" % tuple(fields))
            self.mousestore.set_value(iter, 1, key)

        self.mousestore.set_sort_column_id(0, gtk.SORT_ASCENDING)
        self.mouseview = gtk.TreeView(self.mousestore)
        self.mouseview.set_property("headers-visible", gtk.TRUE)
        col = gtk.TreeViewColumn(_("_Model"), gtk.CellRendererText(), text=0)
        self.mouseview.append_column(col)
        selection = self.mouseview.get_selection()
        selection.connect("changed", self.selectMouseType)

    def setCurrent(self, currentDev, currentMouse, emulate3, recenter=1):
        self.ignoreEvents = 1
        self.currentMouse = currentMouse

        parent = None
        iter = self.mousestore.get_iter_first()
        next = 1
        # iterate over the list, looking for the current mouse selection
        while next:
            # if this is a parent node, get the first child and iter over them
            if self.mousestore.iter_has_child(iter):
                parent = iter
                iter = self.mousestore.iter_children(parent)
                continue
            # if it's not a parent node and the mouse matches, select it.
            elif self.mousestore.get_value(iter, 1) == currentMouse:
		if parent:
		    path = self.mousestore.get_path(parent)
		    self.mouseview.expand_row(path, gtk.TRUE)
                selection = self.mouseview.get_selection()
                selection.unselect_all()
                selection.select_iter(iter)
                path = self.mousestore.get_path(iter)
                col = self.mouseview.get_column(0)
                self.mouseview.set_cursor(path, col, gtk.FALSE)
                if recenter:
                    self.mouseview.scroll_to_cell(path, col, gtk.TRUE,
                                                  0.5, 0.5)
                break
            # get the next row.
            next = self.mousestore.iter_next(iter)
            # if there isn't a next row and we had a parent, go to the node
            # after the parent we've just gotten the children of.
            if not next and parent:
                next = self.mousestore.iter_next(parent)
                iter = parent

        # set up the device list if we have a serial port
	if currentDev and currentDev.startswith('ttyS'):
	    self.serialDevice = currentDev
            selection = self.devview.get_selection()
            path = (int(self.serialDevice[4]),)
            selection.select_path(path)
            col = self.devview.get_column(0)
            self.devview.set_cursor(path, col, gtk.FALSE)
            if recenter:
                self.devview.scroll_to_cell(path, col, gtk.TRUE, 0.5, 0.5)
            self.ics.setNextEnabled(gtk.TRUE)
            self.devview.set_sensitive(gtk.TRUE)
	elif currentDev:
	    self.devview.get_selection().unselect_all();
            self.devview.set_sensitive(gtk.FALSE)
            self.ics.setNextEnabled(gtk.TRUE)
        else:
            # otherwise disable the list
	    self.devview.get_selection().unselect_all();
	    self.serialDevice = None
            self.ics.setNextEnabled(gtk.FALSE)
            self.devview.set_sensitive(gtk.TRUE)
            
        self.emulate3.set_active(emulate3)
        self.ignoreEvents = 0
        
    # MouseWindow tag="mouse"
    def getScreen(self, mouse):
	self.mouse = mouse
	self.flags = flags

        self.ignoreEvents = 0

	self.availableMice = mouse.available()
        self.serialDevice = None

        currentDev = mouse.getDevice()
	currentMouse, emulate3 = mouse.get()
        
        # populate the big widgets with the available selections
        self.setupMice()
        self.setupDeviceList()
        self.emulate3 = gtk.CheckButton(_("_Emulate 3 buttons"))
        self.setCurrent(currentDev, currentMouse, emulate3)

        # set up the box for this screen
        box = gtk.VBox(gtk.FALSE)

        # top header, includes graphic and instructions
        hbox = gtk.HBox(gtk.FALSE, 5)
        pix = self.ics.readPixmap("gnome-mouse.png")
        if pix:
            a = gtk.Alignment()
            a.add(pix)
            a.set(0.0, 0.0, 0.0, 0.0)
            hbox.pack_start(a, gtk.FALSE)
        label = gui.MnemonicLabel(_("Select the appropriate mouse for the system."))
        label.set_line_wrap(gtk.TRUE)
        label.set_size_request(350, -1)
        hbox.pack_start(label, gtk.FALSE)
        box.pack_start(hbox, gtk.FALSE)

        # next is the mouse tree
        sw = gtk.ScrolledWindow()
        sw.set_border_width(5)
        sw.set_shadow_type(gtk.SHADOW_IN)
        sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        sw.add(self.mouseview)
        box.pack_start(sw)
        label.set_mnemonic_widget(self.mouseview)

        # then the port list
        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_IN)
        frame.add(self.devview)
        box.pack_start(frame, gtk.FALSE)

        # finally the emulate 3 buttons
        align = gtk.Alignment()
        align.add(self.emulate3)
        align.set_border_width(5)
        box.pack_start(align, gtk.FALSE)

        return box