Skip to content

Commit

Permalink
on_options_changed for most classic tools #357
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Feb 4, 2023
1 parent 0ac32ef commit 0d99abb
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 50 deletions.
11 changes: 7 additions & 4 deletions src/tools/classic_tools/tool_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions src/tools/classic_tools/tool_brush.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

############################################################################

Expand Down
11 changes: 7 additions & 4 deletions src/tools/classic_tools/tool_eraser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down
11 changes: 7 additions & 4 deletions src/tools/classic_tools/tool_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")

Expand Down
21 changes: 11 additions & 10 deletions src/tools/classic_tools/tool_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'

Expand Down Expand Up @@ -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):
Expand Down
14 changes: 8 additions & 6 deletions src/tools/classic_tools/tool_pencil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
41 changes: 22 additions & 19 deletions src/tools/classic_tools/tool_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 0d99abb

Please sign in to comment.