From b236653f8a4c0ae6a46369c6ff420d9f4a619808 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 18 May 2021 17:38:54 +1000 Subject: 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. --- .../bl_ui/properties_grease_pencil_common.py | 58 ++++++++++++---------- 1 file changed, 32 insertions(+), 26 deletions(-) (limited to '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 = ( -- cgit v1.2.3