"""
xbmc.py - emulator for Xbox Media Center
"""
from Tkinter import *
__author__ = 'alexpoet/bitplane'
__credits__ = 'XBMC TEAM.'
__date__ = '11 July 2004'
__version__ = '0.1a'
# define playlist types
PLAYLIST_MUSIC = 0
PLAYLIST_MUSIC_TEMP = 1
PLAYLIST_VIDEO = 2
PLAYLIST_VIDEO_TEMP = 3
TRAY_OPEN = 16
DRIVE_NOT_READY = 1
TRAY_CLOSED_NO_MEDIA = 64
TRAY_CLOSED_MEDIA_PRESENT = 96
# functions...
def restart():
"""
restart() -- Restart Xbox.
INCOMPLETE: how do you quit python?
"""
raise KeyboardInterrupt
def shutdown():
"""
shutdown() -- Shutdown the xbox
INCOMPLETE: how do you quit python?
"""
raise KeyboardInterrupt
def dashboard():
"""
dashboard() -- Boot to dashboard.
INCOMPLETE: how do you quit python?
"""
raise KeyboardInterrupt
def executescript(script):
"""
executescript(string) -- Execute a python script.
example:
- executescript('q:\scripts\update.py')
"""
pass
def getCpuTemp():
"""
getCpuTemp() -- Returns the current cpu tempature.
INCOMPLETE - hard coded, hardly worth the effort
"""
return 20
def getDVDState():
"""
getDVDState() -- Returns the dvd state.
return values are:
- 16 : xbmc.TRAY_OPEN
- 1 : xbmc.DRIVE_NOT_READY
- 64 : xbmc.TRAY_CLOSED_NO_MEDIA
- 96 : xbmc.TRAY_CLOSED_MEDIA_PRESENT
INCOMPLETE - always returns DRIVE_NOT_READY
"""
return DRIVE_NOT_READY
def getFreeMem():
"""
getFreeMem() -- Returns free memory as a string.
"""
pass
def getIPAddress():
"""
getIPAddress() -- Returns the current ip adres as string.
INCOMPLETE - hard coded loopback
"""
return "127.0.0.1"
def getLanguage():
"""
getLanguage() -- Returns the active language as string.
INCOMPLETE - investigation needed
"""
return "English"
def getLocalizedString(id):
"""
getLocalizedString(int id) -- Returns a Localized 'unicode string'.
See the xml language files in /language/ which id you need for a string
INCOMPLETE - returns ID no as string
"""
return str(id)
def getSkinDir():
"""
getSkinDir() -- Returns the active skin directory.
Note, this is not the full path like 'q:\skins\MediaCenter',
but only 'MediaCenter'
INCOMPLETE - Hard coded
"""
#return "Project Mayhem"
#return "Project Mayhem II"
return "Project Mayhem III"
def output(s):
"""
output(string) -- Write a string to the debug window.
"""
print s
# classes
class Keyboard:
"""
Keyboard([string default]) -- Creates a new Keyboard object with default text
if supplied.
"""
# should this be __init__(self, text=None): ?
def __init__(self, text = ''):
import time
time.sleep(1)
self.confirmed = False
self.root = Toplevel()
box = Frame(self.root)
box.pack(expand = YES, fill = BOTH)
self.ent = Entry(box)
self.ent.insert(0, text)
self.ent.pack(side = TOP, fill = X)
self.ent.focus()
self.ent.bind("<Return>", self.__ok)
Button(box, text = "Accept (Y-button)", command = self.__ok).pack(side = LEFT)
Button(box, text = "Cancel (B-button)", command = self.__cancel).pack(side = RIGHT)
self.root.focus_set()
self.root.grab_set()
self.root.wait_window()
def __ok(self, event = None):
"""
INTERNAL
"""
self.confirmed = True
self.text = self.ent.get()
self.root.destroy()
def __cancel(self):
"""
INTERNAL
"""
self.confirmed = False
self.text = ""
self.root.destroy()
def getText(self):
"""
getText() -- Returns the user input.
"""
return self.text
def doModal(self):
"""
doModal() -- Show keyboard and wait for user action.
INCOMPLETE
"""
pass
def isConfirmed(self):
"""
isConfirmed() -- Returns False if the user cancelled the input.
"""
return self.confirmed
def setDefault(self, text):
"""
setDefault(string text) -- Set new text that is displayed as default.
"""
self.ent.insert(0, text)
class PlayList:
"""
PlayList(int playlist) -- retrieve a reference from a valid xbmc playlist
int playlist can be one of the next values:
- 0 : xbmc.PLAYLIST_MUSIC
- 1 : xbmc.PLAYLIST_MUSIC_TEMP
- 2 : xbmc.PLAYLIST_VIDEO
- 3 : xbmc.PLAYLIST_VIDEO_TEMP
"""
def __init__(self,playlist):
# playlist is "x" in doc strings
self.x = []
def __getitem__(self,y):
return self.x[y]
def __len__(self):
return len(x)
def add(self, filename, description="",duration=0):
"""
add(filename[, description, duration]) -- Add's a new file to the playlist.
"""
self.x.append(PlayListItem())
i = len(self.x) -1
self.x[i].__filename = filename
self.x[i].__description = description
self.x[i].__duration = duration
def clear(self):
"""
clear() -- clear all items in the playlist.
"""
for i in range(0,len(self.x)):
del self.x[len(self.x)-1]
def load(self,filename):
"""
load(filename) -- Load a playlist.
clear current playlist and copy items from the file to this Playlist
filename can be like .pls or .m3u ...
returns False if unable to load playlist
INCOMPLETE
"""
pass
def remove(self,filename):
"""
remove(filename) -- remove an item with this filename from the playlist.
INVESTIGATE: should this raise an error if filename not found?
should it remove dupes?
"""
f = filename.upper()
for i in range(0,len(self.x)-1):
if self.x[i].__filename.upper() == f:
del self.x[i]
return
def shuffle(self):
"""
shuffle() -- shuffle the playlist.
INCOMPLETE
"""
pass
class PlayListItem:
"""
PlayListItem() -- Creates a new PlaylistItem which can be added to a PlayList.
"""
def __init__(self):
self.__filename = ""
self.__description = ""
self.__duration = 0
def getdescription(self):
"""
getdescription() -- Returns the description of this PlayListItem.
"""
return self.__description
def getduration(self):
"""
getduration() -- Returns the duration of this PlayListItem.
"""
return self.__duration
def getfilename(self):
"""
getfilename() -- Returns the filename of this PlayListItem.
"""
return self.__filename
class Player:
"""
Player() -- Creates a new Player with as default the xbmc music playlist.
INCOMPLETE - stubbed for now, Winamp support planned
"""
def __init__(self):
# create default playlist
pass
def isPlaying( self ):
return False
def pause(self):
"""
pause() -- Pause playing.
"""
pass
def play(self,item=None):
"""
play([item]) -- Play this item.
item can be a filename or a PlayList.
If item is not given then the Player will try to play the current item
in the current playlist.
"""
pass
def playnext(self):
"""
playnext() -- Play next item in playlist.
"""
pass
def playprevious(self):
"""
playprevious() -- Play previous item in playlist.
"""
pass
def stop(self):
"""
stop() -- Stop playing.
"""
pass
def getTime(self):
return 0
def getTotalTime(self):
return 0
def seekTime(self, t):
pass
# set up if not ready
#if not ("Ready" in dir(xbmc)):
# Ready = True
# Set up q:\
# read xboxmediacenter.xml
# read settings
# open winamp, read playlist
|