~mmcg069/software-center/bug635994-again

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk/catview_gtk.py

  • Committer: Michael Vogt
  • Date: 2011-07-21 15:28:53 UTC
  • Revision ID: michael.vogt@ubuntu.com-20110721152853-isdwy3wd800y9xd1
add top rated carousel

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
        # sections
175
175
        self.featured_carousel = None
176
176
        self.whatsnew_carousel = None
 
177
        self.toprated_carousel = None
177
178
        self.departments = None
178
179
 
179
180
        # this means that the departments don't jump down once the cache loads
243
244
            cr.stroke()
244
245
            cr.restore()
245
246
 
 
247
        # toprated carousel
 
248
        # draw the info vbox bg
 
249
        if self.toprated_carousel:
 
250
            a = self.toprated_carousel.allocation
 
251
            rounded_rect(cr, a.x, a.y, a.width, a.height, 5)
 
252
            cr.set_source_rgba(*color_floats("#F7F7F7")+(0.75,))
 
253
            cr.fill()
 
254
 
 
255
            # draw the info header bg
 
256
            a = self.toprated_carousel.header.allocation
 
257
            rounded_rect2(cr, a.x, a.y, a.width, a.height, (5, 5, 0, 0))
 
258
            cr.set_source_rgb(*color_floats("#DAD7D3"))
 
259
            cr.fill()
 
260
 
 
261
            a = self.toprated_carousel.allocation
 
262
            cr.save()
 
263
            rounded_rect(cr, a.x+0.5, a.y+0.5, a.width-1, a.height-1, 5)
 
264
            cr.set_source_rgba(*color_floats("#DAD7D3")+(0.3,))
 
265
            cr.set_line_width(1)
 
266
            cr.stroke()
 
267
            cr.restore()
 
268
 
246
269
        if self.featured_carousel:
247
270
            self.featured_carousel.draw(cr, self.featured_carousel.allocation, event.area)
248
271
        if self.whatsnew_carousel:
249
272
            self.whatsnew_carousel.draw(cr, self.whatsnew_carousel.allocation, event.area)
 
273
        if self.toprated_carousel:
 
274
            self.toprated_carousel.draw(cr, self.toprated_carousel.allocation, event.area)
250
275
            
251
276
        self.show_all()
252
277
        self.start_carousels()
268
293
        if self.whatsnew_carousel:
269
294
            for poster in self.whatsnew_carousel.posters:
270
295
                self._poster_sigs.append(poster.connect('clicked', self._on_app_clicked))
 
296
        if self.toprated_carousel:
 
297
            for poster in self.toprated_carousel.posters:
 
298
                self._poster_sigs.append(poster.connect('clicked', self._on_app_clicked))
271
299
 
272
300
#        print self._poster_sigs
273
301
        return
276
304
        # these methods add sections to the page
277
305
        # changing order of methods changes order that they appear in the page
278
306
        self._append_departments()
 
307
        self._append_toprated()
279
308
        self._append_featured()
280
309
        self._append_whatsnew()
 
310
 
281
311
        self._append_recommendations()
282
312
        return
283
313
 
345
375
        return True # mutter..
346
376
 
347
377
    @wait_for_apt_cache_ready # be consistent with new apps
 
378
    def _append_toprated(self):
 
379
 
 
380
        # add some filler...
 
381
        padding = gtk.VBox()
 
382
        padding.set_size_request(-1, 6)
 
383
        self.vbox.pack_start(padding, False)
 
384
 
 
385
        toprated_cat = get_category_by_name(self.categories,
 
386
                                            'Top Rated')    # untranslated name
 
387
 
 
388
        # the spec says the carousel icons should be 4em
 
389
        # however, by not using a stock icon size, icons sometimes dont
 
390
        # look to great.
 
391
        if toprated_cat:
 
392
            # so based on the value of 4*em we try to choose a sane stock
 
393
            # icon size
 
394
            best_stock_size = 64#mkit.get_nearest_stock_size(64)
 
395
            toprated_apps = AppStore(self.cache,
 
396
                                     self.db, 
 
397
                                     self.icons,
 
398
                                     toprated_cat.query,
 
399
                                     toprated_cat.item_limit,
 
400
                                     toprated_cat.sortmode,
 
401
                                     filter=self.apps_filter,
 
402
                                     icon_size=best_stock_size,
 
403
                                     global_icon_cache=False,
 
404
                                     nonapps_visible=AppStore.NONAPPS_ALWAYS_VISIBLE,
 
405
                                     nonblocking_load=False)
 
406
 
 
407
            self.toprated_carousel = CarouselView(self,
 
408
                                                  toprated_apps,
 
409
                                                  _('Top Rated'),
 
410
                                                  self.icons)
 
411
 
 
412
            self.toprated_carousel.more_btn.connect('clicked',
 
413
                                                    self._on_category_clicked,
 
414
                                                    toprated_cat)
 
415
            # pack featured carousel into hbox
 
416
            self.vbox.pack_start(self.toprated_carousel, False)
 
417
        return
 
418
 
 
419
    @wait_for_apt_cache_ready # be consistent with new apps
348
420
    def _append_featured(self):
349
421
 
350
422
        # add some filler...
418
490
            self.whatsnew_carousel.more_btn.connect('clicked',
419
491
                                                    self._on_category_clicked,
420
492
                                                    new_cat)
 
493
 
421
494
            # pack whatsnew carousel into hbox
422
495
            self.vbox.pack_start(self.whatsnew_carousel, False)
423
496
        return
461
534
            self.featured_carousel.start()
462
535
        if self.whatsnew_carousel:
463
536
            self.whatsnew_carousel.start(offset=5000)
 
537
        if self.toprated_carousel:
 
538
            self.toprated_carousel.start(offset=10000)
464
539
        return
465
540
 
466
541
    def stop_carousels(self):
468
543
            self.featured_carousel.stop()
469
544
        if self.whatsnew_carousel:
470
545
            self.whatsnew_carousel.stop()
 
546
        if self.toprated_carousel:
 
547
            self.toprated_carousel.stop()
471
548
        return
472
549
 
473
550
    def build(self, desktopdir):