[Bf-blender-cvs] [b236653f8a4] blender-v2.93-release: Fix error in grease pencil flip color operator

Campbell Barton noreply at git.blender.org
Tue May 18 09:41:05 CEST 2021


Commit: b236653f8a4c0ae6a46369c6ff420d9f4a619808
Author: Campbell Barton
Date:   Tue May 18 17:38:54 2021 +1000
Branches: blender-v2.93-release
https://developer.blender.org/rBb236653f8a4c0ae6a46369c6ff420d9f4a619808

Fix error in grease pencil flip color operator

- Used try/except instead of a poll function.
- The error case referenced a non-existent error handling module.

Prefer poll functions over exception handling where possible,
also having an operators logic in a try block isn't good practice
as it can hide more serious errors in the code.

Note that duplicate pencil settings access should be moved into a
utility function. This can be part of a separate cleanup.

===================================================================

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index c1d60a127d2..766b82f8ba4 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -881,37 +881,43 @@ class GreasePencilFlipTintColors(Operator):
     bl_idname = "gpencil.tint_flip"
     bl_description = "Switch tint colors"
 
-    def execute(self, context):
-        try:
-            ts = context.tool_settings
-            settings = None
-            if context.mode == 'PAINT_GPENCIL':
-                settings = ts.gpencil_paint
-            if context.mode == 'SCULPT_GPENCIL':
-                settings = ts.gpencil_sculpt_paint
-            elif context.mode == 'WEIGHT_GPENCIL':
-                settings = ts.gpencil_weight_paint
-            elif context.mode == 'VERTEX_GPENCIL':
-                settings = ts.gpencil_vertex_paint
-
-            brush = settings.brush
-            if brush is not None:
-                color = brush.color
-                secondary_color = brush.secondary_color
+    @classmethod
+    def poll(cls, context):
+        ts = context.tool_settings
+        settings = None
+        if context.mode == 'PAINT_GPENCIL':
+            settings = ts.gpencil_paint
+        if context.mode == 'SCULPT_GPENCIL':
+            settings = ts.gpencil_sculpt_paint
+        elif context.mode == 'WEIGHT_GPENCIL':
+            settings = ts.gpencil_weight_paint
+        elif context.mode == 'VERTEX_GPENCIL':
+            settings = ts.gpencil_vertex_paint
 
-                orig_prim = color.hsv
-                orig_sec = secondary_color.hsv
+        return settings and settings.brush
 
-                color.hsv = orig_sec
-                secondary_color.hsv = orig_prim
+    def execute(self, context):
+        ts = context.tool_settings
+        settings = None
+        if context.mode == 'PAINT_GPENCIL':
+            settings = ts.gpencil_paint
+        if context.mode == 'SCULPT_GPENCIL':
+            settings = ts.gpencil_sculpt_paint
+        elif context.mode == 'WEIGHT_GPENCIL':
+            settings = ts.gpencil_weight_paint
+        elif context.mode == 'VERTEX_GPENCIL':
+            settings = ts.gpencil_vertex_paint
 
-            return {'FINISHED'}
+        brush = settings.brush
+        color = brush.color
+        secondary_color = brush.secondary_color
 
-        except Exception as e:
-            utils_core.error_handlers(self, "gpencil.tint_flip", e,
-                                      "Flip Colors could not be completed")
+        orig_prim = color.hsv
+        orig_sec = secondary_color.hsv
 
-            return {'CANCELLED'}
+        color.hsv = orig_sec
+        secondary_color.hsv = orig_prim
+        return {'FINISHED'}
 
 
 classes = (



More information about the Bf-blender-cvs mailing list