Added exception drawing code.
It's rather primitive, but at least the GUI reflects that something has gone wrong.
This commit is contained in:
parent
09e9c02d65
commit
0974c460e8
@ -237,6 +237,14 @@ class BlenderCloudBrowser(bpy.types.Operator):
|
|||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
def modal(self, context, event):
|
def modal(self, context, event):
|
||||||
|
task = self.async_task
|
||||||
|
if self._state != 'EXCEPTION' and task.done() and not task.cancelled():
|
||||||
|
ex = task.exception()
|
||||||
|
if ex is not None:
|
||||||
|
self._state = 'EXCEPTION'
|
||||||
|
self.log.error('Exception while running task: %s', ex)
|
||||||
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
if self._state == 'QUIT':
|
if self._state == 'QUIT':
|
||||||
self._finish(context)
|
self._finish(context)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
@ -451,6 +459,7 @@ class BlenderCloudBrowser(bpy.types.Operator):
|
|||||||
drawers = {
|
drawers = {
|
||||||
'BROWSING': self._draw_browser,
|
'BROWSING': self._draw_browser,
|
||||||
'DOWNLOADING_TEXTURE': self._draw_downloading,
|
'DOWNLOADING_TEXTURE': self._draw_downloading,
|
||||||
|
'EXCEPTION': self._draw_exception,
|
||||||
}
|
}
|
||||||
|
|
||||||
if self._state in drawers:
|
if self._state in drawers:
|
||||||
@ -521,9 +530,7 @@ class BlenderCloudBrowser(bpy.types.Operator):
|
|||||||
def _draw_downloading(self, context):
|
def _draw_downloading(self, context):
|
||||||
"""OpenGL drawing code for the DOWNLOADING_TEXTURE state."""
|
"""OpenGL drawing code for the DOWNLOADING_TEXTURE state."""
|
||||||
|
|
||||||
window_region = self._window_region(context)
|
content_height, content_width = self._window_size(context)
|
||||||
content_width = window_region.width
|
|
||||||
content_height = window_region.height
|
|
||||||
|
|
||||||
bgl.glEnable(bgl.GL_BLEND)
|
bgl.glEnable(bgl.GL_BLEND)
|
||||||
bgl.glColor4f(0.0, 0.0, 0.2, 0.6)
|
bgl.glColor4f(0.0, 0.0, 0.2, 0.6)
|
||||||
@ -541,6 +548,41 @@ class BlenderCloudBrowser(bpy.types.Operator):
|
|||||||
blf.draw(font_id, text)
|
blf.draw(font_id, text)
|
||||||
bgl.glDisable(bgl.GL_BLEND)
|
bgl.glDisable(bgl.GL_BLEND)
|
||||||
|
|
||||||
|
def _window_size(self, context):
|
||||||
|
window_region = self._window_region(context)
|
||||||
|
content_width = window_region.width
|
||||||
|
content_height = window_region.height
|
||||||
|
return content_height, content_width
|
||||||
|
|
||||||
|
def _draw_exception(self, context):
|
||||||
|
"""OpenGL drawing code for the EXCEPTION state."""
|
||||||
|
|
||||||
|
import textwrap
|
||||||
|
|
||||||
|
content_height, content_width = self._window_size(context)
|
||||||
|
|
||||||
|
bgl.glEnable(bgl.GL_BLEND)
|
||||||
|
bgl.glColor4f(0.2, 0.0, 0.0, 0.6)
|
||||||
|
bgl.glRectf(0, 0, content_width, content_height)
|
||||||
|
|
||||||
|
font_id = 0
|
||||||
|
text = "An error occurred:\n%s" % self.async_task.exception()
|
||||||
|
lines = textwrap.wrap(text)
|
||||||
|
|
||||||
|
bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
|
||||||
|
blf.size(font_id, 20, 72)
|
||||||
|
_, text_height = blf.dimensions(font_id, 'yhBp')
|
||||||
|
|
||||||
|
def position(line_nr):
|
||||||
|
blf.position(font_id,
|
||||||
|
content_width * 0.1,
|
||||||
|
content_height * 0.8 - line_nr * text_height, 0)
|
||||||
|
|
||||||
|
for line_idx, line in enumerate(lines):
|
||||||
|
position(line_idx)
|
||||||
|
blf.draw(font_id, line)
|
||||||
|
bgl.glDisable(bgl.GL_BLEND)
|
||||||
|
|
||||||
def get_clicked(self) -> MenuItem:
|
def get_clicked(self) -> MenuItem:
|
||||||
|
|
||||||
for item in self.current_display_content:
|
for item in self.current_display_content:
|
||||||
|
Reference in New Issue
Block a user