Package appModules :: Module winamp
[hide private]
[frames] | no frames]

Source Code for Module appModules.winamp

  1  #appModules/winamp.py 
  2  #A part of NonVisual Desktop Access (NVDA) 
  3  #Copyright (C) 2006-2010 NVDA Contributors <http://www.nvda-project.org/> 
  4  #This file is covered by the GNU General Public License. 
  5  #See the file COPYING for more details. 
  6   
  7  from ctypes import * 
  8  from ctypes.wintypes import * 
  9  import winKernel 
 10  import winUser 
 11  from scriptHandler import isScriptWaiting 
 12  from NVDAObjects.IAccessible import IAccessible  
 13  import appModuleHandler 
 14  import speech 
 15  import locale 
 16  import controlTypes 
 17  import api 
 18  import watchdog 
 19   
 20  # message used to sent many messages to winamp's main window.  
 21  # most all of the IPC_* messages involve sending the message in the form of: 
 22  #   result = SendMessage(hwnd_winamp,WM_WA_IPC,(parameter),IPC_*); 
 23   
 24  WM_WA_IPC=winUser.WM_USER 
 25   
 26  # winamp window 
 27  IPC_GET_SHUFFLE=250 
 28  IPC_GET_REPEAT=251 
 29   
 30  # playlist editor 
 31  IPC_PLAYLIST_GET_NEXT_SELECTED=3029 
 32  IPC_PE_GETCURINDEX=100 
 33  IPC_PE_GETINDEXTOTAL=101 
 34  # in_process ONLY 
 35  IPC_PE_GETINDEXTITLE=200 #  lParam = pointer to fileinfo2 structure 
 36   
37 -class fileinfo2(Structure):
38 _fields_=[ 39 ('fileindex',c_int), 40 ('filetitle',c_char*256), 41 ('filelength',c_char*16), 42 ]
43 44 hwndWinamp=0 45
46 -def getShuffle():
47 global hwndWinamp 48 return watchdog.cancellableSendMessage(hwndWinamp,WM_WA_IPC,0,IPC_GET_SHUFFLE)
49
50 -def getRepeat():
51 global hwndWinamp 52 return watchdog.cancellableSendMessage(hwndWinamp,WM_WA_IPC,0,IPC_GET_REPEAT)
53
54 -class AppModule(appModuleHandler.AppModule):
55
56 - def event_NVDAObject_init(self,obj):
57 global hwndWinamp 58 hwndWinamp=windll.user32.FindWindowA("Winamp v1.x",None)
59
60 - def chooseNVDAObjectOverlayClasses(self, obj, clsList):
61 windowClass = obj.windowClassName 62 if windowClass == "Winamp PE": 63 clsList.insert(0, winampPlaylistEditor) 64 elif windowClass == "Winamp v1.x": 65 clsList.insert(0, winampMainWindow)
66
67 -class winampMainWindow(IAccessible):
68
69 - def event_nameChange(self):
70 pass
71
72 - def script_shuffleToggle(self,gesture):
73 gesture.send() 74 if not isScriptWaiting(): 75 api.processPendingEvents() 76 if getShuffle(): 77 onOff=_("on") 78 else: 79 onOff=_("off") 80 speech.speakMessage(onOff)
81
82 - def script_repeatToggle(self,gesture):
83 gesture.send() 84 if not isScriptWaiting(): 85 api.processPendingEvents() 86 if getRepeat(): 87 onOff=_("on") 88 else: 89 onOff=_("off") 90 speech.speakMessage(onOff)
91 92 __gestures = { 93 "kb:s": "shuffleToggle", 94 "kb:r": "repeatToggle", 95 }
96
97 -class winampPlaylistEditor(winampMainWindow):
98
99 - def _get_name(self):
100 curIndex=watchdog.cancellableSendMessage(hwndWinamp,WM_WA_IPC,-1,IPC_PLAYLIST_GET_NEXT_SELECTED) 101 if curIndex <0: 102 return None 103 info=fileinfo2() 104 info.fileindex=curIndex 105 internalInfo=winKernel.virtualAllocEx(self.processHandle,None,sizeof(info),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) 106 try: 107 winKernel.writeProcessMemory(self.processHandle,internalInfo,byref(info),sizeof(info),None) 108 watchdog.cancellableSendMessage(self.windowHandle,WM_WA_IPC,IPC_PE_GETINDEXTITLE,internalInfo) 109 winKernel.readProcessMemory(self.processHandle,internalInfo,byref(info),sizeof(info),None) 110 finally: 111 winKernel.virtualFreeEx(self.processHandle,internalInfo,0,winKernel.MEM_RELEASE) 112 return unicode("%d.\t%s\t%s"%(curIndex+1,info.filetitle,info.filelength), errors="replace", encoding=locale.getlocale()[1])
113
114 - def _get_role(self):
116
117 - def script_changeItem(self,gesture):
118 gesture.send() 119 if not isScriptWaiting(): 120 api.processPendingEvents() 121 speech.speakObject(self,reason=speech.REASON_FOCUS)
122
123 - def event_nameChange(self):
124 return super(winampMainWindow,self).event_nameChange()
125 126 __changeItemGestures = ( 127 "kb:upArrow", 128 "kb:downArrow", 129 "kb:pageUp", 130 "kb:pageDown", 131 ) 132
133 - def initOverlayClass(self):
134 for gesture in self.__changeItemGestures: 135 self.bindGesture(gesture, "changeItem")
136