14
14
'''Test clipboard interaction'''
15
from zim.gui.clipboard import Clipboard
15
from zim.gui.clipboard import *
16
16
clipboard = Clipboard()
18
19
notebook = get_test_notebook()
19
20
page = notebook.get_page(Path('Test:wiki'))
20
21
parsetree = page.get_parsetree()
21
23
clipboard.set_parsetree(notebook, page, parsetree)
22
24
newtree = clipboard.request_parsetree(None, block=True)
23
25
self.assertEqual(newtree.tostring(), parsetree.tostring())
28
text = 'some **bold** text'
29
parsetree = zim.formats.get_format('plain').Parser().parse(text.decode('utf-8'))
30
clipboard.set_parsetree(notebook, page, parsetree)
32
wanted = 'some **bold** text\n'
33
text = clipboard.wait_for_text()
34
self.assertEqualDiff(text, wanted)
39
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
40
<meta name="Description" content="Copy-Paste Buffer">
41
<meta name="Generator" content="Zim">
45
some <strong>bold</strong> text<br>
51
selection = clipboard.wait_for_contents('text/html')
52
self.assertEqualDiff(selection.data, wanted)
58
StartFragment:000000450\r
59
EndFragment:000000495\r
60
StartSelection:000000450\r
61
EndSelection:000000495\r
62
SourceURL:zim://copy-pase-buffer\r
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><meta http-equiv="Content-Type" content="text/html;charset=utf-8">
64
<meta name="Description" content="Copy-Paste Buffer">
65
<meta name="Generator" content="Zim"></HEAD><BODY><!--StartFragment--><p>
66
some <strong>bold</strong> text<br>
68
<!--EndFragment--></BODY></HTML>'''
69
selection = clipboard.wait_for_contents('HTML Format')
70
self.assertEqualDiff(selection.data, wanted)
74
clipboard.set_pagelink(notebook, page)
76
selection = clipboard.wait_for_contents(INTERNAL_PAGELIST_TARGET_NAME)
77
self.assertEqual(selection.data, 'Test:wiki\r\n')
79
selection = clipboard.wait_for_contents(PAGELIST_TARGET_NAME)
80
self.assertEqual(selection.data, 'Unnamed Notebook?Test:wiki\r\n')
26
83
<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<zim-tree><link href="Test:wiki">Test:wiki</link></zim-tree>'''
27
clipboard.set_pagelink(notebook, page)
84
newtree = clipboard.request_parsetree(None, block=True)
85
self.assertEqual(newtree.tostring(), wanted)
87
text = clipboard.wait_for_text()
88
self.assertEqual(text, 'Test:wiki')
92
<?xml version='1.0' encoding='utf-8'?>\n<zim-tree>some string</zim-tree>'''
93
clipboard.set_text('some string')
28
94
newtree = clipboard.request_parsetree(None, block=True)
29
95
self.assertEqual(newtree.tostring(), wanted)