Reload all extractors' config after saving changes in the settings dialog
This commit is contained in:
parent
bb411e7bbc
commit
d33205e84e
@ -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)
|
||||
|
@ -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)
|
||||
@ -258,3 +259,8 @@ class Controller(object):
|
||||
else:
|
||||
self.change_status(u"")
|
||||
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])
|
@ -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:
|
||||
|
12
src/utils.py
12
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
|
||||
# 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)
|
Loading…
x
Reference in New Issue
Block a user