GeoView : Now using NavigationView
svn: r16500
This commit is contained in:
parent
004466dd4d
commit
55385c32c6
@ -74,7 +74,7 @@ import config
|
||||
import Errors
|
||||
from gen.display.name import displayer as _nd
|
||||
from PlaceUtils import conv_lat_lon
|
||||
from gui.views.pageview import PageView
|
||||
from gui.views.navigationview import NavigationView
|
||||
from gui.editors import EditPlace
|
||||
from gui.selectors.selectplace import SelectPlace
|
||||
from Filters.SideBar import PlaceSidebarFilter, EventSidebarFilter
|
||||
@ -119,23 +119,6 @@ from htmlrenderer import HtmlView
|
||||
#covert to unicode for better hadnling of path in Windows
|
||||
GEOVIEW_SUBPATH = Utils.get_empty_tempdir('geoview')
|
||||
|
||||
DISABLED = -1
|
||||
MRU_SIZE = 10
|
||||
|
||||
MRU_TOP = [
|
||||
'<ui>'
|
||||
'<menubar name="MenuBar">'
|
||||
'<menu action="GoMenu">'
|
||||
'<placeholder name="CommonHistory">'
|
||||
]
|
||||
|
||||
MRU_BTM = [
|
||||
'</placeholder>'
|
||||
'</menu>'
|
||||
'</menubar>'
|
||||
'</ui>'
|
||||
]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
@ -311,30 +294,18 @@ class GeoView(HtmlView):
|
||||
self.dbstate = dbstate
|
||||
self.uistate = uistate
|
||||
self.dbstate.connect('database-changed', self._new_database)
|
||||
self.fwd_action = None
|
||||
self.back_action = None
|
||||
self.book_action = None
|
||||
self.other_action = None
|
||||
self.active_signal = None
|
||||
self.mru_signal = None
|
||||
self.widget = None
|
||||
self.nav_group = 0
|
||||
self.mru_active = DISABLED
|
||||
self.invalidpath = const.ROOT_DIR.find("(")
|
||||
if self.invalidpath != -1:
|
||||
_LOG.debug("\n\nInvalid PATH (avoid parenthesis):\n%s\n\n" %
|
||||
const.ROOT_DIR)
|
||||
|
||||
self.uistate.register(dbstate, self.navigation_type(), self.nav_group)
|
||||
self.bookmarks = Bookmarks.PersonBookmarks(self.dbstate, self.uistate,
|
||||
dbstate.db.get_bookmarks(), self.goto_handle)
|
||||
self.displaytype = "person"
|
||||
|
||||
self.additional_uis.append(self.additional_ui())
|
||||
|
||||
def build_widget(self):
|
||||
self.no_network = False
|
||||
self.placeslist = []
|
||||
self.displaytype = "person"
|
||||
self.nbmarkers = 0
|
||||
self.nbplaces = 0
|
||||
self.without = 0
|
||||
@ -883,7 +854,7 @@ class GeoView(HtmlView):
|
||||
config.set('geoview.latitude', "0.0")
|
||||
config.set('geoview.longitude', "0.0")
|
||||
config.set('geoview.map', "person")
|
||||
PageView.on_delete(self)
|
||||
NavigationView.on_delete(self)
|
||||
|
||||
def init_parent_signals_for_map(self, widget, event):
|
||||
"""
|
||||
@ -970,8 +941,6 @@ class GeoView(HtmlView):
|
||||
hobj = self.get_history()
|
||||
self.active_signal = hobj.connect(
|
||||
'active-changed', self._goto_active_person)
|
||||
self.mru_signal = hobj.connect('mru-changed', self.update_mru_menu)
|
||||
self.update_mru_menu(hobj.mru)
|
||||
self._goto_active_person()
|
||||
self.active = True
|
||||
self._test_network()
|
||||
@ -1164,53 +1133,10 @@ class GeoView(HtmlView):
|
||||
|
||||
def define_actions(self):
|
||||
"""
|
||||
Required define_actions function for PageView. Builds the action
|
||||
Required define_actions function for NavigationView. Builds the action
|
||||
group information required.
|
||||
"""
|
||||
PageView.define_actions(self)
|
||||
#self.bookmark_actions()
|
||||
self.book_action = gtk.ActionGroup(self.title + '/Bookmark')
|
||||
self.book_action.add_actions([
|
||||
('AddBook', 'gramps-bookmark-new', _('_Add Bookmark'),
|
||||
'<control>d', None, self.add_bookmark),
|
||||
('EditBook', 'gramps-bookmark-edit',
|
||||
_("%(title)s...") % {'title': _("Organize Bookmarks")},
|
||||
'<shift><control>b', None,
|
||||
self.edit_bookmarks),
|
||||
])
|
||||
|
||||
self._add_action_group(self.book_action)
|
||||
|
||||
#self.navigation_actions()
|
||||
# add the Forward action group to handle the Forward button
|
||||
self.fwd_action = gtk.ActionGroup(self.title + '/Forward')
|
||||
self.fwd_action.add_actions([
|
||||
('Forward', gtk.STOCK_GO_FORWARD, _("_Forward"),
|
||||
"<ALT>Right", _("Go to the next person in the history"),
|
||||
self.fwd_clicked)
|
||||
])
|
||||
|
||||
# add the Backward action group to handle the Forward button
|
||||
self.back_action = gtk.ActionGroup(self.title + '/Backward')
|
||||
self.back_action.add_actions([
|
||||
('Back', gtk.STOCK_GO_BACK, _("_Back"),
|
||||
"<ALT>Left", _("Go to the previous person in the history"),
|
||||
self.back_clicked)
|
||||
])
|
||||
|
||||
self._add_action('HomePerson', gtk.STOCK_HOME, _("_Home"),
|
||||
accel="<Alt>Home",
|
||||
tip=_("Go to the default person"), callback=self.home)
|
||||
|
||||
self.other_action = gtk.ActionGroup(self.title + '/PersonOther')
|
||||
self.other_action.add_actions([
|
||||
('SetActive', gtk.STOCK_HOME, _("Set _Home Person"), None,
|
||||
None, self.set_default_person),
|
||||
])
|
||||
|
||||
self._add_action_group(self.back_action)
|
||||
self._add_action_group(self.fwd_action)
|
||||
self._add_action_group(self.other_action)
|
||||
NavigationView.define_actions(self)
|
||||
|
||||
# geoview actions
|
||||
self._add_action('AddPlace', 'geo-place-add',
|
||||
@ -1261,227 +1187,6 @@ class GeoView(HtmlView):
|
||||
callback=self._event_places,
|
||||
tip=_("Attempt to view places connected to all events."))
|
||||
|
||||
####################################################################
|
||||
# BOOKMARKS
|
||||
####################################################################
|
||||
def add_bookmark(self, obj):
|
||||
"""
|
||||
Add a bookmark to the list.
|
||||
"""
|
||||
from gen.display.name import displayer as name_displayer
|
||||
|
||||
active_handle = self.uistate.get_active('Person')
|
||||
active_person = self.dbstate.db.get_person_from_handle(active_handle)
|
||||
if active_person:
|
||||
self.bookmarks.add(active_handle)
|
||||
name = name_displayer.display(active_person)
|
||||
self.uistate.push_message(self.dbstate,
|
||||
_("%s has been bookmarked") % name)
|
||||
else:
|
||||
from QuestionDialog import WarningDialog
|
||||
WarningDialog(
|
||||
_("Could Not Set a Bookmark"),
|
||||
_("A bookmark could not be set because "
|
||||
"no one was selected."))
|
||||
|
||||
def edit_bookmarks(self, obj):
|
||||
"""
|
||||
Call the bookmark editor.
|
||||
"""
|
||||
self.bookmarks.edit()
|
||||
|
||||
def bookmark_actions(self):
|
||||
"""
|
||||
Define the bookmark menu actions.
|
||||
"""
|
||||
self.book_action = gtk.ActionGroup(self.title + '/Bookmark')
|
||||
self.book_action.add_actions([
|
||||
('AddBook', 'gramps-bookmark-new', _('_Add Bookmark'),
|
||||
'<control>d', None, self.add_bookmark),
|
||||
('EditBook', 'gramps-bookmark-edit',
|
||||
_("%(title)s...") % {'title': _("Organize Bookmarks")},
|
||||
'<shift><control>b', None,
|
||||
self.edit_bookmarks),
|
||||
])
|
||||
|
||||
self._add_action_group(self.book_action)
|
||||
|
||||
####################################################################
|
||||
# NAVIGATION
|
||||
####################################################################
|
||||
def set_default_person(self, obj):
|
||||
"""
|
||||
Set the default person.
|
||||
"""
|
||||
active = self.uistate.get_active('Person')
|
||||
if active:
|
||||
self.dbstate.db.set_default_person_handle(active)
|
||||
|
||||
def home(self, obj):
|
||||
"""
|
||||
Move to the default person.
|
||||
"""
|
||||
defperson = self.dbstate.db.get_default_person()
|
||||
if defperson:
|
||||
self.change_active(defperson.get_handle())
|
||||
|
||||
def jump(self):
|
||||
"""
|
||||
A dialog to move to a Gramps ID entered by the user.
|
||||
"""
|
||||
dialog = gtk.Dialog(_('Jump to by Gramps ID'), None,
|
||||
gtk.DIALOG_NO_SEPARATOR)
|
||||
dialog.set_border_width(12)
|
||||
label = gtk.Label('<span weight="bold" size="larger">%s</span>' %
|
||||
_('Jump to by Gramps ID'))
|
||||
label.set_use_markup(True)
|
||||
dialog.vbox.add(label)
|
||||
dialog.vbox.set_spacing(10)
|
||||
dialog.vbox.set_border_width(12)
|
||||
hbox = gtk.HBox()
|
||||
hbox.pack_start(gtk.Label("%s: " % _('ID')), False)
|
||||
text = gtk.Entry()
|
||||
text.set_activates_default(True)
|
||||
hbox.pack_start(text, False)
|
||||
dialog.vbox.pack_start(hbox, False)
|
||||
dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_JUMP_TO, gtk.RESPONSE_OK)
|
||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
dialog.vbox.show_all()
|
||||
|
||||
if dialog.run() == gtk.RESPONSE_OK:
|
||||
gid = text.get_text()
|
||||
handle = self.get_handle_from_gramps_id(gid)
|
||||
if handle is not None:
|
||||
self.change_active(handle)
|
||||
self.goto_handle(handle)
|
||||
else:
|
||||
self.uistate.push_message(
|
||||
self.dbstate,
|
||||
_("Error: %s is not a valid Gramps ID") % gid)
|
||||
dialog.destroy()
|
||||
|
||||
def get_handle_from_gramps_id(self, gid):
|
||||
"""
|
||||
Get an object handle from its Gramps ID.
|
||||
Needs to be implemented by the inheriting class.
|
||||
"""
|
||||
pass
|
||||
|
||||
def goto_handle(self, handle):
|
||||
self.change_person(handle)
|
||||
|
||||
def fwd_clicked(self, obj):
|
||||
"""
|
||||
Move forward one object in the history.
|
||||
"""
|
||||
hobj = self.get_history()
|
||||
hobj.lock = True
|
||||
if not hobj.at_end():
|
||||
hobj.forward()
|
||||
self.uistate.modify_statusbar(self.dbstate)
|
||||
self.fwd_action.set_sensitive(not hobj.at_end())
|
||||
self.back_action.set_sensitive(True)
|
||||
hobj.lock = False
|
||||
|
||||
def back_clicked(self, obj):
|
||||
"""
|
||||
Move backward one object in the history.
|
||||
"""
|
||||
hobj = self.get_history()
|
||||
hobj.lock = True
|
||||
if not hobj.at_front():
|
||||
hobj.back()
|
||||
self.uistate.modify_statusbar(self.dbstate)
|
||||
self.back_action.set_sensitive(not hobj.at_front())
|
||||
self.fwd_action.set_sensitive(True)
|
||||
hobj.lock = False
|
||||
|
||||
def navigation_group(self):
|
||||
"""
|
||||
Return the navigation group.
|
||||
"""
|
||||
return self.nav_group
|
||||
|
||||
def navigation_type(self):
|
||||
return 'Person'
|
||||
|
||||
def get_history(self):
|
||||
"""
|
||||
Return the history object.
|
||||
"""
|
||||
return self.uistate.get_history(self.navigation_type(),
|
||||
self.navigation_group())
|
||||
|
||||
####################################################################
|
||||
# MRU functions
|
||||
####################################################################
|
||||
|
||||
def mru_disable(self):
|
||||
"""
|
||||
Remove the UI and action groups for the MRU list.
|
||||
"""
|
||||
if self.mru_active != DISABLED:
|
||||
self.uistate.uimanager.remove_ui(self.mru_active)
|
||||
self.uistate.uimanager.remove_action_group(self.mru_action)
|
||||
self.mru_active = DISABLED
|
||||
|
||||
def mru_enable(self):
|
||||
"""
|
||||
Enables the UI and action groups for the MRU list.
|
||||
"""
|
||||
if self.mru_active == DISABLED:
|
||||
self.uistate.uimanager.insert_action_group(self.mru_action, 1)
|
||||
self.mru_active = self.uistate.uimanager.add_ui_from_string(self.mru_ui)
|
||||
self.uistate.uimanager.ensure_update()
|
||||
|
||||
def update_mru_menu(self, items):
|
||||
"""
|
||||
Builds the UI and action group for the MRU list.
|
||||
"""
|
||||
self.mru_disable()
|
||||
nav_type = self.navigation_type()
|
||||
hobj = self.get_history()
|
||||
menu_len = min(len(items) - 1, MRU_SIZE)
|
||||
|
||||
entry = '<menuitem action="%s%02d"/>'
|
||||
data = [entry % (nav_type, index) for index in range(0, menu_len)]
|
||||
self.mru_ui = "".join(MRU_TOP) + "".join(data) + "".join(MRU_BTM)
|
||||
|
||||
mitems = items[-MRU_SIZE - 1:-1] # Ignore current handle
|
||||
mitems.reverse()
|
||||
data = []
|
||||
for index, handle in enumerate(mitems):
|
||||
name, obj = navigation_label(self.dbstate.db, nav_type, handle)
|
||||
data.append(('%s%02d'%(nav_type, index), None, name,
|
||||
"<alt>%d" % index, None,
|
||||
_make_callback(hobj.push, handle)))
|
||||
|
||||
self.mru_action = gtk.ActionGroup(nav_type)
|
||||
self.mru_action.add_actions(data)
|
||||
self.mru_enable()
|
||||
|
||||
####################################################################
|
||||
# End MRU functions
|
||||
####################################################################
|
||||
|
||||
def go_back(self, button): # pylint: disable-msg=W0613
|
||||
"""
|
||||
Go to the previous loaded url.
|
||||
We need to set all the buttons insensitive.
|
||||
"""
|
||||
self.box1.set_sensitive(False)
|
||||
self.renderer.window.go_back()
|
||||
|
||||
def go_forward(self, button): # pylint: disable-msg=W0613
|
||||
"""
|
||||
Go to the next loaded url.
|
||||
We need to set all the buttons sensitive if we cannot go forward.
|
||||
"""
|
||||
self.renderer.window.go_forward()
|
||||
if not self.renderer.window.can_go_forward():
|
||||
self.box1.set_sensitive(True)
|
||||
|
||||
def change_page(self):
|
||||
"""
|
||||
Called by viewmanager at end of realization when arriving on the page
|
||||
@ -2717,3 +2422,34 @@ class GeoView(HtmlView):
|
||||
# How many seconds between tests ? mini = 10 secondes.
|
||||
self._config.set('preferences.network-periodicity', 10)
|
||||
self.__test_network()
|
||||
|
||||
def get_bookmarks(self):
|
||||
return self.dbstate.db.get_family_bookmarks()
|
||||
|
||||
def add_bookmark(self, obj):
|
||||
mlist = self.selected_handles()
|
||||
if mlist:
|
||||
self.bookmarks.add(mlist[0])
|
||||
else:
|
||||
from QuestionDialog import WarningDialog
|
||||
WarningDialog(
|
||||
_("Could Not Set a Bookmark"),
|
||||
_("A bookmark could not be set because "
|
||||
"no one was selected."))
|
||||
|
||||
def navigation_group(self):
|
||||
"""
|
||||
Return the navigation group.
|
||||
"""
|
||||
return self.nav_group
|
||||
|
||||
def navigation_type(self):
|
||||
return 'Person'
|
||||
|
||||
def get_history(self):
|
||||
"""
|
||||
Return the history object.
|
||||
"""
|
||||
_LOG.debug("get history")
|
||||
return self.uistate.get_history(self.navigation_type(),
|
||||
self.navigation_group())
|
||||
|
@ -57,7 +57,8 @@ import gtk
|
||||
# Gramps Modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gui.views.pageview import PageView
|
||||
from gui.views.navigationview import NavigationView
|
||||
import Bookmarks
|
||||
import Utils
|
||||
import constfunc
|
||||
import config
|
||||
@ -435,14 +436,18 @@ class RendererMozilla(Renderer):
|
||||
# HtmlView
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class HtmlView(PageView):
|
||||
class HtmlView(NavigationView):
|
||||
"""
|
||||
HtmlView is a view showing a top widget with controls, and a bottom part
|
||||
with an embedded webbrowser showing a given URL
|
||||
"""
|
||||
|
||||
def __init__(self, pdata, dbstate, uistate, title=_('HtmlView')):
|
||||
PageView.__init__(self, title, pdata, dbstate, uistate)
|
||||
NavigationView.__init__(self, title, pdata, dbstate, uistate,
|
||||
dbstate.db.get_bookmarks(),
|
||||
Bookmarks.PersonBookmarks,
|
||||
nav_group=0
|
||||
)
|
||||
self.dbstate = dbstate
|
||||
self.back_action = None
|
||||
self.forward_action = None
|
||||
@ -621,10 +626,10 @@ class HtmlView(PageView):
|
||||
|
||||
def define_actions(self):
|
||||
"""
|
||||
Required define_actions function for PageView. Builds the action
|
||||
Required define_actions function for NavigationView. Builds the action
|
||||
group information required.
|
||||
"""
|
||||
PageView.define_actions(self)
|
||||
NavigationView.define_actions(self)
|
||||
HtmlView._define_actions_fw_bw(self)
|
||||
|
||||
def _define_actions_fw_bw(self):
|
||||
@ -713,3 +718,24 @@ class HtmlView(PageView):
|
||||
URL_SEP.join(filename.split(os.sep)),
|
||||
'', ''))
|
||||
|
||||
def navigation_group(self):
|
||||
"""
|
||||
Return the navigation group.
|
||||
"""
|
||||
return self.nav_group
|
||||
|
||||
def navigation_type(self):
|
||||
return 'Person'
|
||||
|
||||
def get_history(self):
|
||||
"""
|
||||
Return the history object.
|
||||
"""
|
||||
_LOG.debug("htmlrenderer : get_history" )
|
||||
return self.uistate.get_history(self.navigation_type(),
|
||||
self.navigation_group())
|
||||
|
||||
def goto_handle(self, handle):
|
||||
_LOG.debug("htmlrenderer : gtoto_handle" )
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user