Skip to content

Commit

Permalink
Input Gestures dialog: Delay applying filter for smoother response
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienCochuyt committed Oct 1, 2019
1 parent 2d0ba99 commit 455cfcc
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3241,7 +3241,10 @@ class InputGesturesDialog(SettingsDialog):
# Translators: The title of the Input Gestures dialog where the user can remap input gestures for commands.
title = _("Input Gestures")

POPULATE_TREE_DELAY_MS = 300

def __init__(self, parent):
self.populateTreeTimer = None
super().__init__(parent, resizeable=True)

def makeSettings(self, settingsSizer):
Expand Down Expand Up @@ -3287,13 +3290,26 @@ def makeSettings(self, settingsSizer):
def postInit(self):
self.tree.SetFocus()

def populateTree(self, filter=''):
def populateTree(self, *args, **kwargs):
def delayedCall(*args, **kwargs):
self.tree.Freeze()
try:
self._populateTree(*args, **kwargs)
finally:
self.tree.Thaw()
if self.populateTreeTimer is None:
self.populateTreeTimer = wx.CallLater(self.POPULATE_TREE_DELAY_MS, delayedCall, *args, **kwargs)
else:
self.populateTreeTimer.Start(self.POPULATE_TREE_DELAY_MS, *args, **kwargs)

def _populateTree(self, filter=''):
if filter:
#This regexp uses a positive lookahead (?=...) for every word in the filter, which just makes sure the word is present in the string to be tested without matching position or order.
# #5060: Escape the filter text to prevent unexpected matches and regexp errors.
# Because we're escaping, words must then be split on "\ ".
filter = re.escape(filter)
filterReg = re.compile(r'(?=.*?' + r')(?=.*?'.join(filter.split('\ ')) + r')', re.U|re.IGNORECASE)
self.tree.DeleteChildren(self.treeRoot)
for category in sorted(self.gestures):
treeCat = self.tree.AppendItem(self.treeRoot, category)
commands = self.gestures[category]
Expand All @@ -3313,7 +3329,6 @@ def populateTree(self, filter=''):

def onFilterChange(self, evt):
filter=evt.GetEventObject().GetValue()
self.tree.DeleteChildren(self.treeRoot)
self.populateTree(filter)

def _formatGesture(self, identifier):
Expand Down

0 comments on commit 455cfcc

Please sign in to comment.