From 0d99abb86c8b03090c960eb67c61f90862ca2b6c Mon Sep 17 00:00:00 2001 From: RomainFT Date: Sat, 4 Feb 2023 22:01:38 +0100 Subject: [PATCH] on_options_changed for most classic tools #357 --- src/tools/classic_tools/tool_arc.py | 11 +++--- src/tools/classic_tools/tool_brush.py | 9 +++-- src/tools/classic_tools/tool_eraser.py | 11 +++--- src/tools/classic_tools/tool_highlight.py | 11 +++--- src/tools/classic_tools/tool_line.py | 21 ++++++------ src/tools/classic_tools/tool_pencil.py | 14 ++++---- src/tools/classic_tools/tool_points.py | 41 ++++++++++++----------- 7 files changed, 68 insertions(+), 50 deletions(-) diff --git a/src/tools/classic_tools/tool_arc.py b/src/tools/classic_tools/tool_arc.py index ed298d94..d7f11e3b 100644 --- a/src/tools/classic_tools/tool_arc.py +++ b/src/tools/classic_tools/tool_arc.py @@ -57,10 +57,6 @@ def get_options_label(self): return _("Curve options") def get_editing_tips(self): - self._use_outline = self.get_option_value('pencil-outline') - self._dashes_type = self.get_option_value('dashes-type') - self._arrow_type = self.get_option_value('arrow-type') - self.set_active_shape() is_arrow = self._arrow_type != 'none' use_dashes = self._dashes_type != 'none' @@ -89,6 +85,13 @@ def get_editing_tips(self): full_list = [label_segments, label_options, label_modifier_alt] return list(filter(None, full_list)) + def on_options_changed(self): + super().on_options_changed() + self._use_outline = self.get_option_value('pencil-outline') + self._dashes_type = self.get_option_value('dashes-type') + self._arrow_type = self.get_option_value('arrow-type') + self.set_active_shape() + ############################################################################ def on_press_on_area(self, event, surface, event_x, event_y): diff --git a/src/tools/classic_tools/tool_brush.py b/src/tools/classic_tools/tool_brush.py index 67678b6c..1a3ff80d 100644 --- a/src/tools/classic_tools/tool_brush.py +++ b/src/tools/classic_tools/tool_brush.py @@ -47,14 +47,17 @@ def get_options_label(self): return _("Brush options") def get_editing_tips(self): + active_brush = self._brushes_dict[self._brush_type] + return active_brush._get_tips(self._used_pressure, self._brush_dir) + + def on_options_changed(self): + super().on_options_changed() self._brush_type = self.get_option_value('brush-type') self._brush_dir = self.get_option_value('brush-dir') enable_direction = self._brush_type == 'calligraphic' self.set_action_sensitivity('brush-dir', enable_direction) - - active_brush = self._brushes_dict[self._brush_type] - return active_brush._get_tips(self._used_pressure, self._brush_dir) + # refreshing the rendered operation isn't pertinent ############################################################################ diff --git a/src/tools/classic_tools/tool_eraser.py b/src/tools/classic_tools/tool_eraser.py index 17c4bde0..d4049bbf 100644 --- a/src/tools/classic_tools/tool_eraser.py +++ b/src/tools/classic_tools/tool_eraser.py @@ -43,10 +43,6 @@ def __init__(self, window, **kwargs): } def get_editing_tips(self): - self._rgba_type = self.get_option_value('selection-color') - self._eraser_shape = self.get_option_value('eraser-shape') - self._apply_shape_constraints() - opt = { 'selection-color': self._rgba_type, 'eraser-type': self._eraser_type @@ -66,6 +62,13 @@ def get_editing_tips(self): full_list = [label_options, label_modifier_shift] return list(filter(None, full_list)) + def on_options_changed(self): + super().on_options_changed() + self._rgba_type = self.get_option_value('selection-color') + self._eraser_shape = self.get_option_value('eraser-shape') + self._apply_shape_constraints() + # refreshing the rendered operation isn't pertinent + def get_options_label(self): return _("Eraser options") diff --git a/src/tools/classic_tools/tool_highlight.py b/src/tools/classic_tools/tool_highlight.py index 3b7edde7..083499cb 100644 --- a/src/tools/classic_tools/tool_highlight.py +++ b/src/tools/classic_tools/tool_highlight.py @@ -34,10 +34,6 @@ def __init__(self, window, **kwargs): self.add_tool_action_enum('highlight-bg', 'light') def get_editing_tips(self): - self._bg_type = self.get_option_value('highlight-bg') - self._force_alpha = self.get_option_value('highlight-alpha') - self._is_rigid = self.get_option_value('highlight-rigid') - label_options = self.label + " - " if self._bg_type == 'light': label_options += _("Dark text on light background") @@ -53,6 +49,13 @@ def get_editing_tips(self): full_list = [label_options, label_modifier_shift] return list(filter(None, full_list)) + def on_options_changed(self): + super().on_options_changed() + self._bg_type = self.get_option_value('highlight-bg') + self._force_alpha = self.get_option_value('highlight-alpha') + self._is_rigid = self.get_option_value('highlight-rigid') + # refreshing the rendered operation isn't pertinent + def get_options_label(self): return _("Highlighter options") diff --git a/src/tools/classic_tools/tool_line.py b/src/tools/classic_tools/tool_line.py index b1f6a6f0..ae02590c 100644 --- a/src/tools/classic_tools/tool_line.py +++ b/src/tools/classic_tools/tool_line.py @@ -39,7 +39,7 @@ def __init__(self, window, **kwargs): self.add_tool_action_boolean('use_gradient', self._use_gradient) self.add_tool_action_boolean('pencil-outline', self._use_outline) self.add_tool_action_boolean('line-ortholock', self._ortholock) - self._set_options_attributes() # Not optimal but more readable + self.on_options_changed() # Not optimal but more readable XXX useful? def get_tooltip(self, event_x, event_y, motion_behavior): if motion_behavior != 1: @@ -64,16 +64,7 @@ def _set_active_shape(self): def get_options_label(self): return _("Line options") - def _set_options_attributes(self): - self._use_outline = self.get_option_value('pencil-outline') - self._dashes_type = self.get_option_value('dashes-type') - self._arrow_type = self.get_option_value('arrow-type') - self._use_gradient = self.get_option_value('use_gradient') - self._ortholock = self.get_option_value('line-ortholock') - self._set_active_shape() - def get_editing_tips(self): - self._set_options_attributes() is_arrow = self._arrow_type != 'none' use_dashes = self._dashes_type != 'none' @@ -103,6 +94,16 @@ def get_editing_tips(self): full_list = [label_options, label_modifier_shift, label_modifier_alt] return list(filter(None, full_list)) + def on_options_changed(self): + super().on_options_changed() + self._use_outline = self.get_option_value('pencil-outline') + self._dashes_type = self.get_option_value('dashes-type') + self._arrow_type = self.get_option_value('arrow-type') + self._use_gradient = self.get_option_value('use_gradient') + self._ortholock = self.get_option_value('line-ortholock') + self._set_active_shape() + # refreshing the rendered operation isn't pertinent + ############################################################################ def on_press_on_area(self, event, surface, event_x, event_y): diff --git a/src/tools/classic_tools/tool_pencil.py b/src/tools/classic_tools/tool_pencil.py index d0100fe0..a81ec5d3 100644 --- a/src/tools/classic_tools/tool_pencil.py +++ b/src/tools/classic_tools/tool_pencil.py @@ -52,12 +52,7 @@ def get_options_label(self): return _("Pencil options") def get_editing_tips(self): - self._dashes_type = self.get_option_value('dashes-type') - use_dashes = self._dashes_type != 'none' - self._use_outline = self.get_option_value('pencil-outline') - self._set_active_shape() - - if use_dashes: + if self._dashes_type != 'none': label_options = self.label + " - " + _("Dashed") else: label_options = None @@ -73,6 +68,13 @@ def get_editing_tips(self): full_list = [label_options, label_modifier_alt] return list(filter(None, full_list)) + def on_options_changed(self): + super().on_options_changed() + self._dashes_type = self.get_option_value('dashes-type') + self._use_outline = self.get_option_value('pencil-outline') + self._set_active_shape() + # refreshing the rendered operation isn't pertinent + ############################################################################ def on_press_on_area(self, event, surface, event_x, event_y): diff --git a/src/tools/classic_tools/tool_points.py b/src/tools/classic_tools/tool_points.py index d6bc18d7..70d601ee 100644 --- a/src/tools/classic_tools/tool_points.py +++ b/src/tools/classic_tools/tool_points.py @@ -36,24 +36,7 @@ def __init__(self, window, **kwargs): self.add_tool_action_simple('points_dec_num', self._decrement_number) self._next_number = 1 - self._set_active_type() # Not optimal but more readable - - def _set_active_type(self): - state_as_string = self.get_option_value('points_type') - if state_as_string == 'cross': - self._shape_label = _("Cross") - elif state_as_string == 'x-cross': - self._shape_label = _("X-shaped cross") - elif state_as_string == 'square': - self._shape_label = _("Square") - else: - self._shape_label = _("Circle") - self._points_type = state_as_string - - self._use_number = self.get_option_value('points_number') - self.set_action_sensitivity('points_reset_num', self._use_number) - self.set_action_sensitivity('points_inc_num', self._use_number) - self.set_action_sensitivity('points_dec_num', self._use_number) + self.on_options_changed() # Not optimal but more readable XXX useful? def _reset_number(self, *args): self._next_number = 1 @@ -71,13 +54,33 @@ def get_options_label(self): return _("Points options") def get_editing_tips(self): - self._set_active_type() label = self.label + " - " + self._shape_label if self._use_number: label += " - " + _("Next number: %s") % self._next_number # A single label is returned so the next number is always visible return [label] + def on_options_changed(self): + super().on_options_changed() + + state_as_string = self.get_option_value('points_type') + if state_as_string == 'cross': + self._shape_label = _("Cross") + elif state_as_string == 'x-cross': + self._shape_label = _("X-shaped cross") + elif state_as_string == 'square': + self._shape_label = _("Square") + else: + self._shape_label = _("Circle") + self._points_type = state_as_string + + self._use_number = self.get_option_value('points_number') + self.set_action_sensitivity('points_reset_num', self._use_number) + self.set_action_sensitivity('points_inc_num', self._use_number) + self.set_action_sensitivity('points_dec_num', self._use_number) + + # refreshing the rendered operation isn't pertinent + ############################################################################ def on_press_on_area(self, event, surface, event_x, event_y):