1717import sayAllHandler
1818import eventHandler
1919import braille
20- from scriptHandler import script
20+ from scriptHandler import script , getLastScriptRepeatCount
2121import languageHandler
2222import ui
2323import NVDAHelper
7373wdMaximumNumberOfRows = 15
7474wdStartOfRangeColumnNumber = 16
7575wdMaximumNumberOfColumns = 18
76+ #Underline style
77+ wdUnderlineNone = 0
78+ wdUnderlineSingle = 1
79+ wdUnderlineWords = 2
80+ wdUnderlineDouble = 3
81+ wdUnderlineDotted = 4
82+ wdUnderlineThick = 6
83+ wdUnderlineDash = 7
84+ wdUnderlineDotDash = 9
85+ wdUnderlineDotDotDash = 10
86+ wdUnderlineWavy = 11
87+ wdUnderlineDottedHeavy = 20
88+ wdUnderlineDashHeavy = 23
89+ wdUnderlineDotDashHeavy = 25
90+ wdUnderlineDotDotDashHeavy = 26
91+ wdUnderlineWavyHeavy = 27
92+ wdUnderlineDashLong = 39
93+ wdUnderlineWavyDouble = 43
94+ wdUnderlineDashLongHeavy = 55
7695#Horizontal alignment
7796wdAlignParagraphLeft = 0
7897wdAlignParagraphCenter = 1
195214wdThemeColorText1 = 13
196215wdThemeColorText2 = 15
197216
217+ # WdCharacterCase enumeration
218+ wdNextCase = - 1
219+ wdLowerCase = 0
220+ wdUpperCase = 1
221+ wdTitleWord = 2
222+ wdTitleSentence = 4
223+ wdToggleCase = 5
224+ wdHalfWidth = 6
225+ wdFullWidth = 7
226+ wdKatakana = 8
227+ wdHiragana = 9
228+
198229# Word Field types
199230FIELD_TYPE_REF = 3 # cross reference field
200231FIELD_TYPE_HYPERLINK = 88 # hyperlink field
258289 wdRevisionCellMerge :_ ("cell merge" ),
259290}
260291
292+ wdUnderlineTypeDescriptions = {
293+ # Translators: an underline style in Microsoft Word as announced in the font window.
294+ wdUnderlineSingle :_ ("Single" ),
295+ # Translators: an underline style in Microsoft Word as announced in the font window.
296+ wdUnderlineWords :_ ("Words only" ),
297+ # Translators: an underline style in Microsoft Word as announced in the font window.
298+ wdUnderlineDouble :_ ("Double" ),
299+ # Translators: an underline style in Microsoft Word as announced in the font window.
300+ wdUnderlineDotted :_ ("Dotted" ),
301+ # Translators: an underline style in Microsoft Word as announced in the font window.
302+ wdUnderlineThick :_ ("Thick" ),
303+ # Translators: an underline style in Microsoft Word as announced in the font window.
304+ wdUnderlineDash :_ ("Dash" ),
305+ # Translators: an underline style in Microsoft Word as announced in the font window.
306+ wdUnderlineDotDash :_ ("Dot dash" ),
307+ # Translators: an underline style in Microsoft Word as announced in the font window.
308+ wdUnderlineDotDotDash :_ ("Dot dot dash" ),
309+ # Translators: an underline style in Microsoft Word as announced in the font window.
310+ wdUnderlineWavy :_ ("Wave" ),
311+ # Translators: an underline style in Microsoft Word as announced in the font window.
312+ wdUnderlineDottedHeavy :_ ("Dotted heavy" ),
313+ # Translators: an underline style in Microsoft Word as announced in the font window.
314+ wdUnderlineDashHeavy :_ ("Dashed heavy" ),
315+ # Translators: an underline style in Microsoft Word as announced in the font window.
316+ wdUnderlineDotDashHeavy :_ ("Dot dash heavy" ),
317+ # Translators: an underline style in Microsoft Word as announced in the font window.
318+ wdUnderlineDotDotDashHeavy :_ ("Dot dot dash heavy" ),
319+ # Translators: an underline style in Microsoft Word as announced in the font window.
320+ wdUnderlineWavyHeavy :_ ("Wave heavy" ),
321+ # Translators: an underline style in Microsoft Word as announced in the font window.
322+ wdUnderlineDashLong :_ ("Dashed long" ),
323+ # Translators: an underline style in Microsoft Word as announced in the font window.
324+ wdUnderlineWavyDouble :_ ("Wave double" ),
325+ # Translators: an underline style in Microsoft Word as announced in the font window.
326+ wdUnderlineDashLongHeavy :_ ("Dashed long heavy" ),
327+ }
328+
261329storyTypeLocalizedLabels = {
262330 wdCommentsStory :_ ("Comments" ),
263331 wdEndnotesStory :_ ("Endnotes" ),
271339 wdTextFrameStory :_ ("Text frame" ),
272340}
273341
342+ wdCharacterCaseTypeLabels = {
343+ # Translators: a Microsoft Word character case type
344+ wdNextCase : _ ("No case" ), #Returned when selection range contains only case-insensitive characters
345+ # Translators: a Microsoft Word character case type
346+ wdLowerCase : _ ("Lowercase" ),
347+ # Translators: a Microsoft Word character case type
348+ wdUpperCase : _ ("Uppercase" ),
349+ # Translators: a Microsoft Word character case type
350+ wdTitleWord : _ ("Each word capitalized" ),
351+ # Translators: a Microsoft Word character case type
352+ wdTitleSentence : _ ("Sentence case" ),
353+ # Translators: a Microsoft Word character case type
354+ wdToggleCase : _ ("Mixed case" ),
355+ # Translators: a Microsoft Word character case type
356+ wdHalfWidth : _ ("Half width:" ),
357+ # Translators: a Microsoft Word character case type
358+ wdFullWidth : _ ("Full width" ),
359+ # Translators: a Microsoft Word character case type
360+ wdKatakana : _ ("Katakana" ),
361+ # Translators: a Microsoft Word character case type
362+ wdHiragana : _ ("Hiragana" ),
363+ }
364+
274365wdFieldTypesToNVDARoles = {
275366 wdFieldFormTextInput :controlTypes .ROLE_EDITABLETEXT ,
276367 wdFieldFormCheckBox :controlTypes .ROLE_CHECKBOX ,
@@ -1228,6 +1319,31 @@ def _WaitForValueChangeForAction(self,action,fetcher,timeout=0.15):
12281319 curTime = time .time ()
12291320 return curVal
12301321
1322+ def modified_WaitForValueChangeForAction (self ,action ,fetcher ,timeout = 0.15 ):
1323+ oldVal = fetcher ()
1324+ action ()
1325+ startTime = curTime = time .time ()
1326+ curVal = fetcher ()
1327+ s = []
1328+ s .append ('oldVal = ' + str (oldVal ))
1329+ isSameScript = getLastScriptRepeatCount () > 0
1330+ retVal = None
1331+ s .append ('IsSameScript = ' + str (isSameScript ))
1332+ while (curTime - startTime )< timeout :
1333+ s .append (str (curTime ) + ' - ' + str (curVal ))
1334+ if curVal != oldVal and retVal is None :
1335+ retVal = curVal
1336+ s .append ('retVal = ' + str (curVal ))
1337+ time .sleep (0.002 )
1338+ curVal = fetcher ()
1339+ curTime = time .time ()
1340+ #if (not isSameScript) and curVal!=oldVal:
1341+ # break
1342+ s .append (str (curTime ) + ' - ' + str (curVal ))
1343+ log .debug ('\n ' .join (s ))
1344+ return retVal
1345+
1346+ @script (gestures = ["kb:control+b" ,"kb:control+shift+b" ])
12311347 def script_toggleBold (self ,gesture ):
12321348 if not self .WinwordSelectionObject :
12331349 # We cannot fetch the Word object model, so we therefore cannot report the format change.
@@ -1242,6 +1358,7 @@ def script_toggleBold(self,gesture):
12421358 # Translators: a message when toggling formatting in Microsoft word
12431359 ui .message (_ ("Bold off" ))
12441360
1361+ @script (gestures = ["kb:control+i" ,"kb:control+shift+i" ])
12451362 def script_toggleItalic (self ,gesture ):
12461363 if not self .WinwordSelectionObject :
12471364 # We cannot fetch the Word object model, so we therefore cannot report the format change.
@@ -1256,16 +1373,24 @@ def script_toggleItalic(self,gesture):
12561373 # Translators: a message when toggling formatting in Microsoft word
12571374 ui .message (_ ("Italic off" ))
12581375
1259- def script_toggleUnderline (self ,gesture ):
1376+ @script (gestures = ["kb:control+u" , "kb:control+shift+u" , "kb:control+shift+d" , "kb:control+shift+w" ])
1377+ def script_toggleUnderline (self , gesture ):
12601378 if not self .WinwordSelectionObject :
12611379 # We cannot fetch the Word object model, so we therefore cannot report the format change.
1262- # The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail, or its within Windows Defender Application Guard.
1263- # Eventually UIA will have its own way of detecting format changes at the cursor. For now, just let the gesture through and don't erport anything.
1380+ # The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
1381+ # or its within Windows Defender Application Guard.
1382+ # Eventually UIA will have its own way of detecting format changes at the cursor.
1383+ # For now, just let the gesture through and don't report anything.
12641384 return gesture .send ()
1265- val = self ._WaitForValueChangeForAction (lambda : gesture .send (),lambda : self .WinwordSelectionObject .font .underline )
1266- if val :
1267- # Translators: a message when toggling formatting in Microsoft word
1268- ui .message (_ ("Underline on" ))
1385+ val = self ._WaitForValueChangeForAction (
1386+ lambda : gesture .send (),
1387+ lambda : self .WinwordSelectionObject .font .underline
1388+ )
1389+ if val != wdUnderlineNone :
1390+ msg = wdUnderlineTypeDescriptions .get (val )
1391+ if msg :
1392+ # Translators: a message when toggling formatting in Microsoft word
1393+ ui .message (_ ("Underline {style}" ).format (style = msg ))
12691394 else :
12701395 # Translators: a message when toggling formatting in Microsoft word
12711396 ui .message (_ ("Underline off" ))
@@ -1291,6 +1416,51 @@ def script_toggleAlignment(self,gesture):
12911416 if msg :
12921417 ui .message (msg )
12931418
1419+ @script (gestures = ["kb:control+shift+a" , "kb:control+shift+k" ])
1420+ def script_toggleCaps (self , gesture ):
1421+ if not self .WinwordSelectionObject :
1422+ # We cannot fetch the Word object model, so we therefore cannot report the format change.
1423+ # The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
1424+ # or its within Windows Defender Application Guard.
1425+ # Eventually UIA will have its own way of detecting format changes at the cursor.
1426+ # For now, just let the gesture through and don't report anything.
1427+ return gesture .send ()
1428+ val = self ._WaitForValueChangeForAction (
1429+ lambda : gesture .send (),
1430+ lambda : (self .WinwordSelectionObject .font .allcaps , self .WinwordSelectionObject .font .smallcaps )
1431+ )
1432+ if val [0 ]:
1433+ # Translators: a message when toggling formatting to 'all capital' in Microsoft word
1434+ ui .message (_ ("All caps on" ))
1435+ elif val [1 ]:
1436+ # Translators: a message when toggling formatting to 'small capital' in Microsoft word
1437+ ui .message (_ ("Small caps on" ))
1438+ else :
1439+ # Translators: a message when toggling formatting to 'No capital' in Microsoft word
1440+ ui .message (_ ("Caps off" ))
1441+
1442+ @script (gesture = "kb:shift+f3" )
1443+ def script_changeCase (self , gesture ):
1444+ if not self .WinwordSelectionObject :
1445+ # We cannot fetch the Word object model, so we therefore cannot report the format change.
1446+ # The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
1447+ # or its within Windows Defender Application Guard.
1448+ # For now, just let the gesture through and don't report anything.
1449+ return gesture .send ()
1450+ val = self ._WaitForValueChangeForAction (
1451+ lambda : gesture .send (),
1452+ lambda : self .WinwordSelectionObject .Range .Case
1453+ )
1454+ # Under Outlook, calling the script quickly a second time gives strange results.
1455+ # Case value passes sometimes through an intermediate value.
1456+ # So poll the value a second time.
1457+ val = self ._WaitForValueChangeForAction (
1458+ lambda : None ,
1459+ lambda : self .WinwordSelectionObject .Range .Case
1460+ )
1461+ # Translators: a message when changing case in Microsoft Word
1462+ ui .message (wdCharacterCaseTypeLabels .get (val ))
1463+
12941464 def script_toggleSuperscriptSubscript (self ,gesture ):
12951465 if not self .WinwordSelectionObject :
12961466 # We cannot fetch the Word object model, so we therefore cannot report the format change.
@@ -1484,7 +1654,7 @@ def initOverlayClass(self):
14841654 "kb:control+shift+." :"increaseDecreaseFontSize" ,
14851655 "kb:control+b" :"toggleBold" ,
14861656 "kb:control+i" :"toggleItalic" ,
1487- "kb:control+u " :"toggleUnderline" ,
1657+ "kb:control+shift+d " :"toggleUnderline" ,
14881658 "kb:control+=" :"toggleSuperscriptSubscript" ,
14891659 "kb:control+shift+=" :"toggleSuperscriptSubscript" ,
14901660 "kb:control+l" :"toggleAlignment" ,
0 commit comments