import sys import os from unittest.mock import MagicMock sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) from gi.repository import Gtk, Gdk from gajim.common import app from gajim.common import configpaths configpaths.init() from gajim.common import caps_cache from gajim.gtk.util import get_cursor from gajim.conversation_textview import ConversationTextview from gajim.gui_interface import Interface caps_cache.capscache = MagicMock() app.plugin_manager = MagicMock() app.logger = MagicMock() app.interface = Interface() change_cursor = None htmlview = ConversationTextview(None) def on_textview_motion_notify_event(widget, event): """ Change the cursor to a hand when we are over a mail or an url """ global change_cursor w = htmlview.tv.get_window(Gtk.TextWindowType.TEXT) device = w.get_display().get_device_manager().get_client_pointer() pointer = w.get_device_position(device) x = pointer[1] y = pointer[2] tags = htmlview.tv.get_iter_at_location(x, y)[1].get_tags() if change_cursor: w.set_cursor(get_cursor('XTERM')) change_cursor = None for tag in tags: try: if tag.is_anchor: w.set_cursor(get_cursor('HAND2')) change_cursor = tag except Exception: pass htmlview.tv.connect('motion_notify_event', on_textview_motion_notify_event) def handler(texttag, widget, event, iter_, kind): if event.type == Gdk.EventType.BUTTON_PRESS: pass htmlview.tv.hyperlink_handler = htmlview.hyperlink_handler htmlview.print_real_text(None, xhtml='
a:b Google
O MG, I'm green with envy!
''') htmlview.print_real_text(None, xhtml='As Emerson said in his essay Self-Reliance:
"A foolish consistency is the hobgoblin of little minds."
''') htmlview.print_real_text(None, xhtml='Hey, are you licensed to Jabber?
''') htmlview.print_real_text(None, xhtml='
def fac(n): def faciter(n,acc): if n==0: return acc return faciter(n-1, acc*n) if n<0: raise ValueError('Must be non-negative') return faciter(n,1)''') htmlview.print_real_text(None, xhtml='
examples@example.org wrote:
this cite - bla bla bla, smile- :-) …
some text
#232/1
''') htmlview.print_real_text(None, xhtml='