1.3 Non-default visuals

First you must find the visual you want to use, then you must create a colormap using that visual. When creating a top-level shell widget, you must specify the visual, the colormap, and the depth of the visual.

Motif only allows you to change the visual of a shell widget, so the visual and colormap must be created before the shell widget is created.

When creating another shell widget, the new widget inherits the colormap and depth from the parent widget, but it inherits the visual from the parent window (the root window). Thus on every shell you create you must specify visual, colormap, and depth. Note that popup dialogs and menus are also shells.

Sample code that searches for a visual and creates a colormap which is then used by a shell widget is given here. (Note that Xm must be imported for the CreateForm() method to be available.)

    import Xt, Xm, X, sys
    Xt.ToolkitInitialize()
    dpy = Xt.OpenDisplay(None, None, None, [], sys.argv)
    visuals = dpy.GetVisualInfo({'class': X.TrueColor})
    if not visuals:
        print 'No TrueColor visuals available'
        sys.exit(1)
    v_best = visuals[0]
    for v in visuals:
        if v.depth > v_best.depth:
            v_best = v
    colormap = v_best.CreateColormap(X.AllocNone)
    toplevel = Xt.CreateApplicationShell('shell', Xt.ApplicationShell,
        {'visual': v_best, 'depth': v_best.depth, 'colormap': colormap})
    form = toplevel.CreateForm('form', {'width': 100, 'height': 100})
    form.ManageChild()
    toplevel.RealizeWidget()
    Xt.MainLoop()