Viewing file: mouse_tui.py (5.56 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# mouse_tui.py: text mode mouse selection dialog # # Large parts of this file were taken from the anaconda # text mode mouse configuration screen # # Copyright 2002,2003 Red Hat, Inc. # # 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 Library 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.mouse import Mouse from rhpl.translate import _, textdomain_codeset import os import mouse_backend import locale
locale.setlocale(locale.LC_ALL, "") textdomain_codeset("system-config-mouse", locale.nl_langinfo(locale.CODESET)) textdomain_codeset("rhpl", locale.nl_langinfo(locale.CODESET))
mouseBackend = mouse_backend.MouseBackend()
class MouseDeviceWindow: def __call__(self, screen, mouse): choices = { _("/dev/ttyS0 (COM1 under DOS)") : "ttyS0", _("/dev/ttyS1 (COM2 under DOS)") : "ttyS1", _("/dev/ttyS2 (COM3 under DOS)") : "ttyS2", _("/dev/ttyS3 (COM4 under DOS)") : "ttyS3" }
i = 0 default = 0 mousedev = mouse.getDevice() if (not mousedev or mousedev[0:4] != "ttyS"): return -2
l = choices.keys() l.sort() for choice in l: if mouse.info.has_key("DEVICE") and choices[choice] == mouse.info["DEVICE"][5:]: default = i break i = i + 1
(button, result) = ListboxChoiceWindow(screen, _("Device"), _("What device is your mouse located on?"), l, [ _("OK"), _("Back") ], help = "mousedevice", default = default ) if button == "back": return -1
mouse.setDevice(choices[l[result]])
return mouse
class MouseWindow: def listcb(self): if self.mice[self.micenames[self.l.current()]][4]: self.c.setValue("*") else: self.c.setValue(" ") def __call__(self, screen, mouse): # XXX ewt changed this and we can't figure out why -- we always # want to display this dialog so that you can turn on 3 button emu # if mouse.probed(): return
self.mice = mouse.available () mice = self.mice.keys () mice.sort () self.micenames = mice (default, emulate) = mouse.get ()
try: default = mice.index (default) except: #Must be some kind of mouse we don't know about. Assume generic 3 button ps/2 default = mice.index ("Generic - 3 Button Mouse (PS/2)")
bb = ButtonBar(screen, [_("OK"), _("Cancel")]) t = TextboxReflowed(40, _("Select the appropriate mouse for the system.")) l = Listbox(8, scroll = 1, returnExit = 0) self.l = l
key = 0 for amouse in mice: l.append(amouse, key) key = key + 1
l.setCurrent(default) l.setCallback (self.listcb)
self.c = Checkbox(_("Emulate 3 Buttons?"), isOn = emulate)
if "XEMU3" in mouse.info.keys(): if mouse.info["XEMU3"] == "yes": self.c.setValue("*")
g = GridFormHelp(screen, _("Mouse Selection"), "mousetype", 1, 4) g.add(t, 0, 0) g.add(l, 0, 1, padding = (0, 1, 0, 1)) g.add(self.c, 0, 2, padding = (0, 0, 0, 1)) g.add(bb, 0, 3, growx = 1)
rc = g.runOnce()
button = bb.buttonPressed(rc)
if button == "cancel": return -1
choice = l.current() emulate = self.c.selected()
mouse.set(mice[choice], emulate)
oldDev = mouse.getDevice() if (oldDev): newDev = mouse.available()[mice[choice]][3] if ((oldDev[0:4] == "ttyS" and newDev[0:4] == "ttyS") or (oldDev == newDev)): pass else: mouse.setDevice(newDev)
return mouse
class childWindow: def __init__(self): screen = SnackScreen() screen.drawRootText (0, 0, "mouseconfig - (C) 2002 Red Hat, Inc.");
DONE = 0
while not DONE:
mouse = Mouse(skipProbe = 1) mouse.read() rc = MouseWindow()(screen, mouse) if rc == -1: screen.finish() DONE = 1 else: if rc.getDevice() == "ttyS": rc = MouseDeviceWindow()(screen, mouse) if rc == -1: continue else: screen.finish() self.runConfig(rc) DONE = 1 else: screen.finish() self.runConfig(rc) DONE = 1 def runConfig(self, rc): selectedMouse = rc.get()[0] if rc.get()[1] == 0: Xemu3 = "no" else: Xemu3 = "yes"
(gpm, xprotocol, iprotocol, device, emulate, shortname) = rc.available()[selectedMouse] mouseBackend.writeMouseFile(selectedMouse, gpm, Xemu3, xprotocol, iprotocol, rc.getDevice()) mouseBackend.restartGpm()
|