Skip to content

Commit 1aa4a2b

Browse files
committed
modules/startup: Executing Python cannot import module.
Signed-off-by: lbuque <[email protected]>
1 parent 3640231 commit 1aa4a2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+728
-940
lines changed

m5stack/modules/startup/airq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def on_exit(self):
443443
async def _keycode_enter_event_handler(self, fw):
444444
# print("_keycode_enter_event_handler")
445445
M5.Lcd.clear()
446-
execfile("apps/" + self._files[self._file_pos]) # noqa: F821
446+
execfile("/".join(["apps/", self._files[self._file_pos]]), {"__name__": "__main__"}) # noqa: F821
447447
sys.exit(0)
448448

449449
async def _keycode_back_event_handler(self, fw):

m5stack/modules/startup/basic/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .apps.app_list import ListApp
1212
from .apps.ezdata import EzDataApp
1313
import time
14-
from .res import LOGO_IMG
14+
from . import res
1515

1616

1717
class Sprite:
@@ -33,7 +33,7 @@ def startup(self, ssid: str, pswd: str, timeout: int = 60) -> None:
3333
M5.Speaker.setVolume(80)
3434
M5.Speaker.tone(4000, 50)
3535

36-
M5.Lcd.drawImage(LOGO_IMG)
36+
M5.Lcd.drawImage(res.LOGO_IMG)
3737
time.sleep_ms(200)
3838

3939
fw = Framework()

m5stack/modules/startup/basic/apps/app_list.py

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,20 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
from ..app import AppBase
6-
from widgets.image import Image
7-
from widgets.label import Label
8-
from M5 import Lcd, Widgets
5+
from .. import app
6+
import widgets
7+
import M5
8+
from M5 import Widgets
99
import os
1010
import sys
1111
import time
1212
import machine
1313
import boot_option
14-
from ..res import (
15-
APPLIST_UNSELECTED_IMG,
16-
APPLIST_SELECTED_IMG,
17-
APPLIST_IMG,
18-
BAR5_IMG,
19-
APPLIST_LEFT_IMG,
20-
APPLIST_RIGHT_IMG,
21-
)
14+
from .. import res
2215

2316

2417
class Rectangle:
25-
def __init__(self, x, y, w, h, color, fill_c, parent=Lcd) -> None:
18+
def __init__(self, x, y, w, h, color, fill_c, parent=M5.Lcd) -> None:
2619
self._x = x
2720
self._y = y
2821
self._w = w
@@ -88,12 +81,12 @@ def __len__(self):
8881
return self.files_len
8982

9083

91-
class ListApp(AppBase):
84+
class ListApp(app.AppBase):
9285
def __init__(self, icos: dict, data=None) -> None:
9386
super().__init__()
9487

9588
def on_install(self):
96-
Lcd.drawImage(APPLIST_UNSELECTED_IMG, 5 + 62 * 3, 0)
89+
M5.Lcd.drawImage(res.APPLIST_UNSELECTED_IMG, 5 + 62 * 3, 0)
9790

9891
def on_launch(self):
9992
self._files = FileList("apps")
@@ -105,9 +98,9 @@ def on_view(self):
10598
self._origin_x = 0
10699
self._origin_y = 56
107100

108-
Lcd.drawImage(APPLIST_SELECTED_IMG, 5 + 62 * 3, 0)
109-
Lcd.drawImage(APPLIST_IMG, self._origin_x + 4, self._origin_y + 4)
110-
Lcd.drawImage(BAR5_IMG, 0, 220)
101+
M5.Lcd.drawImage(res.APPLIST_SELECTED_IMG, 5 + 62 * 3, 0)
102+
M5.Lcd.drawImage(res.APPLIST_IMG, self._origin_x + 4, self._origin_y + 4)
103+
M5.Lcd.drawImage(res.BAR5_IMG, 0, 220)
111104

112105
self._line_spacing = 36 + 2 + 2
113106
self._left_cursor_x = self._origin_x + 4
@@ -117,25 +110,25 @@ def on_view(self):
117110
self._left_cursor_x, self._left_cursor_y, 10, 36, 0xFEFEFE, 0xFEFEFE
118111
)
119112

120-
self._left_img = Image(use_sprite=False)
113+
self._left_img = widgets.Image(use_sprite=False)
121114
self._left_img.set_pos(self._left_cursor_x, self._left_cursor_y)
122115
self._left_img.set_size(10, 36)
123-
self._left_img.set_src(APPLIST_LEFT_IMG)
116+
self._left_img.set_src(res.APPLIST_LEFT_IMG)
124117

125118
self._right_cursor_x = 320 - 4 - 60 - 10
126119
self._right_cursor_y = self._origin_y + 4 + 2
127120

128121
self._rect1 = Rectangle(
129-
self._right_cursor_x, self._right_cursor_y, 10, 36, 0xFEFEFE, 0xFEFEFE, parent=Lcd
122+
self._right_cursor_x, self._right_cursor_y, 10, 36, 0xFEFEFE, 0xFEFEFE, parent=M5.Lcd
130123
)
131124

132-
self._right_img = Image(use_sprite=False)
125+
self._right_img = widgets.Image(use_sprite=False)
133126
self._right_img.set_pos(self._right_cursor_x, self._right_cursor_y)
134127
self._right_img.set_size(10, 36)
135-
self._right_img.set_src(APPLIST_RIGHT_IMG)
128+
self._right_img.set_src(res.APPLIST_RIGHT_IMG)
136129

137130
if not hasattr(self, "_label0"):
138-
self._label0 = Label(
131+
self._label0 = widgets.Label(
139132
"",
140133
self._left_cursor_x + 10,
141134
self._left_cursor_y + 8,
@@ -147,7 +140,7 @@ def on_view(self):
147140
)
148141

149142
if not hasattr(self, "_label1"):
150-
self._label1 = Label(
143+
self._label1 = widgets.Label(
151144
"",
152145
self._left_cursor_x + 10,
153146
self._left_cursor_y + 8 + self._line_spacing,
@@ -159,7 +152,7 @@ def on_view(self):
159152
)
160153

161154
if not hasattr(self, "_label2"):
162-
self._label2 = Label(
155+
self._label2 = widgets.Label(
163156
"",
164157
self._left_cursor_x + 10,
165158
self._left_cursor_y + 8 + self._line_spacing + self._line_spacing,
@@ -171,7 +164,7 @@ def on_view(self):
171164
)
172165

173166
if not hasattr(self, "_label3"):
174-
self._label3 = Label(
167+
self._label3 = widgets.Label(
175168
"",
176169
self._left_cursor_x + 10,
177170
self._left_cursor_y
@@ -187,10 +180,6 @@ def on_view(self):
187180
)
188181
if not hasattr(self, "_labels"):
189182
self._labels = (self._label0, self._label1, self._label2, self._label3)
190-
# self._labels.append(self._label0)
191-
# self._labels.append(self._label1)
192-
# self._labels.append(self._label2)
193-
# self._labels.append(self._label3)
194183

195184
for label, file in zip(self._labels, self._files):
196185
file and label and label.set_text(file)
@@ -202,7 +191,7 @@ def on_hide(self):
202191
pass
203192

204193
def on_exit(self):
205-
Lcd.drawImage(APPLIST_UNSELECTED_IMG, 5 + 62 * 3, 0)
194+
M5.Lcd.drawImage(res.APPLIST_UNSELECTED_IMG, 5 + 62 * 3, 0)
206195
del (
207196
self._left_img,
208197
self._right_img,
@@ -253,7 +242,7 @@ async def _btnb_event_handler(self, fw):
253242
file and label and label.set_text(file)
254243

255244
async def _btnc_event_handler(self, fw):
256-
execfile("apps/" + self._files[self._file_pos]) # noqa: F821
245+
execfile("/".join(["apps/", self._files[self._file_pos]]), {"__name__": "__main__"}) # noqa: F821
257246
sys.exit(0)
258247

259248
async def _btnc_hold_event_handler(self, fw):

m5stack/modules/startup/basic/apps/app_run.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
from ..app import AppBase
6-
from M5 import Lcd, Widgets
5+
from .. import app
6+
import M5
7+
from M5 import Widgets
78
import sys
89
import machine
910
import os
1011
import time
1112
import boot_option
12-
from ..res import (
13-
APPRUN_UNSELECTED_IMG,
14-
APPRUN_SELECTED_IMG,
15-
RUN_IMG,
16-
BAR4_IMG,
17-
)
13+
from .. import res
1814

1915

2016
try:
@@ -25,40 +21,40 @@
2521
_HAS_SERVER = False
2622

2723

28-
class RunApp(AppBase):
24+
class RunApp(app.AppBase):
2925
def __init__(self, icos: dict, data=None) -> None:
3026
super().__init__()
3127

3228
def on_install(self):
33-
Lcd.drawImage(APPRUN_UNSELECTED_IMG, 5 + 62 * 2, 0)
29+
M5.Lcd.drawImage(res.APPRUN_UNSELECTED_IMG, 5 + 62 * 2, 0)
3430

3531
def on_launch(self):
3632
self._mtime_text, self._account_text, self._ver_text = self._get_file_info("main.py")
3733

3834
def on_view(self):
3935
self._origin_x = 0
4036
self._origin_y = 56
41-
Lcd.drawImage(APPRUN_SELECTED_IMG, 5 + 62 * 2, 0)
42-
Lcd.fillRect(self._origin_x, self._origin_y, 320, 184, 0x000000)
43-
Lcd.drawImage(RUN_IMG, self._origin_x + 4, self._origin_y + 4)
44-
Lcd.drawImage(BAR4_IMG, self._origin_x, 220)
37+
M5.Lcd.drawImage(res.APPRUN_SELECTED_IMG, 5 + 62 * 2, 0)
38+
M5.Lcd.fillRect(self._origin_x, self._origin_y, 320, 184, 0x000000)
39+
M5.Lcd.drawImage(res.RUN_IMG, self._origin_x + 4, self._origin_y + 4)
40+
M5.Lcd.drawImage(res.BAR4_IMG, self._origin_x, 220)
4541

4642
# file name
47-
Lcd.setFont(Widgets.FONTS.DejaVu18)
48-
Lcd.setTextColor(0x000000, 0xEEEEEF)
49-
Lcd.drawString("main.py", 4 + 10, self._origin_y + 4 + 4)
43+
M5.Lcd.setFont(Widgets.FONTS.DejaVu18)
44+
M5.Lcd.setTextColor(0x000000, 0xEEEEEF)
45+
M5.Lcd.drawString("main.py", 4 + 10, self._origin_y + 4 + 4)
5046

51-
Lcd.setFont(Widgets.FONTS.DejaVu12)
52-
Lcd.setTextColor(0x000000, 0xDCDDDD)
53-
Lcd.drawString(self._mtime_text, 4 + 10 + 8, self._origin_y + 4 + 4 + 20 + 6)
47+
M5.Lcd.setFont(Widgets.FONTS.DejaVu12)
48+
M5.Lcd.setTextColor(0x000000, 0xDCDDDD)
49+
M5.Lcd.drawString(self._mtime_text, 4 + 10 + 8, self._origin_y + 4 + 4 + 20 + 6)
5450

55-
Lcd.setFont(Widgets.FONTS.DejaVu12)
56-
Lcd.setTextColor(0x000000, 0xDCDDDD)
57-
Lcd.drawString(self._account_text, 4 + 10 + 8, self._origin_y + 4 + 4 + 20 + 6 + 18)
51+
M5.Lcd.setFont(Widgets.FONTS.DejaVu12)
52+
M5.Lcd.setTextColor(0x000000, 0xDCDDDD)
53+
M5.Lcd.drawString(self._account_text, 4 + 10 + 8, self._origin_y + 4 + 4 + 20 + 6 + 18)
5854

59-
Lcd.setFont(Widgets.FONTS.DejaVu12)
60-
Lcd.setTextColor(0x000000, 0xDCDDDD)
61-
Lcd.drawString(self._ver_text, 4 + 10 + 8, self._origin_y + 4 + 4 + 20 + 6 + 18 + 18)
55+
M5.Lcd.setFont(Widgets.FONTS.DejaVu12)
56+
M5.Lcd.setTextColor(0x000000, 0xDCDDDD)
57+
M5.Lcd.drawString(self._ver_text, 4 + 10 + 8, self._origin_y + 4 + 4 + 20 + 6 + 18 + 18)
6258

6359
def on_ready(self):
6460
pass
@@ -67,7 +63,7 @@ def on_hide(self):
6763
pass
6864

6965
def on_exit(self):
70-
Lcd.drawImage(APPRUN_UNSELECTED_IMG, 5 + 62 * 2, 0)
66+
M5.Lcd.drawImage(res.APPRUN_UNSELECTED_IMG, 5 + 62 * 2, 0)
7167
del self._origin_x, self._origin_y
7268
del self._mtime_text, self._account_text, self._ver_text
7369

@@ -77,7 +73,7 @@ def on_exit(self):
7773

7874
async def _btnb_event_handler(self, fw):
7975
# print("_btnb_event_handler")
80-
execfile("main.py") # noqa: F821
76+
execfile("main.py", {"__name__": "__main__"}) # noqa: F821
8177
sys.exit(0)
8278

8379
async def _btnc_event_handler(self, fw):

0 commit comments

Comments
 (0)