|
8 | 8 | import ctypes |
9 | 9 | import enum |
10 | 10 | from typing import ( |
11 | | - Optional, Dict, |
| 11 | + Optional, Dict, Any |
12 | 12 | ) |
13 | 13 |
|
14 | 14 | from comtypes import COMError, BSTR |
|
39 | 39 | import mouseHandler |
40 | 40 | from displayModel import DisplayModelTextInfo |
41 | 41 | import controlTypes |
42 | | -from controlTypes import TextPosition |
| 42 | +from controlTypes import TextPosition, TextAlign, VerticalTextAlign |
43 | 43 | from . import Window |
44 | 44 | from .. import NVDAObjectTextInfo |
45 | 45 | import scriptHandler |
|
48 | 48 | import inputCore |
49 | 49 | import ctypes |
50 | 50 | import vision |
| 51 | +from utils.displayString import DisplayStringIntEnum |
| 52 | +import NVDAState |
51 | 53 |
|
52 | 54 | excel2010VersionMajor=14 |
53 | 55 |
|
54 | 56 | xlNone=-4142 |
55 | 57 | xlSimple=-4154 |
56 | 58 | xlExtended=3 |
57 | | -xlCenter=-4108 |
58 | | -xlJustify=-4130 |
59 | | -xlLeft=-4131 |
60 | | -xlRight=-4152 |
61 | | -xlDistributed=-4117 |
62 | | -xlBottom=-4107 |
63 | | -xlTop=-4160 |
| 59 | + |
| 60 | + |
| 61 | +class XlHAlign(DisplayStringIntEnum): |
| 62 | + # XlHAlign enumeration from https://docs.microsoft.com/en-us/office/vba/api/excel.xlhalign |
| 63 | + CENTER = -4108 |
| 64 | + CENTER_ACROSS_SELECTION = 7 |
| 65 | + DISTRIBUTED = -4117 |
| 66 | + FILL = 5 |
| 67 | + GENERAL = 1 |
| 68 | + JUSTIFY = -4130 |
| 69 | + LEFT = -4131 |
| 70 | + RIGHT = -4152 |
| 71 | + |
| 72 | + @property |
| 73 | + def _displayStringLabels(self): |
| 74 | + return _horizontalAlignmentLabels |
| 75 | + |
| 76 | + |
| 77 | +class XlVAlign(DisplayStringIntEnum): |
| 78 | + # XlVAlign enumeration from https://docs.microsoft.com/en-us/office/vba/api/excel.xlvalign |
| 79 | + BOTTOM = -4107 |
| 80 | + CENTER = -4108 |
| 81 | + DISTRIBUTED = -4117 |
| 82 | + JUSTIFY = -4130 |
| 83 | + TOP = -4160 |
| 84 | + |
| 85 | + @property |
| 86 | + def _displayStringLabels(self): |
| 87 | + return _verticalAlignmentLabels |
| 88 | + |
| 89 | + |
| 90 | +_horizontalAlignmentLabels = { |
| 91 | + XlHAlign.CENTER: TextAlign.CENTER, |
| 92 | + XlHAlign.CENTER_ACROSS_SELECTION: TextAlign.CENTER_ACROSS_SELECTION, |
| 93 | + XlHAlign.DISTRIBUTED: TextAlign.DISTRIBUTE, |
| 94 | + XlHAlign.FILL: TextAlign.FILL, |
| 95 | + XlHAlign.GENERAL: TextAlign.GENERAL, |
| 96 | + XlHAlign.JUSTIFY: TextAlign.JUSTIFY, |
| 97 | + XlHAlign.LEFT: TextAlign.LEFT, |
| 98 | + XlHAlign.RIGHT: TextAlign.RIGHT, |
| 99 | +} |
| 100 | + |
| 101 | +_verticalAlignmentLabels = { |
| 102 | + XlVAlign.BOTTOM: VerticalTextAlign.BOTTOM, |
| 103 | + XlVAlign.CENTER: VerticalTextAlign.CENTER, |
| 104 | + XlVAlign.DISTRIBUTED: VerticalTextAlign.DISTRIBUTE, |
| 105 | + XlVAlign.JUSTIFY: VerticalTextAlign.JUSTIFY, |
| 106 | + XlVAlign.TOP: VerticalTextAlign.TOP, |
| 107 | +} |
| 108 | + |
| 109 | + |
| 110 | +def __getattr__(attrName: str) -> Any: |
| 111 | + """Module level `__getattr__` used to preserve backward compatibility.""" |
| 112 | + _deprecatedConstantsMap = { |
| 113 | + "xlCenter": -4108, # XlHAlign.CENTER or XlVAlign.CENTER |
| 114 | + "xlJustify": -4130, # XlHAlign.JUSTIFY or XlVAlign.JUSTIFY |
| 115 | + "xlLeft": XlHAlign.LEFT.value, |
| 116 | + "xlRight": XlHAlign.RIGHT.value, |
| 117 | + "xlDistributed": -4117, # XlHAlign.DDISTRIBUTED or XlVAlign.DDISTRIBUTED |
| 118 | + "xlBottom": XlVAlign.BOTTOM.value, |
| 119 | + "xlTop": XlVAlign.TOP.value, |
| 120 | + "alignmentLabels": { |
| 121 | + XlHAlign.CENTER.value: "center", |
| 122 | + XlHAlign.JUSTIFY.value: "justify", |
| 123 | + XlHAlign.LEFT.value: "left", |
| 124 | + XlHAlign.RIGHT.value: "right", |
| 125 | + XlHAlign.DISTRIBUTED.value: "distributed", |
| 126 | + XlVAlign.BOTTOM.value: "botom", |
| 127 | + XlVAlign.TOP.value: "top", |
| 128 | + 1: "default", |
| 129 | + } |
| 130 | + } |
| 131 | + if attrName in _deprecatedConstantsMap and NVDAState._allowDeprecatedAPI(): |
| 132 | + replacementSymbol = _deprecatedConstantsMap[attrName] |
| 133 | + log.warning( |
| 134 | + f"Importing {attrName} from here is deprecated. " |
| 135 | + f"Import XlVAlign or XlHAlign enumerations instead.", |
| 136 | + stack_info=True, |
| 137 | + ) |
| 138 | + return replacementSymbol |
| 139 | + raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}") |
| 140 | + |
| 141 | + |
64 | 142 | xlDown=-4121 |
65 | 143 | xlToLeft=-4159 |
66 | 144 | xlToRight=-4161 |
67 | 145 | xlUp=-4162 |
68 | 146 | xlCellWidthUnitToPixels = 7.5919335705812574139976275207592 |
69 | 147 | xlSheetVisible=-1 |
70 | | -alignmentLabels={ |
71 | | - xlCenter:"center", |
72 | | - xlJustify:"justify", |
73 | | - xlLeft:"left", |
74 | | - xlRight:"right", |
75 | | - xlDistributed:"distributed", |
76 | | - xlBottom:"botom", |
77 | | - xlTop:"top", |
78 | | - 1:"default", |
79 | | -} |
80 | 148 |
|
81 | 149 | xlA1 = 1 |
82 | 150 | xlRC = 2 |
@@ -1097,11 +1165,17 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True): |
1097 | 1165 | cellObj=self.obj.excelCellObject |
1098 | 1166 | fontObj=cellObj.font |
1099 | 1167 | if formatConfig['reportAlignment']: |
1100 | | - value=alignmentLabels.get(self.obj.excelCellObject.horizontalAlignment) |
1101 | | - if value: |
| 1168 | + try: |
| 1169 | + value = XlHAlign(self.obj.excelCellObject.horizontalAlignment).displayString |
| 1170 | + except ValueError: |
| 1171 | + pass |
| 1172 | + else: |
1102 | 1173 | formatField['text-align']=value |
1103 | | - value=alignmentLabels.get(self.obj.excelCellObject.verticalAlignment) |
1104 | | - if value: |
| 1174 | + try: |
| 1175 | + value = XlVAlign(self.obj.excelCellObject.verticalAlignment).displayString |
| 1176 | + except ValueError: |
| 1177 | + pass |
| 1178 | + else: |
1105 | 1179 | formatField['vertical-align']=value |
1106 | 1180 | if formatConfig['reportFontName']: |
1107 | 1181 | formatField['font-name']=fontObj.name |
|
0 commit comments