Skip to content

Commit 977347e

Browse files
committed
- apply (temporary?) stackprinter fix?
1 parent 704c98f commit 977347e

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

thonnycontrib/thonny-py5mode/__init__.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import os
88
import pathlib
99
import platform
10-
import py5_tools
1110
import pyperclip
1211
import shutil
1312
import site
1413
import subprocess
1514
import sys
1615
import tkinter as tk
16+
import types
1717
import webbrowser
1818
from .about_plugin import add_about_py5mode_command, open_about_plugin
1919
from .install_jdk import install_jdk
2020
from distutils.sysconfig import get_python_lib
21-
from importlib import util
21+
from importlib import machinery, util
2222
from thonny import editors, get_workbench, get_runner, running, token_utils
2323
from thonny.common import BackendEvent
2424
from thonny.languages import tr
@@ -100,8 +100,14 @@ def patched_execute_current(self: Runner, command_name: str) -> None:
100100

101101
def patch_token_coloring() -> None:
102102
'''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
105111
matches = token_utils.matches_any('builtin', patched_builtinlist)
106112
patched_BUILTIN = r'([^.\'"\\#]\b|^)' + (matches + r'\b')
107113
token_utils.BUILTIN = patched_BUILTIN
@@ -181,19 +187,6 @@ def patched_handle_program_output(self, msg: BackendEvent) -> None:
181187
BaseShellText._original_handle_program_output(self, msg)
182188

183189

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-
197190
def show_sketch_folder() -> None:
198191
'''open the enclosing folder of the current file'''
199192
current_editor = get_workbench().get_editor_notebook().get_current_editor()
@@ -259,13 +252,6 @@ def load_plugin() -> None:
259252
lambda: webbrowser.open(git_raw_user + git_asset_path),
260253
group=30
261254
)
262-
get_workbench().add_command(
263-
'conversion_tools',
264-
'py5',
265-
tr('Conversion helpers'),
266-
submenu=conversion_tools_menu,
267-
group=40
268-
)
269255
get_workbench().add_command(
270256
'open_folder',
271257
'py5',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.4.4-alpha'
1+
__version__ = '0.4.5-alpha'

thonnycontrib/thonny-py5mode/about_plugin.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
from ._version import __version__
1515

1616

17-
try:
18-
import py5
19-
_PY5_VERSION = py5.__version__
20-
except JVMNotFoundException: # jre not installed (yet?)
21-
_PY5_VERSION = 'version unknown (did you run py5 > Imported mode for py5?)'
17+
_PY5_VERSION = 'version details in Tools > Manage plug-ins'
2218

2319

2420
def get_os_word_size_guess() -> None:

0 commit comments

Comments
 (0)