1 # -*- Mode: Python; py-indent-offset: 4 -*-
2 # vim: tabstop=4 shiftwidth=4 expandtab
6 from gi.repository import GLib
9 from gi.repository import Pango
10 from gi.repository import Atk
11 from gi.repository import Gdk
12 from gi.repository import Gtk
13 (Atk, Gtk, Pango) # pyflakes
18 pygtkcompat.enable_gtk(version='3.0')
29 @unittest.skipUnless(Gtk, 'Gtk not available')
30 class TestATKCompat(unittest.TestCase):
31 def test_object(self):
32 self.assertTrue(hasattr(atk, 'Object'))
35 @unittest.skipUnless(Gtk, 'Gtk not available')
36 class TestPangoCompat(unittest.TestCase):
37 def test_layout(self):
38 self.assertTrue(hasattr(pango, 'Layout'))
41 @unittest.skipUnless(Gtk, 'Gtk not available')
42 class TestPangoCairoCompat(unittest.TestCase):
43 def test_error_underline_path(self):
44 self.assertTrue(hasattr(pangocairo, 'error_underline_path'))
47 @unittest.skipUnless(Gtk, 'Gtk not available')
48 class TestGTKCompat(unittest.TestCase):
49 def test_buttons(self):
50 self.assertEqual(Gdk._2BUTTON_PRESS, 5)
51 self.assertEqual(Gdk.BUTTON_PRESS, 4)
54 self.assertEqual(gtk.WINDOW_TOPLEVEL, Gtk.WindowType.TOPLEVEL)
55 self.assertEqual(gtk.PACK_START, Gtk.PackType.START)
58 self.assertEqual(gtk.EXPAND, Gtk.AttachOptions.EXPAND)
59 self.assertEqual(gtk.gdk.SHIFT_MASK, Gdk.ModifierType.SHIFT_MASK)
61 def test_keysyms(self):
63 self.assertEqual(gtk.keysyms.Escape, Gdk.KEY_Escape)
64 self.assertTrue(gtk.keysyms._0, Gdk.KEY_0)
68 self.assertTrue(isinstance(widget.style.base[gtk.STATE_NORMAL],
71 def test_alignment(self):
73 self.assertEqual(a.props.xalign, 0.0)
74 self.assertEqual(a.props.yalign, 0.0)
75 self.assertEqual(a.props.xscale, 0.0)
76 self.assertEqual(a.props.yscale, 0.0)
83 expand, fill, padding, pack_type = box.query_child_packing(child)
84 self.assertTrue(expand)
86 self.assertEqual(padding, 0)
87 self.assertEqual(pack_type, gtk.PACK_START)
91 expand, fill, padding, pack_type = box.query_child_packing(child)
92 self.assertTrue(expand)
94 self.assertEqual(padding, 0)
95 self.assertEqual(pack_type, gtk.PACK_END)
97 def test_combobox_entry(self):
98 liststore = gtk.ListStore(int, str)
99 liststore.append((1, 'One'))
100 liststore.append((2, 'Two'))
101 liststore.append((3, 'Three'))
102 # might cause a Pango warning, do not break on this
103 old_mask = GLib.log_set_always_fatal(
104 GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR)
106 combo = gtk.ComboBoxEntry(model=liststore)
108 GLib.log_set_always_fatal(old_mask)
109 combo.set_text_column(1)
111 self.assertEqual(combo.get_text_column(), 1)
112 self.assertEqual(combo.get_child().get_text(), 'One')
113 combo = gtk.combo_box_entry_new()
114 combo.set_model(liststore)
115 combo.set_text_column(1)
117 self.assertEqual(combo.get_text_column(), 1)
118 self.assertEqual(combo.get_child().get_text(), 'One')
119 combo = gtk.combo_box_entry_new_with_model(liststore)
120 combo.set_text_column(1)
122 self.assertEqual(combo.get_text_column(), 1)
123 self.assertEqual(combo.get_child().get_text(), 'One')
125 def test_size_request(self):
127 self.assertEqual(box.size_request(), [0, 0])
129 def test_pixbuf(self):
132 def test_pixbuf_loader(self):
133 loader = gtk.gdk.PixbufLoader('png')
136 def test_pixbuf_formats(self):
137 formats = gtk.gdk.pixbuf_get_formats()
138 self.assertEqual(type(formats[0]), dict)
139 self.assertTrue('name' in formats[0])
140 self.assertTrue('description' in formats[0])
141 self.assertTrue('mime_types' in formats[0])
142 self.assertEqual(type(formats[0]['extensions']), list)
144 def test_gdk_window(self):
147 self.assertEqual(w.get_window().get_origin(), (0, 0))