X display visual
Ivan Van Laningham
ivanlan at callware.com
Wed Dec 8 15:06:35 EST 1999
Hi All--
Randall Hopper wrote:
>
[snip]
> |so I guess that means python took the first color visual type it
> |found... is there a way to force it to use my 24 bit visual?
>
> Yes. Frame and Toplevel widgets have visual and colormap resources which
> can be set. Here is some simple code that just deals with 8bpp pseudo and
> 24bpp true.
>
> ---------------------------------------------------------------------------
> root = Tk()
> root.wm_withdraw()
>
> # Determine the depth, if non specified
> if depth: assert depth in [ 8, 24 ]
> else: depth = root.winfo_depth()
>
> # Just force 24-bit
> depth = 24
>
> if depth == 8: visual = "pseudocolor 8"
> else: visual = "truecolor 24"
>
> main = Toplevel( root, visual=visual )
> ---------------------------------------------------------------------------
>
> Stack your widgets under 'main' rather than 'root'.
>
> To be more robust, pick a visual returned by:
>
> root.winfo_visualsavailable()
>
> As you suggested, selecting the proper visual is the best solution (as
> opposed to forcing the user to reconfigure the default depth of their X
> server).
>
1) I don't follow the logic in solution 1, above: it looks like you're
forcing the depth to 24 regardless of whatever you find out.
2) winfo_visualsavailable() doesn't work on Windows. I can find out
the depth and get the visual string back, but I can't use
winfo_visualsavailable(). Here's the traceback:
Traceback (innermost last):
File ".\ccube.py", line 212, in ?
x = root.winfo_visualsavailable()
File ".\Tkinter.py", line 429, in winfo_visualsavailable
return map(parseitem, data)
File ".\Tkinter.py", line 428, in parseitem
return x[:1] + tuple(map(getint, x[1:]))
TypeError: illegal argument type for built-in operation
I put a temporary print into Tkinter.py:
def winfo_visualsavailable(self, includeids=0):
data = self.tk.split(
self.tk.call('winfo', 'visualsavailable', self._w,
includeids and 'includeids' or None))
print data # <== Temp print
def parseitem(x, self=self):
return x[:1] + tuple(map(getint, x[1:]))
return map(parseitem, data)
Before getting the exception, it prints "truecolor 16" for the
data--i.e., just a plain old string.
On Linux, the same call returns a list of tuples:
[('pseudocolor', 8), ('directcolor', 8), ....
and works fine.
I ended up just putting a quick check in to find out the depth, and if
it's less than 16 I modify the number of colors the program asks for.
<plain-ol-string>-ly y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan at callware.com
ivanlan at home.com
http://www.pauahtun.org
See also:
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
----------------------------------------------
More information about the Python-list
mailing list