Skip to content

Commit

Permalink
implement on_options_changed preview #357 for the "shapes" tool
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Jan 31, 2023
1 parent abbdfe9 commit bff80e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/tools/classic_tools/abstract_classic_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def build_bottom_pane(self):
def set_common_values(self, event_btn, event_x, event_y):
self.x_press = event_x
self.y_press = event_y
self._last_btn = event_btn
# TODO eventually all tools will correctly rely on on_options_changed so
# this call to _set_options will only exist if the button changed
self._set_options(event_btn)
self._last_btn = event_btn

def on_options_changed(self):
self._set_options(self._last_btn)
Expand Down
24 changes: 18 additions & 6 deletions src/tools/classic_tools/tool_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,15 @@ def get_options_label(self):
return _("Shape options")

def get_editing_tips(self):
self._set_active_shape()
shape_name = self.SHAPE_TYPES[self._shape_id]

label_options = shape_name
self._set_filling_style()
self._set_outline_style()

if self._outline_id != 'solid':
label_options += " - " + self.OUTLINE_TYPES[self._outline_id]
if self._filling_id != 'empty':
label_options += " - " + self.FILLING_TYPES[self._filling_id]

if (self._shape_id == 'polygon' or self._shape_id == 'freeshape') and \
self._path is not None:
if self._shape_id in ['polygon', 'freeshape'] and self._path is not None:
label_instruction = shape_name + " - " + \
_("Click on the shape's first point to close it.")
else:
Expand All @@ -139,6 +135,19 @@ def get_editing_tips(self):
full_list = [label_options, label_instruction, label_modifiers]
return list(filter(None, full_list))

def on_options_changed(self):
super().on_options_changed()
self._set_active_shape()
self._set_filling_style()
self._set_outline_style()

if self._path is None:
return
operation = self.build_operation(self._path)
if self._shape_id in ['polygon', 'freeshape']:
operation['closed'] = False
self.do_tool_operation(operation)

def give_back_control(self, preserve_selection, next_tool=None):
self.restore_pixbuf()
self._reset_temp_points()
Expand All @@ -150,6 +159,7 @@ def on_press_on_area(self, event, surface, event_x, event_y):
self.last_mouse_btn = event.button
self.set_common_values(self.last_mouse_btn, event_x, event_y)

former_modifiers = self._modifier_keys
self.update_modifier_state(event.state)
if 'SHIFT' in self._modifier_keys and 'ALT' in self._modifier_keys:
self._filling_id = 'secondary'
Expand All @@ -160,6 +170,8 @@ def on_press_on_area(self, event, surface, event_x, event_y):
elif 'ALT' in self._modifier_keys:
self._filling_id = 'filled'
self._outline_id = 'none'
elif former_modifiers != self._modifier_keys:
self.on_options_changed()

def on_motion_on_area(self, event, surface, event_x, event_y, render=True):
if self._shape_id == 'freeshape':
Expand Down

0 comments on commit bff80e0

Please sign in to comment.