diff --git a/hydrus/client/ClientPaths.py b/hydrus/client/ClientPaths.py index 52e94360..ce8c5184 100644 --- a/hydrus/client/ClientPaths.py +++ b/hydrus/client/ClientPaths.py @@ -1,9 +1,12 @@ import webbrowser +import os 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' ] @@ -34,3 +37,27 @@ def LaunchURLInWebBrowser( url ): HydrusPaths.LaunchFile( url, launch_path = web_browser_path ) +def OpenDocumentation( documentation_path : str ): + + local = os.path.join( HC.HELP_DIR, documentation_path ) + remote = "/".join((HC.REMOTE_HELP.rstrip("/"), documentation_path.lstrip("/"))) + + local_open = local + + if "#" in local: + + local = local[ :local.find("#") ] + + if os.path.isfile( local ): + + LaunchPathInWebBrowser( local_open ) + + 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 3ed9dc22..8514d8fe 100644 --- a/hydrus/client/gui/ClientGUI.py +++ b/hydrus/client/gui/ClientGUI.py @@ -3226,7 +3226,7 @@ class FrameGUI( CAC.ApplicationCommandProcessorMixin, ClientGUITopLevelWindows.M ClientGUIMenus.AppendMenu( menu, links, 'links' ) - ClientGUIMenus.AppendMenuItem( menu, 'changelog', 'Open hydrus\'s local changelog in your web browser.', ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'changelog.html' ) ) + ClientGUIMenus.AppendMenuItem( menu, 'changelog', 'Open hydrus\'s local changelog in your web browser.', ClientPaths.OpenDocumentation, HC.DOCUMENTATION_CHANGELOG ) ClientGUIMenus.AppendSeparator( menu ) @@ -4964,42 +4964,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/client/gui/ClientGUIDownloaders.py b/hydrus/client/gui/ClientGUIDownloaders.py index a168cb4e..507f3ba0 100644 --- a/hydrus/client/gui/ClientGUIDownloaders.py +++ b/hydrus/client/gui/ClientGUIDownloaders.py @@ -564,7 +564,7 @@ class EditGUGsPanel( ClientGUIScrolledPanels.EditPanel ): menu_items = [] - call = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_gugs.html' ) ) + call = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_GUGS ) menu_items.append( ( 'normal', 'open the gugs help', 'Open the help page for gugs in your web browser.', call ) ) @@ -2002,7 +2002,7 @@ class EditURLClassesPanel( ClientGUIScrolledPanels.EditPanel ): menu_items = [] - call = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_url_classes.html' ) ) + call = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_URL_CLASSES ) menu_items.append( ( 'normal', 'open the url classes help', 'Open the help page for url classes in your web browser.', call ) ) diff --git a/hydrus/client/gui/ClientGUILogin.py b/hydrus/client/gui/ClientGUILogin.py index 6ab797a0..8fa5ffa3 100644 --- a/hydrus/client/gui/ClientGUILogin.py +++ b/hydrus/client/gui/ClientGUILogin.py @@ -1305,7 +1305,7 @@ class EditLoginScriptPanel( ClientGUIScrolledPanels.EditPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_login.html' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_LOGIN ) menu_items.append( ( 'normal', 'open the login scripts help', 'Open the help page for login scripts in your web browser.', page_func ) ) diff --git a/hydrus/client/gui/ClientGUIScrolledPanelsReview.py b/hydrus/client/gui/ClientGUIScrolledPanelsReview.py index 6bffb783..775db7ec 100644 --- a/hydrus/client/gui/ClientGUIScrolledPanelsReview.py +++ b/hydrus/client/gui/ClientGUIScrolledPanelsReview.py @@ -142,7 +142,7 @@ class MigrateDatabasePanel( ClientGUIScrolledPanels.ReviewPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'database_migration.html' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DATABASE_MIGRATION ) menu_items.append( ( 'normal', 'open the html migration help', 'Open the help page for database migration in your web browser.', page_func ) ) @@ -1821,7 +1821,7 @@ class ReviewDownloaderImport( ClientGUIScrolledPanels.ReviewPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'adding_new_downloaders.html' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_ADDING_NEW_DOWNLOADERS ) menu_items.append( ( 'normal', 'open the easy downloader import help', 'Open the help page for easily importing downloaders in your web browser.', page_func ) ) diff --git a/hydrus/client/gui/ClientGUISubscriptions.py b/hydrus/client/gui/ClientGUISubscriptions.py index 2a032078..676d269d 100644 --- a/hydrus/client/gui/ClientGUISubscriptions.py +++ b/hydrus/client/gui/ClientGUISubscriptions.py @@ -132,7 +132,7 @@ class EditSubscriptionPanel( ClientGUIScrolledPanels.EditPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'getting_started_subscriptions.html' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_GETTING_STARTED_SUBSCRIPTIONS ) menu_items.append( ( 'normal', 'open the html subscriptions help', 'Open the help page for subscriptions in your web browser.', page_func ) ) @@ -1325,7 +1325,7 @@ class EditSubscriptionsPanel( ClientGUIScrolledPanels.EditPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'getting_started_subscriptions.html' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_GETTING_STARTED_SUBSCRIPTIONS ) menu_items.append( ( 'normal', 'open the html subscriptions help', 'Open the help page for subscriptions in your web browser.', page_func ) ) diff --git a/hydrus/client/gui/pages/ClientGUIManagementPanels.py b/hydrus/client/gui/pages/ClientGUIManagementPanels.py index b39c1d7a..e261c4f0 100644 --- a/hydrus/client/gui/pages/ClientGUIManagementPanels.py +++ b/hydrus/client/gui/pages/ClientGUIManagementPanels.py @@ -479,7 +479,7 @@ class ManagementPanelDuplicateFilter( ManagementPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'duplicates.html' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DUPLICATES ) menu_items.append( ( 'normal', 'open the html duplicates help', 'Open the help page for duplicates processing in your web browser.', page_func ) ) diff --git a/hydrus/client/gui/parsing/ClientGUIParsing.py b/hydrus/client/gui/parsing/ClientGUIParsing.py index d2778126..0daf88ec 100644 --- a/hydrus/client/gui/parsing/ClientGUIParsing.py +++ b/hydrus/client/gui/parsing/ClientGUIParsing.py @@ -52,7 +52,7 @@ class DownloaderExportPanel( ClientGUIScrolledPanels.ReviewPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_sharing.html' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_SHARING ) menu_items.append( ( 'normal', 'open the downloader sharing help', 'Open the help page for sharing downloaders in your web browser.', page_func ) ) @@ -498,7 +498,7 @@ class EditContentParserPanel( ClientGUIScrolledPanels.EditPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_parsers_content_parsers.html#content_parsers' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_PARSERS_CONTENT_PARSERS__CONTENT_PARSERS ) menu_items.append( ( 'normal', 'open the content parsers help', 'Open the help page for content parsers in your web browser.', page_func ) ) @@ -1185,7 +1185,7 @@ class EditPageParserPanel( ClientGUIScrolledPanels.EditPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_parsers_page_parsers.html#page_parsers' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_PARSERS_PAGE_PARSERS__PAGE_PARSERS ) menu_items.append( ( 'normal', 'open the page parser help', 'Open the help page for page parsers in your web browser.', page_func ) ) diff --git a/hydrus/client/gui/parsing/ClientGUIParsingFormulae.py b/hydrus/client/gui/parsing/ClientGUIParsingFormulae.py index a7a1b043..9759be70 100644 --- a/hydrus/client/gui/parsing/ClientGUIParsingFormulae.py +++ b/hydrus/client/gui/parsing/ClientGUIParsingFormulae.py @@ -49,7 +49,7 @@ class EditCompoundFormulaPanel( EditSpecificFormulaPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_parsers_formulae.html#compound_formula' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__COMPOUND_FORMULA ) menu_items.append( ( 'normal', 'open the compound formula help', 'Open the help page for compound formulae in your web browser.', page_func ) ) @@ -283,7 +283,7 @@ class EditContextVariableFormulaPanel( EditSpecificFormulaPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_parsers_formulae.html#context_variable_formula' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__CONTEXT_VARIABLE_FORMULA ) menu_items.append( ( 'normal', 'open the context variable formula help', 'Open the help page for context variable formulae in your web browser.', page_func ) ) @@ -748,7 +748,7 @@ class EditHTMLFormulaPanel( EditSpecificFormulaPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_parsers_formulae.html#html_formula' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__HTML_FORMULA ) menu_items.append( ( 'normal', 'open the html formula help', 'Open the help page for html formulae in your web browser.', page_func ) ) @@ -1107,7 +1107,7 @@ class EditJSONFormulaPanel( EditSpecificFormulaPanel ): menu_items = [] - page_func = HydrusData.Call( ClientPaths.LaunchPathInWebBrowser, os.path.join( HC.HELP_DIR, 'downloader_parsers_formulae.html#json_formula' ) ) + page_func = HydrusData.Call( ClientPaths.OpenDocumentation, HC.DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__JSON_FORMULA ) menu_items.append( ( 'normal', 'open the json formula help', 'Open the help page for json formulae in your web browser.', page_func ) ) diff --git a/hydrus/core/HydrusConstants.py b/hydrus/core/HydrusConstants.py index 7c365674..596c35fe 100644 --- a/hydrus/core/HydrusConstants.py +++ b/hydrus/core/HydrusConstants.py @@ -1205,6 +1205,29 @@ url_type_string_lookup = { URL_TYPE_SUB_GALLERY : 'sub-gallery url (is queued even if creator found no post/file urls)' } + + +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' +DOCUMENTATION_ADDING_NEW_DOWNLOADERS = 'adding_new_downloaders.html' +DOCUMENTATION_DOWNLOADER_URL_CLASSES = 'downloader_url_classes.html' +DOCUMENTATION_GETTING_STARTED_SUBSCRIPTIONS = 'getting_started_subscriptions.html' +DOCUMENTATION_DATABASE_MIGRATION = 'database_migration.html' +DOCUMENTATION_DUPLICATES = 'duplicates.html' +DOCUMENTATION_DOWNLOADER_SHARING = 'downloader_sharing.html' +DOCUMENTATION_DOWNLOADER_PARSERS_PAGE_PARSERS__PAGE_PARSERS = 'downloader_parsers_page_parsers.html#page_parsers' +DOCUMENTATION_DOWNLOADER_PARSERS_CONTENT_PARSERS__CONTENT_PARSERS = 'downloader_parsers_content_parsers.html#content_parsers' +DOCUMENTATION_DOWNLOADER_PARSERS_FORMULAE__COMPOUND_FORMULA = 'downloader_parsers_formulae.html#compound_formula' +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 DEFAULT_SERVER_ADMIN_PORT = 45870