The showTextureMap() function allows control over both material and map level texture showing in the viewport.
The form is:
showTextureMap <material> [<texmap>|<material>] <boolean>
If the optional <texmap> or <material> is not specified, Show Map in Viewports is set for the argument 1 material to the <boolean> argument.
If the optional <texmap> is specified, it will be searched for in the argument 1 material. It must be a direct subtexture of the supplied argument 1 material. Its show-in-viewport state will be set on or off according to the <boolean> argument.
If the optional material is specified, it will be searched for in the argument 1 material. Its show-in-viewport state will be set on or off according to the <boolean> argument.
Example:
showTextureMap $foo.material on
showTextureMap $foo.material $foo.material.diffusemap off
Note:
Mapping coordinates aren't explicitly enabled for all objects at creation time. When a script is run in the Listener, using 'showTextureMap' is indirectly turning mapping coordinates on. This happens during the scene redraw which happens after each line is executed, if needed. If a script is run from a script editor, or if you put parenthesis around a script, no scene redraw is performed until the entire script is run. Since no redraw is performed, no mapping coordinates exist on the object when the script tries to access them. Solutions: explicitly perform a scene redraw [redrawViews()] after 'showTextureMap', or explicitly turn on mapping coordinates for the object.
See also
TextureMap Common Properties, Operators, and Methods
Accessing The Material Editor Active Slot