3
# Copyright 2012 Igalia, S.L.
5
# Author: Joanmarie Diggs <jdiggs@igalia.com>
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.
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.
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.
22
"""Displays a GUI for Orca navigation list dialogs"""
25
__version__ = "$Revision$"
27
__copyright__ = "Copyright (c) 2012 Igalia, S.L."
30
from gi.repository import GObject, Gdk, Gtk
33
from . import orca_state
34
from .orca_i18n import _
38
def __init__(self, title, columnHeaders, rows):
40
self._activateButton = None
41
self._gui = self._createNavListDialog(columnHeaders, rows)
42
self._gui.set_title(title)
43
self._gui.set_modal(True)
46
def _createNavListDialog(self, columnHeaders, rows):
48
dialog.set_default_size(500, 400)
51
contentArea = dialog.get_content_area()
54
scrolledWindow = Gtk.ScrolledWindow()
55
grid.add(scrolledWindow)
57
self._tree = Gtk.TreeView()
58
self._tree.set_hexpand(True)
59
self._tree.set_vexpand(True)
60
scrolledWindow.add(self._tree)
62
cols = [GObject.TYPE_OBJECT]
63
cols.extend(len(columnHeaders) * [GObject.TYPE_STRING])
64
model = Gtk.ListStore(*cols)
65
self._tree.set_model(model)
67
cell = Gtk.CellRendererText()
68
column = Gtk.TreeViewColumn("Accessible", cell, text=0)
69
column.set_visible(False)
70
self._tree.append_column(column)
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)
78
model = self._tree.get_model()
80
rowIter = model.append(None)
81
for i, cell in enumerate(row):
82
model.set_value(rowIter, i, cell)
84
btn = dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
85
btn.connect('clicked', self._onCancelClicked)
87
btn = dialog.add_button(Gtk.STOCK_JUMP_TO, Gtk.ResponseType.APPLY)
89
btn.connect('clicked', self._onJumpToClicked)
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)
100
self._tree.connect('key-release-event', self._onKeyRelease)
101
self._tree.connect('cursor-changed', self._onCursorChanged)
107
ts = orca_state.lastInputEventTimestamp
109
ts = Gtk.get_current_event_time()
110
self._gui.present_with_time(ts)
112
def _onCursorChanged(self, widget):
113
obj = self._getSelectedAccessible()
115
action = obj.queryAction()
117
self._activateButton.set_sensitive(False)
119
self._activateButton.set_sensitive(action.get_nActions() > 0)
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()
130
def _onCancelClicked(self, widget):
133
def _onJumpToClicked(self, widget):
134
obj = self._getSelectedAccessible()
137
obj.queryComponent().grabFocus()
139
debug.println(debug.LEVEL_FINE, 'Could not grab focus on %s' % obj)
141
text = obj.queryText()
142
text.setCaretOffset(0)
143
except NotImplementedError:
146
def _onActivateClicked(self, widget):
147
obj = self._getSelectedAccessible()
150
action = obj.queryAction()
153
debug.LEVEL_FINE, 'Could not perform action on %s' % obj)
157
def _getSelectedAccessible(self):
161
selection = self._tree.get_selection()
165
model, paths = selection.get_selected_rows()
169
return model.get_value(model.get_iter(paths[0]), 0)
171
def showUI(title='', columnHeaders=[], rows=[()]):
172
gui = OrcaNavListGUI(title, columnHeaders, rows)