Skip to content

Commit

Permalink
double gesture issue
Browse files Browse the repository at this point in the history
when gesture is pressed twice, and not watching any object, do not say "stop watcher".
  • Loading branch information
ibrahim-s committed Aug 31, 2023
1 parent 6fe1cd4 commit 83e3ec8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions addon/globalPlugins/objWatcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def __init__(self):
super().__init__()
self.watchingObj = None
self.lastAttributeText = None
# self.callLater will be assigned the value wx.CallLater(510, _toggleWatcher), used to stop calling the function when the gesture presse twice.
# Borrowed from Luke's Version collector addon. Thanks Luke
self.callLater= None
self.timer = wx.Timer(gui.mainFrame)
gui.mainFrame.Bind(
wx.EVT_TIMER, handler=self.onTimerEvent, source=self.timer)
Expand All @@ -43,14 +46,19 @@ def script_startOrStopWatcher(self, gesture):
return
repeatCount = getLastScriptRepeatCount()
if repeatCount > 0:
# stop the effects of first press.
if self.callLater.IsRunning():
self.callLater.Stop()
if not self.timer.IsRunning():
return
self._toggleWatcher()
else:
if self.timer.IsRunning():
ui.message(self._getWatchingAttribute())
else:
self._toggleWatcher()
self.callLater= wx.CallLater(510, self._toggleWatcher) if not self.callLater else self.callLater
# call after 510 ms, and we will stop it if gesture press twice.
self.callLater.Start(510)

def _toggleWatcher(self):
if self.timer.IsRunning():
Expand All @@ -60,8 +68,8 @@ def _toggleWatcher(self):
ui.message(_("Stopped watcher"))
else:
self.watchingObj = api.getNavigatorObject()
self.timer.Start(WATCHER_TIMER_INTERVAL)
if self.watchingObj:
self.timer.Start(WATCHER_TIMER_INTERVAL)
cues.Start()
# Translators: Messages reported when watcher is started.
ui.message(_("Started watcher {}").format(
Expand Down

0 comments on commit 83e3ec8

Please sign in to comment.