From 204690a3357c3b367c408ab5b44f21108b4c2dcd Mon Sep 17 00:00:00 2001 From: Benedict Xavier Wanyonyi Date: Thu, 30 May 2024 17:50:57 +0300 Subject: [PATCH] feat: added debug screen --- app/Utility/utils.py | 10 ++++++++- app/View/CrashLogScreen/crashlog_screen.kv | 9 +++++--- app/View/CrashLogScreen/crashlog_screen.py | 24 ++++++++++++++-------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/Utility/utils.py b/app/Utility/utils.py index 06bb719..e61eeb8 100644 --- a/app/Utility/utils.py +++ b/app/Utility/utils.py @@ -1,6 +1,6 @@ from datetime import datetime import shutil - +import os # TODO: make it use color_text instead of fixed vals # from .kivy_markup_helper import color_text @@ -18,6 +18,14 @@ def write_crash(e: Exception): return index +def read_crash_file(): + crash_file_path = "./crashfile.txt" + if not os.path.exists(crash_file_path): + return None + else: + with open(crash_file_path,"r") as file: + return file.read() + def move_file(source_path, dest_path): try: path = shutil.move(source_path, dest_path) diff --git a/app/View/CrashLogScreen/crashlog_screen.kv b/app/View/CrashLogScreen/crashlog_screen.kv index 2944391..49374f8 100644 --- a/app/View/CrashLogScreen/crashlog_screen.kv +++ b/app/View/CrashLogScreen/crashlog_screen.kv @@ -13,6 +13,9 @@ MDBoxLayout: orientation: 'vertical' SearchBar: - - MDLabel: - text:"Crash Log" \ No newline at end of file + MDScrollView: + MDLabel: + text:root.crash_text + adaptive_height:True + markup:True + padding:"10dp" \ No newline at end of file diff --git a/app/View/CrashLogScreen/crashlog_screen.py b/app/View/CrashLogScreen/crashlog_screen.py index 51de6cc..92f2b04 100644 --- a/app/View/CrashLogScreen/crashlog_screen.py +++ b/app/View/CrashLogScreen/crashlog_screen.py @@ -1,13 +1,21 @@ -from kivy.properties import ObjectProperty +from kivy.properties import StringProperty + from View.base_screen import BaseScreenView +from Utility.utils import read_crash_file +from Utility.kivy_markup_helper import color_text, bolden class CrashLogScreenView(BaseScreenView): """The crash log screen""" - main_container = ObjectProperty() - def model_is_changed(self) -> None: - """ - Called whenever any change has occurred in the data model. - The view in this method tracks these changes and updates the UI - according to these changes. - """ + + crash_text = StringProperty() + + def __init__(self, **kw): + super().__init__(**kw) + if crashes := read_crash_file(): + self.crash_text = crashes + else: + self.crash_text = color_text( + f"No Crashes so far :) and if there are any in the future {bolden('please report! Okay?')}", + self.theme_cls.primaryColor, + )