forked from Support/sp-hydra-veil-gui
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
|
|
from core.services.profiles.attribute_filters import get_filtered_protocol_list
|
|
from core.models.enum_models import ProtocolChoice
|
|
|
|
from pathlib import Path
|
|
|
|
def get_protocol_button_data(button_path: str) -> dict|None:
|
|
"""Return a dict of protocols with their image paths."""
|
|
protocol_list = get_filtered_protocol_list()
|
|
|
|
protocol_display_dto = {}
|
|
|
|
for each_protocol in protocol_list:
|
|
name_as_string = each_protocol.value
|
|
button_image_path = f"{name_as_string}_button.png"
|
|
full_image_path = Path(button_path, button_image_path)
|
|
protocol_display_dto[each_protocol] = full_image_path
|
|
|
|
return protocol_display_dto
|
|
|
|
|
|
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(image_path, "browsers_mini.png")
|
|
|
|
elif isinstance(protocol, ProtocolChoice):
|
|
protocol = protocol.value
|
|
|
|
icon_image_path = f"{protocol}_mini.png"
|
|
full_image_path = Path(image_path, icon_image_path)
|
|
|
|
if full_image_path.exists():
|
|
return full_image_path
|
|
else:
|
|
return Path(image_path, "browsers_mini.png")
|