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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646
|
'''
AT-SPI interface viewer plugin.
@author: Eitan Isaacson
@organization: Mozilla Foundation
@copyright: Copyright (c) 2007 Mozilla Foundation
@license: BSD
All rights reserved. This program and the accompanying materials are made
available under the terms of the BSD which accompanies this distribution, and
is available at U{http://www.opensource.org/licenses/bsd-license.php}
'''
import gi
from gi.repository import Gtk as gtk
from gi.repository import GdkPixbuf
from gi.repository.GLib import markup_escape_text
import pyatspi
import os.path
from accerciser.plugin import ViewportPlugin
from accerciser.icons import getIcon
from accerciser.i18n import _, N_, DOMAIN
from xml.dom import minidom
UI_FILE = os.path.join(os.path.dirname(__file__),
'interface_view.ui')
class InterfaceViewer(ViewportPlugin):
'''
Interface Viewer plugin class.
@ivar label_role: Top plugin label that displays the role name and
the accessible name.
@type label_role: gtk.Label
@ivar sections: List of L{_InterfaceSection} instances.
@type sections: list
'''
# Translators: this is a plugin name
plugin_name = N_('Interface Viewer')
plugin_name_localized = _(plugin_name)
# Translators: this is a plugin description
plugin_description = N_('Allows viewing of various interface properties')
def init(self):
'''
Intialize plugin.
'''
# HACK: Put all the callbacks in this class.
dom = minidom.parse(UI_FILE)
callbacks= set([signal.getAttribute('handler') \
for signal in dom.getElementsByTagName('signal')])
del dom
ui_xml = gtk.Builder()
ui_xml.set_translation_domain(DOMAIN)
ui_xml.add_from_file(UI_FILE)
frame = ui_xml.get_object('iface_view_frame')
self.label_role = ui_xml.get_object('label_role')
self.plugin_area.add(frame)
self.sections = [
_SectionAccessible(ui_xml, self.node),
_SectionAction(ui_xml, self.node),
_SectionApplication(ui_xml, self.node),
_SectionComponent(ui_xml, self.node),
_SectionDocument(ui_xml, self.node),
_SectionHyperlink(ui_xml, self.node),
_SectionHypertext(ui_xml, self.node),
_SectionImage(ui_xml, self.node),
_SectionSelection(ui_xml, self.node),
_SectionStreamableContent(ui_xml, self.node),
_SectionTable(ui_xml, self.node),
_SectionText(ui_xml, self.node),
_SectionValue(ui_xml, self.node),
_SectionCollection(ui_xml, self.node),
_SectionDesktop(ui_xml, self.node),
_SectionLoginHelper(ui_xml, self.node)]
# HACK: Add callbacks to this class.
for cb in callbacks:
for section in self.sections:
method = getattr(section, cb, None)
if not method: continue
setattr(self, cb, method)
ui_xml.connect_signals(self)
# Mark all expanders with no associated section classes as unimplemented
implemented_expanders = [s.expander for s in self.sections]
vbox_ifaces = ui_xml.get_object('vbox_ifaces')
for expander in vbox_ifaces.get_children():
if expander not in implemented_expanders:
iface_name = \
expander.get_label().lower().replace(' ', '').replace('_', '')
section = _InterfaceSection(ui_xml, self.node, iface_name)
section.disable()
pyatspi.Registry.registerEventListener(
self.onAccNameChanged, 'object:property-change:accessible-name')
def onAccNameChanged(self, event):
'''
Listener for accessible name changes, if it is ours, change the name.
@param event: 'object:property-change:accessible-name' event.
@type acc: Accessibility.Event
'''
if event.source != self.node.acc:
return
role = self.node.acc.getRoleName()
name = self.node.acc.name
if name:
role_name = '%s: %s' % (role, name)
else:
role_name = role
self.label_role.set_markup('<b>%s</b>' % markup_escape_text(role_name))
def onAccChanged(self, acc):
'''
Method that is invoked when the main accessible selection s changed.
@param acc: New accessible
@type acc: Accessibility.Accessible
'''
role = acc.getRoleName()
name = acc.name
if name:
role_name = '%s: %s' % (role, name)
else:
role_name = role
self.label_role.set_markup('<b>%s</b>' % markup_escape_text(role_name))
interfaces = pyatspi.listInterfaces(acc)
for section_obj in self.sections:
section_obj.disable()
if section_obj.interface_name in interfaces:
section_obj.enable(acc)
class _InterfaceSection(object):
'''
An abstract class that defines the interface for interface sections.
@cvar interface_name: Name of interface this section is for.
@type interface_name: string
@ivar node: Application-wide L{Node}.
@type node: L{Node}
@ivar expander: The section expander widget.
@type expander: gtk.Expander
@ivar event_listeners: List of client and event pairs that are
registered by this section. They are typically registered an population time,
and alwas deregistered on L{clearUI}.
@type event_listeners: list
'''
interface_name = None
def __init__(self, ui_xml, node, interface_name=None):
'''
Initialize section object. and call init() for derived classes.
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
@param node: Application-wide node of selected accessible.
@type node: L{Node}
@param interface_name: Override default interface name.
@type interface_name: string
'''
self.interface_name = interface_name or self.interface_name
self.node = node
self.expander = \
ui_xml.get_object('expander_%s' % self.interface_name.lower())
self._setExpanderChildrenSensitive(False)
self.event_listeners = []
self.init(ui_xml)
def init(self, ui_xml):
'''
Abtract method for initializing section-specific code.
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
pass
def enable(self, acc):
'''
Make section sensitive and populate it.
@param acc: Accessible to use for information when populating section.
@type acc: Accessibility.Accessible
'''
self._setExpanderChildrenSensitive(True)
self.populateUI(acc)
def populateUI(self, acc):
'''
Abstract method for section specific populating code.
@param acc: Accessible to use for information when populating section.
@type acc: Accessibility.Accessible
'''
pass
def disable(self):
'''
Disable section, make insensitive.
'''
self._setExpanderChildrenSensitive(False)
for client, event_names in self.event_listeners:
pyatspi.Registry.deregisterEventListener(client, *event_names)
self.clearUI()
def clearUI(self):
'''
Abstract method for section-specific cleanup.
'''
pass
def _setExpanderChildrenSensitive(self, sensitive, expander=None):
'''
Convinience method for making the expander's children insensitive.
We don't want tomake the expander itself insensitive because the user might
still want to keep it open or close it when it is disabled.
@param sensitive: True for sensitive.
@type sensitive: boolean
@param expander: Expander widget. Uses instances expander by default.
@type expander: gtk.Expander
'''
expander = expander or self.expander
label = expander.get_label_widget()
label_text = label.get_label()
not_implemented_str = _('(not implemented)')
if sensitive:
label_text = label_text.replace(not_implemented_str, '')
label_text = label_text.strip(' ')
elif not not_implemented_str in label_text:
label_text = label_text + ' ' + not_implemented_str
label.set_label(label_text)
for child in expander.get_children():
child.set_sensitive(sensitive)
def _isSelectedInView(self, selection):
'''
Convinience method for determining if a given treeview selection has any
selected nodes.
@param selection: Selection to check.
@type selection: gtk.TreeSelection
@return: True is something is selected
@rtype: boolean
'''
model, rows = selection.get_selected_rows()
something_is_selected = bool(rows)
return something_is_selected
def _onViewSelectionChanged(self, selection, *widgets):
'''
Convinience callback for selection changes. Useful for setting given
widgets to be sensitive only when something is selected, for example
action buttons.
@param selection: The selection object that triggered the callback.
@type selection: gtk.TreeSelection
@param widgets: list of widgets that should be made sensitive/insensitive
on selection changes.
@type widgets: list of gtk.Widget
'''
for widget in widgets:
widget.set_sensitive(self._isSelectedInView(selection))
def registerEventListener(self, client, *event_names):
pyatspi.Registry.registerEventListener(client, *event_names)
self.event_listeners.append((client, event_names))
class _SectionAccessible(_InterfaceSection):
'''
A class that populates an Accessible interface section.
@ivar states_model: Model for accessible states.
@type states_model: gtk.ListStore
@ivar relations_view: Tree view for accessible relations.
@type relations_view: gtk.TreeView
@ivar relations_model: Model for accessible relations.
@type relations_view: gtk.TreeStore
@ivar header_bg: Background color for relation header.
@type header_bg: gtk.gdk.Color
@ivar relation_bg: Background color for relation row.
@type relation_bg: gtk.gdk.Color
@ivar attr_model: Model for accessible attributes.
@type attr_model: gtk.ListStore
'''
interface_name = 'Accessible'
def init(self, ui_xml):
'''
Initialization that is specific to the Accessible interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
# Child count and description labels
self.child_count_label = ui_xml.get_object('label_acc_child count')
self.desc_label = ui_xml.get_object('label_acc_desc')
# configure states tree view
self.states_model = ui_xml.get_object('states_liststore')
# configure relations tree view
self.relations_view = ui_xml.get_object('relations_view')
self.relations_model = ui_xml.get_object('relations_treestore')
# preset the different bg colors
style = self.relations_view.get_style_context()
self.header_bg = style.get_background_color(gtk.StateFlags.NORMAL).to_string()
self.relation_bg = style.get_color(gtk.StateFlags.NORMAL).to_string()
selection = self.relations_view.get_selection()
selection.set_select_function(self._relationSelectFunc, None)
show_button = ui_xml.get_object('button_relation_show')
show_button.set_sensitive(self._isSelectedInView(selection))
selection.connect('changed', self._onViewSelectionChanged, show_button)
# configure accessible attributes tree view
self.attr_model = ui_xml.get_object('accattrib_liststore')
def populateUI(self, acc):
'''
Populate the Accessible section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
self.child_count_label.set_text(str(acc.childCount))
self.desc_label.set_label(acc.description or _('(no description)'))
states = [pyatspi.stateToString(s) for s in acc.getState().getStates()]
states.sort()
list(map(self.states_model.append, [[state] for state in states]))
try:
attribs = acc.getAttributes()
except:
pass
else:
for attr in attribs:
name, value = attr.split(':', 1)
self.attr_model.append([name, value])
relations = acc.getRelationSet()
for relation in relations:
r_type_name = repr(relation.getRelationType()).replace('RELATION_', '')
r_type_name = r_type_name.replace('_', ' ').lower().capitalize()
iter = self.relations_model.append(
None, [None,
markup_escape_text(r_type_name), -1,
self.header_bg, False])
for i in range(relation.getNTargets()):
acc = relation.getTarget(i)
self.relations_model.append(
iter, [getIcon(acc),
markup_escape_text(acc.name), i,
self.relation_bg, True])
self.relations_view.expand_all()
self.registerEventListener(self._accEventState, 'object:state-changed')
def clearUI(self):
'''
Clear all section-specific data.
'''
self.relations_model.clear()
self.states_model.clear()
self.attr_model.clear()
def _relationSelectFunc(self, path):
'''
Make relation-type headers unselectable.
@param path: The path about to be selected
@type path: tuple
@return: True if selectable
@rtype: boolean
'''
return not len(path) == 1
def _onRelationShow(self, relations_view, *more_args):
'''
Callback for row activation or button press. Selects the related
accessible in the main application.
@param relations_view: The relations treeview.
@type relations_view: gtk.TreeView
@param *more_args: More arguments that are provided by variuos types of
signals, but we discard them all.
@type *more_args: list
'''
selection = relations_view.get_selection()
model, iter = selection.get_selected()
if iter:
path = model.get_path(iter)
relations = self.node.acc.getRelationSet()
acc = relations[path[0]].getTarget(model[iter][2])
if acc:
self.node.update(acc)
def _accEventState(self, event):
'''
Callback for accessible state changes. Repopulates the states model.
@param event: Event that triggered this callback.
@type event: Accessibility.Event
'''
if self.node.acc == event.source:
self.states_model.clear()
try:
states = [pyatspi.stateToString(s) for s in \
self.node.acc.getState().getStates()]
except LookupError:
# Maybe we got a defunct state, in which case the object is diseased.
states = []
states.sort()
list(map(self.states_model.append, [[state] for state in states]))
class _SectionAction(_InterfaceSection):
'''
A class that populates an Action interface section.
@ivar actions_model: Model for accessible states.
@type actions_model: gtk.ListStore
@ivar action_selection: Current selection of actions tree view.
@type action_selection: gtk.TreeSelection
'''
interface_name = 'Action'
def init(self, ui_xml):
'''
Initialization that is specific to the Action interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
# configure actions tree view
treeview = ui_xml.get_object('treeview_action')
self.actions_model = treeview.get_model()
self.action_selection = treeview.get_selection()
show_button = ui_xml.get_object('button_action_do')
show_button.set_sensitive(self._isSelectedInView(self.action_selection))
self.action_selection.connect('changed',
self._onViewSelectionChanged, show_button)
def populateUI(self, acc):
'''
Populate the Action section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
ai = acc.queryAction()
for i in range(ai.nActions):
self.actions_model.append([i, ai.getName(i),
ai.getDescription(i),
ai.getKeyBinding(i)])
def clearUI(self):
'''
Clear all section-specific data.
'''
self.actions_model.clear()
def _onActionRowActivated(self, treeview, path, view_column):
'''
Callback for row activation in action treeview. Performs actions.
@param treeview: Actions tree view.
@type treeview: gtk.TreeView
@param path: Path of activated role.
@type path: tuple
@param view_column: The column that was clicked
@type view_column: integer
'''
action_num = self.actions_model[path][0]
ai = self.node.acc.queryAction()
ai.doAction(action_num)
def _onActionClicked(self, button):
'''
Callback for "do action" button. Performs action of currently selected row.
@param button: The button that was pressed.
@type button: gtk.Button
'''
actions_model, iter = self.action_selection.get_selected()
action_num = actions_model[iter][0]
ai = self.node.acc.queryAction()
ai.doAction(action_num)
class _SectionApplication(_InterfaceSection):
'''
A class that populates an Application interface section.
@ivar label_id: Label that displays application id info.
@type label_id: gtk.Label
@ivar label_tk: Label for toolkit name.
@type label_tk: gtk.Label
@ivar label_version: Label for toolkit version.
@type label_version: gtk.Label
'''
interface_name = 'Application'
def init(self, ui_xml):
'''
Initialization that is specific to the Application interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
self.label_id = ui_xml.get_object('label_app_id')
self.label_tk = ui_xml.get_object('label_app_tk')
self.label_version = ui_xml.get_object('label_app_version')
def populateUI(self, acc):
'''
Populate the Application section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
ai = acc.queryApplication()
self.label_id.set_text(repr(ai.id))
self.label_tk.set_text(ai.toolkitName)
self.label_version.set_text(ai.version)
def clearUI(self):
'''
Clear all section-specific data.
'''
self.label_id.set_text('')
self.label_tk.set_text('')
self.label_version.set_text('')
class _SectionComponent(_InterfaceSection):
'''
A class that populates a Component interface section.
@ivar label_posrel: Relative position label
@type label_posrel: gtk.Label
@ivar label_posabs: Absolute position label
@type label_posabs: gtk.Label
@ivar label_layer: Layer label
@type label_layer: gtk.Label
@ivar label_zorder: Z-order label
@type label_zorder: gtk.Label
@ivar label_alpha: Alpha label
@type label_alpha: gtk.Label
'''
interface_name = 'Component'
def init(self, ui_xml):
'''
Initialization that is specific to the Component interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
self.label_posabs = ui_xml.get_object('absolute_position_label')
self.label_posrel = ui_xml.get_object('relative_position_label')
self.label_size = ui_xml.get_object('size_label')
self.label_layer = ui_xml.get_object('layer_label')
self.label_zorder = ui_xml.get_object('zorder_label')
self.label_alpha = ui_xml.get_object('alpha_label')
def populateUI(self, acc):
'''
Populate the Component section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
ci = acc.queryComponent()
bbox = ci.getExtents(pyatspi.DESKTOP_COORDS)
self.label_posabs.set_text('%d, %d' % (bbox.x, bbox.y))
self.label_size.set_text('%dx%d' % (bbox.width, bbox.height))
bbox = ci.getExtents(pyatspi.WINDOW_COORDS)
self.label_posrel.set_text('%d, %d' % (bbox.x, bbox.y))
layer = ci.getLayer()
self.label_layer.set_text(repr(ci.getLayer()).replace('LAYER_', ''))
self.label_zorder.set_text(repr(ci.getMDIZOrder()))
self.label_alpha.set_text(repr(ci.getAlpha()))
self.registerEventListener(self._accEventComponent,
'object:bounds-changed',
'object:visible-data-changed')
def clearUI(self):
'''
Clear all section-specific data.
'''
self.label_posrel.set_text('')
self.label_posabs.set_text('')
self.label_size.set_text('')
self.label_layer.set_text('')
self.label_zorder.set_text('')
self.label_alpha.set_text('')
def _accEventComponent(self, event):
'''
Callback for whenever any of the component attributes change.
@param event: Evnt that triggered this callback.
@type event: Accessibility.Event
'''
if event.source == self.node.acc:
self.populateUI(event.source)
class _SectionDocument(_InterfaceSection):
interface_name = 'Document'
'''
A class that populates an Component interface section.
@ivar attr_model: Attribute data model
@type attr_model: gtk.ListStore
@ivar label_locale: Locale label
@type label_locale: gtk.Label
'''
def init(self, ui_xml):
'''
Initialization that is specific to the Document interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
# configure document attributes tree view
self.attr_model = ui_xml.get_object('docattrib_liststore')
self.label_locale = ui_xml.get_object('label_doc_locale')
def populateUI(self, acc):
'''
Populate the Document section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
di = acc.queryDocument()
self.label_locale.set_text(di.getLocale())
try:
attribs = di.getAttributes()
except:
attribs = None
if attribs:
for attr in attribs:
name, value = attr.split(':', 1)
self.attr_model.append([name, value])
def clearUI(self):
'''
Clear all section-specific data.
'''
self.attr_model.clear()
self.label_locale.set_text('')
class _SectionHyperlink(_InterfaceSection):
interface_name = 'Hyperlink'
'''
A placeholder class for Hyperlink interface section.
'''
class _SectionCollection(_InterfaceSection):
interface_name = 'Collection'
'''
A placeholder class for Collection interface section.
'''
class _SectionDesktop(_InterfaceSection):
interface_name = 'Desktop'
'''
A placeholder class for Desktop interface section.
'''
class _SectionLoginHelper(_InterfaceSection):
interface_name = 'LoginHelper'
'''
A placeholder class for LoginHelper interface section.
'''
class _SectionHypertext(_InterfaceSection):
'''
A class that populates an Hypertext interface section.
@ivar links_model: Data model for available links.
@type links_model: gtk.ListStore
'''
interface_name = 'Hypertext'
def init(self, ui_xml):
'''
Initialization that is specific to the Hypertext interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
# configure links tree view
treeview = ui_xml.get_object('treeview_links')
# It's a treestore because of potential multiple anchors
self.links_model = gtk.TreeStore(int, # Link index
str, # Name
str, # Description
str, # URI
int, # Start offset
int, # End offset
object) # Anchor object
treeview.set_model(self.links_model)
crt = gtk.CellRendererText()
tvc = gtk.TreeViewColumn(_('Name'))
tvc.set_sizing(gtk.TreeViewColumnSizing.AUTOSIZE)
tvc.set_resizable(True)
tvc.pack_start(crt, True)
tvc.add_attribute(crt, 'text', 1)
treeview.append_column(tvc)
crt = gtk.CellRendererText()
tvc = gtk.TreeViewColumn(_('URI'))
tvc.set_sizing(gtk.TreeViewColumnSizing.AUTOSIZE)
tvc.set_resizable(True)
tvc.pack_start(crt, True)
tvc.add_attribute(crt, 'text', 3)
treeview.append_column(tvc)
crt = gtk.CellRendererText()
tvc = gtk.TreeViewColumn(_('Start'))
tvc.set_sizing(gtk.TreeViewColumnSizing.AUTOSIZE)
tvc.set_resizable(True)
tvc.pack_start(crt, True)
tvc.add_attribute(crt, 'text', 4)
treeview.append_column(tvc)
crt = gtk.CellRendererText()
tvc = gtk.TreeViewColumn(_('End'))
tvc.set_sizing(gtk.TreeViewColumnSizing.AUTOSIZE)
tvc.set_resizable(True)
tvc.pack_start(crt, True)
tvc.add_attribute(crt, 'text', 5)
treeview.append_column(tvc)
selection = treeview.get_selection()
show_button = ui_xml.get_object('button_hypertext_show')
show_button.set_sensitive(self._isSelectedInView(selection))
selection.connect('changed', self._onViewSelectionChanged, show_button)
def populateUI(self, acc):
'''
Populate the Hypertext section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
hti = acc.queryHypertext()
for link_index in range(hti.getNLinks()):
link = hti.getLink(link_index)
iter = self.links_model.append(None,
[link_index,
'', '', '',
link.startIndex,
link.endIndex, None])
for anchor_index in range(link.nAnchors):
acc_obj = link.getObject(anchor_index)
self.links_model.append(iter,
[link_index, acc_obj.name, acc_obj.description,
link.getURI(anchor_index),
link.startIndex, link.endIndex, acc_obj])
if anchor_index == 0:
self.links_model[iter][1] = \
acc_obj.name # Otherwise the link is nameless.
def clearUI(self):
'''
Clear all section-specific data.
'''
self.links_model.clear()
def _onLinkShow(self, link_view, *more_args):
'''
Callback for row activation or button press. Selects the related
link accessible in the main application.
@param link_view: The links tree view.
@type link_view: gtk.TreeView
@param *more_args: More arguments that are provided by variuos types of
signals, but we discard them all.
@type *more_args: list
'''
selection = link_view.get_selection()
model, iter = selection.get_selected()
if iter:
acc = model[iter][6]
if acc:
self.node.update(acc)
class _SectionImage(_InterfaceSection):
'''
A class that populates an Image interface section.
@ivar label_pos: Position label
@type label_pos: gtk.Label
@ivar label_size: Size label
@type label_size: gtk.Label
'''
interface_name = 'Image'
def init(self, ui_xml):
'''
Initialization that is specific to the Image interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
self.label_pos = ui_xml.get_object('img_position_label')
self.label_size = ui_xml.get_object('img_size_label')
self.label_locale = ui_xml.get_object('img_locale_label')
self.label_desc = ui_xml.get_object('img_locale_label')
def populateUI(self, acc):
'''
Populate the Image section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
ii = acc.queryImage()
bbox = ii.getImageExtents(pyatspi.DESKTOP_COORDS)
self.label_pos.set_text('%d, %d' % (bbox.x, bbox.y))
self.label_size.set_text('%dx%d' % (bbox.width, bbox.height))
self.label_desc.set_label(ii.imageDescription or \
_('(no description)'))
self.label_locale.set_text(ii.imageLocale)
def clearUI(self):
'''
Clear all section-specific data.
'''
self.label_pos.set_text('')
self.label_size.set_text('')
class _SectionSelection(_InterfaceSection):
'''
A class that populates a Selection interface section.
@ivar sel_model: Data model for child selection options.
@type sel_model: gtk.ListStore
@ivar sel_selection: Selection in selection treeview.
@type sel_selection: gtk.TreeSelection
@ivar button_select_all: Button for selecting all of the selection nodes.
@type button_select_all: gtk.Button
'''
interface_name = 'Selection'
def init(self, ui_xml):
'''
Initialization that is specific to the Selection interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
# configure selection tree view
treeview = ui_xml.get_object('treeview_selection')
self.sel_model = gtk.ListStore(GdkPixbuf.Pixbuf, str, object)
treeview.set_model(self.sel_model)
# connect selection changed signal
self.sel_selection = treeview.get_selection()
show_button = ui_xml.get_object('button_select_clear')
show_button.set_sensitive(self._isSelectedInView(self.sel_selection))
self.sel_selection.connect('changed',
self._onViewSelectionChanged,
show_button)
self.sel_selection.connect('changed',
self._onSelectionSelected)
self.button_select_all = ui_xml.get_object('button_select_all')
def populateUI(self, acc):
'''
Populate the Selection section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
if acc.childCount > 50:
theme = gtk.IconTheme.get_default()
self.sel_model.append(
[theme.load_icon('gtk-dialog-warning', 24,
gtk.IconLookupFlags.USE_BUILTIN),
_('Too many selectable children'), None])
# Set section as insensitive, but leave expander label sensitive.
section_widgets = self.expander.get_children()
section_widgets.remove(self.expander.get_label_widget())
for child in section_widgets:
child.set_sensitive(False)
return
for child in acc:
if child is not None:
state = child.getState()
if state.contains(pyatspi.STATE_SELECTABLE):
self.sel_model.append([getIcon(child), child.name, child])
state = acc.getState()
multiple_selections = state.contains(pyatspi.STATE_MULTISELECTABLE)
self.button_select_all.set_sensitive(multiple_selections)
if multiple_selections:
self.sel_selection.set_mode = gtk.SelectionMode.MULTIPLE
else:
self.sel_selection.set_mode = gtk.SelectionMode.SINGLE
def _onSelectionSelected(self, selection):
'''
Callback for selection change in the selection treeview. Confusing?
@param selection: The treeview's selection object.
@type selection: gtk.TreeSelection
'''
try:
si = self.node.acc.querySelection()
except NotImplementedError:
return
model, paths = selection.get_selected_rows()
selected_children = [model.get_value(model.get_iter(path), 2).getIndexInParent() for path in paths]
for child_index in range(len(self.node.acc)):
if child_index in selected_children:
si.selectChild(child_index)
else:
si.deselectChild(child_index)
def clearUI(self):
'''
Clear all section-specific data.
'''
self.sel_model.clear()
def _onSelectionClear(self, widget):
'''
Callback for selection clear button.
@param widget: Widget that triggered callback.
@type widget: gtk.Widget
'''
si = self.node.acc.querySelection()
self.sel_selection.unselect_all()
si.clearSelection()
def _onSelectAll(self, widget):
'''
Callback for selection select all button.
@param widget: Widget that triggered callback.
@type widget: gtk.Widget
'''
si = self.node.acc.querySelection()
si.selectAll()
class _SectionStreamableContent(_InterfaceSection):
'''
A class that populates a StreamableContent interface section.
@ivar streams_model: Data model for available streams.
@type streams_model: gtk.ListStore
'''
interface_name = 'StreamableContent'
def init(self, ui_xml):
'''
Initialization that is specific to the StreamableContent interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
# configure streamable content tree view
self.streams_model = ui_xml.get_object('streams_liststore')
def populateUI(self, acc):
'''
Populate the StreamableContent section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
sci = acc.queryStreamableContent()
for content_type in sci.getContentTypes():
self.streams_model.append([content_type,
sci.getURI(content_type)])
def clearUI(self):
'''
Clear all section-specific data.
'''
self.streams_model.clear()
class _SectionTable(_InterfaceSection):
'''
A class that populates a Selection interface section.
@ivar selected_frame: Container frame for selected cell info.
@type selected_frame: gtk.Frame
@ivar caption_label: Caption label.
@type caption_label: gtk.Label
@ivar summary_label: Summary label.
@type summary_label: gtk.Label
@ivar rows_label: Rows label.
@type rows_label: gtk.Label
@ivar columns_label: Columns label.
@type columns_label: gtk.Label
@ivar srows_label: Selected rows label.
@type srows_label: gtk.Label
@ivar scolumns_label: Scolumns label.
@type scolumns_label: gtk.Label
@ivar row_ext_label: Row extents label.
@type row_ext_label: gtk.Label
@ivar col_ext_label: Column extents label.
@type col_ext_label: gtk.Label
@ivar hrow_button: Row header button.
@type hrow_button: gtk.Button
@ivar hcol_button: Column header button.
@type hcol_button: gtk.Button
@ivar cell_button: Cell button.
@type cell_button: gtk.Button
'''
interface_name = 'Table'
def init(self, ui_xml):
'''
Initialization that is specific to the Table interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
self.selected_frame = ui_xml.get_object('selected_cell_frame')
self.caption_label = ui_xml.get_object('table_caption_label')
self.summary_label = ui_xml.get_object('table_summary_label')
self.rows_label = ui_xml.get_object('table_rows_label')
self.columns_label = ui_xml.get_object('table_columns_label')
self.srows_label = ui_xml.get_object('table_srows_label')
self.scolumns_label = ui_xml.get_object('table_scolumns_label')
self.row_ext_label = ui_xml.get_object('table_row_extents')
self.col_ext_label = ui_xml.get_object('table_column_extents')
self.col_ext_label = ui_xml.get_object('table_column_extents')
self.hrow_button = ui_xml.get_object('table_hrow_button')
self.hcol_button = ui_xml.get_object('table_hcol_button')
self.cell_button = ui_xml.get_object('table_cell_button')
def populateUI(self, acc):
'''
Populate the Table section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
ti = acc.queryTable()
self.selected_frame.set_sensitive(False)
for attr, label in [(ti.caption, self.caption_label),
(ti.summary, self.summary_label),
(ti.nRows, self.rows_label),
(ti.nColumns, self.columns_label),
(ti.nSelectedRows, self.srows_label),
(ti.nSelectedColumns, self.scolumns_label)]:
label.set_text(str(attr))
self.registerEventListener(self._accEventTable,
'object:active-descendant-changed')
def clearUI(self):
'''
Clear all section-specific data.
'''
self.caption_label.set_text('')
self.summary_label.set_text('')
self.rows_label.set_text('')
self.columns_label.set_text('')
self.srows_label.set_text('')
self.scolumns_label.set_text('')
self.row_ext_label.set_text('')
self.col_ext_label.set_text('')
self.col_ext_label.set_text('')
self.hrow_button.set_label('')
self.hcol_button.set_label('')
self.cell_button.set_label('')
def _accEventTable(self, event):
'''
Callback for 'object:active-descendant-changed' to detect selected cell
changes.
@param event: The event that triggered the callback.
@type event: Accessibility.Event
'''
if self.node.acc != event.source:
return
acc = event.source
ti = acc.queryTable()
self.selected_frame.set_sensitive(True)
is_cell, row, column, rextents, cextents, selected = \
ti.getRowColumnExtentsAtIndex(event.any_data.getIndexInParent())
for attr, label in [(rextents, self.row_ext_label),
(cextents, self.col_ext_label),
(ti.nSelectedRows, self.srows_label),
(ti.nSelectedColumns, self.scolumns_label)]:
label.set_text(str(attr))
for desc, acc, button in [(ti.getRowDescription(row),
ti.getRowHeader(row),
self.hrow_button),
(ti.getColumnDescription(column),
ti.getColumnHeader(column),
self.hcol_button),
('%s (%s, %s)' % (event.any_data, row, column),
event.any_data,
self.cell_button)]:
button.set_label(str(desc or '<no description>'))
button.set_sensitive(bool(acc))
setattr(button, 'acc', acc)
def _onTableButtonClicked(self, button):
'''
Callback for buttons that represent headers.
Will make the header the main application's selection.
@param button: Button that triggered event.
@type button: gtk.Button
'''
self.node.update(getattr(button, 'acc'))
class _SectionText(_InterfaceSection):
'''
A class that populates a Text interface section.
@ivar attr_model: Data model for text attributes.
@type attr_model: gtk.ListStore
@ivar offset_spin: Offset spinner.
@type offset_spin: gtk.SpinButton
@ivar text_view: Text view of provided text.
@type text_view: gtk.TextView
@ivar text_buffer: Text buffer of provided text.
@type text_buffer: gtk.TextBuffer
@ivar toggle_defaults: Toggle button for viewing default text attributes.
@type toggle_defaults: gtk.CheckButton
@ivar label_start: Label for current attributes start offset.
@type label_start: gtk.Label
@ivar label_end: Label for current attributes end offset.
@type label_end: gtk.Label
@ivar _text_insert_handler: Handler ID for text insert events.
@type _text_insert_handler: integer
@ivar _text_delete_handler: Handler ID for text delete events.
@type _text_delete_handler: integer
@ivar outgoing_calls: Cached outgoing calls to avoid circular event
invocation.
@type outgoing_calls: dictionary
'''
interface_name = 'Text'
def init(self, ui_xml):
'''
Initialization that is specific to the Text interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
# configure text attribute tree view
self.attr_model = ui_xml.get_object('textattrib_liststore')
self.offset_spin = ui_xml.get_object('spinbutton_text_offset')
self.text_view = ui_xml.get_object('textview_text')
self.text_buffer = self.text_view.get_buffer()
self.toggle_defaults = ui_xml.get_object('checkbutton_text_defaults')
self.label_start = ui_xml.get_object('label_text_attr_start')
self.label_end = ui_xml.get_object('label_text_attr_end')
self._text_insert_handler = 0
self._text_delete_handler = 0
mark = self.text_buffer.create_mark('attr_mark',
self.text_buffer.get_start_iter(), True)
self.text_buffer.create_tag('attr_region', foreground='red')
self.text_buffer.connect('mark-set', self._onTextMarkSet)
mark.set_visible(True)
self.text_buffer.connect('modified-changed',
self._onTextModified)
self.text_buffer.connect('notify::cursor-position',
self._onTextCursorMove)
self.text_buffer.set_modified(False)
# Initialize fifos to help eliminate the viscous cycle of signals.
# It would be nice if we could just block/unblock it like in gtk, but
# since it is IPC, asynchronous and not atomic, we are forced to do this.
self.outgoing_calls = {'itext_insert': self.CallCache(),
'itext_delete': self.CallCache()}
def populateUI(self, acc):
'''
Populate the Text section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
self.offset_spin.set_value(0)
ti = acc.queryText()
text = ti.getText(0, ti.characterCount)
self.text_buffer.set_text(text)
self.offset_spin.get_adjustment().upper = ti.characterCount
self.popTextAttr(offset=0)
try:
eti = acc.queryEditableText()
except:
eti = None
expander_label = self.expander.get_label_widget()
label_text = expander_label.get_label()
label_text = label_text.replace(_('(Editable)'), '')
label_text = label_text.strip(' ')
if eti and acc.getState().contains(pyatspi.STATE_EDITABLE):
label_text += ' ' + _('(Editable)')
self.text_view.set_editable(True)
else:
self.text_view.set_editable(False)
expander_label.set_label(label_text)
self._text_insert_handler = self.text_buffer.connect('insert-text',
self._onITextInsert)
self._text_delete_handler = self.text_buffer.connect('delete-range',
self._onITextDelete)
self.registerEventListener(self._accEventText,
'object:text-changed')
def clearUI(self):
'''
Clear all section-specific data.
'''
if self._text_insert_handler:
self.text_buffer.disconnect(self._text_insert_handler)
self._text_insert_handler = 0
if self._text_delete_handler:
self.text_buffer.disconnect(self._text_delete_handler)
self._text_delete_handler = 0
self.offset_spin.set_value(0)
self.label_start.set_text('')
self.label_end.set_text('')
self.text_buffer.set_text('')
self.attr_model.clear()
def _attrStringToDict(self, attr_string):
'''
Convinience method for converting attribute strings to dictionaries.
@param attr_string: "key:value" pairs seperated by semi-colons.
@type attr_string: string
@return: Dictionary of attributes
@rtype: dictionary
'''
if not attr_string:
return {}
attr_dict = {}
for attr_pair in attr_string.split(';'):
key, value = attr_pair.split(':', 1)
if ((key[0]==' ') and (len(key) > 0)): #at-spi 1
key = key[1:]
attr_dict[key] = value
return attr_dict
def _onTextModified(self, text_buffer):
'''
Callback that is triggered when the main text buffer is modified.
Allows to adjust the spinners bounds accordingly.
@param text_buffer: The section's main text buffer.
@type text_buffer: gtk.TextBuffer
'''
self.offset_spin.get_adjustment().upper = text_buffer.get_char_count()
self.offset_spin.set_range(0, text_buffer.get_char_count())
text_buffer.set_modified(False)
def _onTextMarkSet(self, text_buffer, iter, text_mark):
'''
Callback that is triggered when the attribute mark is moved to
allow repopulation of the attributes view.
@param text_buffer: The section's main text buffer.
@type text_buffer: gtk.TextBuffer
@param iter: Text iter of the new mark position.
@type iter: gtk.TextIter
@param text_mark: The text mark that was moved.
@type text_mark: gtk.TextMark
'''
self.popTextAttr()
def _onTextSpinnerChanged(self, spinner):
'''
Callback for hen the spinner's value changes.
Moves attribute mark accordingly.
@param spinner: The marker offset spinner.
@type spinner: gtk.SpinButton
'''
iter = self.text_buffer.get_iter_at_offset(int(self.offset_spin.get_value()))
self.text_buffer.move_mark_by_name('attr_mark', iter)
def _onDefaultsToggled(self, toggle_button):
'''
Callback for when the "defaults" checkbutton is toggled. Re-populates
attributes view.
@param toggle_button: The defaults checkbutton
@type toggle_button: gtk.CheckButton
'''
self.popTextAttr()
def popTextAttr(self, offset=None):
'''
Populate the attributes view with attributes at the given offset, or at
the attribute mark.
@param offset: Offset of wanted attributes. If none is given,
use attribute mark's offset.
@type offset: integer
'''
try:
ti = self.node.acc.queryText()
except:
return
if offset is None:
mark = self.text_buffer.get_mark('attr_mark')
iter = self.text_buffer.get_iter_at_mark(mark)
offset = iter.get_offset()
show_default = self.toggle_defaults.get_active()
attr, start, end = ti.getAttributes(offset)
if show_default:
def_attr = ti.getDefaultAttributes()
attr_dict = self._attrStringToDict(def_attr)
attr_dict.update(self._attrStringToDict(attr))
else:
attr_dict = self._attrStringToDict(attr)
attr_list = list(attr_dict.keys())
attr_list.sort()
self.attr_model.clear()
for attr in attr_list:
self.attr_model.append([attr, attr_dict[attr]])
self.text_buffer.remove_tag_by_name(
'attr_region',
self.text_buffer.get_start_iter(),
self.text_buffer.get_end_iter())
self.text_buffer.apply_tag_by_name(
'attr_region',
self.text_buffer.get_iter_at_offset(start),
self.text_buffer.get_iter_at_offset(end))
# Translators: This string appears in Accerciser's Interface Viewer
# and refers to a range of characters which has a particular format.
# "Start" is the character offset where the formatting begins. If
# the first four letters of some text is bold, the start offset of
# that bold formatting is 0.
self.label_start.set_markup(_('Start: %d') % start)
# Translators: This string appears in Accerciser's Interface Viewer
# and refers to a range of characters which has a particular format.
# "End" is the character offset where the formatting ends. If the
# first four letters of some text is bold, the end offset of that
# bold formatting is 4.
self.label_end.set_markup(_('End: %d') % end)
def _onTextViewPressed(self, widget, event):
'''
Update spin button in the case that the textview was clicked.
Once the spin button's value changes, it's own callback fires which
re-populates the attribute view.
@param widget: The widget that recived the click event,
typically the text view.
@type widget: gtk.Widget
@param event: The click event.
@type event: gtk.gdk.Event
'''
if event.button != 1:
return
x, y = event.get_coords()
x, y = self.text_view.window_to_buffer_coords(gtk.TextWindowType.WIDGET,
int(x), int(y))
iter = self.text_view.get_iter_at_location(x, y)
self.offset_spin.set_value(iter.get_offset())
def _onTextCursorMove(self, text_buffer, param_spec):
'''
Update spinner when input cursor moves.
@param text_buffer: The section's main text buffer.
@type text_buffer: gtk.TextBuffer
@param param_spec: Some gobject crud
@type param_spec: object
'''
self.offset_spin.set_value(text_buffer.get_property('cursor-position'))
def _accEventText(self, event):
'''
Callback for accessible text changes. Updates the text buffer accordingly.
@param event: Event that triggered thi callback.
@type event: Accessibility.Event
'''
if self.node.acc != event.source:
return
if event.type.major == 'text-changed':
text_iter = self.text_buffer.get_iter_at_offset(event.detail1)
if event.type.minor == 'insert':
call = (event.detail1, event.any_data, event.detail2)
if self.outgoing_calls['itext_insert'].isCached(call):
return
self.text_buffer.handler_block(self._text_insert_handler)
self.text_buffer.insert(text_iter, event.any_data)
self.text_buffer.handler_unblock(self._text_insert_handler)
elif event.type.minor == 'delete':
call = (event.detail1, event.detail1 + event.detail2)
if self.outgoing_calls['itext_delete'].isCached(call):
return
text_iter_end = \
self.text_buffer.get_iter_at_offset(event.detail1 + event.detail2)
self.text_buffer.handler_block(self._text_delete_handler)
self.text_buffer.delete(text_iter, text_iter_end)
self.text_buffer.handler_unblock(self._text_delete_handler)
def _onITextInsert(self, text_buffer, iter, text, length):
'''
Callback for text inserts in the text buffer. Sends changes to examined
accessible.
@param text_buffer: The section's main text buffer.
@type text_buffer: gtk.TextBuffer
@param iter: Text iter in which the insert occured.
@type iter: gtk.TextIter
@param text: The text that was inserted
@type text: string
@param length: The length of theinserted text.
@type length: integer
'''
try:
eti = self.node.acc.queryEditableText()
except:
return
call = (iter.get_offset(), text, length)
self.outgoing_calls['itext_insert'].append(call)
eti.insertText(*call)
def _onITextDelete(self, text_buffer, start, end):
'''
Callback for text deletes in the text buffer. Sends changes to examined
accessible.
@param text_buffer: The section's main text buffer.
@type text_buffer: gtk.TextBuffer
@param start: The start offset of the delete action.
@type start: integer
@param end: The end offset of the delete action.
@type end: integer
'''
try:
eti = self.node.acc.queryEditableText()
except:
return
call = (start.get_offset(), end.get_offset())
self.outgoing_calls['itext_delete'].append(call)
eti.deleteText(*call)
def _onTextFocusChanged(self, text_view, event):
'''
Callback for leaving and entering focus from the textview,
it hides/shows the attribute marker. When the textview has focus
there is no need for the marker to be visible because of th input
cursor.
@param text_view: The text view that is being entered or leaved.
@type text_view: gtk.TextView
@param event: The focus event.
@type event: gtk.gdk.Event
'''
mark = self.text_buffer.get_mark('attr_mark')
mark.set_visible(not event.in_)
class CallCache(list):
'''
A list derivative that provides a method for checking if something
is in the list and removing it at the same time.
'''
def isCached(self, obj):
'''
Checks if a certain object is in this list instance. If it is, return
True and remove it.
@param obj: Object to check for.
@type obj: object
@return: True if it is in the list.
@rtype: boolean
'''
if obj in self:
self.remove(obj)
return True
else:
return False
class _SectionValue(_InterfaceSection):
'''
A class that populates a Value interface section.
@ivar spinbutton: Value spinner.
@type spinbutton: gtk.SpinButton
@ivar label_max: Label of maximal value.
@type label_max: gtk.Label
@ivar label_min: Label of minimal value.
@type label_min: gtk.Label
@ivar label_inc: Label of minimal value increment.
@type label_inc: gtk.Label
'''
interface_name = 'Value'
def init(self, ui_xml):
'''
Initialization that is specific to the Value interface
(construct data models, connect signals to callbacks, etc.)
@param ui_xml: Interface viewer glade xml.
@type ui_xml: gtk.glade.XML
'''
self.spinbutton = ui_xml.get_object('spinbutton_value')
self.label_max = ui_xml.get_object('label_value_max')
self.label_min = ui_xml.get_object('label_value_min')
self.label_inc = ui_xml.get_object('label_value_inc')
self.registerEventListener(self._accEventValue,
'object:value-changed')
def populateUI(self, acc):
'''
Populate the Value section with relevant data of the
currently selected accessible.
@param acc: The currently selected accessible.
@type acc: Accessibility.Accessible
'''
vi = acc.queryValue()
self.label_max.set_text(str(vi.maximumValue))
self.label_min.set_text(str(vi.minimumValue))
self.label_inc.set_text(str(vi.minimumIncrement))
minimumIncrement = vi.minimumIncrement
digits = 0
while minimumIncrement - int(minimumIncrement) != 0:
digits += 1
minimumIncrement *= 10
# Calling set_range will clamp the value of spinbutton to the allowable
# range, causing us to try to set the value of the accessible when we
# really shouldn't.
self.ignore_value_changes = True
self.spinbutton.set_range(vi.minimumValue, vi.maximumValue)
self.ignore_value_changes = False
self.spinbutton.set_value(vi.currentValue)
self.spinbutton.set_digits(digits)
def _onValueSpinnerChange(self, spinner):
'''
Callback for spinner changes. Updates accessible.
@param spinner: The Value spinner
@type spinner: gtk.SpinButton
'''
if self.ignore_value_changes: return
vi = self.node.acc.queryValue()
vi.currentValue = spinner.get_value()
def _accEventValue(self, event):
'''
Callback for value changes from the accessible. Update spin button.
@param event: The event that triggered the callback.
@type event: Accessibility.Event
'''
if self.node.acc != event.source:
return
vi = self.node.acc.queryValue()
if self.spinbutton.get_value() != vi.currentValue:
self.spinbutton.set_value(vi.currentValue)
|