~kiwinote/software-center/experimental-fastlist

« back to all changes in this revision

Viewing changes to softwarecenter/view/pkgview.py

merge from mvo

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical
2
 
#
3
 
# Authors:
4
 
#  Michael Vogt
5
 
#
6
 
# This program is free software; you can redistribute it and/or modify it under
7
 
# the terms of the GNU General Public License as published by the Free Software
8
 
# Foundation; version 3.
9
 
#
10
 
# This program is distributed in the hope that it will be useful, but WITHOUT
11
 
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
 
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13
 
# details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License along with
16
 
# this program; if not, write to the Free Software Foundation, Inc.,
17
 
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
 
 
19
 
 
20
 
import gtk
21
 
import logging
22
 
import pango
23
 
from softwarecenter.db.application import Application
24
 
 
25
 
#FIXME: These need to come from the main app
26
 
ICON_SIZE = 24
27
 
MISSING_APP_ICON = "applications-other"
28
 
 
29
 
LOG = logging.getLogger(__name__)
30
 
 
31
 
class PkgNamesView(gtk.TreeView):
32
 
    """ show a bunch of pkgnames with description """
33
 
 
34
 
    (COL_ICON,
35
 
     COL_TEXT) = range(2)
36
 
 
37
 
    def __init__(self, header, cache, pkgnames, icons, db):
38
 
        super(PkgNamesView, self).__init__()
39
 
        model = gtk.ListStore(gtk.gdk.Pixbuf, str)
40
 
        self.set_model(model)
41
 
        tp = gtk.CellRendererPixbuf()
42
 
        column = gtk.TreeViewColumn("Icon", tp, pixbuf=self.COL_ICON)
43
 
        self.append_column(column)
44
 
        tr = gtk.CellRendererText()
45
 
        tr.set_property("ellipsize", pango.ELLIPSIZE_END)
46
 
        column = gtk.TreeViewColumn(header, tr, markup=self.COL_TEXT)
47
 
        self.append_column(column)
48
 
        for pkgname in sorted(pkgnames):
49
 
            s = "%s \n<small>%s</small>" % (
50
 
                cache[pkgname].installed.summary.capitalize(), pkgname)
51
 
            
52
 
            app_details = Application("", pkgname).get_details(db)
53
 
            proposed_icon = app_details.icon
54
 
            if not proposed_icon or not icons.has_icon(proposed_icon):
55
 
                proposed_icon = MISSING_APP_ICON
56
 
            try:
57
 
                pix = icons.load_icon(proposed_icon, ICON_SIZE, ()).scale_simple(ICON_SIZE, 
58
 
                                      ICON_SIZE, gtk.gdk.INTERP_BILINEAR)
59
 
            except:
60
 
                LOG.warning("cant set icon for '%s' " % pkgname)
61
 
                pix = icons.load_icon(MISSING_APP_ICON, ICON_SIZE, ()).scale_simple(ICON_SIZE, 
62
 
                                      ICON_SIZE, gtk.gdk.INTERP_BILINEAR)
63
 
            row = model.append([pix, s])