Skip to content

Commit bc710b0

Browse files
Mattkmmrsam-m888
authored andcommitted
[BirthdaysGramplet]Add 'Only show birthdays with tag' functionality[gramps51](#213)
As requested by @wroldwiedbwe an opposite option that only shows birthdays of persons tagged with a certain tag: All birthdays are shown when neither the 'ignore tag' nor the 'only tag' is selected. The 'ignore tag' hides all birthdays of people tagged with it and the 'only tag' hides all birthdays of person NOT tagged with it. If a person is tagged with both tags (ignore and only) the birthday will be ignored. The tag names don't have to be 'ignore' or 'only'. All tag names are valid.
1 parent cb601e8 commit bc710b0

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

BirthdaysGramplet/BirthdaysGramplet.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,42 @@ def build_options(self):
4242
"""Build the configuration options"""
4343
db = self.dbstate.db
4444

45-
name = _("Ignore birthdays with tag")
46-
self.option = EnumeratedListOption(name, self.ignore_tag)
45+
name_ignore = _("Ignore birthdays with tag")
46+
name_only = _("Only show birthdays with tag")
47+
self.opt_ignore = EnumeratedListOption(name_ignore, self.ignore_tag)
48+
self.opt_only = EnumeratedListOption(name_only, self.only_tag)
4749

48-
self.option.add_item('', '') # No ignore tag
50+
self.opt_ignore.add_item('', '') # No ignore tag
51+
self.opt_only.add_item('', '')
4952
if db.is_open():
5053
for tag_handle in db.get_tag_handles(sort_handles=True):
5154
tag = db.get_tag_from_handle(tag_handle)
5255
tag_name = tag.get_name()
53-
self.option.add_item(tag_name, tag_name)
56+
self.opt_ignore.add_item(tag_name, tag_name)
57+
self.opt_only.add_item(tag_name, tag_name)
5458

55-
self.add_option(self.option)
59+
self.add_option(self.opt_ignore)
60+
self.add_option(self.opt_only)
5661

5762
def save_options(self):
5863
"""Save gramplet configuration data"""
59-
self.ignore_tag = self.option.get_value()
64+
self.ignore_tag = self.opt_ignore.get_value()
65+
self.only_tag = self.opt_only.get_value()
6066

6167
def save_update_options(self, obj):
6268
"""Save a gramplet's options to file"""
6369
self.save_options()
64-
self.gui.data = [self.ignore_tag]
70+
self.gui.data = [self.ignore_tag, self.only_tag]
6571
self.update()
6672

6773
def on_load(self):
6874
"""Load stored configuration data"""
69-
if len(self.gui.data) == 1:
75+
if len(self.gui.data) == 2:
7076
self.ignore_tag = self.gui.data[0]
77+
self.only_tag = self.gui.data[1]
7178
else:
7279
self.ignore_tag = ''
80+
self.only_tag = ''
7381

7482
def db_changed(self):
7583
"""Update gramplet when database was changed"""
@@ -81,24 +89,29 @@ def main(self):
8189
"""Main function of the Birthdays gramplet"""
8290
self.set_text(_("Processing..."))
8391
database = self.dbstate.db
84-
personList = database.iter_people()
92+
person_list = database.iter_people()
8593
self.result = []
8694

87-
# get ignore tag handle
88-
ignore_tag_handle = "" # No ignore handle selceted by user
89-
tag_name = self.option.get_value()
95+
ignore_tag_handle = ""
96+
only_tag_handle = ""
97+
tag_name_ignore = self.opt_ignore.get_value()
98+
tag_name_only = self.opt_only.get_value()
9099
tag_handles = database.get_tag_handles()
91100
for handle in tag_handles:
92101
tag = database.get_tag_from_handle(handle)
93-
if tag_name == tag.get_name():
94-
# overwrite ignore_handle to user selction
102+
# overwrite ignore_handle and only_handle to user selection
103+
# if a handle is selected
104+
if tag_name_ignore == tag.get_name():
95105
ignore_tag_handle = tag.get_handle()
106+
if tag_name_only == tag.get_name():
107+
only_tag_handle = tag.get_handle()
96108

97-
for cnt, person in enumerate(personList):
98-
person_tag_handles = person.get_tag_list()
99-
if ignore_tag_handle in person_tag_handles:
109+
for person in list(person_list):
110+
pers_tag_handles = person.get_tag_list()
111+
if ignore_tag_handle in pers_tag_handles:
100112
pass # ignore person
101-
else: # calculate age and days until birthday:
113+
elif only_tag_handle in pers_tag_handles or only_tag_handle == "":
114+
# calculate age and days until birthday
102115
self.__calculate(database, person)
103116

104117
# Reverse sort on number of days from now:

0 commit comments

Comments
 (0)