62 before a plugin is activated |
62 before a plugin is activated |
63 @signal pluginActivated(moduleName, pluginObject) emitted just after |
63 @signal pluginActivated(moduleName, pluginObject) emitted just after |
64 a plugin was activated |
64 a plugin was activated |
65 @signal allPlugginsActivated() emitted at startup after all plugins have |
65 @signal allPlugginsActivated() emitted at startup after all plugins have |
66 been activated |
66 been activated |
|
67 @signal allTypedPlugginsActivated(pluginType) emitted at startup after all |
|
68 plugins of the type have been activated |
67 @signal pluginAboutToBeDeactivated(moduleName, pluginObject) emitted just |
69 @signal pluginAboutToBeDeactivated(moduleName, pluginObject) emitted just |
68 before a plugin is deactivated |
70 before a plugin is deactivated |
69 @signal pluginDeactivated(moduleName, pluginObject) emitted just after |
71 @signal pluginDeactivated(moduleName, pluginObject) emitted just after |
70 a plugin was deactivated |
72 a plugin was deactivated |
71 @signal pluginRepositoryFileDownloaded() emitted to indicate a completed |
73 @signal pluginRepositoryFileDownloaded() emitted to indicate a completed |
74 |
76 |
75 shutdown = pyqtSignal() |
77 shutdown = pyqtSignal() |
76 pluginAboutToBeActivated = pyqtSignal(str, object) |
78 pluginAboutToBeActivated = pyqtSignal(str, object) |
77 pluginActivated = pyqtSignal(str, object) |
79 pluginActivated = pyqtSignal(str, object) |
78 allPlugginsActivated = pyqtSignal() |
80 allPlugginsActivated = pyqtSignal() |
|
81 allTypedPlugginsActivated = pyqtSignal(str) |
79 pluginAboutToBeDeactivated = pyqtSignal(str, object) |
82 pluginAboutToBeDeactivated = pyqtSignal(str, object) |
80 pluginDeactivated = pyqtSignal(str, object) |
83 pluginDeactivated = pyqtSignal(str, object) |
81 pluginRepositoryFileDownloaded = pyqtSignal() |
84 pluginRepositoryFileDownloaded = pyqtSignal() |
82 |
85 |
83 def __init__( |
86 def __init__( |
615 inactiveList.remove(self.__develPluginName) |
618 inactiveList.remove(self.__develPluginName) |
616 names = sorted(self.__inactiveModules) |
619 names = sorted(self.__inactiveModules) |
617 for name in names: |
620 for name in names: |
618 if name not in inactiveList: |
621 if name not in inactiveList: |
619 self.activatePlugin(name) |
622 self.activatePlugin(name) |
|
623 |
620 self.allPlugginsActivated.emit() |
624 self.allPlugginsActivated.emit() |
|
625 |
|
626 def activateTypedPlugins(self, pluginType): |
|
627 """ |
|
628 Public method to activate all plugins having the "autoactivate" attribute |
|
629 set to True and being of the given plugin type. |
|
630 |
|
631 @param pluginType plugin type |
|
632 @type str |
|
633 """ |
|
634 for name, module in self.__inactiveModules.items(): |
|
635 if getPluginHeaderEntry(module, "pluginType", "") == pluginType: |
|
636 self.activatePlugin(name) |
|
637 |
|
638 self.allTypedPlugginsActivated.emit(pluginType) |
621 |
639 |
622 def activatePlugin(self, name, onDemand=False): |
640 def activatePlugin(self, name, onDemand=False): |
623 """ |
641 """ |
624 Public method to activate a plugin. |
642 Public method to activate a plugin. |
625 |
643 |
793 for being deactivated |
811 for being deactivated |
794 @rtype bool |
812 @rtype bool |
795 """ |
813 """ |
796 return getPluginHeaderEntry(module, "deactivateable", True) |
814 return getPluginHeaderEntry(module, "deactivateable", True) |
797 |
815 |
798 def getPluginObject(self, type_, typename, maybeActive=False): |
816 def getPluginObject(self, pluginType, pluginTypename, maybeActive=False): |
799 """ |
817 """ |
800 Public method to activate an on-demand plugin given by type and |
818 Public method to activate an on-demand plugin given by type and |
801 type name. |
819 type name. |
802 |
820 |
803 @param type_ type of the plugin to be activated |
821 @param pluginType type of the plugin to be activated |
804 @type str |
822 @type str |
805 @param typename name of the plugin within the type category |
823 @param pluginTypename name of the plugin within the type category |
806 @type str |
824 @type str |
807 @param maybeActive flag indicating, that the plugin may be active |
825 @param maybeActive flag indicating, that the plugin may be active |
808 already |
826 already |
809 @type bool |
827 @type bool |
810 @return reference to the initialized plugin object and an error string |
828 @return reference to the initialized plugin object and an error string |
811 @rtype tuple of (QObject, str) |
829 @rtype tuple of (QObject, str) |
812 """ |
830 """ |
813 for name, module in self.__onDemandInactiveModules.items(): |
831 for name, module in self.__onDemandInactiveModules.items(): |
814 if ( |
832 if ( |
815 getPluginHeaderEntry(module, "pluginType", "") == type_ |
833 getPluginHeaderEntry(module, "pluginType", "") == pluginType |
816 and getPluginHeaderEntry(module, "pluginTypename", "") == typename |
834 and getPluginHeaderEntry(module, "pluginTypename", "") == pluginTypename |
817 ): |
835 ): |
818 return self.activatePlugin(name, onDemand=True) |
836 return self.activatePlugin(name, onDemand=True) |
819 |
837 |
820 if maybeActive: |
838 if maybeActive: |
821 for name, module in self.__onDemandActiveModules.items(): |
839 for name, module in self.__onDemandActiveModules.items(): |
822 if ( |
840 if ( |
823 getPluginHeaderEntry(module, "pluginType", "") == type_ |
841 getPluginHeaderEntry(module, "pluginType", "") == pluginType |
824 and getPluginHeaderEntry(module, "pluginTypename", "") == typename |
842 and getPluginHeaderEntry(module, "pluginTypename", "") |
|
843 == pluginTypename |
825 ): |
844 ): |
826 self.deactivatePlugin(name, onDemand=True) |
845 self.deactivatePlugin(name, onDemand=True) |
827 return self.activatePlugin(name, onDemand=True) |
846 return self.activatePlugin(name, onDemand=True) |
828 |
847 |
829 return None, f"no plugin module of type {type_}: {typename}" |
848 return None, f"no plugin module of type {pluginType}: {pluginTypename}" |
830 |
849 |
831 def getPluginInfos(self): |
850 def getPluginInfos(self): |
832 """ |
851 """ |
833 Public method to get infos about all loaded plug-ins. |
852 Public method to get infos about all loaded plug-ins. |
834 |
853 |
979 names.append(name) |
998 names.append(name) |
980 Preferences.getSettings().setValue(self.__inactivePluginsKey, names) |
999 Preferences.getSettings().setValue(self.__inactivePluginsKey, names) |
981 |
1000 |
982 self.shutdown.emit() |
1001 self.shutdown.emit() |
983 |
1002 |
984 def getPluginDisplayStrings(self, type_): |
1003 def getPluginDisplayStrings(self, pluginType): |
985 """ |
1004 """ |
986 Public method to get the display strings of all plugins of a specific |
1005 Public method to get the display strings of all plugins of a specific |
987 type. |
1006 type. |
988 |
1007 |
989 @param type_ type of the plugins |
1008 @param pluginType type of the plugins |
990 @type str |
1009 @type str |
991 @return dictionary with name as key and display string as value |
1010 @return dictionary with name as key and display string as value |
992 @rtype dict |
1011 @rtype dict |
993 """ |
1012 """ |
994 pluginDict = {} |
1013 pluginDict = {} |
996 for module in itertools.chain( |
1015 for module in itertools.chain( |
997 self.__onDemandActiveModules.values(), |
1016 self.__onDemandActiveModules.values(), |
998 self.__onDemandInactiveModules.values(), |
1017 self.__onDemandInactiveModules.values(), |
999 ): |
1018 ): |
1000 if ( |
1019 if ( |
1001 getPluginHeaderEntry(module, "pluginType", "") == type_ |
1020 getPluginHeaderEntry(module, "pluginType", "") == pluginType |
1002 and getPluginHeaderEntry(module, "error", "") == "" |
1021 and getPluginHeaderEntry(module, "error", "") == "" |
1003 ): |
1022 ): |
1004 plugin_name = getPluginHeaderEntry(module, "pluginTypename", "") |
1023 plugin_name = getPluginHeaderEntry(module, "pluginTypename", "") |
1005 if plugin_name: |
1024 if plugin_name: |
1006 pluginDict[plugin_name] = getPluginHeaderEntry( |
1025 pluginDict[plugin_name] = getPluginHeaderEntry( |
1007 module, "displayString", plugin_name |
1026 module, "displayString", plugin_name |
1008 ) |
1027 ) |
1009 |
1028 |
1010 return pluginDict |
1029 return pluginDict |
1011 |
1030 |
1012 def getPluginPreviewPixmap(self, type_, name): |
1031 def getPluginPreviewPixmap(self, pluginType, name): |
1013 """ |
1032 """ |
1014 Public method to get a preview pixmap of a plugin of a specific type. |
1033 Public method to get a preview pixmap of a plugin of a specific type. |
1015 |
1034 |
1016 @param type_ type of the plugin |
1035 @param pluginType type of the plugin |
1017 @type str |
1036 @type str |
1018 @param name name of the plugin type |
1037 @param name name of the plugin type |
1019 @type str |
1038 @type str |
1020 @return preview pixmap |
1039 @return preview pixmap |
1021 @rtype QPixmap |
1040 @rtype QPixmap |
1023 for module in itertools.chain( |
1042 for module in itertools.chain( |
1024 self.__onDemandActiveModules.values(), |
1043 self.__onDemandActiveModules.values(), |
1025 self.__onDemandInactiveModules.values(), |
1044 self.__onDemandInactiveModules.values(), |
1026 ): |
1045 ): |
1027 if ( |
1046 if ( |
1028 getPluginHeaderEntry(module, "pluginType", "") == type_ |
1047 getPluginHeaderEntry(module, "pluginType", "") == pluginType |
1029 and getPluginHeaderEntry(module, "pluginTypename", "") == name |
1048 and getPluginHeaderEntry(module, "pluginTypename", "") == name |
1030 ): |
1049 ): |
1031 if hasattr(module, "previewPix"): |
1050 if hasattr(module, "previewPix"): |
1032 return module.previewPix() |
1051 return module.previewPix() |
1033 else: |
1052 else: |
1492 |
1511 |
1493 ######################################################################## |
1512 ######################################################################## |
1494 ## Methods to clear private data of plug-ins below |
1513 ## Methods to clear private data of plug-ins below |
1495 ######################################################################## |
1514 ######################################################################## |
1496 |
1515 |
1497 def clearPluginsPrivateData(self, type_): |
1516 def clearPluginsPrivateData(self, pluginType): |
1498 """ |
1517 """ |
1499 Public method to clear the private data of plug-ins of a specified |
1518 Public method to clear the private data of plug-ins of a specified |
1500 type. |
1519 type. |
1501 |
1520 |
1502 Plugins supporting this functionality must support the module function |
1521 Plugins supporting this functionality must support the module function |
1503 'clearPrivateData()' (and may have the module level attribute 'pluginType'). |
1522 'clearPrivateData()' (and may have the module level attribute 'pluginType'). |
1504 |
1523 |
1505 @param type_ type of the plugin to clear private data for |
1524 @param pluginType type of the plugin to clear private data for |
1506 @type str |
1525 @type str |
1507 """ |
1526 """ |
1508 for module in itertools.chain( |
1527 for module in itertools.chain( |
1509 self.__onDemandActiveModules.values(), |
1528 self.__onDemandActiveModules.values(), |
1510 self.__onDemandInactiveModules.values(), |
1529 self.__onDemandInactiveModules.values(), |
1511 self.__activeModules.values(), |
1530 self.__activeModules.values(), |
1512 self.__inactiveModules.values(), |
1531 self.__inactiveModules.values(), |
1513 ): |
1532 ): |
1514 if getPluginHeaderEntry(module, "pluginType", "") == type_ and hasattr( |
1533 if getPluginHeaderEntry(module, "pluginType", "") == pluginType and hasattr( |
1515 module, "clearPrivateData" |
1534 module, "clearPrivateData" |
1516 ): |
1535 ): |
1517 module.clearPrivateData() |
1536 module.clearPrivateData() |
1518 |
1537 |
1519 ######################################################################## |
1538 ######################################################################## |