show_tooltip uses less argumens, added some

docs, explaining what this arguments are for
This commit is contained in:
Dimitur Kirov 2006-02-28 10:13:42 +00:00
parent 2af0a1dd29
commit 1f467c0fc3
5 changed files with 93 additions and 71 deletions

View File

@ -985,14 +985,14 @@ class ToplevelAgentBrowser(AgentBrowser):
view = self.window.services_treeview view = self.window.services_treeview
pointer = view.get_pointer() pointer = view.get_pointer()
props = view.get_path_at_pos(pointer[0], pointer[1]) props = view.get_path_at_pos(pointer[0], pointer[1])
if props and self.tooltip.id == props[0]:
# check if the current pointer is at the same path # check if the current pointer is at the same path
# as it was before setting the timeout # as it was before setting the timeout
if props and self.tooltip.id == props[0]:
# bounding rectangle of coordinates for the cell within the treeview
rect = view.get_cell_area(props[0], props[1]) rect = view.get_cell_area(props[0], props[1])
# position of the treeview on the screen
position = view.window.get_origin() position = view.window.get_origin()
pointer = self.window.window.get_pointer() self.tooltip.show_tooltip(state, rect.height, position[1] + rect.y)
self.tooltip.show_tooltip(state, (pointer[0], rect.height),
(position[0], position[1] + rect.y))
else: else:
self.tooltip.hide_tooltip() self.tooltip.hide_tooltip()

View File

@ -811,16 +811,18 @@ _('Connection with peer cannot be established.'))
pointer = self.tree.get_pointer() pointer = self.tree.get_pointer()
props = self.tree.get_path_at_pos(pointer[0], props = self.tree.get_path_at_pos(pointer[0],
pointer[1] - self.height_diff) pointer[1] - self.height_diff)
if props and self.tooltip.id == props[0]:
# check if the current pointer is at the same path # check if the current pointer is at the same path
# as it was before setting the timeout # as it was before setting the timeout
if props and self.tooltip.id == props[0]:
iter = self.model.get_iter(props[0]) iter = self.model.get_iter(props[0])
sid = self.model[iter][C_SID].decode('utf-8') sid = self.model[iter][C_SID].decode('utf-8')
file_props = self.files_props[sid[0]][sid[1:]] file_props = self.files_props[sid[0]][sid[1:]]
# bounding rectangle of coordinates for the cell within the treeview
rect = self.tree.get_cell_area(props[0],props[1]) rect = self.tree.get_cell_area(props[0],props[1])
# position of the treeview on the screen
position = widget.window.get_origin() position = widget.window.get_origin()
self.tooltip.show_tooltip(file_props , (pointer[0], rect.height ), self.tooltip.show_tooltip(file_props , rect.height,
(position[0], position[1] + rect.y + self.height_diff)) position[1] + rect.y + self.height_diff)
else: else:
self.tooltip.hide_tooltip() self.tooltip.hide_tooltip()

View File

@ -860,14 +860,15 @@ class RosterWindow:
def show_tooltip(self, contact): def show_tooltip(self, contact):
pointer = self.tree.get_pointer() pointer = self.tree.get_pointer()
props = self.tree.get_path_at_pos(pointer[0], pointer[1]) props = self.tree.get_path_at_pos(pointer[0], pointer[1])
if props and self.tooltip.id == props[0]:
# check if the current pointer is at the same path # check if the current pointer is at the same path
# as it was before setting the timeout # as it was before setting the timeout
if props and self.tooltip.id == props[0]:
# bounding rectangle of coordinates for the cell within the treeview
rect = self.tree.get_cell_area(props[0], props[1]) rect = self.tree.get_cell_area(props[0], props[1])
# position of the treeview on the screen
position = self.tree.window.get_origin() position = self.tree.window.get_origin()
pointer = self.window.get_pointer() self.tooltip.show_tooltip(contact, rect.height, position[1] + rect.y)
self.tooltip.show_tooltip(contact, (pointer[0], rect.height),
(position[0], position[1] + rect.y))
else: else:
self.tooltip.hide_tooltip() self.tooltip.hide_tooltip()

View File

@ -341,8 +341,7 @@ class Systray:
position = widget.window.get_origin() position = widget.window.get_origin()
if self.tooltip.id == position: if self.tooltip.id == position:
size = widget.window.get_size() size = widget.window.get_size()
self.tooltip.show_tooltip('', self.tooltip.show_tooltip('', size[1], position[1])
(widget.window.get_pointer()[0], size[1]), position)
def on_tray_motion_notify_event(self, widget, event): def on_tray_motion_notify_event(self, widget, event):
wireq=widget.size_request() wireq=widget.size_request()

View File

@ -41,23 +41,33 @@ _ = i18n._
APP = i18n.APP APP = i18n.APP
class BaseTooltip: class BaseTooltip:
''' Base Tooltip; Usage: ''' Base Tooltip class;
Usage:
tooltip = BaseTooltip() tooltip = BaseTooltip()
.... ....
tooltip.show_tooltip('', window_positions, widget_positions) tooltip.show_tooltip(data, widget_height, widget_y_position)
#FIXME: what is window, what is widget?
.... ....
if tooltip.timeout != 0: if tooltip.timeout != 0:
tooltip.hide_tooltip() tooltip.hide_tooltip()
* data - the text to be displayed (extenders override this argument and
dislpay 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): def __init__(self):
self.timeout = 0 self.timeout = 0
self.prefered_position = [0, 0] self.preferred_position = [0, 0]
self.win = None self.win = None
self.id = None self.id = None
def populate(self, data): def populate(self, data):
''' this method must be overriden by all extenders ''' ''' 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.create_window()
self.win.add(gtk.Label(data)) self.win.add(gtk.Label(data))
@ -68,33 +78,34 @@ class BaseTooltip:
self.win.set_resizable(False) self.win.set_resizable(False)
self.win.set_name('gtk-tooltips') self.win.set_name('gtk-tooltips')
self.win.set_events(gtk.gdk.POINTER_MOTION_MASK) self.win.set_events(gtk.gdk.POINTER_MOTION_MASK)
self.win.connect_after('expose_event', self.expose) self.win.connect_after('expose_event', self.expose)
self.win.connect('size-request', self.size_request) self.win.connect('size-request', self.on_size_request)
self.win.connect('motion-notify-event', self.motion_notify_event) self.win.connect('motion-notify-event', self.motion_notify_event)
self.screen = self.win.get_screen()
def motion_notify_event(self, widget, event): def motion_notify_event(self, widget, event):
self.hide_tooltip() self.hide_tooltip()
def size_request(self, widget, requisition): def on_size_request(self, widget, requisition):
screen = self.win.get_screen()
half_width = requisition.width / 2 + 1 half_width = requisition.width / 2 + 1
if self.prefered_position[0] < half_width: if self.preferred_position[0] < half_width:
self.prefered_position[0] = 0 self.preferred_position[0] = 0
elif self.prefered_position[0] + requisition.width > screen.get_width() \ elif self.preferred_position[0] + requisition.width > \
+ half_width: self.screen.get_width() + half_width:
self.prefered_position[0] = screen.get_width() - requisition.width self.preferred_position[0] = self.screen.get_width() - \
requisition.width
else: else:
self.prefered_position[0] -= half_width self.preferred_position[0] -= half_width
screen.get_height() screen.get_height()
if self.prefered_position[1] + requisition.height > screen.get_height(): if self.preferred_position[1] + requisition.height > \
self.screen.get_height():
# flip tooltip up # flip tooltip up
self.prefered_position[1] -= requisition.height + self.widget_height \ self.preferred_position[1] -= requisition.height + \
+ 8 self.widget_height + 8
if self.prefered_position[1] < 0: if self.preferred_position[1] < 0:
self.prefered_position[1] = 0 self.preferred_position[1] = 0
self.win.move(self.prefered_position[0], self.prefered_position[1]) self.win.move(self.preferred_position[0], self.preferred_position[1])
def expose(self, widget, event): def expose(self, widget, event):
style = self.win.get_style() style = self.win.get_style()
@ -109,12 +120,24 @@ class BaseTooltip:
None, self.win, 'tooltip', size[0] - 1, 0, 1, -1) None, self.win, 'tooltip', size[0] - 1, 0, 1, -1)
return True return True
def show_tooltip(self, data, widget_pos, win_size): 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
'''
# set tooltip contents
self.populate(data) self.populate(data)
new_x = win_size[0] + widget_pos[0]
new_y = win_size[1] + widget_pos[1] + 4 # get the X position of mouse pointer on the screen
self.prefered_position = [new_x, new_y] pointer_x = self.screen.get_display().get_pointer()[1]
self.widget_height = widget_pos[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.ensure_style() self.win.ensure_style()
self.win.show_all() self.win.show_all()
@ -150,7 +173,7 @@ class StatusTable:
if status: if status:
status = status.strip() status = status.strip()
if status != '': if status != '':
# make sure 'status' is unicode before we send to to reduce_chars... # make sure 'status' is unicode before we send to to reduce_chars
if isinstance(status, str): if isinstance(status, str):
status = unicode(status, encoding='utf-8') status = unicode(status, encoding='utf-8')
status = gtkgui_helpers.reduce_chars_newlines(status, 0, 1) status = gtkgui_helpers.reduce_chars_newlines(status, 0, 1)
@ -183,7 +206,10 @@ class StatusTable:
self.current_row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0) self.current_row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0)
if status_time: if status_time:
self.current_row += 1 self.current_row += 1
status_time_label = gtk.Label(time.strftime("%c", status_time)) # decode locale encoded string, the same way as below (10x nk)
local_time = time.strftime("%c", status_time)
local_time = local_time.decode(locale.getpreferredencoding())
status_time_label = gtk.Label(local_time)
self.table.attach(status_time_label, 2, 4, self.current_row, self.table.attach(status_time_label, 2, 4, self.current_row,
self.current_row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0) self.current_row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0)
@ -435,9 +461,6 @@ class RosterTooltip(NotificationAreaTooltip):
info += '\n<span weight="bold">' + _('OpenPGP: ') + \ info += '\n<span weight="bold">' + _('OpenPGP: ') + \
'</span>' + gtkgui_helpers.escape_for_pango_markup(keyID) '</span>' + gtkgui_helpers.escape_for_pango_markup(keyID)
our_jids = gajim.get_our_jids()
num_resources = 0 num_resources = 0
for contact in contacts: for contact in contacts:
if contact.resource: if contact.resource:
@ -447,9 +470,7 @@ class RosterTooltip(NotificationAreaTooltip):
self.table.resize(2,1) self.table.resize(2,1)
info += '\n<span weight="bold">' + _('Status: ') + '</span>' info += '\n<span weight="bold">' + _('Status: ') + '</span>'
for contact in contacts: for contact in contacts:
# only if we have resource and it's not us add resources info and if contact.resource:
# images
if contact.resource and contact.jid not in our_jids:
status_line = self.get_status_info(contact.resource, status_line = self.get_status_info(contact.resource,
contact.priority, contact.show, contact.status) contact.priority, contact.show, contact.status)
icon_name = helpers.get_icon_name_to_show(contact) icon_name = helpers.get_icon_name_to_show(contact)
@ -484,22 +505,21 @@ class RosterTooltip(NotificationAreaTooltip):
text = text % local_time text = text % local_time
info += '\n<span style="italic">%s</span>' % text info += '\n<span style="italic">%s</span>' % text
for type_ in ('jpeg', 'png'): # uncomment this
file = os.path.join(gajim.AVATAR_PATH, prim_contact.jid + '.' + type_) #~ for type_ in ('jpeg', 'png'):
if os.path.exists(file): #~ file = os.path.join(gajim.AVATAR_PATH, prim_contact.jid + '.' + type_)
self.avatar_image.set_from_file(file) #~ if os.path.exists(file):
pix = self.avatar_image.get_pixbuf() #~ self.avatar_image.set_from_file(file)
pix = gtkgui_helpers.get_scaled_pixbuf(pix, 'tooltip') #~ pix = self.avatar_image.get_pixbuf()
self.avatar_image.set_from_pixbuf(pix) #~ pix = gtkgui_helpers.get_scaled_pixbuf(pix, 'tooltip')
break #~ self.avatar_image.set_from_pixbuf(pix)
else: #~ break
self.avatar_image.set_from_pixbuf(None) #~ else:
#~ self.avatar_image.set_from_pixbuf(None)
self.text_label.set_markup(info) self.text_label.set_markup(info)
if prim_contact.jid not in our_jids: # do not add image if it's us
self.hbox.pack_start(self.image, False, False) self.hbox.pack_start(self.image, False, False)
self.hbox.pack_start(self.table, True, True) self.hbox.pack_start(self.table, True, True)
self.hbox.pack_start(self.avatar_image, False, False) #~ self.hbox.pack_start(self.avatar_image, False, False)
self.win.add(self.hbox) self.win.add(self.hbox)
class FileTransfersTooltip(BaseTooltip): class FileTransfersTooltip(BaseTooltip):