Skip to content

Commit

Permalink
A script to read the URL that the link under the cursor points was im…
Browse files Browse the repository at this point in the history
…plemented.

Works in web pages in Firefox and messages in Thunderbird with browse mode on.
Also, other minor fixes and improvements.
  • Loading branch information
Javi Domínguez committed Oct 31, 2023
1 parent fffab1b commit 11319df
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 70 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@
* Also, you can assign, in NVDA preferences, an alternative gesture to display the toolbar buttons which is more comfortable for you than twice pressing.
* NVDA+Control+N Reads the last notification and it takes the system focus to it if it is possible. By pressing two times quickly shows the history of notifications.
* NVDA+F6 Brings the focus to the document.
* Dot (.) With browse mode enabled, if the cursor is over a link, reads the URL it points to (This key cannot be customized).

## Thunderbird

* In a message window:
* Control+Shift+(1-9) Reads the sender and recipients of the message. If pressed twice quickly, opens the options menu.
* Alt+Control+Shift+1-9 opens the options menu too; Use it if twice pressing does not work well.
* Control+Shift+A Brings the focus to the list of attachments, if any.
* NVDA+F6 Brings the focus to the body of the message
* Control+Shift+A Brings the focus to the list of attachments, if any.

(These scripts are also available in the list of messages if you activate the preview pane.)

* In message body with browse mode enabled, if the cursor is over a link, dot key reads the URL it points to (This key cannot be customized).

* In messages list:
* If the preview pane is active, press NVDA+downArrow (desktop) or NVDA+A (laptop) to read the message without leaving the list.
* Control+NVDA+(1-9) Read the information in the corresponding column.

Keystrokes can be customized in Preferences of NVDA > Input gestures when Firefox or Thunderbird are open.
Gestures can be customized in Preferences of NVDA > Input gestures when Firefox or Thunderbird are open.

In NVDA Preferences > Options > Mozilla Thunderbird you can enable/disable automatic message reading in the preview pane.
c
24 changes: 20 additions & 4 deletions addon/appModules/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@
from threading import Timer
from urllib.parse import urlparse
import re
import treeInterceptorHandler
import browseMode
from . import shared

addonHandler.initTranslation()

class AppModule(AppModule):

tbDialog = None

#TRANSLATORS: category for Firefox input gestures
scriptCategory = _("mozilla Firefox")

def __init__(self, *args, **kwargs):
super(AppModule, self).__init__(*args, **kwargs)
self.tbDialog = None
setattr(browseMode.BrowseModeTreeInterceptor, "script_linkURL", shared.linkURL)

def event_alert(self, obj, nextHandler):
try:
if obj.IA2Attributes["id"] == "customizationui-widget-panel":
Expand Down Expand Up @@ -82,6 +87,12 @@ def event_alert(self, obj, nextHandler):
shared.notificationsDialog.registerFirefoxNotification((datetime.now(), alertText))
nextHandler()

def event_gainFocus(self, obj, nextHandler):
if obj.role == controlTypes.Role.DOCUMENT:
if hasattr(obj, "treeInterceptor") and isinstance(obj.treeInterceptor, treeInterceptorHandler.TreeInterceptor):
obj.treeInterceptor.bindGesture("kb:.", "linkURL")
nextHandler()

def script_status(self, gesture):
if not self.inMainWindow():
#TRANSLATORS: message spoken by NVDA when the focus is not in the main Firefox window
Expand All @@ -96,7 +107,7 @@ def script_status(self, gesture):
except StopIteration:
pass
try:
ui.message(obj.name)
ui.message(obj.firstChild.name)
except NameError:
#TRANSLATORS: message spoken when there is no status bar in Firefox
ui.message (_("Status bar not found"))
Expand All @@ -111,6 +122,11 @@ def script_status(self, gesture):
#TRANSLATORS: message shown in Input gestures dialog for this script
script_status.__doc__ = _("Reads the status bar. If pressed twice quickly, copies it to clipboard.")

@scriptHandler.script(gesture="kb:nvda+numpadPlus")
def script_linkURL(self, gesture):
if not shared.linkURL():
gesture.send()

def script_url(self, gesture):
if not self.inMainWindow():
#TRANSLATORS: message spoken by NVDA when the focus is not in the main Firefox window
Expand Down Expand Up @@ -229,7 +245,7 @@ def script_focusDocument(self, gesture):
if group:
for propertyPage in filter(lambda o: o.role == controlTypes.Role.PROPERTYPAGE, group.children):
try:
doc = filter(lambda o: o.role == controlTypes.Role.INTERNALFRAME and controlTypes.State.FOCUSABLE in o.states, propertyPage.children)[0].children[0]
doc = next(filter(lambda o: o.role == controlTypes.Role.INTERNALFRAME and controlTypes.State.FOCUSABLE in o.states, propertyPage.children)).children[0]
break
except IndexError:
pass
Expand Down
26 changes: 21 additions & 5 deletions addon/appModules/shared/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import controlTypes
import gui
import re
import scriptHandler
import speech
import ui
import wx

addonHandler.initTranslation()
Expand Down Expand Up @@ -99,6 +101,19 @@ def searchAmongTheChildren(id, into):
obj = obj.next
return(obj)

def linkURL(obj=None, gesture=None):
obj = api.getReviewPosition().focusableNVDAObjectAtStart
if obj.role == controlTypes.Role.LINK and obj.value:
if scriptHandler.getLastScriptRepeatCount() == 1:
if api.copyToClip(obj.value):
#TRANSLATORS: message spoken when an item hast just been copied to the clipboard
ui.message(_("Copied to clipboard"))
ui.message(obj.value)
return True
ui.message(_("The cursor must be over a link to read its URL."))
return False
linkURL.__doc__ = _("Reads the URL of the link under the cursor, pressing twice quickly copies it to the clipboard.")

class TabPanel(wx.Panel):

def __init__(self, parent, lbLabel):
Expand Down Expand Up @@ -137,10 +152,11 @@ def onKeyDown(self, event):
menu = wx.Menu()
item = menu.Append(wx.ID_ANY, _("Refresh F5"))
self.Bind(wx.EVT_MENU, self.onMenuRefresh, item)
item = menu.Append(wx.ID_ANY, _("Delete item Supr"))
self.Bind(wx.EVT_MENU, self.onMenuDelete, item)
item = menu.Append(wx.ID_ANY, _("Clear all"))
self.Bind(wx.EVT_MENU, self.onMenuClear, item)
if self.TopLevelParent.history[self.Parent.GetPageText(self.Parent.Selection)]:
item = menu.Append(wx.ID_ANY, _("Delete item Supr"))
self.Bind(wx.EVT_MENU, self.onMenuDelete, item)
item = menu.Append(wx.ID_ANY, _("Clear all"))
self.Bind(wx.EVT_MENU, self.onMenuClear, item)
self.listBox.PopupMenu(menu, self.listBox.ScreenPosition)
# Delete list item
elif event.GetKeyCode() == wx.WXK_DELETE and event.EventObject == self.listBox:
Expand All @@ -166,7 +182,7 @@ def updateList(self):
else:
self.listBox.SetItems(["%s, %s" % (elapsedFromTimestamp(i[0]), i[1].split("\n")[0]) for i in self.TopLevelParent.history[self.Parent.GetPageText(self.Parent.Selection)]])
self.text.Enabled = True
self.text.SetValue(self.TopLevelParent.history[self.Parent.GetPageText(self.Parent.Selection)][0][1])
self.text.SetValue(self.TopLevelParent.history[self.Parent.GetPageText(self.Parent.Selection)][0][1])
self.listBox.SetSelection(0)
self.listBox.SetFocus()

Expand Down
6 changes: 6 additions & 0 deletions addon/appModules/thunderbird.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import addonHandler
import api
import browseMode
import config
import controlTypes
import globalCommands
Expand Down Expand Up @@ -54,6 +55,8 @@ def __init__(self, *args, **kwargs):
self.docCache = None
self.previewPane = None
NVDASettingsDialog.categoryClasses.append(ThunderbirdPanel)
setattr(browseMode.BrowseModeTreeInterceptor, "script_linkURL", shared.linkURL)
setattr(browseMode.BrowseModeTreeInterceptor, "script_linkURL", shared.linkURL)

if int(self.productVersion.split(".")[0]) < 115:
raise RuntimeError(_("The addon Mozilla Apps Enhancements is not compatible with this version of Thunderbird. The application module will be temporarily disabled."))
Expand Down Expand Up @@ -106,6 +109,9 @@ def event_gainFocus(self, obj, nextHandler):
)
except:
pass
if obj.role == controlTypes.Role.DOCUMENT:
if hasattr(obj, "treeInterceptor") and isinstance(obj.treeInterceptor, treeInterceptorHandler.TreeInterceptor):
obj.treeInterceptor.bindGesture("kb:.", "linkURL")
nextHandler()

def event_focusEntered(self, obj, nextHandler):
Expand Down
5 changes: 4 additions & 1 deletion addon/doc/es/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
* También puede asignar, en las preferencias de NVDA, un gesto alternativo que le resulte más cómodo que la doble pulsación para mostrar los botones de la barra de herramientas.
* NVDA+Control+N Lee la última notificación y lleva el foco del sistema a ella si es posible. Pulsando dos veces rápidamente muestra el historial de notificaciones.
* NVDA+F6 Lleva el foco al documento.
* Punto (.) Con el modo de exploración activado, si el cursor está sobre un enlace, lee la URL a la que apunta. Esta tecla no se puede personalizar.

## Thunderbird

* En una ventana de mensaje:
* Control+Shift+(1-9) Lee el remitente y los destinatarios del mensaje. Si se pulsa dos veces rápidamente, abre el menú de opciones.
* Alt + Control + Shift + 1-9 también abre el menú de opciones; Úselo si la doble pulsación no funciona bien.
* Control+Shift+A Lleva el foco a la lista de adjuntos si los hay.
* NVDA+F6 Lleva el foco al texto del mensaje.
* NVDA+F6 Lleva el foco al cuerpo del mensaje.

(Estos scripts también están disponibles en la lista de mensajes con el panel de vista previa activo.)

* En el cuerpo del mensaje con el modo de exploración activado, si el cursor está sobre un enlace, la tecla punto (.) lee la URL a la que apunta. Esta tecla no se puede personalizar.

* En la lista de mensajes:
* Si el panel de vista previa está activado, pulsa NVDA + flecha abajo (sobremesa) o NVDA+A (portátil) para leer el mensaje sin salir de la lista.
* Control+NVDA+(1-9) Lee la información de la columna correspondiente.
Expand Down
Loading

0 comments on commit 11319df

Please sign in to comment.