Repository: nvaccess/nvda

Issue:
2 instances of "Input gestures" dialog open
<!-- Please read the text in this edit field before filling it in.
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/blob/master/devDocs/githubIssueTemplateExplanationAndExamples.md
Please also note that the NVDA project has a Citizen and Contributor Code of Conduct which can be found at https://github.com/nvaccess/nvda/blob/master/CODE_OF_CONDUCT.md. NV Access expects that all contributors and other community members read and abide by the rules set out in this document while participating or contributing to this project. This includes creating or commenting on issues and pull requests. 

Each of the questions and sections below start with multiple hash symbols (#). Place your answers and information on the blank line below each question.
-->

### Steps to reproduce:
- launch nvda with add-ons disabled,
- display the "Input gestures" dialog,
- press "end" to select the last category,
- go up two categories to select the "tools" category (english language, , "mouse" category for french language),
- then "shift+tab" to position the cursor in the "filter" field,
- type "z".
### Actual behavior:
A series of errors appear in the log.
Then, each time the "Input gestures" dialog is restarted, a new error is entered in the log.
### Expected behavior:
No error in the log.
### System configuration
#### NVDA installed/portable/running from source:
NVDA 2021.1.3 installed, NVDA 2022.1 portable and NVDA 2022.2 beta portable
#### NVDA version:
It seems that the problem occurs on all versions of NVDA.

#### Windows version:
Windows 10 21H1 (10.0.19043) workstation

#### Name and version of other software in use when RASreproducing the issue:
None
#### Other information about your system:
None
### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
Yes. Same problem.
#### If NVDA add-ons are disabled, is your problem still occurring?
Yes.
#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Yes.


Discussion:
Thanks @paulber19 for taking care of reporting this issue on GitHub.

Additional information:

1. This issue has first been reported on a [thread](https://nvda.groups.io/g/nvda/topic/92062474?p=Created,,,100,1,0,0::recentpostdate/sticky,,,100,2,0,92062474,previd=1656521897216851032,nextid=1654197375300790093) on the NVDA mailing list.

2. A consequence of this error is that you may be able to open two instance of the input gesture dialog, what is not an wanted behaviour. For this, after the initial STR (Steps To Reproduce) of this issue, do the following:
* Close the Input gesture dialog
* Open the Input gesture dialog
* Open the Input gesture dialog

3. An alternative way to reproduce it is described in [this message](https://nvda.groups.io/g/nvda/message/97038).

Hi,
For information, in my add-on, I managed to avoid the registration of 
errors in the log.
It does not correct the indexing error, but it prevents it.
I found that each type of character in the "filter by:" field makes a 
call to the "doRefresh" method of the treeessence.
This method refreshes the elements of the tree species according to the 
result of the filtering and generates a series of "EVT_TREE_SEL_CHANGED" 
events which are processed by the "onTreeSelect" method.
The latter method systematically updates the state of the "Add" and 
"Remove" buttonsby calling the "_refreshButtonState" method..
It is in this method that the error occurs when the call to 
"getSelectedItemData" is made to know the selected item.
As I think that it is useless to update the state of these buttons 
during the refresh of the tree essence and that it is enough to do it 
during the selection of the last element, I worked around the problem by 
delaying the updating of the state of the buttons.
So I modified the method like this:
     def onTreeSelect(self, evt):
         if evt:
             evt.Skip()
         if self.refreshButtonStateDelay is not None:
             self.refreshButtonStateDelay.Stop()
         self.refreshButtonStateDelay = wx.CallLater(50, 
self._refreshButtonState)
And reset the timer refreshButtonStateDelay  in the 
"_refreshButtonState" method.

Best regards.
Paul.
Le 29/06/2022 22:04, Cyrille Bougot a écrit :
>
> Thanks @paulber19 <https://github.com/paulber19> for taking care of 
> reporting this issue on GitHub.
>
> Additional information:
>
> 1.
>
>     This issue has first been reported on a thread
>     <https://nvda.groups.io/g/nvda/topic/92062474?p=Created,,,100,1,0,0::recentpostdate/sticky,,,100,2,0,92062474,previd=1656521897216851032,nextid=1654197375300790093>
>     on the NVDA mailing list.
>
> 2.
>
>     A consequence of this error is that you may be able to open two
>     instance of the input gesture dialog, what is not an wanted
>     behaviour. For this, after the initial STR (Steps To Reproduce) of
>     this issue, do the following:
>
>   * Close the Input gesture dialog
>   * Open the Input gesture dialog
>   * Open the Input gesture dialog
>
>  3. An alternative way to reproduce it is described in this message
>     <https://nvda.groups.io/g/nvda/message/97038>.
>
> —
> Reply to this email directly, view it on GitHub 
> <https://github.com/nvaccess/nvda/issues/13854#issuecomment-1170442387>, 
> or unsubscribe 
> <https://github.com/notifications/unsubscribe-auth/ADZLFFGM64Z6XH42DLRMIJTVRST4LANCNFSM52GTECYA>.
> You are receiving this because you were mentioned.Message ID: 
> ***@***.***>
>



Resolving patch:
diff --git a/source/gui/inputGestures.py b/source/gui/inputGestures.py
--- a/source/gui/inputGestures.py
+++ b/source/gui/inputGestures.py
@@ -636,6 +636,7 @@ def _onWindowDestroy(self, evt):
 		super()._onWindowDestroy(evt)
 
 	def onFilterChange(self, evt):
+		self.tree.Unselect()
 		filterText = evt.GetEventObject().GetValue()
 		self.filter(filterText)
 


Test patch: