I am trying to load a remote .py file in Thonny editor but I get the following error:
File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/editors.py", line 193, in _load_local_file
with open(filename, "rb") as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'https://raw.githubusercontent.com/thonny/thonny/3eaa0319a9722bcdac12b4401b0a69b47d2e9f00/thonny/first_run.py'
The file I am just using for testing purposes is the: https://github.com/thonny/thonny/blob/3eaa0319a9722bcdac12b4401b0a69b47d2e9f00/thonny/first_run.py
Any ideas why self.editor._load_file( ... )
does not understands that this is a remote file?
Here is my __init__.py
of my plugin:
class Exercise:
"""
Fetch exercise to the current loaded file.
Description
"""
def __init__(self) -> None:
"""Get the workbench to fetch and copy the fetched content to editor, later."""
self.workbench = get_workbench()
def load_exercise(self) -> None:
"""Handle the plugin execution."""
self.editor = self.workbench.get_editor_notebook().get_current_editor()
self.filename = self.editor.get_filename()
if self.filename is not None and self.filename[-3:] == ".py":
self.editor.save_file()
# self.filename = "/Users/limitcracker/Documents/Projects/ThonnyPlugin/test.py"
self.filename = "https://raw.githubusercontent.com/thonny/thonny/3eaa0319a9722bcdac12b4401b0a69b47d2e9f00/thonny/first_run.py"
self.editor._load_file(self.filename, keep_undo=True)
showinfo(title="Exercise Loader", message="OK")
def load_plugin(self) -> None:
"""
Load the plugin on runtime.
Using self.workbench.add_command(), the plugin is registered in Thonny
with all the given arguments.
"""
self.workbench.add_command(
command_id="load_exercise",
menu_name="tools",
command_label="Load Exercise",
handler=self.load_exercise,
default_sequence="<Control-Alt-c>",
extra_sequences=["<<CtrlAltCInText>>"],
)
if get_workbench() is not None:
run = Exercise().load_plugin()