From 150700d78b96845eb5cdd97dccdf9c7073e11902 Mon Sep 17 00:00:00 2001 From: Tobias Sterbak Date: Mon, 27 Mar 2023 11:33:51 +0200 Subject: [PATCH 1/2] Make all text and markdown elements selectable --- openandroidinstaller/openandroidinstaller.py | 4 ++- openandroidinstaller/styles.py | 30 +++++++++++++++++++ openandroidinstaller/views/addon_view.py | 6 ++-- .../views/install_addons_view.py | 5 +++- openandroidinstaller/views/install_view.py | 5 +++- .../views/requirements_view.py | 6 ++-- openandroidinstaller/views/select_view.py | 6 ++-- openandroidinstaller/views/start_view.py | 6 ++-- openandroidinstaller/views/step_view.py | 6 +++- openandroidinstaller/views/success_view.py | 4 ++- openandroidinstaller/views/welcome_view.py | 7 +++-- openandroidinstaller/widgets.py | 7 +++-- 12 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 openandroidinstaller/styles.py diff --git a/openandroidinstaller/openandroidinstaller.py b/openandroidinstaller/openandroidinstaller.py index a04bea42..1862c3fd 100644 --- a/openandroidinstaller/openandroidinstaller.py +++ b/openandroidinstaller/openandroidinstaller.py @@ -31,7 +31,6 @@ Icon, Image, Page, - Text, TextButton, UserControl, colors, @@ -39,6 +38,9 @@ ) from loguru import logger +from styles import ( + Text, +) from app_state import AppState from views import ( SelectFilesView, diff --git a/openandroidinstaller/styles.py b/openandroidinstaller/styles.py new file mode 100644 index 00000000..6d8f8aa8 --- /dev/null +++ b/openandroidinstaller/styles.py @@ -0,0 +1,30 @@ +"""This module contains different pre-configured style elements for building the application.""" + +# This file is part of OpenAndroidInstaller. +# OpenAndroidInstaller is free software: you can redistribute it and/or modify it under the terms of +# the GNU General Public License as published by the Free Software Foundation, +# either version 3 of the License, or (at your option) any later version. + +# OpenAndroidInstaller is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along with OpenAndroidInstaller. +# If not, see .""" +# Author: Tobias Sterbak + +import flet as ft + + +class Text(ft.Text): + """Text element to replace the default text element from flet but is selectable.""" + + def __init__(self, *args, **kwargs): + super().__init__(selectable=True, *args, **kwargs) + + +class Markdown(ft.Markdown): + """Markdown element to replace the markdown element from flet but is selectable.""" + + def __init__(self, *args, **kwargs): + super().__init__(selectable=True, *args, **kwargs) diff --git a/openandroidinstaller/views/addon_view.py b/openandroidinstaller/views/addon_view.py index d9d89333..93171ece 100644 --- a/openandroidinstaller/views/addon_view.py +++ b/openandroidinstaller/views/addon_view.py @@ -23,9 +23,7 @@ ElevatedButton, OutlinedButton, FilledButton, - Markdown, Row, - Text, colors, icons, TextButton, @@ -35,6 +33,10 @@ ) from flet.buttons import CountinuosRectangleBorder +from styles import ( + Text, + Markdown, +) from views import BaseView from app_state import AppState from widgets import get_title, confirm_button diff --git a/openandroidinstaller/views/install_addons_view.py b/openandroidinstaller/views/install_addons_view.py index 7bb71e42..6470a840 100644 --- a/openandroidinstaller/views/install_addons_view.py +++ b/openandroidinstaller/views/install_addons_view.py @@ -21,10 +21,13 @@ Column, ElevatedButton, Row, - Text, icons, Switch, colors, +) + +from styles import ( + Text, Markdown, ) diff --git a/openandroidinstaller/views/install_view.py b/openandroidinstaller/views/install_view.py index 29283fab..54b90e77 100644 --- a/openandroidinstaller/views/install_view.py +++ b/openandroidinstaller/views/install_view.py @@ -21,10 +21,13 @@ Column, ElevatedButton, Row, - Text, icons, Switch, colors, +) + +from styles import ( + Text, Markdown, ) diff --git a/openandroidinstaller/views/requirements_view.py b/openandroidinstaller/views/requirements_view.py index 327649d6..3d3d7efd 100644 --- a/openandroidinstaller/views/requirements_view.py +++ b/openandroidinstaller/views/requirements_view.py @@ -22,17 +22,19 @@ Container, Divider, ElevatedButton, - Markdown, Row, colors, OutlinedButton, - Text, icons, TextButton, AlertDialog, ) from flet.buttons import CountinuosRectangleBorder +from styles import ( + Text, + Markdown, +) from views import BaseView from app_state import AppState from widgets import get_title diff --git a/openandroidinstaller/views/select_view.py b/openandroidinstaller/views/select_view.py index ac65fd5d..0f851241 100644 --- a/openandroidinstaller/views/select_view.py +++ b/openandroidinstaller/views/select_view.py @@ -23,9 +23,7 @@ ElevatedButton, OutlinedButton, FilledButton, - Markdown, Row, - Text, colors, icons, TextButton, @@ -35,6 +33,10 @@ ) from flet.buttons import CountinuosRectangleBorder +from styles import ( + Text, + Markdown, +) from views import BaseView from app_state import AppState from widgets import get_title, confirm_button diff --git a/openandroidinstaller/views/start_view.py b/openandroidinstaller/views/start_view.py index abf64064..31c2d85f 100644 --- a/openandroidinstaller/views/start_view.py +++ b/openandroidinstaller/views/start_view.py @@ -25,15 +25,17 @@ ElevatedButton, OutlinedButton, FilledButton, - Markdown, Row, - Text, TextButton, colors, icons, ) from flet.buttons import CountinuosRectangleBorder +from styles import ( + Text, + Markdown, +) from views import BaseView from app_state import AppState from widgets import get_title diff --git a/openandroidinstaller/views/step_view.py b/openandroidinstaller/views/step_view.py index eb484eb3..03aefe9d 100644 --- a/openandroidinstaller/views/step_view.py +++ b/openandroidinstaller/views/step_view.py @@ -22,13 +22,17 @@ Column, ElevatedButton, Row, - Text, icons, TextField, Switch, colors, ) + +from styles import ( + Text, +) + from views import BaseView from installer_config import Step from app_state import AppState diff --git a/openandroidinstaller/views/success_view.py b/openandroidinstaller/views/success_view.py index 30a1dc8a..697b59d7 100644 --- a/openandroidinstaller/views/success_view.py +++ b/openandroidinstaller/views/success_view.py @@ -17,10 +17,12 @@ from flet import ( ElevatedButton, Row, +) + +from styles import ( Text, Markdown, ) - from views import BaseView from app_state import AppState from widgets import get_title diff --git a/openandroidinstaller/views/welcome_view.py b/openandroidinstaller/views/welcome_view.py index 59de038b..a3560ea7 100644 --- a/openandroidinstaller/views/welcome_view.py +++ b/openandroidinstaller/views/welcome_view.py @@ -18,12 +18,15 @@ from flet import ( Divider, ElevatedButton, - Markdown, Row, - Text, icons, ) +from styles import ( + Text, + Markdown, +) + from views import BaseView from app_state import AppState from widgets import get_title diff --git a/openandroidinstaller/widgets.py b/openandroidinstaller/widgets.py index d57c006f..c488d36c 100644 --- a/openandroidinstaller/widgets.py +++ b/openandroidinstaller/widgets.py @@ -26,7 +26,6 @@ ProgressRing, ProgressBar, Row, - Text, alignment, icons, IconButton, @@ -34,6 +33,10 @@ Column, ) +from styles import ( + Text, +) + class TerminalBox(UserControl): def __init__(self, expand: bool = True, visible: bool = False): @@ -43,7 +46,7 @@ def __init__(self, expand: bool = True, visible: bool = False): def build(self): self._box = Container( content=Column( - controls=[Text("", selectable=True)], + controls=[Text("")], scroll="auto", expand=True, auto_scroll=True, From a9a421dacee6bc67a5e927a35d458aafefd5026f Mon Sep 17 00:00:00 2001 From: Tobias Sterbak Date: Mon, 27 Mar 2023 11:43:02 +0200 Subject: [PATCH 2/2] If there are not instructions to unlock the bootloader, assume that there is nothing to do and toggle the switch by default --- openandroidinstaller/views/start_view.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openandroidinstaller/views/start_view.py b/openandroidinstaller/views/start_view.py index 31c2d85f..e1927816 100644 --- a/openandroidinstaller/views/start_view.py +++ b/openandroidinstaller/views/start_view.py @@ -259,6 +259,8 @@ def search_devices(self, e): f"{device_name} (code: {self.state.config.device_code})" ) self.device_name.color = colors.GREEN + # if there are no steps for bootloader unlocking, assume there is nothing to do and toggle the switch + self.bootloader_switch.value = True else: # failed to load config logger.error(f"Failed to load config for {device_code}.")