6171: No icon under Places View for mapservices

* old way of menutoolbutton was depreacated, could not find workaround via uimanager, so 
    deprecated uimanager way, must be added by code now


svn: r20670
This commit is contained in:
Benny Malengier 2012-11-17 14:37:40 +00:00
parent 95e7a74f42
commit 79491a995c
5 changed files with 32 additions and 122 deletions

View File

@ -49,7 +49,6 @@ from gramps.gen.ggettext import gettext as _
#----------------------------------------------------------------
from gramps.gen.errors import WindowActiveError
from ..dbguielement import DbGUIElement
from ..widgets.menutoolbuttonaction import MenuToolButtonAction
from ..grampsbar import GrampsBar
from ..configure import ConfigureDialog
from gramps.gen.config import config
@ -431,16 +430,6 @@ class PageView(DbGUIElement):
self.action_group.add_actions(self.action_list)
if len(self.action_toggle_list) > 0:
self.action_group.add_toggle_actions(self.action_toggle_list)
for action_toolmenu in self.action_toolmenu_list:
self.action_toolmenu[action_toolmenu[0]] = \
MenuToolButtonAction(action_toolmenu[0], #unique name
action_toolmenu[1], #label
action_toolmenu[2], #tooltip
action_toolmenu[3], #callback
action_toolmenu[4] #arrow tooltip
)
self.action_group.add_action(
self.action_toolmenu[action_toolmenu[0]])
def _add_action(self, name, stock_icon, label, accel=None, tip=None,
callback=None):

View File

@ -1,87 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2009 Benny Malengier
#
# 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$
"MenuToolButtonAction class."
__all__ = ["MenuToolButtonAction"]
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger(".widgets.menutoolbuttonaction")
#-------------------------------------------------------------------------
#
# GTK modules
#
#-------------------------------------------------------------------------
from gi.repository import GObject
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
#
# MenuToolButtonAction class
#
#-------------------------------------------------------------------------
class MenuToolButtonAction(Gtk.Action):
"""MenuToolButton action class.
(A MenuToolButtonAction with menu item doesn't make any sense,
use for toolbar.)
"""
__gtype_name__ = "MenuToolButtonAction"
__gsignals__ = {
'changed': (GObject.SignalFlags.RUN_FIRST,
None, #return value
()), # arguments
}
def __init__(self, name, label, tooltip, callback, arrowtooltip):
"""Create a new MenuToolButtonAction instance.
@param name: the name of the action
@type name: str
@param tooltip: tooltip string
@type tooltip: str
"""
GObject.GObject.__init__(self, name=name, label=label, tooltip=tooltip,
stock_id=None)
##TODO GTK3: following is deprecated, must be replaced by
## Gtk.MenuToolButton.set_related_action(MenuToolButtonAction) in calling class?
## self.set_tool_item_type(Gtk.MenuToolButton)
if callback:
self.connect('activate', callback)
self.arrowtooltip = arrowtooltip

View File

@ -84,7 +84,7 @@ class MapService():
None, None if invalid
"""
return conv_lat_lon(place.get_latitude(),
place.get_longitude(), format)
place.get_longitude(), format)
def calc_url(self):
"""Base class needs to overwrite this, calculation of the self.path"""

View File

@ -150,7 +150,7 @@ class PlaceBaseView(ListView):
'<PRIMARY>J' : self.jump,
'<PRIMARY>BackSpace' : self.key_delete,
})
self.maptoolbtn = None
self.additional_uis.append(self.additional_ui())
def navigation_type(self):
@ -161,11 +161,6 @@ class PlaceBaseView(ListView):
def define_actions(self):
ListView.define_actions(self)
self._add_toolmenu_action('MapsList', _('Loading...'),
_("Attempt to see selected locations with a Map "
"Service (OpenstreetMap, Google Maps, ...)"),
self.gotomap,
_('Select a Map Service'))
self._add_action('GotoMap', Gtk.STOCK_JUMP_TO,
_('_Look up with Map Service'),
callback=self.gotomap,
@ -175,6 +170,13 @@ class PlaceBaseView(ListView):
callback=self.filter_editor)
self._add_action('QuickReport', None, _("Quick View"), None, None, None)
def set_inactive(self):
"""called by viewmanager when moving away from the page
Here we need to remove the menutoolbutton from the menu
"""
tb = self.uistate.viewmanager.uimanager.get_widget('/ToolBar')
tb.remove(self.maptoolbtn)
def change_page(self):
"""
Called by viewmanager at end of realization when arriving on the page
@ -186,11 +188,18 @@ class PlaceBaseView(ListView):
5. store label so it can be changed when selection changes
"""
ListView.change_page(self)
#menutoolbutton actions are stored in PageView class,
# obtain the widgets where we need to add to menu
actionservices = self.action_toolmenu['MapsList']
widgets = actionservices.get_proxies()
mmenu = self.__create_maps_menu_actions()
#menutoolbutton has to be made and added in correct place on toolbar
if not self.maptoolbtn:
self.maptoolbtn = Gtk.MenuToolButton.new_from_stock(Gtk.STOCK_JUMP_TO)
self.maptoolbtn.connect('clicked', self.gotomap)
self.mmenu = self.__create_maps_menu_actions()
self.maptoolbtn.set_menu(self.mmenu)
self.maptoolbtn.show()
tb = self.uistate.viewmanager.uimanager.get_widget('/ToolBar')
ind = tb.get_item_index(self.uistate.viewmanager.uimanager.get_widget(
'/ToolBar/CommonEdit/Merge'))
tb.insert(self.maptoolbtn, ind+1)
widget = self.maptoolbtn
if not self.mapservicedata:
return
@ -200,16 +209,17 @@ class PlaceBaseView(ListView):
#stored val no longer exists, use the first key instead
self.set_mapservice(list(self.mapservicedata.keys())[0])
#store all gtk labels to be able to update label on selection change
for widget in widgets :
if isinstance(widget, Gtk.MenuToolButton):
widget.set_menu(mmenu)
widget.set_arrow_tooltip_text(actionservices.arrowtooltip)
lbl = Gtk.Label(label=self.mapservice_label())
lbl.show()
self.mapslistlabel.append(lbl)
widget.set_label_widget(self.mapslistlabel[-1])
widget.set_stock_id(Gtk.STOCK_JUMP_TO)
#store all gtk labels to be able to update label on selection change_('Loading...'),
widget.set_menu(self.mmenu)
widget.set_arrow_tooltip_text(_('Select a Map Service'))
widget.set_tooltip_text(
_("Attempt to see selected locations with a Map "
"Service (OpenstreetMap, Google Maps, ...)"))
lbl = Gtk.Label(label=self.mapservice_label())
lbl.show()
self.mapslistlabel.append(lbl)
widget.set_label_widget(self.mapslistlabel[-1])
widget.set_stock_id(Gtk.STOCK_JUMP_TO)
if self.drag_info():
self.list.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK,
[],
@ -341,7 +351,6 @@ class PlaceBaseView(ListView):
<toolitem action="Remove"/>
<toolitem action="Merge"/>
<separator/>
<toolitem action="MapsList"/>
</placeholder>
</toolbar>
<popup name="Popup">

View File

@ -376,7 +376,6 @@ gramps/gui/widgets/basicentry.py
gramps/gui/widgets/fanchartdesc.py
gramps/gui/widgets/linkbox.py
gramps/gui/widgets/menuitem.py
gramps/gui/widgets/menutoolbuttonaction.py
gramps/gui/widgets/multitreeview.py
gramps/gui/widgets/shortlistcomboentry.py
gramps/gui/widgets/springseparator.py