Mercurial > vixm
annotate vixm/playlist.py @ 9:eaa800169f5b v0.10
Hooked up the playlists to control xmms!
Also added help string to all the commands, and added a stub for help
command
author  Josef "Jeff" Sipek <jeffpc@josefsipek.net> 

date  Sat, 19 Aug 2006 20:02:59 0400 
parents  79340745c952 
children  50584a5c300e 
rev  line source 

2
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

1 # a playlist definition 
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

2 
3
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

3 import xmms 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

4 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

5 LIST_PRIO = 0 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

6 LIST_DEFAULT = 1 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

7 
2
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

8 class playlist: 
3
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

9 def __init__(self, allowrandom=False): 
2
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

10 self.__list = [] 
3
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

11 self.__allowrand = allowrandom # allow randomization of this list 
2
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

12 
3
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

13 def enqueue(self, song): 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

14 """ Append a song to the list """ 
2
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

15 self.__list.append(song) 
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

16 
3
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

17 def dequeue(self, song): 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

18 """ Remove a song from the list """ 
2
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

19 self.__list.remove(song) 
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

20 
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

21 def pop(self): 
3
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

22 """ Pop the next song """ 
9
eaa800169f5b
Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
8
diff
changeset

23 try: 
eaa800169f5b
Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
8
diff
changeset

24 return self.__list.pop(0) 
eaa800169f5b
Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
8
diff
changeset

25 except IndexError: 
eaa800169f5b
Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
8
diff
changeset

26 return None 
2
80a717f97cef
Basic definition of a playlist class
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
diff
changeset

27 
3
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

28 def __getitem__(self, i): 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

29 """ Get item at position i """ 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

30 return self.__list[i] 
dd00b69169c6
Created initial ui thread code, fixed up playlist code
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2
diff
changeset

31 
8
79340745c952
Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3
diff
changeset

32 def __len__(self): 
79340745c952
Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3
diff
changeset

33 """ Return the length of the playlist """ 
79340745c952
Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3
diff
changeset

34 return len(self.__list) 
79340745c952
Reimplemented enqueuing & quit properly, implemented list and number commands
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3
diff
changeset

35 
9
eaa800169f5b
Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
8
diff
changeset

36 def index(self, song): 
eaa800169f5b
Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
8
diff
changeset

37 """ Returns the index of the first occurence of song """ 
eaa800169f5b
Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
8
diff
changeset

38 return self.__list.index(song) 
eaa800169f5b
Hooked up the playlists to control xmms!
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
8
diff
changeset

39 