Пример #1
0
    def __update_models(self):
        def set_sensitive(state):
            self.__hbox.set_sensitive(state)
            self.__treeview.set_sensitive(state)
            return False
        gobject.idle_add(set_sensitive, False)

        with self.__lock:
            images = set()
            releases = (blafm.get_new_releases(),
                        blafm.get_new_releases(recommended=True))
            active = blacfg.getint("general", "releases.filter")
            if releases[0]:
                self.__count_library = len(releases[0])
            if releases[1]:
                self.__count_recommended = len(releases[1])
            items = [
                (blaconst.NEW_RELEASES_FROM_LIBRARY, releases[0] or []),
                (blaconst.NEW_RELEASES_RECOMMENDED, releases[1] or [])
            ]
            current_week = datetime.date.today().isocalendar()[:2]
            for filt, releases in items:
                model = gtk.ListStore(gobject.TYPE_PYOBJECT)
                previous_week = None
                for release in releases:
                    release = BlaRelease(release)
                    week = release.calender_week
                    if previous_week != week:
                        previous_week = week
                        date = self.__cw_to_start_end_day(*week)
                        date = "%s - %s" % (date[0].strftime("%a %d %b"),
                                            date[1].strftime("%a %d %b"))
                        datestring = "\n<span size=\"larger\"><b>%s\n"
                        if week == current_week:
                            datestring %= "This week</b></span> (%s)" % date
                        else:
                            datestring %= "Week of %s</b></span>" % date
                        model.append([datestring])
                    model.append([release])
                    path = release.get_cover()
                    if path:
                        images.add(path)
                self.__models[filt] = model

            # Get rid of covers for releases that don't show up anymore.
            for image in set(blautil.discover(blaconst.RELEASES)).difference(
                images):
                try:
                    os.unlink(image)
                except OSError:
                    pass

            gobject.idle_add(set_sensitive, True)
            gobject.idle_add(self.__treeview.set_model, self.__models[active])

            if active == blaconst.NEW_RELEASES_FROM_LIBRARY:
                count = self.__count_library
            else:
                count = self.__count_recommended
            gobject.idle_add(
                self.emit, "count_changed", blaconst.VIEW_RELEASES, count)
            return True
Пример #2
0
    def __update_models(self):
        def set_sensitive(state):
            self.__hbox.set_sensitive(state)
            self.__treeview.set_sensitive(state)
            return False
        gobject.idle_add(set_sensitive, False)

        with self.__lock:
            images = set()

            active = blacfg.getint("general", "events.filter")
            limit = blacfg.getint("general", "events.limit")
            country = blacfg.getstring("general", "events.country")
            city = blacfg.getstring("general", "events.city")

            events = (blafm.get_events(limit=limit, recommended=True),
                      blafm.get_events(limit=limit, recommended=False,
                                       country=country, city=city))
            if events[0]:
                self.__count_recommended = len(events[0])
            if events[1]:
                self.__count_all = len(events[1])
            items = [
                (blaconst.EVENTS_RECOMMENDED, events[0] or []),
                (blaconst.EVENTS_ALL, events[1] or [])
            ]
            for filt, events in items:
                model = gtk.ListStore(gobject.TYPE_PYOBJECT)
                previous_date = None
                for event in events:
                    event = BlaEvent(event)
                    date = event.date
                    if previous_date != date:
                        previous_date = date
                        model.append(
                            ["\n<span size=\"larger\"><b>%s</b></span>\n" %
                             date])
                    model.append([event])
                    path = event.get_image()
                    if path:
                        images.add(path)
                self.__models[filt] = model

            # Get rid of images for events that don't show up anymore.
            for image in set(blautil.discover(blaconst.EVENTS)).difference(
                images):
                try:
                    os.unlink(image)
                except OSError:
                    pass

            gobject.idle_add(set_sensitive, True)
            # TODO: Only set the model when we verified that we successfully
            #       retrieved event information. This avoids that we delete a
            #       restored model.
            gobject.idle_add(self.__treeview.set_model, self.__models[active])

            if active == blaconst.EVENTS_RECOMMENDED:
                count = self.__count_recommended
            else:
                count = self.__count_all
            gobject.idle_add(
                self.emit, "count_changed", blaconst.VIEW_EVENTS, count)
            return True