Update of /cvsroot/freevo/freevo/WIP/Dischi
In directory sc8-pr-cvs1:/tmp/cvs-serv17548
Modified Files:
viewer.py
Added Files:
directory.py osd.py playlist.py tiny_osd.py update
Log Message:
some directory fixes, osd in image viewer
--- NEW FILE: directory.py ---
#if 0 /*
# -----------------------------------------------------------------------
# directory.py - Directory handling
# -----------------------------------------------------------------------
# $Id: directory.py,v 1.1 2003/11/15 19:02:00 dischi Exp $
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# $Log: directory.py,v $
# Revision 1.1 2003/11/15 19:02:00 dischi
# some directory fixes, osd in image viewer
#
# Revision 1.57 2003/11/03 17:24:21 dischi
# check if we have write permission
#
# Revision 1.56 2003/10/27 17:36:56 dischi
# NOOOOOOOOOOOOOOOOOO, stupid!!!!!! (sorry, I mean bugfix)
[...1028 lines suppressed...]
for f in self.files:
if not f in files:
del_files += [ f ]
if new_files or del_files:
_debug_('directory has changed')
self.item.update(new_files, del_files, files)
self.files = files
self.lock.release()
def run(self):
while 1:
if self.dir and self.menuw and \
self.menuw.menustack[-1] == self.item_menu and not rc.app():
self.scan()
time.sleep(2)
--- NEW FILE: playlist.py ---
#if 0 /*
# -----------------------------------------------------------------------
# playlist.py - This is the Freevo playlist reading module.
# -----------------------------------------------------------------------
# $Id: playlist.py,v 1.1 2003/11/15 19:02:01 dischi Exp $
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# $Log: playlist.py,v $
# Revision 1.1 2003/11/15 19:02:01 dischi
# some directory fixes, osd in image viewer
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif
import random
import os
import re
import copy
import menu
import util
import config
from event import *
import rc
from item import Item
import video
import audio
import image
from audio import AudioItem
from video import VideoItem
from image import ImageItem
class Playlist(Item):
def read_m3u(self, plsname):
"""
This is the (m3u) playlist reading function.
Arguments: plsname - the playlist filename
Returns: The list of interesting lines in the playlist
"""
try:
lines = util.readfile(plsname)
except IOError:
print 'Cannot open file "%s"' % list
return 0
playlist_lines_dos = map(lambda l: l.strip(), lines)
playlist_lines = filter(lambda l: l[0] != '#', playlist_lines_dos)
(curdir, playlistname) = os.path.split(plsname)
for line in playlist_lines:
if line.endswith('\r\n'):
line = line.replace('\\', '/') # Fix MSDOS slashes
if os.path.exists(os.path.join(curdir,line)):
# skip files that don't exist
if util.match_suffix(line, config.SUFFIX_AUDIO_FILES):
self.playlist += [ AudioItem(os.path.join(curdir, line), self) ]
elif util.match_suffix(line, config.SUFFIX_VIDEO_FILES):
self.playlist += [ VideoItem(os.path.join(curdir, line), self) ]
def read_pls(self, plsname):
"""
This is the (pls) playlist reading function.
Arguments: plsname - the playlist filename
Returns: The list of interesting lines in the playlist
"""
try:
lines = util.readfile(plsname)
except IOError:
print _('Cannot open file "%s"') % list
return 0
playlist_lines_dos = map(lambda l: l.strip(), lines)
playlist_lines = filter(lambda l: l[0:4] == 'File', playlist_lines_dos)
for line in playlist_lines:
numchars=line.find("=")+1
if numchars > 0:
playlist_lines[playlist_lines.index(line)] = \
line[numchars:]
(curdir, playlistname) = os.path.split(plsname)
for line in playlist_lines:
if line.endswith('\r\n'):
line = line.replace('\\', '/') # Fix MSDOS slashes
if util.match_suffix(line, config.SUFFIX_AUDIO_FILES):
self.playlist += [ AudioItem(os.path.join(curdir, line), self) ]
elif util.match_suffix(line, config.SUFFIX_VIDEO_FILES):
self.playlist += [ VideoItem(os.path.join(curdir, line), self) ]
def read_ssr(self, ssrname):
"""
This is the (ssr) slideshow reading function.
Arguments: ssrname - the slideshow filename
Returns: The list of interesting lines in the slideshow
File line format:
FileName: "image file name"; Caption: "caption text"; Delay: "sec"
The caption and delay are optional.
"""
(curdir, playlistname) = os.path.split(ssrname)
out_lines = []
try:
lines = util.readfile(ssrname)
except IOError:
print _('Cannot open file "%s"') % list
return 0
playlist_lines_dos = map(lambda l: l.strip(), lines)
playlist_lines = filter(lambda l: l[0] != '#', lines)
"""
Here's where we parse the line. See the format above.
TODO: Make the search case insensitive
"""
for line in playlist_lines:
tmp_list = []
ss_name = re.findall('FileName: \"(.*?)\"', line)
ss_caption = re.findall('Caption: \"(.*?)\"', line)
ss_delay = re.findall('Delay: \"(.*?)\"', line)
if ss_name != []:
if ss_caption == []:
ss_caption += [""]
if ss_delay == []:
ss_delay += [5]
self.playlist += [ ImageItem(os.path.join(curdir, ss_name[0]), self,
ss_caption[0], int(ss_delay[0])) ]
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]
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):
"""
Special copy value Playlist
"""
Item.copy(self, obj)
if obj.type == 'playlist':
self.current_item = obj.current_item
self.playlist = obj.playlist
self.autoplay = obj.autoplay
def randomize(self):
"""
resort the playlist by random
"""
old = self.playlist
self.playlist = []
while old:
element = random.choice(old)
old.remove(element)
self.playlist += [ element ]
self.name = _('Random Playlist')
def actions(self):
if self.autoplay:
return [ ( self.play, _('Play') ),
( self.browse, _('Browse Playlist') ) ]
return [ ( self.browse, _('Browse Playlist') ),
( self.play, _('Play') ) ]
def browse(self, arg=None, menuw=None):
self.read_playlist()
moviemenu = menu.Menu(self.name, self.playlist)
menuw.pushmenu(moviemenu)
def play(self, arg=None, menuw=None):
self.read_playlist()
if not self.menuw:
self.menuw = menuw
if not self.playlist:
print _('empty playlist')
return False
if not arg or arg != 'next':
self.current_item = self.playlist[0]
if not self.current_item.actions():
# skip item
pos = self.playlist.index(self.current_item)
pos = (pos+1) % len(self.playlist)
if pos:
self.current_item = self.playlist[pos]
self.play(menuw=menuw, arg='next')
else:
# no repeat
self.current_item = None
return True
self.current_item.actions()[0][0](menuw=menuw)
def cache_next(self):
pos = self.playlist.index(self.current_item)
pos = (pos+1) % len(self.playlist)
if pos and hasattr(self.playlist[pos], 'cache'):
self.playlist[pos].cache()
def eventhandler(self, event, menuw=None):
if not menuw:
menuw = self.menuw
if event in ( PLAYLIST_NEXT, PLAY_END, USER_END) \
and self.current_item and self.playlist:
pos = self.playlist.index(self.current_item)
pos = (pos+1) % len(self.playlist)
if pos:
if hasattr(self.current_item, 'stop'):
try:
self.current_item.stop()
except OSError:
_debug_('ignore playlist event', 1)
return True
self.current_item = self.playlist[pos]
self.play(menuw=menuw, arg='next')
return True
else:
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):
self.current_item = None
if menuw:
menuw.show()
return True
if event == PLAYLIST_PREV and self.current_item and self.playlist:
pos = self.playlist.index(self.current_item)
if pos:
if hasattr(self.current_item, 'stop'):
try:
self.current_item.stop()
except OSError:
_debug_('ignore playlist event', 1)
return True
pos = (pos-1) % len(self.playlist)
self.current_item = self.playlist[pos]
self.play(menuw=menuw, arg='next')
return True
else:
rc.post_event(Event(OSD_MESSAGE, arg=_('no previous item in
playlist')))
# give the event to the next eventhandler in the list
return Item.eventhandler(self, event, menuw)
class RandomPlaylist(Playlist):
def __init__(self, playlist, parent, add_args = None, recursive = True, random =
True):
Item.__init__(self, parent)
self.type = 'playlist'
# variables only for Playlist
self.current_item = None
self.playlist = []
self.autoplay = True
self.unplayed = playlist
self.recursive = recursive
self.random = random
def actions(self):
return [ ( self.play, _('Play') ) ]
def play_next(self, arg=None, menuw=None):
if self.random:
element = random.choice(self.unplayed)
else:
element = self.unplayed[0]
self.unplayed.remove(element)
if not callable(element):
# try to get the item for this file
files = [ element, ]
play_items = []
for t in ( 'video', 'audio', 'image' ):
play_items += eval(t + '.cwd(self, files)')
if not play_items:
print 'FIXME: this should never happen'
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 isinstance(self.unplayed, tuple):
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 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)
# end and no next item
if event == PLAY_END:
if self.current_item:
self.current_item.parent = self.parent
self.current_item = None
if menuw:
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)
--- NEW FILE: tiny_osd.py ---
#if 0 /*
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# time_osd.py - An osd for Freevo
# -----------------------------------------------------------------------
# $Id: tiny_osd.py,v 1.1 2003/11/15 19:02:01 dischi Exp $
#
# Notes:
# This plugin is an osd for freevo. It displays the message send by the
# event OSD_MESSAGE
#
# This file should be called osd.py, but this conflicts with the global
# osd.py. This global file should be renamed, because it's no osd, it's
# a render engine
#
# -----------------------------------------------------------------------
# $Log: tiny_osd.py,v $
# Revision 1.1 2003/11/15 19:02:01 dischi
# some directory fixes, osd in image viewer
#
# Revision 1.3 2003/10/04 18:37:29 dischi
# i18n changes and True/False usage
#
# Revision 1.2 2003/09/21 18:17:50 dischi
# only update skin when something changes
#
# Revision 1.1 2003/09/21 13:14:00 dischi
# a small osd to display messages on screen
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif
import os
import sys
import copy
import rc
import config
import skin
import plugin
from event import *
class PluginInterface(plugin.DaemonPlugin):
"""
osd plugin.
This plugin shows messages send from other parts of Freevo on
the screen for 2 seconds.
activate with plugin.activate('plugin.tiny_osd')
"""
def __init__(self):
"""
init the osd
"""
plugin.DaemonPlugin.__init__(self)
self.poll_interval = 200
self.plugins = None
plugin.register(self, 'osd')
self.visible = True
self.message = ''
# set to 2 == we have no idea right now if
# we have an idlebar
self.idlebar_visible = 2
self.poll_menu_only = False
def draw(self, (type, object), renderer):
"""
draw current message
"""
if not self.message:
return
# check for the idlebar plugin
if self.idlebar_visible == 2:
self.idlebar_visible = plugin.getbyname('idlebar')
try:
font = renderer.get_font('osd')
except AttributeError:
try:
font = skin.get_singleton().settings.font['osd']
except:
font = skin.get_singleton().settings.font['default']
w = font.font.stringsize(self.message)
if type == 'osd':
x = config.OVERSCAN_X
y = config.OVERSCAN_Y
renderer.drawstringframed(self.message, config.OVERSCAN_X,
config.OVERSCAN_Y + 10,
renderer.width - 2 * config.OVERSCAN_X, -1,
font.font, fgcolor=0xffffff, bgcolor=0xa0000000,
align_h='right', mode='hard')
else:
y = renderer.y + 10
if self.idlebar_visible:
y += 60
renderer.write_text(self.message, font, None,
(renderer.x + renderer.width-w - 10), y,
w, -1, 'right', 'center')
def eventhandler(self, event, menuw=None):
"""
catch OSD_MESSAGE and display it, return False, maybe someone
else is watching for the event.
"""
if event == OSD_MESSAGE:
self.poll_counter = 1
self.message = event.arg
if not rc.app():
skin.get_singleton().redraw()
elif hasattr(rc.app(), 'im_self') and hasattr(rc.app().im_self, 'redraw'):
rc.app().im_self.redraw()
return False
def poll(self):
"""
clear the osd after 2 seconds
"""
if self.message:
self.message = ''
if not rc.app():
skin.get_singleton().redraw()
elif hasattr(rc.app(), 'im_self') and hasattr(rc.app().im_self, 'redraw'):
rc.app().im_self.redraw()
--- NEW FILE: update ---
cp directory.py osd.py playlist.py ../../src
cp imageitem.py viewer.py ../../src/image
cp tiny_osd.py ../../src/plugins
Index: viewer.py
===================================================================
RCS file: /cvsroot/freevo/freevo/WIP/Dischi/viewer.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** viewer.py 15 Nov 2003 13:46:21 -0000 1.1
--- viewer.py 15 Nov 2003 19:02:01 -0000 1.2
***************
*** 10,15 ****
# -----------------------------------------------------------------------
# $Log$
! # Revision 1.1 2003/11/15 13:46:21 dischi
! # blend effect added
#
# Revision 1.30 2003/09/14 20:09:36 dischi
--- 10,15 ----
# -----------------------------------------------------------------------
# $Log$
! # Revision 1.2 2003/11/15 19:02:01 dischi
! # some directory fixes, osd in image viewer
#
# Revision 1.30 2003/09/14 20:09:36 dischi
***************
*** 54,57 ****
--- 54,58 ----
import os
import time
+ import plugin
import config # Configuration file.
***************
*** 228,231 ****
--- 229,234 ----
osd.screen.blit(i1, (last_image[1], last_image[2]))
osd.screen.blit(i2, (x, y))
+ if plugin.getbyname('osd'):
+ plugin.getbyname('osd').draw(('osd', None), osd)
osd.update()
***************
*** 237,240 ****
--- 240,246 ----
self.drawosd()
+ if plugin.getbyname('osd'):
+ plugin.getbyname('osd').draw(('osd', None), osd)
+
# draw
osd.update()
***************
*** 250,254 ****
!
def cache(self, fileitem):
# cache the next image (most likely we need this)
--- 256,262 ----
! def redraw(self):
! self.view(self.fileitem, zoom=self.zoom, rotation=self.rotation)
!
def cache(self, fileitem):
# cache the next image (most likely we need this)
-------------------------------------------------------
This SF. Net email is sponsored by: GoToMyPC
GoToMyPC is the fast, easy and secure way to access your computer from
any Web browser or wireless device. Click here to Try it Free!
https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog