1# optionsbar_selection.py
2#
3# Copyright 2018-2021 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
18from .abstract_optionsbar import AbstractOptionsBar
19
20class OptionsBarSelection(AbstractOptionsBar):
21	__gtype_name__ = 'OptionsBarSelection'
22
23	def __init__(self, window):
24		super().__init__()
25		self.window = window
26		builder = self._build_ui('selection/optionsbar-selection.ui')
27
28		self.import_box_narrow = builder.get_object('import_box_narrow')
29		self.import_box_long = builder.get_object('import_box_long')
30		self.clipboard_box = builder.get_object('clipboard_box')
31
32		self.actions_btn = builder.get_object('actions_btn')
33		self.actions_btn_long = builder.get_object('actions_btn_long')
34		self._togglable_btn = self.actions_btn
35
36		self.minimap_btn = builder.get_object('minimap_btn')
37		self.minimap_label = builder.get_object('minimap_label')
38		self.minimap_arrow = builder.get_object('minimap_arrow')
39
40	def get_minimap_btn(self):
41		return self.minimap_btn
42
43	def set_minimap_label(self, label):
44		self.minimap_label.set_label(label)
45
46	def middle_click_action(self):
47		self.window.lookup_action('new_tab_selection').activate()
48
49	############################################################################
50
51	def init_adaptability(self):
52		super().init_adaptability()
53		temp_limit_size = self.import_box_long.get_preferred_width()[0] + \
54		                    self.clipboard_box.get_preferred_width()[0] + \
55		                      self.actions_btn.get_preferred_width()[0] + \
56		                      self.options_btn.get_preferred_width()[0] + \
57		                         self.help_btn.get_preferred_width()[0] + \
58		                      self.minimap_btn.get_preferred_width()[0]
59		self._set_limit_size(temp_limit_size)
60
61	def set_compact(self, state):
62		super().set_compact(state)
63		self.import_box_narrow.set_visible(state)
64		self.import_box_long.set_visible(not state)
65		self.actions_btn.set_visible(not state)
66		self.clipboard_box.set_visible(not state)
67		if state:
68			self._togglable_btn = self.actions_btn_long
69		else:
70			self._togglable_btn = self.actions_btn
71		self.minimap_arrow.set_visible(not state)
72
73	############################################################################
74################################################################################
75
76