Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some classes from the main gui module. #12105

Merged
merged 6 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def doStartupDialogs():
_("Configuration File Error"),
wx.OK | wx.ICON_EXCLAMATION)
if config.conf["general"]["showWelcomeDialogAtStartup"]:
gui.WelcomeDialog.run()
from gui.startupDialogs import WelcomeDialog
WelcomeDialog.run()
Comment on lines +82 to +83
Copy link
Member

@seanbudd seanbudd Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from gui.startupDialogs import WelcomeDialog
WelcomeDialog.run()
gui.startupDialogs.WelcomeDialog.run()

I think we are trying to avoid these imports that aren't at the top of file, or the most outer scope when this isn't possible. Since gui has already been imported at the top of doStartupDialogs, if you want to import WelcomeDialog directly, it would be preferable to add the from gui.startupDialogs import WelcomeDialog statement to the top of doStartupDialogs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a matter of style obviously, however since WelcomeDialog is used only for users who haven't disabled it so a very small percentage isn't it wasteful to always import it rather than do it conditionally as it is done now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, definitely a matter of preference. From a discussion with another developer these are fine as is. However in this case wouldn't there be no performance changes because the entire gui module has already been imported in the same scope?

if config.conf["brailleViewer"]["showBrailleViewerAtStartup"]:
gui.mainFrame.onToggleBrailleViewerCommand(evt=None)
if config.conf["speechViewer"]["showSpeechViewerAtStartup"]:
Expand All @@ -105,7 +106,7 @@ def onResult(ID):
except:
pass
# Ask the user if usage stats can be collected.
gui.runScriptModalDialog(gui.AskAllowUsageStatsDialog(None),onResult)
gui.runScriptModalDialog(gui.startupDialogs.AskAllowUsageStatsDialog(None), onResult)

def restart(disableAddons=False, debugLogging=False):
"""Restarts NVDA by starting a new copy."""
Expand Down Expand Up @@ -519,7 +520,8 @@ def handlePowerStatusChange(self):
except:
log.error("", exc_info=True)
if globalVars.appArgs.launcher:
gui.LauncherDialog.run()
from gui.startupDialogs import LauncherDialog
LauncherDialog.run()
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
# LauncherDialog will call doStartupDialogs() afterwards if required.
else:
wx.CallAfter(doStartupDialogs)
Expand Down
52 changes: 52 additions & 0 deletions source/documentationUtils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: UTF-8 -*-
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2006-2021 NV Access Limited, Łukasz Golonka
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html

import os
import sys

import globalVars
import languageHandler


def getDocFilePath(fileName, localized=True):
if not getDocFilePath.rootPath:
if hasattr(sys, "frozen"):
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "documentation")
else:
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "..", "user_docs")

if localized:
lang = languageHandler.getLanguage()
tryLangs = [lang]
if "_" in lang:
# This locale has a sub-locale, but documentation might not exist for the sub-locale, so try stripping it.
tryLangs.append(lang.split("_")[0])
# If all else fails, use English.
tryLangs.append("en")

fileName, fileExt = os.path.splitext(fileName)
for tryLang in tryLangs:
tryDir = os.path.join(getDocFilePath.rootPath, tryLang)
if not os.path.isdir(tryDir):
continue

# Some out of date translations might include .txt files which are now .html files in newer translations.
# Therefore, ignore the extension and try both .html and .txt.
for tryExt in ("html", "txt"):
tryPath = os.path.join(tryDir, f"{fileName}.{tryExt}")
if os.path.isfile(tryPath):
return tryPath
return None
else:
# Not localized.
if not hasattr(sys, "frozen") and fileName in ("copying.txt", "contributors.txt"):
# If running from source, these two files are in the root dir.
return os.path.join(globalVars.appDir, "..", fileName)
else:
return os.path.join(getDocFilePath.rootPath, fileName)


getDocFilePath.rootPath = None
Loading