Skip to content

Commit

Permalink
text tool: help tips, + apply when changing to another tool #357
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Feb 17, 2023
1 parent ea78324 commit 64a40b2
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/tools/classic_tools/tool_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ToolText(AbstractClassicTool):

def __init__(self, window, **kwargs):
super().__init__('text', _("Text"), 'tool-text-symbolic', window)
self._should_cancel = False

# There are several types of possible interactions with the canvas,
# depending on where the pointer is during the press event.
Expand Down Expand Up @@ -100,6 +99,13 @@ def get_options_label(self):
return _("Text options")

def get_editing_tips(self):
if self._has_current_text():
label_move = self.label + " - " + _("Grab the rectangle to adjust the text position")
label_apply = self.label + " - " + _("Click outside the rectangle to apply")
else:
label_move = None
label_apply = None

label_options = self.label + " - " + self._font_fam_name
if self._background_id != 'none':
bg_label = {
Expand All @@ -110,7 +116,9 @@ def get_editing_tips(self):
'rectangle': _("Rectangle background"),
}[self._background_id]
label_options += " - " + bg_label
return [label_options]

full_list = [label_options, label_move, label_apply]
return list(filter(None, full_list))

def on_options_changed(self):
super().on_options_changed()
Expand All @@ -127,7 +135,11 @@ def on_tool_unselected(self):
self.set_action_sensitivity('selection_copy', True)

def give_back_control(self, preserve_selection, next_tool=None):
if self._should_cancel:
if self._has_current_text():
operation = self.build_operation()
self.apply_operation(operation)
self._set_string('')
else:
self._on_cancel()
return next_tool

Expand Down Expand Up @@ -172,7 +184,6 @@ def on_motion_on_area(self, event, surface, event_x, event_y, render=True):
self._preview_text()

def on_release_on_area(self, event, surface, event_x, event_y):
self._should_cancel = True
if 'input' == self._pointer_target:
if not self._has_current_text():
self.set_common_values(event.button, event_x, event_y)
Expand Down Expand Up @@ -266,7 +277,13 @@ def on_draw_above(self, area, ccontext):
def _on_cancel(self, *args):
self._hide_entry()
self._set_string('')
self._should_cancel = False

def on_unclicked_motion_on_area(self, event, surface):
if not self._has_current_text():
self.cursor_name = 'text'
else:
self.cursor_name = 'pointer'
self.window.set_cursor(True)

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

Expand Down

0 comments on commit 64a40b2

Please sign in to comment.