src/eric7/PluginManager/PluginManager.py

branch
eric7
changeset 9299
e40589582f82
parent 9221
bf71ee032bb4
child 9413
80c06d472826
equal deleted inserted replaced
9298:8863f3e970a2 9299:e40589582f82
597 def activatePlugin(self, name, onDemand=False): 597 def activatePlugin(self, name, onDemand=False):
598 """ 598 """
599 Public method to activate a plugin. 599 Public method to activate a plugin.
600 600
601 @param name name of the module to be activated 601 @param name name of the module to be activated
602 @type str
602 @param onDemand flag indicating activation of an 603 @param onDemand flag indicating activation of an
603 on demand plugin (boolean) 604 on demand plugin
604 @return reference to the initialized plugin object 605 @type bool
606 @return reference to the initialized plugin object and an error string
607 @rtype tuple of (QObject, str)
605 @exception PluginActivationError raised to indicate an issue during the 608 @exception PluginActivationError raised to indicate an issue during the
606 plug-in activation 609 plug-in activation
607 """ 610 """
608 try: 611 try:
609 try: 612 try:
611 self.__onDemandInactiveModules[name] 614 self.__onDemandInactiveModules[name]
612 if onDemand 615 if onDemand
613 else self.__inactiveModules[name] 616 else self.__inactiveModules[name]
614 ) 617 )
615 except KeyError: 618 except KeyError:
616 return None 619 return None, f"no such plugin module: {name}"
617 620
618 if not self.__canActivatePlugin(module): 621 if not self.__canActivatePlugin(module):
619 raise PluginActivationError(module.eric7PluginModuleName) 622 raise PluginActivationError(module.eric7PluginModuleName)
620 version = getattr(module, "version", "0.0.0") 623 version = getattr(module, "version", "0.0.0")
621 className = getattr(module, "className", "") 624 className = getattr(module, "className", "")
637 except Exception as err: 640 except Exception as err:
638 module.error = str(err) 641 module.error = str(err)
639 obj = None 642 obj = None
640 ok = False 643 ok = False
641 if not ok: 644 if not ok:
642 return None 645 return None, module.error
643 646
644 self.pluginActivated.emit(name, pluginObject) 647 self.pluginActivated.emit(name, pluginObject)
645 pluginObject.eric7PluginModule = module 648 pluginObject.eric7PluginModule = module
646 pluginObject.eric7PluginName = className 649 pluginObject.eric7PluginName = className
647 pluginObject.eric7PluginVersion = version 650 pluginObject.eric7PluginVersion = version
656 self.__inactiveModules.pop(name) 659 self.__inactiveModules.pop(name)
657 with contextlib.suppress(KeyError): 660 with contextlib.suppress(KeyError):
658 self.__inactivePlugins.pop(name) 661 self.__inactivePlugins.pop(name)
659 self.__activePlugins[name] = pluginObject 662 self.__activePlugins[name] = pluginObject
660 self.__activeModules[name] = module 663 self.__activeModules[name] = module
661 return obj 664 return obj, ""
662 except PluginActivationError: 665 except PluginActivationError as err:
663 return None 666 return None, str(err)
664 667
665 def __canActivatePlugin(self, module): 668 def __canActivatePlugin(self, module):
666 """ 669 """
667 Private method to check, if a plugin can be activated. 670 Private method to check, if a plugin can be activated.
668 671
756 def getPluginObject(self, type_, typename, maybeActive=False): 759 def getPluginObject(self, type_, typename, maybeActive=False):
757 """ 760 """
758 Public method to activate an ondemand plugin given by type and 761 Public method to activate an ondemand plugin given by type and
759 typename. 762 typename.
760 763
761 @param type_ type of the plugin to be activated (string) 764 @param type_ type of the plugin to be activated
762 @param typename name of the plugin within the type category (string) 765 @type str
766 @param typename name of the plugin within the type category
767 @type str
763 @param maybeActive flag indicating, that the plugin may be active 768 @param maybeActive flag indicating, that the plugin may be active
764 already (boolean) 769 already
765 @return reference to the initialized plugin object 770 @type bool
771 @return reference to the initialized plugin object and an error string
772 @rtype tuple of (QObject, str)
766 """ 773 """
767 for name, module in list(self.__onDemandInactiveModules.items()): 774 for name, module in list(self.__onDemandInactiveModules.items()):
768 if ( 775 if (
769 getattr(module, "pluginType", "") == type_ 776 getattr(module, "pluginType", "") == type_
770 and getattr(module, "pluginTypename", "") == typename 777 and getattr(module, "pluginTypename", "") == typename
778 and getattr(module, "pluginTypename", "") == typename 785 and getattr(module, "pluginTypename", "") == typename
779 ): 786 ):
780 self.deactivatePlugin(name, onDemand=True) 787 self.deactivatePlugin(name, onDemand=True)
781 return self.activatePlugin(name, onDemand=True) 788 return self.activatePlugin(name, onDemand=True)
782 789
783 return None 790 return None, f"no plugin module of type {type_}: {typename}"
784 791
785 def getPluginInfos(self): 792 def getPluginInfos(self):
786 """ 793 """
787 Public method to get infos about all loaded plug-ins. 794 Public method to get infos about all loaded plug-ins.
788 795

eric ide

mercurial