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='
' 'Hello
\n' '
\n' 'World\n' '
\n') htmlview.print_real_text(None, xhtml='
') htmlview.print_real_text(None, xhtml='''

a:b Google


''') htmlview.print_real_text(None, xhtml='''

O MG, I'm green with envy!

''') htmlview.print_real_text(None, xhtml='
') htmlview.print_real_text(None, xhtml=''' http://test.com/ testing links autolinkifying ''') htmlview.print_real_text(None, xhtml='
') 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='
') htmlview.print_real_text(None, xhtml='''

Hey, are you licensed to Jabber?

A License to Jabber

''') htmlview.print_real_text(None, xhtml='
') 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='
') htmlview.print_real_text(None, xhtml='''
  1. One
  2. Two is nested:
  3. Three
''') htmlview.print_real_text(None, xhtml='
') htmlview.print_real_text(None, xhtml='''

xmpp link :

examples@example.org wrote:

this cite - bla bla bla, smile- :-) …

some text

#232/1

''') htmlview.print_real_text(None, xhtml='
') htmlview.print_real_text(None, xhtml='''
Larry ''') htmlview.tv.show() sw = Gtk.ScrolledWindow() sw.set_property('hscrollbar-policy', Gtk.PolicyType.AUTOMATIC) sw.set_property('vscrollbar-policy', Gtk.PolicyType.AUTOMATIC) sw.set_property('border-width', 0) sw.add(htmlview.tv) sw.show() frame = Gtk.Frame() frame.set_shadow_type(Gtk.ShadowType.IN) frame.show() frame.add(sw) win = Gtk.Window() win.add(frame) win.set_default_size(400, 300) win.show_all() win.connect('destroy', lambda win: Gtk.main_quit()) Gtk.main()