|
1 | | -# $Id: display.py,v 1.21 2007-03-17 22:14:06 mggrant Exp $ |
| 1 | +# $Id: display.py,v 1.22 2007-03-17 22:24:47 mggrant Exp $ |
2 | 2 | # |
3 | 3 | # Xlib.display -- high level display object |
4 | 4 | # |
@@ -64,17 +64,22 @@ class _BaseDisplay(protocol.display.Display): |
64 | 64 | # dealing with some ICCCM properties not defined in Xlib.Xatom |
65 | 65 |
|
66 | 66 | def __init__(self, *args, **keys): |
67 | | - apply(protocol.display.Display.__init__, (self, ) + args, keys) |
68 | | - self._atom_cache = {} |
| 67 | + apply(protocol.display.Display.__init__, (self, ) + args, keys) |
| 68 | + self._atom_cache = {} |
| 69 | + |
| 70 | + def get_atom(self, atomname, only_if_exists=0): |
| 71 | + if self._atom_cache.has_key(atomname): |
| 72 | + return self._atom_cache[atomname] |
| 73 | + |
| 74 | + r = request.InternAtom(display = self, name = atomname, only_if_exists = only_if_exists) |
| 75 | + |
| 76 | + # don't cache NONE responses in case someone creates this later |
| 77 | + if r.atom != X.NONE: |
| 78 | + self._atom_cache[atomname] = r.atom |
| 79 | + |
| 80 | + return r.atom |
69 | 81 |
|
70 | | - def get_atom(self, atomname): |
71 | | - if not self._atom_cache.has_key(atomname): |
72 | | - r = request.InternAtom(display = self, name = atomname, only_if_exists = 0) |
73 | | - self._atom_cache[atomname] = r.atom |
74 | | - |
75 | | - return self._atom_cache[atomname] |
76 | 82 |
|
77 | | - |
78 | 83 | class Display: |
79 | 84 | def __init__(self, display = None): |
80 | 85 | self.display = _BaseDisplay(display) |
@@ -444,15 +449,8 @@ def intern_atom(self, name, only_if_exists = 0): |
444 | 449 | return r.atom |
445 | 450 |
|
446 | 451 | def get_atom(self, atom, only_if_exists = 0): |
447 | | - """Alias for intern_atom, using internal cache if safe to do""" |
448 | | - if only_if_exists == 0: |
449 | | - # cache lookup will create the atom, as the user wishes |
450 | | - # safe to use the cache |
451 | | - return self.display.get_atom(atom) |
452 | | - else: |
453 | | - # the user doesn't want the atom created if it doesn't |
454 | | - # exist, so use intern_atom to avoid the cache creating it |
455 | | - return self.intern_atom(atom, only_if_exists) |
| 452 | + """Alias for intern_atom, using internal cache""" |
| 453 | + return self.display.get_atom(atom, only_if_exists) |
456 | 454 |
|
457 | 455 |
|
458 | 456 | def get_atom_name(self, atom): |
|
0 commit comments