[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

'win32': Winstart() # startfile or system
#'win32': Cmdline('start %s')
}


videotools = {
'linux2': Cmdline('tkcVideo_c700 %s'), # zaurus pda
'win32': Winstart(), # avoid DOS pop up
}


imagetools = {
'linux2': Cmdline('zimager %s'), # zaurus pda
'win32': Winstart(),
}


texttools = {
'linux2': Cmdline('vi %s'), # zaurus pda
'win32': Cmdline('notepad %s') # or try PyEdit?
}


apptools = {
'win32': Winstart() # doc, xls, etc: use at your own risk!
}


map mimetype of filenames to player tables


mimetable = {'audio': audiotools,
'video': videotools,
'image': imagetools,
'text': texttools, # not html text: browser
'application': apptools}


##################################################################################


top-level interfaces


##################################################################################


def trywebbrowser(filename, helpmsg=helpmsg, options):
"""
try to open a file in a web browser
last resort if unknown mimetype or platform, and for text/html
"""
trace('trying browser', filename)
try:
player = Webbrowser() # open in local browser
player.run(filename,
options)
except:
print(helpmsg % filename) # else nothing worked


def playknownfile(filename, playertable={}, options):
"""
play media file of known type: uses platform-specific
player objects, or spawns a web browser if nothing for
this platform; accepts a media-specific player table
"""
if sys.platform in playertable:
playertable[sys.platform].run(filename,
options) # specific tool


Playing Media Files | 345
Free download pdf