diff --git a/fsl/__init__.py b/fsl/__init__.py index d80e672baeaf78374a52a522603e8d4d5d981a6b..a99ecb4f6034754a1869c162feb7605473ba2495 100644 --- a/fsl/__init__.py +++ b/fsl/__init__.py @@ -289,7 +289,7 @@ def _loadFSLTool(moduleName): # Each FSL tool module may specify several things toolName = getattr(module, 'FSL_TOOLNAME', None) - helpPage = getattr(module, 'FSL_HELPPAGE', 'index') + helpPage = getattr(module, 'FSL_HELPPAGE', None) init = getattr(module, 'FSL_INIT', None) parseArgs = getattr(module, 'FSL_PARSEARGS', None) context = getattr(module, 'FSL_CONTEXT', None) @@ -600,10 +600,16 @@ def _buildGUI(args, fslTool, toolCtx): actions = [] + def help(ev): + if fslTool.helpPage is not None: + webpage.openPage(fslTool.helpPage) + else: + webpage.openLocalHelp(fslTool.toolName) + actions.append(( wx.ID_HELP, '{} Help'.format(fslTool.toolName), - lambda *ev: webpage.openFSLHelp(fslTool.helpPage))) + help)) for (name, func) in fslTool.actions: actions.append((wx.ID_ANY, name, lambda ev, f=func: f(frame, toolCtx))) diff --git a/fsl/tools/bet.py b/fsl/tools/bet.py index cb0fe09ff5ecc79c9cb954f8c0a515fb66850210..4b81d2963fe95a072a18ae1ee3d8d3292081af8c 100644 --- a/fsl/tools/bet.py +++ b/fsl/tools/bet.py @@ -336,7 +336,6 @@ def runBet(parent, opts): FSL_TOOLNAME = 'BET' -FSL_HELPPAGE = 'bet' FSL_CONTEXT = lambda *a: Options() FSL_INTERFACE = interface FSL_ACTIONS = [('Run BET', runBet)] diff --git a/fsl/tools/feat.py b/fsl/tools/feat.py index b0a30e73efbbdc35ef3b9a6e0a8fe24c3b5032b2..38451096ba84edda15e4da99e6e1a035f9ef7ebe 100644 --- a/fsl/tools/feat.py +++ b/fsl/tools/feat.py @@ -551,6 +551,5 @@ def interface(parent, args, featOpts): FSL_TOOLNAME = 'FEAT' -FSL_HELPPAGE = 'feat' FSL_CONTEXT = lambda *a: Options() FSL_INTERFACE = interface diff --git a/fsl/tools/flirt.py b/fsl/tools/flirt.py index b89c3bcac26afadda4ca41afa2186bd834271d2b..3529c616c6494e2a01b00044ad683da0d78ae303 100644 --- a/fsl/tools/flirt.py +++ b/fsl/tools/flirt.py @@ -195,7 +195,6 @@ def interface(parent, args, opts): FSL_TOOLNAME = 'FLIRT' -FSL_HELPPAGE = 'flirt' FSL_CONTEXT = lambda *a: Options() FSL_INTERFACE = interface FSL_ACTIONS = [('Run FLIRT', runFlirt)] diff --git a/fsl/utils/webpage.py b/fsl/utils/webpage.py index a8d15ffb6cc6faa92386976f2baa69ac562420bc..c532ec23d9104ed042111311783e4a3373086196 100644 --- a/fsl/utils/webpage.py +++ b/fsl/utils/webpage.py @@ -13,38 +13,50 @@ The following functions are provided: :nosignatures: openPage - openFSLHelp + localHelpUrl + openLocalHelp """ -import os -import webbrowser +import os +import os.path as op +import webbrowser def openPage(url): """Opens the given URL in the system-default web browser.""" webbrowser.open(url) - -def openFSLHelp(toolName): - """Attempts to open the FSL help documentation for the given FSL tool. - If the ``$FSLDIR`` environment variable is not set, pops up a warning - message instead. + +def localHelpUrl(toolName): + """Checks the ``$FSLDIR`` to see if a local help page exists for the + FSL tool with the specified name. """ + fsldir = os.environ.get('FSLDIR', None) - import wx + if fsldir is None: + return None - fsldir = os.environ.get('FSLDIR', None) - url = 'file://{}/doc/redirects/{}.html'.format(fsldir, toolName) + toolName = toolName.lower() + localUrl = op.join(fsldir, 'doc', 'redirects', '{}.html'.format(toolName)) + + if op.exists(localUrl): + import urlparse + import urllib + return urlparse.urljoin( + 'file:', urllib.pathname2url(localUrl)) - if fsldir is not None: - openPage(url) + return None + + +def openLocalHelp(toolName): + """Attempts to open the locally hosted FSL help documentation + for the given FSL tool. If there is no help page for the + given tool, attempts to open the FSL wiki. + """ - else: + localUrl = localHelpUrl(toolName) - msg = 'The FSLDIR environment variable is not set - I don\'t '\ - 'know where to find the FSL documentation.' + if localUrl is None: + localUrl = "http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/" - wx.MessageDialog( - None, - message=msg, - style=wx.OK | wx.ICON_ERROR).ShowModal() + openPage(localUrl)