本文整理匯總了Python中quodlibet.browsers.playlists.PlaylistsBrowser._rename方法的典型用法代碼示例。如果您正苦於以下問題:Python PlaylistsBrowser._rename方法的具體用法?Python PlaylistsBrowser._rename怎麽用?Python PlaylistsBrowser._rename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類quodlibet.browsers.playlists.PlaylistsBrowser
的用法示例。
在下文中一共展示了PlaylistsBrowser._rename方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TPlaylistsBrowser
# 需要導入模塊: from quodlibet.browsers.playlists import PlaylistsBrowser [as 別名]
# 或者: from quodlibet.browsers.playlists.PlaylistsBrowser import _rename [as 別名]
class TPlaylistsBrowser(TSearchBar):
Bar = PlaylistsBrowser
ANOTHER_SONG = AudioFile({
"title": "lonely",
"artist": "new artist",
"~filename": dummy_path(u"/dev/urandom")})
def setUp(self):
# Testing locally is VERY dangerous without this...
self.assertTrue(_TEMP_DIR in PLAYLISTS or os.name == "nt",
msg="Failing, don't want to delete %s" % PLAYLISTS)
try:
shutil.rmtree(PLAYLISTS)
except OSError:
pass
mkdir(PLAYLISTS)
self.lib = quodlibet.browsers.playlists.library = SongLibrary()
self.lib.librarian = SongLibrarian()
all_songs = SONGS + [self.ANOTHER_SONG]
for af in all_songs:
af.sanitize()
self.lib.add(all_songs)
self.big = pl = FileBackedPlaylist.new(PLAYLISTS, "Big", self.lib)
pl.extend(SONGS)
pl.write()
self.small = pl = FileBackedPlaylist.new(PLAYLISTS, "Small", self.lib)
pl.extend([self.ANOTHER_SONG])
pl.write()
PlaylistsBrowser.init(self.lib)
self.bar = PlaylistsBrowser(self.lib)
self.bar.connect('songs-selected', self._expected)
self.bar._select_playlist(self.bar.playlists()[0])
self.expected = None
def tearDown(self):
self.bar.destroy()
self.lib.destroy()
shutil.rmtree(PLAYLISTS)
PlaylistsBrowser.deinit(self.lib)
def test_saverestore(self):
# Flush previous signals, etc. Hmm.
self.expected = None
self._do()
self.expected = [SONGS[0]]
self.bar.filter_text("title = %s" % SONGS[0]["title"])
self.bar._select_playlist(self.bar.playlists()[0])
self.expected = [SONGS[0]]
self._do()
self.bar.save()
self.bar.filter_text("")
self.expected = list(sorted(SONGS))
self._do()
self.bar.restore()
self.bar.activate()
self.expected = [SONGS[0]]
self._do()
def test_active_filter_playlists(self):
self.bar._select_playlist(self.bar.playlists()[1])
# Second playlist should not have any of `SONGS`
self.assertFalse(self.bar.active_filter(SONGS[0]))
# But it should have `ANOTHER_SONG`
self.assertTrue(self.bar.active_filter(self.ANOTHER_SONG),
msg="Couldn't find song from second playlist")
# ... and setting a reasonable filter on that song should match still
self.bar.filter_text("lonely")
self.assertTrue(self.bar.active_filter(self.ANOTHER_SONG),
msg="Couldn't find song from second playlist with "
"filter of 'lonely'")
# ...unless it doesn't match that song
self.bar.filter_text("piman")
self.assertFalse(self.bar.active_filter(self.ANOTHER_SONG),
msg="Shouldn't have matched 'piman' on second list")
def test_rename(self):
self.assertEquals(self.bar.playlists()[1], self.small)
self.bar._rename(0, "zBig")
self.assertEquals(self.bar.playlists()[0], self.small)
self.assertEquals(self.bar.playlists()[1].name, "zBig")
def test_default_display_pattern(self):
pattern_text = self.bar.display_pattern_text
self.failUnlessEqual(pattern_text, DEFAULT_PATTERN_TEXT)
self.failUnless("<~name>" in pattern_text)
示例2: TPlaylistsBrowser
# 需要導入模塊: from quodlibet.browsers.playlists import PlaylistsBrowser [as 別名]
# 或者: from quodlibet.browsers.playlists.PlaylistsBrowser import _rename [as 別名]
#.........這裏部分代碼省略.........
self._do()
self.expected = [SONGS[0]]
self.bar.filter_text("title = %s" % SONGS[0]["title"])
self.bar._select_playlist(self.bar.playlists()[0])
self.expected = [SONGS[0]]
self._do()
self.bar.save()
self.bar.filter_text("")
self.expected = list(sorted(SONGS))
self._do()
self.bar.restore()
self.bar.activate()
self.expected = [SONGS[0]]
self._do()
def test_active_filter_playlists(self):
self.bar._select_playlist(self.bar.playlists()[1])
# Second playlist should not have any of `SONGS`
self.assertFalse(self.bar.active_filter(SONGS[0]))
# But it should have `ANOTHER_SONG`
self.assertTrue(self.bar.active_filter(self.ANOTHER_SONG),
msg="Couldn't find song from second playlist")
# ... and setting a reasonable filter on that song should match still
self.bar.filter_text("lonely")
self.assertTrue(self.bar.active_filter(self.ANOTHER_SONG),
msg="Couldn't find song from second playlist with "
"filter of 'lonely'")
# ...unless it doesn't match that song
self.bar.filter_text("piman")
self.assertFalse(self.bar.active_filter(self.ANOTHER_SONG),
msg="Shouldn't have matched 'piman' on second list")
def test_rename(self):
self.assertEquals(self.bar.playlists()[1], self.small)
self.bar._rename(0, "zBig")
self.assertEquals(self.bar.playlists()[0], self.small)
self.assertEquals(self.bar.playlists()[1].name, "zBig")
def test_default_display_pattern(self):
pattern_text = self.bar.display_pattern_text
self.failUnlessEqual(pattern_text, DEFAULT_PATTERN_TEXT)
self.failUnless("<~name>" in pattern_text)
def test_drag_data_get(self):
b = self.bar
song = AudioFile()
song["~filename"] = fsnative(u"foo")
sel = MockSelData()
qltk.selection_set_songs(sel, [song])
b._drag_data_get(None, None, sel, DND_QL, None)
def test_deletion(self):
def a_delete_event():
ev = Gdk.Event()
ev.type = Gdk.EventType.KEY_PRESS
ev.keyval, accel_mod = Gtk.accelerator_parse("Delete")
ev.state = Gtk.accelerator_get_default_mod_mask() & accel_mod
return ev
b = self.bar
self._fake_browser_pack(b)
event = a_delete_event()
# This is selected in setUp()
first_pl = b.playlists()[0]
app.window.songlist.set_songs(first_pl)
app.window.songlist.select_by_func(lambda x: True,
scroll=False, one=True)
original_length = len(first_pl)
ret = b.key_pressed(event)
self.failUnless(ret, msg="Didn't simulate a delete keypress")
self.failUnlessEqual(len(first_pl), original_length - 1)
def test_import(self):
pl_name = u"_€3 œufs à Noël"
pl = FileBackedPlaylist(_TEMP_DIR, pl_name, None)
pl.extend(SONGS)
pl.write()
new_fn = os.path.splitext(text2fsn(pl.name))[0] + '.m3u'
new_path = os.path.join(pl.dir, new_fn)
os.rename(pl.filename, new_path)
added = self.bar._import_playlists([new_path], self.lib)
self.failUnlessEqual(added, 1, msg="Failed to add '%s'" % new_path)
os.unlink(new_path)
pls = self.bar.playlists()
self.failUnlessEqual(len(pls), 3)
# Leading underscore makes it always the last entry
imported = pls[-1]
self.failUnlessEqual(imported.name, pl_name)
def fns(songs):
return [song('~filename') for song in songs]
self.failUnlessEqual(fns(imported.songs), fns(pl.songs))
@staticmethod
def _fake_browser_pack(b):
app.window.get_child().pack_start(b, True, True, 0)