1
2
3
4
5
6
7 from comtypes import COMError
8 import comtypes.automation
9 import wx
10 import oleacc
11 import textInfos
12 import colors
13 import eventHandler
14 import gui
15 import winUser
16 import controlTypes
17 from . import Window
18 from .. import NVDAObjectTextInfo
19 import scriptHandler
20
21 xlA1 = 1
24 """A base that all Excel NVDAObjects inherit from, which contains some useful methods."""
25
26 @staticmethod
33
34 @staticmethod
36 return cell.Address(False, False, xlA1, external)
37
39 selection=self.excelWindowObject.Selection
40 if selection.Count>1:
41 obj=ExcelSelection(windowHandle=self.windowHandle,excelWindowObject=self.excelWindowObject,excelRangeObject=selection)
42 else:
43 obj=ExcelCell(windowHandle=self.windowHandle,excelWindowObject=self.excelWindowObject,excelCellObject=selection)
44 eventHandler.executeEvent("gainFocus",obj)
45
47 """An overlay class for Window for the EXCEL7 window class, which simply bounces focus to the active excel cell."""
48
51
54
56
57 role=controlTypes.ROLE_TABLE
58
59 - def __init__(self,windowHandle=None,excelWindowObject=None,excelWorksheetObject=None):
65
67 return self.excelWorksheetObject.name
68
70 if not super(ExcelWorksheet, self)._isEqual(other):
71 return False
72 return self.excelWorksheetObject.index == other.excelWorksheetObject.index
73
75 cell=self.excelWorksheetObject.cells(1,1)
76 return ExcelCell(windowHandle=self.windowHandle,excelWindowObject=self.excelWindowObject,excelCellObject=cell)
77
84 script_changeSelection.canPropagate=True
85
86 __changeSelectionGestures = (
87 "kb:tab",
88 "kb:shift+tab",
89 "kb:upArrow",
90 "kb:downArrow",
91 "kb:leftArrow",
92 "kb:rightArrow",
93 "kb:control+upArrow",
94 "kb:control+downArrow",
95 "kb:control+leftArrow",
96 "kb:control+rightArrow",
97 "kb:home",
98 "kb:end",
99 "kb:control+home",
100 "kb:control+end",
101 "kb:shift+upArrow",
102 "kb:shift+downArrow",
103 "kb:shift+leftArrow",
104 "kb:shift+rightArrow",
105 "kb:shift+control+upArrow",
106 "kb:shift+control+downArrow",
107 "kb:shift+control+leftArrow",
108 "kb:shift+control+rightArrow",
109 "kb:shift+home",
110 "kb:shift+end",
111 "kb:shift+control+home",
112 "kb:shift+control+end",
113 "kb:shift+space",
114 "kb:control+space",
115 "kb:control+pageUp",
116 "kb:control+pageDown",
117 "kb:control+v",
118 )
119
120 -class ExcelCellTextInfo(NVDAObjectTextInfo):
121
123 formatField=textInfos.FormatField()
124 fontObj=self.obj.excelCellObject.font
125 if formatConfig['reportFontName']:
126 formatField['font-name']=fontObj.name
127 if formatConfig['reportFontSize']:
128 formatField['font-size']=str(fontObj.size)
129 if formatConfig['reportFontAttributes']:
130 formatField['bold']=fontObj.bold
131 formatField['italic']=fontObj.italic
132 formatField['underline']=fontObj.underline
133 if formatConfig['reportColor']:
134 try:
135 formatField['color']=colors.RGB.fromCOLORREF(int(fontObj.color))
136 except COMError:
137 pass
138 try:
139 formatField['background-color']=colors.RGB.fromCOLORREF(int(self.obj.excelCellObject.interior.color))
140 except COMError:
141 pass
142 return formatField,(self._startOffset,self._endOffset)
143
145
146 @classmethod
148 windowHandle=kwargs['windowHandle']
149 excelWindowObject=cls.excelWindowObjectFromWindow(windowHandle)
150 if not excelWindowObject:
151 return False
152 if isinstance(relation,tuple):
153 excelCellObject=excelWindowObject.rangeFromPoint(relation[0],relation[1])
154 else:
155 excelCellObject=excelWindowObject.ActiveCell
156 if not excelCellObject:
157 return False
158 kwargs['excelWindowObject']=excelWindowObject
159 kwargs['excelCellObject']=excelCellObject
160 return True
161
162 - def __init__(self,windowHandle=None,excelWindowObject=None,excelCellObject=None):
163 self.excelWindowObject=excelWindowObject
164 self.excelCellObject=excelCellObject
165 super(ExcelCell,self).__init__(windowHandle=windowHandle)
166
167 role=controlTypes.ROLE_TABLECELL
168
169 TextInfo=ExcelCellTextInfo
170
172 if not super(ExcelCell,self)._isEqual(other):
173 return False
174 thisAddr=self.getCellAddress(self.excelCellObject,True)
175 try:
176 otherAddr=self.getCellAddress(other.excelCellObject,True)
177 except COMError:
178
179 return False
180 return thisAddr==otherAddr
181
184
186 return self.excelCellObject.Text
187
189 return _("has formula") if self.excelCellObject.HasFormula else ""
190
192 worksheet=self.excelCellObject.Worksheet
193 return ExcelWorksheet(windowHandle=self.windowHandle,excelWindowObject=self.excelWindowObject,excelWorksheetObject=worksheet)
194
196 try:
197 next=self.excelCellObject.next
198 except COMError:
199 next=None
200 if next:
201 return ExcelCell(windowHandle=self.windowHandle,excelWindowObject=self.excelWindowObject,excelCellObject=next)
202
210
212
213 role=controlTypes.ROLE_TABLECELL
214
215 - def __init__(self,windowHandle=None,excelWindowObject=None,excelRangeObject=None):
216 self.excelWindowObject=excelWindowObject
217 self.excelRangeObject=excelRangeObject
218 super(ExcelSelection,self).__init__(windowHandle=windowHandle)
219
224
226 firstCell=self.excelRangeObject.Item(1)
227 lastCell=self.excelRangeObject.Item(self.excelRangeObject.Count)
228 return _("%s %s through %s %s")%(self.getCellAddress(firstCell),firstCell.Text,self.getCellAddress(lastCell),lastCell.Text)
229
231 worksheet=self.excelRangeObject.Worksheet
232 return ExcelWorksheet(windowHandle=self.windowHandle,excelWindowObject=self.excelWindowObject,excelWorksheetObject=worksheet)
233
234
235 - def makeTextInfo(self,position):
239