Remove BaseTooltip

We dont needed anymore
This commit is contained in:
Philipp Hörist 2017-12-23 21:10:40 +01:00
parent 912192ed41
commit 2a41c7198f
2 changed files with 0 additions and 154 deletions

View File

@ -1102,8 +1102,6 @@ if __name__ == '__main__':
htmlview = ConversationTextview(None)
tooltip = tooltips.BaseTooltip()
def on_textview_motion_notify_event(widget, event):
"""
Change the cursor to a hand when we are over a mail or an url
@ -1129,17 +1127,6 @@ if __name__ == '__main__':
except Exception:
pass
#if line_tooltip.timeout != 0:
# Check if we should hide the line tooltip
# if not over_line:
# line_tooltip.hide_tooltip()
#if over_line and not line_tooltip.win:
# line_tooltip.timeout = GLib.timeout_add(500,
# show_line_tooltip)
# htmlview.tv.get_window(Gtk.TextWindowType.TEXT).set_cursor(
# gtkgui_helpers.get_cursor('LEFT_PTR'))
# change_cursor = tag
htmlview.tv.connect('motion_notify_event', on_textview_motion_notify_event)
def handler(texttag, widget, event, iter_, kind):

View File

@ -43,147 +43,6 @@ from gajim.common import app
from gajim.common import helpers
from gajim.common.i18n import Q_
class BaseTooltip:
"""
Base Tooltip class
Usage:
tooltip = BaseTooltip()
....
tooltip.show_tooltip(data, widget_height, widget_y_position)
....
if tooltip.timeout != 0:
tooltip.hide_tooltip()
* data - the text to be displayed (extenders override this argument and
display more complex contents)
* widget_height - the height of the widget on which we want to show tooltip
* widget_y_position - the vertical position of the widget on the screen
Tooltip is displayed aligned centered to the mouse poiner and 4px below the widget.
In case tooltip goes below the visible area it is shown above the widget.
"""
def __init__(self):
self.timeout = 0
self.preferred_position = [0, 0]
self.win = None
self.id = None
self.cur_data = None
self.shown = False
self.position_computed = False
def populate(self, data):
"""
This method must be overriden by all extenders. This is the most simple
implementation: show data as value of a label
"""
self.create_window()
self.win.add(Gtk.Label(label=data))
def create_window(self):
"""
Create a popup window each time tooltip is requested
"""
self.win = Gtk.Window.new(Gtk.WindowType.POPUP)
self.win.set_title('tooltip')
self.win.set_border_width(3)
self.win.set_resizable(False)
self.win.set_name('gtk-tooltips')
self.win.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)
self.win.set_events(Gdk.EventMask.POINTER_MOTION_MASK)
self.win.connect('size-allocate', self.on_size_allocate)
self.win.connect('motion-notify-event', self.motion_notify_event)
self.screen = self.win.get_screen()
def _get_icon_name_for_tooltip(self, contact):
"""
Helper function used for tooltip contacts/acounts
Tooltip on account has fake contact with sub == '', in this case we show
real status of the account
"""
if contact.ask == 'subscribe':
return 'requested'
elif contact.sub in ('both', 'to', ''):
return contact.show
return 'not in roster'
def motion_notify_event(self, widget, event):
GLib.idle_add(self.hide_tooltip)
def on_size_allocate(self, widget, rect):
if not self.position_computed:
half_width = rect.width / 2 + 1
if self.preferred_position[1] + rect.height > \
self.screen.get_height():
# flip tooltip up
self.preferred_position[1] -= rect.height + self.widget_height \
+ 8
if self.preferred_position[1] < 0:
self.preferred_position[1] = self.screen.get_height() - \
rect.height - 2
if self.preferred_position[0] + rect.width + 7 < \
self.screen.get_width():
self.preferred_position[0] = self.preferred_position[0]\
+ 7
else:
self.preferred_position[0] = self.preferred_position[0]\
- rect.width - 7
self.win.move(self.preferred_position[0],
self.preferred_position[1])
return
if self.preferred_position[0] < half_width:
self.preferred_position[0] = 0
elif self.preferred_position[0] + rect.width > \
self.screen.get_width() + half_width:
self.preferred_position[0] = self.screen.get_width() - \
rect.width
else:
self.preferred_position[0] -= half_width
self.position_computed = True
self.win.move(self.preferred_position[0], self.preferred_position[1])
def show_tooltip(self, data, widget_height, widget_y_position):
"""
Show tooltip on widget
Data contains needed data for tooltip contents.
widget_height is the height of the widget on which we show the tooltip.
widget_y_position is vertical position of the widget on the screen.
"""
if self.shown:
return
self.position_computed = False
self.cur_data = data
# set tooltip contents
self.populate(data)
# get the X position of mouse pointer on the screen
pointer_x = self.screen.get_display().get_device_manager().\
get_client_pointer().get_position()[1]
# get the prefered X position of the tooltip on the screen in case this position is >
# than the height of the screen, tooltip will be shown above the widget
preferred_y = widget_y_position + widget_height + 4
self.preferred_position = [pointer_x, preferred_y]
self.widget_height = widget_height
self.win.show_all()
self.shown = True
def hide_tooltip(self):
if self.timeout > 0:
GLib.source_remove(self.timeout)
self.timeout = 0
if self.win:
self.win.destroy()
self.win = None
self.id = None
self.cur_data = None
self.shown = False
class StatusTable:
"""