Skip to content

Commit d88a5fd

Browse files
authored
Merge pull request #3 from make4all/vpotluri/pre-review-cleanup
Addressed feedback from NVDA
2 parents 3afe3ad + a723725 commit d88a5fd

File tree

5 files changed

+41
-49
lines changed

5 files changed

+41
-49
lines changed

addon/appModules/chrome/__init__.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import review
1414
import wx
1515
import gui
16+
import textInfos
1617
import threading
1718
from .spritesTable import SpritesTable
1819
from .dialogs import SearchDialog
@@ -98,13 +99,12 @@ def post_handleCaretMove(self, pos, *args, **kwargs):
9899
'''
99100
try:
100101
original_handleCaretMove(pos, *args, **kwargs)
101-
nav = api.getNavigatorObject()
102-
tableInfo = self.getTableInfo(nav)
102+
tableInfo = self.getTableInfo()
103103
if tableInfo and not self.hasAnnouncedTable and not self.spritesMode:
104104
self.hasAnnouncedTable = True
105105
# Translators: message announcing sprites mode is available upon entry to a table
106106
ui.message(_('Sprites mode available. Press NVDA+Shift+T to activate.'))
107-
self.logHelper.logTableFound(None, None, tableInfo[0].rowCount, tableInfo[0].columnCount)
107+
self.logHelper.logTableFound(None, None, tableInfo[1], tableInfo[2])
108108
if not tableInfo:
109109
self.hasAnnouncedTable = False
110110
except Exception:
@@ -152,12 +152,11 @@ def script_spritesOn(self, gesture):
152152
Toggle sprites mode on and set up the table state and gestures
153153
'''
154154
try:
155-
nav = api.getNavigatorObject()
156155
# retreive the table object and tableID if available
157-
tableInfo = self.getTableInfo(nav)
156+
tableInfo = self.getTableInfo()
158157
if tableInfo:
159-
tableObj, tableID = tableInfo
160-
self.table = SpritesTable(tableObj, tableID, len(self.rowKeys), len(self.columnKeys))
158+
tableID, rowCount, columnCount = tableInfo
159+
self.table = SpritesTable(tableID, rowCount, columnCount, len(self.rowKeys), len(self.columnKeys))
161160
# Translators: message announcing sprites mode activation and the key to exit
162161
ui.message(_('Sprites mode on. Press escape to exit. Press F to enter search mode.'))
163162
# bind gestures to the table
@@ -167,7 +166,7 @@ def script_spritesOn(self, gesture):
167166
self.spritesID = int(config.conf['sprites']['spritesID']) + 1
168167
config.conf['sprites']['spritesID'] = self.spritesID
169168
self.logHelper.logSpritesToggle(self.spritesID, None, 'on')
170-
self.logHelper.logTableInfo(self.spritesID, None, tableObj.rowCount, tableObj.columnCount)
169+
self.logHelper.logTableInfo(self.spritesID, None, rowCount, columnCount)
171170
self.speakMapping()
172171
self.spritesMode = True
173172
else:
@@ -177,7 +176,7 @@ def script_spritesOn(self, gesture):
177176
self.logHelper.logErrorException(None, None, traceback.format_exc())
178177

179178

180-
def getTableInfo(self, nav):
179+
def getTableInfo(self):
181180
'''
182181
Returns the table object and the tableID associated with the given navigator object
183182
Returns None if the navigator is currently not in a table
@@ -186,20 +185,22 @@ def getTableInfo(self, nav):
186185
try:
187186
selection = focus.treeInterceptor.selection
188187
tableID, origRow, origCol, origRowSpan, origColSpan = focus.treeInterceptor._getTableCellCoords(selection)
188+
if selection.isCollapsed:
189+
selection = selection.copy()
190+
selection.expand(textInfos.UNIT_CHARACTER)
191+
fields = list(selection.getTextWithFields())
192+
for field in fields:
193+
if not (isinstance(field, textInfos.FieldCommand) and field.command == "controlStart"):
194+
# Not a control field.
195+
continue
196+
attrs = field.field
197+
tableID = attrs.get('table-id')
198+
if tableID is not None:
199+
break
200+
return (attrs["table-id"],
201+
int(attrs["table-rowcount"]), int(attrs["table-columncount"]))
189202
except (AttributeError, LookupError):
190203
return None
191-
try:
192-
while nav.parent and not nav.table:
193-
nav = nav.parent
194-
except NotImplementedError:
195-
return None
196-
if not nav.parent:
197-
return None
198-
# found table
199-
if nav.role == controlTypes.ROLE_TABLE:
200-
return nav, tableID
201-
elif nav.table:
202-
return nav.table, tableID
203204

204205
def bindSpritesGesture(self):
205206
'''
@@ -429,7 +430,7 @@ def speakCell(self, row=None, column=None):
429430
currRow, currColumn = self.table.getCurrPosition()
430431
if self.table.hasResultAt(currRow, currColumn):
431432
ui.message(_('Found'))
432-
speech.speakTextInfo(info, formatConfig=formatConfig, reason=controlTypes.REASON_CARET)
433+
speech.speakTextInfo(info, formatConfig=formatConfig, reason=controlTypes.OutputReason.CARET)
433434
# Announce other occurrences on the same row/column
434435
# if the given position contains search result, would exclude current position
435436
# when calculating the occurrences

addon/appModules/chrome/spritesTable.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class SpritesTable():
1111
'''
1212
A class keeping track of the states of the sprites table
1313
'''
14-
def __init__(self, tableObj, tableID, rowKeyCount, columnKeyCount, test=False):
14+
def __init__(self, tableID, rowCount, columnCount, rowKeyCount, columnKeyCount, test=False):
1515
self.tableID = tableID
1616
if not test:
1717
self.interceptor = api.getFocusObject().treeInterceptor
1818

1919
# stores the initial row and column count for the table object
20-
self.rowCount = tableObj.rowCount
21-
self.columnCount = tableObj.columnCount
20+
self.rowCount = rowCount
21+
self.columnCount = columnCount
2222
# list of row and column index including all rows and columns
2323
self.allRows = [r + 1 for r in range(self.rowCount)]
2424
self.allColumns = [c + 1 for c in range(self.columnCount)]
@@ -70,7 +70,7 @@ def getCellAt(self, row=None, column=None):
7070
info = self.interceptor._getTableCellAt(self.tableID, selection, self.currRow, self.currColumn)
7171
# move browse mode selection
7272
self.interceptor.selection = info
73-
log.info(f'switch to row {self.currRow} column {self.currColumn}')
73+
# log.info(f'switch to row {self.currRow} column {self.currColumn}')
7474
return info
7575

7676
def changeRowOffset(self, delta):
@@ -166,8 +166,6 @@ def searchTable(self, keyword, caseSensitive, filterRows, filterColumns, onCompl
166166
if m:
167167
foundCells.append((r, c))
168168
startPos = info
169-
log.info('logging found rows and columns')
170-
log.info(foundCells)
171169
if foundCells:
172170
self.searchResults = foundCells
173171
self.searchTerm = keyword

addon/appModules/chrome/tests.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import unittest
22
from spritesTable import SpritesTable
33

4-
5-
class DummyTable:
6-
def __init__(self, rowCount, columnCount):
7-
self.rowCount = rowCount
8-
self.columnCount = columnCount
9-
10-
114
class TestSpritesTable(unittest.TestCase):
125
def testInit(self):
13-
t = SpritesTable(DummyTable(3, 4), 1, 5, 13, True)
6+
t = SpritesTable(1, 3, 4, 5, 13, True)
147
self.assertEqual(t.tableID, 1)
158
self.assertEqual(t.rowCount, 3)
169
self.assertEqual(t.columnCount, 4)
@@ -32,7 +25,7 @@ def testInit(self):
3225
self.assertFalse(t.filterColumns)
3326

3427
def testChangeRowOffset(self):
35-
t = SpritesTable(DummyTable(3, 4), 1, 5, 13, True)
28+
t = SpritesTable(1, 3, 4, 5, 13, True)
3629
t.changeRowOffset(2)
3730
self.assertEqual(t.currRow, 3)
3831
t.changeRowOffset(-1)
@@ -42,7 +35,7 @@ def testChangeRowOffset(self):
4235
self.assertEqual(t.currRow, 1)
4336

4437
def testChangeColumnOffset(self):
45-
t = SpritesTable(DummyTable(3, 4), 1, 5, 13, True)
38+
t = SpritesTable(1, 3, 4, 5, 13, True)
4639
t.changeColumnOffset(3)
4740
self.assertEqual(t.currColumn, 4)
4841
t.changeColumnOffset(-1)
@@ -52,7 +45,7 @@ def testChangeColumnOffset(self):
5245
self.assertEqual(t.currColumn, 1)
5346

5447
def testScrollRowsRegular(self):
55-
t = SpritesTable(DummyTable(6, 4), 1, 5, 13, True)
48+
t = SpritesTable(1, 6, 4, 5, 13, True)
5649
# cannot scroll to previous at start
5750
self.assertFalse(t.scroll(direction=0, keyIdx=0))
5851
self.assertTrue(t.scroll(direction=0, keyIdx=4))
@@ -66,7 +59,7 @@ def testScrollRowsRegular(self):
6659

6760
def testScrollRowsEdge(self):
6861
# test table with 10 rows
69-
t = SpritesTable(DummyTable(10, 4), 1, 5, 13, True)
62+
t = SpritesTable(1, 10, 4, 5, 13, True)
7063
# cannot scroll to previous at start
7164
self.assertFalse(t.scroll(direction=0, keyIdx=0))
7265
self.assertTrue(t.scroll(direction=0, keyIdx=4))
@@ -80,7 +73,7 @@ def testScrollRowsEdge(self):
8073

8174
def testScrollColumnsRegular(self):
8275
# assume 3 keys for navigate columns
83-
t = SpritesTable(DummyTable(6, 4), 1, 5, 3, True)
76+
t = SpritesTable(1, 6, 4, 5, 3, True)
8477
# cannot scroll to previous at start
8578
self.assertFalse(t.scroll(direction=1, keyIdx=0))
8679
self.assertTrue(t.scroll(direction=1, keyIdx=2))
@@ -94,7 +87,7 @@ def testScrollColumnsRegular(self):
9487

9588
def testScrollColumnsEdge(self):
9689
# test table with 6 columns
97-
t = SpritesTable(DummyTable(6, 6), 1, 5, 3, True)
90+
t = SpritesTable(1, 6, 6, 5, 3, True)
9891
# cannot scroll to previous at start
9992
self.assertFalse(t.scroll(direction=1, keyIdx=0))
10093
self.assertTrue(t.scroll(direction=1, keyIdx=2))
@@ -107,7 +100,7 @@ def testScrollColumnsEdge(self):
107100
self.assertFalse(t.scroll(direction=1, keyIdx=0))
108101

109102
def testNextResult(self):
110-
t = SpritesTable(DummyTable(4, 5), 1, 5, 13, True)
103+
t = SpritesTable(1, 4, 5, 5, 13, True)
111104
t.searchResults = [(1, 1), (2, 3), (3, 3), (3, 4), (3, 5)]
112105
# go through all results using next
113106
self.assertTrue(t.nextResult())
@@ -129,7 +122,7 @@ def testNextResult(self):
129122
self.assertEqual(t.getMappedColumns(), [5])
130123

131124
def testPrevResult(self):
132-
t = SpritesTable(DummyTable(4, 5), 1, 5, 13, True)
125+
t = SpritesTable(1, 4, 5, 5, 13, True)
133126
t.searchResults = [(1, 1), (2, 3), (3, 3), (3, 4), (3, 5)]
134127
t.resultIdx = 4
135128
t.onSearchResult = True
@@ -154,7 +147,7 @@ def testPrevResult(self):
154147
self.assertEqual(t.getCurrPosition(), (1, 1))
155148

156149
def testGetOccurrences(self):
157-
t = SpritesTable(DummyTable(4, 5), 1, 5, 13, True)
150+
t = SpritesTable(1, 4, 5, 5, 13, True)
158151
t.searchResults = [(1, 1), (2, 3), (3, 3), (3, 4), (3, 5)]
159152
# start off at (1, 1)
160153
self.assertEqual(t.getOccurrences(), (0, 0))
@@ -172,7 +165,7 @@ def testGetOccurrences(self):
172165
self.assertEqual(t.getOccurrences(), (0, 0))
173166

174167
def testFilters(self):
175-
t = SpritesTable(DummyTable(4, 5), 1, 5, 13, True)
168+
t = SpritesTable(1, 4, 5, 5, 13, True)
176169
t.searchResults = [(1, 1), (2, 3), (3, 3), (3, 4), (3, 5)]
177170
t.filterRows = True
178171
t.checkAndApplyFilters()
@@ -195,7 +188,7 @@ def testFilters(self):
195188
self.assertEqual(t.columns, [1, 2, 3, 4, 5])
196189

197190
def testExpandTable(self):
198-
t = SpritesTable(DummyTable(8, 10), 1, 5, 4, True)
191+
t = SpritesTable(1, 8, 10, 5, 4, True)
199192
t.searchResults = [(2, 2), (4, 7), (6, 3)]
200193
t.filterRows = True
201194
t.resultIdx = 0

addon/manifest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ summary = "Sprites table navigation for Chrome"
33
description = """This addon introduces a non-linear navigation mode called SPRITEs to navigate tables on webpages browsed using google Chrome."""
44
author = "Venkatesh Potluri <[email protected]>"
55
url = https://make4all.github.io/sprites/tutorial/tutorial.html
6-
version = 0.9
6+
version = 0.9.1
77
docFileName = readme.html
88
minimumNVDAVersion = 2020.3
99
lastTestedNVDAVersion = 2021.1

buildVars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _(arg):
2525
# Translators: Long description to be shown for this add-on on add-on information from add-ons manager
2626
"addon_description": _("""This addon introduces a non-linear navigation mode called SPRITEs to navigate tables on webpages browsed using google Chrome."""),
2727
# version
28-
"addon_version": "0.9",
28+
"addon_version": "0.9.1",
2929
# Author(s)
3030
"addon_author": "Venkatesh Potluri <[email protected]>",
3131
# URL for the add-on documentation support

0 commit comments

Comments
 (0)