Debian Codegraph @

src/tools/selection_tools/select_color.py

raw symbols SCIP
1 # select_color.py
2 #
3 # Copyright 2018-2023 Romain F. T.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 from .abstract_select import AbstractSelectionTool
19 from .utilities_colors import utilities_get_rgba_name, \
20 utilities_gdk_rgba_from_xy, \
21 utilities_gdk_rgba_to_hexadecimal
22 from .utilities_paths import utilities_get_magic_path
23
24 class ToolColorSelect(AbstractSelectionTool):
25 __gtype_name__ = 'ToolColorSelect'
26
27 def __init__(self, window, **kwargs):
28 # Context: this is a tool to "magically" select an area depending on its
29 # color. For example clicking on a white pixel will select the
30 # surrounding area made of white pixels.
31 super().__init__('color_select', _("Color selection"), 'tool-magic-symbolic', window)
32
33 def get_tooltip(self, event_x, event_y, motion_behavior):
34 color = utilities_gdk_rgba_from_xy(self.get_surface(), event_x, event_y)
35 if color is None:
36 return None
37 color_name = utilities_get_rgba_name(color)
38 color_code = utilities_gdk_rgba_to_hexadecimal(color)
39 return color_name + "\n" + color_code
40
41 def get_editing_tips(self):
42 tips = super().get_editing_tips()
43 if not self.selection_is_active():
44 label_warning1 = self.label + " - " + _("May not work for complex shapes")
45 tips.append(label_warning1)
46 label_warning2 = self.label + " - " + _("It will not work well " + \
47 "if the area's edges are blurry")
48 tips.append(label_warning2)
49 return tips
50
51 ############################################################################
52
53 def press_define(self, event_x, event_y):
54 pass
55
56 def motion_define(self, event_x, event_y, render):
57 pass
58
59 def release_define(self, surfc, event_x, event_y):
60 path = utilities_get_magic_path(surfc, event_x, event_y, self.window, 1)
61 self._pre_load_path(path)
62 if path is None:
63 return
64 self.operation_type = 'op-define'
65 operation = self.build_operation()
66 self.apply_operation(operation)
67
68 ############################################################################
69 ################################################################################
70