python 练手
可以播放大部分的音视频.
demo download: http://www.sandy1219.com/python/media.rar
playMP3.py
# -*- coding: utf-8 -*-
import wx;
import wx.media;
import os;
import SPrint;
import mediaStateBar;
import mediaList;
import SaveLog;
import MediaItem;
woldcart = "media files|*.*|avi|*.avi|rmvb|*.rmvb|rm|*.rm|wma|*.wma|mp3|*.mp3";
class MediaFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,wx.NewId(),u"媒体播放器",pos=wx.DefaultPosition,size=(500,500));
self.media = '';
try:
self.media = wx.media.MediaCtrl(self,style=wx.SIMPLE_BORDER,
#szBackend=wx.media.MEDIABACKEND_DIRECTSHOW
#szBackend=wx.media.MEDIABACKEND_QUICKTIME
#szBackend=wx.media.MEDIABACKEND_WMP10
);
self.media.Bind(wx.media.EVT_MEDIA_LOADED,self.mediaLoaded);
self.media.Bind(wx.media.EVT_MEDIA_STATECHANGED,self.mediaStateChange)
except NotImplementedError:
self.Destroy()
raise;
self.listView = '';
self.item = MediaItem.MediaItem();
self.sb = mediaStateBar.MediaStateBar(self);
self.SetStatusBar(self.sb);
self.log = SaveLog.SaveLog();
#self.log.test();
self.menu = wx.Menu()
self.openMenu = self.menu.Append(wx.NewId(),u"打开文件");
self.Bind(wx.EVT_MENU,self._openFile,self.openMenu);
self.quitMenu = self.menu.Append(wx.NewId(),u"退出");
self.Bind(wx.EVT_MENU,self.quit,self.quitMenu);
self.viewMenu = wx.Menu();
self.listMenu = self.viewMenu.Append(wx.NewId(),u"打开播放列表");
self.Bind(wx.EVT_MENU,self.openList,self.listMenu);
self.loadListMenu = self.viewMenu.Append(wx.NewId(),u"加载播放列表");
相关文档:
源代码下载:下载地址在这里
# 024
dict1 = {
'5064001':'Mememe',
'5064002':'tutu',
'5064003':'thrthr',
'5064004':'fofo'
}
print dict1['5064003']
# 也可以使用整型作为唯一的编号
dict2 = {
5064001:'Mememe',
506400 ......
源代码下载:下载地址在这里
# 025
# 序列的神奇之处在于你可以使用相同的方式tuple、list和string
se = ['a', 'b', 'c', 'd']
li = ['a', 'b', 'c', 'd']
tu = ('a', 'b', 'c', 'd')
string = 'abcd'
print se[1]
print li[1]
print tu[1]
print string[1]
# 序列的另外一个神奇之处在于,你可以使用负数进行索 ......
源代码下载:下载地址在这里
# 028
consoleInput = raw_input('请输入点什么吧:')
aFile = file(r'C:\out.txt', 'w')
aFile.write(consoleInput + '\n')
aFile.write('这里是第二行')
aFile.close()
output:
>>>
请输入点什么吧:haha
>>>
......
源代码下载:下载地址在这里
# 029
aFile = file(r'C:\in.txt', 'r')
while True:
line = aFile.readline()
if len(line) == 0:
break
# end of if
print line,
# end of while
aFile.close()
output:
>>>
This is the first line.
This is the second line.
This is ......
源代码下载:下载地址在这里
e.g.1
# 030
aFile = file(r'C:\temp.txt', 'a')
aFile.write('又添加了一行。')
aFile.close()
output:
e.g.2
# 030
aFile = file(r'C:\temp.txt', 'a')
aFile.write('又添加了一行。')
aFile.close()
output:
e.g.3
实现根据原始文件有没有最后一行空行的情况来进行&ldqu ......