Beispiel #1
0
    def _actual_search(self, needle, start, end, step, cb):
        playlist = self.playlist
        xc = self.xc

        search_fields = get_config("search_fields")

        cur = start
        first = True

        # TODO: this loop is ugly
        while True:
            # the end?
            if cur == start and not first:
                # we cycled through
                cb(False)
                return

            # not the first anymore?
            first = False

            # check the playlist item
            item = playlist[cur]
            meta = item.meta

            if meta != None:
                # let's compare
                for key in search_fields:
                    if key in meta:
                        value = meta[key]

                        if isinstance(value, basestring) and needle.search(value):
                            # found one
                            self._focus = cur
                            self.modified()

                            update()

                            cb(True)
                            return
            else:
                # we have to request the meta information
                def request_cb(meta):
                    self._actual_search(needle, cur, end, step, cb)

                item.request(xc, request_cb)

                # prefetch next items
                pre = cur
                for i in range(self.PRE_CACHING):
                    pre = step(pre)

                    if pre != None:
                        playlist[pre].request(xc, None)
                    else:
                        break

                # the callback of the request will continue our work
                return

            cur = step(cur)
Beispiel #2
0
    def init_commands(self):
        self.hotkeys = hotkeys = {}

        for part, mappings in get_config('hotkeys').items():
            hotkeys[part] = part_keys = {}
            for command, bindings in mappings.items():
                for binding in bindings:
                    part_keys[binding] = command