From 143456ae1d794694b9e605eb56b34373351acad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 26 Aug 2016 17:06:32 +0200 Subject: [PATCH] Made AsyncModalOperatorMixin.invoke() start self.async_execute(context). This was already common practice in all subclasses, and has now been moved into the mixin. --- blender_cloud/async_loop.py | 11 +++++++++++ blender_cloud/image_sharing.py | 6 +----- blender_cloud/settings_sync.py | 6 +----- blender_cloud/texture_browser.py | 12 +----------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/blender_cloud/async_loop.py b/blender_cloud/async_loop.py index 6fdbb5f..14d58a3 100644 --- a/blender_cloud/async_loop.py +++ b/blender_cloud/async_loop.py @@ -182,8 +182,19 @@ class AsyncModalOperatorMixin: def invoke(self, context, event): context.window_manager.modal_handler_add(self) self.timer = context.window_manager.event_timer_add(1 / 15, context.window) + + self.log.info('Starting') + self._new_async_task(self.async_execute(context)) + return {'RUNNING_MODAL'} + async def async_execute(self, context): + """Entry point of the asynchronous operator. + + Implement in a subclass. + """ + return + def execute(self, context): return self.invoke(context, None) diff --git a/blender_cloud/image_sharing.py b/blender_cloud/image_sharing.py index 8eb2422..cee5e02 100644 --- a/blender_cloud/image_sharing.py +++ b/blender_cloud/image_sharing.py @@ -107,11 +107,7 @@ class PILLAR_OT_image_share(pillar.PillarOperatorMixin, self.report({'ERROR'}, 'Datablock is dirty, save it first.') return {'CANCELLED'} - async_loop.AsyncModalOperatorMixin.invoke(self, context, event) - - self.log.info('Starting sharing') - self._new_async_task(self.async_execute(context)) - return {'RUNNING_MODAL'} + return async_loop.AsyncModalOperatorMixin.invoke(self, context, event) async def async_execute(self, context): """Entry point of the asynchronous operator.""" diff --git a/blender_cloud/settings_sync.py b/blender_cloud/settings_sync.py index 01671da..69c43b9 100644 --- a/blender_cloud/settings_sync.py +++ b/blender_cloud/settings_sync.py @@ -234,11 +234,7 @@ class PILLAR_OT_sync(pillar.PillarOperatorMixin, self.bss_report({'ERROR'}, 'No Blender version to sync for was given.') return {'CANCELLED'} - async_loop.AsyncModalOperatorMixin.invoke(self, context, event) - - self.log.info('Starting synchronisation') - self._new_async_task(self.async_execute(context)) - return {'RUNNING_MODAL'} + return async_loop.AsyncModalOperatorMixin.invoke(self, context, event) def action_select(self, context): """Allows selection of the Blender version to use. diff --git a/blender_cloud/texture_browser.py b/blender_cloud/texture_browser.py index 62121f7..cfbe99f 100644 --- a/blender_cloud/texture_browser.py +++ b/blender_cloud/texture_browser.py @@ -288,10 +288,7 @@ class BlenderCloudBrowser(pillar.PillarOperatorMixin, self._scroll_reset() context.window.cursor_modal_set('DEFAULT') - async_loop.AsyncModalOperatorMixin.invoke(self, context, event) - self._new_async_task(self.async_execute(context)) - - return {'RUNNING_MODAL'} + return async_loop.AsyncModalOperatorMixin.invoke(self, context, event) def modal(self, context, event): result = async_loop.AsyncModalOperatorMixin.modal(self, context, event) @@ -850,13 +847,6 @@ class PILLAR_OT_switch_hdri(pillar.PillarOperatorMixin, file_uuid = bpy.props.StringProperty(name='file_uuid', description='File ID to download') - def invoke(self, context, event): - async_loop.AsyncModalOperatorMixin.invoke(self, context, event) - - self.log.info('Starting') - self._new_async_task(self.async_execute(context)) - return {'RUNNING_MODAL'} - async def async_execute(self, context): """Entry point of the asynchronous operator."""