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

[GraphView] rewrite theme support #477

Open
wants to merge 1 commit into
base: maintenance/gramps51
Choose a base branch
from

Conversation

vantu5z
Copy link
Contributor

@vantu5z vantu5z commented Feb 9, 2021

Attempt to provide opportunity to add custom themes 12108 (aditional fields).
Fix 11397 (underline call name).
Family theme is only one and hard coded for now.

Added experimental feature to display attributes (for now - eye and hair colors).

To add custom person theme you should put it to GraphView/themes folder.
You should have some python knowledge and know Gramps structure to create custom themes.

Снимок экрана от 2021-02-09 10-31-34

Example for occupation :

# -*- coding: utf-8 -*-

from default_0 import Theme as DefaultTheme
from gramps.gen.lib import EventType

from gramps.gen.const import GRAMPS_LOCALE as glocale
try:
    _trans = glocale.get_addon_translator(__file__)
except ValueError:
    _trans = glocale.translation
_ = _trans.gettext

class Theme(DefaultTheme):
    """
    Use person DefaultTheme as base.
    Add occupation info.
    """
    THEME_KIND = 'person'

    def __init__(self, dot_generator, options, functions):
        DefaultTheme.__init__(self, dot_generator, options, functions)
        self.index = 5
        self.name = _('Example occupation')

        self.html = ('%(img)s'
                     '%(name)s'
                     '%(dates)s'
                     '%(occup)s'    # we want add occupation data befor tags
                     '%(tags)s')

    def get_some_data(self, person):
        """
        Function to get some data from database.
        For example it is occupation.
        """
        occupation = ''
        event_ref_list = person.get_event_ref_list()
        for event_ref in event_ref_list:
            event = self.functions.dbstate.db.get_event_from_handle(
                event_ref.ref)
            if event.type == EventType.OCCUPATION:
                if occupation:
                    occupation += '<BR/>' + event.get_description()
                else:
                    occupation = event.get_description()

        return self.table_row_fmt % occupation if occupation else ''

    def build(self, person, html):
        """
        Build html table.
        Get if from DefaultTheme and edit.
        """       
        return html % {'img': self.get_image_str(person),
                       'name': self.get_name_str(person),
                       'dates': self.get_dates_str(person),
                       'tags': self.get_tags_str(person),
                       'attrs' : self.get_attrs_str(person),
                       'occup' : self.get_some_data(person)     # add this line
                      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant