opengeos / WhiteboxTools-ArcGIS

ArcGIS Python Toolbox for WhiteboxTools
https://www.whiteboxgeo.com/manual/wbt_book/intro.html
MIT License
269 stars 66 forks source link

Enhancement to View Code tool #15

Closed Hornbydd closed 4 years ago

Hornbydd commented 4 years ago

This is a useful tool that generates a URL for the source code but I would like to suggest it takes it one step further and actually take you to the web page. Why else would you use this tool if not for reviewing the code?

To make my suggestion work you would need to include the following import at the top of the file:

import webbrowser

Then replace the following code in the execute() function for the ViewCode class with the following:

    def execute(self, parameters, messages):
        """The source code of the tool."""
        param0 = parameters[0].valueAsText
        tool_name = param0.replace(" ", "").strip()        
        messages.addMessage("Opening default browser...")
        webbrowser.get('windows-default').open(wbt.view_code(tool_name))
        messages.addMessage(wbt.view_code(tool_name))
        return

A small tweak that would make this tool more helpful.

giswqs commented 4 years ago

@Hornbydd I appreciate your suggestion. However, I don't think it would be necessary to open the browser every time a WBT tool is being used. This can be problematic when users are calling a set of WBT tools using arcpy. Since the URLs are available on each tool dialog, uses can choose to view the source code if they wish. The ArcToolbox and WBT Runner provide similar functionalities.

Hornbydd commented 4 years ago

@giswqs The enhancement I am suggesting is ONLY for your ViewCode tool in the About WhiteboxTools toolset, not ALL tools.

I would agree a web browser opening when you open any tool would be irritating. I'm suggesting a tweak to the tool that is specifically designed to give you a URL to the source code.

giswqs commented 4 years ago

@Hornbydd Sorry, I misunderstood your point earlier. I just committed code that incorporates your suggestion. The View Code tool will now open a browser and navigate to the GitHub source code.