X display visual

Randall Hopper aa8vb at yahoo.com
Wed Dec 8 14:18:39 EST 1999


Ivan Van Laningham:
 |A friend of mine is running Python on a Sparc station.  I sent him some
 |code which uses a bunch of colors, and even though he's got a truecolor
 |display it looked screwy.  He ran xdpyinfo, and these are his results:
...
 |  Depth: 8
 |  Visual Class: PseudoColor
 |
 |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).

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list