Script issue on getting text
שמואל רטבי
Hello all Thank you to allwhose help was very useful so far. In the following lines of script, I try to get text at the caret position : FO = api.getFocusObject() T = FO.makeTextInfo(textInfos.POSITION_CARET) T.expand(textInfos.UNIT_WORD) The Word = T.text
If the caret happens not to be at some character position, the expression T.text Causes an error (something like : Invalid NVDAObject start point… or so What is the simplest way to catch the error before it occurs and have TheWord = "Nothing at cursor position" Note : I tried "Try" but I don't get out of it without some bones broken… Thanks in advance Shmuel
|
|
Noelia Ruiz
Hello: One of the possibilities maybe:
toggle quoted messageShow quoted text
try: T = FO.makeTextInfo(textInfos.POSITION_CARET) T.expand(textInfos.UNIT_WORD) The Word = T.text except Exception as e (or probably better Except NotImplementedError): ui.message"No word at caret position"). Hope this helps. 2021-02-21 17:02 GMT+01:00, שמואל רטבי <shretbi@gmail.com>:
Hello all
|
|
שמואל רטבי
Thanks Noelia
toggle quoted messageShow quoted text
Of course "this" helps, as usual... Shmuel
-----Original Message-----
From: nvda-addons@nvda-addons.groups.io <nvda-addons@nvda-addons.groups.io> On Behalf Of Noelia Ruiz Sent: Sunday, February 21, 2021 6:56 PM To: nvda-addons@nvda-addons.groups.io Subject: Re: [nvda-addons] Script issue on getting text Hello: One of the possibilities maybe: try: T = FO.makeTextInfo(textInfos.POSITION_CARET) T.expand(textInfos.UNIT_WORD) The Word = T.text except Exception as e (or probably better Except NotImplementedError): ui.message"No word at caret position"). Hope this helps. 2021-02-21 17:02 GMT+01:00, שמואל רטבי <shretbi@gmail.com>: Hello all
|
|