Phase 1 conversion of gramplets to new plugin system
svn: r13406
This commit is contained in:
@ -53,6 +53,7 @@ from gui.utils import add_menuitem
|
|||||||
from QuickReports import run_quick_report_by_name
|
from QuickReports import run_quick_report_by_name
|
||||||
import GrampsDisplay
|
import GrampsDisplay
|
||||||
from glade import Glade
|
from glade import Glade
|
||||||
|
from gen.plug import PluginManager
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -66,47 +67,35 @@ WIKI_HELP_PAGE = const.URL_MANUAL_PAGE + '_-_Gramplets'
|
|||||||
# Globals
|
# Globals
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
AVAILABLE_GRAMPLETS = {}
|
PLUGMAN = PluginManager.get_instance()
|
||||||
|
|
||||||
GRAMPLET_FILENAME = os.path.join(const.HOME_DIR,"gramplets.ini")
|
GRAMPLET_FILENAME = os.path.join(const.HOME_DIR,"gramplets.ini")
|
||||||
NL = "\n"
|
NL = "\n"
|
||||||
|
|
||||||
debug = False
|
debug = False
|
||||||
|
|
||||||
def register_gramplet(data_dict):
|
def AVAILABLE_GRAMPLETS():
|
||||||
"""
|
return [gplug.id for gplug in PLUGMAN.get_reg_gramplets()]
|
||||||
Function to register a gramplet. Called from plugin directory.
|
|
||||||
"""
|
|
||||||
global AVAILABLE_GRAMPLETS
|
|
||||||
base_opts = {"name":"Unnamed Gramplet",
|
|
||||||
"tname": _("Unnamed Gramplet"),
|
|
||||||
"state":"maximized",
|
|
||||||
"version":"0.0.0",
|
|
||||||
"gramps":"0.0.0",
|
|
||||||
"column": -1, "row": -1,
|
|
||||||
"data": []}
|
|
||||||
base_opts.update(data_dict)
|
|
||||||
if base_opts["name"] not in AVAILABLE_GRAMPLETS:
|
|
||||||
AVAILABLE_GRAMPLETS[base_opts["name"]] = base_opts
|
|
||||||
else: # go with highest version (or current one in case of tie)
|
|
||||||
# GRAMPS loads system plugins first
|
|
||||||
loaded_version = [int(i) for i in
|
|
||||||
AVAILABLE_GRAMPLETS[base_opts["name"]]["version"].split(".")]
|
|
||||||
current_version = [int(i) for i in base_opts["version"].split(".")]
|
|
||||||
if current_version >= loaded_version:
|
|
||||||
AVAILABLE_GRAMPLETS[base_opts["name"]] = base_opts
|
|
||||||
|
|
||||||
def register(**data):
|
def GET_AVAILABLE_GRAMPLETS(name):
|
||||||
"""
|
for gplug in PLUGMAN.get_reg_gramplets():
|
||||||
Wrapper around register_gramplet to demonstrate a common
|
if gplug.id == name:
|
||||||
interface for all plugins.
|
return {
|
||||||
"""
|
"name": gplug.id,
|
||||||
if "type" in data:
|
"tname": gplug.name,
|
||||||
if data["type"].lower() == "gramplet":
|
"version": gplug.version,
|
||||||
register_gramplet(data)
|
"height": gplug.height,
|
||||||
else:
|
"title": gplug.gramplet_title,
|
||||||
print ("Unknown plugin type: '%s'" % data["type"])
|
"content": gplug.gramplet,
|
||||||
else:
|
"detached_width": gplug.detached_width,
|
||||||
print ("Plugin did not define type.")
|
"detached_height": gplug.detached_height,
|
||||||
|
"state": "maximized",
|
||||||
|
"gramps": "0.0.0",
|
||||||
|
"column": -1,
|
||||||
|
"row": -1,
|
||||||
|
"data": [],
|
||||||
|
}
|
||||||
|
return None
|
||||||
|
|
||||||
def parse_tag_attr(text):
|
def parse_tag_attr(text):
|
||||||
"""
|
"""
|
||||||
@ -131,8 +120,8 @@ def get_gramplet_opts(name, opts):
|
|||||||
Lookup the options for a given gramplet name and update
|
Lookup the options for a given gramplet name and update
|
||||||
the options with provided dictionary, opts.
|
the options with provided dictionary, opts.
|
||||||
"""
|
"""
|
||||||
if name in AVAILABLE_GRAMPLETS:
|
if name in AVAILABLE_GRAMPLETS():
|
||||||
data = AVAILABLE_GRAMPLETS[name]
|
data = GET_AVAILABLE_GRAMPLETS(name)
|
||||||
my_data = data.copy()
|
my_data = data.copy()
|
||||||
my_data.update(opts)
|
my_data.update(opts)
|
||||||
return my_data
|
return my_data
|
||||||
@ -145,8 +134,8 @@ def get_gramplet_options_by_name(name):
|
|||||||
Get options by gramplet name.
|
Get options by gramplet name.
|
||||||
"""
|
"""
|
||||||
if debug: print "name:", name
|
if debug: print "name:", name
|
||||||
if name in AVAILABLE_GRAMPLETS:
|
if name in AVAILABLE_GRAMPLETS():
|
||||||
return AVAILABLE_GRAMPLETS[name].copy()
|
return GET_AVAILABLE_GRAMPLETS(name).copy()
|
||||||
else:
|
else:
|
||||||
print ("Unknown gramplet name: '%s'" % name)
|
print ("Unknown gramplet name: '%s'" % name)
|
||||||
return None
|
return None
|
||||||
@ -156,9 +145,9 @@ def get_gramplet_options_by_tname(name):
|
|||||||
get options by translated name.
|
get options by translated name.
|
||||||
"""
|
"""
|
||||||
if debug: print "name:", name
|
if debug: print "name:", name
|
||||||
for key in AVAILABLE_GRAMPLETS:
|
for key in AVAILABLE_GRAMPLETS():
|
||||||
if AVAILABLE_GRAMPLETS[key]["tname"] == name:
|
if GET_AVAILABLE_GRAMPLETS(key)["tname"] == name:
|
||||||
return AVAILABLE_GRAMPLETS[key].copy()
|
return GET_AVAILABLE_GRAMPLETS(key).copy()
|
||||||
print ("Unknown gramplet name: '%s'" % name)
|
print ("Unknown gramplet name: '%s'" % name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -166,10 +155,15 @@ def make_requested_gramplet(viewpage, name, opts, dbstate, uistate):
|
|||||||
"""
|
"""
|
||||||
Make a GUI gramplet given its name.
|
Make a GUI gramplet given its name.
|
||||||
"""
|
"""
|
||||||
if name in AVAILABLE_GRAMPLETS:
|
if name in AVAILABLE_GRAMPLETS():
|
||||||
gui = GuiGramplet(viewpage, dbstate, uistate, **opts)
|
gui = GuiGramplet(viewpage, dbstate, uistate, **opts)
|
||||||
if opts.get("content", None):
|
if opts.get("content", None):
|
||||||
opts["content"](gui)
|
pdata = PLUGMAN.get_plugin(opts["name"])
|
||||||
|
module = PLUGMAN.load_plugin(pdata)
|
||||||
|
if module:
|
||||||
|
getattr(module, opts["content"])(gui)
|
||||||
|
else:
|
||||||
|
print "Unregistered gramplet '%s': skipping content" % opts["name"]
|
||||||
# now that we have user code, set the tooltips
|
# now that we have user code, set the tooltips
|
||||||
msg = gui.tooltip
|
msg = gui.tooltip
|
||||||
if msg is None:
|
if msg is None:
|
||||||
@ -235,7 +229,7 @@ class GrampletWindow(ManagedWindow.ManagedWindow):
|
|||||||
|
|
||||||
def handle_response(self, object, response):
|
def handle_response(self, object, response):
|
||||||
"""
|
"""
|
||||||
Callback for tacking care of button clicks.
|
Callback for taking care of button clicks.
|
||||||
"""
|
"""
|
||||||
if response in [gtk.RESPONSE_CLOSE, gtk.STOCK_CLOSE]:
|
if response in [gtk.RESPONSE_CLOSE, gtk.STOCK_CLOSE]:
|
||||||
self.close()
|
self.close()
|
||||||
@ -1239,8 +1233,8 @@ class GrampletView(PageView):
|
|||||||
else:
|
else:
|
||||||
# give defaults as currently known
|
# give defaults as currently known
|
||||||
for name in ["Top Surnames Gramplet", "Welcome Gramplet"]:
|
for name in ["Top Surnames Gramplet", "Welcome Gramplet"]:
|
||||||
if name in AVAILABLE_GRAMPLETS:
|
if name in AVAILABLE_GRAMPLETS():
|
||||||
retval.append((name, AVAILABLE_GRAMPLETS[name]))
|
retval.append((name, GET_AVAILABLE_GRAMPLETS(name)))
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
def save(self, *args):
|
def save(self, *args):
|
||||||
@ -1519,8 +1513,8 @@ class GrampletView(PageView):
|
|||||||
if ag_menu:
|
if ag_menu:
|
||||||
qr_menu = ag_menu.get_submenu()
|
qr_menu = ag_menu.get_submenu()
|
||||||
qr_menu = gtk.Menu()
|
qr_menu = gtk.Menu()
|
||||||
names = [AVAILABLE_GRAMPLETS[key]["tname"] for key
|
names = [GET_AVAILABLE_GRAMPLETS(key)["tname"] for key
|
||||||
in AVAILABLE_GRAMPLETS]
|
in AVAILABLE_GRAMPLETS()]
|
||||||
names.sort()
|
names.sort()
|
||||||
for name in names:
|
for name in names:
|
||||||
add_menuitem(qr_menu, name,
|
add_menuitem(qr_menu, name,
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
Package init for the DataViews package.
|
Package init for the DataViews package.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from GrampletView import GrampletView, register, Gramplet
|
from GrampletView import GrampletView, Gramplet
|
||||||
from PersonView import PersonView
|
from PersonView import PersonView
|
||||||
from RelationView import RelationshipView
|
from RelationView import RelationshipView
|
||||||
from FamilyList import FamilyListView
|
from FamilyList import FamilyListView
|
||||||
|
@ -195,6 +195,12 @@ class BasePluginManager(object):
|
|||||||
""" Return the list of succeeded plugins. """
|
""" Return the list of succeeded plugins. """
|
||||||
return self.__success_list
|
return self.__success_list
|
||||||
|
|
||||||
|
def get_plugin(self, id):
|
||||||
|
"""
|
||||||
|
Returns a plugin object from PluginRegister by id.
|
||||||
|
"""
|
||||||
|
return self.__pgr.get_plugin(id)
|
||||||
|
|
||||||
def get_reg_reports(self, gui=True):
|
def get_reg_reports(self, gui=True):
|
||||||
""" Return list of registered reports
|
""" Return list of registered reports
|
||||||
:Param gui: bool indicating if GUI reports or CLI reports must be
|
:Param gui: bool indicating if GUI reports or CLI reports must be
|
||||||
@ -224,6 +230,12 @@ class BasePluginManager(object):
|
|||||||
"""
|
"""
|
||||||
return self.__pgr.bookitem_plugins()
|
return self.__pgr.bookitem_plugins()
|
||||||
|
|
||||||
|
def get_reg_gramplets(self):
|
||||||
|
""" Return list of non hidden gramplets.
|
||||||
|
"""
|
||||||
|
return [plg for plg in self.__pgr.gramplet_plugins() if plg.id not in
|
||||||
|
self.__hidden_plugins]
|
||||||
|
|
||||||
def get_external_opt_dict(self):
|
def get_external_opt_dict(self):
|
||||||
""" Return the dictionary of external options. """
|
""" Return the dictionary of external options. """
|
||||||
return self.__external_opt_dict
|
return self.__external_opt_dict
|
||||||
|
@ -927,6 +927,11 @@ class PluginRegister(object):
|
|||||||
"""
|
"""
|
||||||
return self.type_plugins(RELCALC)
|
return self.type_plugins(RELCALC)
|
||||||
|
|
||||||
|
def gramplet_plugins(self):
|
||||||
|
"""Return a list of PluginData that are of type GRAMPLET
|
||||||
|
"""
|
||||||
|
return self.type_plugins(GRAMPLET)
|
||||||
|
|
||||||
def filter_load_on_reg(self):
|
def filter_load_on_reg(self):
|
||||||
"""Return a list of PluginData that have load_on_reg == True
|
"""Return a list of PluginData that have load_on_reg == True
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user