Update of /cvsroot/freevo/freevo/src
In directory sc8-pr-cvs1:/tmp/cvs-serv24051/src

Modified Files:
        playlist.py directory.py 
Log Message:
merged Playlist and RandomPlaylist into one class

Index: playlist.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/playlist.py,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** playlist.py 8 Dec 2003 16:18:44 -0000       1.39
--- playlist.py 8 Dec 2003 20:37:33 -0000       1.40
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.40  2003/12/08 20:37:33  dischi
+ # merged Playlist and RandomPlaylist into one class
+ #
  # Revision 1.39  2003/12/08 16:18:44  mikeruelle
  # getting a lot of crashes. quickfix
***************
*** 71,74 ****
--- 74,110 ----
  
  class Playlist(Item):
+ 
+     def __init__(self, name='', playlist=[], parent=None, display_type=None,
+                  random=False, build=False, autoplay=False, repeat=False):
+         """
+         Init the playlist
+         """
+         Item.__init__(self, parent)
+ 
+         self.type     = 'playlist'
+         self.menuw    = None
+         self.name     = name
+         
+         if (isinstance(playlist, str) or isinstance(playlist, unicode)) and not name:
+             self.name = playlist
+             
+         # variables only for Playlist
+         self.current_item = None
+         self.playlist     = playlist
+         self.autoplay     = autoplay
+         self.repeat       = repeat
+         self.display_type = display_type
+ 
+         self.__build__    = False
+         self.suffixlist   = []
+         self.get_plugins  = []
+ 
+         self.background_playlist = None
+         if build:
+             self.build()
+ 
+         self.random = random
+ 
+ 
      def read_m3u(self, plsname):
          """
***************
*** 78,82 ****
          Returns:   The list of interesting lines in the playlist
          """
- 
          try:
              lines = util.readfile(plsname)
--- 114,117 ----
***************
*** 93,101 ****
                  line = line.replace('\\', '/') # Fix MSDOS slashes
              if os.path.exists(os.path.join(curdir,line)):
!                 # XXX add display_type
!                 for p in plugin.mimetype(None):
!                     for i in p.get(self, [os.path.join(curdir, line)]):
!                         self.playlist.append(i)
!                         break
              
  
--- 128,132 ----
                  line = line.replace('\\', '/') # Fix MSDOS slashes
              if os.path.exists(os.path.join(curdir,line)):
!                 self.playlist.append(os.path.join(curdir,line))
              
  
***************
*** 107,111 ****
          Returns:   The list of interesting lines in the playlist
          """
- 
          try:
              lines = util.readfile(plsname)
--- 138,141 ----
***************
*** 127,135 ****
              if line.endswith('\r\n'):
                  line = line.replace('\\', '/') # Fix MSDOS slashes
!             # XXX add display_type
!             for p in plugin.mimetype(None):
!                 for i in p.get(self, [os.path.join(curdir, line)]):
!                     self.playlist.append(i)
!                     break
              
  
--- 157,162 ----
              if line.endswith('\r\n'):
                  line = line.replace('\\', '/') # Fix MSDOS slashes
!             if os.path.exists(os.path.join(curdir,line)):
!                 self.playlist.append(os.path.join(curdir,line))
              
  
***************
*** 177,181 ****
                      ss_delay += [5]
  
!                 for p in plugin.mimetype('image'):
                      for i in p.get(self, [os.path.join(curdir, ss_name[0])]):
                          if i.type == 'image':
--- 204,208 ----
                      ss_delay += [5]
  
!                 for p in self.get_plugins:
                      for i in p.get(self, [os.path.join(curdir, ss_name[0])]):
                          if i.type == 'image':
***************
*** 186,228 ****
  
  
!     def __init__(self, file, parent):
!         Item.__init__(self, parent)
!         self.type     = 'playlist'
!         self.menuw    = None
! 
!         # variables only for Playlist
!         self.current_item = None
          self.playlist = []
!         self.autoplay = False
  
-         if isinstance(file, list):      # file is a playlist
-             self.filename = ''
-             for i in file:
-                 element = copy.copy(i)
-                 element.parent = self
-                 self.playlist += [ element ]
-             self.name = 'Playlist'
-         else:
-             self.filename = file
-             self.name    = os.path.splitext(os.path.basename(file))[0]
  
!         self.background_playlist = None
  
  
-     def read_playlist(self):
-         """
-         Read the playlist from file and create the items
-         """
-         if hasattr(self, 'filename') and self.filename and not self.playlist:
-             f=open(self.filename, "r")
-             line = f.readline()
-             f.close
-             if line.find("[playlist]") > -1:
-                 self.read_pls(self.filename)
-             elif line.find("[Slides]") > -1:
-                 self.read_ssr(self.filename)
              else:
!                 self.read_m3u(self.filename)
!         
  
      def copy(self, obj):
--- 213,272 ----
  
  
!     def build(self):
!         """
!         Build the playlist. Create a list of items and filenames. This function
!         will load the playlist file or expand directories
!         """
!         if self.suffixlist:
!             # we called this function before
!             return
!         
!         playlist      = self.playlist
          self.playlist = []
!         
!         for p in plugin.mimetype(self.display_type):
!             if self.display_type in p.display_type:
!                 self.suffixlist += p.suffix()
!                 self.get_plugins.append(p)
!                 
!         if isinstance(playlist, str) or isinstance(playlist, unicode):
!             # it's a filename with a playlist
!             try:
!                 f=open(self.filename, "r")
!                 line = f.readline()
!                 f.close
!                 if line.find("[playlist]") > -1:
!                     self.read_pls(self.filename)
!                 elif line.find("[Slides]") > -1:
!                     self.read_ssr(self.filename)
!                 else:
!                     self.read_m3u(self.filename)
!             except OSError, e:
!                 print 'playlist error: %s' % e
  
  
!         # self.playlist is a list of Items or strings (filenames)
!         for i in playlist:
!             if isinstance(i, Item):
!                 # Item object, correct parent
!                 i = copy.copy(i)
!                 i.parent = self
!                 self.playlist.append(i)
  
+             elif isinstance(i, list) or isinstance(i, tuple) and \
+                  len(i) == 2 and vfs.isdir(i[0]):
+                 # (directory, recursive=True|False)
+                 if i[1]:
+                     self.playlist += util.match_files_recursively(i[0], 
self.suffixlist)
+                 else:
+                     self.playlist += util.match_files(i[0], self.suffixlist)
+                 # set autoplay to True on such big lists
+                 self.autoplay = True
  
              else:
!                 # filename
!                 self.playlist.append(i)
!         self.__build__ = True
!                 
  
      def copy(self, obj):
***************
*** 247,251 ****
              old.remove(element)
              self.playlist += [ element ]
-         self.name = _('Random Playlist')
  
          
--- 291,294 ----
***************
*** 254,257 ****
--- 297,301 ----
          return the actions for this item: play and browse
          """
+         self.build()
          if self.autoplay:
              return [ ( self.play, _('Play') ),
***************
*** 266,270 ****
          show the playlist in the menu
          """
!         self.read_playlist()
          moviemenu = menu.Menu(self.name, self.playlist)
          menuw.pushmenu(moviemenu)
--- 310,331 ----
          show the playlist in the menu
          """
!         self.build()
!         for item in self.playlist:
!             if not callable(item):
!                 # element is a string, make a correct item
!                 play_items = []
! 
!                 # get a real item
!                 for p in self.get_plugins:
!                     for i in p.get(self, [ item ]):
!                         play_items.append(i)
! 
!                 if play_items:
!                     pos = self.playlist.index(item)
!                     self.playlist[pos] = play_items[0]
! 
!         if self.random:
!             self.randomize()
! 
          moviemenu = menu.Menu(self.name, self.playlist)
          menuw.pushmenu(moviemenu)
***************
*** 275,282 ****
          play the playlist
          """
-         self.read_playlist()
          if not self.menuw:
              self.menuw = menuw
  
          if not self.playlist:
              # XXX PopupBox please
--- 336,343 ----
          play the playlist
          """
          if not self.menuw:
              self.menuw = menuw
  
+ 
          if not self.playlist:
              # XXX PopupBox please
***************
*** 284,293 ****
              return False
          
          if not arg or arg != 'next':
              if self.background_playlist:
                  self.background_playlist.play()
              self.current_item = self.playlist[0]
              
!         if not self.current_item.actions():
              # skip item
              pos = self.playlist.index(self.current_item)
--- 345,377 ----
              return False
          
+ 
          if not arg or arg != 'next':
+             # first start
+             self.build()
+             if self.random:
+                 self.randomize()
+ 
              if self.background_playlist:
                  self.background_playlist.play()
+ 
              self.current_item = self.playlist[0]
+ 
+ 
+         if not callable(self.current_item):
+             # element is a string, make a correct item
+             play_items = []
+ 
+             # get a real item
+             for p in self.get_plugins:
+                 for i in p.get(self, [ self.current_item ]):
+                     play_items.append(i)
+ 
+             if play_items:
+                 pos = self.playlist.index(self.current_item)
+                 self.current_item = play_items[0]
+                 self.playlist[pos] = play_items[0]
+ 
              
!         if not hasattr(self.current_item, 'actions') or not 
self.current_item.actions():
              # skip item
              pos = self.playlist.index(self.current_item)
***************
*** 342,346 ****
              pos = (pos+1) % len(self.playlist)
  
!             if pos:
                  if hasattr(self.current_item, 'stop'):
                      try:
--- 426,430 ----
              pos = (pos+1) % len(self.playlist)
  
!             if pos or self.repeat:
                  if hasattr(self.current_item, 'stop'):
                      try:
***************
*** 354,361 ****
              elif event == PLAYLIST_NEXT:
                  rc.post_event(Event(OSD_MESSAGE, arg=_('no next item in playlist')))
                  
          # end and no next item
          if event in (PLAY_END, USER_END, STOP):
!             if hasattr(self, 'background_playlist') and self.background_playlist:
                  self.background_playlist.stop()
              self.current_item = None
--- 438,446 ----
              elif event == PLAYLIST_NEXT:
                  rc.post_event(Event(OSD_MESSAGE, arg=_('no next item in playlist')))
+ 
                  
          # end and no next item
          if event in (PLAY_END, USER_END, STOP):
!             if self.background_playlist:
                  self.background_playlist.stop()
              self.current_item = None
***************
*** 385,536 ****
  
  
- 
- 
- 
- class RandomPlaylist(Playlist):
-     """
-     A playlist that can be played in random mode, recursive in subdirs
-     or a combination of both. It is _not_ possible to browse this playlist
-     right now, only play it.
-     """
-     def __init__(self, name, playlist, parent, recursive = True,
-                  random = True):
-         Item.__init__(self, parent)
-         self.type         = 'playlist'
-         self.name         = name
-         
-         # variables only for Playlist
-         self.current_item = None
-         self.playlist     = []
-         self.autoplay     = True
-         self.unplayed     = playlist
-         self.recursive    = recursive
-         self.random       = random
- 
-         self.background_playlist = None
- 
- 
-     def actions(self):
-         return [ ( self.play, _('Play') ) ]
- 
- 
-     def play_next(self, arg=None, menuw=None):
-         if not self.unplayed:
-             return False
-         
-         if self.random:
-             element = random.choice(self.unplayed)
-         else:
-             element = self.unplayed[0]
-         self.unplayed.remove(element)
- 
-         if not callable(element):
-             # element is a string, make a correct item
-             files = [ element, ]
-             play_items = []
- 
-             # get a real item
-             for p in plugin.mimetype(None):
-                 for i in p.get(self, files):
-                     play_items.append(i)
- 
-             if not play_items:
-                 return False
-                 
-             element = play_items[0]
-                 
-         self.playlist += [ element ]
-         self.current_item = element
-         element.parent = self
-         element(menuw=menuw)
-         return True
-         
- 
-     def play(self, arg=None, menuw=None):
-         if not self.menuw:
-             self.menuw = menuw
- 
-         if self.background_playlist:
-             self.background_playlist.play()
-             
-         if isinstance(self.unplayed, tuple):
-             # playlist is a list: dir:prefix
-             # build a correct playlist now
-             dir, prefix = self.unplayed
-             if self.recursive:
-                 self.unplayed = util.match_files_recursively(dir, prefix)
-             else:
-                 self.unplayed = util.match_files(dir, prefix)
- 
-         # reset playlist
-         self.unplayed += self.playlist
-         self.playlist = []
- 
-         # play
-         if self.unplayed:
-             return self.play_next(arg=arg, menuw=menuw)
-         return False
- 
- 
-     def cache_next(self):
-         pass
- 
- 
-     def stop(self):
-         """
-         stop playling
-         """
-         if self.background_playlist:
-             self.background_playlist.stop()
-         if self.current_item:
-             self.current_item.parent = self.parent
-             if hasattr(self.current_item, 'stop'):
-                 try:
-                     self.current_item.stop()
-                 except OSError:
-                     pass
-         
- 
-     def eventhandler(self, event, menuw=None):
-         if not menuw:
-             menuw = self.menuw
- 
-         if (event == PLAYLIST_NEXT or event == PLAY_END) and self.unplayed:
-             if self.current_item:
-                 self.current_item.parent = self.parent
-                 if hasattr(self.current_item, 'stop'):
-                     try:
-                         self.current_item.stop()
-                     except OSError:
-                         _debug_('ignore playlist event', 1)
-                         return True
-             return self.play_next(menuw=menuw)
- 
-         if event == PLAYLIST_NEXT and not self.unplayed:
-             rc.post_event(Event(OSD_MESSAGE, arg=_('no next item in playlist')))
-             return True
-         
-         # end and no next item
-         if event in (STOP, PLAY_END, USER_END):
-             if self.background_playlist:
-                 self.background_playlist.stop()
- 
-             if self.current_item:
-                 self.current_item.parent = self.parent
-             self.current_item = None
-             if menuw:
-                 if hasattr(menuw.menustack[-1], 'is_submenu'):
-                     menuw.back_one_menu()
-                 if menuw.visible:
-                     menuw.refresh()
-                 else:
-                     menuw.show()
-             return True
-             
-         if event == PLAYLIST_PREV:
-             print 'random playlist up: not implemented yet'
- 
-         # give the event to the next eventhandler in the list
-         return Item.eventhandler(self, event, menuw)
      
  
--- 470,473 ----
***************
*** 561,565 ****
  
          for filename in util.find_matches(files, self.suffix()):
!             items.append(Playlist(filename, parent))
              files.remove(filename)
  
--- 498,502 ----
  
          for filename in util.find_matches(files, self.suffix()):
!             items.append(Playlist(playlist=filename, parent=parent, build=True))
              files.remove(filename)
  
***************
*** 604,611 ****
          </freevo>
          """
-         suffix = []
-         for p in plugin.mimetype(fxd.getattr(None, 'display_type')):
-             suffix += p.suffix()
- 
          children = fxd.get_children(node, 'files')
          if children:
--- 541,544 ----
***************
*** 614,636 ****
          items = []
          for child in children:
!             try:
!                 if child.name == 'directory':
!                     try:
!                         recursive = int(fxd.getattr(child, 'recursive', 0))
!                     except:
!                         recursive = False
!                     if recursive:
!                         items += util.match_files_recursively(fxd.gettext(child), 
suffix)
!                     else:
!                         items += util.match_files(fxd.gettext(child), suffix)
  
!                 elif child.name == 'file':
!                     items.append(fxd.gettext(child))
!             except OSError, e:
!                 print 'playlist error:'
!                 print e
  
!         pl = RandomPlaylist('', items, fxd.getattr(None, 'parent', None),
!                             random = fxd.getattr(node, 'random', 0))
  
          pl.name     = fxd.getattr(node, 'title')
--- 547,559 ----
          items = []
          for child in children:
!             if child.name == 'directory':
!                 items.append((fxd.gettext(child), fxd.getattr(child, 'recursive', 
0)))
  
!             elif child.name == 'file':
!                 items.append(fxd.gettext(child))
  
!         pl = Playlist('', items, fxd.getattr(None, 'parent', None),
!                       display_type=fxd.getattr(None, 'display_type'),
!                       build=True, random=fxd.getattr(node, 'random', 0))
  
          pl.name     = fxd.getattr(node, 'title')
***************
*** 646,648 ****
  # load the MimetypePlugin
  plugin.activate(Mimetype())
- 
--- 569,570 ----

Index: directory.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/directory.py,v
retrieving revision 1.73
retrieving revision 1.74
diff -C2 -d -r1.73 -r1.74
*** directory.py        7 Dec 2003 14:45:57 -0000       1.73
--- directory.py        8 Dec 2003 20:37:33 -0000       1.74
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.74  2003/12/08 20:37:33  dischi
+ # merged Playlist and RandomPlaylist into one class
+ #
  # Revision 1.73  2003/12/07 14:45:57  dischi
  # make the busy icon thread save
***************
*** 105,109 ****
  
  from item import Item
! from playlist import Playlist, RandomPlaylist
  from event import *
  from gui import PasswordInputBox, AlertBox, ProgressBox
--- 108,112 ----
  
  from item import Item
! from playlist import Playlist
  from event import *
  from gui import PasswordInputBox, AlertBox, ProgressBox
***************
*** 157,161 ****
      """
      def __init__(self, directory, parent, name = '', display_type = None, add_args = 
None):
!         Item.__init__(self, parent)
          self.type = 'dir'
          self.menuw = None
--- 160,164 ----
      """
      def __init__(self, directory, parent, name = '', display_type = None, add_args = 
None):
!         Playlist.__init__(self, parent=parent)
          self.type = 'dir'
          self.menuw = None
***************
*** 166,174 ****
              self.name = name
          
-         # variables only for Playlist
-         self.current_item = 0
-         self.playlist = []
-         self.autoplay = False
- 
          # variables only for DirItem
          self.dir          = os.path.abspath(directory)
--- 169,172 ----
***************
*** 365,395 ****
          return a list of actions for this item
          """
-         suffix = []
- 
          display_type = self.display_type
          if self.display_type == 'tv':
              display_type = 'video'
  
!         for p in plugin.mimetype(display_type):
!             suffix += p.suffix()
  
!         items = [ ( self.cwd, _('Browse directory')),
!                   ( self.play, _('Play all files in directory')) ]
  
!         if display_type in self.DIRECTORY_AUTOPLAY_ITEMS:
!             for d in util.getdirnames(self.dir):
!                 if not (d.endswith('CVS') or d.endswith('.xvpics') or \
!                         d.endswith('.thumbnails') or d.endswith('.pics')):
!                     break
!             else:
!                 items.reverse()
  
!         if suffix:
!             items += [ RandomPlaylist(_('Random play all items'), (self.dir, suffix),
!                                       self, recursive=False),
!                        RandomPlaylist(_('Recursive random play all items'),
!                                       (self.dir, suffix), self),
!                        RandomPlaylist(_('Recursive play all items'), (self.dir, 
suffix),
!                                       self, random = False) ]
  
          items.append((self.configure, _('Configure directory'), 'configure'))
--- 363,398 ----
          return a list of actions for this item
          """
          display_type = self.display_type
          if self.display_type == 'tv':
              display_type = 'video'
  
!         items = [ ( self.cwd, _('Browse directory')) ]
  
!         has_files = False
!         has_dirs  = False
  
!         for f in vfs.listdir(self.dir):
!             if vfs.isfile(f):
!                 has_files = True
!             if vfs.isdir(f) and not (f.endswith('CVS') or f.endswith('.xvpics') or \
!                                      f.endswith('.thumbnails') or 
f.endswith('.pics')):
!                 has_dirs = True
!             if has_dirs and has_files:
!                 break
  
!         if has_files:
!             items.append((self.play, _('Play all files in directory')))
!             
!         if display_type in self.DIRECTORY_AUTOPLAY_ITEMS and not has_dirs:
!             items.reverse()
! 
!         if has_files:
!             items.append(Playlist(_('Random play all items'), [ (self.dir, 0) ],
!                                   self, display_type=display_type, random=True))
!         if has_dirs:
!             items += [ Playlist(_('Recursive random play all items'), [ (self.dir, 
1) ],
!                                 self, display_type=display_type, random=True),
!                        Playlist(_('Recursive play all items'), [ (self.dir, 1) ],
!                                 self, display_type=display_type, random=False) ]
  
          items.append((self.configure, _('Configure directory'), 'configure'))
***************
*** 507,512 ****
          if self.display_type and self.display_type in 
self.DIRECTORY_ADD_RANDOM_PLAYLIST \
                 and len(self.play_items) > 1:
!             pl = Playlist(self.play_items, self)
!             pl.randomize()
              pl.autoplay = True
              items = [ pl ] + items
--- 510,514 ----
          if self.display_type and self.display_type in 
self.DIRECTORY_ADD_RANDOM_PLAYLIST \
                 and len(self.play_items) > 1:
!             pl = Playlist(_('Random playlist'), self.play_items, self, random=True)
              pl.autoplay = True
              items = [ pl ] + items




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to