Texture browser now uses pillar.PillarOperatorMixin too.

This commit is contained in:
Sybren A. Stüvel 2016-06-24 15:00:38 +02:00
parent 645529bf35
commit 0f26551368
2 changed files with 20 additions and 39 deletions

View File

@ -200,7 +200,9 @@ class MenuItem:
return self.x < mouse_x < self.x + self.width and self.y < mouse_y < self.y + self.height return self.x < mouse_x < self.x + self.width and self.y < mouse_y < self.y + self.height
class BlenderCloudBrowser(async_loop.AsyncModalOperatorMixin, bpy.types.Operator): class BlenderCloudBrowser(pillar.PillarOperatorMixin,
async_loop.AsyncModalOperatorMixin,
bpy.types.Operator):
bl_idname = 'pillar.browser' bl_idname = 'pillar.browser'
bl_label = 'Blender Cloud Texture Browser' bl_label = 'Blender Cloud Texture Browser'
@ -252,10 +254,10 @@ class BlenderCloudBrowser(async_loop.AsyncModalOperatorMixin, bpy.types.Operator
self.current_display_content = [] self.current_display_content = []
self.loaded_images = set() self.loaded_images = set()
self.check_credentials()
context.window.cursor_modal_set('DEFAULT') context.window.cursor_modal_set('DEFAULT')
async_loop.AsyncModalOperatorMixin.invoke(self, context, event) async_loop.AsyncModalOperatorMixin.invoke(self, context, event)
self._new_async_task(self.async_execute(context))
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
@ -313,42 +315,21 @@ class BlenderCloudBrowser(async_loop.AsyncModalOperatorMixin, bpy.types.Operator
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
def check_credentials(self): async def async_execute(self, context):
self._state = 'CHECKING_CREDENTIALS' self._state = 'CHECKING_CREDENTIALS'
self.log.debug('Checking credentials') self.log.debug('Checking credentials')
self._new_async_task(self._check_credentials())
async def _check_credentials(self):
"""Checks credentials with Pillar, and if ok goes to the BROWSING state."""
try: try:
await pillar.check_pillar_credentials() user_id = await self.check_credentials(context)
except pillar.NotSubscribedToCloudError: except pillar.NotSubscribedToCloudError:
self.log.info('User not subscribed to Blender Cloud.') self.log.info('User not subscribed to Blender Cloud.')
self._show_subscribe_screen() self._show_subscribe_screen()
return return None
except pillar.CredentialsNotSyncedError:
self.log.info('Credentials not synced, re-syncing automatically.')
else:
self.log.info('Credentials okay, browsing assets.')
await self.async_download_previews()
return
try:
await pillar.refresh_pillar_credentials()
except pillar.NotSubscribedToCloudError:
self.log.info('User is not a Blender Cloud subscriber.')
self._show_subscribe_screen()
return
except pillar.UserNotLoggedInError:
self.log.error('User not logged in on Blender ID.')
else:
self.log.info('Credentials refreshed and ok, browsing assets.')
await self.async_download_previews()
return
if user_id is None:
raise pillar.UserNotLoggedInError() raise pillar.UserNotLoggedInError()
# self._new_async_task(self._check_credentials())
await self.async_download_previews()
def _show_subscribe_screen(self): def _show_subscribe_screen(self):
"""Shows the "You need to subscribe" screen.""" """Shows the "You need to subscribe" screen."""

View File

@ -674,11 +674,8 @@ class PillarOperatorMixin:
try: try:
user_id = await check_pillar_credentials() user_id = await check_pillar_credentials()
except NotSubscribedToCloudError: except NotSubscribedToCloudError:
self.log.warning( self._log_subscription_needed()
'Please subscribe to the blender cloud at https://cloud.blender.org/join') raise
self.report({'INFO'},
'Please subscribe to the blender cloud at https://cloud.blender.org/join')
return None
except CredentialsNotSyncedError: except CredentialsNotSyncedError:
self.log.info('Credentials not synced, re-syncing automatically.') self.log.info('Credentials not synced, re-syncing automatically.')
else: else:
@ -688,11 +685,8 @@ class PillarOperatorMixin:
try: try:
user_id = await refresh_pillar_credentials() user_id = await refresh_pillar_credentials()
except NotSubscribedToCloudError: except NotSubscribedToCloudError:
self.log.warning( self._log_subscription_needed()
'Please subscribe to the blender cloud at https://cloud.blender.org/join') raise
self.report({'INFO'},
'Please subscribe to the blender cloud at https://cloud.blender.org/join')
return None
except UserNotLoggedInError: except UserNotLoggedInError:
self.log.error('User not logged in on Blender ID.') self.log.error('User not logged in on Blender ID.')
else: else:
@ -700,3 +694,9 @@ class PillarOperatorMixin:
return user_id return user_id
return None return None
def _log_subscription_needed(self):
self.log.warning(
'Please subscribe to the blender cloud at https://cloud.blender.org/join')
self.report({'INFO'},
'Please subscribe to the blender cloud at https://cloud.blender.org/join')