1# This file is part of Gajim. 2# 3# Gajim is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published 5# by the Free Software Foundation; version 3 only. 6# 7# Gajim is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU General Public License for more details. 11# 12# You should have received a copy of the GNU General Public License 13# along with Gajim. If not, see <http://www.gnu.org/licenses/>. 14 15 16from gi.repository import Gtk 17 18 19class SideBarSwitcher(Gtk.ListBox): 20 def __init__(self): 21 Gtk.ListBox.__init__(self) 22 self.set_vexpand(True) 23 self.get_style_context().add_class('settings-menu') 24 self.connect('row-activated', self._on_row_activated) 25 self._stack = None 26 27 def set_stack(self, stack): 28 self._stack = stack 29 for page in self._stack.get_children(): 30 attributes = ['name', 'title', 'icon-name'] 31 properties = self._stack.child_get(page, *attributes) 32 self.add(Row(*properties)) 33 34 self._select_first_row() 35 36 def _on_row_activated(self, _listbox, row): 37 self._stack.set_visible_child_name(row.name) 38 39 def _select_first_row(self): 40 self.select_row(self.get_row_at_index(0)) 41 42 43class Row(Gtk.ListBoxRow): 44 def __init__(self, name, title, icon_name): 45 Gtk.ListBoxRow.__init__(self) 46 47 self.name = name 48 box = Gtk.Box() 49 if icon_name: 50 image = Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.MENU) 51 image.get_style_context().add_class('dim-label') 52 box.add(image) 53 54 label = Gtk.Label(label=title) 55 label.set_xalign(0) 56 box.add(label) 57 self.add(box) 58