|
7 | 7 | import os |
8 | 8 | import pathlib |
9 | 9 | import platform |
10 | | -import py5_tools |
11 | 10 | import pyperclip |
12 | 11 | import shutil |
13 | 12 | import site |
14 | 13 | import subprocess |
15 | 14 | import sys |
16 | 15 | import tkinter as tk |
| 16 | +import types |
17 | 17 | import webbrowser |
18 | 18 | from .about_plugin import add_about_py5mode_command, open_about_plugin |
19 | 19 | from .install_jdk import install_jdk |
20 | 20 | from distutils.sysconfig import get_python_lib |
21 | | -from importlib import util |
| 21 | +from importlib import machinery, util |
22 | 22 | from thonny import editors, get_workbench, get_runner, running, token_utils |
23 | 23 | from thonny.common import BackendEvent |
24 | 24 | from thonny.languages import tr |
@@ -100,8 +100,14 @@ def patched_execute_current(self: Runner, command_name: str) -> None: |
100 | 100 |
|
101 | 101 | def patch_token_coloring() -> None: |
102 | 102 | '''add py5 keywords to syntax highlighting''' |
103 | | - py5_dir_str = py5_tools.reference.PY5_DIR_STR |
104 | | - patched_builtinlist = token_utils._builtinlist + py5_dir_str |
| 103 | + spec = util.find_spec('py5_tools') |
| 104 | + # cannot use `dir(py5)` because of jvm check, hence direct loading |
| 105 | + path = pathlib.Path(spec.submodule_search_locations[0]) / 'reference.py' |
| 106 | + loader = machinery.SourceFileLoader('py5_tools_reference', str(path)) |
| 107 | + module = types.ModuleType(loader.name) |
| 108 | + loader.exec_module(module) |
| 109 | + # add keywords to thonny builtin list |
| 110 | + patched_builtinlist = token_utils._builtinlist + module.PY5_ALL_STR |
105 | 111 | matches = token_utils.matches_any('builtin', patched_builtinlist) |
106 | 112 | patched_BUILTIN = r'([^.\'"\\#]\b|^)' + (matches + r'\b') |
107 | 113 | token_utils.BUILTIN = patched_BUILTIN |
@@ -181,19 +187,6 @@ def patched_handle_program_output(self, msg: BackendEvent) -> None: |
181 | 187 | BaseShellText._original_handle_program_output(self, msg) |
182 | 188 |
|
183 | 189 |
|
184 | | -conversion_tools_menu = tk.Menu(tearoff=0) |
185 | | -# items for the menu: py5 > Conversion tools |
186 | | -conversion_tools_menu.add_command( |
187 | | - label='Processing.py → py5 imported mode', |
188 | | - command=lambda: convert_code(py5_tools.translators.processingpy2imported)) |
189 | | -conversion_tools_menu.add_command( |
190 | | - label='py5 module mode → imported mode', |
191 | | - command=lambda: convert_code(py5_tools.translators.imported2module)) |
192 | | -conversion_tools_menu.add_command( |
193 | | - label='py5 imported mode → module mode', |
194 | | - command=lambda: convert_code(py5_tools.translators.module2imported)) |
195 | | - |
196 | | - |
197 | 190 | def show_sketch_folder() -> None: |
198 | 191 | '''open the enclosing folder of the current file''' |
199 | 192 | current_editor = get_workbench().get_editor_notebook().get_current_editor() |
@@ -259,13 +252,6 @@ def load_plugin() -> None: |
259 | 252 | lambda: webbrowser.open(git_raw_user + git_asset_path), |
260 | 253 | group=30 |
261 | 254 | ) |
262 | | - get_workbench().add_command( |
263 | | - 'conversion_tools', |
264 | | - 'py5', |
265 | | - tr('Conversion helpers'), |
266 | | - submenu=conversion_tools_menu, |
267 | | - group=40 |
268 | | - ) |
269 | 255 | get_workbench().add_command( |
270 | 256 | 'open_folder', |
271 | 257 | 'py5', |
|
0 commit comments