当前位置: 首页>>代码示例>>Python>>正文


Python Fetcher.stop方法代码示例

本文整理汇总了Python中fetcher.Fetcher.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Fetcher.stop方法的具体用法?Python Fetcher.stop怎么用?Python Fetcher.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fetcher.Fetcher的用法示例。


在下文中一共展示了Fetcher.stop方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RadiosWindow

# 需要导入模块: from fetcher import Fetcher [as 别名]
# 或者: from fetcher.Fetcher import stop [as 别名]
class RadiosWindow(hildon.StackableWindow):
    def __init__(self):
        hildon.StackableWindow.__init__(self)
        self.fetcher = None
        self.radios = {}

        self.set_title("Radios")
        self.connect('destroy', self.on_destroy)

        # Results list
        self.panarea = hildon.PannableArea()
        self.radiolist = RadioList()
        self.radiolist.connect('row-activated', self.row_activated)
        self.panarea.add(self.radiolist)
        self.add(self.panarea)

        self.start_radio_fetcher()

    def on_destroy(self, wnd):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None

    def row_activated(self, treeview, path, view_column):
        name, _id = self.radiolist.get_radio_id(path)
        wnd = open_playerwindow()
        wnd.play_radio(name, _id)

    def start_radio_fetcher(self):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None
        self.fetcher = Fetcher(jamaendo.starred_radios, self,
                               on_item = self.on_radio_result,
                               on_ok = self.on_radio_complete,
                               on_fail = self.on_radio_complete)
        self.fetcher.start()

    def on_radio_result(self, wnd, item):
        if wnd is self:
            self.radios[item.ID] = item
            self.radiolist.add_radios([item])

    def on_radio_complete(self, wnd, error=None):
        if wnd is self:
            self.fetcher.stop()
            self.fetcher = None
开发者ID:krig,项目名称:jamaendo,代码行数:49,代码来源:radios.py

示例2: FeaturedWindow

# 需要导入模块: from fetcher import Fetcher [as 别名]
# 或者: from fetcher.Fetcher import stop [as 别名]
class FeaturedWindow(hildon.StackableWindow):
    features = (
        ("New releases",jamaendo.new_releases),
        ("Top albums today", lambda: jamaendo.top_albums(order='ratingday_desc')),
        ("Top tracks today", lambda: jamaendo.top_tracks(order='ratingday_desc')),
        ("Albums of the week",jamaendo.albums_of_the_week),
        ("Tracks of the week",jamaendo.tracks_of_the_week),
        ("Top 50 tags", lambda: jamaendo.top_tags(count=50)),
        ("Top 50 artists", lambda: jamaendo.top_artists(count=50)),
        ("Top 50 albums", lambda: jamaendo.top_albums(count=50)),
        ("Top 50 tracks", lambda: jamaendo.top_tracks(count=50)),
        )

    def __init__(self, feature):
        hildon.StackableWindow.__init__(self)
        self.set_title(feature)

        self.fetcher = None
        self.connect('destroy', self.on_destroy)
        self.featurefn = _alist(self.features, feature)

        # Results list
        self.panarea = hildon.PannableArea()
        self.musiclist = MusicList()
        self.musiclist.connect('row-activated', self.row_activated)
        self.panarea.add(self.musiclist)

        self.idmap = {}
        self.items = []

        self.add(self.panarea)

        self.create_menu()

        self.start_feature_fetcher()

    def start_feature_fetcher(self):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None
        self.fetcher = Fetcher(self.featurefn, self,
                               on_item = self.on_feature_result,
                               on_ok = self.on_feature_complete,
                               on_fail = self.on_feature_complete)
        self.fetcher.start()

    def on_feature_result(self, wnd, item):
        if wnd is self:
            self.musiclist.add_items([item])
            self.idmap[item.ID] = item
            self.items.append(item)

    def on_feature_complete(self, wnd, error=None):
        if wnd is self:
            if error:
                banner = hildon.hildon_banner_show_information(self, '', "Unable to get list")
                banner.set_timeout(2000)
            self.fetcher.stop()
            self.fetcher = None

    def create_menu(self):
        def on_player(*args):
            from playerwindow import open_playerwindow
            open_playerwindow()
        self.menu = hildon.AppMenu()
        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
        player.set_label("Open player")
        player.connect("clicked", on_player)
        self.menu.append(player)
        self.menu.show_all()
        self.set_app_menu(self.menu)

    def on_destroy(self, wnd):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None

    def row_activated(self, treeview, path, view_column):
        _id = self.musiclist.get_item_id(path)
        item = self.idmap[_id]
        self.open_item(item)

    def open_item(self, item):
        if isinstance(item, jamaendo.Album):
            wnd = ShowAlbum(item)
            wnd.show_all()
        elif isinstance(item, jamaendo.Artist):
            wnd = ShowArtist(item)
            wnd.show_all()
        elif isinstance(item, jamaendo.Track):
            playlist = Playlist(self.items)
            playlist.jump_to(item.ID)
            wnd = open_playerwindow()
            wnd.play_tracks(playlist)
        elif isinstance(item, jamaendo.Tag):
            self.start_tag_fetcher(item.ID)

    def start_tag_fetcher(self, item_id):
        if self.fetcher:
            self.fetcher.stop()
#.........这里部分代码省略.........
开发者ID:krig,项目名称:jamaendo,代码行数:103,代码来源:featured.py

示例3: SearchWindow

# 需要导入模块: from fetcher import Fetcher [as 别名]
# 或者: from fetcher.Fetcher import stop [as 别名]
class SearchWindow(hildon.StackableWindow):
    def __init__(self):
        hildon.StackableWindow.__init__(self)
        self.set_title("Search")
        self.idmap = {}

        vbox = gtk.VBox(False, 0)

        self.fetcher = None
        self.connect('destroy', self.on_destroy)

        # Results list
        self.panarea = hildon.PannableArea()
        self.musiclist = MusicList()
        self.musiclist.loading_message = "Nothing found yet"
        self.musiclist.empty_message = "No matching results"
        self.musiclist.connect('row-activated', self.row_activated)
        self.panarea.add(self.musiclist)
        vbox.pack_start(self.panarea, True, True, 0)


        # Create selector for search mode
        self.mode_selector = hildon.TouchSelector(text=True)

        self.mode_selector.append_text("Artists")
        self.mode_selector.append_text("Albums")
        self.mode_selector.append_text("Tracks")
        self.mode = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT,
                                        hildon.BUTTON_ARRANGEMENT_VERTICAL)
        self.mode.set_title("Search for")
        self.mode.set_selector(self.mode_selector)
        self.mode_selector.connect("changed", self.mode_changed)
        #vbox.pack_start(self.mode, False)
        self.mode.set_active(1)


        # Search box
        hbox = gtk.HBox(False, 0)
        self.entry = hildon.Entry(gtk.HILDON_SIZE_FINGER_HEIGHT)
        self.entry.set_placeholder("Search")
        self.entry.connect('activate', self.on_search)
        btn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
        btn.set_label(">>")
        btn.connect('clicked', self.on_search)
        hbox.pack_start(self.mode, False)
        hbox.pack_start(self.entry, True, True, 0)
        hbox.pack_start(btn, False)
        vbox.pack_start(hbox, False)
        self.add(vbox)

        self.create_menu()

    def create_menu(self):
        def on_player(*args):
            from playerwindow import open_playerwindow
            open_playerwindow()
        self.menu = hildon.AppMenu()
        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
        player.set_label("Open player")
        player.connect("clicked", on_player)
        self.menu.append(player)
        self.menu.show_all()
        self.set_app_menu(self.menu)

    def on_destroy(self, wnd):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None

    def mode_changed(self, selector, user_data):
        pass
        #current_selection = selector.get_current_text()

    def on_search(self, w):
        mode = self.mode.get_active()
        txt = self.entry.get_text()
        self.musiclist.set_loading(False)
        self.musiclist.empty_message = "Searching..."
        self.musiclist.get_model().clear()

        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None

        itemgen = None
        if mode == 0:
            itemgen = lambda: jamaendo.search_artists(query=txt)
        elif mode == 1:
            itemgen = lambda: jamaendo.search_albums(query=txt)
        elif mode == 2:
            itemgen = lambda: jamaendo.search_tracks(query=txt)
        else:
            return

        self.fetcher = Fetcher(itemgen, self,
                               on_item = self.on_add_result,
                               on_ok = self.on_add_complete,
                               on_fail = self.on_add_complete)
        self.fetcher.start()
        '''
#.........这里部分代码省略.........
开发者ID:krig,项目名称:jamaendo,代码行数:103,代码来源:search.py

示例4: Player

# 需要导入模块: from fetcher import Fetcher [as 别名]
# 或者: from fetcher.Fetcher import stop [as 别名]
class Player(object):
    def __init__(self):
        self.backend = PlayerBackend()
        self.backend.set_eos_callback(self._on_eos)
        self.playlist = Playlist()
        self.fetcher = None # for refilling the radio

    def get_position_duration(self):
        return self.backend.get_position_duration()

    def _play_track(self, track, notify='play'):
        self.backend.play_url('mp3', track.mp3_url())
        log.debug("playing %s", track)
        postoffice.notify(notify, track)

    def _refill_radio(self):
        log.debug("Refilling radio %s", self.playlist)
        #self.playlist.add(jamaendo.get_radio_tracks(self.playlist.radio_id))
        self._start_radio_fetcher()

    def _start_radio_fetcher(self):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None
        self.fetcher = Fetcher(lambda: jamaendo.get_radio_tracks(self.playlist.radio_id),
                               self,
                               on_item = self._on_radio_result,
                               on_ok = self._on_radio_complete,
                               on_fail = self._on_radio_complete)
        self.fetcher.has_no_results = True
        self.fetcher.start()

    def _on_radio_result(self, wnd, item):
        if wnd is self:
            self.playlist.add(item)
            if not self.playing():
                if self.fetcher.has_no_results:
                    self.fetcher.has_no_results = False
                    entry = self.playlist.next()
                    self._play_track(entry)

    def _on_radio_complete(self, wnd, error=None):
        if wnd is self:
            if error:
                self.stop()
            self.fetcher.stop()
            self.fetcher = None

    def play(self, playlist = None):
        if playlist:
            self.playlist = playlist
        elif self.playlist is None:
            self.playlist = Playlist()

        if self.playlist.current():
            entry = self.playlist.current()
            self._play_track(entry)
        elif self.playlist.has_next():
            entry = self.playlist.next()
            self._play_track(entry)
        elif self.playlist.radio_mode:
            self._refill_radio()
            #self.play()

    def next(self):
        if self.playlist.has_next():
            self.backend.stop(reset=False)
            entry = self.playlist.next()
            self._play_track(entry, notify='next')
        elif self.playlist.radio_mode:
            self._refill_radio()
        else:
            self.stop()

    def prev(self):
        if self.playlist.has_prev():
            self.backend.stop(reset=False)
            entry = self.playlist.prev()
            self._play_track(entry, 'prev')

    def pause(self):
        self.backend.pause()
        postoffice.notify('pause', self.playlist.current())

    def stop(self):
        self.backend.stop()
        postoffice.notify('stop', self.playlist.current())

    def playing(self):
        return self.backend.playing()

    def seek(self, nanoseconds=None, percent=None):
        self.backend.seek(nanoseconds=nanoseconds, percent=percent)

    def _on_eos(self):
        self.next()
开发者ID:krig,项目名称:jamaendo,代码行数:98,代码来源:player.py

示例5: FavoritesWindow

# 需要导入模块: from fetcher import Fetcher [as 别名]
# 或者: from fetcher.Fetcher import stop [as 别名]
class FavoritesWindow(hildon.StackableWindow):
    def __init__(self):
        hildon.StackableWindow.__init__(self)
        self.set_title("Favorites")
        self.connect('destroy', self.on_destroy)
        self.fetcher = None
        self.idmap = {}

        self.panarea = hildon.PannableArea()
        self.favorites = MusicList()
        self.favorites.connect('row-activated', self.row_activated)
        self.panarea.add(self.favorites)
        self.add(self.panarea)

        if not settings.user:
            self.favorites.loading_message = """give your username
to the settings dialog
favorites appear
"""
        else:
            self.favorites.loading_message = """Loading favorites"""

        self.start_favorites_fetcher()

    def on_destroy(self, wnd):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None

    def start_favorites_fetcher(self):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None

        def gen():
            generated = []
            for item in jamaendo.favorite_albums(settings.user):
                generated.append(item.ID)
                yield item
            fav = [f[1] for f in settings.favorites \
                       if isinstance(f, tuple) and \
                       len(f) == 2 and \
                       f[0] == 'album' and \
                       f[1] not in generated]
            for item in jamaendo.get_albums(fav):
                yield item

        self.fetcher = Fetcher(gen,
                               self,
                               on_item = self.on_favorites_result,
                               on_ok = self.on_favorites_complete,
                               on_fail = self.on_favorites_complete)
        self.fetcher.start()

    def on_favorites_result(self, wnd, item):
        if wnd is self:
            if item.ID not in self.idmap:
                self.idmap[item.ID] = item
                self.favorites.add_items([item])

    def on_favorites_complete(self, wnd, error=None):
        if wnd is self:
            self.fetcher.stop()
            self.fetcher = None

    def get_item_text(self, item):
        if isinstance(item, jamaendo.Album):
            return "%s - %s" % (item.artist_name, item.name)
        elif isinstance(item, jamaendo.Track):
            return "%s - %s" % (item.artist_name, item.name)
        else:
            return item.name

    def row_activated(self, treeview, path, view_column):
        _id = self.favorites.get_item_id(path)
        item = self.idmap.get(_id)
        if item:
            self.open_item(item)

    def open_item(self, item):
        if isinstance(item, jamaendo.Album):
            wnd = ShowAlbum(item)
            wnd.show_all()
        elif isinstance(item, jamaendo.Artist):
            wnd = ShowArtist(item)
            wnd.show_all()
        elif isinstance(item, jamaendo.Track):
            wnd = open_playerwindow()
            wnd.play_tracks([item])
开发者ID:krig,项目名称:jamaendo,代码行数:91,代码来源:favorites.py

示例6: ShowPlaylist

# 需要导入模块: from fetcher import Fetcher [as 别名]
# 或者: from fetcher.Fetcher import stop [as 别名]
class ShowPlaylist(hildon.StackableWindow):
    def __init__(self, plname, playlist):
        hildon.StackableWindow.__init__(self)
        self.set_title(plname)
        self.playlist_name = plname
        self.playlist = playlist
        self.fetcher = None

        self.connect('destroy', self.on_destroy)

        top_hbox = gtk.HBox()
        vbox1 = gtk.VBox()
        self.cover = gtk.Image()
        tmp = util.find_resource('album.png')
        if tmp:
            self.cover.set_from_file(tmp)

        vbox2 = gtk.VBox()
        self.trackarea = hildon.PannableArea()
        self.tracks = TrackList(numbers=True)
        self.tracks.connect('row-activated', self.row_activated)
        self.tracklist = []

        top_hbox.pack_start(vbox1, False)
        top_hbox.pack_start(vbox2, True)
        vbox1.pack_start(self.cover, True)
        vbox2.pack_start(self.trackarea, True)
        self.trackarea.add(self.tracks)

        self.add(top_hbox)

        postoffice.connect('album-cover', self, self.on_album_cover)
        if len(self.playlist) > 0:
            postoffice.notify('request-album-cover', int(self.playlist[0].album_id), 300)

        self.create_menu()
        self.start_track_fetcher()

    def create_menu(self):
        def on_player(*args):
            from playerwindow import open_playerwindow
            open_playerwindow()
        self.menu = hildon.AppMenu()
        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
        player.set_label("Open player")
        player.connect("clicked", on_player)
        self.menu.append(player)
        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
        player.set_label("Delete playlist")
        player.connect("clicked", self.on_delete_pl)
        self.menu.append(player)
        self.menu.show_all()
        self.set_app_menu(self.menu)

    def on_destroy(self, wnd):
        postoffice.disconnect('album-cover', self)
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None

    def start_track_fetcher(self):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None
        self.fetcher = Fetcher(lambda: self.playlist, self,
                               on_item = self.on_track_result,
                               on_ok = self.on_track_complete,
                               on_fail = self.on_track_complete)
        self.fetcher.start()

    def on_track_result(self, wnd, item):
        if wnd is self:
            self.tracklist.append(item)
            self.tracks.add_track(item)

    def on_track_complete(self, wnd, error=None):
        if wnd is self:
            self.fetcher.stop()
            self.fetcher = None

    def on_delete_pl(self, btn):
        note = hildon.hildon_note_new_confirmation(self, "Do you want to delete '%s' ?" % (self.playlist_name))
        response = note.run()
        note.destroy()
        print response
        if response == gtk.RESPONSE_OK:
            settings.delete_playlist(self.playlist_name)
            settings.save()
            self.destroy()

    def on_album_cover(self, albumid, size, cover):
        if size == 300:
            self.cover.set_from_file(cover)

    def on_play(self, btn):
        self.open_item(self.album)

    def row_activated(self, treeview, path, view_column):
        # TODO: wait for all tracks to load
        _id = self.tracks.get_track_id(path)
#.........这里部分代码省略.........
开发者ID:krig,项目名称:jamaendo,代码行数:103,代码来源:showplaylist.py

示例7: ShowAlbum

# 需要导入模块: from fetcher import Fetcher [as 别名]
# 或者: from fetcher.Fetcher import stop [as 别名]
class ShowAlbum(hildon.StackableWindow):
    def __init__(self, album):
        hildon.StackableWindow.__init__(self)
        self.set_title(album.artist_name)
        self.album = album
        self.fetcher = None

        self.connect("destroy", self.on_destroy)

        top_hbox = gtk.HBox()
        vbox1 = gtk.VBox()
        self.cover = gtk.Image()
        tmp = util.find_resource("album.png")
        if tmp:
            self.cover.set_from_file(tmp)
        self.bbox = gtk.HButtonBox()
        self.bbox.set_property("layout-style", gtk.BUTTONBOX_SPREAD)
        self.goto_artist = self.make_imagebutton("artist", self.on_goto_artist)
        self.download = self.make_imagebutton("download", self.on_download)
        self.favorite = self.make_imagebutton("favorite", self.on_favorite)
        self.license = self.make_imagebutton("license", self.on_license)

        vbox2 = gtk.VBox()
        self.albumname = gtk.Label()
        self.albumname.set_markup("<big>%s</big>" % (cgi.escape(album.name)))
        self.trackarea = hildon.PannableArea()

        self.tracks = TrackList(numbers=True)
        self.tracks.connect("row-activated", self.row_activated)

        self.tracklist = []
        # self.tracklist = jamaendo.get_tracks(album.ID)
        # for track in self.tracklist:
        # self.tracks.add_track(track)

        top_hbox.pack_start(vbox1, False)
        top_hbox.pack_start(vbox2, True)
        vbox1.pack_start(self.cover, True)
        vbox1.pack_start(self.bbox, False)
        self.bbox.add(self.goto_artist)
        self.bbox.add(self.download)
        self.bbox.add(self.favorite)
        self.bbox.add(self.license)
        vbox2.pack_start(self.albumname, False)
        vbox2.pack_start(self.trackarea, True)
        self.trackarea.add(self.tracks)

        self.add(top_hbox)

        postoffice.connect("album-cover", self, self.on_album_cover)
        postoffice.notify("request-album-cover", self.album.ID, 300)

        self.create_menu()
        self.start_track_fetcher()

    def create_menu(self):
        def on_player(*args):
            from playerwindow import open_playerwindow

            open_playerwindow()

        self.menu = hildon.AppMenu()
        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
        player.set_label("Open player")
        player.connect("clicked", on_player)
        self.menu.append(player)
        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
        player.set_label("Add to playlist")
        player.connect("clicked", self.on_add_to_playlist)
        self.menu.append(player)
        self.menu.show_all()
        self.set_app_menu(self.menu)

    def on_destroy(self, wnd):
        postoffice.disconnect("album-cover", self)
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None

    def start_track_fetcher(self):
        if self.fetcher:
            self.fetcher.stop()
            self.fetcher = None
        self.fetcher = Fetcher(
            lambda: jamaendo.get_tracks(self.album.ID),
            self,
            on_item=self.on_track_result,
            on_ok=self.on_track_complete,
            on_fail=self.on_track_complete,
        )
        self.fetcher.start()

    def on_track_result(self, wnd, item):
        if wnd is self:
            self.tracklist.append(item)
            self.tracks.add_track(item)

    def on_track_complete(self, wnd, error=None):
        if wnd is self:
            self.fetcher.stop()
#.........这里部分代码省略.........
开发者ID:krig,项目名称:jamaendo,代码行数:103,代码来源:showalbum.py


注:本文中的fetcher.Fetcher.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。