コード例 #1
0
class TMDbList(GUIListComponent, TMDbSkinParam, object):
    def __init__(self):
        GUIListComponent.__init__(self)
        TMDbSkinParam.__init__(self)
        self.l.setBuildFunc(self.buildMovieSelectionListEntry)
        self.picloader = PicLoader()
        self.picloader.setSize(self.picSize.width(), self.picSize.height())
        self.build_update_callback = []
        self.list = []

    def destroy(self):
        self.picloader.destroy()
        GUIListComponent.destroy(self)

    def buildMovieSelectionListEntry(self, movie, movie_base=None):
        width = self.l.getItemSize().width()
        height = self.l.getItemSize().height()
        res = [None]
        try:
            for callback in self.build_update_callback:
                callback(movie)

            name = movie.Title
            if movie_base:
                name = movie_base + " - " + movie.Title

            if isinstance(movie.ReleaseDate, datetime.date):
                released = str(movie.ReleaseDate.year)
            else:
                released = str(movie.ReleaseDate)

            cover_url = movie.poster_url

            if not cover_url:
                png = self.picloader.load(getNocover())
            else:
                parts = cover_url.split("/")
                filename = os_path.join(IMAGE_TEMPFILE,
                                        str(movie.ID) + str(parts[-1]))
                print filename
                if downloadCover(cover_url, filename):
                    png = self.picloader.load(filename)
                else:
                    png = self.picloader.load(getNocover())
            res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST,
                        self.picPos.x(), self.picPos.y(), self.picSize.width(),
                        self.picSize.height(), png))
            res.append(
                (eListboxPythonMultiContent.TYPE_TEXT, self.line1Pos.x(),
                 self.line1Pos.y(), width - self.line1Pos.x(), self.f0h, 0,
                 RT_HALIGN_LEFT, name))
            res.append((eListboxPythonMultiContent.TYPE_TEXT, width - 255,
                        self.line1Pos.y(), 250, self.f0h, 0, RT_HALIGN_RIGHT,
                        released))
            res.append(
                (eListboxPythonMultiContent.TYPE_TEXT, self.line2Pos.x(),
                 self.line2Pos.y(), width - self.line2Pos.x(),
                 height - self.line2Pos.y(), 1, RT_WRAP, movie.Overview))
        except:
            from Source.Globals import printStackTrace
            printStackTrace()
        return res

    def setList(self, l):
        self.list = l
        self.l.setList(l)

    def getCurrent(self):
        return self.l.getCurrentSelection()

    def getLength(self):
        return len(self.list)
コード例 #2
0
class TMDbList(GUIComponent, object):
    def __init__(self):
        GUIComponent.__init__(self)
        self.l = eListboxPythonMultiContent()
        self.l.setBuildFunc(self.buildMovieSelectionListEntry)
        self.l.setFont(0, gFont('Regular', 20))
        self.l.setFont(1, gFont('Regular', 17))
        self.l.setItemHeight(140)
        self.picloader = PicLoader(92, 138)

    def destroy(self):
        self.picloader.destroy()
        GUIComponent.destroy(self)

    def buildMovieSelectionListEntry(self, movie):
        width = self.l.getItemSize().width()
        res = [None]
        try:
            name = movie.title
            overview = movie.overview
            released = None
            if isinstance(movie.releasedate, datetime.datetime):
                released = movie.releasedate.year
            cover_url = movie.poster_url
            if overview:
                overview = overview.encode('utf-8', 'ignore')
            else:
                overview = ''
            if released:
                released_text = released
            else:
                released_text = ''
            if not cover_url:
                png = self.picloader.load(nocover)
            else:
                parts = cover_url.split('/')
                filename = os_path.join(IMAGE_TEMPFILE,
                                        str(movie.id) + str(parts[(-1)]))
                print(filename)
                if downloadCover(cover_url, filename):
                    png = self.picloader.load(filename)
                else:
                    png = self.picloader.load(nocover)
            res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 0, 1,
                        92, 138, png))
            res.append((eListboxPythonMultiContent.TYPE_TEXT, 100, 5,
                        width - 100, 20, 0, RT_HALIGN_LEFT | RT_VALIGN_CENTER,
                        '%s' % name.encode('utf-8', 'ignore')))
            res.append(
                (eListboxPythonMultiContent.TYPE_TEXT, width - 140, 5, 130, 20,
                 1, RT_HALIGN_RIGHT | RT_VALIGN_CENTER, '%s' % released_text))
            res.append((eListboxPythonMultiContent.TYPE_TEXT, 100, 30,
                        width - 100, 100, 1, RT_WRAP, '%s' % overview))
        except:
            from Source.Globals import printStackTrace
            printStackTrace()

        return res

    GUI_WIDGET = eListbox

    def postWidgetCreate(self, instance):
        instance.setContent(self.l)

    def preWidgetRemove(self, instance):
        instance.setContent(None)
        return

    def getCurrentIndex(self):
        return self.instance.getCurrentIndex()

    def setList(self, list):
        self.list = list
        self.l.setList(list)

    def getCurrent(self):
        return self.l.getCurrentSelection()

    def getLength(self):
        return len(self.list)

    def moveUp(self):
        self.instance.moveSelection(self.instance.moveUp)

    def moveDown(self):
        self.instance.moveSelection(self.instance.moveDown)