Workspace: Move engines to workspace and Properties Editor cleanup
[blender.git] / release / scripts / templates_py / operator_modal_timer.py
index 3088d59fbcfe8bc5cb4ee62f9997a57ac49c4cd7..df4d10e656b604e5cbed173d0c2b888f8ffeb505 100644 (file)
@@ -9,8 +9,9 @@ class ModalTimerOperator(bpy.types.Operator):
     _timer = None
 
     def modal(self, context, event):
-        if event.type == 'ESC':
-            return self.cancel(context)
+        if event.type in {'RIGHTMOUSE', 'ESC'}:
+            self.cancel(context)
+            return {'CANCELLED'}
 
         if event.type == 'TIMER':
             # change theme color, silly!
@@ -21,13 +22,14 @@ class ModalTimerOperator(bpy.types.Operator):
         return {'PASS_THROUGH'}
 
     def execute(self, context):
-        self._timer = context.window_manager.event_timer_add(0.1, context.window)
-        context.window_manager.modal_handler_add(self)
+        wm = context.window_manager
+        self._timer = wm.event_timer_add(0.1, context.window)
+        wm.modal_handler_add(self)
         return {'RUNNING_MODAL'}
 
     def cancel(self, context):
-        context.window_manager.event_timer_remove(self._timer)
-        return {'CANCELLED'}
+        wm = context.window_manager
+        wm.event_timer_remove(self._timer)
 
 
 def register():