Debian Codegraph @

src/tools/classic_tools/tool_picker.py

raw symbols SCIP
1 # tool_picker.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 gi.repository import Gdk
19 from .abstract_classic_tool import AbstractClassicTool
20 from .utilities_colors import utilities_get_rgba_name, \
21 utilities_gdk_rgba_from_xy, \
22 utilities_gdk_rgba_to_hexadecimal
23
24 class ToolPicker(AbstractClassicTool):
25 __gtype_name__ = 'ToolPicker'
26
27 def __init__(self, window, **kwargs):
28 # Context: this is a tool to pick a RGBA color in the image in order to
29 # use it to draw with other tools
30 super().__init__('picker', _("Color Picker"), 'color-select-symbolic', window)
31 self.use_size = False
32
33 def get_options_model(self):
34 return None
35
36 def get_tooltip(self, event_x, event_y, motion_behavior):
37 color = utilities_gdk_rgba_from_xy(self.get_surface(), event_x, event_y)
38 if color is None:
39 return None
40 color_name = utilities_get_rgba_name(color)
41 color_code = utilities_gdk_rgba_to_hexadecimal(color)
42 return color_name + "\n" + color_code
43
44 def on_release_on_area(self, event, surface, event_x, event_y):
45 color = utilities_gdk_rgba_from_xy(surface, event_x, event_y)
46 if event.button == 1:
47 self.window.options_manager.set_left_color(color)
48 elif event.button == 3:
49 self.window.options_manager.set_right_color(color)
50 self.window.back_to_previous()
51
52 ############################################################################
53 ################################################################################