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
17 gi.pygtkcompat.enable()
18 gi.pygtkcompat.enable_gtk(version='3.0')
29 @unittest.skipUnless(Gtk, 'Gtk not available')
30 class TestATKCompat(unittest.TestCase):
32 self.assertTrue(hasattr(atk, 'Object'))
35 @unittest.skipUnless(Gtk, 'Gtk not available')
36 class TestPangoCompat(unittest.TestCase):
38 self.assertTrue(hasattr(pango, 'Layout'))
41 @unittest.skipUnless(Gtk, 'Gtk not available')
42 class TestPangoCairoCompat(unittest.TestCase):
43 def testErrorUnderlinePath(self):
44 self.assertTrue(hasattr(pangocairo, 'error_underline_path'))
47 @unittest.skipUnless(Gtk, 'Gtk not available')
48 class TestGTKCompat(unittest.TestCase):
49 def testButtons(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 testKeysyms(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 testAlignment(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 testComboBoxEntry(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)
105 combo = gtk.ComboBoxEntry(model=liststore)
106 GLib.log_set_always_fatal(old_mask)
107 combo.set_text_column(1)
109 self.assertEqual(combo.get_text_column(), 1)
110 self.assertEqual(combo.get_child().get_text(), 'One')
111 combo = gtk.combo_box_entry_new()
112 combo.set_model(liststore)
113 combo.set_text_column(1)
115 self.assertEqual(combo.get_text_column(), 1)
116 self.assertEqual(combo.get_child().get_text(), 'One')
117 combo = gtk.combo_box_entry_new_with_model(liststore)
118 combo.set_text_column(1)
120 self.assertEqual(combo.get_text_column(), 1)
121 self.assertEqual(combo.get_child().get_text(), 'One')
123 def testSizeRequest(self):
125 self.assertEqual(box.size_request(), [0, 0])
127 def testPixbuf(self):
130 def testPixbufLoader(self):
131 loader = gtk.gdk.PixbufLoader('png')
134 def testPixbufFormats(self):
135 formats = gtk.gdk.pixbuf_get_formats()
136 self.assertEqual(type(formats[0]), dict)
137 self.assertTrue('name' in formats[0])
138 self.assertTrue('description' in formats[0])
139 self.assertTrue('mime_types' in formats[0])
140 self.assertEqual(type(formats[0]['extensions']), list)
142 def testGdkWindow(self):
145 self.assertEqual(w.get_window().get_origin(), (0, 0))