Skip to content

Commit

Permalink
on_options_changed for the "scale" tool #357
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Feb 19, 2023
1 parent 064d4f4 commit 52a4b24
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/tools/transform_tools/tool_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ def get_options_label(self):
return _("Scaling options")

def get_editing_tips(self):
# The current method is called when options change, so i use it to:

# 1) update the visibility of the spinbuttons depending on which ones
# the user wants to use.
self._update_to_wanted_unit()

# 2) update the bullshit around ratio preservation actions
ratio_option = self.get_option_value('scale-proportions')
if not ratio_option == 'corners':
action = self.window.lookup_action('scale-ratio-spinbtns')
action.set_state(GLib.Variant.new_boolean(ratio_option == 'always'))
self.set_action_sensitivity('scale-ratio-spinbtns', ratio_option == 'corners')

if self.apply_to_selection:
label_action = _("Scaling the selection")
label_confirm = None
Expand All @@ -107,6 +94,28 @@ def get_editing_tips(self):
full_list = [label_action, label_confirm, label_modifier_shift]
return list(filter(None, full_list))

def on_options_changed(self):
# 1) update the visibility of the spinbuttons depending on which ones
# the user wants to use.
want_pixels = self.get_option_value('scale-unit') == 'pixels'
if want_pixels:
self._width_btn.set_visible(True)
self._height_btn.set_visible(True)
self._w100_btn.set_visible(False)
self._h100_btn.set_visible(False)
else:
self._width_btn.set_visible(False)
self._height_btn.set_visible(False)
self._w100_btn.set_visible(True)
self._h100_btn.set_visible(True)

# 2) update the bullshit around ratio preservation actions
ratio_option = self.get_option_value('scale-proportions')
if not ratio_option == 'corners':
action = self.window.lookup_action('scale-ratio-spinbtns')
action.set_state(GLib.Variant.new_boolean(ratio_option == 'always'))
self.set_action_sensitivity('scale-ratio-spinbtns', ratio_option == 'corners')

def on_tool_selected(self, *args):
super().on_tool_selected()
self._x = 0
Expand All @@ -133,19 +142,6 @@ def _get_original_size(self):

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

def _update_to_wanted_unit(self):
want_pixels = self.get_option_value('scale-unit') == 'pixels'
if want_pixels:
self._width_btn.set_visible(True)
self._height_btn.set_visible(True)
self._w100_btn.set_visible(False)
self._h100_btn.set_visible(False)
else:
self._width_btn.set_visible(False)
self._height_btn.set_visible(False)
self._w100_btn.set_visible(True)
self._h100_btn.set_visible(True)

def set_preserve_ratio(self, for_spinbtns=False):
"""Set whether or not `self._preserve_ratio` should be true. If it is,
AND that wasn't already the case before, this method sets the value of
Expand Down

0 comments on commit 52a4b24

Please sign in to comment.