tools (common/template), cli (call/gui): use font-awesome instead of fontello:

following change in Libervia Media, code has been updated to use font-awesome now instead
of fontello.
This commit is contained in:
Goffi 2024-10-26 22:42:17 +02:00
commit da51288c7a
2 changed files with 47 additions and 14 deletions

View file

@ -516,7 +516,7 @@ class Renderer(object):
self.env.filters["media_type_sub"] = self.media_type_sub
# custom tests
self.env.tests["in_the_past"] = self._in_the_past
self.icons_path = os.path.join(host.media_dir, "fonts/fontello/svg")
self.fa_svgs_path = Path(host.media_dir, "fonts/fontawesome/svgs")
# policies
self.env.policies["ext.i18n.trimmed"] = True
@ -998,7 +998,6 @@ class Renderer(object):
def _icon_defs(self, *names):
"""Define svg icons which will be used in the template.
Their name is used as id
"""
svg_elt = etree.Element(
@ -1010,13 +1009,47 @@ class Renderer(object):
)
defs_elt = etree.SubElement(svg_elt, "defs")
for name in names:
path = os.path.join(self.icons_path, name + ".svg")
icon_svg_elt = etree.parse(path).getroot()
# we use icon name as id, so we can retrieve them easily
icon_svg_elt.set("id", name)
if "/" in name:
raise ValueError("SVG name must not have a `/` in it.")
if name.startswith("regular "):
name = name[8:]
path = self.fa_svgs_path / f"regular/{name}.svg"
else:
if name.startswith("solid "):
# "solid" can be explicitely specified, and it's the default value.
name = name[6:]
path = self.fa_svgs_path / f"solid/{name}.svg"
# Parse the source SVG
try:
icon_svg_elt = etree.parse(path).getroot()
except OSError:
log.exception(f"Can't load icon at {path}.")
return safe("")
if not icon_svg_elt.tag == "{http://www.w3.org/2000/svg}svg":
raise exceptions.DataError("invalid SVG element")
defs_elt.append(icon_svg_elt)
# Extract the viewBox and path data
viewbox = icon_svg_elt.get("viewBox")
path_element = icon_svg_elt.find(".//{http://www.w3.org/2000/svg}path")
# Create a new symbol element
symbol = etree.SubElement(
defs_elt,
"symbol",
id=name,
viewBox=viewbox,
)
# Add the path to the symbol
if path_element is not None:
path = etree.SubElement(
symbol,
"path",
d=path_element.get("d"),
)
return safe(etree.tostring(svg_elt, encoding="unicode"))
def _icon_use(self, name: str, cls: str = "", **kwargs: str) -> safe:
@ -1024,7 +1057,7 @@ class Renderer(object):
extra_attrs = " ".join(f'{k}="{html.escape(str(v))}"' for k, v in kwargs.items())
return safe(
'<svg class="svg-icon{cls}"{extra_attrs} xmlns="http://www.w3.org/2000/svg" '
'viewBox="0 0 100 100">\n'
'width="1em" height="1em" fill="currentColor" >\n'
' <use href="#{name}"/>'
"</svg>\n".format(
name=name,

View file

@ -205,7 +205,7 @@ class AVCallUI(QMainWindow):
async def run(cls, parent, call_data):
"""Run PyQt loop and show the app"""
media_dir = Path(await parent.host.bridge.config_get("", "media_dir"))
icons_path = media_dir / "fonts/fontello/svg"
icons_path = media_dir / "fonts/fontawesome/svgs/solid"
app = QApplication([])
av_call_gui = cls(parent.host, icons_path)
av_call_gui.show()
@ -255,8 +255,8 @@ class AVCallUI(QMainWindow):
fullscreen_layout.addStretch()
self.fullscreen_btn = QPushButton("", self)
self.fullscreen_btn.setFixedSize(BUTTON_SIZE)
self.fullscreen_icon_normal = QIcon(str(self.icons_path / "resize-full.svg"))
self.fullscreen_icon_fullscreen = QIcon(str(self.icons_path / "resize-small.svg"))
self.fullscreen_icon_normal = QIcon(str(self.icons_path / "maximize.svg"))
self.fullscreen_icon_fullscreen = QIcon(str(self.icons_path / "minimize.svg"))
self.fullscreen_btn.setIcon(self.fullscreen_icon_normal)
self.fullscreen_btn.setIconSize(ICON_SIZE)
self.fullscreen_btn.clicked.connect(self.toggle_fullscreen)
@ -266,13 +266,13 @@ class AVCallUI(QMainWindow):
self.control_buttons_layout = QHBoxLayout()
self.control_buttons_layout.setSpacing(40)
self.toggle_video_btn = cast(
ActivableButton, self.add_control_button("videocam", self.toggle_video)
ActivableButton, self.add_control_button("video", self.toggle_video)
)
self.toggle_audio_btn = cast(
ActivableButton, self.add_control_button("volume-up", self.toggle_audio)
ActivableButton, self.add_control_button("volume-high", self.toggle_audio)
)
self.share_desktop_btn = cast(
ActivableButton, self.add_control_button("desktop", self.share_desktop)
ActivableButton, self.add_control_button("display", self.share_desktop)
)
self.share_desktop_btn.deactivated_colour = "#47c68e"
self.share_desktop_btn.activated_colour = "#f24468"