word wrap in ancestortree

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

word wrap in ancestortree

Hans Ulrich Frink-2
Dear Devs
I try to display aditional information (i.e. wittnesses) in ancestortree. so I tweek libsubstkeyword.py That works well. But as this results in a very long line (approx. 100 letters) the surrounding box gets very wide.
Even if I insert "\n" it doesnt display well: This gives an additional line, but width (corresponding to width of total line without \n) and hight of the box remain too wide resp. too less high.
So my question: where is width and hight calculated? If I insert a "\n" the "linefactor" should be +1 and width should meashure actual width.
Any help apreciated
cheers 
Uli


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel
Reply | Threaded
Open this post in threaded view
|

Re: word wrap in ancestortree

Paul Franklin-5
> So my question: where is width and hight calculated?

That report and its two library files are hard for anybody
but its prime developer to understand.  Too bad he's
not very active anymore.

You could always copy them into your own "plugin" area
(with a different name and gpr file) and do whatever
you want with them.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel
Reply | Threaded
Open this post in threaded view
|

Fwd: word wrap in ancestortree

Hans Ulrich Frink-2
Subject: Re: [Gramps-devel] word wrap in ancestortree

Hi Paul,
I found the right place for that in libtreebase.py and it works perfectly for my purposes.
I also accomplished to allow users to choose from four different name formats for witnesses in libsubstkeyword.py 
But I found no way to make a new call for personformat as I couldn't understand the structure. So I had to write it my way.
Another open problem is that I use a dictionary of all baptism events and the persons who are witnesses. It would be perfect if I found a way to fill this dictionary once per report. Unfortunately I fill it on every init of the witness event class which costs time. I could put this dictionary in the report, but then I would have to pass it through all function calls. And I would like to have it in the libsubstkeyword library, as it belongs there and works for descendants report as well. But even if I put it in an own class I find no way to fill it only once.
The following shows my attempts:
######################
# $r   only primary event
# $w Witness event
# $w sSlL s Firstname Surname Suffix
# $w sSlL S Firstname Surname Suffix Gramps_ID
# $w sSlL l Surname Firstname Suffix
# $w sSlL L Surname Firstname Suffix Gramps_ID
#########################
class RunOnce:
    """Dictionary read once for witnesses
    """
    _init = False
    def __call__(self):
        if self._init:
            print "Already initialized"
        else:
            print "initializing ..."
            self._init = True
            self.database = database
            pedic = defaultdict(list)
            for pe in self.database.get_person_handles():
                for eventref in self.database.get_person_from_handle(pe).event_ref_list:
                    if not eventref.get_role().is_primary():
                        pedic[eventref.ref].append((eventref.get_role(),pe))
            
        # for testing
            for er in pedic:
                print("init     ", er)
################
class WitnessEventFormat(GenericFormat):
    """ The WitnessEvent format class.
    If no format string, the event description is displayed
    otherwise, parse through the format string and put in the parts
        dates and places can have their own format strings
    """

    def __init__(self, database, _in, locale):
        self.database = database
        GenericFormat.__init__(self, _in, locale)

    def parse_format(self, WitnessEvent):
        """ Parse the event format string.
        let the date or place classes handle any sub-format strings """

        def format_witness_psu():
            return format_witness('psu')
        def format_witness_spu():
            return format_witness('spu')
        def format_witness_spui():
            return format_witness('spui')
        def format_witness_psui():
            return format_witness('psui')
                
        def format_witness(personformat):
            """ Get the name and then get the attributes value """
            #WitnessEvent's Atribute
            #print(WitnessEvent)
            ########################
            line=""
            def format_witness_person(personhandle, personformat):
                if personformat == "psu":
                    wp=str(self.database.get_person_from_handle(personhandle).primary_name.get_name())+ " "
                    wp=wp + str(self.database.get_person_from_handle(personhandle).primary_name.get_suffix())+ " "
                    #wp=wp + "\n"

                elif personformat == "spu":
                    wp=str(self.database.get_person_from_handle(b).primary_name.get_first_name())+ " "
                    wp=wp + str(self.database.get_person_from_handle(b).primary_name.get_surname())+ " "
                    wp=wp + str(self.database.get_person_from_handle(b).primary_name.get_suffix())+ " "
                    #wp=wp + "\n"

                elif personformat == "spui":
                    wp=str(self.database.get_person_from_handle(b).primary_name.get_first_name())+ " "
                    wp=wp + str(self.database.get_person_from_handle(b).primary_name.get_surname())+ " "
                    wp=wp + str(self.database.get_person_from_handle(b).primary_name.get_suffix())+ " "
                    wp=wp + str(self.database.get_person_from_handle(b).gramps_id)
                    #wp=wp + "\n"

                elif personformat == "psui":
                    wp=str(self.database.get_person_from_handle(personhandle).primary_name.get_name())+ " "
                    wp=wp + str(self.database.get_person_from_handle(personhandle).primary_name.get_suffix())+ " "
                    wp=wp + str(self.database.get_person_from_handle(personhandle).gramps_id)
                    #wp=wp + "\n"

                return wp
            
            def get_dict(database):
                print("pedic in subroutine")
                pedic = defaultdict(list)
                for pe in self.database.get_person_handles():
                    for eventref in self.database.get_person_from_handle(pe).event_ref_list:
                        if not eventref.get_role().is_primary():
                            pedic[eventref.ref].append((eventref.get_role(),pe))
                return pedic
            

            if WitnessEvent:
                pedic = None
                print(pedic)
                pedic = get_dict(self.database)
                for er in pedic:
                    event_s = self.database.get_event_from_handle(er)
                    if WitnessEvent.gramps_id == event_s.gramps_id:
                        line = ""
                        lict=0
                        for (a,b) in pedic[er]:
                            line=line+ format_witness_person(b, personformat)
                            line = line + ", "
                            lict=lict+1
                            if lict % 2 == 0 and lict % 4 != 0:
                                line=line+"\n  "
            return(line[:-2])    

        code = "ndDiasSlL"
        upper = ""
        function = [WitnessEvent.get_description,
                    format_date,
                    format_place,
                    WitnessEvent.get_gramps_id,
                    format_attrib,
                    format_witness_psu,
                    format_witness_spu,
                    format_witness_spui,
                    format_witness_psui
                    ]
        return self.generic_format(WitnessEvent, code, upper, function)

################
Cheers
Uli

Am 05.03.2017 8:08 nachm. schrieb "Paul Franklin" <[hidden email]>:
> So my question: where is width and hight calculated?

That report and its two library files are hard for anybody
but its prime developer to understand.  Too bad he's
not very active anymore.

You could always copy them into your own "plugin" area
(with a different name and gpr file) and do whatever
you want with them.


------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Gramps-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gramps-devel