Commit c140f806 authored by eric pellegrini's avatar eric pellegrini
Browse files

The registry viewer now display the information about a given registry

object in pure HTML form
Added a method to get the fully fotted name of a given module
Added docstring to MDANSE.Core.ClassRegistry
parent 69289a79
......@@ -53,22 +53,28 @@ class _Meta(type):
class ClassRegistry(abc.ABCMeta):
'''
Metaclass that registers the subclasses of all the base classes used in MDANSE framework.
Metaclass that registers the classes that make the MDANSE framework.
The subclasses are stored internally in a nested dictionary whose primary key
is the 'type' class attribute of the base class they are inheriting from and secondary key is
their own 'type' class attribute.
The MDANSE framework is based on a set of interfaces that covers different aspects of the framework such
as the analysis, the input data, the output file formats ... By metaclassing each base class of these interfaces
with :class:`ClassRegistry` object, their corresponding concrete class instances will be automatically registered at import time in
a data structure that can be further used all over the framework.
The data structure used to store the concrete classes is a nested dictionary whose primary key
is the :py:attr:`type` class attribute of the base class they are inheriting from and secondary key is
their own :py:attr:`type` class attribute. Any concrete class of those interfaces that does not define the
:py:attr:`type` class attribute will not be registered.
'''
__metaclass__ = _Meta
__interfaces = []
__interfaces = set()
_registry = {}
def __init__(self, name, bases, namespace):
'''
Constructor of a class metaclassed by ClassFactory
Constructor
:param name: the name of the class to be built by this metaclass
:type name: str
......@@ -80,16 +86,16 @@ class ClassRegistry(abc.ABCMeta):
super(ClassRegistry, self).__init__(name, bases, namespace)
# Get the typ of the class
# Any class
typ = getattr(self, 'type', None)
if typ is None:
return
metaClass = namespace.get("__metaclass__", None)
# A class metaclassed by ClassRegistry will define a new section of the registry.
metaClass = namespace.get("__metaclass__", None)
if metaClass is ClassRegistry:
ClassRegistry.__interfaces.append(self)
ClassRegistry.__interfaces.add(self)
if (ClassRegistry._registry.has_key(typ)):
return
ClassRegistry._registry[typ] = {}
......
......@@ -34,10 +34,12 @@ import abc
import ctypes
import datetime
import getpass
import inspect
import os
import re
import subprocess
import tempfile
import types
from MDANSE.Core.Error import Error
......@@ -137,6 +139,32 @@ class Platform(object):
return path
def full_dotted_module(self,obj):
'''
Returns the fully dotted name of a module given the module object itself or a class stored in this module.
:param obj: the module object or a class stored in stored in this module.
:type obj: module or class
:return: the fully dotted name of the module.
:rtype: str
'''
if inspect.ismodule(obj):
path = obj.__file__
elif inspect.isclass(obj):
path = inspect.getmodule(obj).__file__
else:
raise PlatformError('Invalid query object type.')
basepath = os.path.join(os.path.dirname(self.package_directory()),'')
_,relativePath = path.split(basepath)
relativePath = os.path.splitext(relativePath)[0]
return '.'.join(relativePath.split(os.path.sep))
def change_directory(self, directory):
'''
Change the current directory to a new directory.
......
......@@ -30,10 +30,13 @@ Created on Apr 14, 2015
:author: Gael Goret, Eric C. Pellegrini
'''
import os
import wx
import wx.aui as wxaui
import wx.html as wxhtml
from MDANSE import REGISTRY
from MDANSE import PLATFORM, REGISTRY
from MDANSE.Core.Error import Error
from MDANSE.Framework.Plugins.ComponentPlugin import ComponentPlugin
......@@ -70,10 +73,10 @@ class RegistryViewerPlugin(ComponentPlugin):
self._treePanel.SetSizer(treeSizer)
self._infoPanel = wx.Panel(self, wx.ID_ANY, size=self.GetSize())
infoSizer = wx.BoxSizer(wx.HORIZONTAL)
self._info = wx.TextCtrl(self._infoPanel, wx.ID_ANY, style=wx.TE_MULTILINE|wx.TE_READONLY)
self._info = wxhtml.HtmlWindow(self._infoPanel, wx.ID_ANY, size=self.GetSize())
infoSizer.Add(self._info, 1, wx.ALL|wx.EXPAND, 5)
......@@ -92,7 +95,7 @@ class RegistryViewerPlugin(ComponentPlugin):
def set_plugins_tree(self, node, data):
for k, v in data.items():
for k, v in sorted(data.items()):
if isinstance(v, dict):
subnode = self._tree.AppendItem(node, str(k), data=None)
......@@ -111,12 +114,12 @@ class RegistryViewerPlugin(ComponentPlugin):
if ItemData.GetData() is None:
return
moduleFullName = PLATFORM.full_dotted_module(ItemData.GetData())
containerStr = ''
containerStr += str(ItemData.GetData()) + '\n'
containerStr += str(ItemData.GetData().__doc__)
self._info.SetValue(containerStr)
moduleDocPath = os.path.join(PLATFORM.help_path(), moduleFullName+'.html')
self._info.LoadPage(moduleDocPath)
def close(self):
pass
......
......@@ -12,11 +12,11 @@ class JobHelpFrame(wx.Frame):
wx.Frame.__init__(self, parent, wx.ID_ANY, title="About %s" % job.label, size =(800,600))
self.nolog = wx.LogNull()
fully_qualified_name = 'MDANSE.Framework.Jobs' + '.' + job.__class__.__name__
self._doc = PLATFORM.get_path(os.path.join(PLATFORM.help_path(), fully_qualified_name + '.html'))
moduleFullName = PLATFORM.full_dotted_module(job.__class__)
self._doc = os.path.join(PLATFORM.help_path(), moduleFullName+'.html')
self.build()
def build(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment