0

When we create a simple web page and read this line with NVDA shortcut key H it will be read as "Flash Sale heading level three"

<h3 class="hp-mod-card-title">Flash Sale</h3>

But is there a way to assign this Flash Sale to a python variable?. Really sorry I'm bit new to this.

import globalPluginHandler
import ui

class GlobalPlugin(globalPluginHandler.GlobalPlugin):

        def script_sayHeader(self, gesture):
                x = "Header 123"
                ui.message(x + 'is a nice header')

        __gestures={
                "kb:h":"sayHeader"
        }

This is the code for a global plugin I created and I need to add a current header or shortcut key value to this x. This is a sample code and what I intend to do is a bit complicated.

I tried adding this too but still showing only page title all the time :(

import globalPluginHandler
import ui
import api #added this

class GlobalPlugin(globalPluginHandler.GlobalPlugin):

        def script_sayHeader(self, gesture):
                x = api.getNavigatorObject().name #added this
                ui.message(x + 'is a nice header')

        __gestures={
                "kb:h":"sayHeader"
        }

1 Answers1

0

Have you tried with x = api.getNavigatorObject().name?

Developer info for navigator object:
name: u'Flash Sale'
role: ROLE_HEADING
states: 
isFocusable: False
hasFocus: False
Python object: <NVDAObjects.IAccessible.mozilla.Mozilla object at 0x1AFE9C70>
Python class mro: (<class 'NVDAObjects.IAccessible.mozilla.Mozilla'>, <class 'NVDAObjects.IAccessible.ia2Web.Ia2Web'>, <class 'NVDAObjects.IAccessible.IAccessible'>, <class 'NVDAObjects.window.Window'>, <class 'NVDAObjects.NVDAObject'>, <class 'documentBase.TextContainerObject'>, <class 'baseObject.ScriptableObject'>, <class 'baseObject.AutoPropertyObject'>, <type 'object'>)
description: u''
location: RectLTWH(left=156, top=190, width=1710, height=33)

You can retrieve these infos at any time via the log viewer (NVDA+f1). Sorry if I misunderstood the question.

  • I added it and still not getting it. I updated my answer. Really sorry if I'm wrong since I'm so new to this :( And do I need to use app module? – Jaya Balasooriya Jul 08 '19 at 19:26
  • What exactly do you want this script to do? If I have understood correctly, when you press the quick nav key "h" (to go on the following h1-h6), you want: - hear "'foo bar' heading level 1 is a nice header" - retrieve "foo bar" in a variable. Is that right? –  Jul 09 '19 at 09:11