1# 2# Gramps - a GTK+/GNOME based genealogy program 3# 4# Copyright (C) 2000-2006 Donald N. Allingham 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19# 20 21__all__ = ["ExpandCollapseArrow"] 22 23#------------------------------------------------------------------------- 24# 25# Standard python modules 26# 27#------------------------------------------------------------------------- 28from gramps.gen.const import GRAMPS_LOCALE as glocale 29_ = glocale.translation.gettext 30 31import logging 32_LOG = logging.getLogger(".widgets.expandcollapsearrow") 33 34#------------------------------------------------------------------------- 35# 36# GTK/Gnome modules 37# 38#------------------------------------------------------------------------- 39from gi.repository import Gtk 40from gi.repository import Gdk 41from gramps.gen.constfunc import has_display 42 43#------------------------------------------------------------------------- 44# 45# Constants 46# 47#------------------------------------------------------------------------- 48if has_display(): 49 HAND_CURSOR = Gdk.Cursor.new_for_display(Gdk.Display.get_default(), 50 Gdk.CursorType.HAND2) 51 52#------------------------------------------------------------------------- 53# 54# Module functions 55# 56#------------------------------------------------------------------------- 57def realize_cb(widget): 58 widget.get_window().set_cursor(HAND_CURSOR) 59 60#------------------------------------------------------------------------- 61# 62# ExpandCollapseArrow class 63# 64#------------------------------------------------------------------------- 65class ExpandCollapseArrow(Gtk.EventBox): 66 """ 67 Arrow to be used for expand/collapse of sections. 68 69 .. note:: shadow does not work, we indicate action with realize_cb 70 """ 71 def __init__(self, collapsed, onbuttonpress, pair): 72 """ 73 Constructor for the ExpandCollapseArrow class. 74 75 :param collapsed: True if arrow must be shown collapsed, 76 False otherwise 77 :type collapsed: bool 78 :param onbuttonpress: The callback function for button press 79 :type onbuttonpress: callback 80 :param pair: user param for onbuttonpress function 81 """ 82 Gtk.EventBox.__init__(self) 83 if collapsed : 84 self.arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.RIGHT, 85 shadow_type=Gtk.ShadowType.OUT) 86 self.set_tooltip_text(_("Expand this section")) 87 else: 88 self.arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, 89 shadow_type=Gtk.ShadowType.OUT) 90 self.set_tooltip_text(_("Collapse this section")) 91 self.add(self.arrow) 92 self.connect('button-press-event', onbuttonpress, pair) 93 self.connect('realize', realize_cb) 94