~mmcg069/software-center/sc-janitor

« back to all changes in this revision

Viewing changes to softwarecenter/view/maintenancepane.py

  • Committer: Matthew McGowan
  • Date: 2010-09-06 07:28:58 UTC
  • Revision ID: matthew.joseph.mcgowan@gmail.com-20100906072858-tw9lqzyxtsu0dcx7
the beginings of a cellrenderenderer. broken for now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 
54
54
 
55
55
 
 
56
_pixbuf_cache = {}
 
57
 
56
58
 
57
59
# custom cell renderer to support dynamic grow
58
60
class CellRendererMaintenanceView(gtk.CellRendererText):
65
67
    OVERLAY_SIZE = 16
66
68
 
67
69
    __gproperties__ = {
68
 
        'pixbuf' :  (gtk.gdk.Pixbuf, "Pixbuf", 
69
 
                    "Application icon pixbuf image", gobject.PARAM_READWRITE),
70
 
 
71
 
        'expanded': (bool, 'IsExpanded', 'Is expanded?', False,
72
 
                    gobject.PARAM_READWRITE),
73
 
 
74
 
        'short_desc': (str, 'short_desc', 'The short description', '',
75
 
                   gobject.PARAM_READWRITE),
76
 
 
77
 
        'long_desc': (str, 'long_desc', 'The long description', '',
 
70
        #'pixbuf' :  (gtk.gdk.Pixbuf, "Pixbuf", 
 
71
                    #"Application icon pixbuf image", gobject.PARAM_READWRITE),
 
72
 
 
73
        #'expanded': (bool, 'IsExpanded', 'Is expanded?', False,
 
74
                    #gobject.PARAM_READWRITE),
 
75
 
 
76
        'markup': (str, 'short_desc', 'The short description', '',
78
77
                   gobject.PARAM_READWRITE)
 
78
 
 
79
#        'long_desc': (str, 'long_desc', 'The long description', '',
 
80
#                   gobject.PARAM_READWRITE)
79
81
        }
80
82
 
81
 
    def __init__(self):
 
83
    def __init__(self, icons):
82
84
        gtk.CellRendererText.__init__(self)
83
85
        # geometry-state values
84
86
        self.pixbuf_width = 0
85
 
        self.normal_height = 0
86
 
        self.selected_height = 0
 
87
        self.normal_height = 40
 
88
        self.selected_height = 40
87
89
 
88
90
        # attributes
 
91
        self.icons = icons
 
92
        self.fb_icon = self.icons.load_icon(MISSING_APP_ICON, 24, 0)
89
93
        self.pixbuf = None
90
 
        self.short_desc = ''
 
94
        self.markup = ''
91
95
        self.long_desc = ''
92
96
        self.expanded = False
93
97
 
108
112
        return layout.get_pixel_extents()[1][3]
109
113
 
110
114
    def _render_icon(self, window, widget, cell_area, state, xpad, ypad, direction):
 
115
        if self.markup in _pixbuf_cache:
 
116
            pixbuf = _pixbuf_cache[self.markup]
 
117
        else:
 
118
            try:
 
119
                pixbuf = self.icons.load_icon(self.markup, 24, 0)
 
120
                _pixbuf_cache[self.markup] = pixbuf
 
121
            except:
 
122
                _pixbuf_cache[self.markup] = pixbuf = self.fb_icon
 
123
 
111
124
        # calc offsets so icon is nicely centered
112
 
        xo = (self.pixbuf_width - self.pixbuf.get_width())/2
 
125
        xo = (self.pixbuf_width - pixbuf.get_width())/2
113
126
 
114
127
        if direction != gtk.TEXT_DIR_RTL:
115
128
            x = xpad+xo
116
129
        else:
117
130
            x = cell_area.width+xo-self.pixbuf_width
118
131
 
 
132
 
119
133
        # draw appicon pixbuf
120
134
        window.draw_pixbuf(None,
121
 
                           self.pixbuf,             # icon
 
135
                           pixbuf,             # icon
122
136
                           0, 0,                    # src pixbuf
123
137
                           x, cell_area.y+ypad,     # dest in window
124
138
                           -1, -1,                  # size
125
139
                           0, 0, 0)                 # dither
126
 
 
127
 
        # draw overlay if application is installed
128
 
        if self.overlay:
129
 
            if direction != gtk.TEXT_DIR_RTL:
130
 
                x = self.OFFSET_X
131
 
            else:
132
 
                x = cell_area.width - self.OVERLAY_SIZE
133
 
 
134
 
            y = cell_area.y + self.OFFSET_Y
135
 
            window.draw_pixbuf(None,
136
 
                               self._installed,     # icon
137
 
                               0, 0,                # src pixbuf
138
 
                               x, y,                # dest in window
139
 
                               -1, -1,              # size
140
 
                               0, 0, 0)             # dither
141
140
        return
142
141
 
143
 
    def _render_appsummary(self, window, widget, cell_area, state, layout, xpad, ypad, direction):
 
142
    def _render_description(self, window, widget, cell_area, state, layout, xpad, ypad, direction):
144
143
        # adjust cell_area
145
144
 
146
145
        # work out max allowable layout width
147
146
        lw = self._layout_get_pixel_width(layout)
148
147
        max_layout_width = cell_area.width - self.pixbuf_width - 3*xpad
149
148
 
150
 
        if self.isactive and self.props.action_in_progress > 0:
151
 
            action_btn = self.get_button_by_name('action0')
152
 
            if not action_btn:
153
 
                logging.warn("No action button? This doesn't make sense!")
154
 
                return
155
 
            max_layout_width -= (xpad + action_btn.allocation.width) 
156
 
 
157
149
        if lw >= max_layout_width:
158
150
            layout.set_width((max_layout_width)*pango.SCALE)
159
151
            layout.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
233
225
        else:
234
226
            state = gtk.STATE_NORMAL
235
227
 
236
 
        if not self._layout:
237
 
            self._layout = widget.get_pango_layout('')
238
 
            self._layout.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
 
228
        self._layout.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
239
229
 
240
230
        self._render_icon(window, widget,
241
231
                          cell_area, state,
242
232
                          xpad, ypad,
243
233
                          direction)
244
234
 
245
 
        self._layout.set_markup(self.short_desc)
 
235
        self._layout.set_markup(self.markup)
246
236
        self._render_description(window, widget,
247
237
                                cell_area, state,
248
238
                                self._layout,
280
270
        return
281
271
 
282
272
    def do_get_size(self, widget, cell_area):
283
 
        if not self.isactive:
284
 
            return -1, -1, -1, self.normal_height
 
273
        if not self.expanded:
 
274
            if not self._layout:
 
275
                self._layout = widget.create_pango_layout('')
 
276
            self._layout.set_markup('T\n<small>T</small>')
 
277
            h = self._layout_get_pixel_height(self._layout)
 
278
            return -1, -1, -1, h
285
279
        return -1, -1, -1, self.selected_height
286
280
 
287
281
gobject.type_register(CellRendererMaintenanceView)
425
419
 
426
420
    def _create_listview(self, treeview, filter_func):
427
421
        """Set up a column in the named TreeView."""
428
 
        # XXX 2010-03-04 barry: This is a bit of an abuse because it's
429
 
        # supposed to specify whether users are to read across the rows.  As a
430
 
        # side effect it renders the columns with alternating row colors, but
431
 
        # that's not it's primary function.
432
 
        #treeview.set_rules_hint(True)
433
 
        # Each TreeView contains two columns.  The leftmost one is a toggle
434
 
        # that when select tells c-j to act on that cruft.  Deselecting the
435
 
        # toggle ignores the package for next time.
436
 
        toggle_cr = gtk.CellRendererToggle()
437
 
        #toggle_cr.connect('toggled', self._toggled, treeview)
438
 
        toggle_cr.set_property('yalign', 0)
439
 
        toggle_col = gtk.TreeViewColumn()
440
 
        toggle_col.pack_start(toggle_cr)
441
 
        toggle_col.add_attribute(toggle_cr, 'active', ListStoreColumns.active)
442
 
        treeview.append_column(toggle_col)
443
 
        # The rightmost column contains the details of the cruft.  It will
444
 
        # always contain the cruft name and can be expanded to display cruft
445
 
        # details.  Tell the column to get its toggle's active state from the
446
 
        # model.
447
 
        name_cr = gtk.CellRendererText()
448
 
        name_cr.set_property('yalign', 0)
449
 
        name_cr.set_property('wrap-mode', pango.WRAP_WORD)
450
 
        name_col = gtk.TreeViewColumn()
451
 
        name_col.pack_start(name_cr)
452
 
        name_col.add_attribute(name_cr, 'markup', ListStoreColumns.text)
453
 
        treeview.append_column(name_col)
454
 
        #self.cruft_name_columns.add(name_col)
 
422
 
 
423
        cr = CellRendererMaintenanceView(self.icons)
 
424
        cr.set_pixbuf_width(32)
 
425
        cr.set_button_spacing(3)        
 
426
        column = gtk.TreeViewColumn("Cruft", cr,
 
427
                                    markup=ListStoreColumns.short_name)
 
428
        treeview.append_column(column)
455
429
        # The individual crufts may or may not be visible in this TreeView.
456
430
        # It's the filter function that controls this, so set that now.
457
431
        filter_store = self.store.filter_new()
458
432
        filter_store.set_visible_func(filter_func)
459
433
        treeview.set_model(filter_store)
460
 
        treeview.connect('button-press-event', self.treeview_button_press_event)
461
 
 
 
434
        #treeview.connect('button-press-event', self.treeview_button_press_event)
462
435
 
463
436
    def toggle_long_description(self, treeview):
464
437
        """Toggle the currently selected cruft's long description.
493
466
        model.set_value(iter, ListStoreColumns.text, value)
494
467
        model.set_value(iter, ListStoreColumns.expanded, not expanded)
495
468
 
496
 
 
497
469
    def treeview_button_press_event(self, treeview, event):
498
470
        """Handle mouse button press events on the TreeView ourselves.
499
471
 
659
631
        #scan_btn.set_sensitive(False)
660
632
        # Connect to the signal the server will emit when cleaning up.
661
633
        self.working = 'scanning'
 
634
        self.searching.start()
 
635
        self.store.clear()
662
636
        self.store.find_cruft()
663
 
        self.searching.start()
664
637
        #self.sort_cruft()
665
638
 
666
639
    def get_status_text(self):