Refactor htmltextview test
This commit is contained in:
parent
e281fb6839
commit
f26db88424
|
@ -1,17 +1,14 @@
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, Gdk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import configpaths
|
from gajim.common import configpaths
|
||||||
configpaths.init()
|
configpaths.init()
|
||||||
from gajim.common import caps_cache
|
from gajim.common import caps_cache
|
||||||
|
|
||||||
from gajim.gtk.util import get_cursor
|
|
||||||
from gajim.conversation_textview import ConversationTextview
|
from gajim.conversation_textview import ConversationTextview
|
||||||
from gajim.gui_interface import Interface
|
from gajim.gui_interface import Interface
|
||||||
|
|
||||||
|
@ -20,168 +17,192 @@ app.plugin_manager = MagicMock()
|
||||||
app.logger = MagicMock()
|
app.logger = MagicMock()
|
||||||
app.interface = Interface()
|
app.interface = Interface()
|
||||||
|
|
||||||
change_cursor = None
|
|
||||||
htmlview = ConversationTextview(None)
|
|
||||||
|
|
||||||
|
XHTML = [
|
||||||
|
'''
|
||||||
|
<div>
|
||||||
|
<span style="color: red; text-decoration:underline">Hello</span>
|
||||||
|
<br/>\n
|
||||||
|
<img src="http://images.slashdot.org/topics/topicsoftware.gif"/>
|
||||||
|
<br/>\n
|
||||||
|
<span style="font-size: 500%; font-family: serif">World</span>\n
|
||||||
|
</div>
|
||||||
|
\n
|
||||||
|
''',
|
||||||
|
|
||||||
def on_textview_motion_notify_event(widget, event):
|
'''
|
||||||
"""
|
<hr />
|
||||||
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)
|
'''
|
||||||
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
|
<p xmlns='http://www.w3.org/1999/xhtml'>a:b
|
||||||
|
<a href='http://google.com/' xmlns='http://www.w3.org/1999/xhtml'>Google</a>
|
||||||
|
</p>
|
||||||
|
<br/>
|
||||||
|
</body>
|
||||||
|
''',
|
||||||
|
|
||||||
def handler(texttag, widget, event, iter_, kind):
|
'''
|
||||||
if event.type == Gdk.EventType.BUTTON_PRESS:
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
pass
|
<p style='font-size:large'>
|
||||||
|
<span style='font-style: italic'>O
|
||||||
|
<span style='font-size:larger'>M</span>G
|
||||||
|
</span>, I'm <span style='color:green'>green</span>with
|
||||||
|
<span style='font-weight: bold'>envy</span>!
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
''',
|
||||||
|
|
||||||
|
'''
|
||||||
|
<hr />
|
||||||
|
''',
|
||||||
|
|
||||||
htmlview.print_real_text(None, xhtml='<div>'
|
'''
|
||||||
'<span style="color: red; text-decoration:underline">Hello</span><br/>\n'
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
' <img src="http://images.slashdot.org/topics/topicsoftware.gif"/><br/>\n'
|
|
||||||
'<span style="font-size: 500%; font-family: serif">World</span>\n'
|
|
||||||
'</div>\n')
|
|
||||||
htmlview.print_real_text(None, xhtml='<hr />')
|
|
||||||
htmlview.print_real_text(None, xhtml='''
|
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
|
||||||
<p xmlns='http://www.w3.org/1999/xhtml'>a:b
|
|
||||||
<a href='http://google.com/' xmlns='http://www.w3.org/1999/xhtml'>Google
|
|
||||||
</a>
|
|
||||||
</p><br/>
|
|
||||||
</body>''')
|
|
||||||
htmlview.print_real_text(None, xhtml='''
|
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
|
||||||
<p style='font-size:large'>
|
|
||||||
<span style='font-style: italic'>O
|
|
||||||
<span style='font-size:larger'>M</span>G</span>,
|
|
||||||
I'm <span style='color:green'>green</span>
|
|
||||||
with <span style='font-weight: bold'>envy</span>!
|
|
||||||
</p>
|
|
||||||
</body>
|
|
||||||
''')
|
|
||||||
htmlview.print_real_text(None, xhtml='<hr />')
|
|
||||||
htmlview.print_real_text(None, xhtml='''
|
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
|
||||||
http://test.com/ testing links autolinkifying
|
http://test.com/ testing links autolinkifying
|
||||||
</body>
|
</body>
|
||||||
''')
|
''',
|
||||||
htmlview.print_real_text(None, xhtml='<hr />')
|
|
||||||
htmlview.print_real_text(None, xhtml='''
|
'''
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
<hr />
|
||||||
<p>As Emerson said in his essay <span style='
|
''',
|
||||||
font-style: italic; background-color:cyan'>Self-Reliance</span>:</p>
|
|
||||||
<p style='margin-left: 5px; margin-right: 2%'>
|
'''
|
||||||
"A foolish consistency is the hobgoblin of little minds."
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
</p>
|
<p>As Emerson said in his essay <span style='
|
||||||
</body>
|
font-style: italic; background-color:cyan'>Self-Reliance</span>:</p>
|
||||||
''')
|
<p style='margin-left: 5px; margin-right: 2%'>
|
||||||
htmlview.print_real_text(None, xhtml='<hr />')
|
"A foolish consistency is the hobgoblin of little minds."
|
||||||
htmlview.print_real_text(None, xhtml='''
|
</p>
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
</body>
|
||||||
<p style='text-align:center'>
|
''',
|
||||||
Hey, are you licensed to <a href='http://www.jabber.org/'>Jabber</a>?
|
|
||||||
</p>
|
'''
|
||||||
<p style='text-align:right'>
|
<hr />
|
||||||
<img src='http://www.xmpp.org/images/psa-license.jpg'
|
''',
|
||||||
alt='A License to Jabber' width='50%' height='50%'/>
|
|
||||||
</p>
|
'''
|
||||||
</body>
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
''')
|
<p style='text-align:center'>
|
||||||
htmlview.print_real_text(None, xhtml='<hr />')
|
Hey, are you licensed to <a href='http://www.jabber.org/'>Jabber</a>?
|
||||||
htmlview.print_real_text(None, xhtml='''
|
</p>
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
<p style='text-align:right'>
|
||||||
<ul style='background-color:rgb(120,140,100)'>
|
<img src='http://www.xmpp.org/images/psa-license.jpg'
|
||||||
<li> One </li>
|
alt='A License to Jabber' width='50%' height='50%'/>
|
||||||
<li> Two </li>
|
</p>
|
||||||
<li> Three </li>
|
</body>
|
||||||
</ul><hr /><pre style="background-color:rgb(120,120,120)">def fac(n):
|
''',
|
||||||
def faciter(n,acc):
|
|
||||||
if n==0: return acc
|
'''
|
||||||
return faciter(n-1, acc*n)
|
<hr />
|
||||||
if n<0: raise ValueError('Must be non-negative')
|
''',
|
||||||
return faciter(n,1)</pre>
|
|
||||||
</body>
|
'''
|
||||||
''')
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
htmlview.print_real_text(None, xhtml='<hr />')
|
<ul style='background-color:rgb(120,140,100)'>
|
||||||
htmlview.print_real_text(None, xhtml='''
|
<li> One </li>
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
<li> Two </li>
|
||||||
<ol style='background-color:rgb(120,140,100)'>
|
<li> Three </li>
|
||||||
<li> One </li>
|
</ul>
|
||||||
<li> Two is nested: <ul style='background-color:rgb(200,200,100)'>
|
<hr />
|
||||||
<li> One </li>
|
<pre style="background-color:rgb(120,120,120)">def fac(n):
|
||||||
<li style='font-size:50%'> Two </li>
|
def faciter(n,acc):
|
||||||
<li style='font-size:200%'> Three </li>
|
if n==0: return acc
|
||||||
<li style='font-size:9999pt'> Four </li>
|
return faciter(n-1, acc*n)
|
||||||
</ul></li>
|
if n<0: raise ValueError('Must be non-negative')
|
||||||
<li> Three </li></ol>
|
return faciter(n,1)</pre>
|
||||||
</body>
|
</body>
|
||||||
''')
|
''',
|
||||||
htmlview.print_real_text(None, xhtml='<hr />')
|
|
||||||
htmlview.print_real_text(None, xhtml='''
|
'''
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
<hr />
|
||||||
<p>
|
''',
|
||||||
<strong>
|
|
||||||
<a href='xmpp:example@example.org'>xmpp link</a>
|
'''
|
||||||
</strong>: </p>
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
<div xmlns='http://www.w3.org/1999/xhtml'>
|
<ol style='background-color:rgb(120,140,100)'>
|
||||||
<cite style='margin: 7px;' title='xmpp:examples@example.org'>
|
<li> One </li>
|
||||||
<p>
|
<li>
|
||||||
<strong>examples@example.org wrote:</strong>
|
Two is nested:
|
||||||
</p>
|
<ul style='background-color:rgb(200,200,100)'>
|
||||||
<p>this cite - bla bla bla, smile- :-) …</p>
|
<li> One </li>
|
||||||
</cite>
|
<li style='font-size:50%'> Two </li>
|
||||||
<div>
|
<li style='font-size:200%'> Three </li>
|
||||||
<p>some text</p>
|
<li style='font-size:9999pt'> Four </li>
|
||||||
</div>
|
</ul>
|
||||||
</div>
|
</li>
|
||||||
<p/>
|
<li> Three </li>
|
||||||
<p>#232/1</p>
|
</ol>
|
||||||
</body>
|
</body>
|
||||||
''')
|
''',
|
||||||
htmlview.print_real_text(None, xhtml='<hr />')
|
|
||||||
htmlview.print_real_text(None, xhtml='''
|
'''
|
||||||
<body xmlns='http://www.w3.org/1999/xhtml'>
|
<hr />
|
||||||
<br/>
|
''',
|
||||||
<img src='data:image/png;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAw\
|
|
||||||
AAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFz\
|
'''
|
||||||
ByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp\
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
a/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJl\
|
<p>
|
||||||
ZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uis\
|
<strong>
|
||||||
F81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PH\
|
<a href='xmpp:example@example.org'>xmpp link</a>
|
||||||
hhx4dbgYKAAA7' alt='Larry'/>
|
</strong>:
|
||||||
</body>
|
</p>
|
||||||
''')
|
<div xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
htmlview.tv.show()
|
<cite style='margin: 7px;' title='xmpp:examples@example.org'>
|
||||||
sw = Gtk.ScrolledWindow()
|
<p>
|
||||||
sw.set_property('hscrollbar-policy', Gtk.PolicyType.AUTOMATIC)
|
<strong>examples@example.org wrote:</strong>
|
||||||
sw.set_property('vscrollbar-policy', Gtk.PolicyType.AUTOMATIC)
|
</p>
|
||||||
sw.set_property('border-width', 0)
|
<p>this cite - bla bla bla, smile- :-) …</p>
|
||||||
sw.add(htmlview.tv)
|
</cite>
|
||||||
sw.show()
|
<div>
|
||||||
frame = Gtk.Frame()
|
<p>some text</p>
|
||||||
frame.set_shadow_type(Gtk.ShadowType.IN)
|
</div>
|
||||||
frame.show()
|
</div>
|
||||||
frame.add(sw)
|
<p/>
|
||||||
win = Gtk.Window()
|
<p>#232/1</p>
|
||||||
win.add(frame)
|
</body>
|
||||||
win.set_default_size(400, 300)
|
''',
|
||||||
|
|
||||||
|
'''
|
||||||
|
<hr />
|
||||||
|
''',
|
||||||
|
|
||||||
|
'''
|
||||||
|
<body xmlns='http://www.w3.org/1999/xhtml'>
|
||||||
|
<br/>
|
||||||
|
<img src='data:image/png;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAw\
|
||||||
|
AAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFz\
|
||||||
|
ByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp\
|
||||||
|
a/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJl\
|
||||||
|
ZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uis\
|
||||||
|
F81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PH\
|
||||||
|
hhx4dbgYKAAA7' alt='Larry'/>
|
||||||
|
</body>
|
||||||
|
''',
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class TextviewWindow(Gtk.Window):
|
||||||
|
def __init__(self):
|
||||||
|
Gtk.Window.__init__(self, title="Textview Test")
|
||||||
|
self.set_default_size(600, 600)
|
||||||
|
|
||||||
|
self._textview = ConversationTextview(None)
|
||||||
|
|
||||||
|
scrolled = Gtk.ScrolledWindow()
|
||||||
|
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
|
||||||
|
scrolled.add(self._textview.tv)
|
||||||
|
self.add(scrolled)
|
||||||
|
self.show()
|
||||||
|
self._print_xhtml()
|
||||||
|
|
||||||
|
def _print_xhtml(self):
|
||||||
|
for xhtml in XHTML:
|
||||||
|
self._textview.print_real_text(None, xhtml=xhtml)
|
||||||
|
|
||||||
|
win = TextviewWindow()
|
||||||
|
win.connect("destroy", Gtk.main_quit)
|
||||||
win.show_all()
|
win.show_all()
|
||||||
win.connect('destroy', lambda win: Gtk.main_quit())
|
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
|
Loading…
Reference in New Issue