Code Search for Developers
 
 
  

ToolTips.py from gramps at Krugle


Show ToolTips.py syntax highlighted

# -*- coding: utf-8 -*-
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006  Donald N. Allingham
#
# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

# $Id: ToolTips.py 8747 2007-07-20 12:03:35Z pez4brian $

#------------------------------------------------------------------------
#
# ToolTips
#
# The model provides a framework for generating tooltips for different
# gramps objects. The idea is to hide the task of generating these tips
# from the other parts of gramps and to provide a single place were
# a tooltip is generated so that it is consistent everywhere it is used.
#
# The tooltips generated by this module are meant to be passed to the
# TreeTips module for rendering.
#
# To add tooltips for a new object:
#
#    1. copy one of the existing <object>Tip classes and change the tooltip()
#       method to suit the new object.
#    2. add a new entry to the CLASS_MAP at the bottom of the file.
#    3. thats it.
#
# To use the tips, use one of the factory classes to generate the tips.
# The factory classes generate methods that TreeTips will execute only
# if the tip is needed. So the processing is deferred until required.
#------------------------------------------------------------------------

#------------------------------------------------------------------------
#
# standard python modules
#
#------------------------------------------------------------------------
from xml.sax.saxutils import escape
from gettext import gettext as _

#-------------------------------------------------------------------------
#
# gtk
#
#-------------------------------------------------------------------------

#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
import RelLib
import DateHandler

#-------------------------------------------------------------------------
#
# Utility functions
#
#-------------------------------------------------------------------------

def short(val,size=60):
    if len(val) > size:
        return "%s..." % val[0:size]
    else:
        return val

#-------------------------------------------------------------------------
#
# Factory classes
#
#-------------------------------------------------------------------------

class TipFromFunction:
    """
    TipFromFunction generates a tooltip callable. 
    """
    def __init__(self,db,fetch_function):
        """
        fetch_function: a callable that will return a Rellib object
        when it is run. The function will not be run until the tooltip
        is required. Use a lambda function to currie any required
        arguments.
        """
        self._db = db
        self._fetch_function = fetch_function

    def get_tip(self):
        o = self._fetch_function()

        # check if we have a handler for the object type returned
        for cls in CLASS_MAP.keys():
            if isinstance(o,cls):
                return CLASS_MAP[cls](self._db,o)()

        return "no tip"

    __call__ = get_tip


#-------------------------------------------------------------------------
#
# Tip generator classes.
#
#-------------------------------------------------------------------------

class RepositoryTip:
    def __init__(self,db,repos):
        self._db = db
        self._obj = repos

    def get_tip(self):
        global escape
        s = "<big><b>%s:</b>\t%s</big>\n\n"\
            "\t<b>%s:</b>\n"\
            "\t\t%s\n"\
            "\t\t%s\n"\
            "\t\t%s\n"\
            "\t\t%s\n"\
            "\t\t%s\n"\
            "\t\t%s\n"\
            "\t<b>%s:</b>\t%s\n"\
            "\t<b>%s:</b>\t%s\n"\
            "\t<b>%s:</b>\t%s\n"\
            "\t<b>%s:</b>\t%s\n"\
            % (
            _("Repository"),escape(self._obj.get_name()),
            _("Location"),
            escape(self._obj.address.get_parish()),
            escape(self._obj.address.get_city()),
            escape(self._obj.address.get_county()),
            escape(self._obj.address.get_state()),
            escape(self._obj.address.get_postal_code()),
            escape(self._obj.address.get_country()),
            _("Telephone"), escape(self._obj.address.get_phone()),
            _("Email"), escape(self._obj.get_email()),
            _("Search Url"), escape(self._obj.get_search_url()),
            _("Home Url"), escape(self._obj.get_home_url()))    

        # Get the notes
        notelist = self._obj.get_note_list()
        for notehandle in notelist:
            note = self._db.get_note_from_handle(notehandle)
            s += "\t<b>%s:</b>\t%s\n" % (
                    _("Note"), escape(note.get(False)))

        # Get the list of sources that reference this repository
        repos_handle = self._obj.get_handle()
        source_list = [ src_handle for src_handle \
                        in self._db.get_source_handles() \
                        if self._db.get_source_from_handle(src_handle).has_repo_reference(repos_handle)]

        if len(source_list) > 0:
            s += "\n<big><b>%s</b></big>\n\n" % (_("Sources in repository"),)
                
            for src_handle in source_list:
                src = self._db.get_source_from_handle(src_handle)
                s += "\t<b>%s:</b>\t%s\n" % (
                    _("Name"),escape(short(src.get_title())))
                
        return s

    __call__ = get_tip

class PersonTip:
    def __init__(self,db,repos):
        self._db = db
        self._obj = repos

    def get_tip(self):
        global escape

        birth_str = ""
        birth_ref = self._obj.get_birth_ref()
        if birth_ref:
            birth = self._db.get_event_from_handle(birth_ref.ref)
            date_str = DateHandler.get_date(birth)
            if date_str != "":
                birth_str = escape(date_str)
                
        s = "<span size=\"larger\" weight=\"bold\">%s</span>\n"\
            "   <span weight=\"bold\">%s:</span> %s\n"\
            "   <span weight=\"bold\">%s:</span> %s\n" % (
            _("Person"),
            _("Name"),escape(self._obj.get_primary_name().get_name()),
            _("Birth"),birth_str)

        if len(self._obj.get_source_references()) > 0:
            psrc_ref = self._obj.get_source_references()[0]
            psrc_id = psrc_ref.get_reference_handle()
            psrc = self._db.get_source_from_handle(psrc_id)

            s += "\n<span size=\"larger\" weight=\"bold\">%s</span>\n"\
                 "   <span weight=\"bold\">%s:</span> %s\n" % (
                _("Primary source"),
                _("Name"),
                escape(short(psrc.get_title())))
                
        return s

    __call__ = get_tip

class FamilyTip:
    def __init__(self,db,obj):
        self._db = db
        self._obj = obj

    def get_tip(self):
        global escape

        fhandle = self._obj.get_father_handle()
        mhandle = self._obj.get_mother_handle()
                
        s = "<span size=\"larger\" weight=\"bold\">%s</span>" % _("Family")

        if fhandle:
            father = self._db.get_person_from_handle(fhandle)
            s +="\n   <span weight=\"bold\">%s:</span> %s" % (
                _("Father"),escape(father.get_primary_name().get_name()))

        if mhandle:
            mother = self._db.get_person_from_handle(mhandle)
            s +="\n   <span weight=\"bold\">%s:</span> %s" % (
                _("Mother"),escape(mother.get_primary_name().get_name()))

        for cref in self._obj.get_child_ref_list():
            child =  self._db.get_person_from_handle(cref.ref)
            s +="\n   <span weight=\"bold\">%s:</span> %s" % (
                _("Child"),escape(child.get_primary_name().get_name()))

        return s

    __call__ = get_tip


CLASS_MAP = {
    RelLib.Repository : RepositoryTip,
    RelLib.Person     : PersonTip,
    RelLib.Family     : FamilyTip
    }




See more files for this project here

gramps

GRAMPS is a GNOME genealogy program for Linux and FreeBSD that allows you to easily build\r\nand keep track of your family tree.

Project homepage: http://sourceforge.net/projects/gramps
Programming language(s): Python
License: other

  BasicUtils/
    Makefile.am
    _NameDisplay.py
    _UpdateCallback.py
    __init__.py
  Config/
    Makefile.am
    _GrampsConfigKeys.py
    _GrampsGconfKeys.py
    _GrampsIniKeys.py
    __init__.py
    gen_schema_keys.py
  DataViews/
    Makefile.am
    _EventView.py
    _FamilyList.py
    _MapView.py
    _MediaView.py
    _NoteView.py
    _PedigreeView.py
    _PersonView.py
    _PlaceView.py
    _RelationView.py
    _RepositoryView.py
    _SourceView.py
    __init__.py
  DateHandler/
    Makefile.am
    _DateDisplay.py
    _DateHandler.py
  DisplayModels/
  DisplayTabs/
  Editors/
  FilterEditor/
  Filters/
  GrampsDb/
  GrampsDbUtils/
  GrampsLocale/
  GrampsLogger/
  Merge/
  Mime/
  Models/
  ObjectSelector/
  PluginUtils/
  RelLib/
  ReportBase/
  Selectors/
  Simple/
  TreeViews/
  data/
  docgen/
  glade/
  images/
  plugins/
  AddMedia.py
  ArgHandler.py
  Assistant.py
  AutoComp.py
  BaseDoc.py
  Bookmarks.py
  ColumnOrder.py
  Date.py
  DateEdit.py
  DbLoader.py
  DbManager.py
  DbState.py
  DdTargets.py
  DisplayState.py
  Errors.py
  ExportAssistant.py
  ExportOptions.py
  FontScale.py
  GrampsCfg.py
  GrampsDisplay.py
  GrampsWidgets.py
  ImgManip.py
  LdsUtils.py
  ListModel.py
  Lru.py
  Makefile.am
  ManagedWindow.py
  MarkupText.py
  Navigation.py
  PageView.py
  PlaceUtils.py
  ProgressDialog.py
  QuestionDialog.py
  QuickReports.py
  RecentFiles.py
  Relationship.py
  Reorder.py
  ScratchPad.py
  Sort.py
  Spell.py
  SubstKeywords.py
  TipOfDay.py
  ToolTips.py
  TransUtils.py
  TreeTips.py
  UndoHistory.py
  Utils.py
  ViewManager.py
  accent.py
  ansel_utf8.py
  build_cmdplug
  const.py.in
  date_test.py
  gramps.py
  gramps_main.py
  soundex.py