Do not use own window for RosterTooltip

This commit is contained in:
Philipp Hörist 2018-11-07 23:44:16 +01:00
parent 13c82ae777
commit 4534f3dbac
2 changed files with 25 additions and 32 deletions

View file

@ -258,9 +258,8 @@ class GCTooltip():
affiliation = formatted % (color, affiliation) affiliation = formatted % (color, affiliation)
return affiliation return affiliation
class RosterTooltip(Gtk.Window, StatusTable): class RosterTooltip(StatusTable):
def __init__(self, parent): def __init__(self):
Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP, transient_for=parent)
StatusTable.__init__(self) StatusTable.__init__(self)
self.create_table() self.create_table()
self.account = None self.account = None
@ -269,17 +268,9 @@ class RosterTooltip(Gtk.Window, StatusTable):
self.prim_contact = None self.prim_contact = None
self.last_widget = None self.last_widget = None
self.num_resources = 0 self.num_resources = 0
self.set_title('tooltip')
self.set_border_width(3)
self.set_resizable(False)
self.set_name('gtk-tooltips')
self.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)
self._ui = get_builder('tooltip_roster_contact.ui') self._ui = get_builder('tooltip_roster_contact.ui')
self.add(self._ui.tooltip_grid)
self._ui.tooltip_grid.show()
def clear_tooltip(self): def clear_tooltip(self):
""" """
Hide all Elements of the Tooltip Grid Hide all Elements of the Tooltip Grid
@ -290,8 +281,17 @@ class RosterTooltip(Gtk.Window, StatusTable):
if status_table: if status_table:
status_table.destroy() status_table.destroy()
self.create_table() self.create_table()
self.row = None
def populate(self, contacts, account, typ): def get_tooltip(self, row, connected_contacts, account, typ):
if self.row == row:
return True, self._ui.tooltip_grid
self._populate_grid(connected_contacts, account, typ)
self.row = row
return False, self._ui.tooltip_grid
def _populate_grid(self, contacts, account, typ):
""" """
Populate the Tooltip Grid with data of from the contact Populate the Tooltip Grid with data of from the contact
""" """
@ -447,7 +447,7 @@ class RosterTooltip(Gtk.Window, StatusTable):
self._set_idle_time(contact) self._set_idle_time(contact)
# Avatar # Avatar
scale = self.get_scale_factor() scale = self._ui.tooltip_grid.get_scale_factor()
surface = app.contacts.get_avatar( surface = app.contacts.get_avatar(
account, self.prim_contact.jid, AvatarSize.TOOLTIP, scale) account, self.prim_contact.jid, AvatarSize.TOOLTIP, scale)
if surface is None: if surface is None:

View file

@ -5563,12 +5563,14 @@ class RosterWindow:
renderer.set_property(self.renderers_propertys[renderer][0], renderer.set_property(self.renderers_propertys[renderer][0],
self.renderers_propertys[renderer][1]) self.renderers_propertys[renderer][1])
def query_tooltip(self, widget, x_pos, y_pos, keyboard_mode, tooltip): def query_tooltip(self, widget, x_pos, y_pos, _keyboard_mode, tooltip):
try: try:
row = widget.get_path_at_pos(x_pos, y_pos)[0] row = widget.get_path_at_pos(x_pos, y_pos)[0]
except TypeError: except TypeError:
self._roster_tooltip.clear_tooltip()
return False return False
if not row: if not row:
self._roster_tooltip.clear_tooltip()
return False return False
iter_ = None iter_ = None
@ -5576,6 +5578,7 @@ class RosterWindow:
model = widget.get_model() model = widget.get_model()
iter_ = model.get_iter(row) iter_ = model.get_iter(row)
except Exception: except Exception:
self._roster_tooltip.clear_tooltip()
return False return False
typ = model[iter_][Column.TYPE] typ = model[iter_][Column.TYPE]
@ -5586,9 +5589,9 @@ class RosterWindow:
if typ in ('contact', 'self_contact'): if typ in ('contact', 'self_contact'):
contacts = app.contacts.get_contacts(account, jid) contacts = app.contacts.get_contacts(account, jid)
for c in contacts: for contact in contacts:
if c.show not in ('offline', 'error'): if contact.show not in ('offline', 'error'):
connected_contacts.append(c) connected_contacts.append(contact)
if not connected_contacts: if not connected_contacts:
# no connected contacts, show the offline one # no connected contacts, show the offline one
connected_contacts = contacts connected_contacts = contacts
@ -5597,19 +5600,10 @@ class RosterWindow:
elif typ != 'account': elif typ != 'account':
return False return False
if self.current_tooltip != row: value, widget = self._roster_tooltip.get_tooltip(
# If the row changes we hide the current tooltip row, connected_contacts, account, typ)
self.current_tooltip = row tooltip.set_custom(widget)
return False return value
tooltip = widget.get_tooltip_window()
if tooltip.row == row:
# We already populated the window with the row data
return True
tooltip.row = row
tooltip.populate(connected_contacts, account, typ)
return True
def add_actions(self): def add_actions(self):
action = Gio.SimpleAction.new_stateful( action = Gio.SimpleAction.new_stateful(
@ -5842,8 +5836,7 @@ class RosterWindow:
self.collapsed_rows = app.config.get('collapsed_rows').split('\t') self.collapsed_rows = app.config.get('collapsed_rows').split('\t')
self.tree.set_has_tooltip(True) self.tree.set_has_tooltip(True)
self.tree.set_tooltip_window(RosterTooltip(self.window)) self._roster_tooltip = RosterTooltip()
self.current_tooltip = None
self.tree.connect('query-tooltip', self.query_tooltip) self.tree.connect('query-tooltip', self.query_tooltip)
# Workaround: For strange reasons signal is behaving like row-changed # Workaround: For strange reasons signal is behaving like row-changed
self._toggeling_row = False self._toggeling_row = False