Skip to content

Commit

Permalink
Action to define the selection as the current image (#332 #369 #85)
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed May 12, 2021
1 parent eada619 commit 79f70d6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/tools/selection_tools/abstract_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ def import_selection(self, pixbuf):
self.apply_operation(operation)
self.operation_type = 'op-define'

def replace_canvas(self):
self.operation_type = 'op-replace-canvas'
# XXX it's copied so many times?! ugly but seems necessary
self._future_pixbuf = self.get_selection_pixbuf().copy()
operation = self.build_operation()
self.apply_operation(operation)
self.operation_type = 'op-define'

def expand_canvas(self):
pass

def invert_selection(self):
pass # TODO

def unselect_and_apply(self):
# Pre-loading the coords is NEEDED because we may "unselect_and_apply" a
# selection which was defined by a selection manager in very different
Expand Down Expand Up @@ -325,6 +339,14 @@ def _op_import(self, op):
self.get_selection().set_coords(False, op['pixb_x'], op['pixb_y'])
self.get_selection().set_pixbuf(op['pixbuf'].copy())

def _op_replace_canvas(self, op):
if op['pixbuf'] is None:
raise NoSelectionPixbufException()
self.get_image().set_main_pixbuf(op['pixbuf'].copy())
self.get_image().use_stable_pixbuf()
self.get_selection().reset(True)
self.get_selection().reset_future_data()

def _op_clean(self, operation):
if operation['initial_path'] is None:
return # The user double-clicked: there is no path, and it's normal
Expand Down Expand Up @@ -374,6 +396,9 @@ def do_tool_operation(self, operation):
# de type "clic-droit > importer" ou "clic-droit > coller".
# On charge un pixbuf dans le selection_manager.
self._op_import(operation)
elif operation['operation_type'] == 'op-replace-canvas':
# TODO commentaire
self._op_replace_canvas(operation)
elif operation['operation_type'] == 'op-define':
# Opération instantanée (sans preview), correspondant à une
# sélection (rectangulaire ou non) par définition d'un path.
Expand Down
10 changes: 7 additions & 3 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,14 @@ def add_all_win_actions(self):
self.add_action_simple('paste', self.action_paste, ['<Ctrl>v'])
self.add_action_simple('select_all', self.action_select_all, ['<Ctrl>a'])
self.add_action_simple('unselect', self.action_unselect, ['<Ctrl><Shift>a'])
#self.add_action_simple('selection_invert', self.action_selection_invert, None)
self.add_action_simple('selection_cut', self.action_cut, ['<Ctrl>x'])
self.add_action_simple('selection_copy', self.action_copy, ['<Ctrl>c'])
self.add_action_simple('selection_delete', self.action_delete, ['Delete'])

self.add_action_simple('selection_export', self.action_selection_export, None)
self.add_action_simple('selection-replace-canvas', \
self.action_selection_replace_canvas, None)

self.add_action_simple('back_to_previous', self.back_to_previous, ['<Ctrl>b'])
self.add_action_simple('force_selection', self.force_selection, None)
Expand Down Expand Up @@ -1132,13 +1136,13 @@ def action_selection_export(self, *args):
return self.saving_manager.save_current_image(True, True, True, True)

def action_selection_replace_canvas(self, *args):
pass
self.get_selection_tool().replace_canvas()

def action_selection_expand_canvas(self, *args):
pass
self.get_selection_tool().expand_canvas()

def action_selection_invert(self, *args):
pass
self.get_selection_tool().invert_selection()

def get_selection_tool(self):
if 'rect_select' in self.tools:
Expand Down

0 comments on commit 79f70d6

Please sign in to comment.