forked from grocanar/Remove-Tag-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoveTagTool.py
696 lines (620 loc) · 27.9 KB
/
RemoveTagTool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2019 Matthias Kemmer
#
# 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.
# -------------------------------------------------
#
# GRAMPS modules
#
# -------------------------------------------------
from gramps.gui.plug import MenuToolOptions, PluginWindows
from gramps.gen.plug.menu import FilterOption, PersonOption, FamilyOption
from gramps.gen.db import DbTxn
import gramps.gen.plug.report.utils as ReportUtils
from gramps.gui.dialog import OkDialog
from gramps.gen.filters import CustomFilters
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 RemoveTagOptions(MenuToolOptions):
"""
Class for creating the remove tag menu options wich are needed for
processing tag removal in class RemoveTagWindow.
"""
def __init__(self, name, person_id=None, dbstate=None):
self.__db = dbstate.get_database()
self.__tag_dict = self.__get_tag_dict()
self.__item_list = self.__get_item_list()
MenuToolOptions.__init__(self, name, person_id, dbstate)
def __get_tag_dict(self):
"""
Return a dict in format:
{tag_name <type:string> : tag_handle <type:string>}
"""
db = self.__db
tag_list = db.iter_tags()
tag_dict = {}
for Tag in tag_list:
serialized = Tag.serialize()
tag_handle = serialized[0]
tag_name = serialized[1]
tag_dict[tag_name] = tag_handle
return tag_dict
def __get_item_list(self):
"""
Return an enumerated list containing the tag touples.
Needed so users can select a tag name from the list.
format:
(number <int>, tag_name <str>)
"""
item_list = []
number = 0
for tag_name in self.__tag_dict:
item = (number, tag_name)
item_list.append(item)
number += 1
return item_list
def add_menu_options(self, menu):
"""
Add the menu options for the Remove Tag Tool.
"""
self.__add_tag_category_options(menu)
self.__add_person_options(menu)
self.__add_family_options(menu)
self.__add_event_options(menu)
self.__add_place_options(menu)
self.__add_source_options(menu)
self.__add_citation_options(menu)
self.__add_repository_options(menu)
self.__add_media_options(menu)
self.__add_note_options(menu)
self.__update_options()
def __add_tag_category_options(self, menu):
"""
Menu Options for general category. Users selects from which category
they'd like to remove a tag. The chosen category also restricts
the tag removal to this category e.g. remove tag 'ToDo' from
filtered persons, but not from places, events, etc.
"""
item_list = []
self.category_names = ["People", "Families", "Events", "Places",
"Sources", "Citations", "Repositories",
"Media", "Notes"]
for i in range(1, 10):
txt = i, _(self.category_names[i-1])
item_list.append(txt)
self.__tag_category = FilterOption(_("Category"), 1)
text = _("Choose a category from where would you like to remove a tag")
tag_category_text = text
self.__tag_category.set_help(tag_category_text)
menu.add_option(_("Configuration"), "tag_category",
self.__tag_category)
self.__tag_category.set_items(item_list)
self.__tag_category.connect('value-changed', self.__update_options)
item_list = self.__item_list
self.__tag_name = FilterOption("Remove Tag", 0)
self.__tag_name.set_help(_("Choose a tag to remove"))
menu.add_option(_("Configuration"), "tag_name", self.__tag_name)
self.__tag_name.set_items(item_list)
def __update_options(self):
self.__filter.set_available(False)
self.__pid.set_available(False)
self.__family_filter.set_available(False)
self.__fid.set_available(False)
self.__event_filter.set_available(False)
self.__place_filter.set_available(False)
self.__source_filter.set_available(False)
self.__cit_filter.set_available(False)
self.__repo_filter.set_available(False)
self.__media_filter.set_available(False)
self.__note_filter.set_available(False)
value = self.__tag_category.get_value()
if value == 1:
self.__filter.set_available(True)
self.__filter_changed()
elif value == 2:
self.__family_filter.set_available(True)
self.__family_filter_changed()
elif value == 3:
self.__event_filter.set_available(True)
elif value == 4:
self.__place_filter.set_available(True)
elif value == 5:
self.__source_filter.set_available(True)
elif value == 6:
self.__cit_filter.set_available(True)
elif value == 7:
self.__repo_filter.set_available(True)
elif value == 8:
self.__media_filter.set_available(True)
elif value == 9:
self.__note_filter.set_available(True)
def __add_person_options(self, menu):
"""
Menu Options for person category. Menu Option 'filter' is used to
choose a generic or custom person filter. Menu Option 'pid' selects
the center person, which is needed for some person filters.
"""
self.__filter = FilterOption(_("Person Filter"), 0)
self.__filter.set_help(_("Select filter to restrict people"))
menu.add_option(_("Configuration"), "filter", self.__filter)
self.__filter.connect('value-changed', self.__filter_changed)
self.__pid = PersonOption(_("Center Person"))
self.__pid.set_help(_("The center person for the filter"))
menu.add_option(_("Configuration"), "pid", self.__pid)
self.__pid.connect('value-changed', self.__update_filters)
def __update_filters(self):
"""
Update the filter list based on the selected person.
"""
gid = self.__pid.get_value()
person = self.__db.get_person_from_gramps_id(gid)
filter_list = ReportUtils.get_person_filters(person, False)
self.__filter.set_filters(filter_list)
def __filter_changed(self):
"""
Handle filter change. If the filter is not specific to a person,
disable the person option.
"""
filter_value = self.__filter.get_value()
if filter_value in [1, 2, 3, 4]:
self.__pid.set_available(True)
else:
self.__pid.set_available(False)
def __add_family_options(self, menu):
"""
Menu Options for family category. Menu Option 'family_filter' is used
to choose a generic or custom family filter. Menu Option 'fid'
selects the center family, which is needed for some filters.
"""
self.__family_filter = FilterOption(_("Family Filter"), 0)
self.__family_filter.set_help(_("Select filter to restrict families"))
menu.add_option(_("Configuration"), "family_filter", self.__family_filter)
self.__family_filter.connect('value-changed',
self.__family_filter_changed)
self.__fid = FamilyOption(_("Center Family"))
self.__fid.set_help(_("The center person for the filter"))
menu.add_option(_("Configuration"), "fid", self.__fid)
self.__fid.connect('value-changed', self.__update_family_filters)
def __update_family_filters(self):
"""
Update the filter list based on the selected family.
"""
gid = self.__fid.get_value()
family = self.__db.get_family_from_gramps_id(gid)
filter_list = ReportUtils.get_family_filters(self.__db, family, False)
self.__family_filter.set_filters(filter_list)
def __family_filter_changed(self):
"""
Handle filter change. If the filter is not specific to a family,
disable the family option.
"""
filter_value = self.__family_filter.get_value()
if filter_value in [1, 2]:
self.__fid.set_available(True)
else:
self.__fid.set_available(False)
def __add_event_options(self, menu):
"""
Menu Options for event category. Menu Option 'event_filter' is used
to choose a custom event filter.
"""
self.__event_filter = FilterOption(_("Event Filter"), 0)
self.__event_filter.set_help(_("Select filter to restrict events"))
menu.add_option(_("Configuration"), "event_filter", self.__event_filter)
filter_list = CustomFilters.get_filters('Event')
self.__event_filter.set_filters(filter_list)
def __add_place_options(self, menu):
"""
Menu Options for place category. Menu Option 'place_filter' is used
to choose a custom place filter.
"""
self.__place_filter = FilterOption(_("Place Filter"), 0)
self.__place_filter.set_help(_("Select filter to restrict places"))
menu.add_option(_("Configuration"), "place_filter", self.__place_filter)
filter_list = CustomFilters.get_filters('Place')
self.__place_filter.set_filters(filter_list)
def __add_source_options(self, menu):
"""
Menu Options for scoure category. Menu Option 'source_filter' is used
to choose a custom source filter.
"""
self.__source_filter = FilterOption(_("Source Filter"), 0)
self.__source_filter.set_help(_("Select filter to restrict sources"))
menu.add_option(_("Configuration"), "source_filter", self.__source_filter)
filter_list = CustomFilters.get_filters('Source')
self.__source_filter.set_filters(filter_list)
def __add_citation_options(self, menu):
"""
Menu Options for citation category. Menu Option 'cit_filter' is used
to choose a custom citation filter.
"""
self.__cit_filter = FilterOption(_("Citation Filter"), 0)
self.__cit_filter.set_help(_("Select filter to restrict citations"))
menu.add_option(_("Configuration"), "cit_filter", self.__cit_filter)
filter_list = CustomFilters.get_filters('Citation')
self.__cit_filter.set_filters(filter_list)
def __add_repository_options(self, menu):
"""
Menu Options for repository category. Menu Option 'repo_filter' is
usedto choose a custom repository filter.
"""
self.__repo_filter = FilterOption(_("Repository Filter"), 0)
text = _("Select filter to restrict repositories")
self.__repo_filter.set_help(text)
menu.add_option(_("Configuration"), "repo_filter", self.__repo_filter)
filter_list = CustomFilters.get_filters('Repository')
self.__repo_filter.set_filters(filter_list)
def __add_media_options(self, menu):
"""
Menu Options for media category. Menu Option 'media_filter' is used
to choose a custom media filter.
"""
self.__media_filter = FilterOption(_("Media Filter"), 0)
self.__media_filter.set_help(_("Select filter to restrict media"))
menu.add_option(_("Configuration"), "media_filter", self.__media_filter)
filter_list = CustomFilters.get_filters('Media')
self.__media_filter.set_filters(filter_list)
def __add_note_options(self, menu):
"""
Menu Options for notes category. Menu Option 'note_filter' is used
to choose a custom note filter.
"""
self.__note_filter = FilterOption(_("Note Filter"), 0)
self.__note_filter.set_help(_("Select filter to restrict notes"))
menu.add_option(_("Configuration"), "note_filter", self.__note_filter)
filter_list = CustomFilters.get_filters('Note')
self.__note_filter.set_filters(filter_list)
class RemoveTagWindow(PluginWindows.ToolManagedWindowBatch):
def get_title(self):
"""
Window title.
"""
return _("Remove Tag Tool")
def initial_frame(self):
"""
Category tab title.
"""
return _("Options")
def run(self):
"""
Main function running the Remove Tag Tool.
"""
self.__db = self.dbstate.get_database()
self.__tag_dict = self.__get_tag_dict()
self.__get_menu_options()
def __get_tag_dict(self):
"""
Return a dict in format:
{tag_name <type:string> : tag_handle <type:string>}
"""
db = self.__db
tag_list = db.iter_tags()
tag_dict = {}
counter = 0
for Tag in tag_list:
serialized = Tag.serialize()
tag_handle = serialized[0]
tag_name = serialized[1]
tag_dict[counter] = (tag_name, tag_handle)
counter += 1
return tag_dict
def __get_menu_options(self):
"""
A function selecting which category is processed e.g people,
events, etc. The category_value is selected by the user in the
menu options for general category. This function is the interating
through the items of that category, aplying the selected filter
from the menu options. Finally the tag_handle is removed from all
those items of the category, but not from the other categories.
"""
tag_category = self.options.menu.get_option_by_name('tag_category')
category_value = tag_category.get_value()
tag_value = self.options.handler.options_dict['tag_name']
tag_dict = self.__tag_dict
tag_name = tag_dict[tag_value][0]
tag_handle = tag_dict[tag_value][1]
# Case 1: Remove tag from people
if category_value == 1:
iter_people = self.dbstate.db.iter_person_handles()
self.filter_opt = self.options.menu.get_option_by_name('filter')
self.filter = self.filter_opt.get_filter()
people = self.filter.apply(self.dbstate.db, iter_people)
self.__remove_from_people(people, tag_name, tag_handle)
# Case 2: Remove tag from families
elif category_value == 2:
iter_families = self.dbstate.db.iter_family_handles()
opt = self.options.menu
self.filter_opt = opt.get_option_by_name('family_filter')
self.filter = self.filter_opt.get_filter()
families = self.filter.apply(self.dbstate.db, iter_families)
self.__remove_from_families(families, tag_name, tag_handle)
# Case 3: Remove tag from events
elif category_value == 3:
iter_events = self.dbstate.db.iter_event_handles()
opt = self.options.menu
self.filter_opt = opt.get_option_by_name('event_filter')
self.filter = self.filter_opt.get_filter()
events = self.filter.apply(self.dbstate.db, iter_events)
self.__remove_from_events(events, tag_name, tag_handle)
# Case 4: Remove tag from places
elif category_value == 4:
iter_places = self.dbstate.db.iter_place_handles()
opt = self.options.menu
self.filter_opt = opt.get_option_by_name('place_filter')
self.filter = self.filter_opt.get_filter()
places = self.filter.apply(self.dbstate.db, iter_places)
self.__remove_from_places(places, tag_name, tag_handle)
# Case 5: Remove tag from sources
elif category_value == 5:
iter_sources = self.dbstate.db.iter_source_handles()
opt = self.options.menu
self.filter_opt = opt.get_option_by_name('source_filter')
self.filter = self.filter_opt.get_filter()
sources = self.filter.apply(self.dbstate.db, iter_sources)
self.__remove_from_sources(sources, tag_name, tag_handle)
# Case 6: Remove tag from citations
elif category_value == 6:
iter_cits = self.dbstate.db.iter_citation_handles()
opt = self.options.menu
self.filter_opt = opt.get_option_by_name('cit_filter')
self.filter = self.filter_opt.get_filter()
citations = self.filter.apply(self.dbstate.db, iter_cits)
self.__remove_from_citations(citations, tag_name, tag_handle)
# Case 7: Remove tag from repositories
elif category_value == 7:
iter_repos = self.dbstate.db.iter_repository_handles()
opt = self.options.menu
self.filter_opt = opt.get_option_by_name('repo_filter')
self.filter = self.filter_opt.get_filter()
repos = self.filter.apply(self.dbstate.db, iter_repos)
self.__remove_from_repositories(repos, tag_name, tag_handle)
# Case 8: Remove tag from media
elif category_value == 8:
iter_media = self.dbstate.db.iter_media_handles()
opt = self.options.menu
self.filter_opt = opt.get_option_by_name('media_filter')
self.filter = self.filter_opt.get_filter()
media = self.filter.apply(self.dbstate.db, iter_media)
self.__remove_from_media(media, tag_name, tag_handle)
# Case 9: Remove tag from notes
elif category_value == 9:
iter_notes = self.dbstate.db.iter_note_handles()
opt = self.options.menu
self.filter_opt = opt.get_option_by_name('note_filter')
self.filter = self.filter_opt.get_filter()
notes = self.filter.apply(self.dbstate.db, iter_notes)
self.__remove_from_notes(notes, tag_name, tag_handle)
def __remove_from_people(self, people, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of people the tag was
removed from.
"""
counter = 0
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_people = len(people)
self.progress.set_pass(_('Removing tags...'),
num_people)
for person_handle in people:
person = self.dbstate.db.get_person_from_handle(person_handle)
if tag_handle in person.get_tag_list():
person.remove_tag(tag_handle)
self.db.commit_person(person, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} people.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)
def __remove_from_families(self, families, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of families the tag was
removed from.
"""
counter = 0
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_families = len(families)
self.progress.set_pass(_('Removing tags...'),
num_families)
for family_handle in families:
family = self.dbstate.db.get_family_from_handle(family_handle)
if tag_handle in family.get_tag_list():
family.remove_tag(tag_handle)
self.db.commit_family(family, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} families.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)
def __remove_from_events(self, events, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of events the tag was
removed from.
"""
counter = 0
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_events = len(events)
self.progress.set_pass(_('Removing tags...'),
num_events)
for event_handle in events:
event = self.dbstate.db.get_event_from_handle(event_handle)
if tag_handle in event.get_tag_list():
event.remove_tag(tag_handle)
self.db.commit_event(event, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} events.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)
def __remove_from_places(self, places, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of places the tag was
removed from.
"""
counter = 0
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_places = len(places)
self.progress.set_pass(_('Removing tags...'),
num_places)
for place_handle in places:
place = self.dbstate.db.get_place_from_handle(place_handle)
if tag_handle in place.get_tag_list():
place.remove_tag(tag_handle)
self.db.commit_place(place, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} places.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)
def __remove_from_sources(self, sources, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of sources the tag was
removed from.
"""
counter = 0
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_sources = len(sources)
self.progress.set_pass(_('Removing tags...'),
num_sources)
for source_handle in sources:
source = self.dbstate.db.get_source_from_handle(source_handle)
if tag_handle in source.get_tag_list():
source.remove_tag(tag_handle)
self.db.commit_source(source, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} sources.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)
def __remove_from_citations(self, cits, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of sources the tag was
removed from.
"""
counter = 0
# cit = citation
# cits = citations
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_cits = len(cits)
self.progress.set_pass(_('Removing tags...'),
num_cits)
for cit_handle in cits:
cit = self.dbstate.db.get_citation_from_handle(cit_handle)
if tag_handle in cit.get_tag_list():
cit.remove_tag(tag_handle)
self.db.commit_citation(cit, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} citations.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)
def __remove_from_repositories(self, repos, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of sources the tag was
removed from.
"""
counter = 0
# repo = repository
# repos = repositories
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_repos = len(repos)
self.progress.set_pass(_('Removing tags...'),
num_repos)
for repo_handle in repos:
repo = self.dbstate.db.get_repository_from_handle(repo_handle)
if tag_handle in repo.get_tag_list():
repo.remove_tag(tag_handle)
self.db.commit_citation(repo, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} repositories.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)
def __remove_from_media(self, media, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of sources the tag was
removed from.
"""
counter = 0
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_media = len(media)
self.progress.set_pass(_('Removing tags...'),
num_media)
for media_handle in media:
media_ = self.dbstate.db.get_media_from_handle(media_handle)
if tag_handle in media_.get_tag_list():
media_.remove_tag(tag_handle)
self.db.commit_citation(media_, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} media.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)
def __remove_from_notes(self, notes, tag_name, tag_handle):
"""
This functions handles the tag removal and the progress window as
well as informing the user about the amount of sources the tag was
removed from.
"""
counter = 0
with DbTxn(_("Remove Tag Tool"), self.db, batch=True) as self.trans:
self.db.disable_signals()
num_notes = len(notes)
self.progress.set_pass(_('Removing tags...'),
num_notes)
for note_handle in notes:
note = self.dbstate.db.get_note_from_handle(note_handle)
if tag_handle in note.get_tag_list():
note.remove_tag(tag_handle)
self.db.commit_citation(note, self.trans)
counter += 1
self.db.enable_signals()
self.db.request_rebuild()
text = _("Tag '{}' removed from {} notes.\n")
text_f = text.format(tag_name, str(counter))
OkDialog("INFO", text_f, parent=self.window)