def find_decoder(cls, tag): """ This assumes that tag is present in a decoder and if it cannot find a decoder with the tag it raises ValueError :param tag: String; The tag used for saving and thus to be reused for loading that encoder back. :return: Decoder object; The object of a decoder for the tag that was passed. Or None if none were found. """ for decoder in cls.decoder_list: if tag in decoder.tags(): return decoder() return UserSubWindowFactory.Instance().findDecoder(tag)
def _discover_cpp_interfaces(self): """Return a dictionary mapping a category to a set of named C++ interfaces""" interfaces = {} cpp_interface_factory = UserSubWindowFactory.Instance() interface_names = cpp_interface_factory.keys() for name in interface_names: categories = cpp_interface_factory.categories(name) if len(categories) == 0: categories = ["General"] for category in categories: interfaces.setdefault(category, []).append(name) return interfaces
def _discover_cpp_interfaces(self, interfaces): """Return a dictionary mapping a category to a set of named C++ interfaces""" cpp_interface_factory = UserSubWindowFactory.Instance() interface_names = cpp_interface_factory.keys() for name in interface_names: categories = cpp_interface_factory.categories(name) if len(categories) == 0: categories = ["General"] for category in categories: if category in interfaces.keys(): interfaces[category].append(name) else: interfaces[category] = [name] return interfaces
def find_encoder(cls, obj): """ This assumes that obj is of a class that has an encode else it returns None :param obj: The object for encoding :return: Encoder or None; Returns the Encoder of the obj or None. """ obj_encoders = [ encoder for (encoder, compatible) in cls.encoder_dict.values() if compatible(obj, encoder) ] if len(obj_encoders) > 1: raise RuntimeError( "EncoderFactory: One or more encoder type claims to work with the passed obj: " + obj.__class__.__name__) elif len(obj_encoders) == 1: return obj_encoders[0]() else: # attempt C++! return UserSubWindowFactory.Instance().findEncoder(obj)
def __init__(self): super(CppInterfacesStartupTest, self).__init__() self._app = get_application() self._interface_manager = InterfaceManager() self._cpp_interface_names = UserSubWindowFactory.Instance().keys()