diff --git a/addons/fastwq/gui/dictmanager.py b/addons/fastwq/gui/dictmanager.py index d1412ef..768f120 100644 --- a/addons/fastwq/gui/dictmanager.py +++ b/addons/fastwq/gui/dictmanager.py @@ -77,16 +77,14 @@ class DictManageDialog(Dialog): # dict service list confs = config.dicts dicts = list() - for clazz in service_manager.web_services: - service = service_pool.get(clazz.__unique__) - if service and service.support: - dicts.append({ - 'title': service.title, - 'unique': service.unique, - 'path': clazz.__path__, - 'enabled': confs.get(service.unique, dict()).get('enabled', True) - }) - service_pool.put(service) + services = service_manager.local_custom_services + service_manager.web_services + for clazz in services: + dicts.append({ + 'title': clazz.__title__, + 'unique': clazz.__unique__, + 'path': clazz.__path__, + 'enabled': confs.get(clazz.__unique__, dict()).get('enabled', True) + }) # add dict for i, d in enumerate(dicts): self.add_dict_layout(i, **d) diff --git a/addons/fastwq/gui/options.py b/addons/fastwq/gui/options.py index 586edef..93da946 100644 --- a/addons/fastwq/gui/options.py +++ b/addons/fastwq/gui/options.py @@ -80,13 +80,14 @@ class OptionsDialog(Dialog): 'web': [] #网络词典 } for clazz in service_manager.local_services: - service = service_pool.get(clazz.__unique__) - if service and service.support: - self.dict_services['local'].append({ - 'title': service.title, - 'unique': service.unique - }) - service_pool.put(service) + if dicts.get(clazz.__unique__, dict()).get('enabled', True): + service = service_pool.get(clazz.__unique__) + if service and service.support: + self.dict_services['local'].append({ + 'title': service.title, + 'unique': service.unique + }) + service_pool.put(service) for clazz in service_manager.web_services: if dicts.get(clazz.__unique__, dict()).get('enabled', True): service = service_pool.get(clazz.__unique__) diff --git a/addons/fastwq/service/manager.py b/addons/fastwq/service/manager.py index 04a8936..35f8ca0 100644 --- a/addons/fastwq/service/manager.py +++ b/addons/fastwq/service/manager.py @@ -87,7 +87,10 @@ class ServiceManager(object): for name, clazz in inspect.getmembers(module, predicate=inspect.isclass): if clazz in base_class: continue + if not(issubclass(clazz, WebService) or issubclass(clazz, LocalService)): + continue service = service_wrap(clazz, *args) + service.__title__ = getattr(clazz, '__register_label__', name) service.__unique__ = name service.__path__ = os.path.join(mypath, f) if issubclass(clazz, WebService): diff --git a/addons/fastwq/utils/importlib.py b/addons/fastwq/utils/importlib.py index ab19fe9..4df2ed0 100644 --- a/addons/fastwq/utils/importlib.py +++ b/addons/fastwq/utils/importlib.py @@ -2,13 +2,17 @@ # While not critical (and in no way guaranteed!), it would be nice to keep this # code compatible with Python 2.3. import sys +try: + from importlib import reload +except: + pass def _resolve_name(name, package, level): """Return the absolute name of the module to be imported.""" if not hasattr(package, 'rindex'): raise ValueError("'package' not set to a string") dot = len(package) - for x in xrange(level, 1, -1): + for x in range(level, 1, -1): try: dot = package.rindex('.', 0, dot) except ValueError: @@ -19,11 +23,9 @@ def _resolve_name(name, package, level): def import_module(name, package=None): """Import a module. - The 'package' argument is required when performing a relative import. It specifies the package to use as the anchor point from which to resolve the relative import to an absolute import. - """ if name.startswith('.'): if not package: @@ -35,5 +37,9 @@ def import_module(name, package=None): level += 1 name = _resolve_name(name[level:], package, level) - __import__(name) - return sys.modules[name] \ No newline at end of file + if name in sys.modules: + reload(sys.modules[name]) + else: + __import__(name) + return sys.modules[name] + \ No newline at end of file diff --git a/addons21/fastwq/gui/dictmanager.py b/addons21/fastwq/gui/dictmanager.py index d1412ef..768f120 100644 --- a/addons21/fastwq/gui/dictmanager.py +++ b/addons21/fastwq/gui/dictmanager.py @@ -77,16 +77,14 @@ class DictManageDialog(Dialog): # dict service list confs = config.dicts dicts = list() - for clazz in service_manager.web_services: - service = service_pool.get(clazz.__unique__) - if service and service.support: - dicts.append({ - 'title': service.title, - 'unique': service.unique, - 'path': clazz.__path__, - 'enabled': confs.get(service.unique, dict()).get('enabled', True) - }) - service_pool.put(service) + services = service_manager.local_custom_services + service_manager.web_services + for clazz in services: + dicts.append({ + 'title': clazz.__title__, + 'unique': clazz.__unique__, + 'path': clazz.__path__, + 'enabled': confs.get(clazz.__unique__, dict()).get('enabled', True) + }) # add dict for i, d in enumerate(dicts): self.add_dict_layout(i, **d) diff --git a/addons21/fastwq/gui/options.py b/addons21/fastwq/gui/options.py index 586edef..93da946 100644 --- a/addons21/fastwq/gui/options.py +++ b/addons21/fastwq/gui/options.py @@ -80,13 +80,14 @@ class OptionsDialog(Dialog): 'web': [] #网络词典 } for clazz in service_manager.local_services: - service = service_pool.get(clazz.__unique__) - if service and service.support: - self.dict_services['local'].append({ - 'title': service.title, - 'unique': service.unique - }) - service_pool.put(service) + if dicts.get(clazz.__unique__, dict()).get('enabled', True): + service = service_pool.get(clazz.__unique__) + if service and service.support: + self.dict_services['local'].append({ + 'title': service.title, + 'unique': service.unique + }) + service_pool.put(service) for clazz in service_manager.web_services: if dicts.get(clazz.__unique__, dict()).get('enabled', True): service = service_pool.get(clazz.__unique__) diff --git a/addons21/fastwq/service/manager.py b/addons21/fastwq/service/manager.py index 64e212e..34d5ba4 100644 --- a/addons21/fastwq/service/manager.py +++ b/addons21/fastwq/service/manager.py @@ -82,7 +82,10 @@ class ServiceManager(object): for name, clazz in inspect.getmembers(module, predicate=inspect.isclass): if clazz in base_class: continue + if not(issubclass(clazz, WebService) or issubclass(clazz, LocalService)): + continue service = service_wrap(clazz, *args) + service.__title__ = getattr(clazz, '__register_label__', name) service.__unique__ = name service.__path__ = os.path.join(mypath, f) if issubclass(clazz, WebService): diff --git a/addons21/fastwq/utils/importlib.py b/addons21/fastwq/utils/importlib.py index ed95846..4df2ed0 100644 --- a/addons21/fastwq/utils/importlib.py +++ b/addons21/fastwq/utils/importlib.py @@ -2,6 +2,10 @@ # While not critical (and in no way guaranteed!), it would be nice to keep this # code compatible with Python 2.3. import sys +try: + from importlib import reload +except: + pass def _resolve_name(name, package, level): """Return the absolute name of the module to be imported.""" @@ -33,6 +37,9 @@ def import_module(name, package=None): level += 1 name = _resolve_name(name[level:], package, level) - __import__(name) + if name in sys.modules: + reload(sys.modules[name]) + else: + __import__(name) return sys.modules[name] \ No newline at end of file