Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement API changes for messageBox
  • Loading branch information
seanbudd committed Feb 22, 2022
commit c7680670b63fa5807ebef8c5ad793308f633d12e
25 changes: 11 additions & 14 deletions source/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import queueHandler
import core
from . import guiHelper
from buildVersion import version_year
from .message import (
isInMessageBox as _isInMessageBox,
# isInMessageBox is accessed through `gui.isInMessageBox`
# as opposed to `gui.message.isInMessageBox` throughout NVDA,
# be cautious when removing
isInMessageBox,
# messageBox is accessed through `gui.messageBox` as opposed to `gui.message.messageBox` throughout NVDA,
# be cautious when removing
messageBox,
Expand Down Expand Up @@ -61,11 +63,6 @@
### Globals
mainFrame = None

if version_year < 2022:
# Like other top level variables, this must be used as follows (#13011):
# import gui; doSomething(gui.isInMessageBox)
# NOT the following: from gui import isInMessageBox; doSomething(isInMessageBox)
isInMessageBox = False

class MainFrame(wx.Frame):

Expand Down Expand Up @@ -159,7 +156,7 @@ def onSaveConfigurationCommand(self,evt):
messageBox(_("Could not save configuration - probably read only file system"),_("Error"),wx.OK | wx.ICON_ERROR)

def _popupSettingsDialog(self, dialog, *args, **kwargs):
if _isInMessageBox():
if isInMessageBox():
return
self.prePopup()
try:
Expand Down Expand Up @@ -208,7 +205,7 @@ def evaluateUpdatePendingUpdateMenuItemCommand(self):
self.sysTrayIcon.menu.Insert(self.sysTrayIcon.installPendingUpdateMenuItemPos,self.sysTrayIcon.installPendingUpdateMenuItem)

def onExitCommand(self, evt):
if _isInMessageBox():
if isInMessageBox():
return
if config.conf["general"]["askToExit"]:
self.prePopup()
Expand Down Expand Up @@ -311,7 +308,7 @@ def onPythonConsoleCommand(self, evt):
pythonConsole.activate()

def onAddonsManagerCommand(self,evt):
if _isInMessageBox() or globalVars.appArgs.secure:
if isInMessageBox() or globalVars.appArgs.secure:
return
self.prePopup()
from .addonGui import AddonsDialog
Expand All @@ -327,7 +324,7 @@ def onReloadPluginsCommand(self, evt):
NVDAObject.clearDynamicClassCache()

def onCreatePortableCopyCommand(self,evt):
if _isInMessageBox():
if isInMessageBox():
return
self.prePopup()
import gui.installerGui
Expand All @@ -336,13 +333,13 @@ def onCreatePortableCopyCommand(self,evt):
self.postPopup()

def onInstallCommand(self, evt):
if _isInMessageBox():
if isInMessageBox():
return
from gui import installerGui
installerGui.showInstallGui()

def onRunCOMRegistrationFixesCommand(self, evt):
if _isInMessageBox():
if isInMessageBox():
return
if messageBox(
# Translators: A message to warn the user when starting the COM Registration Fixing tool
Expand Down Expand Up @@ -376,7 +373,7 @@ def onRunCOMRegistrationFixesCommand(self, evt):
)

def onConfigProfilesCommand(self, evt):
if _isInMessageBox():
if isInMessageBox():
return
self.prePopup()
from .configProfiles import ProfilesDialog
Expand Down
13 changes: 5 additions & 8 deletions source/gui/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

from buildVersion import version_year
import threading
from typing import Optional
import wx
Expand All @@ -15,7 +14,8 @@


def isInMessageBox() -> bool:
return _messageBoxCounter != 0
with _messageBoxCounterLock:
return _messageBoxCounter != 0


def messageBox(
Expand All @@ -34,21 +34,18 @@ def messageBox(
@return: Same as for wx.MessageBox.
"""
from gui import mainFrame
import gui
global _messageBoxCounter
with _messageBoxCounterLock:
_messageBoxCounter += 1
if version_year < 2022:
gui.isInMessageBox = True

try:
if not parent:
mainFrame.prePopup()
res = wx.MessageBox(message, caption, style, parent or mainFrame)
finally:
if not parent:
mainFrame.postPopup()
finally:
with _messageBoxCounterLock:
_messageBoxCounter -= 1
if version_year < 2022:
gui.isInMessageBox = isInMessageBox()

return res
1 change: 1 addition & 0 deletions user_docs/en/changes.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ This can dramatically decrease build times on multi core systems. (#13226)
- ``cachedAutomationId`` can be used if obtained directly from the element.
-
- ``NVDAObjects.window.scintilla.CharacterRangeStruct`` has moved to ``NVDAObjects.window.scintilla.Scintilla.CharacterRangeStruct``. (#13364)
- ``gui.isInMessageBox`` is now a function which returns a boolean. (#TODO)
-


Expand Down