~ubuntu-branches/ubuntu/trusty/gramps/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gui/views/treemodels/sourcemodel.py

  • Committer: Package Import Robot
  • Author(s): Ross Gammon
  • Date: 2014-02-03 17:28:04 UTC
  • mfrom: (39.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140203172804-76y7nwxiw92zhlnj
Tags: 4.0.3+dfsg-1
* New upstream release (Closes: #720858)
* To-do notes improved and made persistent (Closes: #680692)
* Applied patch to setup.py to fix resource path problem
* Applied patch to disable the optional HTML View & prevent a crash
* Remove sourceless javascript files (Closes: #736436)
* Gramps uses Bat Mitzva internally (Closes: #502532)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Gramps - a GTK+/GNOME based genealogy program
3
 
#
4
 
# Copyright (C) 2000-2006  Donald N. Allingham
5
 
#
6
 
# This program is free software; you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; either version 2 of the License, or
9
 
# (at your option) any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program; if not, write to the Free Software
18
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
#
20
 
# $Id: sourcemodel.py 18361 2011-10-23 03:13:50Z paul-franklin $
21
 
 
22
 
#-------------------------------------------------------------------------
23
 
#
24
 
# python modules
25
 
#
26
 
#-------------------------------------------------------------------------
27
 
import logging
28
 
log = logging.getLogger(".")
29
 
 
30
 
#-------------------------------------------------------------------------
31
 
#
32
 
# GNOME/GTK modules
33
 
#
34
 
#-------------------------------------------------------------------------
35
 
import gtk
36
 
 
37
 
#-------------------------------------------------------------------------
38
 
#
39
 
# GRAMPS modules
40
 
#
41
 
#-------------------------------------------------------------------------
42
 
import const
43
 
import ToolTips
44
 
import Utils
45
 
from gui.views.treemodels.flatbasemodel import FlatBaseModel
46
 
 
47
 
#-------------------------------------------------------------------------
48
 
#
49
 
# SourceModel
50
 
#
51
 
#-------------------------------------------------------------------------
52
 
class SourceModel(FlatBaseModel):
53
 
 
54
 
    def __init__(self,db,scol=0, order=gtk.SORT_ASCENDING,search=None,
55
 
                 skip=set(), sort_map=None):
56
 
        self.map = db.get_raw_source_data
57
 
        self.gen_cursor = db.get_source_cursor
58
 
        self.fmap = [
59
 
            self.column_title,
60
 
            self.column_id,
61
 
            self.column_author,
62
 
            self.column_abbrev,
63
 
            self.column_pubinfo,
64
 
            self.column_change,
65
 
            self.column_handle,
66
 
            self.column_tooltip
67
 
            ]
68
 
        self.smap = [
69
 
            self.column_title,
70
 
            self.column_id,
71
 
            self.column_author,
72
 
            self.column_abbrev,
73
 
            self.column_pubinfo,
74
 
            self.sort_change,
75
 
            ]
76
 
        FlatBaseModel.__init__(self,db,scol, order,tooltip_column=7,search=search,
77
 
                           skip=skip, sort_map=sort_map)
78
 
 
79
 
    def destroy(self):
80
 
        """
81
 
        Unset all elements that can prevent garbage collection
82
 
        """
83
 
        self.db = None
84
 
        self.gen_cursor = None
85
 
        self.map = None
86
 
        self.fmap = None
87
 
        self.smap = None
88
 
        FlatBaseModel.destroy(self)
89
 
 
90
 
    def on_get_n_columns(self):
91
 
        return len(self.fmap)+1
92
 
 
93
 
    def column_title(self,data):
94
 
        return unicode(data[2])
95
 
 
96
 
    def column_handle(self,data):
97
 
        return unicode(data[0])
98
 
 
99
 
    def column_author(self,data):
100
 
        return unicode(data[3])
101
 
 
102
 
    def column_abbrev(self,data):
103
 
        return unicode(data[7])
104
 
 
105
 
    def column_id(self,data):
106
 
        return unicode(data[1])
107
 
 
108
 
    def column_pubinfo(self,data):
109
 
        return unicode(data[4])
110
 
 
111
 
    def column_change(self,data):
112
 
        return Utils.format_time(data[8])
113
 
    
114
 
    def sort_change(self,data):
115
 
        return "%012x" % data[8]
116
 
 
117
 
    def column_tooltip(self,data):
118
 
        if const.USE_TIPS:
119
 
            try:
120
 
                t = ToolTips.TipFromFunction(self.db, lambda:
121
 
                                             self.db.get_source_from_handle(data[0]))
122
 
            except:
123
 
                log.error("Failed to create tooltip.",exc_info=True)
124
 
            return t
125
 
        else:
126
 
            return u''