You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Refactor to simplify imports
This commit is contained in:
@@ -2,8 +2,7 @@ import time
|
||||
import random
|
||||
import lvgl as lv
|
||||
|
||||
from mpos.apps import Activity, Intent
|
||||
import mpos.config
|
||||
from mpos import Activity, Intent, config
|
||||
import mpos.ui
|
||||
|
||||
class Confetti(Activity):
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import time
|
||||
import random
|
||||
|
||||
from mpos.apps import Activity
|
||||
import mpos.ui
|
||||
from mpos import Activity, ui
|
||||
|
||||
try:
|
||||
import lvgl as lv
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import lvgl as lv
|
||||
import os
|
||||
from mpos.apps import Activity
|
||||
from mpos import TaskManager, sdcard
|
||||
from mpos import Activity, TaskManager, sdcard
|
||||
|
||||
class Main(Activity):
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from mpos.apps import Activity
|
||||
import mpos.ui
|
||||
import lvgl as lv
|
||||
from mpos import Activity, ui
|
||||
|
||||
indev_error_x = 160
|
||||
indev_error_y = 120
|
||||
@@ -35,11 +35,11 @@ class Draw(Activity):
|
||||
def touch_cb(self, event):
|
||||
event_code=event.get_code()
|
||||
if event_code not in [19,23,25,26,27,28,29,30,49]:
|
||||
name = mpos.ui.get_event_name(event_code)
|
||||
name = ui.get_event_name(event_code)
|
||||
#print(f"lv_event_t: code={event_code}, name={name}") # target={event.get_target()}, user_data={event.get_user_data()}, param={event.get_param()}
|
||||
if event_code == lv.EVENT.PRESSING: # this is probably enough
|
||||
#if event_code in [lv.EVENT.PRESSED, lv.EVENT.PRESSING, lv.EVENT.LONG_PRESSED, lv.EVENT.LONG_PRESSED_REPEAT]:
|
||||
x, y = mpos.ui.get_pointer_xy()
|
||||
x, y = ui.get_pointer_xy()
|
||||
#canvas.set_px(x,y,lv.color_black(),lv.OPA.COVER) # draw a tiny point
|
||||
self.draw_rect(x,y)
|
||||
#self.draw_line(x,y)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from mpos.apps import ActivityDoesntExist # should fail here
|
||||
from mpos import ActivityDoesntExist # should fail here
|
||||
|
||||
class Error(Activity):
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from mpos.apps import Activity
|
||||
import mpos.ui
|
||||
import lvgl as lv
|
||||
from mpos import Activity, ui
|
||||
|
||||
class FileManager(Activity):
|
||||
|
||||
@@ -40,7 +40,7 @@ class FileManager(Activity):
|
||||
# GET_SELF_SIZE
|
||||
# 47 STYLE CHANGED
|
||||
if event_code not in [2,19,23,24,25,26,27,28,29,30,31,32,33,47,49,52]:
|
||||
name = mpos.ui.get_event_name(event_code)
|
||||
name = ui.get_event_name(event_code)
|
||||
print(f"file_explorer_event_cb {event_code} with name {name}")
|
||||
if event_code == lv.EVENT.VALUE_CHANGED:
|
||||
path = self.file_explorer.explorer_get_current_path()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from mpos.apps import Activity
|
||||
from mpos import Activity
|
||||
|
||||
class Hello(Activity):
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import gc
|
||||
import os
|
||||
|
||||
from mpos.apps import Activity
|
||||
import mpos.ui
|
||||
from mpos import Activity, ui
|
||||
import mpos.ui.anim
|
||||
|
||||
class ImageView(Activity):
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from mpos.apps import Activity
|
||||
import mpos.sensor_manager as SensorManager
|
||||
from mpos import Activity, sensor_manager as SensorManager
|
||||
|
||||
class IMU(Activity):
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ import machine
|
||||
import os
|
||||
import time
|
||||
|
||||
from mpos.apps import Activity, Intent
|
||||
import mpos.sdcard
|
||||
from mpos import Activity, Intent, sdcard
|
||||
import mpos.ui
|
||||
import mpos.audio.audioflinger as AudioFlinger
|
||||
|
||||
|
||||
@@ -49,8 +49,7 @@ battery power:
|
||||
import lvgl as lv
|
||||
import time
|
||||
|
||||
import mpos.battery_voltage
|
||||
from mpos.apps import Activity
|
||||
from mpos import battery_voltage, Activity
|
||||
|
||||
class Hello(Activity):
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from mpos.apps import Activity
|
||||
from mpos import Activity
|
||||
import lvgl as lv
|
||||
|
||||
class ShowFonts(Activity):
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from mpos.apps import Activity
|
||||
import mpos.ui
|
||||
from mpos import Activity, ui
|
||||
import mpos.audio.audioflinger as AudioFlinger
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from mpos.apps import Activity
|
||||
from mpos import Activity, pct_of_display_width
|
||||
|
||||
import mpos.info
|
||||
import sys
|
||||
@@ -9,7 +9,7 @@ class About(Activity):
|
||||
screen = lv.obj()
|
||||
screen.set_style_border_width(0, 0)
|
||||
screen.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
screen.set_style_pad_all(mpos.ui.pct_of_display_width(2), 0)
|
||||
screen.set_style_pad_all(pct_of_display_width(2), 0)
|
||||
# Make the screen focusable so it can be scrolled with the arrow keys
|
||||
focusgroup = lv.group_get_default()
|
||||
if focusgroup:
|
||||
|
||||
@@ -10,9 +10,7 @@
|
||||
# Most of this time is actually spent reading and parsing manifests.
|
||||
import lvgl as lv
|
||||
import mpos.apps
|
||||
import mpos.ui
|
||||
from mpos.content.package_manager import PackageManager
|
||||
from mpos import Activity
|
||||
from mpos import ui, PackageManager, Activity, pct_of_display_width
|
||||
import time
|
||||
import uhashlib
|
||||
import ubinascii
|
||||
@@ -31,7 +29,7 @@ class Launcher(Activity):
|
||||
main_screen.set_style_border_width(0, lv.PART.MAIN)
|
||||
main_screen.set_style_radius(0, 0)
|
||||
main_screen.set_pos(0, mpos.ui.topmenu.NOTIFICATION_BAR_HEIGHT)
|
||||
main_screen.set_style_pad_hor(mpos.ui.pct_of_display_width(2), 0)
|
||||
main_screen.set_style_pad_hor(pct_of_display_width(2), 0)
|
||||
main_screen.set_style_pad_ver(mpos.ui.topmenu.NOTIFICATION_BAR_HEIGHT, 0)
|
||||
main_screen.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
|
||||
self.setContentView(main_screen)
|
||||
|
||||
@@ -3,10 +3,8 @@ import requests
|
||||
import ujson
|
||||
import time
|
||||
|
||||
from mpos.apps import Activity
|
||||
from mpos import PackageManager, ConnectivityManager, TaskManager, DownloadManager
|
||||
from mpos import Activity, PackageManager, ConnectivityManager, TaskManager, DownloadManager, pct_of_display_width, pct_of_display_height
|
||||
import mpos.info
|
||||
import mpos.ui
|
||||
|
||||
class OSUpdate(Activity):
|
||||
|
||||
@@ -42,7 +40,7 @@ class OSUpdate(Activity):
|
||||
|
||||
def onCreate(self):
|
||||
self.main_screen = lv.obj()
|
||||
self.main_screen.set_style_pad_all(mpos.ui.pct_of_display_width(2), 0)
|
||||
self.main_screen.set_style_pad_all(pct_of_display_width(2), 0)
|
||||
|
||||
# Make the screen focusable so it can be scrolled with the arrow keys
|
||||
if focusgroup := lv.group_get_default():
|
||||
@@ -55,7 +53,7 @@ class OSUpdate(Activity):
|
||||
self.force_update.set_text("Force Update")
|
||||
self.force_update.add_event_cb(lambda *args: self.force_update_clicked(), lv.EVENT.VALUE_CHANGED, None)
|
||||
#self.force_update.add_event_cb(lambda e: mpos.ui.print_event(e), lv.EVENT.ALL, None)
|
||||
self.force_update.align_to(self.current_version_label, lv.ALIGN.OUT_BOTTOM_LEFT, 0, mpos.ui.pct_of_display_height(5))
|
||||
self.force_update.align_to(self.current_version_label, lv.ALIGN.OUT_BOTTOM_LEFT, 0, pct_of_display_height(5))
|
||||
self.install_button = lv.button(self.main_screen)
|
||||
self.install_button.align(lv.ALIGN.TOP_RIGHT, 0, 0)
|
||||
self.install_button.add_state(lv.STATE.DISABLED) # button will be enabled if there is an update available
|
||||
@@ -76,7 +74,7 @@ class OSUpdate(Activity):
|
||||
check_again_label.center()
|
||||
|
||||
self.status_label = lv.label(self.main_screen)
|
||||
self.status_label.align_to(self.force_update, lv.ALIGN.OUT_BOTTOM_LEFT, 0, mpos.ui.pct_of_display_height(5))
|
||||
self.status_label.align_to(self.force_update, lv.ALIGN.OUT_BOTTOM_LEFT, 0, pct_of_display_height(5))
|
||||
self.setContentView(self.main_screen)
|
||||
|
||||
def _update_ui_for_state(self):
|
||||
|
||||
@@ -10,10 +10,7 @@ Guides user through IMU calibration process:
|
||||
import lvgl as lv
|
||||
import time
|
||||
import sys
|
||||
from mpos.app.activity import Activity
|
||||
import mpos.ui
|
||||
import mpos.sensor_manager as SensorManager
|
||||
from mpos.ui.testing import wait_for_render
|
||||
from mpos import Activity, sensor_manager as SensorManager, wait_for_render, pct_of_display_width
|
||||
|
||||
|
||||
class CalibrationState:
|
||||
@@ -43,7 +40,7 @@ class CalibrateIMUActivity(Activity):
|
||||
|
||||
def onCreate(self):
|
||||
screen = lv.obj()
|
||||
screen.set_style_pad_all(mpos.ui.pct_of_display_width(3), 0)
|
||||
screen.set_style_pad_all(pct_of_display_width(3), 0)
|
||||
screen.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
screen.set_flex_align(lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER)
|
||||
focusgroup = lv.group_get_default()
|
||||
|
||||
+4
-6
@@ -7,9 +7,7 @@ variance, expected value comparison, and overall quality score.
|
||||
import lvgl as lv
|
||||
import time
|
||||
import sys
|
||||
from mpos.app.activity import Activity
|
||||
import mpos.ui
|
||||
import mpos.sensor_manager as SensorManager
|
||||
from mpos import Activity, sensor_manager as SensorManager, pct_of_display_width
|
||||
|
||||
|
||||
class CheckIMUCalibrationActivity(Activity):
|
||||
@@ -36,7 +34,7 @@ class CheckIMUCalibrationActivity(Activity):
|
||||
|
||||
def onCreate(self):
|
||||
screen = lv.obj()
|
||||
screen.set_style_pad_all(mpos.ui.pct_of_display_width(1), 0)
|
||||
screen.set_style_pad_all(pct_of_display_width(1), 0)
|
||||
#screen.set_style_pad_all(0, 0)
|
||||
screen.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
focusgroup = lv.group_get_default()
|
||||
@@ -98,7 +96,7 @@ class CheckIMUCalibrationActivity(Activity):
|
||||
|
||||
# Gyroscope section
|
||||
gyro_cont = lv.obj(data_cont)
|
||||
gyro_cont.set_width(mpos.ui.pct_of_display_width(45))
|
||||
gyro_cont.set_width(pct_of_display_width(45))
|
||||
gyro_cont.set_height(lv.SIZE_CONTENT)
|
||||
gyro_cont.set_style_border_width(0, 0)
|
||||
gyro_cont.set_style_pad_all(0, 0)
|
||||
@@ -261,7 +259,7 @@ class CheckIMUCalibrationActivity(Activity):
|
||||
|
||||
def start_calibration(self, event):
|
||||
"""Navigate to calibration activity."""
|
||||
from mpos.content.intent import Intent
|
||||
from mpos import Intent
|
||||
from calibrate_imu import CalibrateIMUActivity
|
||||
|
||||
intent = Intent(activity_class=CalibrateIMUActivity)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import lvgl as lv
|
||||
|
||||
from mpos.apps import Intent
|
||||
from mpos import PackageManager, SettingActivity, SettingsActivity
|
||||
from mpos import Intent, PackageManager, SettingActivity, SettingsActivity
|
||||
|
||||
from calibrate_imu import CalibrateIMUActivity
|
||||
from check_imu_calibration import CheckIMUCalibrationActivity
|
||||
|
||||
@@ -2,13 +2,8 @@ import time
|
||||
import lvgl as lv
|
||||
import _thread
|
||||
|
||||
from mpos.apps import Activity, Intent
|
||||
from mpos.ui.keyboard import MposKeyboard
|
||||
|
||||
from mpos import Activity, Intent, MposKeyboard, WifiService, CameraActivity, pct_of_display_width
|
||||
import mpos.apps
|
||||
from mpos.net.wifi_service import WifiService
|
||||
|
||||
from mpos import CameraActivity
|
||||
|
||||
class WiFi(Activity):
|
||||
"""
|
||||
@@ -243,8 +238,8 @@ class EditNetwork(Activity):
|
||||
label.set_text(f"Network name:")
|
||||
self.ssid_ta = lv.textarea(password_page)
|
||||
self.ssid_ta.set_width(lv.pct(100))
|
||||
self.ssid_ta.set_style_margin_left(mpos.ui.pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.ssid_ta.set_style_margin_right(mpos.ui.pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.ssid_ta.set_style_margin_left(pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.ssid_ta.set_style_margin_right(pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.ssid_ta.set_one_line(True)
|
||||
self.ssid_ta.set_placeholder_text("Enter the SSID")
|
||||
self.keyboard = MposKeyboard(password_page)
|
||||
@@ -259,8 +254,8 @@ class EditNetwork(Activity):
|
||||
label.set_text(f"Password for '{self.selected_ssid}':")
|
||||
self.password_ta = lv.textarea(password_page)
|
||||
self.password_ta.set_width(lv.pct(100))
|
||||
self.password_ta.set_style_margin_left(mpos.ui.pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.password_ta.set_style_margin_right(mpos.ui.pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.password_ta.set_style_margin_left(pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.password_ta.set_style_margin_right(pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.password_ta.set_one_line(True)
|
||||
if known_password:
|
||||
self.password_ta.set_text(known_password)
|
||||
@@ -272,7 +267,7 @@ class EditNetwork(Activity):
|
||||
# Hidden network:
|
||||
self.hidden_cb = lv.checkbox(password_page)
|
||||
self.hidden_cb.set_text("Hidden network (always try connecting)")
|
||||
self.hidden_cb.set_style_margin_left(mpos.ui.pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.hidden_cb.set_style_margin_left(pct_of_display_width(2), lv.PART.MAIN)
|
||||
if known_hidden:
|
||||
self.hidden_cb.set_state(lv.STATE.CHECKED, True)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user