|
30 | 30 | # messageBox is accessed through `gui.messageBox` as opposed to `gui.message.messageBox` throughout NVDA, |
31 | 31 | # be cautious when removing |
32 | 32 | messageBox, |
| 33 | + displayDialogAsModal, |
33 | 34 | ) |
| 35 | +from .nvdaControls import MessageDialog |
34 | 36 | from . import blockAction |
35 | 37 | from .speechDict import ( |
36 | 38 | DefaultDictionaryDialog, |
|
67 | 69 | import speechViewer |
68 | 70 | import winUser |
69 | 71 | import api |
| 72 | +import gui.contextHelp as contextHelp |
70 | 73 | import NVDAState |
71 | 74 |
|
72 | 75 |
|
@@ -438,35 +441,96 @@ def onInstallCommand(self, evt): |
438 | 441 | blockAction.Context.SECURE_MODE, |
439 | 442 | blockAction.Context.MODAL_DIALOG_OPEN, |
440 | 443 | ) |
441 | | - def onRunCOMRegistrationFixesCommand(self, evt): |
442 | | - if messageBox( |
443 | | - # Translators: A message to warn the user when starting the COM Registration Fixing tool |
444 | | - _("You are about to run the COM Registration Fixing tool. This tool will try to fix common system problems that stop NVDA from being able to access content in many programs including Firefox and Internet Explorer. This tool must make changes to the System registry and therefore requires administrative access. Are you sure you wish to proceed?"), |
445 | | - # Translators: The title of the warning dialog displayed when launching the COM Registration Fixing tool |
446 | | - _("Warning"),wx.YES|wx.NO|wx.ICON_WARNING,self |
447 | | - )==wx.NO: |
| 444 | + def onRunCOMRegistrationFixesCommand(self, evt) -> None: |
| 445 | + """Manages the interactive running of the COM Registration Fixing Tool. |
| 446 | + Shows a dialog to the user, giving an overview of what is going to happen. |
| 447 | + If the user chooses to continue: runs the tool, and displays a completion dialog. |
| 448 | + Cancels the run attempt if the user fails or declines the UAC prompt. |
| 449 | + """ |
| 450 | + # Translators: Explain the COM Registration Fixing tool to users before running |
| 451 | + introMessage: str = _( |
| 452 | +"""Welcome to the COM Registration Fixing tool. |
| 453 | +This tool is used by NVDA to fix problems it may have as it tries to interact with various applications, or with Windows itself.\n |
| 454 | + It examines the system registry for corrupted or missing accessibility entries and will correct them.\n |
| 455 | +Those entries can sometimes be damaged by installing or uninstalling programs, or other system events. This can result in "unknown" or "pane" being spoken instead of the content you were expecting, or previously accessible elements suddenly no longer reading correctly.\n\n |
| 456 | + You have most likely been asked to run this tool by NVDA support or a power user trying to assist you.\n |
| 457 | +Because it needs to modify the Windows registry, if you have User Account Control (UAC) active, you will be prompted by UAC before this tool can do its job. This is normal and you should answer by pressing the yes button.\n\n |
| 458 | +Do you wish to try to repair the registry now?\n""" # noqa: E501 Flake8 sees this block as one line |
| 459 | + ) |
| 460 | + # Translators: The title of various dialogs displayed when using the COM Registration Fixing tool |
| 461 | + genericTitle: str = _("Fix COM Registrations") |
| 462 | + '''class CRFTInfoPromptDialog(MessageDialog): |
| 463 | + def _addButtons(self, buttonHelper): |
| 464 | + """Adds continue / cancel buttons. |
| 465 | + """ |
| 466 | + continueButton = buttonHelper.addButton( |
| 467 | + self, |
| 468 | + id=wx.ID_OK, |
| 469 | + # Translators: a button in the COM Registration Fixing Tool info dialog which will run the tool. |
| 470 | + label=_("&Continue") |
| 471 | + ) |
| 472 | + continueButton.SetDefault() |
| 473 | + continueButton.Bind(wx.EVT_BUTTON, lambda evt: self.EndModal(wx.OK)) |
| 474 | + cancel = buttonHelper.addButton( |
| 475 | + self, |
| 476 | + id=wx.ID_CANCEL, |
| 477 | + # Translators: Cancels the COM Registration Fixing Tool. |
| 478 | + label=_("Cancel") |
| 479 | + ) |
| 480 | + cancel.Bind(wx.EVT_BUTTON, lambda evt: self.EndModal(wx.CANCEL)) |
| 481 | + #response = displayDialogAsModal(CRFTInfoPromptDialog( |
| 482 | + ''' |
| 483 | + response: int = messageBox( |
| 484 | + introMessage, |
| 485 | + caption=genericTitle, |
| 486 | + style=wx.YES_NO | wx.CANCEL | wx.STAY_ON_TOP, |
| 487 | + parent=self |
| 488 | + ) |
| 489 | + if response == wx.CANCEL or response == wx.NO: |
| 490 | + log.debug("Run of COM Registration Fixing Tool canceled before UAC.") |
448 | 491 | return |
449 | | - progressDialog = IndeterminateProgressDialog(mainFrame, |
450 | | - # Translators: The title of the dialog presented while NVDA is running the COM Registration fixing tool |
451 | | - _("COM Registration Fixing Tool"), |
452 | | - # Translators: The message displayed while NVDA is running the COM Registration fixing tool |
453 | | - _("Please wait while NVDA tries to fix your system's COM registrations.") |
| 492 | + progressDialog = IndeterminateProgressDialog( |
| 493 | + mainFrame, |
| 494 | + genericTitle, |
| 495 | + # Translators: The message displayed while NVDA is running the COM Registration fixing tool |
| 496 | + _("Please wait while NVDA attempts to fix your system's COM registrations...") |
454 | 497 | ) |
| 498 | + error: Optional[str] = None |
455 | 499 | try: |
456 | 500 | systemUtils.execElevated(config.SLAVE_FILENAME, ["fixCOMRegistrations"]) |
457 | | - except: |
458 | | - log.error("Could not execute fixCOMRegistrations command",exc_info=True) |
459 | | - progressDialog.done() |
460 | | - del progressDialog |
| 501 | + except WindowsError as e: |
| 502 | + # 1223 is "The operation was canceled by the user." |
| 503 | + if e.winerror == 1223: |
| 504 | + # Same as if the user selected "no" in the initial dialog. |
| 505 | + log.debug("Run of COM Registration Fixing Tool canceled during UAC.") |
| 506 | + return |
| 507 | + else: |
| 508 | + log.error("Could not execute fixCOMRegistrations command", exc_info=True) |
| 509 | + error = e # Hold for later display to the user |
| 510 | + return # Safe because of finally block |
| 511 | + except Exception as e: |
| 512 | + log.error("Could not execute fixCOMRegistrations command", exc_info=True) |
| 513 | + return |
| 514 | + finally: # Clean up the progress dialog, and display any important error to the user before returning |
| 515 | + progressDialog.done() |
| 516 | + del progressDialog |
| 517 | + self.postPopup() |
| 518 | + # If there was a Windows error, inform the user because it may have support value |
| 519 | + if error is not None: |
| 520 | + messageBox( |
| 521 | + _( |
| 522 | + # Translators: message shown to the user on COM Registration Fix fail |
| 523 | + "The COM Registration Fixing Tool was unsuccessful. This Windows " |
| 524 | + "error may provide more information. {}" |
| 525 | + ).format(error), |
| 526 | + # Translators: Added to the title of the dialog showing the COM Registration Fix failure |
| 527 | + genericTitle + " " + _("Failed"), wx.OK |
| 528 | + ) |
| 529 | + # Display success dialog if there were no errors |
461 | 530 | messageBox( |
462 | | - _( |
463 | | - # Translators: The message displayed when the COM Registration Fixing tool completes. |
464 | | - "The COM Registration Fixing tool has finished. " |
465 | | - "It is highly recommended that you restart your computer now, to make sure the changes take full effect." |
466 | | - ), |
467 | | - # Translators: The title of a dialog presented when the COM Registration Fixing tool is complete. |
468 | | - _("COM Registration Fixing Tool"), |
469 | | - wx.OK |
| 531 | + # Translators: Message shown when the COM Registration Fixing tool completes. |
| 532 | + _("The COM Registration Fixing Tool has completed successfully."), |
| 533 | + genericTitle, wx.OK |
470 | 534 | ) |
471 | 535 |
|
472 | 536 | @blockAction.when(blockAction.Context.MODAL_DIALOG_OPEN) |
|
0 commit comments