Debian Codegraph @

src/optionsbars/transform/optionsbar_scale.py

raw symbols SCIP
1 # optionsbar_scale.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 Gtk
19 from .abstract_optionsbar import AbstractOptionsBar
20 from .utilities_units import utilities_add_unit_to_spinbtn
21
22 class OptionsBarScale(AbstractOptionsBar):
23 __gtype_name__ = 'OptionsBarScale'
24
25 def __init__(self, scale_tool):
26 super().__init__()
27
28 self._build_ui('transform/abstract-optionsbar-transform.ui')
29 builder = self._hydrate_transform_tool('transform/optionsbar-scale.ui')
30
31 self.width_btn = builder.get_object('width_btn')
32 self.height_btn = builder.get_object('height_btn')
33 utilities_add_unit_to_spinbtn(self.height_btn, 4, 'px')
34 utilities_add_unit_to_spinbtn(self.width_btn, 4, 'px')
35
36 self.width_100_btn = builder.get_object('width_100_btn')
37 self.height_100_btn = builder.get_object('height_100_btn')
38 utilities_add_unit_to_spinbtn(self.height_100_btn, 3, '%')
39 utilities_add_unit_to_spinbtn(self.width_100_btn, 3, '%')
40
41 self.width_label = builder.get_object('width_label')
42 self.height_label = builder.get_object('height_label')
43 self.separator = builder.get_object('separator')
44
45 def init_adaptability(self):
46 super().init_adaptability()
47 # this ^ just did a show_all, but both sets of spinbuttons can't be
48 # visible at the same time: the limit size only depends on one of them
49 self.width_100_btn.set_visible(False)
50 self.height_100_btn.set_visible(False)
51 temp_limit_size = self.centered_box.get_preferred_width()[0] + \
52 self.cancel_btn.get_preferred_width()[0] + \
53 self.options_btn.get_preferred_width()[0] + \
54 self.help_btn.get_preferred_width()[0] + \
55 self.apply_btn.get_preferred_width()[0]
56 self._set_limit_size(temp_limit_size)
57
58 def set_compact(self, state):
59 super().set_compact(state)
60 if state:
61 self.centered_box.set_orientation(Gtk.Orientation.VERTICAL)
62 else:
63 self.centered_box.set_orientation(Gtk.Orientation.HORIZONTAL)
64 # future possible improvement: the pane may not compact the same way if
65 # the manipulation concerns the selection.
66 self.width_label.set_visible(not state)
67 self.height_label.set_visible(not state)
68 self.separator.set_visible(not state)
69
70 ############################################################################
71 ################################################################################
72