Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/model/accessibility.py
blob: 586e1b9c5ebed78f3f18e4812c5b1c65e685e918 (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
# Copyright (C) 2010 Plan Ceibal
#
# Author: Esteban Arias <earias@plan.ceibal.edu.uy>
# Contact information: comunidad@plan.ceibal.edu.uy 
# Plan Ceibal http://www.ceibal.edu.uy
#
# 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 3 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 General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from gi.repository import Gtk
from gi.repository import GConf
import subprocess
import logging

class Keyboard:

    def get_mouse_keys(self):
        client = GConf.Client.get_default()
        return client.get_bool("/desktop/sugar/accessibility/keyboard/mousekeys_enable")

    def set_mouse_keys(self, activar):
        client = GConf.Client.get_default()
        client.set_bool("/desktop/sugar/accessibility/keyboard/mousekeys_enable", activar)
        self.run_config_keyboard()

    def get_sticky_keys(self):
        client = GConf.Client.get_default()
        return client.get_bool("/desktop/sugar/accessibility/keyboard/stickykeys_enable")

    def set_sticky_keys(self, activar):
        client = GConf.Client.get_default()
        client.set_bool("/desktop/sugar/accessibility/keyboard/stickykeys_enable", activar)
        self.run_config_keyboard()

    def get_bounce_keys(self):
        client = GConf.Client.get_default()
        return client.get_bool("/desktop/sugar/accessibility/keyboard/bouncekeys_enable")

    def set_bounce_keys(self, activar):
        client = GConf.Client.get_default()
        client.set_bool("/desktop/sugar/accessibility/keyboard/bouncekeys_enable", activar)

    def get_virtualkeyboard(self):
        client = GConf.Client.get_default()
        return client.get_bool("/desktop/sugar/accessibility/keyboard/virtualkeyboard_enable")

    def set_virtualkeyboard(self, activar):
        client = GConf.Client.get_default()
        client.set_bool("/desktop/sugar/accessibility/keyboard/virtualkeyboard_enable", activar)
        self.run_config_keyboard()

    def run_config_keyboard(self):
        cmd = ['ax']
        if self.get_sticky_keys():
            cmd.append('+stickykeys')
        else:
            cmd.append('-stickykeys')
        if self.get_bounce_keys():
            cmd.append('+bouncekeys')
        else:
            cmd.append('-bouncekeys')
        if self.get_mouse_keys():
            cmd += ['+mousekeys', 'mousemaxspeed', '3000', 'mousetimetomax', '1000', '-timeout', '-repeatkeys']
        else:
            cmd += ['-mousekeys', 'mousemaxspeed', '3000', 'mousetimetomax', '1000', '+timeout', '+repeatkeys']
        try:
            subprocess.call(cmd)
        except:
            logging.error('"ax" command not found')

class Screen:

    DEFAULT_THEME = "sugar"
    DEFAULT_FONT_SIZE = 10
    DEFAULT_FONT_FACE = "Sans Serif"
    CONTRAST_THEME = "sugar-contrast"
    CONTRAST_FONT_SIZE = 11
    CAPITAL_LETTERS_FONT_FACE = "Oracle"

    def get_contrast(self):
        client = GConf.Client.get_default()
        value = client.get_string("/desktop/sugar/interface/gtk_theme")
        return value==self.CONTRAST_THEME

    def set_contrast(self, activar):
        client = GConf.Client.get_default()
        if (activar):
            client.set_string("/desktop/sugar/interface/gtk_theme", self.CONTRAST_THEME)
            client.set_float('/desktop/sugar/font/default_size', self.CONTRAST_FONT_SIZE)
        else:
            client.set_string("/desktop/sugar/interface/gtk_theme", self.DEFAULT_THEME)
            if not self.get_capital_letters():
                client.set_float('/desktop/sugar/font/default_size', self.DEFAULT_FONT_SIZE)

    def get_capital_letters(self):
        client = GConf.Client.get_default()
        value = client.get_string("/desktop/sugar/font/default_face")
        return value==self.CAPITAL_LETTERS_FONT_FACE

    def set_capital_letters(self, activar):
        client = GConf.Client.get_default()
        if (activar):
            client.set_string('/desktop/sugar/font/default_face', self.CAPITAL_LETTERS_FONT_FACE)
            client.set_float('/desktop/sugar/font/default_size', self.CONTRAST_FONT_SIZE)
        else:
            client.set_string('/desktop/sugar/font/default_face', self.DEFAULT_FONT_FACE)
            if not self.get_contrast():
                client.set_float('/desktop/sugar/font/default_size', self.DEFAULT_FONT_SIZE)


class Mouse:

    WHITE_CURSOR_THEME="FlatbedCursors.White.Huge"
    DEFAULT_CURSOR_THEME="sugar"
    DEFAULT_ACCEL_MOUSE=3

    def get_white_mouse(self):
        client = GConf.Client.get_default()
        value = client.get_string("/desktop/sugar/peripherals/mouse/cursor_theme")
        return value==self.WHITE_CURSOR_THEME

    def set_white_mouse(self, activar):
        client = GConf.Client.get_default()
        if (activar):
            client.set_string("/desktop/sugar/peripherals/mouse/cursor_theme", self.WHITE_CURSOR_THEME)
        else:
            client.set_string("/desktop/sugar/peripherals/mouse/cursor_theme", self.DEFAULT_CURSOR_THEME)

    def _set_white_mouse_setting(self):
        cursor_theme = self.DEFAULT_CURSOR_THEME
        if (self.get_white_mouse()):
            cursor_theme = self.WHITE_CURSOR_THEME
        settings = Gtk.Settings.get_default()
        settings.set_property("gtk-cursor-theme-name", "%s" % (cursor_theme))

    def get_accel_mouse(self):
        client = GConf.Client.get_default()
        value = client.get_float("/desktop/sugar/peripherals/mouse/motion_acceleration")
        return value

    def set_accel_mouse(self, value):
        client = GConf.Client.get_default()
        client.set_float("/desktop/sugar/peripherals/mouse/motion_acceleration", value)
        self.run_config_mouse()

    def _set_accel_mouse_setting(self):
        cmd = ['xset', 'm' , str(self.get_accel_mouse())]
        subprocess.call(cmd)

    def run_config_mouse(self):
        self._set_accel_mouse_setting()
        self._set_white_mouse_setting()

class AccessibilityManager:
    def setup_accessibility(self):
        client = GConf.Client.get_default()
        is_accessibility = client.dir_exists("/desktop/sugar/accessibility")
        mouse = Mouse()
        if is_accessibility:
            keyboard = Keyboard()
            keyboard.run_config_keyboard()
            mouse.run_config_mouse()
        else:
            #mouse.set_accel_mouse(mouse.DEFAULT_ACCEL_MOUSE)
            #mouse.set_white_mouse(False)
            mouse._set_accel_mouse_setting()