Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Gramplet: Historical Context (Gramps 5.2) Gramplet will show historical events in the gramplet panel. #615

Open
wants to merge 7 commits into
base: maintenance/gramps52
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HistContext/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*bak
locale/
*2024*
da.po
18 changes: 18 additions & 0 deletions HistContext/HistContext.gpr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
register(GRAMPLET,
id="HistContext",
name=_("Historical Context"),
description = _("Displaying a historical context"),
status = BETA,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change status to "STABLE"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

version = '0.2.10',
fname="HistContext.py",
height = 20,
detached_width = 510,
detached_height = 480,
expand = True,
gramplet = "HistContext",
gramplet_title=_("Historical Context"),
gramps_target_version="5.2",
help_url="https://github.com/kajmikkelsen/TimeLineGramplet",
Copy link

@Call-Me-Dave Call-Me-Dave Nov 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to point to the new help page on the Gramps wiki for this addon say

help_url="https://gramps-project.org/wiki/index.php/Addon:Historical_Context",

navtypes=["Person","Dashboard"],
include_in_listing = True,
)
298 changes: 298 additions & 0 deletions HistContext/HistContext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2024 Kaj Mikkelsen <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

#----------------------------------------------------------------------------
"""
Historical Context - a plugin for showing historical events
Will show the person in a historical context
"""

# File: HistContext.py
#from gramps.gen.plug import Gramplet

import os
import logging
import gi
import glob
from gramps.gen.plug import Gramplet
from gramps.gen.const import GRAMPS_LOCALE as glocale
from gramps.gen.utils.db import (get_birth_or_fallback, get_death_or_fallback)
from gramps.gui.display import display_url
from gramps.gui.dialog import ErrorDialog
from gramps.gen.plug.menu import EnumeratedListOption,BooleanOption,StringOption


from gi.repository import Pango
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

#------------------------------------------------------------------------
#
# GRAMPS modules
#
#------------------------------------------------------------------------

local_log = logging.getLogger('HistContext')
local_log.setLevel(logging.WARNING)

try:
_trans = glocale.get_addon_translator(__file__)
except ValueError:
_trans = glocale.translation
_ = _trans.gettext
lang = glocale.lang
local_log.info('Sprog = %s',lang)


class HistContext(Gramplet):
"""
class for showing a timeline
"""
def init(self):
self.model = Gtk.ListStore(str, str, str,str,str)
self.gui.WIDGET = self.build_gui()
self.gui.get_container_widget().remove(self.gui.textview)
self.gui.get_container_widget().add(self.gui.WIDGET)
self.gui.WIDGET.show()
self.model.clear()


def build_options(self):
"""
Build the configuration options.
"""
files = []

self.opts = []

name = _("Filter string ")
opt = StringOption(name, self.__start_filter_st)
self.opts.append(opt)
name = _("Use filter ")
opt = BooleanOption(name,self.__use_filter)
self.opts.append(opt)
name =_("Hide outside life span ")
opt = BooleanOption(name,self.__hide_it)
self.opts.append(opt)
name = _("Files")
flnam = os.path.join(os.path.dirname(__file__), '*.txt')
files = [f for f in glob.glob(flnam)]
opt = EnumeratedListOption(name,self.__selFile)
for filnm in files:
opt.add_item(filnm,os.path.basename(filnm))
self.opts.append(opt)
if self.dbstate.db.is_open():
for tag_handle in self.dbstate.db.get_tag_handles(sort_handles=True):
tag = self.dbstate.db.get_tag_from_handle(tag_handle)
tag_name = tag.get_name()
list(map(self.add_option, self.opts))

def save_options(self):
"""
Save gramplet configuration data.
"""
self.__start_filter_st = self.opts[0].get_value()
self.__use_filter = self.opts[1].get_value()
self.__hide_it = self.opts[2].get_value()
self.__selFile = self.opts[3].get_value()
local_log.info('1 stored Filename = %s',self.__selFile)

def save_update_options(self, obj):
"""
Save a gramplet's options to file.
"""
self.save_options()
self.gui.data = [
self.__start_filter_st,
self.__use_filter,
self.__hide_it,
self.__selFile,
]
local_log.info('3 stored Filename = %s',self.__selFile)
self.update()

def on_load(self):
"""
Load stored configuration data.
"""
local_log.info('Antal = %d',len(self.gui.data))
if len(self.gui.data) == 4:
self.__start_filter_st = self.gui.data[0]
self.__use_filter = (self.gui.data[1] == 'True')
self.__hide_it = (self.gui.data[2] == 'True')
self.__selFile = self.gui.data[3]
else:
self.__start_filter_st = "Census"
self.__use_filter = True
self.__hide_it = True
self.__selFile = os.path.join(os.path.dirname(__file__),'default_data_v1_0.txt')
local_log.info('2 stored Filename = %s',self.__selFile)


def get_birth_year(self):
"""
returning the years of birth and death of the active person
"""
birthyear = 0
deathyear = 0
active_person = self.get_active_object("Person")
if active_person:
navn = active_person.get_primary_name().get_name()
birth = get_birth_or_fallback(self.dbstate.db, active_person)
if birth:
birthdate = birth.get_date_object()
if birthdate:
birthyear = birthdate.to_calendar("gregorian").get_year()
local_log.info ("Født: %s",birthyear)
death = get_death_or_fallback(self.dbstate.db, active_person)
if death:
deathdate = death.get_date_object()
if deathdate:
deathyear = deathdate.to_calendar("gregorian").get_year()
local_log.info ("Død: %s",deathyear)

else:
local_log.info ("no active person")
if (birthyear > 0) and (deathyear == 0):
deathyear = birthyear+100
if (deathyear > 0) and (birthyear == 0):
birthyear = deathyear - 100
return birthyear, deathyear

def load_file(self,flnm):
local_log.info('FILENANME %s',flnm);
birthyear,deathyear = self.get_birth_year()
linenbr = 0
with open(flnm,encoding='utf-8') as myfile:
for line in myfile:
linenbr += 1
line = line.rstrip()+';'
words = line.split(';')
if len(words) != 5:
if len(line) > 10:
errormessage = _(': not four semicolons in : "')+line+'i" File: '+flnm
errormessage = str(linenbr)+errormessage
ErrorDialog(_('Error:'),errormessage)
else:
words[2] = words[2].replace('"','')
if words[1] == '':
end_year = words[0]
else:
end_year = words[1]

if ((int(words[0]) >= int(birthyear)) and (int(words[0]) <= int(deathyear))) or \
((int(end_year) >= int(birthyear)) and (int(end_year) <= int(deathyear))):
mytupple = (words[0],words[1],words[2],words[3],'#000000','#ffffff')
hide_this = False
else:
hide_this = self.__hide_it
mytupple = (words[0],words[1],words[2],words[3],'#000000','#ededed')
if not hide_this:
if self.__use_filter:
if not words[2].startswith(self.__start_filter_st):
local_log.info('appending %s',words[2])
self.model.append(mytupple)
else:
local_log.info('appending %s',words[2])
self.model.append(mytupple)



def main(self):
local_log.info('testing string %s ',self.__start_filter_st)
local_log.info('testing boolean %r ',self.__use_filter)
self.model.clear()
flnm = self.__selFile
if not os.path.exists(flnm):
flnm = os.path.join(os.path.dirname(__file__), 'default'+'_data_v1_0.txt')

if os.path.exists(flnm):
if os.path.isfile(flnm):
self.load_file(flnm)
else:
self.set_text('No file '+flnm)
else:
self.set_text('No path '+flnm)
def_flnm = os.path.join(os.path.dirname(__file__), 'custom_v1_0.txt')
if flnm != def_flnm:
if os.path.exists(def_flnm):
if os.path.isfile(def_flnm):
self.load_file(def_flnm)

def active_changed(self, handle):
"""
Called when the active person is changed.
"""
local_log.info('Active changed')
self.update()

def act(self,tree_view,path, column):
"""
Called when the user double-click a row
"""
tree_iter = self.model.get_iter(path)
URL = self.model.get_value(tree_iter, 3)
if URL.startswith("https://"):
display_url(URL)
else:
errormessage = _('Cannot open URL: ')+URL
ErrorDialog(_('Error:'),errormessage)




def build_gui(self):
"""
Build the GUI interface.
"""
tip = _("Double click row to follow link")
self.set_tooltip(tip)
self.model = Gtk.ListStore(str,str,str,str,str,str)
top = Gtk.TreeView()
top.connect("row-activated", self.act)
renderer = Gtk.CellRendererText()
renderer.set_property('ellipsize', Pango.EllipsizeMode.END)

column = Gtk.TreeViewColumn(_('From'), renderer, text=0,foreground=4,background=5)
column.set_expand(False)
column.set_resizable(True)
column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
column.set_fixed_width(50)
column.set_sort_column_id(0)
top.append_column(column)
renderer = Gtk.CellRendererText()

column = Gtk.TreeViewColumn(_('To'), renderer, text=1,foreground=4,background=5)
column.set_sort_column_id(1)
column.set_fixed_width(50)
top.append_column(column)

column = Gtk.TreeViewColumn(_('Text'), renderer, text=2,foreground=4,background=5)
column.set_sort_column_id(2)
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
top.append_column(column)

# column = Gtk.TreeViewColumn(_('Link'), renderer, text=3,foreground=4,background=5)
# column.set_sort_column_id(3)
# column.set_fixed_width(150)
# top.append_column(column)
self.model.set_sort_column_id(0,Gtk.SortType.ASCENDING)
top.set_model(self.model)
return top
1 change: 1 addition & 0 deletions HistContext/MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HistTime/README.md
28 changes: 28 additions & 0 deletions HistContext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### Histtory Context gramplet

Gramplet to display historical events with the year they happened, and optionally the year they ended.
A double-click on a row will open your browser at the provided Link

The gramplet works on the person and the relations view.
The data for the gramplet comes from a CSV file, which can be edited with a normal editor.

The Format is:

`from;to;event;link to event`

example:

1789;1797;George Washington;https://en.wikipedia.org/wiki/George\_Washington

The file name is `<locale>_data_v1_0.txt `e.g. `da_DK_data_v1_0.txt` for Denmark
Currently only four files are provided, `da_DK_data_v1_0.txt` and `en_US_data_v1_0.txt` which simply is a list of American presidents.
The third is `deafult_data_v1_0.txt`which will be used, if there isn't any data file for your language.
The fourth file is `custom_v1_0.txt`which can be used for adding your own data, which will be merged into the view.

You can select the data file form the options in the view

In the options you can also elect whether you want see all historical data, or only those in the focus persons lifetime

I have added all the danish census'es to the Danish data file. To avoid looking at this you can go into the settings for the person list, and make a filter. If you check the "use filter" checkbox, the historical list will not display the events starting with the text you have added. In my case the text is "Folketælling"


Loading