diff --git a/src/controller/configuration.py b/src/controller/configuration.py index fd40626..6c22597 100644 --- a/src/controller/configuration.py +++ b/src/controller/configuration.py @@ -21,7 +21,7 @@ class configuration(object): if str(i["id"]) == current_output_device: self.view.set_value("general", "output_device", i["name"]) break - extractors = get_extractors() + extractors = get_extractors(import_all=True) for i in extractors: if hasattr(i, "settings"): panel = getattr(i, "settings")(self.view.notebook) diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 5682e9b..64c4269 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -92,6 +92,7 @@ class Controller(object): # Event functions. These functions will call other functions in a thread and are bound to widget events. def on_settings(self, *args, **kwargs): settings = configuration.configuration() + self.reload_extractors() def on_search(self, *args, **kwargs): wx.CallAfter(self.search) @@ -257,4 +258,9 @@ class Controller(object): self.change_status(_(u"No results found. ")) else: self.change_status(u"") - wx.CallAfter(self.window.list.SetFocus) \ No newline at end of file + wx.CallAfter(self.window.list.SetFocus) + + def reload_extractors(self): + extractors = [i.interface.name for i in get_extractors()] + self.window.extractor.SetItems(extractors) + self.window.extractor.SetValue(extractors[0]) \ No newline at end of file diff --git a/src/extractors/zaycev.py b/src/extractors/zaycev.py index c3d5729..f8e424c 100644 --- a/src/extractors/zaycev.py +++ b/src/extractors/zaycev.py @@ -14,7 +14,6 @@ log = logging.getLogger("extractors.zaycev.net") class interface(base.baseInterface): name = "zaycev.net" enabled = config.app["services"]["zaycev"].get("enabled") - print(enabled) def search(self, text, page=1): if text == "" or text == None: diff --git a/src/utils.py b/src/utils.py index be00c38..2094a6b 100644 --- a/src/utils.py +++ b/src/utils.py @@ -4,6 +4,8 @@ import requests import threading import logging import types +import extractors +from importlib import reload from pubsub import pub log = logging.getLogger("utils") @@ -70,9 +72,15 @@ def download_file(url, local_filename): log.debug("Download finished successfully") return local_filename -def get_extractors(): +def get_extractors(import_all=False): """ Function for importing everything wich is located in the extractors package and has a class named interface.""" - import extractors module_type = types.ModuleType - classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface') and m.interface.enabled != False] + # first of all, import all classes for the package so we can reload everything if they have changes in config. + _classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface')] + for cls in _classes: + reload(cls) + if not import_all: + classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface') and m.interface.enabled != False] + else: + classes = [m for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface')] return classes#sorted(classes, key=lambda c: c.name) \ No newline at end of file