Beispiel #1
0
    def __init__(self,
                 name,
                 ordering,
                 parentClass=None,
                 instanceClass=Who,
                 proxyClasses=[],
                 secret=0):
        self._name = name  # names must be unique!
        self.ordering = ordering
        self.parentClass = parentClass
        self.instanceClass = instanceClass
        # list of names of proxies that should be created for this class:
        self.proxyClasses = proxyClasses
        self.members = labeltree.LabelTree()
        self.nmembers = 0
        self.nproxies = 0
        ## TODO 3.1: For situations in which this whoclass object
        ## needs to be secret for some kinds of display and not for
        ## others the boolean type would not be enough. We will have
        ## to think of another structure to handle different kinds of
        ## secrecy for those displays.
        self.secret = secret  # does not appear in GUI if secret==1
        # Insert the new WhoClass in the list of all WhoClasses,
        # updating each class's index.
        global whoClasses
        nwho = len(whoClasses)
        for i in range(nwho):
            if whoClasses[i].ordering > ordering:
                whoClasses.insert(i, self)
                for j in range(i, nwho + 1):
                    whoClasses[j]._index = j
                break
        else:
            whoClasses.append(self)
            self._index = nwho

        # Create proxy objects if requested.  The proxy class may not
        # have been loaded yet.  That's ok: when the class is created
        # it will create the proxy for this WhoClass.
        for whoproxyclassname in proxyClasses:
            try:
                whoproxyclass = WhoProxyClass.allProxyClasses[
                    whoproxyclassname]
            except KeyError:
                pass
            else:
                self.addProxy(whoproxyclass.makeProxy(self))

        switchboard.notify('new who class', name)

        # Be notified when a who object changes its name, in case that
        # object's WhoClass is a parent class of this class.  If it
        # is, objects in this class need to update their paths.
        switchboard.requestCallback('rename who', self.renameWho)
Beispiel #2
0
            if type(help) is types.StringType:
                return help
            return help.read(obj)


##################

# Keep track of other objects that need to be documented -- this
# includes anything except for RegisteredClasses, Enums, Outputs, and
# MenuItems. Every file that defines such objects must create an
# XMLObjectDoc object for each object type.  The 'discussion' argument
# should be a complete docbook refentry element or a DiscussionFile
# object containing a refentry.  The refentry id should be
# 'Object:name' where 'name' is the name of the object.

objDocs = labeltree.LabelTree()


class XMLObjectDoc:
    def __init__(self, name, discussion, ordering=0):
        self.name = name
        self.discussion = discussion
        objDocs.__setitem__(name, self, ordering)


# Other parts of the code that want to add a complete Section to the
# reference manual can register a callback here.  The callback will be
# called with a file argument.

otherSections = []
Beispiel #3
0
    def __init__(self):
        self.materialmanager = None  # Set by materialmanager when it starts up.
        self.data = labeltree.LabelTree()

        # Need to own the references to the key objects, which are
        # only weakly referenced in LabelTree, and used to identify
        # menus.  This allows the menus to disappear automatically
        # when the PropertyManager is destroyed.  (Why bother?  The
        # PropertyManager isn't destroyed until the program quits.)
        self.parametrizekey = parametrizeKey
        self.loadkey = loadKey

        def paramcopy(object):
            # This routine is a callback function passed to
            # LabelTree.makeOOFMenu. makeOOFMenu uses it to get the
            # list of parameters for each menuitem that it creates.
            # The 'object' argument is the PropertyRegistration for
            # which the menu item is being built.

            # It's tempting to simply return the
            # PropertyRegistration's list of Parameters, so that the
            # registration and the menu item share Parameter objects,
            # and eliminating the need to copy values back and forth.
            # This temptation must be resisted.  If the Parameters are
            # shared, then loading a named Property from a data file
            # will change the settings of an already parametrized
            # unnamed Property.
            if object:
                return [p.clone() for p in object.getDefaultParams()]
            return []

        def kwarg_func(object):  # Extra kwargs for OOFMenuItem ctor.
            if object and object.secret():
                return {'secret': 1, 'no_doc': 1}
            return {}

        # Menu items are put into OOF.Property for scripts and
        # OOF.LoadData.Property for data files.  The menus are created
        # automatically by the LabelTree, which uses the given key to
        # distinguish them.
        OOF.Property.addItem(
            self.data.makeOOFMenu(
                # The name 'Parametrize' is also used in _parametrizeDiscussion.
                # Don't change it here without changing it there.
                name='Parametrize',
                key=self.parametrizekey,
                param_func=paramcopy,
                kwarg_func=kwarg_func,
                callback=self.parametrizercallback,
                help=xmlmenudump.DiscussionFunc(_parametrizeHelp),
                discussion=xmlmenudump.DiscussionFunc(_parametrizeDiscussion)))

        OOF.LoadData.addItem(
            self.data.makeOOFMenu(
                name='Property',
                key=self.loadkey,
                param_func=paramcopy,
                kwarg_func=kwarg_func,
                callback=self.creatorcallback,
                params=[
                    parameter.StringParameter('name', tip="Name of Property.")
                ],
                discussion=xmlmenudump.DiscussionFunc(_loadDiscussion),
                help=xmlmenudump.DiscussionFunc(_loadHelp)))