def _emoji_event_box_selected(self, event_box):
'''
Called when an event box containing an emoji
was selected in the flowbox.
The emoji is then copied to the clipboard and a popover
pops up for a short time to notify the user that the emoji
has been copied to the clipboard.
:param event_box: The event box which contains the emoji
:type event_box: Gtk.EventBox object
'''
# Use .get_label() instead of .get_text() to fetch the text
# from the label widget including any embedded underlines
# indicating mnemonics and Pango markup. The emoji is in
# first <span>...</span>, and we want fetch only the emoji
# here:
text = event_box.get_child().get_label()
if _ARGS.debug:
sys.stdout.write("_emoji_event_box_selected() text = %s\n" %text)
(emoji, name) = self._parse_emoji_and_name_from_text(text)
if not emoji:
return Gdk.EVENT_PROPAGATE
self._set_clipboards(emoji)
self._add_to_recently_used(emoji)
self._emoji_selected_popover = Gtk.Popover()
self._emoji_selected_popover.set_relative_to(event_box)
self._emoji_selected_popover.set_position(Gtk.PositionType.TOP)
if name:
rectangle = Gdk.Rectangle()
rectangle.x = 0
rectangle.y = 0
rectangle.width = self._fontsize * 1.5
rectangle.height = self._fontsize * 1.5
self._emoji_selected_popover.set_pointing_to(rectangle)
label = Gtk.Label(_('Copied to clipboard!'))
self._emoji_selected_popover.add(label)
if GTK_VERSION >= (3, 22, 0):
self._emoji_selected_popover.popup()
self._emoji_selected_popover.show_all()
GLib.timeout_add(500, self._emoji_selected_popover_popdown)
评论列表
文章目录