Refactor GCTooltip
- Dont create a Tooltip window - Just return the tooltip grid, so we can use it with set_custom()
This commit is contained in:
parent
bc5d9c76b1
commit
8116ef1316
|
@ -302,7 +302,6 @@ class GroupchatControl(ChatControlBase):
|
|||
formattings_button = self.xml.get_object('formattings_button')
|
||||
formattings_button.set_sensitive(False)
|
||||
|
||||
self.current_tooltip = None
|
||||
if parent_win is not None:
|
||||
# On AutoJoin with minimize Groupchats are created without parent
|
||||
# Tooltip Window and Actions have to be created with parent
|
||||
|
@ -473,6 +472,9 @@ class GroupchatControl(ChatControlBase):
|
|||
self.banner_actionbar.pack_end(self.hide_roster_button)
|
||||
self.banner_actionbar.pack_start(self.subject_button)
|
||||
|
||||
# GC Roster tooltip
|
||||
self.gc_tooltip = tooltips.GCTooltip()
|
||||
|
||||
self.control_menu = gui_menu_builder.get_groupchat_menu(self.control_id)
|
||||
|
||||
app.ged.register_event_handler('gc-presence-received', ged.GUI1,
|
||||
|
@ -702,8 +704,6 @@ class GroupchatControl(ChatControlBase):
|
|||
if widget.get_tooltip_window():
|
||||
return
|
||||
widget.set_has_tooltip(True)
|
||||
widget.set_tooltip_window(tooltips.GCTooltip(
|
||||
self.account, self.parent_win.window))
|
||||
id_ = widget.connect('query-tooltip', self.query_tooltip)
|
||||
self.handlers[id_] = widget
|
||||
|
||||
|
@ -711,41 +711,35 @@ class GroupchatControl(ChatControlBase):
|
|||
try:
|
||||
row = self.list_treeview.get_path_at_pos(x_pos, y_pos)[0]
|
||||
except TypeError:
|
||||
self.gc_tooltip.clear_tooltip()
|
||||
return False
|
||||
if not row:
|
||||
self.gc_tooltip.clear_tooltip()
|
||||
return False
|
||||
|
||||
iter_ = None
|
||||
try:
|
||||
iter_ = self.model.get_iter(row)
|
||||
except Exception:
|
||||
self.gc_tooltip.clear_tooltip()
|
||||
return False
|
||||
|
||||
typ = self.model[iter_][Column.TYPE]
|
||||
nick = self.model[iter_][Column.NICK]
|
||||
|
||||
if typ != 'contact':
|
||||
self.gc_tooltip.clear_tooltip()
|
||||
return False
|
||||
|
||||
if self.current_tooltip != row:
|
||||
# If the row changes we hide the current tooltip
|
||||
self.current_tooltip = row
|
||||
return False
|
||||
|
||||
tooltip = widget.get_tooltip_window()
|
||||
|
||||
if tooltip.row == row:
|
||||
# We already populated the window with the row data
|
||||
return True
|
||||
tooltip.row = row
|
||||
|
||||
contact = app.contacts.get_gc_contact(
|
||||
self.account, self.room_jid, nick)
|
||||
if not contact:
|
||||
self.gc_tooltip.clear_tooltip()
|
||||
return False
|
||||
|
||||
tooltip.populate(contact)
|
||||
return True
|
||||
value, widget = self.gc_tooltip.get_tooltip(contact)
|
||||
tooltip.set_custom(widget)
|
||||
return value
|
||||
|
||||
def fill_column(self, col):
|
||||
for rend in self.renderers_list:
|
||||
|
|
|
@ -169,39 +169,40 @@ class NotificationAreaTooltip(StatusTable):
|
|||
return self.hbox
|
||||
|
||||
|
||||
class GCTooltip(Gtk.Window):
|
||||
class GCTooltip():
|
||||
# pylint: disable=E1101
|
||||
def __init__(self, account, parent):
|
||||
Gtk.Window.__init__(self, type=Gtk.WindowType.POPUP, transient_for=parent)
|
||||
self.account = account
|
||||
self.row = None
|
||||
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)
|
||||
def __init__(self):
|
||||
self.contact = None
|
||||
|
||||
self.xml = gtkgui_helpers.get_gtk_builder('tooltip_gc_contact.ui')
|
||||
for name in ('nick', 'status', 'jid', 'user_show', 'fillelement',
|
||||
'resource', 'affiliation', 'avatar', 'resource_label',
|
||||
'jid_label', 'tooltip_grid'):
|
||||
'resource', 'affiliation', 'avatar', 'resource_label',
|
||||
'jid_label', 'tooltip_grid'):
|
||||
setattr(self, name, self.xml.get_object(name))
|
||||
|
||||
self.add(self.tooltip_grid)
|
||||
self.tooltip_grid.show()
|
||||
|
||||
def clear_tooltip(self):
|
||||
self.contact = None
|
||||
|
||||
def get_tooltip(self, contact):
|
||||
if self.contact == contact:
|
||||
return True, self.tooltip_grid
|
||||
|
||||
self._populate_grid(contact)
|
||||
self.contact = contact
|
||||
return False, self.tooltip_grid
|
||||
|
||||
def _hide_grid_childs(self):
|
||||
"""
|
||||
Hide all Elements of the Tooltip Grid
|
||||
"""
|
||||
for child in self.tooltip_grid.get_children():
|
||||
child.hide()
|
||||
|
||||
def populate(self, contact):
|
||||
def _populate_grid(self, contact):
|
||||
"""
|
||||
Populate the Tooltip Grid with data of from the contact
|
||||
"""
|
||||
self.clear_tooltip()
|
||||
self._hide_grid_childs()
|
||||
|
||||
self.nick.set_text(contact.get_shown_name())
|
||||
self.nick.show()
|
||||
|
|
Loading…
Reference in New Issue