Debian Codegraph @

src/optionsbars/transform/optionsbar_filters.py

raw symbols SCIP
1 # optionsbar_filters.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 OptionsBarFilters(AbstractOptionsBar):
23 __gtype_name__ = 'OptionsBarFilters'
24
25 def __init__(self, window, filters_tool):
26 super().__init__()
27 self.window = window
28 self.filters_tool = filters_tool
29
30 self._build_ui('transform/abstract-optionsbar-transform.ui')
31 builder = self._hydrate_transform_tool('transform/optionsbar-filters.ui')
32
33 self.menu_btn = builder.get_object('menu_btn')
34 self._togglable_btn = self.menu_btn
35 self.menu_btn.set_menu_model(self.filters_tool.get_options_model())
36 self._menu_label = builder.get_object('menu_label')
37 self._menu_icon = builder.get_object('menu_icon')
38
39 def add_spinbtn(self, caption, adj_as_array, spin_chars, unit):
40 widget_label = Gtk.Label(label=caption)
41 widget_spinbtn = Gtk.SpinButton(tooltip_text=caption)
42 adj = Gtk.Adjustment()
43 # it's [value, lower, upper, step_increment, page_increment, page_size]
44 adj.configure(*adj_as_array)
45 widget_spinbtn.set_adjustment(adj)
46 utilities_add_unit_to_spinbtn(widget_spinbtn, spin_chars, unit)
47
48 self.centered_box.add(widget_label)
49 self.centered_box.add(widget_spinbtn)
50 return widget_label, widget_spinbtn
51
52 ############################################################################
53
54 def init_adaptability(self):
55 super().init_adaptability()
56 self._menu_icon.set_visible(False)
57 widgets_size = self.filters_tool.get_max_filter_width()
58 temp_limit_size = self.menu_btn.get_preferred_width()[0] + \
59 50 + widgets_size + \
60 self.cancel_btn.get_preferred_width()[0] + \
61 self.help_btn.get_preferred_width()[0] + \
62 self.apply_btn.get_preferred_width()[0]
63 self._set_limit_size(temp_limit_size)
64
65 def on_filter_changed(self):
66 self.set_compact(self._is_narrow)
67 self.window.set_window_subtitles()
68 # self.menu_label.set_label(self.filters_tool.type_label) # XXX width???
69
70 def set_compact(self, state):
71 super().set_compact(state)
72 self._menu_label.set_visible(not state)
73 self._menu_icon.set_visible(state)
74 self.filters_tool.set_filters_compact(state)
75
76 ############################################################################
77 ################################################################################
78