Allow hooke.ui to load with missing hooke.license submodule.
[hooke.git] / hooke / ui / __init__.py
index 42085c25a0b05b5216cb8263004ae4158a4e1b54..6a76b82e5356c8b3a764b8d4542d1833766f4d27 100644 (file)
@@ -2,15 +2,15 @@
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation, either
-# version 3 of the License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
 #
-# Hooke is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
+# Public License for more details.
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with Hooke.  If not, see
 import ConfigParser as configparser
 
 from .. import version
-from ..compat.odict import odict
 from ..config import Setting
-from ..util.pluggable import IsSubclass
+from ..util.pluggable import IsSubclass, construct_odict
+
+try:
+    from ..license import short_license
+except ImportError, e:
+    import logging
+    logging.warn('Could not load short_license from hooke.license')
+    from .. import __license__
+    def short_license(extra_info, **kwargs):
+        return __license__
 
 
 USER_INTERFACE_MODULES = [
@@ -52,8 +60,10 @@ class CommandMessage (QueueMessage):
     a :class:`dict` with `argname` keys and `value` values to be
     passed to the command.
     """
-    def __init__(self, command, arguments):
+    def __init__(self, command, arguments=None):
         self.command = command
+        if arguments == None:
+            arguments = {}
         self.arguments = arguments
 
 class UserInterface (object):
@@ -91,42 +101,21 @@ class UserInterface (object):
 
     # Assorted useful tidbits for subclasses
 
-    def _splash_text(self):
+    def _splash_text(self, extra_info, **kwargs):
         return ("""
 Hooke version %s
 
-COPYRIGHT
+%s
 ----
-""" % version()).strip()
+""" % (version(), short_license(extra_info, **kwargs))).strip()
 
     def _playlist_status(self, playlist):
         if len(playlist) > 0:
-            return '%s (%s/%s)' % (playlist.name, playlist._index + 1,
+            return '%s (%s/%s)' % (playlist.name, playlist.index() + 1,
                                    len(playlist))
         return 'The playlist %s does not contain any valid force curve data.' \
             % self.name
 
-def construct_odict(this_modname, submodnames, class_selector):
-    """Search the submodules `submodnames` of a module `this_modname`
-    for class objects for which `class_selector(class)` returns
-    `True`.  These classes are instantiated and stored in the returned
-    :class:`hooke.compat.odict.odict` in the order in which they were
-    discovered.
-    """
-    instances = odict()
-    for submodname in submodnames:
-        count = len([s for s in submodnames if s == submodname])
-        assert count > 0, 'No %s entries: %s' % (submodname, submodnames)
-        assert count == 1, 'Multiple (%d) %s entries: %s' \
-            % (count, submodname, submodnames)
-        this_mod = __import__(this_modname, fromlist=[submodname])
-        submod = getattr(this_mod, submodname)
-        for objname in dir(submod):
-            obj = getattr(submod, objname)
-            if class_selector(obj):
-                instance = obj()
-                instances[instance.name] = instance
-    return instances
 
 USER_INTERFACES = construct_odict(
     this_modname=__name__,