Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions/cpsection/accessibility/view.py
blob: bae14dcfafdaff179b8ba501522fa6c5347c853c (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
# 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/>.


import gtk
from gettext import gettext as _

from sugar.graphics import style

from jarabe.controlpanel.sectionview import SectionView
from jarabe.controlpanel.inlinealert import InlineAlert

class accessibility(SectionView):
    def __init__(self, model, alerts=None):
        SectionView.__init__(self)

        self._model = model
        self.restart_alerts = alerts
        self.set_border_width(style.DEFAULT_SPACING * 2)
        self.set_spacing(style.DEFAULT_SPACING)
        scrollwindow = gtk.ScrolledWindow()
        scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.pack_start(scrollwindow, expand=True)
        scrollwindow.show()

        self._vbox_section = gtk.VBox()
        scrollwindow.add_with_viewport(self._vbox_section)
        self._vbox_section.show()

        self._zone_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
        self.pack_start(self._zone_alert_box, False)

        self._zone_alert = InlineAlert()
        self._zone_alert_box.pack_start(self._zone_alert)
        if 'zone' in self.restart_alerts:
            self._zone_alert.props.msg = self.restart_msg
            self._zone_alert.show()
        self._zone_alert_box.show()

        self.needs_restart = False

        self._view_keyboard_options()
        self._view_screen_options()


    def _view_keyboard_options(self):
        separator_pm_keyboard = gtk.HSeparator()
        self._vbox_section.pack_start(separator_pm_keyboard, expand=False)
        separator_pm_keyboard.show()

        label_pm_keyboard = gtk.Label(_('Keyboard'))
        label_pm_keyboard.set_alignment(0, 0)
        self._vbox_section.pack_start(label_pm_keyboard, expand=False)
        label_pm_keyboard.show()

        self.box_pm_keyboard = gtk.VBox()
        self.box_pm_keyboard.set_border_width(style.DEFAULT_SPACING * 2)
        self.box_pm_keyboard.set_spacing(style.DEFAULT_SPACING)

        self._view_mouse_keys()
        self._view_sticky_keys()
        self._view_bounce_keys()

        self._vbox_section.pack_start(self.box_pm_keyboard, expand=False)
        self.box_pm_keyboard.show()

    def _view_screen_options(self):
        separator_pm_screen = gtk.HSeparator()
        self._vbox_section.pack_start(separator_pm_screen, expand=False)
        separator_pm_screen.show()

        label_pm_screen = gtk.Label(_('Screen'))
        label_pm_screen.set_alignment(0, 0)
        self._vbox_section.pack_start(label_pm_screen, expand=False)
        label_pm_screen.show()

        self.box_pm_screen = gtk.VBox()
        self.box_pm_screen.set_border_width(style.DEFAULT_SPACING * 2)
        self.box_pm_screen.set_spacing(style.DEFAULT_SPACING)

        self._view_contrast()

        self._vbox_section.pack_start(self.box_pm_screen, expand=False)
        self.box_pm_screen.show()
    
    def _set_mouse_keys(self, widget):
        state = widget.get_active()
        self._model.set_mouse_keys(state)

    def _set_sticky_keys(self, widget):
        state = widget.get_active()
        self._model.set_sticky_keys(state)

    def _set_bounce_keys(self, widget):
        state = widget.get_active()
        self._model.set_bounce_keys(state)

    def _set_contrast(self, widget):
        state = widget.get_active()
        self._model.set_contrast(state)
        self.restart_alerts.append('zone')
        self.needs_restart = True
        self._zone_alert.props.msg = self.restart_msg
        self._zone_alert.show()

    def undo(self):
        self._model.set_mouse_keys(self.init_state_mouse_keys)
        self._model.set_sticky_keys(self.init_state_sticky_keys)
        self._model.set_bounce_keys(self.init_state_bounce_keys)

        self._model.set_contrast(self.init_state_contrast)
        self.btn_contrast.set_active(self.init_state_contrast)
        self.needs_restart = False
        self._zone_alert.hide()

    def _view_mouse_keys(self):
        self.btn_mouse_keys = gtk.CheckButton(_('Mouse Keys'))
        self._mouse_pm_change_handler = self.btn_mouse_keys.connect("toggled", self._set_mouse_keys)
        self.init_state_mouse_keys = self._model.get_mouse_keys() 
        self.btn_mouse_keys.set_active(self.init_state_mouse_keys)            
        self.box_pm_keyboard.pack_start(self.btn_mouse_keys, True, True, 2)
        self.btn_mouse_keys.show()

        lbl_mouse = gtk.Label(_('Move the mouse pointer with keyboard number.'))
        lbl_mouse.set_alignment(0, 0)
        self.box_pm_keyboard.pack_start(lbl_mouse, True, True, 2)
        lbl_mouse.show()

    def _view_sticky_keys(self):
        self.btn_sticky_keys = gtk.CheckButton(_('Sticky Keys'))
        self._sticky_pm_change_handler = self.btn_sticky_keys.connect("toggled", self._set_sticky_keys)
        self.init_state_sticky_keys = self._model.get_sticky_keys()
        self.btn_sticky_keys.set_active(self.init_state_sticky_keys)
        self.box_pm_keyboard.pack_start(self.btn_sticky_keys, True, True, 2)
        self.btn_sticky_keys.show()

        lbl_sticky = gtk.Label(_('Instead of having to press two keys at once (such as CTRL + Q), you can press one key at a time.'))
        lbl_sticky.set_line_wrap(True)
        lbl_sticky.set_alignment(0, 0)
        self.box_pm_keyboard.pack_start(lbl_sticky, True, True, 2)
        lbl_sticky.show()

    def _view_bounce_keys(self):
        self.btn_bounce_keys = gtk.CheckButton(_('Bounce Keys'))
        self._bounce_pm_change_handler = self.btn_bounce_keys.connect("toggled", self._set_bounce_keys)
        self.init_state_bounce_keys = self._model.get_bounce_keys()
        self.btn_bounce_keys.set_active(self.init_state_bounce_keys)
        self.box_pm_keyboard.pack_start(self.btn_bounce_keys, True, True, 2)
        self.btn_bounce_keys.show()

        lbl_bounce = gtk.Label(_('Ignore rapid, repeated keypresses of the same key.'))
        lbl_bounce.set_alignment(0, 0)
        self.box_pm_keyboard.pack_start(lbl_bounce, True, True, 2)
        lbl_bounce.show()

    def _view_contrast(self):
        self.btn_contrast = gtk.CheckButton(_('Contrast'))
        self._contrast_pm_change_handler = self.btn_contrast.connect("toggled", self._set_contrast)
        self.init_state_contrast = self._model.get_contrast()
        if self.init_state_contrast:
            self.btn_contrast.handler_block(self._contrast_pm_change_handler)
            self.btn_contrast.set_active(True)
            self.btn_contrast.handler_unblock(self._contrast_pm_change_handler)
        else:
            self.btn_contrast.set_active(False)
        self.box_pm_screen.pack_start(self.btn_contrast, True, True, 2)
        self.btn_contrast.show()

        lbl_contrast = gtk.Label(_('Enables the color contrast of the graphic interface.'))
        lbl_contrast.set_alignment(0, 0)
        self.box_pm_screen.pack_start(lbl_contrast, True, True, 2)
        lbl_contrast.show()