Skip to content

Commit 1225ee6

Browse files
committed
支持quecpython的api补全提示,待补充pyi文件
1 parent b397096 commit 1225ee6

File tree

6 files changed

+43
-85
lines changed

6 files changed

+43
-85
lines changed

thonnycontrib/quecpython/__init__.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
from thonny import get_workbench
22
from thonny.plugins.quecpython.backend.mp_front import (
3-
add_micropython_backend,
3+
add_quecpython_backend,
44
GenericBareMetalMicroPythonConfigPage,
5-
GenericBareMetalMicroPythonProxy,
5+
GenericBareMetalMicroPythonProxy
66
)
7-
from .view import QuecView, open_quecview
8-
from .locale import tr
97

108

11-
def load_plugin():
12-
add_micropython_backend(
13-
"GenericQuecPython",
14-
GenericBareMetalMicroPythonProxy,
15-
"QuecPython (generic)",
16-
GenericBareMetalMicroPythonConfigPage,
17-
sort_key="51",
18-
)
19-
9+
def create_view():
10+
from .view import QuecView, open_quecview
11+
from .locale import tr
2012
get_workbench().add_view(QuecView, tr("QuecPython Kits"), "s")
2113
get_workbench().add_command(
2214
'quecpython_kits',
2315
'tools',
2416
tr('QuecPython Kits'),
2517
open_quecview
2618
)
19+
20+
21+
def load_plugin():
22+
add_quecpython_backend(
23+
"GenericQuecPython",
24+
GenericBareMetalMicroPythonProxy,
25+
"QuecPython (generic)",
26+
GenericBareMetalMicroPythonConfigPage,
27+
sort_key="51",
28+
)
29+
create_view()
Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import platform
21

3-
from thonny import get_workbench
4-
from thonny.languages import tr
52
from thonny.plugins.quecpython.backend.mp_front import (
63
BareMetalMicroPythonConfigPage,
74
BareMetalMicroPythonProxy,
@@ -12,48 +9,6 @@
129
MicroPythonProxy,
1310
SshMicroPythonConfigPage,
1411
SshMicroPythonProxy,
15-
add_micropython_backend,
12+
add_quecpython_backend,
1613
list_serial_ports,
1714
)
18-
19-
20-
def load_plugin():
21-
add_micropython_backend(
22-
"GenericMicroPython",
23-
GenericBareMetalMicroPythonProxy,
24-
tr("MicroPython (generic)"),
25-
GenericBareMetalMicroPythonConfigPage,
26-
sort_key="49",
27-
)
28-
29-
get_workbench().set_default("serial.last_backend_per_vid_pid", {})
30-
31-
if platform.system() in ("Linux", "Darwin"):
32-
add_micropython_backend(
33-
"LocalMicroPython",
34-
LocalMicroPythonProxy,
35-
tr("MicroPython (local)"),
36-
LocalMicroPythonConfigPage,
37-
bare_metal=False,
38-
local_rtc=False,
39-
sort_key="21",
40-
)
41-
get_workbench().set_default("LocalMicroPython.executable", "micropython")
42-
43-
add_micropython_backend(
44-
"SshMicroPython",
45-
SshMicroPythonProxy,
46-
tr("MicroPython (SSH)"),
47-
SshMicroPythonConfigPage,
48-
bare_metal=False,
49-
local_rtc=False,
50-
sort_key="22",
51-
)
52-
get_workbench().set_default("SshMicroPython.executable", "micropython")
53-
get_workbench().set_default("SshMicroPython.cwd", None)
54-
get_workbench().set_default("SshMicroPython.host", "")
55-
get_workbench().set_default("SshMicroPython.user", "")
56-
get_workbench().set_default("SshMicroPython.auth_method", "password")
57-
get_workbench().set_default("SshMicroPython.make_uploaded_shebang_scripts_executable", True)
58-
59-
get_workbench().set_default("esptool.show_advanced_options", False)

thonnycontrib/quecpython/backend/bare_metal_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import BinaryIO, Callable, List, Optional, Union
1010

1111
# make sure thonny folder is in sys.path (relevant in dev)
12-
thonny_container = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
12+
thonny_container = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
1313
if thonny_container not in sys.path:
1414
sys.path.insert(0, thonny_container)
1515

@@ -122,7 +122,7 @@
122122
]
123123

124124
# Can't use __name__, because it will be "__main__"
125-
logger = getLogger("thonny.plugins.micropython.bare_metal_backend")
125+
logger = getLogger("thonny.plugins.quecpython.backend.bare_metal_backend")
126126

127127

128128
class BareMetalMicroPythonBackend(MicroPythonBackend, UploadDownloadMixin):
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11

22

3-
def waitNetworkReady(timeout: int = 60) -> bool:
4-
"""
5-
@timeout: int, 超时时间, 范围1~3600秒, 默认60秒.
6-
等待模组网络就绪。该方法会依次检测SIM卡状态、模组网络注册状态和PDP Context激活状态;在设定的超时时间之内,如果检测到PDP Context激活成功,会立即返回,否则直到超时才会退出。
7-
返回值描述:
3+
def waitNetworkReady(timeout: int = 60) -> tuple:
4+
"""阻塞等待网络连接成功。
5+
6+
@timeout: int,超时时间,范围1~3600秒,默认60秒。
7+
等待模组网络就绪。该方法会依次检测SIM卡状态、模组网络注册状态和PDP Context激活状态;
8+
在设定的超时时间之内,如果检测到PDP Context激活成功,会立即返回,否则直到超时才会退出。
89
9-
返回一个元组,格式为:(stage, state)
10-
参数 类型 含义
11-
stage 整型 表示当前正在检测什么状态:
12-
1 - 正在检测SIM卡状态;
13-
2 - 正在检测网络注册状态;
14-
3 - 正在检测PDP Context激活状态。
15-
state 整型 根据stage值,来表示不同的状态,具体如下:
16-
stage = 1时,state表示 SIM卡的状态,范围0-21,每个状态值的详细说明,请参考sim.getStatus()方法的返回值说明;
17-
stage = 2时,state表示网络注册状态,范围0-11,每个状态值的详细说明,请参考net.getState()方法的返回值说明;
18-
stage = 3时,state表示PDP Context激活状态,0表示没有激活成功,1表示激活成功。
10+
@return:返回一个元组,格式为:(stage, state)。
11+
stage,整型,表示当前正在检测什么状态:
12+
1表示正在检测SIM卡状态;
13+
2表示正在检测网络注册状态;
14+
3表示正在检测PDP Context激活状态。
15+
state,整型,根据stage值,来表示不同的状态,具体如下:
16+
1表示 SIM卡的状态,范围0-21,每个状态值的详细说明,请参考sim.getStatus()方法的返回值说明;
17+
2表示网络注册状态,范围0-11,每个状态值的详细说明,请参考net.getState()方法的返回值说明;
18+
3表示PDP Context激活状态,0表示没有激活成功,1表示激活成功。
1919
"""

thonnycontrib/quecpython/backend/mp_front.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ def stop_restart_kills_user_program(self) -> bool:
170170
return False
171171

172172
def _get_backend_launcher_path(self) -> str:
173-
import thonny.plugins.micropython.bare_metal_backend
173+
import thonny.plugins.quecpython.backend.bare_metal_backend
174174

175-
return thonny.plugins.micropython.bare_metal_backend.__file__
175+
return thonny.plugins.quecpython.backend.bare_metal_backend.__file__
176176

177177
def _get_write_block_size(self):
178178
return get_workbench().get_option(self.backend_name + ".write_block_size")
@@ -394,7 +394,7 @@ def open_custom_system_shell(self):
394394
running.get_front_interpreter_for_subprocess(sys.executable),
395395
"-m",
396396
# "serial.tools.miniterm",
397-
"thonny.plugins.micropython.miniterm_wrapper",
397+
"thonny.plugins.quecpython.backend.miniterm_wrapper",
398398
"--exit-char",
399399
"20",
400400
"--menu-char",
@@ -700,10 +700,10 @@ def get_target_executable(self) -> Optional[str]:
700700
return self._target_executable
701701

702702
def _get_launcher_with_args(self):
703-
import thonny.plugins.micropython.os_mp_backend
703+
import thonny.plugins.quecpython.backend.os_mp_backend
704704

705705
cmd = [
706-
thonny.plugins.micropython.os_mp_backend.__file__,
706+
thonny.plugins.quecpython.backend.os_mp_backend.__file__,
707707
repr(
708708
{
709709
"interpreter": self._target_executable,
@@ -829,7 +829,7 @@ def __init__(self, clean):
829829
super().__init__(clean)
830830

831831
def _get_launcher_with_args(self):
832-
import thonny.plugins.micropython.os_mp_backend
832+
import thonny.plugins.quecpython.backend.os_mp_backend
833833

834834
args = {
835835
"cwd": get_workbench().get_option(f"{self.backend_name}.cwd") or "",
@@ -842,7 +842,7 @@ def _get_launcher_with_args(self):
842842
args.update(self._get_extra_launcher_args())
843843

844844
cmd = [
845-
thonny.plugins.micropython.os_mp_backend.__file__,
845+
thonny.plugins.quecpython.backend.os_mp_backend.__file__,
846846
repr(args),
847847
]
848848
return cmd
@@ -1070,7 +1070,7 @@ def get_port_info(port):
10701070
raise RuntimeError("Port %s not found" % port)
10711071

10721072

1073-
def add_micropython_backend(
1073+
def add_quecpython_backend(
10741074
name,
10751075
proxy_class,
10761076
description,

thonnycontrib/quecpython/backend/os_mp_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from thonny.plugins.quecpython.backend.mp_common import PASTE_SUBMIT_MODE
3434

3535
# Can't use __name__, because it will be "__main__"
36-
logger = getLogger("thonny.plugins.micropython.os_mp_backend")
36+
logger = getLogger("thonny.plugins.quecpython.backend.os_mp_backend")
3737

3838

3939
FALLBACK_BUILTIN_MODULES = [

0 commit comments

Comments
 (0)