class RemoveTagOptions(MenuToolOptions):
    """
    Class for creating 'Remove Tag Tool' menu options.

    The options are needed for processing tag removal in
    :class RemoveTagWindow:.
    """
    def __init__(self, name, person_id=None, dbstate=None):
        self.__db = dbstate.get_database()
        MenuToolOptions.__init__(self, name, person_id, dbstate)

    def get_enum_tag_name_list(self):
        """
        Returns an enumerated tag name list.

        :rtype: list
        """
        tag_list = list(self.__db.iter_tags())
        if tag_list:
            L = list(map(lambda x: x.get_name(), tag_list))
            return list(enumerate(L))

    def is_db_empty(self):
        """
        Check if database has at least one person, family and tag.

        :returns: True or False
        """
        try:
            next(self.__db.iter_person_handles())
            next(self.__db.iter_family_handles())
            next(self.__db.iter_tag_handles())
        except StopIteration:
            # StopIteration is raised if at least one category has no objects
            return True  # Empty
        return False  # Not empty

    def add_menu_options(self, menu):
        """
        Add the menu options for the Remove Tag Tool.
        """
        if self.is_db_empty():
            txt = [
                _("The Remove Tag Tool requires at least "
                  "one person, family and tag to execute.")
            ]
            self.empty = TextOption(_("ERROR"), txt)
            menu.add_option(_("ERROR"), "empty", self.empty)
        else:
            self.__add_tag_category_options(menu)
            self.__add_person_options(menu)
            self.__add_family_options(menu)

            self.filter_dict = {}
            lst = [("events", _("Event Filter"), "event_filter", 'Event',
                    _("All Events")),
                   ("places", _("Place Filter"), "place_filter", 'Place',
                    _("All Places")),
                   ("sources", _("Source Filter"), "scource_filter", 'Source',
                    _("All Sources")),
                   ("citations", _("Citation Filter"), "cit_filter",
                    'Citation', _("All Citations")),
                   ("repositories", _("Repository Filter"), "repo_filter",
                    'Repository', _("All Repositories")),
                   ("media", _("Media Filter"), "media_filter", 'Media',
                    _("All Media")),
                   ("notes", _("Note Filter"), "note_filter", 'Note',
                    _("All Notes"))]

            for entry in lst:
                filter_name = FilterOption(entry[1], 0)
                filter_name.set_help(
                    _("Select filter to restrict {}".format(entry[0])))
                menu.add_option(_("Option 2"), entry[2], filter_name)
                self.filter_dict[entry[3]] = filter_name

                filter_list = CustomFilters.get_filters(entry[3])
                GenericFilter = GenericFilterFactory(entry[3])
                all_filter = GenericFilter()
                all_filter.set_name(entry[4])
                all_filter.add_rule(rules.event.AllEvents([]))
                all_filter_in_list = False
                for fltr in filter_list:
                    if fltr.get_name() == all_filter.get_name():
                        all_filter_in_list = True
                if not all_filter_in_list:
                    filter_list.insert(0, all_filter)
                self.filter_dict[entry[3]].set_filters(filter_list)

    def __add_tag_category_options(self, menu):
        """
        Menu Options for general category tab.

        Users select 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.
        """
        lst = [
            "People", "Families", "Events", "Places", "Sources", "Citations",
            "Repositories", "Media", "Notes"
        ]
        category_list = list(enumerate(lst))

        self.__tag_category = FilterOption(_("Category"), 0)
        self.__tag_category.set_help(_("Choose a category."))
        menu.add_option(_("Option 1"), "category", self.__tag_category)
        self.__tag_category.set_items(category_list)
        self.__tag_category.connect('value-changed', self.__update_options)

        tag_list = self.get_enum_tag_name_list()
        self.__tag_name = FilterOption("Remove Tag", 0)
        self.__tag_name.set_help(_("Choose a tag to remove."))
        menu.add_option(_("Option 1"), "tag_name", self.__tag_name)
        self.__tag_name.set_items(tag_list)

    def __update_options(self):
        """
        Turn availability on depending on user selection.
        """
        self.__disable_all_options()
        value = self.__tag_category.get_value()

        if value == 0:
            self.__person_filter.set_available(True)
            self.__filter_changed()
        elif value == 1:
            self.__family_filter.set_available(True)
            self.__family_filter_changed()
        elif value == 2:
            self.filter_dict['Event'].set_available(True)
        elif value == 3:
            self.filter_dict['Place'].set_available(True)
        elif value == 4:
            self.filter_dict['Source'].set_available(True)
        elif value == 5:
            self.filter_dict['Citation'].set_available(True)
        elif value == 6:
            self.filter_dict['Repository'].set_available(True)
        elif value == 7:
            self.filter_dict['Media'].set_available(True)
        elif value == 8:
            self.filter_dict['Note'].set_available(True)

    def __disable_all_options(self):
        """
        Turn all options off, except options 'category' and 'tag_name'
        """
        self.__person_filter.set_available(False)
        self.__pid.set_available(False)
        self.__family_filter.set_available(False)
        self.__fid.set_available(False)
        for entry in [
                'Event', 'Place', 'Source', 'Citation', 'Repository', 'Media',
                'Note'
        ]:
            self.filter_dict[entry].set_available(False)

    def __add_person_options(self, menu):
        """
        Menu Options for person category.

        Menu Option 'pers_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.

        :param menu: a menu object where options can be added
        :type menu: :class Menu: object
        """
        self.__person_filter = FilterOption(_("Person Filter"), 0)
        self.__person_filter.set_help(_("Select filter to restrict people"))
        menu.add_option(_("Option 1"), "pers_filter", self.__person_filter)
        self.__person_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(_("Option 1"), "pid", self.__pid)
        self.__pid.connect('value-changed', self.__update_filters)

        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.__person_filter.set_filters(filter_list)

    def __filter_changed(self):
        """
        Handle person filter change.

        If the filter is not specific to a person, disable the person option.
        """
        filter_value = self.__person_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.

        :param menu: a menu object where options can be added
        :type menu: :class Menu: object
        """
        self.__family_filter = FilterOption(_("Family Filter"), 0)
        self.__family_filter.set_help(_("Select filter to restrict families"))
        menu.add_option(_("Option 1"), "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(_("Option 1"), "fid", self.__fid)
        self.__fid.connect('value-changed', self.__update_family_filters)

        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 family 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)
Exemple #2
0
class FamilyGroupOptions(MenuReportOptions):
    """
    Defines options and provides handling interface.
    """
    def __init__(self, name, dbase):
        self.__db = dbase
        self.__fid = None
        self.__filter = None
        self.__recursive = None
        self._nf = None
        MenuReportOptions.__init__(self, name, dbase)

    def get_subject(self):
        """ Return a string that describes the subject of the report. """
        return self.__filter.get_filter().get_name()

    def add_menu_options(self, menu):

        ##########################
        category_name = _("Report Options")
        add_option = partial(menu.add_option, category_name)
        ##########################

        self.__filter = FilterOption(_("Filter"), 0)
        self.__filter.set_help(
            _("Select the filter to be applied to the report."))
        add_option("filter", self.__filter)
        self.__filter.connect('value-changed', self.__filter_changed)

        self.__fid = FamilyOption(_("Center Family"))
        self.__fid.set_help(_("The center family for the filter"))
        add_option("family_id", self.__fid)
        self.__fid.connect('value-changed', self.__update_filters)

        self._nf = stdoptions.add_name_format_option(menu, category_name)
        self._nf.connect('value-changed', self.__update_filters)

        self.__update_filters()

        stdoptions.add_private_data_option(menu, category_name)

        stdoptions.add_living_people_option(menu, category_name)

        self.__recursive = BooleanOption(_('Recursive (down)'), False)
        self.__recursive.set_help(
            _("Create reports for all descendants "
              "of this family."))
        add_option("recursive", self.__recursive)

        stdoptions.add_localization_option(menu, category_name)

        ##########################
        add_option = partial(menu.add_option, _("Include"))
        ##########################

        gramps_ids = BooleanOption(_('Gramps ID'), False)
        gramps_ids.set_help(_("Whether to include Gramps ID next to names."))
        add_option("gramps_ids", gramps_ids)

        generations = BooleanOption(
            _("Generation numbers "
              "(recursive only)"), True)
        generations.set_help(
            _("Whether to include the generation on each "
              "report (recursive only)."))
        add_option("generations", generations)

        inc_par_events = BooleanOption(_("Parent Events"), False)
        inc_par_events.set_help(_("Whether to include events for parents."))
        add_option("incParEvents", inc_par_events)

        inc_par_addr = BooleanOption(_("Parent Addresses"), False)
        inc_par_addr.set_help(_("Whether to include addresses for parents."))
        add_option("incParAddr", inc_par_addr)

        inc_par_notes = BooleanOption(_("Parent Notes"), False)
        inc_par_notes.set_help(_("Whether to include notes for parents."))
        add_option("incParNotes", inc_par_notes)

        incattrs = BooleanOption(_("Parent Attributes"), False)
        incattrs.set_help(_("Whether to include attributes."))
        add_option("incattrs", incattrs)

        inc_par_names = BooleanOption(_("Alternate Parent Names"), False)
        inc_par_names.set_help(
            _("Whether to include alternate names for parents."))
        add_option("incParNames", inc_par_names)

        inc_par_mar = BooleanOption(_("Parent Marriage"), True)
        inc_par_mar.set_help(
            _("Whether to include marriage information for parents."))
        add_option("incParMar", inc_par_mar)

        inc_fam_notes = BooleanOption(_("Family Notes"), False)
        inc_fam_notes.set_help(_("Whether to include notes for families."))
        add_option("incFamNotes", inc_fam_notes)

        inc_rel_dates = BooleanOption(_("Dates of Relatives"), False)
        inc_rel_dates.set_help(
            _("Whether to include dates for relatives "
              "(father, mother, spouse)."))
        add_option("incRelDates", inc_rel_dates)

        inc_chi_mar = BooleanOption(_("Children Marriages"), True)
        inc_chi_mar.set_help(
            _("Whether to include marriage information for children."))
        add_option("incChiMar", inc_chi_mar)

        ##########################
        add_option = partial(menu.add_option, _("Missing Information"))
        ##########################

        missinginfo = BooleanOption(
            _("Print fields for missing "
              "information"), True)
        missinginfo.set_help(
            _("Whether to include fields for missing "
              "information."))
        add_option("missinginfo", missinginfo)

    def __update_filters(self):
        """
        Update the filter list based on the selected family
        """
        fid = self.__fid.get_value()
        family = self.__db.get_family_from_gramps_id(fid)
        nfv = self._nf.get_value()
        filter_list = utils.get_family_filters(self.__db,
                                               family,
                                               include_single=True,
                                               name_format=nfv)
        self.__filter.set_filters(filter_list)

    def __filter_changed(self):
        """
        Handle filter change.
        If the filter is not family-specific, disable the family option
        """
        filter_value = self.__filter.get_value()
        if filter_value in [0, 2, 3]:  # filters that rely on the center family
            self.__fid.set_available(True)
        else:  # filters that don't
            self.__fid.set_available(False)

        # only allow recursion if the center family is the only family
        if self.__recursive and filter_value == 0:
            self.__recursive.set_available(True)
        elif self.__recursive:
            self.__recursive.set_value(False)
            self.__recursive.set_available(False)

    def make_default_style(self, default_style):
        """Make default output style for the Family Group Report."""
        para = ParagraphStyle()
        #Paragraph Styles
        font = FontStyle()
        font.set_size(4)
        para.set_font(font)
        default_style.add_paragraph_style('FGR-blank', para)

        font = FontStyle()
        font.set_type_face(FONT_SANS_SERIF)
        font.set_size(16)
        font.set_bold(1)
        para = ParagraphStyle()
        para.set_font(font)
        para.set_alignment(PARA_ALIGN_CENTER)
        para.set_header_level(1)
        para.set_description(_("The style used for the title of the page."))
        default_style.add_paragraph_style('FGR-Title', para)

        font = FontStyle()
        font.set_type_face(FONT_SERIF)
        font.set_size(10)
        font.set_bold(0)
        para = ParagraphStyle()
        para.set_font(font)
        para.set_description(_('The basic style used for the text display.'))
        default_style.add_paragraph_style('FGR-Normal', para)

        para = ParagraphStyle()
        font = FontStyle()
        font.set_type_face(FONT_SERIF)
        font.set_size(10)
        font.set_bold(0)
        para.set_font(font)
        para.set(lmargin=0.0)
        para.set_top_margin(0.0)
        para.set_bottom_margin(0.0)
        para.set_description(_('The basic style used for the note display.'))
        default_style.add_paragraph_style("FGR-Note", para)

        font = FontStyle()
        font.set_type_face(FONT_SANS_SERIF)
        font.set_size(10)
        font.set_bold(1)
        para = ParagraphStyle()
        para.set_font(font)
        para.set_description(
            _('The style used for the text related to the children.'))
        default_style.add_paragraph_style('FGR-ChildText', para)

        font = FontStyle()
        font.set_type_face(FONT_SANS_SERIF)
        font.set_size(12)
        font.set_bold(1)
        para = ParagraphStyle()
        para.set_font(font)
        para.set_header_level(3)
        para.set_description(_("The style used for the parent's name"))
        default_style.add_paragraph_style('FGR-ParentName', para)

        #Table Styles
        cell = TableCellStyle()
        cell.set_padding(0.2)
        cell.set_top_border(1)
        cell.set_bottom_border(1)
        cell.set_right_border(1)
        cell.set_left_border(1)
        default_style.add_cell_style('FGR-ParentHead', cell)

        cell = TableCellStyle()
        cell.set_padding(0.1)
        cell.set_bottom_border(1)
        cell.set_left_border(1)
        default_style.add_cell_style('FGR-TextContents', cell)

        cell = TableCellStyle()
        cell.set_padding(0.1)
        cell.set_bottom_border(0)
        cell.set_left_border(1)
        cell.set_padding(0.1)
        default_style.add_cell_style('FGR-TextChild1', cell)

        cell = TableCellStyle()
        cell.set_padding(0.1)
        cell.set_bottom_border(1)
        cell.set_left_border(1)
        cell.set_padding(0.1)
        default_style.add_cell_style('FGR-TextChild2', cell)

        cell = TableCellStyle()
        cell.set_padding(0.1)
        cell.set_bottom_border(1)
        cell.set_right_border(1)
        cell.set_left_border(1)
        default_style.add_cell_style('FGR-TextContentsEnd', cell)

        cell = TableCellStyle()
        cell.set_padding(0.2)
        cell.set_bottom_border(1)
        cell.set_right_border(1)
        cell.set_left_border(1)
        default_style.add_cell_style('FGR-ChildName', cell)

        table = TableStyle()
        table.set_width(100)
        table.set_columns(3)
        table.set_column_width(0, 20)
        table.set_column_width(1, 40)
        table.set_column_width(2, 40)
        default_style.add_table_style('FGR-ParentTable', table)

        table = TableStyle()
        table.set_width(100)
        table.set_columns(4)
        table.set_column_width(0, 7)
        table.set_column_width(1, 18)
        table.set_column_width(2, 35)
        table.set_column_width(3, 40)
        default_style.add_table_style('FGR-ChildTable', table)
Exemple #3
0
class FamilyGroupOptions(MenuReportOptions):

    """
    Defines options and provides handling interface.
    """

    def __init__(self, name, dbase):
        self.__db = dbase
        self.__fid = None
        self.__filter = None
        self.__recursive = None
        self._nf = None
        MenuReportOptions.__init__(self, name, dbase)

    def get_subject(self):
        """ Return a string that describes the subject of the report. """
        return self.__filter.get_filter().get_name()

    def add_menu_options(self, menu):

        ##########################
        category_name = _("Report Options")
        add_option = partial(menu.add_option, category_name)
        ##########################

        self.__filter = FilterOption(_("Filter"), 0)
        self.__filter.set_help(
            _("Select the filter to be applied to the report."))
        add_option("filter", self.__filter)
        self.__filter.connect('value-changed', self.__filter_changed)

        self.__fid = FamilyOption(_("Center Family"))
        self.__fid.set_help(_("The center family for the filter"))
        add_option("family_id", self.__fid)
        self.__fid.connect('value-changed', self.__update_filters)

        self._nf = stdoptions.add_name_format_option(menu, category_name)
        self._nf.connect('value-changed', self.__update_filters)

        self.__update_filters()

        stdoptions.add_private_data_option(menu, category_name)

        stdoptions.add_living_people_option(menu, category_name)

        self.__recursive = BooleanOption(_('Recursive (down)'), False)
        self.__recursive.set_help(_("Create reports for all descendants "
                                    "of this family."))
        add_option("recursive", self.__recursive)

        stdoptions.add_localization_option(menu, category_name)

        ##########################
        add_option = partial(menu.add_option, _("Include 1"))
        ##########################

        gramps_ids = BooleanOption(_('Gramps ID'), False)
        gramps_ids.set_help(_("Whether to include Gramps ID next to names."))
        add_option("gramps_ids", gramps_ids)

        inc_par_events = BooleanOption(_("Parent Events"), False)
        inc_par_events.set_help(_("Whether to include events for parents."))
        add_option("incParEvents", inc_par_events)

        inc_par_addr = BooleanOption(_("Parent Addresses"), False)
        inc_par_addr.set_help(_("Whether to include addresses for parents."))
        add_option("incParAddr", inc_par_addr)

        inc_par_notes = BooleanOption(_("Parent Notes"), False)
        inc_par_notes.set_help(_("Whether to include notes for parents."))
        add_option("incParNotes", inc_par_notes)

        incattrs = BooleanOption(_("Parent Attributes"), False)
        incattrs.set_help(_("Whether to include attributes."))
        add_option("incattrs", incattrs)

        inc_par_names = BooleanOption(_("Alternate Parent Names"), False)
        inc_par_names.set_help(
            _("Whether to include alternate names for parents."))
        add_option("incParNames", inc_par_names)

        inc_par_mar = BooleanOption(_("Parent Marriage"), True)
        inc_par_mar.set_help(
            _("Whether to include marriage information for parents."))
        add_option("incParMar", inc_par_mar)

        ##########################
        add_option = partial(menu.add_option, _("Include 2"))
        ##########################

        inc_fam_notes = BooleanOption(_("Family Notes"), False)
        inc_fam_notes.set_help(_("Whether to include notes for families."))
        add_option("incFamNotes", inc_fam_notes)

        inc_rel_dates = BooleanOption(_("Dates of Relatives"), False)
        inc_rel_dates.set_help(_("Whether to include dates for relatives "
                                 "(father, mother, spouse)."))
        add_option("incRelDates", inc_rel_dates)

        inc_chi_mar = BooleanOption(_("Children Marriages"), True)
        inc_chi_mar.set_help(
            _("Whether to include marriage information for children."))
        add_option("incChiMar", inc_chi_mar)

        generations = BooleanOption(_("Generation numbers "
                                      "(recursive only)"), False)
        generations.set_help(_("Whether to include the generation on each "
                               "report (recursive only)."))
        add_option("generations", generations) # TODO make insensitive if ...

        ##########################
        add_option = partial(menu.add_option, _("Missing Information"))
        ##########################

        missinginfo = BooleanOption(_("Print fields for missing "
                                      "information"), True)
        missinginfo.set_help(_("Whether to include fields for missing "
                               "information."))
        add_option("missinginfo", missinginfo)

    def __update_filters(self):
        """
        Update the filter list based on the selected family
        """
        fid = self.__fid.get_value()
        family = self.__db.get_family_from_gramps_id(fid)
        nfv = self._nf.get_value()
        filter_list = utils.get_family_filters(self.__db, family,
                                               include_single=True,
                                               name_format=nfv)
        self.__filter.set_filters(filter_list)

    def __filter_changed(self):
        """
        Handle filter change.
        If the filter is not family-specific, disable the family option
        """
        filter_value = self.__filter.get_value()
        if filter_value == 1: # "Entire Database" (as "include_single=True")
            self.__fid.set_available(False)
        else:
            # The other filters need a center family (assume custom ones too)
            self.__fid.set_available(True)

        # only allow recursion if the center family is the only family
        if self.__recursive and filter_value == 0:
            self.__recursive.set_available(True)
        elif self.__recursive:
            self.__recursive.set_value(False)
            self.__recursive.set_available(False)

    def make_default_style(self, default_style):
        """Make default output style for the Family Group Report."""
        para = ParagraphStyle()
        #Paragraph Styles
        font = FontStyle()
        font.set_size(4)
        para.set_font(font)
        default_style.add_paragraph_style('FGR-blank', para)

        font = FontStyle()
        font.set_type_face(FONT_SANS_SERIF)
        font.set_size(16)
        font.set_bold(1)
        para = ParagraphStyle()
        para.set_font(font)
        para.set_alignment(PARA_ALIGN_CENTER)
        para.set_header_level(1)
        para.set_description(_("The style used for the title of the page."))
        default_style.add_paragraph_style('FGR-Title', para)

        font = FontStyle()
        font.set_type_face(FONT_SERIF)
        font.set_size(10)
        font.set_bold(0)
        para = ParagraphStyle()
        para.set_font(font)
        para.set_description(_('The basic style used for the text display.'))
        default_style.add_paragraph_style('FGR-Normal', para)

        para = ParagraphStyle()
        font = FontStyle()
        font.set_type_face(FONT_SERIF)
        font.set_size(10)
        font.set_bold(0)
        para.set_font(font)
        para.set(lmargin=0.0)
        para.set_top_margin(0.0)
        para.set_bottom_margin(0.0)
        para.set_description(_('The basic style used for the note display.'))
        default_style.add_paragraph_style("FGR-Note", para)

        font = FontStyle()
        font.set_type_face(FONT_SANS_SERIF)
        font.set_size(10)
        font.set_bold(1)
        para = ParagraphStyle()
        para.set_font(font)
        para.set_description(
            _('The style used for the text related to the children.'))
        default_style.add_paragraph_style('FGR-ChildText', para)

        font = FontStyle()
        font.set_type_face(FONT_SANS_SERIF)
        font.set_size(12)
        font.set_bold(1)
        para = ParagraphStyle()
        para.set_font(font)
        para.set_header_level(3)
        para.set_description(_("The style used for the parent's name"))
        default_style.add_paragraph_style('FGR-ParentName', para)

        #Table Styles
        cell = TableCellStyle()
        cell.set_padding(0.2)
        cell.set_top_border(1)
        cell.set_bottom_border(1)
        cell.set_right_border(1)
        cell.set_left_border(1)
        default_style.add_cell_style('FGR-ParentHead', cell)

        cell = TableCellStyle()
        cell.set_padding(0.1)
        cell.set_bottom_border(1)
        cell.set_left_border(1)
        default_style.add_cell_style('FGR-TextContents', cell)

        cell = TableCellStyle()
        cell.set_padding(0.1)
        cell.set_bottom_border(0)
        cell.set_left_border(1)
        cell.set_padding(0.1)
        default_style.add_cell_style('FGR-TextChild1', cell)

        cell = TableCellStyle()
        cell.set_padding(0.1)
        cell.set_bottom_border(1)
        cell.set_left_border(1)
        cell.set_padding(0.1)
        default_style.add_cell_style('FGR-TextChild2', cell)

        cell = TableCellStyle()
        cell.set_padding(0.1)
        cell.set_bottom_border(1)
        cell.set_right_border(1)
        cell.set_left_border(1)
        default_style.add_cell_style('FGR-TextContentsEnd', cell)

        cell = TableCellStyle()
        cell.set_padding(0.2)
        cell.set_bottom_border(1)
        cell.set_right_border(1)
        cell.set_left_border(1)
        default_style.add_cell_style('FGR-ChildName', cell)

        table = TableStyle()
        table.set_width(100)
        table.set_columns(3)
        table.set_column_width(0, 20)
        table.set_column_width(1, 40)
        table.set_column_width(2, 40)
        default_style.add_table_style('FGR-ParentTable', table)

        table = TableStyle()
        table.set_width(100)
        table.set_columns(4)
        table.set_column_width(0, 7)
        table.set_column_width(1, 18)
        table.set_column_width(2, 35)
        table.set_column_width(3, 40)
        default_style.add_table_style('FGR-ChildTable', table)
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)