Skip to content

Commit

Permalink
update(ui): display avatar right into the combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Oct 10, 2024
1 parent 6492e6d commit d24b16e
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 222 deletions.
41 changes: 31 additions & 10 deletions qtribu/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,39 @@ def local_path(self, base_path: Path = Path().home() / ".geotribu/cdn/") -> Path
)

# QChat
QCHAT_NICKNAME_MINLENGTH = 3
ADMIN_MESSAGES_NICKNAME = "admin"
ADMIN_MESSAGES_AVATAR = "mIconWarning.svg"
ERROR_MESSAGES_COLOR = "#ff0000"
INTERNAL_MESSAGE_AUTHOR = "internal"
QCHAT_NICKNAME_MINLENGTH: int = 3
ADMIN_MESSAGES_NICKNAME: str = "admin"
ADMIN_MESSAGES_AVATAR: str = "mIconWarning.svg"
ERROR_MESSAGES_COLOR: str = "#ff0000"
INTERNAL_MESSAGE_AUTHOR: str = "internal"
QCHAT_USER_AVATARS: dict[str, str] = {
"Arrow Up": "mActionArrowUp.svg",
"Calculate": "mActionCalculateField.svg",
"Camera": "mIconCamera.svg",
"Certificate": "mIconCertificate.svg",
"Comment": "mIconInfo.svg",
"Compressed": "mIconZip.svg",
"Folder": "mIconFolder.svg",
"GeoPackage": "mGeoPackage.svg",
"GPU": "mIconGPU.svg",
"HTML": "mActionAddHtml.svg",
"Information": "mActionPropertiesWidget.svg",
"Network Logger": "mIconNetworkLogger.svg",
"Postgis": "mIconPostgis.svg",
"Python": "mIconPythonFile.svg",
"Pyramid": "mIconPyramid.svg",
"Raster": "mIconRaster.svg",
"Spatialite": "mIconSpatialite.svg",
"Tooltip": "mActionMapTips.svg",
"XYZ": "mIconXyz.svg",
}

# QChat cheatcodes
CHEATCODE_DIZZY = "givemesomecheese"
CHEATCODE_DONTCRYBABY = "dontcrybaby"
CHEATCODE_IAMAROBOT = "iamarobot"
CHEATCODE_10OCLOCK = "its10oclock"
CHEATCODE_QGIS_PRO_LICENSE = "qgisprolicense"
CHEATCODE_DIZZY: str = "givemesomecheese"
CHEATCODE_DONTCRYBABY: str = "dontcrybaby"
CHEATCODE_IAMAROBOT: str = "iamarobot"
CHEATCODE_10OCLOCK: str = "its10oclock"
CHEATCODE_QGIS_PRO_LICENSE: str = "qgisprolicense"

CHEATCODES = [
CHEATCODE_DIZZY,
Expand Down
1 change: 0 additions & 1 deletion qtribu/gui/dck_qchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any, Optional

# PyQGIS
#
from PyQt5 import QtWebSockets # noqa QGS103
from qgis.core import Qgis, QgsApplication
from qgis.gui import QgisInterface, QgsDockWidget
Expand Down
65 changes: 44 additions & 21 deletions qtribu/gui/wdg_authoring.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# standard
from pathlib import Path
from typing import Optional

# PyQGIS
from qgis.core import QgsApplication
from qgis.core import Qgis, QgsApplication
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QWidget

# plugin
from qtribu.constants import QCHAT_USER_AVATARS
from qtribu.gui.gui_commons import QVAL_ALPHANUM, QVAL_EMAIL, QVAL_URL
from qtribu.toolbelt import PlgLogger, PlgOptionsManager


class AuthoringWidget(QWidget):
def __init__(self, parent: QWidget = None):
def __init__(self, parent: Optional[QWidget] = None):
"""QWidget to set user informations.
:param parent: parent widget or application
Expand All @@ -32,26 +33,34 @@ def __init__(self, parent: QWidget = None):
self.lne_linkedin_account.setValidator(QVAL_URL)
self.lne_twitter_account.setValidator(QVAL_URL)

# play sound on ringtone changed
self.cbb_qchat_avatar.currentIndexChanged.connect(self.on_avatar_index_changed)
# avatar combobox
self.cbb_avatars_populate()

# fill fields from saved settings
self.load_settings()

def load_settings(self) -> dict:
def load_settings(self) -> None:
"""Load options from QgsSettings into UI form."""
settings = self.plg_settings.get_plg_settings()

# author
self.lne_qchat_nickname.setText(settings.author_nickname)
avatar_index = self.cbb_qchat_avatar.findText(
settings.author_avatar, Qt.MatchFixedString
)
if avatar_index >= 0:
self.cbb_qchat_avatar.setCurrentIndex(avatar_index)
self.btn_avatar_preview.setIcon(
QIcon(QgsApplication.iconPath(settings.author_avatar))

# retrieve avatar amon values
if settings.author_avatar in QCHAT_USER_AVATARS.values():

self.cbb_qchat_avatar.setCurrentIndex(
list(QCHAT_USER_AVATARS.values()).index(settings.author_avatar)
)
else:
self.log(
message="Avatar {} has not been found among available one: {}".format(
settings.author_avatar, ", ".join(QCHAT_USER_AVATARS.values())
),
log_level=Qgis.Warning,
push=True,
)
self.cbb_qchat_avatar.setCurrentIndex(4)

self.lne_firstname.setText(settings.author_firstname)
self.lne_lastname.setText(settings.author_lastname)
Expand All @@ -68,7 +77,9 @@ def save_settings(self) -> None:

# store user inputs
settings.author_nickname = self.lne_qchat_nickname.text()
settings.author_avatar = self.cbb_qchat_avatar.currentText()
settings.author_avatar = QCHAT_USER_AVATARS.get(
self.cbb_qchat_avatar.currentText(), "mIconInfo.svg"
)
settings.author_firstname = self.lne_firstname.text()
settings.author_lastname = self.lne_lastname.text()
settings.author_email = self.lne_email.text()
Expand All @@ -80,10 +91,22 @@ def save_settings(self) -> None:
# save it
self.plg_settings.save_from_object(settings)

def on_avatar_index_changed(self) -> None:
"""
Action launched when avatar index is changed in combobox
"""
self.btn_avatar_preview.setIcon(
QIcon(QgsApplication.iconPath(self.cbb_qchat_avatar.currentText()))
)
def cbb_avatars_populate(self) -> None:
"""Populate combobox of avatars."""
# save current index
current_item_idx = self.cbb_qchat_avatar.currentIndex()

# clear
self.cbb_qchat_avatar.clear()

# populate
for avatar_description, avatar_path in QCHAT_USER_AVATARS.items():

# avatar
self.cbb_qchat_avatar.addItem(
QIcon(QgsApplication.iconPath(avatar_path)),
avatar_description,
)

# restore current index
self.cbb_qchat_avatar.setCurrentIndex(current_item_idx)
Loading

0 comments on commit d24b16e

Please sign in to comment.