pyface.ui package

class pyface.ui.ShadowedModuleLoader(fullname, new_name, new_spec)[source]

Bases: Loader

This loads another module into sys.modules with a given name.

Parameters
  • fullname (str) – The full name of the module we’re trying to import. Eg. “pyface.ui.qt4.foo”

  • new_name (str) – The full name of the corresponding “real” module. Eg. “pyface.ui.qt.foo”

  • new_spec (ModuleSpec) – The spec object for the corresponding “real” module.

create_module(spec)[source]

Create the module object.

This doesn’t create the module object directly, rather it gets the underlying “real” module’s object, importing it if needed. This object is then returned as the “new” module.

exec_module(module)[source]

Execute code for the module.

This is given a module which has already been executed, so we don’t need to execute anything. However we do need to remove the __spec__ that the importlibs machinery has injected into the module and replace it with the original spec for the underlying “real” module.

class pyface.ui.ShadowedModuleFinder(package='pyface.ui.qt4.', true_package='pyface.ui.qt.')[source]

Bases: MetaPathFinder

MetaPathFinder for shadowing modules in a package

This finds modules with names that match a package but arranges loading from a different package. By default this is matches imports from any path starting with pyface.ui.qt4. and returns a loader which will instead load from pyface.ui.qt.*

The end result is that sys.modules has two entries for pointing to the same module object.

This may be hooked up by code in pyface.ui.qt4, but it can also be installed manually with:

import sys
sys.meta_path.append(ShadowedModuleFinder())
Parameters
  • package (str) – The prefix of the “shadow” package.

  • true_package (str) – The prefix of the “real” package which contains the actual code.

find_spec(fullname, path, target=None)[source]