From 17341a4dc77f254a90fc714148582b05a6f4da15 Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Wed, 18 Nov 2026 11:41:32 -0500 Subject: [PATCH] Operator display data logic is moved to isolated helper functions --- gui/v2/presenters/data/profile_data.py | 29 ++++++++++++++++++++++++++ gui/v2/ui/pages/menu_page.py | 26 ++++++----------------- gui/v2/ui/styles/css/menu_css.py | 9 +++++++- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/gui/v2/presenters/data/profile_data.py b/gui/v2/presenters/data/profile_data.py index fb4c95d..601e9fa 100644 --- a/gui/v2/presenters/data/profile_data.py +++ b/gui/v2/presenters/data/profile_data.py @@ -198,3 +198,32 @@ def convert_to_dto(raw_dict: dict) -> ProfileDto: needs_warning=needs_warning ) + +#################################################### +### Above this line is the creation of the DTO + +### Below is the use of the DTO in the display + + +def get_display_text(dto: RenderProfileDto) -> tuple: + """Create the display text for when a profile is selected on the menu page.""" + location_text = dto.location_text + operator_name = dto.operator_name + nostr_public_key = dto.nostr_public_key + needs_warning = dto.needs_warning + + if needs_warning: + top_text = "Upgrade browser!" + bottom_text = "Go to Edit Profile, and Pick a New Browser." + else: + top_text = f"Location: {location_text}\n\nOperator: {operator_name}" + bottom_text = f"Nostr: {nostr_public_key}" + + return top_text, bottom_text + + +def get_display_color(dto: RenderProfileDto) -> str: + """Pick the display color, based on the profile type, from the DTO""" + profile_type = dto.profile_type + color = "black" if profile_type == ProfileType.SESSION else "white" + return color \ No newline at end of file diff --git a/gui/v2/ui/pages/menu_page.py b/gui/v2/ui/pages/menu_page.py index f444f07..4cfd0d9 100755 --- a/gui/v2/ui/pages/menu_page.py +++ b/gui/v2/ui/pages/menu_page.py @@ -34,7 +34,7 @@ from gui.v2.actions.menu_results import MenuResult from gui.v2.ui.pages.Page import Page from gui.v2.ui.pages.location_verification_page import LocationVerificationPage from gui.v2.ui.styles.styles import SCROLLBAR_CYAN_QSS -from gui.v2.ui.styles.css.menu_css import CREATE_BUTTON_STYLE, verification_style_one, VERIFICATION_STYLE_TWO +from gui.v2.ui.styles.css.menu_css import CREATE_BUTTON_STYLE, verification_style_one, VERIFICATION_STYLE_TWO, left_panel_profile_style, check_mark_style from gui.v2.ui.popups.confirmation_popup import ConfirmationPopup from gui.v2.ui.popups.endpoint_verification_popup import EndpointVerificationPopup from gui.v2.ui.popups.ticket_data_loss_popup import TicketDataLossPopup @@ -43,7 +43,7 @@ from gui.v2.infrastructure.setup_observers import ( application_version_observer, connection_observer, profile_observer ) -from gui.v2.presenters.data.profile_data import ProfileDto, RenderProfileDto, convert_one_render_dto +from gui.v2.presenters.data.profile_data import ProfileDto, RenderProfileDto, convert_one_render_dto, get_display_text, get_display_color from gui.v2.infrastructure.thread_singleton import get_main_thread_dispatcher mainthread = get_main_thread_dispatcher() @@ -438,8 +438,7 @@ class MenuPage(Page): container_layout.addWidget(value_widget, 1) checkmark_widget = QLabel("✓") - checkmark_widget.setStyleSheet( - f"color: #4CAF50; font-size: 20px; font-weight: bold; {self.font_style}") + checkmark_widget.setStyleSheet(check_mark_style(self.font_style)) checkmark_widget.setFixedSize(20, 20) checkmark_widget.setAlignment(Qt.AlignmentFlag.AlignCenter) checkmark_widget.setVisible(bool(value and value != "N/A")) @@ -541,22 +540,9 @@ class MenuPage(Page): def _render_operator_details(self, dto: RenderProfileDto): """Create the left display for the profile, based on the DTO data""" - profile_type = dto.profile_type - location_text = dto.location_text - operator_name = dto.operator_name - nostr_public_key = dto.nostr_public_key detail_image = dto.detail_image - needs_warning = dto.needs_warning - - if needs_warning: - top_text = "Upgrade browser!" - bottom_text = "Go to Edit Profile, and Pick a New Browser." - else: - top_text = f"Location: {location_text}\n\nOperator: {operator_name}" - bottom_text = f"Nostr: {nostr_public_key}" - - - color = "black" if profile_type == ProfileType.SESSION else "white" + top_text, bottom_text = get_display_text(dto) + color = get_display_color(dto) self._detail_image(detail_image, (20, 125, 100, 100)) text_blocks = [ @@ -569,7 +555,7 @@ class MenuPage(Page): widget.setGeometry(*geometry) widget.setReadOnly(True) widget.setFrameStyle(QFrame.Shape.NoFrame) - widget.setStyleSheet(f"background: transparent; border: none; color: {color}; font-size: 17px;") + widget.setStyleSheet(left_panel_profile_style(color)) widget.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) widget.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) widget.setWordWrapMode(wrapping) diff --git a/gui/v2/ui/styles/css/menu_css.py b/gui/v2/ui/styles/css/menu_css.py index 35fe9b5..4de60ea 100644 --- a/gui/v2/ui/styles/css/menu_css.py +++ b/gui/v2/ui/styles/css/menu_css.py @@ -37,4 +37,11 @@ VERIFICATION_STYLE_TWO = f""" background: rgba(255, 255, 255, 0.1); border-radius: 4px; }} -""" \ No newline at end of file +""" + +def left_panel_profile_style(color: str) -> str: + return f"background: transparent; border: none; color: {color}; font-size: 17px;" + + +def check_mark_style(font_style: str) -> str: + return f"color: #4CAF50; font-size: 20px; font-weight: bold; {font_style}"