Bug fixes

This commit is contained in:
St.Huang 2018-08-15 01:52:12 +08:00
parent 8ea7a27d33
commit fd3dbf73c1
8 changed files with 57 additions and 40 deletions

View File

@ -77,16 +77,14 @@ class DictManageDialog(Dialog):
# dict service list # dict service list
confs = config.dicts confs = config.dicts
dicts = list() dicts = list()
for clazz in service_manager.web_services: services = service_manager.local_custom_services + service_manager.web_services
service = service_pool.get(clazz.__unique__) for clazz in services:
if service and service.support: dicts.append({
dicts.append({ 'title': clazz.__title__,
'title': service.title, 'unique': clazz.__unique__,
'unique': service.unique, 'path': clazz.__path__,
'path': clazz.__path__, 'enabled': confs.get(clazz.__unique__, dict()).get('enabled', True)
'enabled': confs.get(service.unique, dict()).get('enabled', True) })
})
service_pool.put(service)
# add dict # add dict
for i, d in enumerate(dicts): for i, d in enumerate(dicts):
self.add_dict_layout(i, **d) self.add_dict_layout(i, **d)

View File

@ -80,13 +80,14 @@ class OptionsDialog(Dialog):
'web': [] #网络词典 'web': [] #网络词典
} }
for clazz in service_manager.local_services: for clazz in service_manager.local_services:
service = service_pool.get(clazz.__unique__) if dicts.get(clazz.__unique__, dict()).get('enabled', True):
if service and service.support: service = service_pool.get(clazz.__unique__)
self.dict_services['local'].append({ if service and service.support:
'title': service.title, self.dict_services['local'].append({
'unique': service.unique 'title': service.title,
}) 'unique': service.unique
service_pool.put(service) })
service_pool.put(service)
for clazz in service_manager.web_services: for clazz in service_manager.web_services:
if dicts.get(clazz.__unique__, dict()).get('enabled', True): if dicts.get(clazz.__unique__, dict()).get('enabled', True):
service = service_pool.get(clazz.__unique__) service = service_pool.get(clazz.__unique__)

View File

@ -87,7 +87,10 @@ class ServiceManager(object):
for name, clazz in inspect.getmembers(module, predicate=inspect.isclass): for name, clazz in inspect.getmembers(module, predicate=inspect.isclass):
if clazz in base_class: if clazz in base_class:
continue continue
if not(issubclass(clazz, WebService) or issubclass(clazz, LocalService)):
continue
service = service_wrap(clazz, *args) service = service_wrap(clazz, *args)
service.__title__ = getattr(clazz, '__register_label__', name)
service.__unique__ = name service.__unique__ = name
service.__path__ = os.path.join(mypath, f) service.__path__ = os.path.join(mypath, f)
if issubclass(clazz, WebService): if issubclass(clazz, WebService):

View File

@ -2,13 +2,17 @@
# While not critical (and in no way guaranteed!), it would be nice to keep this # While not critical (and in no way guaranteed!), it would be nice to keep this
# code compatible with Python 2.3. # code compatible with Python 2.3.
import sys import sys
try:
from importlib import reload
except:
pass
def _resolve_name(name, package, level): def _resolve_name(name, package, level):
"""Return the absolute name of the module to be imported.""" """Return the absolute name of the module to be imported."""
if not hasattr(package, 'rindex'): if not hasattr(package, 'rindex'):
raise ValueError("'package' not set to a string") raise ValueError("'package' not set to a string")
dot = len(package) dot = len(package)
for x in xrange(level, 1, -1): for x in range(level, 1, -1):
try: try:
dot = package.rindex('.', 0, dot) dot = package.rindex('.', 0, dot)
except ValueError: except ValueError:
@ -19,11 +23,9 @@ def _resolve_name(name, package, level):
def import_module(name, package=None): def import_module(name, package=None):
"""Import a module. """Import a module.
The 'package' argument is required when performing a relative import. It 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 specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import. relative import to an absolute import.
""" """
if name.startswith('.'): if name.startswith('.'):
if not package: if not package:
@ -35,5 +37,9 @@ def import_module(name, package=None):
level += 1 level += 1
name = _resolve_name(name[level:], package, level) name = _resolve_name(name[level:], package, level)
__import__(name) if name in sys.modules:
return sys.modules[name] reload(sys.modules[name])
else:
__import__(name)
return sys.modules[name]

View File

@ -77,16 +77,14 @@ class DictManageDialog(Dialog):
# dict service list # dict service list
confs = config.dicts confs = config.dicts
dicts = list() dicts = list()
for clazz in service_manager.web_services: services = service_manager.local_custom_services + service_manager.web_services
service = service_pool.get(clazz.__unique__) for clazz in services:
if service and service.support: dicts.append({
dicts.append({ 'title': clazz.__title__,
'title': service.title, 'unique': clazz.__unique__,
'unique': service.unique, 'path': clazz.__path__,
'path': clazz.__path__, 'enabled': confs.get(clazz.__unique__, dict()).get('enabled', True)
'enabled': confs.get(service.unique, dict()).get('enabled', True) })
})
service_pool.put(service)
# add dict # add dict
for i, d in enumerate(dicts): for i, d in enumerate(dicts):
self.add_dict_layout(i, **d) self.add_dict_layout(i, **d)

View File

@ -80,13 +80,14 @@ class OptionsDialog(Dialog):
'web': [] #网络词典 'web': [] #网络词典
} }
for clazz in service_manager.local_services: for clazz in service_manager.local_services:
service = service_pool.get(clazz.__unique__) if dicts.get(clazz.__unique__, dict()).get('enabled', True):
if service and service.support: service = service_pool.get(clazz.__unique__)
self.dict_services['local'].append({ if service and service.support:
'title': service.title, self.dict_services['local'].append({
'unique': service.unique 'title': service.title,
}) 'unique': service.unique
service_pool.put(service) })
service_pool.put(service)
for clazz in service_manager.web_services: for clazz in service_manager.web_services:
if dicts.get(clazz.__unique__, dict()).get('enabled', True): if dicts.get(clazz.__unique__, dict()).get('enabled', True):
service = service_pool.get(clazz.__unique__) service = service_pool.get(clazz.__unique__)

View File

@ -82,7 +82,10 @@ class ServiceManager(object):
for name, clazz in inspect.getmembers(module, predicate=inspect.isclass): for name, clazz in inspect.getmembers(module, predicate=inspect.isclass):
if clazz in base_class: if clazz in base_class:
continue continue
if not(issubclass(clazz, WebService) or issubclass(clazz, LocalService)):
continue
service = service_wrap(clazz, *args) service = service_wrap(clazz, *args)
service.__title__ = getattr(clazz, '__register_label__', name)
service.__unique__ = name service.__unique__ = name
service.__path__ = os.path.join(mypath, f) service.__path__ = os.path.join(mypath, f)
if issubclass(clazz, WebService): if issubclass(clazz, WebService):

View File

@ -2,6 +2,10 @@
# While not critical (and in no way guaranteed!), it would be nice to keep this # While not critical (and in no way guaranteed!), it would be nice to keep this
# code compatible with Python 2.3. # code compatible with Python 2.3.
import sys import sys
try:
from importlib import reload
except:
pass
def _resolve_name(name, package, level): def _resolve_name(name, package, level):
"""Return the absolute name of the module to be imported.""" """Return the absolute name of the module to be imported."""
@ -33,6 +37,9 @@ def import_module(name, package=None):
level += 1 level += 1
name = _resolve_name(name[level:], package, level) 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] return sys.modules[name]