1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
11 gi
.require_version("Gtk", "3.0")
12 except ValueError as e
:
14 from gi
.repository
import Gtk
15 from gi
.repository
import Pango
16 from gi
.repository
import Atk
17 from gi
.repository
import Gdk
18 (Atk
, Gtk
, Pango
) # pyflakes
23 pygtkcompat
.enable_gtk(version
='3.0')
33 from helper
import capture_gi_deprecation_warnings
, capture_glib_warnings
36 @unittest.skipUnless(Gtk
, 'Gtk not available')
37 class TestATKCompat(unittest
.TestCase
):
38 def test_object(self
):
39 self
.assertTrue(hasattr(atk
, 'Object'))
42 @unittest.skipUnless(Gtk
, 'Gtk not available')
43 class TestPangoCompat(unittest
.TestCase
):
44 def test_layout(self
):
45 self
.assertTrue(hasattr(pango
, 'Layout'))
48 @unittest.skipUnless(Gtk
, 'Gtk not available')
49 class TestPangoCairoCompat(unittest
.TestCase
):
50 def test_error_underline_path(self
):
51 self
.assertTrue(hasattr(pangocairo
, 'error_underline_path'))
54 @unittest.skipUnless(Gtk
, 'Gtk not available')
55 class TestGTKCompat(unittest
.TestCase
):
56 def test_buttons(self
):
57 self
.assertEqual(Gdk
._2BUTTON
_PRESS
, 5)
58 self
.assertEqual(Gdk
.BUTTON_PRESS
, 4)
61 self
.assertEqual(gtk
.WINDOW_TOPLEVEL
, Gtk
.WindowType
.TOPLEVEL
)
62 self
.assertEqual(gtk
.PACK_START
, Gtk
.PackType
.START
)
65 self
.assertEqual(gtk
.EXPAND
, Gtk
.AttachOptions
.EXPAND
)
66 self
.assertEqual(gtk
.gdk
.SHIFT_MASK
, Gdk
.ModifierType
.SHIFT_MASK
)
68 def test_keysyms(self
):
70 self
.assertEqual(gtk
.keysyms
.Escape
, Gdk
.KEY_Escape
)
71 self
.assertTrue(gtk
.keysyms
._0, Gdk
.KEY_0
)
75 with
capture_gi_deprecation_warnings():
76 widget
.get_style_context().set_state(gtk
.STATE_NORMAL
)
77 self
.assertTrue(isinstance(widget
.style
.base
[gtk
.STATE_NORMAL
],
80 def test_alignment(self
):
81 # Creation of pygtk.Alignment causes hard warnings, ignore this in testing.
82 with
capture_glib_warnings(allow_warnings
=True):
85 self
.assertEqual(a
.props
.xalign
, 0.0)
86 self
.assertEqual(a
.props
.yalign
, 0.0)
87 self
.assertEqual(a
.props
.xscale
, 0.0)
88 self
.assertEqual(a
.props
.yscale
, 0.0)
95 expand
, fill
, padding
, pack_type
= box
.query_child_packing(child
)
96 self
.assertTrue(expand
)
98 self
.assertEqual(padding
, 0)
99 self
.assertEqual(pack_type
, gtk
.PACK_START
)
103 expand
, fill
, padding
, pack_type
= box
.query_child_packing(child
)
104 self
.assertTrue(expand
)
105 self
.assertTrue(fill
)
106 self
.assertEqual(padding
, 0)
107 self
.assertEqual(pack_type
, gtk
.PACK_END
)
109 def test_combobox_entry(self
):
110 liststore
= gtk
.ListStore(int, str)
111 liststore
.append((1, 'One'))
112 liststore
.append((2, 'Two'))
113 liststore
.append((3, 'Three'))
114 # might cause a Pango warning, do not break on this
115 with
capture_glib_warnings(allow_warnings
=True):
116 combo
= gtk
.ComboBoxEntry(model
=liststore
)
117 combo
.set_text_column(1)
119 self
.assertEqual(combo
.get_text_column(), 1)
120 self
.assertEqual(combo
.get_child().get_text(), 'One')
121 combo
= gtk
.combo_box_entry_new()
122 combo
.set_model(liststore
)
123 combo
.set_text_column(1)
125 self
.assertEqual(combo
.get_text_column(), 1)
126 self
.assertEqual(combo
.get_child().get_text(), 'One')
127 combo
= gtk
.combo_box_entry_new_with_model(liststore
)
128 combo
.set_text_column(1)
130 self
.assertEqual(combo
.get_text_column(), 1)
131 self
.assertEqual(combo
.get_child().get_text(), 'One')
133 def test_size_request(self
):
135 with
capture_gi_deprecation_warnings():
136 self
.assertEqual(box
.size_request(), [0, 0])
138 def test_pixbuf(self
):
141 def test_pixbuf_loader(self
):
142 # load a 1x1 pixel PNG from memory
143 data
= base64
.b64decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4n8Dw'
144 'HwAGIAJf85Z3XgAAAABJRU5ErkJggg==')
145 loader
= gtk
.gdk
.PixbufLoader('png')
149 pixbuf
= loader
.get_pixbuf()
150 self
.assertEqual(pixbuf
.get_width(), 1)
151 self
.assertEqual(pixbuf
.get_height(), 1)
153 def test_pixbuf_formats(self
):
154 formats
= gtk
.gdk
.pixbuf_get_formats()
155 self
.assertEqual(type(formats
[0]), dict)
156 self
.assertTrue('name' in formats
[0])
157 self
.assertTrue('description' in formats
[0])
158 self
.assertTrue('mime_types' in formats
[0])
159 self
.assertEqual(type(formats
[0]['extensions']), list)
161 def test_gdk_window(self
):
164 self
.assertEqual(w
.get_window().get_origin(), (0, 0))