mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Introduce DisplayMetrics framework
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from mpos import Activity, pct_of_display_width, get_display_width, get_display_height, get_dpi
|
||||
from mpos import Activity, DisplayMetrics
|
||||
|
||||
import mpos.info
|
||||
import sys
|
||||
@@ -38,7 +38,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(pct_of_display_width(2), 0)
|
||||
screen.set_style_pad_all(DisplayMetrics.pct_of_width(2), 0)
|
||||
# Make the screen focusable so it can be scrolled with the arrow keys
|
||||
focusgroup = lv.group_get_default()
|
||||
if focusgroup:
|
||||
@@ -147,10 +147,10 @@ class About(Activity):
|
||||
# Display info
|
||||
try:
|
||||
self._add_label(screen, f"{lv.SYMBOL.IMAGE} Display", is_header=True)
|
||||
hor_res = get_display_width()
|
||||
ver_res = get_display_height()
|
||||
hor_res = DisplayMetrics.width()
|
||||
ver_res = DisplayMetrics.height()
|
||||
self._add_label(screen, f"Resolution: {hor_res}x{ver_res}")
|
||||
dpi = get_dpi()
|
||||
dpi = DisplayMetrics.dpi()
|
||||
self._add_label(screen, f"Dots Per Inch (dpi): {dpi}")
|
||||
except Exception as e:
|
||||
print(f"Could not get display info: {e}")
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# Most of this time is actually spent reading and parsing manifests.
|
||||
import lvgl as lv
|
||||
import mpos.apps
|
||||
from mpos import NOTIFICATION_BAR_HEIGHT, PackageManager, Activity, pct_of_display_width
|
||||
from mpos import NOTIFICATION_BAR_HEIGHT, PackageManager, Activity, DisplayMetrics
|
||||
import time
|
||||
import uhashlib
|
||||
import ubinascii
|
||||
@@ -29,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, NOTIFICATION_BAR_HEIGHT)
|
||||
main_screen.set_style_pad_hor(pct_of_display_width(2), 0)
|
||||
main_screen.set_style_pad_hor(DisplayMetrics.pct_of_width(2), 0)
|
||||
main_screen.set_style_pad_ver(NOTIFICATION_BAR_HEIGHT, 0)
|
||||
main_screen.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
|
||||
self.setContentView(main_screen)
|
||||
|
||||
@@ -2,7 +2,7 @@ import lvgl as lv
|
||||
import ujson
|
||||
import time
|
||||
|
||||
from mpos import Activity, PackageManager, ConnectivityManager, TaskManager, DownloadManager, pct_of_display_width, pct_of_display_height
|
||||
from mpos import Activity, PackageManager, ConnectivityManager, TaskManager, DownloadManager, DisplayMetrics
|
||||
import mpos.info
|
||||
|
||||
class OSUpdate(Activity):
|
||||
@@ -39,7 +39,7 @@ class OSUpdate(Activity):
|
||||
|
||||
def onCreate(self):
|
||||
self.main_screen = lv.obj()
|
||||
self.main_screen.set_style_pad_all(pct_of_display_width(2), 0)
|
||||
self.main_screen.set_style_pad_all(DisplayMetrics.pct_of_width(2), 0)
|
||||
|
||||
# Make the screen focusable so it can be scrolled with the arrow keys
|
||||
if focusgroup := lv.group_get_default():
|
||||
@@ -51,7 +51,7 @@ class OSUpdate(Activity):
|
||||
self.force_update = lv.checkbox(self.main_screen)
|
||||
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.align_to(self.current_version_label, lv.ALIGN.OUT_BOTTOM_LEFT, 0, pct_of_display_height(5))
|
||||
self.force_update.align_to(self.current_version_label, lv.ALIGN.OUT_BOTTOM_LEFT, 0, DisplayMetrics.pct_of_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
|
||||
@@ -72,7 +72,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, pct_of_display_height(5))
|
||||
self.status_label.align_to(self.force_update, lv.ALIGN.OUT_BOTTOM_LEFT, 0, DisplayMetrics.pct_of_height(5))
|
||||
self.setContentView(self.main_screen)
|
||||
|
||||
def _update_ui_for_state(self):
|
||||
|
||||
@@ -10,7 +10,7 @@ Guides user through IMU calibration process:
|
||||
import lvgl as lv
|
||||
import time
|
||||
import sys
|
||||
from mpos import Activity, SensorManager, wait_for_render, pct_of_display_width
|
||||
from mpos import Activity, SensorManager, wait_for_render, DisplayMetrics
|
||||
|
||||
|
||||
class CalibrationState:
|
||||
@@ -40,7 +40,7 @@ class CalibrateIMUActivity(Activity):
|
||||
|
||||
def onCreate(self):
|
||||
screen = lv.obj()
|
||||
screen.set_style_pad_all(pct_of_display_width(3), 0)
|
||||
screen.set_style_pad_all(DisplayMetrics.pct_of_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()
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ variance, expected value comparison, and overall quality score.
|
||||
import lvgl as lv
|
||||
import time
|
||||
import sys
|
||||
from mpos import Activity, SensorManager, pct_of_display_width
|
||||
from mpos import Activity, SensorManager, DisplayMetrics
|
||||
|
||||
|
||||
class CheckIMUCalibrationActivity(Activity):
|
||||
@@ -34,7 +34,7 @@ class CheckIMUCalibrationActivity(Activity):
|
||||
|
||||
def onCreate(self):
|
||||
screen = lv.obj()
|
||||
screen.set_style_pad_all(pct_of_display_width(1), 0)
|
||||
screen.set_style_pad_all(DisplayMetrics.pct_of_width(1), 0)
|
||||
#screen.set_style_pad_all(0, 0)
|
||||
screen.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
focusgroup = lv.group_get_default()
|
||||
@@ -96,7 +96,7 @@ class CheckIMUCalibrationActivity(Activity):
|
||||
|
||||
# Gyroscope section
|
||||
gyro_cont = lv.obj(data_cont)
|
||||
gyro_cont.set_width(pct_of_display_width(45))
|
||||
gyro_cont.set_width(DisplayMetrics.pct_of_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)
|
||||
|
||||
@@ -2,7 +2,7 @@ import time
|
||||
import lvgl as lv
|
||||
import _thread
|
||||
|
||||
from mpos import Activity, Intent, MposKeyboard, WifiService, CameraActivity, pct_of_display_width, CameraManager
|
||||
from mpos import Activity, Intent, MposKeyboard, WifiService, CameraActivity, DisplayMetrics, CameraManager
|
||||
import mpos.apps
|
||||
|
||||
class WiFi(Activity):
|
||||
@@ -238,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(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_style_margin_left(DisplayMetrics.pct_of_width(2), lv.PART.MAIN)
|
||||
self.ssid_ta.set_style_margin_right(DisplayMetrics.pct_of_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)
|
||||
@@ -254,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(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_style_margin_left(DisplayMetrics.pct_of_width(2), lv.PART.MAIN)
|
||||
self.password_ta.set_style_margin_right(DisplayMetrics.pct_of_width(2), lv.PART.MAIN)
|
||||
self.password_ta.set_one_line(True)
|
||||
if known_password:
|
||||
self.password_ta.set_text(known_password)
|
||||
@@ -267,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(pct_of_display_width(2), lv.PART.MAIN)
|
||||
self.hidden_cb.set_style_margin_left(DisplayMetrics.pct_of_width(2), lv.PART.MAIN)
|
||||
if known_hidden:
|
||||
self.hidden_cb.set_state(lv.STATE.CHECKED, True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user