From 48b3a71a25c661b663f9b473ca78ff8d1ece6f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 14 Oct 2023 17:06:54 +0200 Subject: refactor: Tooltips: Add ContactTooltip --- gajim/data/gui/contact_tooltip.ui | 159 ++++++++++++++++++++++++++++++++++++++ gajim/data/gui/roster_tooltip.ui | 159 -------------------------------------- gajim/gtk/builder.pyi | 32 ++++---- gajim/gtk/roster.py | 6 +- gajim/gtk/tooltips.py | 15 ++-- 5 files changed, 185 insertions(+), 186 deletions(-) create mode 100644 gajim/data/gui/contact_tooltip.ui delete mode 100644 gajim/data/gui/roster_tooltip.ui diff --git a/gajim/data/gui/contact_tooltip.ui b/gajim/data/gui/contact_tooltip.ui new file mode 100644 index 000000000..52628e59b --- /dev/null +++ b/gajim/data/gui/contact_tooltip.ui @@ -0,0 +1,159 @@ + + + + + + + True + False + start + 6 + 3 + 12 + + + True + False + start + start + <jid> + end + 36 + 0 + + + 1 + 1 + + + + + True + False + end + start + Tune: + + + 0 + 3 + + + + + True + False + end + start + Location: + + + 0 + 4 + + + + + True + False + start + start + True + + + 1 + 3 + + + + + True + False + start + start + True + + + 1 + 4 + + + + + True + False + start + start + <name> + end + True + 25 + 0 + + + + 1 + 0 + + + + + True + False + start + start + image-missing + 6 + + + 0 + 0 + 3 + + + + + True + False + end + start + Subscription: + + + 0 + 5 + + + + + True + False + start + start + True + + + 1 + 5 + + + + + True + False + start + start + vertical + + + + + + 1 + 2 + + + + diff --git a/gajim/data/gui/roster_tooltip.ui b/gajim/data/gui/roster_tooltip.ui deleted file mode 100644 index 52628e59b..000000000 --- a/gajim/data/gui/roster_tooltip.ui +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - True - False - start - 6 - 3 - 12 - - - True - False - start - start - <jid> - end - 36 - 0 - - - 1 - 1 - - - - - True - False - end - start - Tune: - - - 0 - 3 - - - - - True - False - end - start - Location: - - - 0 - 4 - - - - - True - False - start - start - True - - - 1 - 3 - - - - - True - False - start - start - True - - - 1 - 4 - - - - - True - False - start - start - <name> - end - True - 25 - 0 - - - - 1 - 0 - - - - - True - False - start - start - image-missing - 6 - - - 0 - 0 - 3 - - - - - True - False - end - start - Subscription: - - - 0 - 5 - - - - - True - False - start - start - True - - - 1 - 5 - - - - - True - False - start - start - vertical - - - - - - 1 - 2 - - - - diff --git a/gajim/gtk/builder.pyi b/gajim/gtk/builder.pyi index 2631d1bbd..326075a6a 100644 --- a/gajim/gtk/builder.pyi +++ b/gajim/gtk/builder.pyi @@ -301,6 +301,20 @@ class ContactInfoBuilder(Builder): devices_box: Gtk.Box +class ContactTooltipBuilder(Builder): + tooltip_grid: Gtk.Grid + jid: Gtk.Label + tune_label: Gtk.Label + location_label: Gtk.Label + tune: Gtk.Label + location: Gtk.Label + name: Gtk.Label + avatar: Gtk.Image + sub_label: Gtk.Label + sub: Gtk.Label + resources_box: Gtk.Box + + class EmojiChooserBuilder(Builder): box: Gtk.Box search: Gtk.SearchEntry @@ -792,20 +806,6 @@ class RosterItemExchangeBuilder(Builder): accept_button: Gtk.Button -class RosterTooltipBuilder(Builder): - tooltip_grid: Gtk.Grid - jid: Gtk.Label - tune_label: Gtk.Label - location_label: Gtk.Label - tune: Gtk.Label - location: Gtk.Label - name: Gtk.Label - avatar: Gtk.Image - sub_label: Gtk.Label - sub: Gtk.Label - resources_box: Gtk.Box - - class SearchViewBuilder(Builder): calendar_popover: Gtk.Popover calendar: Gtk.Calendar @@ -1011,6 +1011,8 @@ def get_builder(file_name: Literal['chat_paned.ui'], widgets: list[str] = ...) - @overload def get_builder(file_name: Literal['contact_info.ui'], widgets: list[str] = ...) -> ContactInfoBuilder: ... # noqa @overload +def get_builder(file_name: Literal['contact_tooltip.ui'], widgets: list[str] = ...) -> ContactTooltipBuilder: ... # noqa +@overload def get_builder(file_name: Literal['emoji_chooser.ui'], widgets: list[str] = ...) -> EmojiChooserBuilder: ... # noqa @overload def get_builder(file_name: Literal['exception_dialog.ui'], widgets: list[str] = ...) -> ExceptionDialogBuilder: ... # noqa @@ -1083,8 +1085,6 @@ def get_builder(file_name: Literal['roster.ui'], widgets: list[str] = ...) -> Ro @overload def get_builder(file_name: Literal['roster_item_exchange.ui'], widgets: list[str] = ...) -> RosterItemExchangeBuilder: ... # noqa @overload -def get_builder(file_name: Literal['roster_tooltip.ui'], widgets: list[str] = ...) -> RosterTooltipBuilder: ... # noqa -@overload def get_builder(file_name: Literal['search_view.ui'], widgets: list[str] = ...) -> SearchViewBuilder: ... # noqa @overload def get_builder(file_name: Literal['server_info.ui'], widgets: list[str] = ...) -> ServerInfoBuilder: ... # noqa diff --git a/gajim/gtk/roster.py b/gajim/gtk/roster.py index 08046d65b..24dcd49ac 100644 --- a/gajim/gtk/roster.py +++ b/gajim/gtk/roster.py @@ -46,7 +46,7 @@ from gajim.gtk.builder import get_builder from gajim.gtk.dialogs import ConfirmationDialog from gajim.gtk.dialogs import DialogButton from gajim.gtk.menus import get_roster_menu -from gajim.gtk.tooltips import RosterTooltip +from gajim.gtk.tooltips import ContactTooltip from gajim.gtk.util import EventHelper from gajim.gtk.util import GajimPopover from gajim.gtk.util import open_window @@ -77,7 +77,7 @@ class Roster(Gtk.ScrolledWindow, EventHelper): self._client = app.get_client(account) self._contacts = self._client.get_module('Contacts') - self._roster_tooltip = RosterTooltip() + self._roster_tooltip = ContactTooltip() self._ui = get_builder('roster.ui') self._ui.roster_treeview.set_model(None) @@ -262,7 +262,7 @@ class Roster(Gtk.ScrolledWindow, EventHelper): contact = self._contacts.get_bare_contact( model[iter_][Column.JID_OR_GROUP]) assert isinstance(contact, BareContact) - value, widget = self._roster_tooltip.get_tooltip(path, contact) + value, widget = self._roster_tooltip.get_tooltip(contact) tooltip.set_custom(widget) return value diff --git a/gajim/gtk/tooltips.py b/gajim/gtk/tooltips.py index 459b48d1c..005e63212 100644 --- a/gajim/gtk/tooltips.py +++ b/gajim/gtk/tooltips.py @@ -125,30 +125,29 @@ class GCTooltip: self._ui.tooltip_grid.destroy() -class RosterTooltip: +class ContactTooltip: def __init__(self) -> None: - self._row = None - self._ui = get_builder('roster_tooltip.ui') + self._contact = None + self._ui = get_builder('contact_tooltip.ui') def clear_tooltip(self) -> None: - self._row = None + self._contact = None for widget in self._ui.resources_box.get_children(): widget.destroy() for widget in self._ui.tooltip_grid.get_children(): widget.hide() def get_tooltip(self, - row: Gtk.TreePath, contact: types.BareContact) -> tuple[bool, Gtk.Grid]: - if self._row == row: + if self._contact == contact: return True, self._ui.tooltip_grid + self.clear_tooltip() self._populate_grid(contact) - self._row = row + self._contact = contact return False, self._ui.tooltip_grid def _populate_grid(self, contact: types.BareContact) -> None: - self.clear_tooltip() scale = self._ui.tooltip_grid.get_scale_factor() surface = contact.get_avatar(AvatarSize.TOOLTIP, scale) -- cgit v1.2.3