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

Source Code for Module appModules.outlook

  1  #appModules/outlook.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 comtypes import COMError 
  8  import comtypes.client 
  9  import winUser 
 10  import appModuleHandler 
 11  import eventHandler 
 12  import controlTypes 
 13  from NVDAObjects.IAccessible import IAccessible 
 14  from NVDAObjects.window import Window 
 15  from NVDAObjects.IAccessible.MSHTML import MSHTML 
 16   
17 -def getContactString(obj):
18 return ", ".join([x for x in [obj.fullName,obj.companyName,obj.jobTitle,obj.email1address] if x and not x.isspace()])
19
20 -def getReceivedMessageString(obj):
21 nameList=[] 22 nameList.append(obj.senderName) 23 nameList.append(_("subject: %s")%obj.subject) 24 nameList.append(_("received: %s")%obj.receivedTime) 25 26 text=", ".join(nameList) 27 if obj.unread: 28 text="%s %s"%(_("unread"),text) 29 if obj.attachments.count>0: 30 text="%s %s"%(_("attachment"),text) 31 return text
32
33 -def getSentMessageString(obj):
34 nameList=[] 35 nameList.append(obj.to) 36 nameList.append(_("subject: %s")%obj.subject) 37 nameList.append(_("sent: %s")%obj.sentOn) 38 return ", ".join(nameList)
39
40 -class AppModule(appModuleHandler.AppModule):
41
42 - def _get_nativeOm(self):
43 if not getattr(self,'_nativeOm',None): 44 try: 45 nativeOm=comtypes.client.GetActiveObject("outlook.application",dynamic=True) 46 except (COMError,WindowsError): 47 nativeOm=None 48 self._nativeOm=nativeOm 49 return self._nativeOm
50
51 - def _get_outlookVersion(self):
52 nativeOm=self.nativeOm 53 if nativeOm: 54 outlookVersion=int(nativeOm.version.split('.')[0]) 55 else: 56 outlookVersion=0 57 return outlookVersion
58
59 - def event_NVDAObject_init(self,obj):
60 role=obj.role 61 windowClassName=obj.windowClassName 62 controlID=obj.windowControlID 63 #The control showing plain text messages has very stuffed parents 64 #Use the grandparent window as its parent 65 if role==controlTypes.ROLE_EDITABLETEXT and windowClassName=="RichEdit20W" and controlID==8224: 66 obj.parent=Window._get_parent(Window._get_parent(obj)) 67 #The control that shows HTML messages has stuffed parents. Use the control's parent window as its parent 68 if windowClassName=="Internet Explorer_Server" and role==controlTypes.ROLE_PANE and not isinstance(obj,MSHTML): 69 obj.parent=Window._get_parent(Window._get_parent(obj)) 70 if role in (controlTypes.ROLE_MENUBAR,controlTypes.ROLE_MENUITEM): 71 obj.description=None 72 if role in (controlTypes.ROLE_TREEVIEW,controlTypes.ROLE_TREEVIEWITEM,controlTypes.ROLE_LIST,controlTypes.ROLE_LISTITEM): 73 obj.shouldAllowIAccessibleFocusEvent=True 74 if ((windowClassName=="SUPERGRID" and controlID==4704) or (windowClassName=="rctrl_renwnd32" and controlID==109)) and role==controlTypes.ROLE_UNKNOWN: 75 obj.role=controlTypes.ROLE_LISTITEM
76
77 - def chooseNVDAObjectOverlayClasses(self, obj, clsList):
78 role=obj.role 79 windowClassName=obj.windowClassName 80 controlID=obj.windowControlID 81 if role==controlTypes.ROLE_LISTITEM and windowClassName=="OUTEXVLB": 82 clsList.insert(0, AddressBookEntry) 83 return 84 if (windowClassName=="SUPERGRID" and controlID==4704) or (windowClassName=="rctrl_renwnd32" and controlID==109): 85 outlookVersion=self.outlookVersion 86 if outlookVersion and outlookVersion<=9: 87 clsList.insert(0, MessageList_pre2003) 88 elif isinstance(obj,IAccessible) and obj.event_objectID==winUser.OBJID_CLIENT and obj.event_childID==0: 89 clsList.insert(0,SuperGridClient2010)
90
91 -class SuperGridClient2010(IAccessible):
92
93 - def isDuplicateIAccessibleEvent(self,obj):
94 return False
95
96 -class MessageList_pre2003(IAccessible):
97
98 - def _get_name(self):
99 if hasattr(self,'curMessageItem'): 100 return self.curMessageItem.msg.parent.name
101
102 - def _get_role(self):
104
105 - def _get_firstChild(self):
106 return getattr(self,"curMessageItem",None)
107
108 - def _get_children(self):
109 child=getattr(self,"curMessageItem",None) 110 if child: 111 return [child] 112 else: 113 return []
114
115 - def event_gainFocus(self):
116 try: 117 msg=self.nativeOm.ActiveExplorer().selection[0] 118 except: 119 msg=None 120 pass 121 if msg: 122 self.curMessageItem=MessageItem(self,msg) 123 super(MessageList_pre2003,self).event_gainFocus() 124 if msg: 125 eventHandler.executeEvent("gainFocus",self.curMessageItem)
126
127 - def script_moveByMessage(self,gesture):
128 if hasattr(self,'curMessageItem'): 129 oldEntryID=self.curMessageItem.msg.entryID 130 else: 131 oldEntryID=None 132 gesture.send() 133 try: 134 msg=self.nativeOm.ActiveExplorer().selection[0] 135 except: 136 msg=None 137 pass 138 if msg: 139 messageItem=MessageItem(self,msg) 140 newEntryID=messageItem.msg.entryID 141 if newEntryID!=oldEntryID: 142 self.curMessageItem=messageItem 143 eventHandler.executeEvent("gainFocus",messageItem)
144 145 __moveByMessageGestures = ( 146 "kb:downArrow", 147 "kb:upArrow", 148 "kb:home", 149 "kb:end", 150 "kb:delete", 151 ) 152
153 - def initOverlayClass(self):
154 for gesture in self.__moveByMessageGestures: 155 self.bindGesture(gesture, "moveByMessage")
156
157 -class MessageItem(Window):
158
159 - def __init__(self,windowHandle=None,parent=None,msg=None):
160 if not parent or not msg: 161 raise ArguementError("__init__ needs windowHandle, parent and msg arguments") 162 if not windowHandle: 163 windowHandle=parent.windowHandle 164 self.msg=msg 165 self.parent=parent 166 Window.__init__(self,windowHandle=windowHandle)
167
168 - def _get_name(self):
169 typeID=self.msg.Class 170 if typeID==40: 171 return getContactString(self.msg) 172 elif typeID==43: 173 return getReceivedMessageString(self.msg)
174
175 - def _get_role(self):
177
178 - def _get_states(self):
179 return frozenset([controlTypes.STATE_SELECTED])
180
181 -class AddressBookEntry(IAccessible):
182
183 - def script_moveByEntry(self,gesture):
184 gesture.send() 185 eventHandler.queueEvent("nameChange",self)
186 187 __moveByEntryGestures = ( 188 "kb:downArrow", 189 "kb:upArrow", 190 "kb:home", 191 "kb:end", 192 "kb:delete", 193 ) 194
195 - def initOverlayClass(self):
196 for gesture in self.__moveByEntryGestures: 197 self.bindGesture(gesture, "moveByEntry")
198