~ubuntu-branches/ubuntu/raring/gnome-orca/raring-proposed

« back to all changes in this revision

Viewing changes to src/orca/orca_gui_navlist.py

  • Committer: Package Import Robot
  • Author(s): Luke Yelavich
  • Date: 2013-01-04 13:32:55 UTC
  • mfrom: (0.12.5)
  • Revision ID: package-import@ubuntu.com-20130104133255-xioc9ptckam1y1bh
Tags: 3.7.3-0ubuntu1
* New upstream release
  - General
    + Provide support to cycle amongst speech-dispatcher's capitalization
      presentation options
    + Create a generic UI which can be used in element navigation lists
    + Add a _getAll() method to structural_navigation.py
    + Fix for bug 689486 - Broken links to gnome-user-docs in the orca help
    + Remove a missed call to str.decode()
    + Make viewing Orca help in Yelp activatable via Learn Mode
    + Eliminate the Splash window, Main window, and Quit window
    + Increase the default uppercase pitch to 7.0
    + Use GLib.source_remove() instead of the deprecated GObject equivalent
    + Delete the acroread script
  - New and updated translations (THANKS EVERYONE!!!):
    + es            Spanish                 Daniel Mustieles
    + ta            Tamil                   Dr.T.Vasudevan
* debian/patches/01_show_main_window.patch: Drop, no longer needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Orca
 
2
#
 
3
# Copyright 2012 Igalia, S.L.
 
4
#
 
5
# Author: Joanmarie Diggs <jdiggs@igalia.com>
 
6
#
 
7
# This library is free software; you can redistribute it and/or
 
8
# modify it under the terms of the GNU Lesser General Public
 
9
# License as published by the Free Software Foundation; either
 
10
# version 2.1 of the License, or (at your option) any later version.
 
11
#
 
12
# This library is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
# Lesser General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU Lesser General Public
 
18
# License along with this library; if not, write to the
 
19
# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
 
20
# Boston MA  02110-1301 USA.
 
21
 
 
22
"""Displays a GUI for Orca navigation list dialogs"""
 
23
 
 
24
__id__        = "$Id$"
 
25
__version__   = "$Revision$"
 
26
__date__      = "$Date$"
 
27
__copyright__ = "Copyright (c) 2012 Igalia, S.L."
 
28
__license__   = "LGPL"
 
29
 
 
30
from gi.repository import GObject, Gdk, Gtk
 
31
 
 
32
from . import debug
 
33
from . import orca_state
 
34
from .orca_i18n import _
 
35
 
 
36
class OrcaNavListGUI:
 
37
 
 
38
    def __init__(self, title, columnHeaders, rows):
 
39
        self._tree = None
 
40
        self._activateButton = None
 
41
        self._gui = self._createNavListDialog(columnHeaders, rows)
 
42
        self._gui.set_title(title)
 
43
        self._gui.set_modal(True)
 
44
        self.showGUI()
 
45
 
 
46
    def _createNavListDialog(self, columnHeaders, rows):
 
47
        dialog = Gtk.Dialog()
 
48
        dialog.set_default_size(500, 400)
 
49
 
 
50
        grid = Gtk.Grid()
 
51
        contentArea = dialog.get_content_area()
 
52
        contentArea.add(grid)
 
53
 
 
54
        scrolledWindow = Gtk.ScrolledWindow()
 
55
        grid.add(scrolledWindow)
 
56
 
 
57
        self._tree = Gtk.TreeView()
 
58
        self._tree.set_hexpand(True)
 
59
        self._tree.set_vexpand(True)
 
60
        scrolledWindow.add(self._tree)
 
61
 
 
62
        cols = [GObject.TYPE_OBJECT]
 
63
        cols.extend(len(columnHeaders) * [GObject.TYPE_STRING])
 
64
        model = Gtk.ListStore(*cols)
 
65
        self._tree.set_model(model)
 
66
 
 
67
        cell = Gtk.CellRendererText()
 
68
        column = Gtk.TreeViewColumn("Accessible", cell, text=0)
 
69
        column.set_visible(False)
 
70
        self._tree.append_column(column)
 
71
 
 
72
        for i, header in enumerate(columnHeaders):
 
73
            cell = Gtk.CellRendererText()
 
74
            column = Gtk.TreeViewColumn(header, cell, text=i+1)
 
75
            column.set_sort_column_id(i+1)
 
76
            self._tree.append_column(column)
 
77
 
 
78
        model = self._tree.get_model()
 
79
        for row in rows:
 
80
            rowIter = model.append(None)
 
81
            for i, cell in enumerate(row):
 
82
                model.set_value(rowIter, i, cell)
 
83
 
 
84
        btn = dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
 
85
        btn.connect('clicked', self._onCancelClicked)
 
86
 
 
87
        btn = dialog.add_button(Gtk.STOCK_JUMP_TO, Gtk.ResponseType.APPLY)
 
88
        btn.grab_default()
 
89
        btn.connect('clicked', self._onJumpToClicked)
 
90
 
 
91
        # Translators: This string appears on a button in a dialog. "Activating"
 
92
        # the selected item will perform the action that one would expect to
 
93
        # occur if the object were clicked on with the mouse. Thus if the object
 
94
        # is a link, activating it will bring you to a new page. If the object
 
95
        # is a button, activating it will press the button. If the object is a
 
96
        # combobox, activating it will expand it to show all of its contents.
 
97
        self._activateButton = dialog.add_button(_('_Activate'), Gtk.ResponseType.OK)
 
98
        self._activateButton.connect('clicked', self._onActivateClicked)
 
99
 
 
100
        self._tree.connect('key-release-event', self._onKeyRelease)
 
101
        self._tree.connect('cursor-changed', self._onCursorChanged)
 
102
 
 
103
        return dialog
 
104
 
 
105
    def showGUI(self):
 
106
        self._gui.show_all()
 
107
        ts = orca_state.lastInputEventTimestamp
 
108
        if ts == 0:
 
109
            ts = Gtk.get_current_event_time()
 
110
        self._gui.present_with_time(ts)
 
111
 
 
112
    def _onCursorChanged(self, widget):
 
113
        obj = self._getSelectedAccessible()
 
114
        try:
 
115
            action = obj.queryAction()
 
116
        except:
 
117
            self._activateButton.set_sensitive(False)
 
118
        else:
 
119
            self._activateButton.set_sensitive(action.get_nActions() > 0)
 
120
 
 
121
    def _onKeyRelease(self, widget, event):
 
122
        keycode = event.hardware_keycode
 
123
        keymap = Gdk.Keymap.get_default()
 
124
        entries_for_keycode = keymap.get_entries_for_keycode(keycode)
 
125
        entries = entries_for_keycode[-1]
 
126
        eventString = Gdk.keyval_name(entries[0])
 
127
        if eventString == 'Return':
 
128
            self._gui.activate_default()
 
129
 
 
130
    def _onCancelClicked(self, widget):
 
131
        self._gui.destroy()
 
132
 
 
133
    def _onJumpToClicked(self, widget):
 
134
        obj = self._getSelectedAccessible()
 
135
        self._gui.destroy()
 
136
        try:
 
137
            obj.queryComponent().grabFocus()
 
138
        except:
 
139
            debug.println(debug.LEVEL_FINE, 'Could not grab focus on %s' % obj)
 
140
        try:
 
141
            text = obj.queryText()
 
142
            text.setCaretOffset(0)
 
143
        except NotImplementedError:
 
144
            pass
 
145
 
 
146
    def _onActivateClicked(self, widget):
 
147
        obj = self._getSelectedAccessible()
 
148
        self._gui.destroy()
 
149
        try:
 
150
            action = obj.queryAction()
 
151
        except:
 
152
            debug.println(
 
153
                debug.LEVEL_FINE, 'Could not perform action on %s' % obj)
 
154
        else:
 
155
            action.doAction(0)
 
156
 
 
157
    def _getSelectedAccessible(self):
 
158
        if not self._tree:
 
159
            return None
 
160
 
 
161
        selection = self._tree.get_selection()
 
162
        if not selection:
 
163
            return None
 
164
 
 
165
        model, paths = selection.get_selected_rows()
 
166
        if not paths:
 
167
            return None
 
168
 
 
169
        return model.get_value(model.get_iter(paths[0]), 0)
 
170
 
 
171
def showUI(title='', columnHeaders=[], rows=[()]):
 
172
    gui = OrcaNavListGUI(title, columnHeaders, rows)
 
173
    gui.showGUI()