1 from __future__
import absolute_import
7 from gi
.repository
import Gtk
, Atk
, Gdk
13 from .helper
import capture_glib_deprecation_warnings
18 from gi
.repository
import Gdk
, GdkX11
22 display
= Gdk
.Display
.get_default()
23 return isinstance(display
, GdkX11
.X11Display
)
26 @unittest.skipUnless(Gdk
, 'Gdk not available')
27 class TestGdkAtom(unittest
.TestCase
):
28 def test_create(self
):
29 atom
= Gdk
.Atom
.intern('my_string', False)
30 self
.assertEqual(atom
.name(), 'my_string')
33 atom
= Gdk
.Atom
.intern('my_string', False)
34 self
.assertEqual(str(atom
), 'my_string')
36 self
.assertEqual(str(Gdk
.SELECTION_CLIPBOARD
), 'CLIPBOARD')
39 # __repr__ should generate a string which is parsable when possible
40 # http://docs.python.org/2/reference/datamodel.html#object.__repr__
41 atom
= Gdk
.Atom
.intern('my_string', False)
42 self
.assertEqual(repr(atom
), 'Gdk.Atom.intern("my_string", False)')
43 self
.assertEqual(eval(repr(atom
)), atom
)
45 self
.assertEqual(repr(Gdk
.SELECTION_CLIPBOARD
), 'Gdk.Atom.intern("CLIPBOARD", False)')
47 @unittest.skipUnless(os
.name
!= "nt", "not on Windows")
48 def test_in_single(self
):
49 a_selection
= Gdk
.Atom
.intern('test_clipboard', False)
50 clipboard
= Gtk
.Clipboard
.get(a_selection
)
51 clipboard
.set_text('hello', 5)
53 # needs a Gdk.Atom, not a string
54 self
.assertRaises(TypeError, Gtk
.Clipboard
.get
, 'CLIPBOARD')
56 def test_in_array(self
):
57 a_plain
= Gdk
.Atom
.intern('text/plain', False)
58 a_html
= Gdk
.Atom
.intern('text/html', False)
59 a_jpeg
= Gdk
.Atom
.intern('image/jpeg', False)
61 self
.assertFalse(Gtk
.targets_include_text([]))
62 self
.assertTrue(Gtk
.targets_include_text([a_plain
, a_html
]))
63 self
.assertFalse(Gtk
.targets_include_text([a_jpeg
]))
64 self
.assertTrue(Gtk
.targets_include_text([a_jpeg
, a_plain
]))
66 self
.assertFalse(Gtk
.targets_include_image([], False))
67 self
.assertFalse(Gtk
.targets_include_image([a_plain
, a_html
], False))
68 self
.assertTrue(Gtk
.targets_include_image([a_jpeg
], False))
69 self
.assertTrue(Gtk
.targets_include_image([a_jpeg
, a_plain
], False))
71 @unittest.skipUnless(is_X11(), "only on X11")
72 def test_out_array(self
):
73 a_selection
= Gdk
.Atom
.intern('my_clipboard', False)
74 clipboard
= Gtk
.Clipboard
.get(a_selection
)
77 (res
, targets
) = clipboard
.wait_for_targets()
78 self
.assertEqual(res
, False)
79 self
.assertEqual(targets
, [])
82 clipboard
.set_text('hello', 5)
83 (res
, targets
) = clipboard
.wait_for_targets()
84 self
.assertEqual(res
, True)
85 self
.assertNotEqual(targets
, [])
86 self
.assertEqual(type(targets
[0]), Gdk
.Atom
)
87 names
= [t
.name() for t
in targets
]
88 self
.assertFalse(None in names
, names
)
89 self
.assertTrue('TEXT' in names
, names
)
91 @unittest.skipUnless(is_X11(), "only on X11")
92 @unittest.skipIf(not Gdk
or Gdk
._version
== "4.0", "not in gdk4")
93 def test_out_glist(self
):
94 display
= Gdk
.Display
.get_default()
95 with
capture_glib_deprecation_warnings():
96 dm
= display
.get_device_manager()
97 device
= dm
.get_client_pointer()
98 axes
= device
.list_axes()
99 axes_names
= [atom
.name() for atom
in axes
]
100 self
.assertNotEqual(axes_names
, [])