diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-05-18 10:38:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-05-18 10:38:54 +0300 |
commit | b236653f8a4c0ae6a46369c6ff420d9f4a619808 (patch) | |
tree | bcd66929b1682ed358fb590641f0b919add2e72b /release | |
parent | dfb963c70df515213c452094c20c83720bc017ee (diff) |
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.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/startup/bl_ui/properties_grease_pencil_common.py | 58 |
1 files changed, 32 insertions, 26 deletions
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 = ( |