Random
- Made a random check button to toggle the random preference - Playlists pick a random song from what is visible
This commit is contained in:
parent
b697abb8e0
commit
6d7b08f921
|
@ -17,6 +17,13 @@ import lens
|
|||
library = lens.Library()
|
||||
playlist = lens.Playlist()
|
||||
|
||||
def init():
|
||||
libsaria.init_pref("random", False)
|
||||
libsaria.event.invite("POSTINIT", init)
|
||||
|
||||
def toggle_rand():
|
||||
libsaria.prefs["random"] = not libsaria.prefs["random"]
|
||||
|
||||
cur_lib_id = -1
|
||||
|
||||
def new_source(path, bg=True):
|
||||
|
@ -94,10 +101,13 @@ def plist_filter(text):
|
|||
def plist_refresh():
|
||||
return call("PLISTREFRESH")
|
||||
|
||||
def plist_next(arg):
|
||||
def plist_next(arg=None):
|
||||
global playlist
|
||||
global cur_lib_id
|
||||
next = playlist.next_id(cur_lib_id)
|
||||
if libsaria.prefs["random"] == True:
|
||||
next = playlist.random()
|
||||
else:
|
||||
next = playlist.next_id(cur_lib_id)
|
||||
if next != None:
|
||||
lib_play_id(next)
|
||||
libsaria.event.invite("POSTEOS", plist_next)
|
||||
|
|
|
@ -77,6 +77,12 @@ class Collection:
|
|||
return True
|
||||
return id in self.visible
|
||||
|
||||
def num_visible(self):
|
||||
if self.filtered == True:
|
||||
return len(self.visible)
|
||||
else:
|
||||
return self.size
|
||||
|
||||
def walk_tags(self):
|
||||
for tag in self.tag_tree.walk_forwards():
|
||||
rec = self.records[tag[3]]
|
||||
|
@ -118,6 +124,7 @@ class Collection:
|
|||
def insert_tags(self, artist, album, title, id):
|
||||
tags = self.tag_tree.insert([artist, album, title, id])
|
||||
self.index.insert([artist, album, title], id)
|
||||
self.size += 1
|
||||
|
||||
def insert_allocate(self, components, ref):
|
||||
t = ref.tag()
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
import libsaria
|
||||
import collection
|
||||
|
||||
import random as rand
|
||||
|
||||
from libsaria import data
|
||||
|
||||
save = data.save
|
||||
|
@ -78,5 +80,17 @@ class Playlist(collection.Collection):
|
|||
return first
|
||||
return None
|
||||
|
||||
def random(self):
|
||||
num = self.num_visible()
|
||||
next_idx = rand.randint(0, num-1)
|
||||
func = self.visible
|
||||
if self.filtered == False:
|
||||
func = self.walk_ids
|
||||
for n in func():
|
||||
if next_idx == 0:
|
||||
return n
|
||||
next_idx -= 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -55,6 +55,13 @@ class StopButton(Button):
|
|||
def clicked(self, button):
|
||||
LS.music.stop()
|
||||
|
||||
|
||||
class NextButton(Button):
|
||||
def __init__(self):
|
||||
Button.__init__(self, gtk.STOCK_MEDIA_NEXT)
|
||||
def clicked(self, button):
|
||||
LS.collection.plist_next()
|
||||
|
||||
class OpenButton(Button):
|
||||
def __init__(self):
|
||||
Button.__init__(self, gtk.STOCK_OPEN)
|
||||
|
@ -62,6 +69,16 @@ class OpenButton(Button):
|
|||
from ocarina import fsselect
|
||||
fsselect.run_chooser2(LS.data.universal_open)
|
||||
|
||||
class RandomButton(gtk.CheckButton):
|
||||
def __init__(self):
|
||||
gtk.CheckButton.__init__(self, "Random")
|
||||
self.set_active(prefs["random"])
|
||||
self.connect("toggled", self.toggle)
|
||||
self.show()
|
||||
|
||||
def toggle(self, button):
|
||||
LS.collection.toggle_rand()
|
||||
|
||||
|
||||
class UpButton(Button):
|
||||
def __init__(self, callback):
|
||||
|
|
|
@ -41,6 +41,8 @@ class FilterBar(Bar):
|
|||
|
||||
self.pack(entry.FilterEntry(), True, True)
|
||||
self.pack(button.OpenButton())
|
||||
self.pack(button.RandomButton())
|
||||
self.pack(button.VolumeButton())
|
||||
|
||||
|
||||
class InfoBar(Bar):
|
||||
|
@ -57,7 +59,8 @@ class InfoBar(Bar):
|
|||
self.pack(button.PlayButton())
|
||||
self.pack(button.PauseButton())
|
||||
self.pack(button.StopButton())
|
||||
self.pack(button.VolumeButton())
|
||||
self.pack(button.NextButton())
|
||||
#self.pack(button.VolumeButton())
|
||||
self.pack(button.UpButton(up_button))
|
||||
|
||||
libsaria.event.invite("POSTLOAD", self.change_title)
|
||||
|
@ -82,7 +85,8 @@ class InfoTab(gtk.Notebook):
|
|||
hbox.pack_start(button.PlayButton())
|
||||
hbox.pack_start(button.PauseButton())
|
||||
hbox.pack_start(button.StopButton())
|
||||
hbox.pack_start(button.VolumeButton())
|
||||
hbox.pack_start(button.NextButton())
|
||||
#hbox.pack_start(button.VolumeButton())
|
||||
hbox.pack_start(button.DownButton(down_button))
|
||||
self.set_action_widget(hbox, gtk.PACK_END)
|
||||
|
||||
|
|
Loading…
Reference in New Issue