diff --git a/src/tools/classic_tools/tool_line.py b/src/tools/classic_tools/tool_line.py index a194f542..3394e283 100644 --- a/src/tools/classic_tools/tool_line.py +++ b/src/tools/classic_tools/tool_line.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import cairo +import cairo, math from .abstract_classic_tool import AbstractClassicTool from .utilities_paths import utilities_add_arrow_triangle @@ -41,6 +41,19 @@ def __init__(self, window, **kwargs): self.add_tool_action_boolean('line-ortholock', self._ortholock) self._set_options_attributes() # Not optimal but more readable + def get_tooltip(self, event_x, event_y, motion_behavior): + if motion_behavior != 1: + return None # no line is being drawn + + delta_x = abs(self.x_press - event_x) + delta_y = abs(self.y_press - event_y) + line1 = _("Width: %spx") % str(delta_x) + line2 = _("Height: %spx") % str(delta_y) + length = round(math.sqrt(delta_x * delta_x + delta_y * delta_y), 2) + return line1 + "\n" + line2 + "\n" + _("Length: %spx") % str(length) + + ############################################################################ + def _set_active_shape(self): state_as_string = self.get_option_value('line_shape') if state_as_string == 'thin': diff --git a/src/tools/classic_tools/tool_shape.py b/src/tools/classic_tools/tool_shape.py index 61052de0..9714a46a 100644 --- a/src/tools/classic_tools/tool_shape.py +++ b/src/tools/classic_tools/tool_shape.py @@ -48,6 +48,25 @@ def _reset_temp_points(self): self.initial_x = -1.0 self.initial_y = -1.0 + def get_tooltip(self, event_x, event_y, motion_behavior): + if motion_behavior != 1: + return None # no line is being drawn + if self._shape_id in ['polygon', 'freeshpae']: + return None # no tooltip for these shapes + + delta_x = abs(self.x_press - event_x) + delta_y = abs(self.y_press - event_y) + + if self._shape_id == 'circle': + length = round(math.sqrt(delta_x * delta_x + delta_y * delta_y), 2) + return _("Radius: %spx") % length + + line1 = _("Width: %spx") % str(delta_x) + line2 = _("Height: %spx") % str(delta_y) + return line1 + "\n" + line2 + + ############################################################################ + def _set_filling_style(self): self._filling_id = self.get_option_value('shape_filling') diff --git a/src/tools/selection_tools/select_rect.py b/src/tools/selection_tools/select_rect.py index 911bad24..f87aef16 100644 --- a/src/tools/selection_tools/select_rect.py +++ b/src/tools/selection_tools/select_rect.py @@ -24,6 +24,18 @@ class ToolRectSelect(AbstractSelectionTool): def __init__(self, window, **kwargs): super().__init__('rect_select', _("Rectangle selection"), 'tool-select-rect-symbolic', window) + def get_tooltip(self, event_x, event_y, motion_behavior): + if motion_behavior != 1: + return None # no line is being drawn + + delta_x = abs(self.x_press - event_x) + delta_y = abs(self.y_press - event_y) + line1 = _("Width: %spx") % str(delta_x) + line2 = _("Height: %spx") % str(delta_y) + return line1 + "\n" + line2 + + ############################################################################ + def press_define(self, event_x, event_y): pass