tabreturn / thonny-py5mode

A py5 plug-in for Thonny
Do What The F*ck You Want To Public License
23 stars 8 forks source link

Feature idea: Menu command to 'open enclosing folder' #5

Closed villares closed 1 year ago

villares commented 2 years ago

I miss this from the Processing IDE, I had a proof of concept working, but I have since broken my Thonny env and I have yet to find my way again on how to play with its plug-ins...

    def open_folder(self) -> None:
        """Open the enclosing folder to the current file."""
        import subprocess
        import platform
        self.editor = self.workbench.get_editor_notebook().get_current_editor()
        try:
            filename = self.editor.get_filename()
        except AttributeError:
            print("Do you have an open file?")  # maybe a message?
            return
        else:
            path = os.path.dirname(filename)
            print(sys.platform)
        if sys.platform == 'darwin':
            subprocess.Popen(['open', path])
        elif sys.platform == 'linux':
            subprocess.Popen(["xdg-open", path])
        else: # 'win32'
            # os.startfile(path) # I should test this someday
            subprocess.Popen(["explorer", path])

    def load_plugin(self) -> None:
        ...  # other menus
        self.workbench.add_command(
            command_id='open_folder',
            menu_name='tools',
            command_label="Open enclosing folder",
            handler=self.open_folder,
            default_sequence='<Control-Alt-k>',
            extra_sequences=['<<CtrlAltKInText>>'],
        )
tabreturn commented 2 years ago

A neat idea, @villares! I'll look into this.

BTW: For thonny-py5mode development, I use the following setup (on Linux) --

I delete the "thonnycontrib" directory in ./local/lib/python3.9/sitepackages and replace this with a symlink/shortcut to my thonny-py5mode git repo directory. This way, no matter how badly I screw things up, I have a tracked history to roll back.

Also, I quite routinely delete the Thonny ~/.config/configuration.ini file for a clean slate.

tabreturn commented 2 years ago

Done

https://github.com/tabreturn/thonny-py5mode/commit/85da608011d2ff043d63ed2d1a5349443d711807

tabreturn commented 2 years ago

Maybe I should consider opening the enclosing folder in the Files pane (to the relevant path), which includes the option to open the location in the OS file manager

Screenshot from 2022-07-10 22-50-00

villares commented 2 years ago

I have missed the Files pane completely!

I was thinking these days it might be something nice to have in the tab context menu...

image

Curiously, I haven't upgraded to Thonny 4 in my main computer, só I still don't have this option in my Files pane.

villares commented 1 year ago

Thank you adding this!