Protocol images now properly display with the refactored format, of the backend producing the paths

This commit is contained in:
SimplifiedPrivacy 2026-11-18 08:53:28 -05:00
parent 5cb567c385
commit ee1157d9ab
10 changed files with 84 additions and 22 deletions

View file

@ -1,4 +1,5 @@
from core.models.orm_calls.location_calls import execute_all_locations
from core.models.enum_models import ProtocolChoice
from core.errors.logger import logger
from pathlib import Path
@ -64,3 +65,24 @@ def get_location_icon_path(image_path: Path, country_code: str, code: str, large
return full_image_path
else:
return Path(image_path, "default_location_mini.png")
def get_larger_protocol_image(image_path: Path, country_code: str, code: str, protocol: ProtocolChoice):
"""Return a Path for the location's full screen image by protocol, with None if not found."""
if protocol is None:
return None
elif isinstance(protocol, ProtocolChoice):
protocol = protocol.value
icon_image_path = f"{protocol}_{country_code}_{code}.png"
print(f"icon_image_path is {icon_image_path}")
full_image_path = Path(image_path, icon_image_path)
if full_image_path.exists():
return full_image_path
else:
return None

View file

@ -1,9 +1,9 @@
from core.models.enum_models import ProtocolChoice
from core.models.BaseProfile import ProfileType
from gui.v2.infrastructure.folders import FolderStash
from gui.v2.presenters.data.location_data import get_location_icon_path
from gui.v2.presenters.data.location_data import get_location_icon_path, get_larger_protocol_image
from gui.v2.presenters.data.app_data import get_app_icon_path
from gui.v2.presenters.data.protocol_data import get_protocol_icon_path
from core.models.enum_models import ProtocolChoice
from dataclasses import dataclass
from typing import Optional
@ -28,6 +28,19 @@ class RenderProfileDto():
nostr_public_key: str
detail_image: Path
primary_asset: Path
raised_primary_asset: bool
def _is_browser_box_this_image(image_path: Path, profile_type: ProfileType, is_tor: bool) -> Path|None:
"""Should the browser box be the detail image? If so, give us the image path"""
if profile_type == ProfileType.SESSION and not is_tor: # (tor doesn't need the browser border)
final_image_path = Path(image_path, "browser only.png")
if not final_image_path.exists():
final_image_path = None
else:
final_image_path = None
return final_image_path
def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
@ -43,30 +56,16 @@ def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
profile_id = raw_dict.get("id")
profile_type = raw_dict.get("type")
location = raw_dict.get("location")
if profile_type == ProfileType.SESSION:
primary_asset = Path(image_path, "browser only.png")
if not primary_asset.exists():
primary_asset = None
else:
primary_asset = None
protocol = raw_dict.get("protocol")
if not location:
print(raw_dict)
print("Couldn't find a location in the above dict")
return None
detail_image = get_location_icon_path(
image_path=image_path,
country_code=location.get("country_code", "na") if location else "na",
code=location.get("code", "na") if location else "na",
larger_version=True
)
country_name = location.get("country_name", "N/A")
country_city = location.get("name", "N/A")
location_text = f"{country_city}, {country_name}"
operator = location.get("operator")
if not operator:
@ -74,8 +73,37 @@ def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
print("Couldn't find the operator in the above location")
return None
country_code = location.get("country_code", "na") if location else "na"
code = location.get("code", "na") if location else "na"
nostr_public_key = operator.get("nostr_public_key", "Nostr not setup yet.")
operator_name = operator.get("name", "N/A")
sp_operator = bool(operator_name in ("Simplified Privacy", "simplified privacy"))
is_tor = bool(protocol == ProtocolChoice.TOR)
detail_image = None
if sp_operator or is_tor:
raised_primary_asset = True
primary_asset = get_larger_protocol_image(
image_path=image_path,
country_code=country_code,
code=code,
protocol=protocol
)
detail_image = _is_browser_box_this_image(image_path=image_path, profile_type=profile_type, is_tor=is_tor)
else:
raised_primary_asset = False
detail_image = get_location_icon_path(
image_path=image_path,
country_code=country_code,
code=code,
larger_version=True
)
primary_asset = _is_browser_box_this_image(image_path=image_path, profile_type=profile_type, is_tor=is_tor)
return RenderProfileDto(
profile_id=profile_id,
@ -84,7 +112,8 @@ def convert_one_render_dto(raw_dict: dict) -> Optional[RenderProfileDto]:
operator_name=operator_name,
nostr_public_key=nostr_public_key,
detail_image=detail_image,
primary_asset=primary_asset
primary_asset=primary_asset,
raised_primary_asset=raised_primary_asset
)

View file

@ -23,7 +23,7 @@ def get_protocol_icon_path(image_path: Path, protocol: ProtocolChoice) -> Path:
"""Return a Path for the location's icon, with the default if not found."""
if protocol is None:
return Path(button_path, "browsers_mini.png")
return Path(image_path, "browsers_mini.png")
elif isinstance(protocol, ProtocolChoice):
protocol = protocol.value
@ -34,4 +34,4 @@ def get_protocol_icon_path(image_path: Path, protocol: ProtocolChoice) -> Path:
if full_image_path.exists():
return full_image_path
else:
return Path(button_path, "browsers_mini.png")
return Path(image_path, "browsers_mini.png")

View file

@ -502,6 +502,9 @@ class MenuPage(Page):
# verification icons:
self._set_verification_icons_enabled()
if dto.raised_primary_asset:
self._render_protocol_image(dto)
else:
self._render_protocol_image(dto)
self._render_operator_details(dto)
@ -522,8 +525,16 @@ class MenuPage(Page):
def _render_protocol_image(self, dto):
"""Render the protocol image, or just the browser background"""
raised_primary_asset = dto.raised_primary_asset
primary_asset = dto.primary_asset
detail_image = dto.detail_image
profile_type = dto.profile_type
if raised_primary_asset and profile_type == ProfileType.SESSION:
pixmap = QPixmap(str(detail_image))
self._detail_image(detail_image, (0, 90, 400, 300), pixmap=pixmap)
pixmap = QPixmap(str(primary_asset))
self._detail_image(primary_asset, (0, 80 if profile_type == ProfileType.SESSION else 90, 400, 300), pixmap=pixmap)