Commit 67136184 authored by Martin Pitt's avatar Martin Pitt
Browse files

Fix Gdk.Atom to have a proper str() and repr()

Gdk.Atom is not proper GType'd class, so we cannot override the whole class.
Just override its __str__() and __repr__() methods so that printing atoms shows
something sensible. For nameless/invalid atoms, fall back to the old
<void at 0xdeadbeef> output to help with debugging.
parent 56e62858
......@@ -345,6 +345,27 @@ def color_parse(color):
return None
return color
# Note, we cannot override the entire class as Gdk.Atom has no gtype, so just
# hack some individual methods
def _gdk_atom_str(atom):
n =
if n:
return n
return Gdk.Atom.__str__(n)
def _gdk_atom_repr(atom):
n =
if n:
return 'Gdk.Atom<%s>' % n
return Gdk.Atom.__str__(n)
Gdk.Atom.__str__ = _gdk_atom_str
Gdk.Atom.__repr__ = _gdk_atom_repr
# constants
if Gdk._version >= '3.0':
SELECTION_PRIMARY = Gdk.atom_intern('PRIMARY', True)
......@@ -13,6 +13,18 @@ class TestGdkAtom(unittest.TestCase):
atom = Gdk.Atom.intern('my_string', False)
self.assertEqual(, 'my_string')
def test_str(self):
atom = Gdk.Atom.intern('my_string', False)
self.assertEqual(str(atom), 'my_string')
self.assertEqual(str(Gdk.SELECTION_CLIPBOARD), 'CLIPBOARD')
def test_repr(self):
atom = Gdk.Atom.intern('my_string', False)
self.assertEqual(repr(atom), 'Gdk.Atom<my_string>')
self.assertEqual(repr(Gdk.SELECTION_CLIPBOARD), 'Gdk.Atom<CLIPBOARD>')
def test_in_single(self):
a_selection = Gdk.Atom.intern('test_clipboard', False)
clipboard = Gtk.Clipboard.get(a_selection)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment