From 1d1fb3c12535ec727e32ff2792ddce2c41bd447a Mon Sep 17 00:00:00 2001 From: Minnowo <62451415+Minnowo@users.noreply.github.com> Date: Mon, 24 Jul 2023 01:58:07 -0400 Subject: [PATCH] added confirmation dialog before opening online help --- hydrus/client/ClientPaths.py | 8 +++++ hydrus/client/gui/ClientGUI.py | 38 ++-------------------- hydrus/client/gui/ClientGUIDialogsQuick.py | 29 ++++++++++++++++- hydrus/core/HydrusConstants.py | 3 +- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/hydrus/client/ClientPaths.py b/hydrus/client/ClientPaths.py index ec00d0dd..ce8c5184 100644 --- a/hydrus/client/ClientPaths.py +++ b/hydrus/client/ClientPaths.py @@ -5,6 +5,8 @@ from hydrus.core import HydrusConstants as HC from hydrus.core import HydrusGlobals as HG from hydrus.core import HydrusPaths +from hydrus.client.gui import ClientGUIDialogsQuick + def DeletePath( path, always_delete_fully = False ): delete_to_recycle_bin = HC.options[ 'delete_to_recycle_bin' ] @@ -52,4 +54,10 @@ def OpenDocumentation( documentation_path : str ): else: + remote = ClientGUIDialogsQuick.ConfirmOpenOnlineHelpIfLocalDoesntExist( None, remote ) + + if remote is None: + + return + LaunchURLInWebBrowser( remote ) diff --git a/hydrus/client/gui/ClientGUI.py b/hydrus/client/gui/ClientGUI.py index 48400dcb..e8247a5e 100644 --- a/hydrus/client/gui/ClientGUI.py +++ b/hydrus/client/gui/ClientGUI.py @@ -4963,42 +4963,8 @@ class FrameGUI( CAC.ApplicationCommandProcessorMixin, ClientGUITopLevelWindows.M def _OpenHelp( self ): - - help_path = os.path.join( HC.HELP_DIR, 'index.html' ) - - if os.path.exists( help_path ): - - ClientPaths.LaunchPathInWebBrowser( help_path ) - - else: - - message = 'You do not have a local help! Are you running from source? Would you like to open the online help or see a guide on how to build your own?' - - yes_tuples = [] - - yes_tuples.append( ( 'open online help', 0 ) ) - yes_tuples.append( ( 'open how to build guide', 1 ) ) - - try: - - result = ClientGUIDialogsQuick.GetYesYesNo( self, message, yes_tuples = yes_tuples, no_label = 'forget it' ) - - except HydrusExceptions.CancelledException: - - return - - - if result == 0: - - url = 'https://hydrusnetwork.github.io/hydrus/' - - elif result == 1: - - url = 'https://hydrusnetwork.github.io/hydrus/about_docs.html' - - - ClientPaths.LaunchURLInWebBrowser( url ) - + + ClientPaths.OpenDocumentation( HC.DOCUMENTATION_INDEX ) def _OpenInstallFolder( self ): diff --git a/hydrus/client/gui/ClientGUIDialogsQuick.py b/hydrus/client/gui/ClientGUIDialogsQuick.py index 0678d55c..b3ea2f8d 100644 --- a/hydrus/client/gui/ClientGUIDialogsQuick.py +++ b/hydrus/client/gui/ClientGUIDialogsQuick.py @@ -255,4 +255,31 @@ def SelectServiceKey( service_types = None, service_keys = None, unallowed = Non return None - +def ConfirmOpenOnlineHelpIfLocalDoesntExist( dialog_owner, online_help_link : str ) -> str: + + message = 'You do not have a local help! Are you running from source? Would you like to open the online help or see a guide on how to build your own?' + + yes_tuples = [] + + yes_tuples.append( ( 'open online help', 0 ) ) + yes_tuples.append( ( 'open how to build guide', 1 ) ) + + try: + + result = GetYesYesNo( dialog_owner, message, yes_tuples = yes_tuples, no_label = 'forget it' ) + + except HydrusExceptions.CancelledException: + + return + + + if result == 0: + + url = online_help_link + + elif result == 1: + + url = "/".join( ( HC.REMOTE_HELP.rstrip("/"), HC.DOCUMENTATION_ABOUT_DOCS.lstrip("/") ) ) + + return url + diff --git a/hydrus/core/HydrusConstants.py b/hydrus/core/HydrusConstants.py index e81b57a6..569480ac 100644 --- a/hydrus/core/HydrusConstants.py +++ b/hydrus/core/HydrusConstants.py @@ -1098,6 +1098,7 @@ url_type_string_lookup = { REMOTE_HELP = "https://hydrusnetwork.github.io/hydrus" +DOCUMENTATION_INDEX = "index.html" DOCUMENTATION_CHANGELOG = f"changelog.html#version_{SOFTWARE_VERSION}" DOCUMENTATION_DOWNLOADER_GUGS = "downloader_gugs.html" DOCUMENTATION_DOWNLOADER_LOGIN = 'downloader_login.html' @@ -1113,7 +1114,7 @@ DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__COMPOUND_FORMULA = 'downloader_parser DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__CONTEXT_VARIABLE_FORMULA = 'downloader_parsers_formulae.html#context_variable_formula' DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__HTML_FORMULA = 'downloader_parsers_formulae.html#html_formula' DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__JSON_FORMULA = 'downloader_parsers_formulae.html#json_formula' - +DOCUMENTATION_ABOUT_DOCS = "about_docs.html" # default options