From 140f23536fd814326dc7bd49b1fd5115e61c655f Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Thu, 5 Jul 2012 14:51:14 +0000 Subject: [PATCH] Right click for popup working on listviews svn: r19954 --- src/gui/editors/displaytabs/eventrefmodel.py | 1 + src/gui/editors/displaytabs/namemodel.py | 1 + src/gui/editors/displaytabs/surnamemodel.py | 1 - src/gui/utils.py | 11 --- src/gui/views/listview.py | 2 +- src/gui/widgets/Makefile.am | 1 + src/gui/widgets/grampletpane.py | 5 +- src/gui/widgets/menuitem.py | 74 ++++++++++++++++++++ src/plugins/lib/libplaceview.py | 2 +- 9 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 src/gui/widgets/menuitem.py diff --git a/src/gui/editors/displaytabs/eventrefmodel.py b/src/gui/editors/displaytabs/eventrefmodel.py index c2c3dbb27..cecdd2087 100644 --- a/src/gui/editors/displaytabs/eventrefmodel.py +++ b/src/gui/editors/displaytabs/eventrefmodel.py @@ -33,6 +33,7 @@ from gen.ggettext import gettext as _ # GTK libraries # #------------------------------------------------------------------------- +from gi.repository import GObject from gi.repository import Gtk from gi.repository import Pango WEIGHT_NORMAL = Pango.Weight.NORMAL diff --git a/src/gui/editors/displaytabs/namemodel.py b/src/gui/editors/displaytabs/namemodel.py index 26947dd6b..9ef7ff92d 100644 --- a/src/gui/editors/displaytabs/namemodel.py +++ b/src/gui/editors/displaytabs/namemodel.py @@ -34,6 +34,7 @@ from gen.ggettext import gettext as _ # GTK libraries # #------------------------------------------------------------------------- +from gi.repository import GObject from gi.repository import Gtk from gi.repository import Pango WEIGHT_NORMAL = Pango.Weight.NORMAL diff --git a/src/gui/editors/displaytabs/surnamemodel.py b/src/gui/editors/displaytabs/surnamemodel.py index ff1a55b54..12400c6a1 100644 --- a/src/gui/editors/displaytabs/surnamemodel.py +++ b/src/gui/editors/displaytabs/surnamemodel.py @@ -27,7 +27,6 @@ # #------------------------------------------------------------------------- from gi.repository import Gtk -from gi.repository import GObject #------------------------------------------------------------------------- # diff --git a/src/gui/utils.py b/src/gui/utils.py index 7a03732e8..480ae5485 100644 --- a/src/gui/utils.py +++ b/src/gui/utils.py @@ -55,17 +55,6 @@ from gen.constfunc import has_display, is_quartz, mac, win # # #------------------------------------------------------------------------- -def add_menuitem(menu, msg, obj, func): - """ - add a menuitem to menu with label msg, which activates func, and has data - obj - """ - from gi.repository import Gtk - item = Gtk.MenuItem(label=msg) - item.set_data('o', obj) - item.connect("activate", func) - item.show() - menu.append(item) class CLIVbox(): """ diff --git a/src/gui/views/listview.py b/src/gui/views/listview.py index 47e37bc8c..559101a55 100644 --- a/src/gui/views/listview.py +++ b/src/gui/views/listview.py @@ -57,7 +57,7 @@ from gui.columnorder import ColumnOrder from gen.config import config from gen.errors import WindowActiveError from gui.filters import SearchBar -from gui.utils import add_menuitem +from gui.widgets.menuitem import add_menuitem from gen.const import CUSTOM_FILTERS, USE_TIPS from gen.utils.debug import profile from gen.utils.string import data_recover_msg diff --git a/src/gui/widgets/Makefile.am b/src/gui/widgets/Makefile.am index a7143f890..8e4c36576 100644 --- a/src/gui/widgets/Makefile.am +++ b/src/gui/widgets/Makefile.am @@ -14,6 +14,7 @@ pkgpython_PYTHON = \ grampletpane.py \ labels.py \ linkbox.py \ + menuitem.py \ menutoolbuttonaction.py \ monitoredwidgets.py \ multitreeview.py \ diff --git a/src/gui/widgets/grampletpane.py b/src/gui/widgets/grampletpane.py index 13773420f..55e4e7023 100644 --- a/src/gui/widgets/grampletpane.py +++ b/src/gui/widgets/grampletpane.py @@ -49,6 +49,7 @@ from gen.const import URL_MANUAL_PAGE, VERSION_DIR from gui.editors import EditPerson, EditFamily from gui.managedwindow import ManagedWindow import gui.utils +from gui.widgets.menuitem import add_menuitem from gui.plug.quick import run_quick_report_by_name from gui.display import display_help, display_url from gui.glade import Glade @@ -1386,7 +1387,7 @@ class GrampletPane(Gtk.ScrolledWindow): if gplug.navtypes == []] names.sort() for name in names: - gui.utils.add_menuitem(qr_menu, name, None, + add_menuitem(qr_menu, name, None, self.add_gramplet) ag_menu.set_submenu(qr_menu) rg_menu = uiman.get_widget('/GrampletPopup/RestoreGramplet') @@ -1400,7 +1401,7 @@ class GrampletPane(Gtk.ScrolledWindow): if len(names) > 0: qr_menu = Gtk.Menu() for name in names: - gui.utils.add_menuitem(qr_menu, name, None, + add_menuitem(qr_menu, name, None, self.restore_gramplet) rg_menu.set_submenu(qr_menu) menu = uiman.get_widget('/GrampletPopup') diff --git a/src/gui/widgets/menuitem.py b/src/gui/widgets/menuitem.py new file mode 100644 index 000000000..04d3df384 --- /dev/null +++ b/src/gui/widgets/menuitem.py @@ -0,0 +1,74 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2008 Zsolt Foldvari +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id: toolcomboentry.py 19858 2012-06-17 21:25:37Z bmcage $ + +"ToolComboEntry class." + +__all__ = ["MenuItemWithData", "add_menuitem"] + +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +import logging +_LOG = logging.getLogger(".widgets.menuitem") + +#------------------------------------------------------------------------- +# +# GTK modules +# +#------------------------------------------------------------------------- +from gi.repository import GObject +from gi.repository import Gtk + +#------------------------------------------------------------------------- +# +# MenuItemWithData class +# +#------------------------------------------------------------------------- + + +class MenuItemWithData(Gtk.MenuItem): + """ A MenuItem that stores a data property. As set_data in GTK3 is not + working, this is a workaround to have set_data""" + data = GObject.Property(type=object) + + def __init__(self, label=''): + GObject.GObject.__init__(self, label=label) + + def set_data(self, data): + self.data = data + + def get_data(self, _=None): + """ obtain the data, for backward compat, we allow a dummy argument""" + return self.data + +def add_menuitem(menu, msg, obj, func): + """ + add a menuitem to menu with label msg, which activates func, and has data + obj + """ + item = MenuItemWithData(label=msg) + item.set_data(obj) + item.connect("activate", func) + item.show() + menu.append(item) diff --git a/src/plugins/lib/libplaceview.py b/src/plugins/lib/libplaceview.py index 124237032..637b6ebd8 100644 --- a/src/plugins/lib/libplaceview.py +++ b/src/plugins/lib/libplaceview.py @@ -47,7 +47,7 @@ from gi.repository import Gtk #------------------------------------------------------------------------- import gen.lib from gui.views.listview import ListView -from gui.utils import add_menuitem +from gui.widgets.menuitem import add_menuitem from gen.errors import WindowActiveError from gui.views.bookmarks import PlaceBookmarks from gen.config import config