Added a new addon type 'WebConnect' which defines a method to lookup data on websites
svn: r15812
This commit is contained in:
parent
ea90894193
commit
47e3d110d5
@ -53,11 +53,65 @@ import gtk
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
from gui.pluginmanager import GuiPluginManager
|
||||
from gen.plug import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, CATEGORY_QR_MEDIA,
|
||||
CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, CATEGORY_QR_MISC,
|
||||
CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY, CATEGORY_QR_NOTE)
|
||||
from gui.pluginmanager import GuiPluginManager
|
||||
CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY,
|
||||
CATEGORY_QR_NOTE)
|
||||
|
||||
def flatten(L):
|
||||
"""
|
||||
Flattens a possibly nested list. Removes None results, too.
|
||||
"""
|
||||
retval = []
|
||||
if isinstance(L, (list, tuple)):
|
||||
for item in L:
|
||||
fitem = flatten(item)
|
||||
if fitem is not None:
|
||||
retval.extend(fitem)
|
||||
elif L is not None:
|
||||
retval.append(L)
|
||||
return retval
|
||||
|
||||
def create_web_connect_menu(dbstate, uistate, nav_group, handle):
|
||||
"""
|
||||
This functions querries the registered web connects. It collects
|
||||
the connects of the requested category, which must be one of
|
||||
nav_group.
|
||||
|
||||
It constructs the ui string of the menu, and it's actions. The
|
||||
action callback function is constructed, using the dbstate and the
|
||||
handle as input method. A tuple is returned, containing the ui
|
||||
string of the menu, and its associated actions.
|
||||
"""
|
||||
actions = []
|
||||
ofile = StringIO()
|
||||
ofile.write('<menu action="WebConnect">')
|
||||
actions.append(('WebConnect', None, _("Web Connect"), None, None, None))
|
||||
menu = gtk.Menu()
|
||||
menu.show()
|
||||
#select the web connects to show
|
||||
showlst = []
|
||||
pmgr = GuiPluginManager.get_instance()
|
||||
plugins = pmgr.process_plugin_data('WebConnect')
|
||||
try:
|
||||
connections = [plug(nav_group) if callable(plug) else plug
|
||||
for plug in plugins]
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
connections = []
|
||||
connections = flatten(connections)
|
||||
connections.sort(key=lambda plug: plug.name)
|
||||
actions = []
|
||||
for connect in connections:
|
||||
ofile.write('<menuitem action="%s"/>' % connect.key)
|
||||
actions.append((connect.key, None, connect.name, None, None,
|
||||
connect(dbstate, uistate, nav_group, handle)))
|
||||
ofile.write('</menu>')
|
||||
retval = [ofile.getvalue()]
|
||||
retval.extend(actions)
|
||||
return retval
|
||||
|
||||
def create_quickreport_menu(category,dbstate,uistate, handle) :
|
||||
""" This functions querries the registered quick reports with
|
||||
|
@ -744,7 +744,8 @@ class ListView(NavigationView):
|
||||
"""
|
||||
if not self.dbstate.open:
|
||||
return False
|
||||
from QuickReports import create_quickreport_menu
|
||||
from QuickReports import (create_quickreport_menu,
|
||||
create_web_connect_menu)
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
||||
if self.type_list() == LISTFLAT:
|
||||
self.edit(obj)
|
||||
@ -782,6 +783,23 @@ class ListView(NavigationView):
|
||||
add_menuitem(qr_menu, action[2], None, action[5])
|
||||
self.uistate.uimanager.get_widget('/Popup/QuickReport').\
|
||||
set_submenu(qr_menu)
|
||||
if menu and self.get_active():
|
||||
popup = self.uistate.uimanager.get_widget('/Popup/WebConnect')
|
||||
if popup:
|
||||
qr_menu = popup.get_submenu()
|
||||
webconnects = []
|
||||
if qr_menu:
|
||||
popup.remove_submenu()
|
||||
webconnects = create_web_connect_menu(
|
||||
self.dbstate,
|
||||
self.uistate,
|
||||
self.navigation_type(),
|
||||
self.first_selected())
|
||||
if len(webconnects) > 1 :
|
||||
qr_menu = gtk.Menu()
|
||||
for action in webconnects[1:] :
|
||||
add_menuitem(qr_menu, action[2], None, action[5])
|
||||
popup.set_submenu(qr_menu)
|
||||
if menu:
|
||||
menu.popup(None, None, None, event.button, event.time)
|
||||
return True
|
||||
|
@ -230,6 +230,9 @@ class BasePersonView(ListView):
|
||||
<menu name="QuickReport" action="QuickReport">
|
||||
<menuitem action="Dummy"/>
|
||||
</menu>
|
||||
<menu name="WebConnect" action="WebConnect">
|
||||
<menuitem action="Dummy"/>
|
||||
</menu>
|
||||
</popup>
|
||||
</ui>'''
|
||||
|
||||
@ -326,6 +329,7 @@ class BasePersonView(ListView):
|
||||
('Edit', gtk.STOCK_EDIT, _("action|_Edit..."), "<control>Return",
|
||||
_("Edit the selected person"), self.edit),
|
||||
('QuickReport', None, _("Quick View"), None, None, None),
|
||||
('WebConnect', None, _("Web Connection"), None, None, None),
|
||||
('Dummy', None, ' ', None, None, self.dummy_report),
|
||||
])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user