Skip to content

Commit e1982eb

Browse files
PeWusam-m888
authored andcommitted
[Interactive Family Tree]New Addon (Topola)(#197)[gramps51]
A browser tab will be opened with an interactive tree view. See Topola Genealogy Viewer ( https://pewu.github.io/topola-viewer ) for examples how the visualization works. How it works This Gramps addon starts a HTTP server that serves the GEDCOM file that is loaded by the Topola Genealogy Viewer interface. The user data is not sent to any remote location and only loaded into the browser memory.
1 parent 268fb7b commit e1982eb

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

Topola/Topola.gpr.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
register(TOOL,
2+
id = 'Topola',
3+
name =_('Interactive Family Tree'),
4+
description = _('Opens an interactive tree in the browser'),
5+
status = STABLE,
6+
version = '1.0.0',
7+
fname = 'topola.py',
8+
gramps_target_version = '5.1',
9+
authors = ['Przemek Więch'],
10+
authors_email = ['[email protected]'],
11+
category = TOOL_ANAL,
12+
toolclass = 'Topola',
13+
optionclass = 'TopolaOptions',
14+
tool_modes = [TOOL_MODE_GUI]
15+
)

Topola/po/pl-local.po

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Polish translations for PACKAGE package.
2+
# Copyright (C) 2019 THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the PACKAGE package.
4+
# Przemek Wiech <[email protected]>, 2019.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: gramps51\n"
9+
"Report-Msgid-Bugs-To: \n"
10+
"POT-Creation-Date: 2019-04-16 20:32+0200\n"
11+
"PO-Revision-Date: 2019-04-16 20:32+0200\n"
12+
"Last-Translator: Przemek Więch <[email protected]>\n"
13+
"Language-Team: Polish\n"
14+
"Language: pl\n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=UTF-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
19+
"|| n%100>=20) ? 1 : 2);\n"
20+
21+
#: Topola/Topola.gpr.py:3
22+
msgid "Interactive Family Tree"
23+
msgstr "Interaktywne drzewo genealogiczne"
24+
25+
#: Topola/Topola.gpr.py:4
26+
msgid "Opens an interactive tree in the browser"
27+
msgstr "Otwiera interaktywne drzewo genealogiczne w przeglądarce"

Topola/po/template.pot

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the PACKAGE package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5+
#
6+
#, fuzzy
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: PACKAGE VERSION\n"
10+
"Report-Msgid-Bugs-To: \n"
11+
"POT-Creation-Date: 2019-04-16 20:32+0200\n"
12+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14+
"Language-Team: LANGUAGE <[email protected]>\n"
15+
"Language: \n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=UTF-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
20+
#: Topola/Topola.gpr.py:3
21+
msgid "Interactive Family Tree"
22+
msgstr ""
23+
24+
#: Topola/Topola.gpr.py:4
25+
msgid "Opens an interactive tree in the browser"
26+
msgstr ""

Topola/topola.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Interactive tree tool."""
2+
3+
from tempfile import mkstemp
4+
from threading import Thread
5+
from http.server import BaseHTTPRequestHandler, HTTPServer
6+
7+
from gramps.plugins.export.exportgedcom import GedcomWriter
8+
from gramps.gui.user import User
9+
from gramps.gui.display import display_url
10+
from gramps.gui.plug import tool
11+
12+
# Port to start the HTTP server.
13+
HTTP_PORT = 8156
14+
15+
class TopolaServer(Thread):
16+
"""Server serving the Gramps database in GEDCOM format.
17+
18+
This class is used as a singleton.
19+
"""
20+
def __init__(self):
21+
Thread.__init__(self)
22+
self.daemon = True
23+
self.path = None
24+
25+
def set_path(self, path):
26+
"""Sets a new path of the GEDCOM to be served."""
27+
self.path = path
28+
29+
def run(self):
30+
server = self
31+
32+
class Handler(BaseHTTPRequestHandler):
33+
def do_GET(self):
34+
"""Serves the GEDCOM file."""
35+
self.send_response(200)
36+
self.send_header('Access-Control-Allow-Origin', '*')
37+
self.end_headers()
38+
content = open(server.path, 'rb').read()
39+
self.wfile.write(content)
40+
41+
server_address = ('127.0.0.1', HTTP_PORT)
42+
httpd = HTTPServer(server_address, Handler)
43+
httpd.serve_forever()
44+
45+
class Topola(tool.Tool):
46+
"""Gramps tool that opens an interactive tree in the browser.
47+
48+
Starts a HTTP server that serves the data in GEDCOM format, then opens
49+
Topola Genealogy Viewer at https://pewu.github.io/topola-viewer pointing
50+
to the local server to get data. The online viewer does not send any data
51+
to a remote server. All data is only kept in the browser.
52+
"""
53+
server = None
54+
def __init__(self, dbstate, user, options_class, name, callback=None):
55+
tool.Tool.__init__(self, dbstate, options_class, name)
56+
if not dbstate.db:
57+
return
58+
59+
if not Topola.server:
60+
Topola.server = TopolaServer()
61+
Topola.server.start()
62+
63+
temp_file = mkstemp()[1]
64+
ged_writer = GedcomWriter(dbstate.db, User())
65+
ged_writer.write_gedcom_file(temp_file)
66+
Topola.server.set_path(temp_file)
67+
display_url(
68+
'https://pewu.github.io/topola-viewer/#/view' +
69+
'?utm_source=gramps&handleCors=false&standalone=false' +
70+
'&url=http://127.0.0.1:{}/'.format(HTTP_PORT))
71+
72+
class TopolaOptions(tool.ToolOptions):
73+
"""Empty options class."""

0 commit comments

Comments
 (0)