From 1bf36a3f2118d7b355316bc4b7b5148d2bc4a41e Mon Sep 17 00:00:00 2001
From: Walter Bender <walter@sugarlabs.org>
Date: Fri, 30 Jul 2010 15:49:11 -0400
Subject: [PATCH 1/2] no hardwired paths
---
extensions/deviceicon/touchpad.py | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/extensions/deviceicon/touchpad.py b/extensions/deviceicon/touchpad.py
index 7f3ecb5..897961f 100644
a
|
b
|
TOUCHPAD_MODES = ['capacitive', 'resistive'] |
32 | 32 | STATUS_TEXT = {TOUCHPAD_MODES[0]: _('finger'), TOUCHPAD_MODES[1]: _('stylus')} |
33 | 33 | STATUS_ICON = {TOUCHPAD_MODES[0]: 'touchpad-' + TOUCHPAD_MODES[0], |
34 | 34 | TOUCHPAD_MODES[1]: 'touchpad-' + TOUCHPAD_MODES[1]} |
35 | | # FLAG_PATH is used to preserve status between boots. |
36 | | FLAG_PATH = '/home/olpc/.olpc-pentablet-mode' |
| 35 | # FLAG_FILE is used to preserve status between boots. |
| 36 | FLAG_FILE = '.olpc-pentablet-mode' |
37 | 37 | # NODE_PATH is used to communicate with the touchpad device. |
38 | 38 | NODE_PATH = '/sys/devices/platform/i8042/serio1/ptmode' |
39 | 39 | |
… |
… |
def setup(tray): |
103 | 103 | if os.path.exists(NODE_PATH): |
104 | 104 | tray.add_device(DeviceView()) |
105 | 105 | |
| 106 | # if _flag_path exists, set the initial device value to stylus |
| 107 | _flag_path = os.join(os.environ['HOME'], FLAG_FILE) |
| 108 | if os.path.exists(_flag_path): |
| 109 | write_to_node_file(str(TOUCHPAD_MODES.index('stylus'))) |
| 110 | |
106 | 111 | |
107 | 112 | def read_touchpad_mode(): |
108 | 113 | """ Read the touchpad mode from the node path. """ |
… |
… |
def write_touchpad_mode(touchpad): |
117 | 122 | """ Write the touchpad mode to the node path and set/unset the flag. """ |
118 | 123 | touchpad_mode_index = TOUCHPAD_MODES.index(touchpad) |
119 | 124 | |
120 | | node_file_handle = open(NODE_PATH, 'w') |
121 | | node_file_handle.write(str(touchpad_mode_index)) |
122 | | node_file_handle.close() |
| 125 | write_to_node_file(str(touchpad_mode_index)) |
123 | 126 | |
| 127 | _flag_path = os.join(os.environ['HOME'], FLAG_FILE) |
124 | 128 | if touchpad_mode_index == 0: |
125 | | if os.path.exists(FLAG_PATH): |
| 129 | if os.path.exists(_flag_path): |
126 | 130 | os.remove(FLAG_PATH) |
127 | 131 | else: |
128 | | flag_file_handle = open(FLAG_PATH, 'w') |
| 132 | flag_file_handle = open(_flag_path, 'w') |
129 | 133 | flag_file_handle.close() |
| 134 | |
| 135 | |
| 136 | def write_to_node_file(value): |
| 137 | """ Write to node path, catching exception is there is a problem """ |
| 138 | try: |
| 139 | node_file_handle = open(NODE_PATH, 'w') |
| 140 | except IOError, e: |
| 141 | print e |
| 142 | return |
| 143 | node_file_handle.write(value) |
| 144 | node_file_handle.close() |