# #------------------------------------------------------------------------ from gramps.gen.const import USER_PLUGINS from gramps.gui.glade import Glade from gramps.gui.managedwindow import GrampsWindowManager, ManagedWindow from gramps.gui.plug import tool #------------------------------------------------------------------------ # # Internationalisation # #------------------------------------------------------------------------ from gramps.gen.const import GRAMPS_LOCALE as glocale try: _trans = glocale.get_addon_translator(__file__) except ValueError: _trans = glocale.translation _ = _trans.gettext import gramps.gen.constfunc # Handlers and signal class class GladeHandlers(): """ Experimental try for event functions via python and .glade files """ def on_quit_clicked(): Gtk.main_quit()
def register(ptype, **kwargs): global plugins kwargs["ptype"] = PTYPE_STR[ptype] # need to take care of translated types plugins.append(kwargs) # get current build numbers from English listing fp_in = open(r("../addons/%(gramps_version)s/listings/addons-en.txt"), "r", encoding="utf-8") addons = {} for line in fp_in: dictionary = eval(line) if dictionary["i"] in addons: print("Repeated addon ID:", dictionary["i"]) else: addons[dictionary["i"]] = dictionary # go through all gpr's, check their build versions for gpr in glob.glob(r('''*/*.gpr.py''')): local_gettext = glocale.get_addon_translator( gpr, languages=["en", "en.UTF-8"]).gettext plugins = [] with open(gpr.encode("utf-8", errors="backslashreplace")) as f: code = compile(f.read(), gpr.encode("utf-8", errors="backslashreplace"), 'exec') exec(code, make_environment(_=local_gettext), {"register": register}) for p in plugins: gpr_version = p.get("version", None) id = p.get("id", None) if id not in addons: print("Missing in listing:", id) else: add_version = addons[id]["v"] if gpr_version != add_version:
def listing(LANG): """ Listing files ../listing/{lang}.fr """ if 'GRAMPSPATH' in os.environ: GRAMPSPATH = os.environ['GRAMPSPATH'] else: GRAMPSPATH = '../../../..' try: sys.path.insert(0, GRAMPSPATH) os.environ['GRAMPS_RESOURCES'] = os.path.abspath(GRAMPSPATH) from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.plug import make_environment, PTYPE_STR except ImportError: raise ValueError("Where is 'GRAMPSPATH' or 'GRAMPS_RESOURCES'?") LOCALE = glocale.get_language_list() compilation_all('ALL') listings = [] need = False # change the method fp = open('../listings/addons-%s.txt' % LANG, 'w') for addon in sorted(ADDONS): tgz_file = '%s.addon.tgz' % addon tgz_exists = os.path.isfile('../download/' + tgz_file) gprs = glob.glob('%(addon)s/*gpr.py' % {'addon': addon}) for gpr in gprs: gpr_file = gpr print(gpr_file, gprs) gpr_exists = os.path.isfile(gpr_file) mo_file = "%s/locale/%s/LC_MESSAGES/addon.mo" % (addon, LANG) mo_exists = os.path.isfile(mo_file) if tgz_exists and gpr_exists: gpr = open(gpr_file.encode('utf-8', errors='backslashreplace')) plug = dict([file.strip(), None] for file in gpr if file.strip()) name = ident = ptype = description = version = target = '' if mo_exists: LANGUAGE = LANG +".UTF-8" else: LANGUAGE = os.environ['LANGUAGE'] # print(plug) for p in plug: # print(repr(p)) if repr(p).startswith("'register("): ptype = p.replace("register(", "") ptype = ptype.replace(",", "") # incomplete dirty hack! print(glocale._get_translation(), LANG+".UTF-8") if LANG != LOCALE[0]: # mixup between LOCALE[0] and 'en' (avoid corruption) # need 'en.UTF-8' ! local_gettext = glocale.get_addon_translator(gpr_file, languages=[LANGUAGE]).ugettext #return else: local_gettext = glocale.get_addon_translator(gpr_file, languages=[LANG, "en"]).ugettext ptype = make_environment(_ = local_gettext)[ptype] # need to match translations build by Gramps program try: ptype = PTYPE_STR[ptype] except: # fallback and corruption with LOCALE[0] print(' wrong PTYPE: %s' % ptype) print(local_gettext('Tool')) # always corrupted by the locale print("LANGUAGE='%(language)s', LANG='%(lang)s'" % {'language': os.environ['LANGUAGE'], 'lang': os.environ['LANG']}) return if not (repr(p).startswith("'include_in_listing = False," ) or repr(p).startswith("'status = UNSTABLE,")): need = True else: print("Ignoring: '%s'" % addon) if repr(p).startswith("'id") or repr(p).startswith('"id' ): ident = p.replace('id', '') ident = ident.replace('=', '') ident = ident.replace(',', '') ident = ident.strip() #ident = repr(ident) if repr(p).startswith("'name") \ or repr(p).startswith('"name'): name = p.replace('name', '') name = name.replace('=', '') name = name.replace(',', '') name = name.strip() name = name.replace('_(', '') name = name.replace(')', '') name = name.replace('"', '') name = glocale._get_translation().ugettext(name) try: if name == local_gettext(name): print(addon, name, local_gettext(name)) name = repr(local_gettext(name)) except: print('Cannot use local_gettext on', repr(p)) # ugly workaround for name_accell (Export GEDCOM Extensions) name = name.replace('_accell ', '') name = name.replace('(GED2', '(GED2)') if repr(p).startswith("'description"): description = p.replace('description', '') description = description.replace('=', '') description = description.replace(',', '') description = description.strip() description = description.replace('_(', '') description = description.replace(')', '') description = description.replace('"', '') description = glocale._get_translation().ugettext(description) try: if description == local_gettext(description): print(addon, description, local_gettext(description)) description = repr(local_gettext(description)) except: print('Cannot use local_gettext on', repr(p)) if repr(p).startswith('"version'): version = p.replace('version', '') version = version.replace('=', '') version = version.replace(',', '') version = version.replace("'", "") version = version.replace('"', '') version = version.strip() version = repr(version) # workaround #7395~c38994 if description == '': description = "''" print(description, addon) if need: plugin = { 'n': name, 'i': ident, 't': repr(ptype), 'd': description, 'v': version, 'g': "'4.2'", 'z': repr(tgz_file), } #if name or ident or version or target == "": #print(plugin) fp.write('{"t":%(t)s,"i":%(i)s,"n":%(n)s,"v":%(v)s,"g":%(g)s,"d":%(d)s,"z":%(z)s}\n' % plugin) # print(plugin) listings.append(plugin) # for plugin in sorted(listings, key=lambda p: p["z"]): # fp.write('{"t":%(t)s,"i":%(i)s,"n":%(n)s,"v":%(v)s,"g":%(g)s,"d":%(d)s,"z":%(z)s}\n' % plugin) fp.close()
def is_listing(LANG): """ Listing files ../listing/{lang}.fr """ if 'GRAMPSPATH' in os.environ: GRAMPSPATH = os.environ['GRAMPSPATH'] else: GRAMPSPATH = '../../../..' try: sys.path.insert(0, GRAMPSPATH) os.environ['GRAMPS_RESOURCES'] = os.path.abspath(GRAMPSPATH) from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.plug import make_environment, PTYPE_STR except ImportError: raise ValueError("Where is 'GRAMPSPATH' or 'GRAMPS_RESOURCES'?") def register(ptype, **kwargs): global plugins kwargs['ptype'] = PTYPE_STR[ptype] # related to gramps translations plugins.append(kwargs) cmd_arg = LANG # Make the locale for for any local languages for Addon: for addon in ADDONS: for po in glob.glob('%(addon)s/po/*-local.po' % {'addon': addon}): # Compile locale = os.path.basename(po[:-9]) os.system('mkdir -p "%(addon)s/locale/%(locale)s/LC_MESSAGES/"' % {'addon': addon, 'locale': locale}) os.system('msgfmt %(po)s -o "%(addon)s/locale/%(locale)s/LC_MESSAGES/addon.mo"' % {'po': po, 'addon': addon, 'locale': locale}) # Get all languages from all addons: languages = set(['en']) for addon in [file for file in glob.glob('*') if os.path.isdir(file)]: for po in glob.glob('%(addon)s/po/*-local.po' % {'addon': addon}): length = len(po) locale = po[length - 11:length - 9] (locale_path, locale) = po.rsplit('/', 1) languages.add(locale[:-9]) # next, create/edit a file for all languages listing plugins for lang in languages: print("----Building listing for '%s'..." % lang) listings = [] for addon in ADDONS: for gpr in glob.glob('%(addon)s/*.gpr.py' % {'addon': addon}): print(gpr) # Make fallback language English (rather than current LANG) local_gettext = glocale.get_addon_translator(gpr, languages=[lang, 'en.UTF-8']).gettext plugins = [] with open(gpr.encode('utf-8', errors='backslashreplace' )) as f: code = compile(f.read(), gpr.encode('utf-8', errors='backslashreplace'), 'exec') #exec(code, make_environment(_=local_gettext), #{"register": register}) for p in plugins: tgz_file = '%s.addon.tgz' % gpr.split('/', 1)[0] tgz_exists = os.path.isfile('../download/' + tgz_file) if p.get('include_in_listing', True) and tgz_exists: plugin = { 'n': repr(p['name']), 'i': repr(p['id']), 't': repr(p['ptype']), 'd': repr(p['description']), 'v': repr(p['version']), 'g': repr(p['gramps_target_version']), 'z': repr(tgz_file), } listings.append(plugin) else: print(" ignoring '%s'" % p['name'])
# # GRAMPS modules # #------------------------------------------------- from gramps.gui.plug.tool import Tool from gramps.gui.plug import MenuToolOptions, PluginWindows from gramps.gen.plug.menu import StringOption, FilterOption, PersonOption, \ EnumeratedListOption, BooleanOption import gramps.gen.lib from gramps.gen.db import DbTxn from gramps.gen.display.name import displayer as name_displayer import gramps.gen.plug.report.utils as ReportUtils from gramps.gen.const import GRAMPS_LOCALE as glocale try: _trans = glocale.get_addon_translator(__file__) except ValueError: _trans = glocale.translation _ = _trans.gettext #------------------------------------------------- # # Tool Classes # #------------------------------------------------- class SetAttributeOptions(MenuToolOptions): """ Set Attribute options """ def __init__(self, name, person_id=None, dbstate=None): self.__db = dbstate.get_database() MenuToolOptions.__init__(self, name, person_id, dbstate)
from gramps.gen.config import config from gramps.gen.db import DbTxn from gramps.gen.display.name import displayer as name_displayer from gramps.gen.plug import Gramplet, MenuOptions from gramps.gen.lib import MediaRef, Person from gramps.gen.lib.date import Today from gramps.gui.editors.editperson import EditPerson from gramps.gui.selectors import SelectorFactory from gramps.gen.plug.menu import BooleanOption, NumberOption from gramps.gui.plug import PluginWindows from gramps.gui.widgets import SelectionWidget, Region from gramps.gui.ddtargets import DdTargets from gramps.gen.const import GRAMPS_LOCALE as glocale try: _ = glocale.get_addon_translator(__file__).sgettext except ValueError: _ = glocale.translation.sgettext #------------------------------------------------------------------------- # # face detection module # #------------------------------------------------------------------------- sys.path.append(os.path.abspath(os.path.dirname(__file__))) import facedetection #------------------------------------------------------------------------- # # configuration #