Skip to content

Commit 7def3b3

Browse files
Camera app: Fix status label text handling
1 parent 39c92ec commit 7def3b3

File tree

1 file changed

+10
-9
lines changed
  • internal_filesystem/apps/com.micropythonos.camera/assets

1 file changed

+10
-9
lines changed

internal_filesystem/apps/com.micropythonos.camera/assets/camera_app.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class CameraApp(Activity):
2121
button_width = 75
2222
button_height = 50
2323

24-
status_label_text = "No camera found."
25-
status_label_text_searching = "Searching QR codes...\n\nHold still and try varying scan distance (10-25cm) and make the QR code big (4-12cm). Ensure proper lighting."
26-
status_label_text_found = "Found QR, trying to decode... hold still..."
24+
STATUS_NO_CAMERA = "No camera found."
25+
STATUS_SEARCHING_QR = "Searching QR codes...\n\nHold still and try varying scan distance (10-25cm) and make the QR code big (4-12cm). Ensure proper lighting."
26+
STATUS_FOUND_QR = "Found QR, trying to decode... hold still..."
2727

2828
cam = None
2929
current_cam_buffer = None # Holds the current memoryview to prevent garba
@@ -110,7 +110,7 @@ def onCreate(self):
110110
self.status_label_cont.set_style_bg_opa(66, 0)
111111
self.status_label_cont.set_style_border_width(0, 0)
112112
self.status_label = lv.label(self.status_label_cont)
113-
self.status_label.set_text("No camera found.")
113+
self.status_label.set_text(self.STATUS_NO_CAMERA)
114114
self.status_label.set_long_mode(lv.label.LONG_MODE.WRAP)
115115
self.status_label.set_width(lv.pct(100))
116116
self.status_label.center()
@@ -237,10 +237,10 @@ def qrdecode_one(self):
237237
print(f"qrdecode took {after-before}ms")
238238
except ValueError as e:
239239
print("QR ValueError: ", e)
240-
self.status_label.set_text(self.status_label_text_searching)
240+
self.status_label.set_text(self.STATUS_SEARCHING_QR)
241241
except TypeError as e:
242242
print("QR TypeError: ", e)
243-
self.status_label.set_text(self.status_label_text_found)
243+
self.status_label.set_text(self.STATUS_FOUND_QR)
244244
except Exception as e:
245245
print("QR got other error: ", e)
246246
#result = bytearray("INSERT_TEST_QR_DATA_HERE", "utf-8")
@@ -308,14 +308,15 @@ def start_qr_decoding(self):
308308
self.start_cam()
309309
self.qr_label.set_text(lv.SYMBOL.EYE_CLOSE)
310310
self.status_label_cont.remove_flag(lv.obj.FLAG.HIDDEN)
311-
self.status_label.set_text(self.status_label_text_searching)
311+
self.status_label.set_text(self.STATUS_SEARCHING_QR)
312312

313313
def stop_qr_decoding(self):
314314
print("Deactivating live QR decoding...")
315315
self.scanqr_mode = False
316316
self.qr_label.set_text(lv.SYMBOL.EYE_OPEN)
317-
self.status_label_text = self.status_label.get_text()
318-
if self.status_label_text not in (self.status_label_text_searching or self.status_label_text_found): # if it found a QR code, leave it
317+
status_label_text = self.status_label.get_text()
318+
if status_label_text in (self.STATUS_NO_CAMERA or self.STATUS_SEARCHING_QR or self.STATUS_FOUND_QR): # if it found a QR code, leave it
319+
print(f"status label text {status_label_text} is a known message, not a QR code, hiding it...")
319320
self.status_label_cont.add_flag(lv.obj.FLAG.HIDDEN)
320321
# Check if it's necessary to restart the camera:
321322
oldwidth = self.width

0 commit comments

Comments
 (0)