Beispiel #1
0
 def init_registry(self):
     self._registry = PlotRegistry()
     self._registry.set_global()
Beispiel #2
0
class PlotManager(QtCore.QObject):
    def __init__(self):
        """__init__() -> PlotManager
        
        """
        global _plot_manager
        if _plot_manager:
            m = "Plot manager can only be constructed once."
            raise UVCDATInternalError(m)
        QtCore.QObject.__init__(self)
        _plot_manager = self
        self._plot_list = {}
        self._plot_helpers = {}
        self._plot_versions = {}
        self._registry = None
        self._userplots = None
        self._plots = None
        self._plot_instances = []
        
    def init_registry(self):
        self._registry = PlotRegistry()
        self._registry.set_global()

    def initialize_plots(self):
        self.load_plots() 
            
    def parse_helper_type_str(self, text):
        last_dot = text.rfind(".")
        if last_dot > -1:
            path = text[0:last_dot]
            klass_name = text[last_dot+1:]
            module = __import__(path, globals(), locals(), [klass_name])
            klass = getattr(module, klass_name)
        else:
            try:
                klass = globals()[klass_name]
            except:
                klass =None
        return klass
    
    def load_plots(self):
        self.load_vcs_plots()
        if not self._registry:
            raise UVCDATInternalError("Plot Registry must have been initialized")
        
        pkg_parser = ConfigParser.ConfigParser()
        if pkg_parser.read(os.path.join(PLOT_FILES_PATH, 'registry.cfg')):
            for p in pkg_parser.sections():
                try:
                    plot_package_folder = os.path.join(PLOT_FILES_PATH,
                                                       pkg_parser.get(p,'codepath'))
                    plot_package_config_file = os.path.join(plot_package_folder, 
                                               pkg_parser.get(p,'config_file'))
                    
                    helper = PlotPipelineHelper
                    if pkg_parser.has_option(p, 'helper') :
                        helper = self.parse_helper_type_str(pkg_parser.get(p, 'helper'))
                    self._plot_helpers[p] = helper
                        
                    pl_parser = ConfigParser.ConfigParser()
                    if pl_parser.read(plot_package_config_file):
                        for pl in pl_parser.sections():
                            config_file = os.path.join(plot_package_folder, 
                                                       pl_parser.get(pl,'config_file'))
                            vt_file = os.path.join(plot_package_folder, 
                                                   pl_parser.get(pl, 'vt_file'))
                            if p not in self._plot_list:
                                self._plot_list[p] = {}
                            self._plot_list[p][pl] = self._registry.add_plot(pl,p,
                                                                        config_file, 
                                                                        vt_file)
                    try:
                        self._registry.load_plot_package(p)
                    except Exception, e:
                        print "Error when loading %s plot --> "%p, str(e)
                        import traceback
                        traceback.print_exc()
                        
                except Exception, e:
                    print "%s plots not loaded." % p
                    print "Error when loading package_config_file: %s" % plot_package_config_file, str(e)
                    import traceback
                    traceback.print_exc()