Add ProviderType enum and display provider type in provider item

This commit is contained in:
0xmrtt 2024-02-25 01:10:59 +01:00
parent c543ca1538
commit 495e5a7971
4 changed files with 78 additions and 2 deletions

View File

@ -2,11 +2,18 @@ import unicodedata
import re
from typing import List, Dict
from gi.repository import Gtk, Adw, GLib
from enum import Enum
class ProviderType(Enum):
IMAGE = _("Image")
CHAT = _("Chat")
VOICE = _("Voice")
TEXT = _("Text")
MOVIE = _("Movie")
class BaseProvider:
name: str
description: str = ""
provider_type: ProviderType = ProviderType.CHAT
languages: List[str] = []
developer_name: str = "0xMRTT"
developers = ["0xMRTT https://github.com/0xMRTT"]

View File

@ -8,6 +8,12 @@ template $Provider : Adw.ExpanderRow {
valign: center;
}
[suffix]
Label provider_type {
valign: center;
styles [ "tag" ]
}
Adw.ActionRow no_preferences_available {
title: _("No preferences available");
}

View File

@ -4,7 +4,7 @@ from typing import List, Dict
from gi.repository import Gtk, Adw, GLib
from bavarder.constants import app_id, rootdir
from .base import ProviderType
@Gtk.Template(resource_path=f"{rootdir}/ui/provider_item.ui")
class Provider(Adw.ExpanderRow):
@ -12,6 +12,7 @@ class Provider(Adw.ExpanderRow):
enable_switch = Gtk.Template.Child()
no_preferences_available = Gtk.Template.Child()
provider_type = Gtk.Template.Child()
def __init__(self, app, window, provider, **kwargs):
super().__init__(**kwargs)
@ -24,6 +25,19 @@ class Provider(Adw.ExpanderRow):
def setup(self):
self.set_title(self.provider.name)
self.set_subtitle(self.provider.description)
self.provider_type.set_label(self.provider.provider_type.value)
match self.provider.provider_type:
case ProviderType.IMAGE:
self.provider_type.add_css_class("badge-silver")
case ProviderType.CHAT:
self.provider_type.add_css_class("badge-gold")
case ProviderType.VOICE:
self.provider_type.add_css_class("badge-iron")
case ProviderType.TEXT:
self.provider_type.add_css_class("badge-tin")
case ProviderType.MOVIE:
self.provider_type.add_css_class("badge-titanium")
self.enable_switch.set_active( self.app.data["providers"][self.provider.slug]["enabled"])
if self.provider.get_settings_rows():

View File

@ -33,3 +33,52 @@
.sourceview {
font-family: monospace;
}
.tag {
border-radius: 20px;
background-color: alpha(currentColor, 0.07);
padding: 5px 13px;
margin: 0 2px;
}
badge-gray {
background-color: #deddda;
color: #3d3846;
}
.badge-silver {
background-color: #deddda;
color: #3d3846;
}
.badge-gold {
background-color: #f6d32d;
color: #3d3846;
}
.badge-copper {
background-color: #a47e3c;
}
.badge-bronze {
background-color: #a47e3c;
}
.badge-iron {
background-color: #3d3846;
color: #deddda;
}
.badge-steel {
background-color: #3d3846;
color: #deddda;
}
.badge-tin {
background-color: #deddda;
color: #3d3846;
}
.badge-aluminum {
background-color: #deddda;
color: #3d3846;
}
.badge-cobalt {
background-color: #3584e4;
}
.badge-titanium {
background-color: #3d3846;
color: #deddda;
}