New feature to allow new rules in their own catagory in addons
This commit is contained in:
parent
8366ceb896
commit
eb36980715
@ -39,6 +39,7 @@ import os
|
||||
import sys
|
||||
import re
|
||||
import logging
|
||||
import importlib
|
||||
LOG = logging.getLogger('._manager')
|
||||
LOG.progagate = True
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
@ -197,6 +198,18 @@ class BasePluginManager:
|
||||
plugin.data += results
|
||||
except:
|
||||
plugin.data = results
|
||||
# Get the addon rules and import them and make them findable
|
||||
for plugin in self.__pgr.rule_plugins():
|
||||
mod = self.load_plugin(plugin) # load the addon rule
|
||||
# get place in rule heirarchy to put the new rule
|
||||
obj_rules = importlib.import_module(
|
||||
'gramps.gen.filters.rules.' + plugin.namespace.lower())
|
||||
# get the new rule class object
|
||||
r_class = getattr(mod, plugin.ruleclass)
|
||||
# make the new rule findable via import statements
|
||||
setattr(obj_rules, plugin.ruleclass, r_class)
|
||||
# and add it to the correct fiter editor list
|
||||
obj_rules.editor_rule_list.append(r_class)
|
||||
|
||||
def is_loaded(self, pdata_id):
|
||||
"""
|
||||
|
@ -72,8 +72,9 @@ RELCALC = 9
|
||||
GRAMPLET = 10
|
||||
SIDEBAR = 11
|
||||
DATABASE = 12
|
||||
PTYPE = [REPORT , QUICKREPORT, TOOL, IMPORT, EXPORT, DOCGEN, GENERAL,
|
||||
MAPSERVICE, VIEW, RELCALC, GRAMPLET, SIDEBAR, DATABASE]
|
||||
RULE = 13
|
||||
PTYPE = [REPORT, QUICKREPORT, TOOL, IMPORT, EXPORT, DOCGEN, GENERAL,
|
||||
MAPSERVICE, VIEW, RELCALC, GRAMPLET, SIDEBAR, DATABASE, RULE]
|
||||
PTYPE_STR = {
|
||||
REPORT: _('Report') ,
|
||||
QUICKREPORT: _('Quickreport'),
|
||||
@ -88,6 +89,7 @@ PTYPE_STR = {
|
||||
GRAMPLET: _('Gramplet'),
|
||||
SIDEBAR: _('Sidebar'),
|
||||
DATABASE: _('Database'),
|
||||
RULE: _('Rule')
|
||||
}
|
||||
|
||||
#possible report categories
|
||||
@ -211,7 +213,7 @@ class PluginData:
|
||||
The python path where the plugin implementation can be found
|
||||
.. attribute:: ptype
|
||||
The plugin type. One of REPORT , QUICKREPORT, TOOL, IMPORT,
|
||||
EXPORT, DOCGEN, GENERAL, MAPSERVICE, VIEW, GRAMPLET, DATABASE
|
||||
EXPORT, DOCGEN, GENERAL, MAPSERVICE, VIEW, GRAMPLET, DATABASE, RULE
|
||||
.. attribute:: authors
|
||||
List of authors of the plugin, default=[]
|
||||
.. attribute:: authors_email
|
||||
@ -362,6 +364,13 @@ class PluginData:
|
||||
.. attribute:: reset_system
|
||||
Boolean to indicate that the system (sys.modules) should
|
||||
be reset.
|
||||
|
||||
Attributes for RULE plugins
|
||||
|
||||
.. attribute:: namespace
|
||||
The class (Person, Event, Media, etc.) the rule applies to.
|
||||
.. attribute:: ruleclass
|
||||
The exact class name of the rule; ex: HasSourceParameter
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
@ -440,6 +449,9 @@ class PluginData:
|
||||
#GENERAL attr
|
||||
self._data = []
|
||||
self._process = None
|
||||
#RULE attr
|
||||
self._ruleclass = None
|
||||
self._namespace = None
|
||||
|
||||
def _set_id(self, id):
|
||||
self._id = id
|
||||
@ -987,6 +999,26 @@ class PluginData:
|
||||
data = property(_get_data, _set_data)
|
||||
process = property(_get_process, _set_process)
|
||||
|
||||
#RULE attr
|
||||
def _set_ruleclass(self, data):
|
||||
if self._ptype != RULE:
|
||||
raise ValueError('ruleclass may only be set for RULE plugins')
|
||||
self._ruleclass = data
|
||||
|
||||
def _get_ruleclass(self):
|
||||
return self._ruleclass
|
||||
|
||||
def _set_namespace(self, data):
|
||||
if self._ptype != RULE:
|
||||
raise ValueError('namespace may only be set for RULE plugins')
|
||||
self._namespace = data
|
||||
|
||||
def _get_namespace(self):
|
||||
return self._namespace
|
||||
|
||||
ruleclass = property(_get_ruleclass, _set_ruleclass)
|
||||
namespace = property(_get_namespace, _set_namespace)
|
||||
|
||||
def newplugin():
|
||||
"""
|
||||
Function to create a new plugindata object, add it to list of
|
||||
@ -1034,6 +1066,7 @@ def make_environment(**kwargs):
|
||||
'EXPORT': EXPORT,
|
||||
'DOCGEN': DOCGEN,
|
||||
'GENERAL': GENERAL,
|
||||
'RULE': RULE,
|
||||
'MAPSERVICE': MAPSERVICE,
|
||||
'VIEW': VIEW,
|
||||
'RELCALC': RELCALC,
|
||||
@ -1350,6 +1383,12 @@ class PluginRegister:
|
||||
"""
|
||||
return self.type_plugins(DATABASE)
|
||||
|
||||
def rule_plugins(self):
|
||||
"""
|
||||
Return a list of :class:`PluginData` that are of type RULE
|
||||
"""
|
||||
return self.type_plugins(RULE)
|
||||
|
||||
def filter_load_on_reg(self):
|
||||
"""
|
||||
Return a list of :class:`PluginData` that have load_on_reg == True
|
||||
|
Loading…
x
Reference in New Issue
Block a user