Debian Codegraph @

src/tools/selection_tools/select_rect.py

raw symbols SCIP
1 # select_rect.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_overlay import utilities_show_overlay_on_context
20
21 class ToolRectSelect(AbstractSelectionTool):
22 __gtype_name__ = 'ToolRectSelect'
23
24 def __init__(self, window, **kwargs):
25 super().__init__('rect_select', _("Rectangle selection"), 'tool-select-rect-symbolic', window)
26
27 def get_tooltip(self, event_x, event_y, motion_behavior):
28 if motion_behavior != 1:
29 return None # no line is being drawn
30
31 delta_x = abs(self.x_press - event_x)
32 delta_y = abs(self.y_press - event_y)
33 line1 = _("Width: %spx") % str(delta_x)
34 line2 = _("Height: %spx") % str(delta_y)
35 return line1 + "\n" + line2
36
37 ############################################################################
38
39 def press_define(self, event_x, event_y):
40 pass
41
42 def motion_define(self, event_x, event_y, render):
43 if not render:
44 return
45 self._build_rectangle_path(self.x_press, self.y_press, event_x, event_y)
46 self.restore_pixbuf()
47 rect = self.get_selection().get_future_path()
48 if rect is not None:
49 ccontext = self.get_context()
50 thickness = self.get_overlay_thickness()
51 utilities_show_overlay_on_context(ccontext, rect, thickness)
52
53 def release_define(self, surface, event_x, event_y):
54 self._build_rectangle_path(self.x_press, self.y_press, event_x, event_y)
55 self.operation_type = 'op-define'
56 operation = self.build_operation()
57 self.apply_operation(operation)
58 # self.get_selection().show_popover()
59
60 ############################################################################
61 ################################################################################