From ff407ced3bb84de48963a445cd912f102d63e191 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 24 Nov 2023 12:23:07 +0100 Subject: [PATCH] Media Viewer: Update for 4.x Various breaking changes where done, leading to errors in the application template. This fixes all I could find. Addresses: - `bgl` removal - Removal of `2D_` prefixes in shader names - Removal of context override argument for operators in favor of `context.temp_override()` - Renamed/repurposed `FileSelectParams.display_size` See https://wiki.blender.org/wiki/Reference/Release_Notes/4.0/Python_API. --- .../addons/media_viewer/draw.py | 13 ++++++------- .../blender_media_viewer/addons/media_viewer/ops.py | 4 +++- .../addons/media_viewer/opsdata.py | 2 +- .../addons/media_viewer/states.py | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/draw.py b/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/draw.py index 9d848fa7..7d4134e2 100644 --- a/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/draw.py +++ b/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/draw.py @@ -16,7 +16,6 @@ from copy import copy import bpy import gpu -import bgl import blf from gpu_extras.batch import batch_for_shader from bpy.app.handlers import persistent @@ -94,7 +93,7 @@ def draw_toggle(region_name: str): bot_right = (top_left[0] + width, top_left[1] - height) coordinates = [top_left, top_right, bot_left, bot_right] - shader = gpu.shader.from_builtin("2D_UNIFORM_COLOR") + shader = gpu.shader.from_builtin("UNIFORM_COLOR") batch = batch_for_shader( shader, "TRIS", @@ -114,7 +113,7 @@ def draw_text(region_name: str): y = region.height + offset_y x = 0 + offset_x font_id = 0 - bgl.glEnable(bgl.GL_BLEND) + gpu.state.blend_set('ALPHA') blf.position(font_id, x, y, 0) blf.size(font_id, 12, 72) blf.color(font_id, 1, 1, 1, 0.9) @@ -375,7 +374,7 @@ class ButtonDrawer: def __init__( self, ): - self._shader = gpu.shader.from_builtin("2D_UNIFORM_COLOR") + self._shader = gpu.shader.from_builtin("UNIFORM_COLOR") self.draw_arrow = True self.draw_rect = False self._arrow_direction = "UP" @@ -398,8 +397,8 @@ class ButtonDrawer: def draw_button( self, button: Button, region: bpy.types.Region, color: Float4 ) -> None: - bgl.glEnable(bgl.GL_BLEND) - bgl.glLineWidth(0) + gpu.state.blend_set('ALPHA') + gpu.state.line_width_set(0) coords = button.get_region_coords(region) # Draw rectangle. @@ -441,7 +440,7 @@ class ButtonDrawer: return # Create line batch and draw it. - bgl.glLineWidth(3) + gpu.state.line_width_set(3) self._shader.bind() self._shader.uniform_float("color", color) # print(f"Drawing points: {line_pos}") diff --git a/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/ops.py b/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/ops.py index 1db766ea..3e4001b5 100644 --- a/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/ops.py +++ b/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/ops.py @@ -625,7 +625,9 @@ class MV_OT_set_media_area_type(bpy.types.Operator): # Set annotate tool as active. if area_media.type in ["SEQUENCE_EDITOR", "IMAGE_EDITOR"]: - bpy.ops.wm.tool_set_by_id({"area": area_media}, name="builtin.annotate") + ctx = opsdata.get_context_for_area(area_media) + with context.temp_override(**ctx): + bpy.ops.wm.tool_set_by_id(name="builtin.annotate") logger.info(f"Changed active media area to: {area_media.type}") diff --git a/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/opsdata.py b/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/opsdata.py index 25921cb6..6bb38798 100644 --- a/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/opsdata.py +++ b/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/opsdata.py @@ -216,7 +216,7 @@ def close_area(context: bpy.types.Context, area: bpy.types.Area) -> None: def setup_filebrowser_area(filebrowser_area: bpy.types.Area) -> None: params = filebrowser_area.spaces.active.params params.display_type = "THUMBNAIL" - params.display_size = "NORMAL" + params.display_size_discrete = "NORMAL" params.use_filter = True params.use_filter_image = True params.use_filter_folder = True diff --git a/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/states.py b/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/states.py index e9beb856..b2495902 100644 --- a/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/states.py +++ b/application-templates/blender-media-viewer/blender_media_viewer/addons/media_viewer/states.py @@ -88,7 +88,7 @@ class SpaceData: class FbParams: directory: str = "" display_type: str = "THUMBNAIL" - display_size: str = "NORMAL" + display_size_discrete: str = "NORMAL" use_filter: bool = True use_filter_image: bool = True use_filter_folder: bool = True -- 2.30.2