Esempio n. 1
0
    def content(self, director):
        "Contains of two separate splitters: header and results"
        doc = lc.document(title="Analysis of Simulation Results")
        splitter = doc.splitter(orientation="vertical")
        sInd = splitter.section()  # path indicator
        sAct = splitter.section(id="qe-section-actions")  # actions

        docResults = lc.document(id=ID_RESULTS)
        doc.add(docResults)

        self._pwresult = PWResult(director, self.id,
                                  linkorder=0)  # From first "PW" task

        self._viewIndicator(director, sInd)
        self._showActions(director, sAct)  # Show actions

        # Simulation Data
        resSplitter = docResults.splitter(orientation="vertical")
        self._simData(director, resSplitter)  # Simulation Specific data

        # System Summary and Electron Structure
        sSum = resSplitter.section()  # system summary
        sEle = resSplitter.section()  # electron structure
        self._summary(director, sSum)  # System Summary
        self._electronStructure(director, sEle)  # Electron Structure

        return doc
Esempio n. 2
0
    def output(self):
        "Returns formatted link to output file on local server"
        doc     = lc.document(id = self._outputId())
        content = lc.document()
        doc.add(content)

        outputfile  = self._outputFile()   # Output file    # self._director, self._job

        if not outputfile:    # No output file
            content.add(NONE)
            return doc

        content.add(self._fileLink(outputfile, content))
        return doc
Esempio n. 3
0
    def output(self):
        "Returns formatted link to output file on local server"
        doc = lc.document(id=self._outputId())
        content = lc.document()
        doc.add(content)

        outputfile = self._outputFile(
        )  # Output file    # self._director, self._job

        if not outputfile:  # No output file
            content.add(NONE)
            return doc

        content.add(self._fileLink(outputfile, content))
        return doc
def configuration_wizard(experiment):
    doc = lc.document(
        title='Configuration wizard for ARCS_beam',
        id='instrument-configuration-wizard',
        )

    # button to skip this wizard
    from . import load_manual_instrument_configuration
    load_manual_configuration = load_manual_instrument_configuration(experiment.id)
    skip_button = lc.button(
        label='skip this wizard',
        onclick=select(element=doc).replaceBy(load_manual_configuration),
        )
    doc.add(skip_button)

    # wizard
    form = doc.form(id='arcs-beam-wizard')
    form.text(name='fermi_nu', label = 'Fermi chopper frequency (Hz)', value=600)
    # form.text(name='fermi_bladeradius', label = 'Fermi choipper blade radius (meter)', value=0.060364)
    form.text(name='T0_nu', label = 'T0 chopper frequency (Hz)', value=120)
    form.text(name='E', label = 'Desired incident energy (meV)', value=100)
    form.text(name='emission_time', label = 'Emission time (microsecond)', value=10)
    form.submitbutton()
    form.onsubmit = select(element=form).submit(
        actor='neutronexperiment/edit/ARCS_beam_withmonitor2_wizard',
        experiment_id = experiment.id)
    
    return doc
Esempio n. 5
0
    def create(self):
        view = lc.document(id='atomicstructure-details-view')

        #
        titlebar = lc.splitter(Class='atomicstructure-details-view-title-bar')
        view.add(titlebar)

        # view indicator
        view_indicator = self.createViewIndicator()
        titlebar.section().add(view_indicator)

        # view of pdb content
        id = self.id
        htmldoc = lc.htmldocument(id='pdbview-%s' % id)
        view.add(htmldoc)
        #
        doma = self.domaccess
        pdbfile = doma.hasPDBfile(id)
        if not pdbfile:
            raise IOError, "no pdb data file: %s" % id
        #
        pdbcontent = open(pdbfile).read()
        htmldoc.text = "<pre>" + pdbcontent + "</pre>"

        return view
Esempio n. 6
0
    def _createAPIDocument(self, director):
        w = self.widget
        descriptors = w.getDescriptors()
        descriptors = self._categorizeDescriptors(descriptors)

        doc = lc.document()
        tabs = lc.tabs()
        doc.add(tabs)
        #
        tab1 = tabs.tab(label='Introduction')
        d = self._createIntroductionDocument(descriptors)
        tab1.add(d)
        #
        tab2 = tabs.tab(label='Properties')
        tab2.onselect = select(element=tab2).replaceContent(
            load(actor=self.name, routine='propertiesDocument'))
        #
        tab3 = tabs.tab(label='Events')
        tab3.onselect = select(element=tab3).replaceContent(
            load(actor=self.name, routine='eventsDocument'))
        #
        tab4 = tabs.tab(label='Actions')
        tab4.onselect = select(element=tab4).replaceContent(
            load(actor=self.name, routine='actionsDocument'))
        #
        return doc
Esempio n. 7
0
def configuration_wizard(experiment):
    doc = lc.document(
        title='Configuration wizard for ARCS_beam',
        id='instrument-configuration-wizard',
    )

    # button to skip this wizard
    from . import load_manual_instrument_configuration
    load_manual_configuration = load_manual_instrument_configuration(
        experiment.id)
    skip_button = lc.button(
        label='skip this wizard',
        onclick=select(element=doc).replaceBy(load_manual_configuration),
    )
    doc.add(skip_button)

    # wizard
    form = doc.form(id='arcs-beam-wizard')
    form.text(name='fermi_nu', label='Fermi chopper frequency (Hz)', value=600)
    # form.text(name='fermi_bladeradius', label = 'Fermi choipper blade radius (meter)', value=0.060364)
    form.text(name='T0_nu', label='T0 chopper frequency (Hz)', value=120)
    form.text(name='E', label='Desired incident energy (meV)', value=100)
    form.text(name='emission_time',
              label='Emission time (microsecond)',
              value=10)
    form.submitbutton()
    form.onsubmit = select(element=form).submit(
        actor='neutronexperiment/edit/ARCS_beam_wizard',
        experiment_id=experiment.id)

    return doc
Esempio n. 8
0
    def _createExample(self,
                       director=None,
                       title=None,
                       description=None,
                       func=None,
                       deps=None):
        doc = lc.document(title=title)
        doc.collapsable = True
        doc.Class = 'example-container'

        tabs = self._createTabsForDemoPanelAndCodeViewer(func,
                                                         director,
                                                         deps=deps)
        doc.add(tabs)

        if description:
            p = lc.restructuredtextdocument()
            doc.add(p)
            p.Class = 'example-description'
            p.text = description
            p.text.append('')
            p.text.append(
                'Please click on the "Code" tab to see how this demo is implemented.'
            )

        return doc
Esempio n. 9
0
 def _selectorCores(self, director):
     "Special field: number of cores"
     cores = lc.document(id=ID_SELECTOR_CORES)
     procfield = FormSelectorField(name="numproc",
                                   entries=self._procOptions(director))
     cores.add(procfield)
     return cores
Esempio n. 10
0
    def _showActions(self, director, section):
#        self._backAction(section)
        self._refreshAction(section)
        self._newTestAction(section)
        self._pwInputAction(section)

        section.add(lc.document(Class="clear-both"))
Esempio n. 11
0
    def createFrontPageBodyDocument(self, post_authorization_action, director):
        '''create the body document for the front page
        embed this document inside the skeleton in visuals/skeleton then we
        get the whole front page (frame)
        '''
        bodydoc = lc.document(id='login-body-doc')
        splitter = lc.splitter(id='login-body-splitter')
        bodydoc.add(splitter)

        # left
        left = splitter.section(id='login-body-left')
        # form
        formcontainer = left.document(id='login-form-container')
        form = self.createLoginForm(post_authorization_action, director)
        formcontainer.add(form)
        # portlet
        portlet = director.retrieveVisual('frontpage-portlet')
        left.add(portlet)
        #

        # right
        right = splitter.section(id='login-body-right')
        # introduction
        introcontainer = right.document(
            id='front-page-vnf-intro-container',
            title='Welcome to the Virtual Neutron Facility',
            )
        intro = lc.htmldocument(); introcontainer.add(intro)
        intro.text = [
            #'The Virtual Neutron Facility (VNF) provides online computation tools for simulating neutron scattering experiments.',
            '<p>The Virtual Neutron Facility (VNF) is an online tool that allows users to perform end-to-end, full simulations of neutron scattering experiments. It integrates scientific software packages for material simulations with Monte-Carlo simulations of neutron scattering to gain insights into material properties.</p>',
            ]
        # central display
        ctrldisplay = right.document(id='front-page-central-display')
        initialviewdocuments = [
            'screencasts',
            #'tutorials',
            'status',
            'technology',
            #'personnel',
            ]
        for idoc in initialviewdocuments:
            doc = director.redirect(
                actor='frontpage', routine='createDocument', name=idoc,
                include_credential=False)
            doc.Class += ' alternating-bg'
            ctrldisplay.add(doc)
            continue
        # footnote
        footnotecontainer = right.document(id='front-page-footnote-container')
        htmldoc = lc.htmldocument(); footnotecontainer.add(htmldoc)
        htmldoc.text = [
            'The VNF is a product of the <a target="_blank" href="http://danse.us">DANSE</a> project, which is bringing computational materials science and instrument simulations to neutron scattering experiments. The  DANSE project is funded by the US National Science Foundation under grant DMR-0520547.',
            ]
        htmldoc = lc.htmldocument(); footnotecontainer.add(htmldoc)
        htmldoc.text = [        
            # 'You are presently at the stable release site of VNF; the version under development is <a target="_blank" href="https://vnf-dev.caltech.edu">here</a>.',
            'You are presently at the development site of VNF; the release sites of vnf are available at <a target="_blank" href="https://vnf.caltech.edu">caltech</a> and <a target="_blank" href="https://vnf.sns.gov">SNS</a> (the latter is only accessible from inside ORNL)',
            ]
        return bodydoc
Esempio n. 12
0
    def _createEventsDocument(self, events):
        container = lc.document()

        descriptiontext = """You can specify what actions occur when an event happens in a luban element. The event handlers listed below are attributes of the luban element. If you set an event handler to be an action(or a list of actions), then that action(s) will be performed whenever the event occurs. """
        description = lc.restructuredtextdocument()
        container.add(description)
        description.Class = 'demo-description'
        description.text = [descriptiontext]

        for d in events:
            if hasattr(d, 'tip'): tip = d.tip
            else: tip = 'Please give a tip of property %s' % d.name

            title = d.name
            if hasattr(d, 'experimental') and d.experimental:
                title += '(experimental)'
            doc = container.document(title=title,
                                     collapsable=True,
                                     collapsed=True)
            doc.Class = 'api-item'

            examplecode = self.name + 'instance' + '.' + d.name + ' = some_action'
            ex = doc.paragraph(text=[examplecode])
            ex.Class = 'signature'

            p = doc.paragraph()
            p.text = tip.splitlines()
            p.Class = 'description'
            continue
        return container
Esempio n. 13
0
    def create(self):
        view = lc.document(id='atomicstructure-details-view')

        #
        titlebar = lc.splitter(Class='atomicstructure-details-view-title-bar')
        view.add(titlebar)

        # view indicator
        view_indicator = self.createViewIndicator()
        titlebar.section().add(view_indicator)

        # view of pdb content
        id = self.id
        htmldoc = lc.htmldocument(id='pdbview-%s'%id)
        view.add(htmldoc)
        # 
        doma = self.domaccess
        pdbfile = doma.hasPDBfile(id)
        if not pdbfile: 
            raise IOError, "no pdb data file: %s" % id
        # 
        pdbcontent = open(pdbfile).read()
        htmldoc.text = "<pre>" + pdbcontent + "</pre>"
        
        return view
Esempio n. 14
0
    def _createFCMfield(obj):
        # a new field for force_constant_matrix
        doc = lc.document(title='force constant matrix', Class='force-constant-matrix-input-container')
        from luban.content.FormTextField import FormTextField

        # left and right
        sp = doc.splitter()
        left = sp.section(Class='force-constant-matrix')
        right = sp.section(Class='force-constant-matrix-constraints-section')

        # left is grid for the matrix
        grid = lc.grid(); left.add(grid)
        fcm = obj.force_constant_matrix
        for i in range(3):
            gr = grid.row()
            for j in range(3):
                gc = gr.cell()
                v = fcm[i,j]
                w = FormTextField(value=v, name='%s_%s_%s' % ('force_constant_matrix', i, j))
                gc.add(w)
            continue

        # right is the container for constraints
        cdoc = right.document(name='force-constant-matrix-constraints', title='constraints')

        return doc
Esempio n. 15
0
    def _contentOutput(self, director):
        doc = lc.document()
        visual = 'material_simulations/espresso-analysis/outputs'
        doc.add(
            director.retrieveVisual(visual, director, self.id, self.type,
                                    self.linkorder))

        return doc
Esempio n. 16
0
        def _createfield_for_phonons(obj):
            # this is a method of mold.
            self = drawer.mold

            # imports
            import luban.content as lc
            from luban.content import load, select
            from luban.content.FormSelectorField import FormSelectorField

            # utils
            orm = self.orm

            # data
            record = self.orm(obj)
            referred_record = record.phonons and record.phonons.id \
                              and record.phonons.dereference(self.orm.db)

            # widget
            doc = lc.document(Class='container',
                              id='phonons-selector-container')
            sp = doc.splitter()
            left = sp.section()
            right = sp.section()
            #
            selector = FormSelectorField(label='Phonons:', name='phonons')
            left.add(selector)
            #
            plotcontainer = right.document(Class='container')
            #
            loadplot = lambda uid: load(
                actor='orm/phonons', routine='createGraphicalView', uid=uid)

            # default selection
            if referred_record:
                value = orm.db.getUniqueIdentifierStr(referred_record)
                plotcontainer.oncreate = select(element=plotcontainer).append(
                    loadplot(value))
            else:
                value = None

            # choices
            #  get matter
            matter = orm.db.dereference(record.matter)
            matterid = matter.id
            #  dynamically load choices
            entries = load(
                actor='orm/atomicstructures',
                routine='getSelectorEntriesForPhonons',
                id=matterid,
                include_none_entry=1,
            )
            selector.oncreate = select(element=selector).setAttr(
                entries=entries, value=value)
            selector.onchange = select(element=plotcontainer).replaceContent(
                loadplot(select(element=selector).getAttr('value')))

            return doc
Esempio n. 17
0
    def _outputAction(self, director, container):
        "Simulation output files"
        sA = container.section(Class="qe-section-text-output")
        sA.add(lc.htmldocument(text="Outputs: "))
        sB = container.section(Class="qe-section-output")

        docOutput = lc.document(id=ID_OUTPUTS)  # Hook for output links
        docOutput.add(self._outputLinks(director))
        sB.add(docOutput)
Esempio n. 18
0
    def _document(self, director, title, label, formMethod = "defaultForm", visual = None):
        doc         = lc.document(title = title)
        splitter    = doc.splitter(orientation = "vertical")
        sA          = splitter.section()
        sB          = splitter.section()
        sA.add(self._viewIndicator(director, label))
        sB.add(getattr(self, formMethod)(director, visual))

        return doc
Esempio n. 19
0
def getBaseVectorsDoc(matter, primitive_unitcell=False, title=None, id=None):
    if primitive_unitcell:
        base = matter.primitive_unitcell.base
    else:
        base = matter.lattice.base
    doc = lc.document(id=id, title=title)
    for v in base:
        doc.paragraph(text=[str(v)])
        continue
    return doc
Esempio n. 20
0
        def _createfield_for_sqe(obj):
            # this is a method of mold.
            self = drawer.mold

            # imports
            import luban.content as lc
            from luban.content import load, select
            from luban.content.FormSelectorField import FormSelectorField
            
            # utils
            orm = self.orm

            # data 
            record = self.orm(obj)
            referred_record = record.sqe and record.sqe.id \
                              and record.sqe.dereference(self.orm.db)

            # widget
            doc = lc.document(Class='container', id='sqe-selector-container')
            sp = doc.splitter()
            left = sp.section(); right = sp.section()
            #
            selector = FormSelectorField(label='Sqe:', name='sqe')
            left.add(selector)
            #
            plotcontainer = right.document(Class='container')
            #
            loadplot = lambda uid: load(
                actor='orm/sqe', routine='createGraphicalView',
                uid=uid)

            # default selection
            if referred_record:
                value=orm.db.getUniqueIdentifierStr(referred_record)
                plotcontainer.oncreate = select(element=plotcontainer).append(
                    loadplot(value))
            else:
                value=None

            # choices
            #  get matter
            matter = orm.db.dereference(record.matter)
            matterid = matter.id
            #  dynamically load choices
            entries = load(
                actor='orm/atomicstructures',
                routine='getSelectorEntriesForSqe',
                id = matterid,
                include_none_entry = 1,
                )
            selector.oncreate = select(element=selector).setAttr(entries=entries, value=value)
            selector.onchange = select(element=plotcontainer).replaceContent(
                loadplot(select(element=selector).getAttr('value')))
            
            return doc
Esempio n. 21
0
    def content(self, director):
        "Contains of two separate splitters: header and results"
        self._setup(director)

        doc         = lc.document(title="Convergence Tests")
        splitter    = doc.splitter(orientation="vertical")
        sInd        = splitter.section()                        # path indicator
        sAct        = splitter.section(id="qe-section-actions") # actions

        docResults  = lc.document(id = ID_CONVERGENCE)
        doc.add(docResults)

        self._viewIndicator(director, sInd)
        self._showActions(director, sAct)                 # Show actions

        # Main content
        resSplitter = docResults.splitter(orientation="vertical")
        self._mainContent(director, resSplitter)              # Simulation Specific data

        return doc
Esempio n. 22
0
    def content(self, director):
        "Contains of two separate splitters: header and results"
        self._setup(director)

        doc = lc.document(title="Convergence Tests")
        splitter = doc.splitter(orientation="vertical")
        sInd = splitter.section()  # path indicator
        sAct = splitter.section(id="qe-section-actions")  # actions

        docResults = lc.document(id=ID_CONVERGENCE)
        doc.add(docResults)

        self._viewIndicator(director, sInd)
        self._showActions(director, sAct)  # Show actions

        # Main content
        resSplitter = docResults.splitter(orientation="vertical")
        self._mainContent(director, resSplitter)  # Simulation Specific data

        return doc
Esempio n. 23
0
    def _showActions(self, director, section):
        # Action splitter
        container = lc.splitter(orientation="horizontal",
                                id="qe-splitter-analysis")
        sMain = container.section(Class="qe-section-back")  # Left actions
        section.add(container)
        self._backAction(sMain)
        self._refreshAction(sMain)
        self._exportAction(sMain)
        self._outputAction(director, container)

        section.add(lc.document(Class="clear-both"))
Esempio n. 24
0
    def action(self):
        "Displays simulation task action button: 'Run Task', 'Cancel'"
        doc = lc.document()  # Example: run-task-BFDFX56

        if not self._task:
            return doc

        doc.id = "%s-%s" % (TASK_ACTION, self._task.id)
        action = TaskAction(self._director, self._simid, self._job, self._task)

        doc.add(action.link())
        return doc
Esempio n. 25
0
    def action(self):
        "Displays simulation task action button: 'Run Task', 'Cancel'"
        doc     = lc.document()   # Example: run-task-BFDFX56

        if not self._task:
            return doc

        doc.id = "%s-%s" % (TASK_ACTION, self._task.id)
        action  = TaskAction(self._director, self._simid, self._job, self._task)

        doc.add(action.link())
        return doc
Esempio n. 26
0
        def _createfield_for_neutrons(obj):
            # this is a method of mold.
            self = drawer.mold

            # imports
            import luban.content as lc
            from luban.content import load, select
            from luban.content.FormSelectorField import FormSelectorField
            
            # utils
            orm = self.orm

            # data 
            record = self.orm(obj)
            referred_record = record.neutrons and record.neutrons.id \
                              and record.neutrons.dereference(self.orm.db)

            # widget
            doc = lc.document(Class='container', id='neutrons-selector-container')
            sp = doc.splitter(orientation='horizontal')
            left = sp.section(); right = sp.section()
            #
            selector = FormSelectorField(label='Neutrons:', name='neutrons')
            left.add(selector)
            #
            viewcontainer = right.document(Class='container')
            #
            loadview = lambda uid: load(
                actor='orm/neutronstorages', routine='createGraphicalView',
                uid=uid, start=0, end=2)

            # default selection
            if referred_record:
                value=orm.db.getUniqueIdentifierStr(referred_record)
                viewcontainer.oncreate = select(element=viewcontainer).append(
                    loadview(value))
            else:
                value=None

            # choices
            #  dynamically load choices
            entries = load(
                actor='orm/neutronplayers',
                routine='getSelectorEntriesForReference',
                refname = 'neutrons',
                include_none_entry = 1,
                )
            selector.oncreate = select(element=selector).setAttr(entries=entries, value=value)
            selector.onchange = select(element=viewcontainer).replaceContent(
                loadview(select(element=selector).getAttr('value')))
            
            return doc
Esempio n. 27
0
    def __call__(self, *args, **kwds):
        # there might be one argument that is the director
        if len(args) > 1:
            raise ValueError, "args: %s, kwds: %s" % (args, kwds)
        if len(args):
            kwds['director'] = args[0]
        #
        director = kwds['director']
        self.director = director
        if self.checkPrivilege():
            return lc.document(title='not enough privilege')

        return self.create(**kwds)
Esempio n. 28
0
    def link(self):
        """
        Returns link to results when ready or string with status
        """
        cid         = "%s-%s" % (RESULTS_ID, self._id()) # self._task.id?
        container   = lc.document(id=cid)
        link        = lc.htmldocument(text="None") # Default value

        if self._job:
            link    = self.status()
            
        container.add(link)
        return container
Esempio n. 29
0
    def __call__(self, *args, **kwds):
        # there might be one argument that is the director
        if len(args) > 1:
            raise ValueError, "args: %s, kwds: %s" % (args, kwds)
        if len(args):
            kwds['director'] = args[0]
        #
        director = kwds['director']
        self.director = director
        if self.checkPrivilege():
            return lc.document(title='not enough privilege')

        return self.create(**kwds)
Esempio n. 30
0
    def status(self, formatted=True):
        "Returns status message"
        if not formatted:  # Return just status
            return self._jobStatus()

        doc = lc.document(id=self._statusId())
        content = lc.htmldocument(text=DEFAULT_MESSAGE)
        doc.add(content)

        if not self._job:
            return doc

        content.text = key2str(self._jobStatus())
        return doc
Esempio n. 31
0
    def _document(self,
                  director,
                  title,
                  label,
                  formMethod="defaultForm",
                  visual=None):
        doc = lc.document(title=title)
        splitter = doc.splitter(orientation="vertical")
        sA = splitter.section()
        sB = splitter.section()
        sA.add(self._viewIndicator(director, label))
        sB.add(getattr(self, formMethod)(director, visual))

        return doc
Esempio n. 32
0
    def create(self):
        view = lc.document(id='edit-atomicstructure-details')

        titlebar = lc.splitter(Class='atomicstructure-details-view-title-bar')
        view.add(titlebar)

        # view indicator
        view_indicator = self.createViewIndicator()
        titlebar.section().add(view_indicator)

        #
        view.paragraph(text="This is not yet supported")
        
        return view
Esempio n. 33
0
    def create(self):
        view = lc.document(id='edit-atomicstructure-details')

        titlebar = lc.splitter(Class='atomicstructure-details-view-title-bar')
        view.add(titlebar)

        # view indicator
        view_indicator = self.createViewIndicator()
        titlebar.section().add(view_indicator)

        #
        view.paragraph(text="This is not yet supported")

        return view
Esempio n. 34
0
    def status(self, formatted=True):
        "Returns status message"
        if not formatted:   # Return just status
            return self._jobStatus()

        doc     = lc.document(id = self._statusId())
        content = lc.htmldocument(text = DEFAULT_MESSAGE)
        doc.add(content)

        if not self._job:
            return doc
        
        content.text    = key2str(self._jobStatus())
        return doc
Esempio n. 35
0
 def createDemoDocument(self, director):
     container = lc.document()
     #
     doc = self._createSwitcher(director)
     doc.title = 'Demos'
     doc.collapsable = True
     doc.Class = 'demo-document'
     container.add(doc)
     #
     c = container.document(title='Introduction', collapsable=True)
     #
     d = lc.restructuredtextdocument()
     c.add(d)
     d.text = self.introduction.splitlines()
     return container
        def _createfield_for_lazcontent(obj):
            # this is a method of mold.
            self = drawer.mold

            # imports
            import luban.content as lc
            from luban.content import load, select
            from luban.content.FormTextArea import FormTextArea

            # widget
            doc     = lc.document(Class='container', id='lazcontent-content-container')
            content = FormTextArea(name='lazcontent', label='Content of .laz file')
            doc.add(content)
            
            return doc
Esempio n. 37
0
    def _createSwitcher(self, director):
        import inspect

        # find routines that create panels
        routines = {}
        for k, v in self.__class__.__dict__.iteritems():
            # skip
            #  - private
            if k.startswith('_'): continue
            #  - non-method
            if not inspect.ismethod(v) and not inspect.isfunction(v): continue
            #  - signature
            sig = 'ispanel'
            if not hasattr(v, sig): continue
            if not getattr(v, sig): continue

            routines[k] = v
            continue

        # container
        container = lc.document()
        tabs = lc.tabs()
        container.add(tabs)

        #
        if hasattr(self.__class__, 'demo_panels'):
            panels = self.__class__.demo_panels
        else:
            panels = routines.iterkeys()
        for i, k in enumerate(panels):
            # call method to get inner document
            method = getattr(self, k)
            # use inner document's title as tab's label
            label = method.title
            # create tab
            tab = tabs.tab(label=label)
            # add the first document
            if i == 0:
                inner = method(director)
                tab.add(inner)
            else:
                tab.onselect = select(element=tab).replaceContent(
                    load(actor=self.name, routine=k))
            continue

        return container
Esempio n. 38
0
        def _createfield_for_lazcontent(obj):
            # this is a method of mold.
            self = drawer.mold

            # imports
            import luban.content as lc
            from luban.content import load, select
            from luban.content.FormTextArea import FormTextArea

            # widget
            doc = lc.document(Class='container',
                              id='lazcontent-content-container')
            content = FormTextArea(name='lazcontent',
                                   label='Content of .laz file')
            doc.add(content)

            return doc
Esempio n. 39
0
        def _(self, director):
            # container = lc.document(title = title)
            container = lc.document()
            p = container.paragraph(text=description)
            p.Class = 'demo-description'
            accordion = lc.accordion()
            container.add(accordion)
            accordion.Class = 'demo-panel'

            for i, example in enumerate(examples):
                doc = self.createExampleDocument(getattr(self, example),
                                                 director)
                label = 'Demo %s: %s' % (i + 1, doc.title)
                sec = accordion.section(label=label)
                for elem in doc.contents:
                    sec.add(elem)
                continue
            return container
Esempio n. 40
0
def visual_inline(path):
    # path is a list of (label, action) and one label as the last item

    doc = lc.document(id='view-indicator')

    doc1 = doc
    for (label, action) in path[:-1]:
        doc1.add(lc.link(label=label, onclick=action))
        doc1.paragraph(text=['/ '], Class='splitter')
        continue

    last = path[-1]
    if isinstance(last, basestring):
        doc1.paragraph(text=path[-1])
    else:
        label, action = last
        doc1.add(lc.link(label=label, onclick=action))

    return doc
Esempio n. 41
0
def visual_inline(path):
    # path is a list of (label, action) and one label as the last item

    doc = lc.document(id='view-indicator')

    doc1 = doc
    for (label, action) in path[:-1]:
        doc1.add(lc.link(label=label, onclick=action))
        doc1.paragraph(text=['/ '], Class='splitter')
        continue

    last = path[-1]
    if isinstance(last, basestring):
        doc1.paragraph(text=path[-1])
    else:
        label, action = last
        doc1.add(lc.link(label=label, onclick=action))

    return doc
Esempio n. 42
0
def createComponentButton(component, infocus=False, buttonids=[], refresh_config_panel=None):
    'create the button for the given component'
    
    button = lc.document(id=button_id_formatter_for_component % component.id)
    button.Class='component-chain-button'

    labelelem = createComponentButtonLabelElement(component)
    button.add(labelelem)
    
    if infocus:
        button.addClass('selected')

    #
    from mcvineui.visuals import select_one
    selectthisbutton = select_one(button.id, buttonids)
    button.onclick = selectthisbutton + [refresh_config_panel]
    
    button.tip = '%s: click for more details' % component.componentname
    
    return button
Esempio n. 43
0
    def create(self):
        view = lc.document(id='atomicstructure-details-view')

        titlebar = lc.splitter(Class='atomicstructure-details-view-title-bar')
        view.add(titlebar)

        # view indicator
        view_indicator = self.createViewIndicator()
        titlebar.section().add(view_indicator)

        #
        obj = self.atomicstructure
        director = self.director
        drawer = director.painter.paintObj.drawers.getDrawer(obj.__class__)

        editable = self.domaccess.isEditable(self.id)
        doc = drawer(obj, readonly=True, editlink=editable)
        view.add(doc)
        
        return view
Esempio n. 44
0
    def create(self):
        view = lc.document(id='atomicstructure-details-view')

        titlebar = lc.splitter(Class='atomicstructure-details-view-title-bar')
        view.add(titlebar)

        # view indicator
        view_indicator = self.createViewIndicator()
        titlebar.section().add(view_indicator)

        #
        obj = self.atomicstructure
        director = self.director
        drawer = director.painter.paintObj.drawers.getDrawer(obj.__class__)

        editable = self.domaccess.isEditable(self.id)
        doc = drawer(obj, readonly=True, editlink=editable)
        view.add(doc)

        return view
Esempio n. 45
0
def visual(
    instrument=None,
    components=[], refresh_component_configuration_panel=None, component_in_focus=None,
    actorname = None,
    db = None,
    director = None,
    ):
    """
    instrument: id of the instrument which has the component chain
    components: list of component instances
    refresh_component_configuration_panel: action factory that creates an action to refresh component configuration panel give the component. sth like lambda component: ... some action ...
    component_in_focus: the component that is now being focused
    actorname: the actor to deal with events for this visual
    db: db manager
    """
    
    doc = lc.document(id='component-chain-container', title='Component chain')
    sp = doc.splitter(id='component-chain')

    # ids of components
    ids = [c.id for c in components]

    # ids of buttons for components
    buttonids = [button_id_formatter_for_component % id for id in ids]

    # ids of insert buttons for components
    insertbuttonids = [button_id_formatter_for_insert_before % id for id in ids]
        
    for component in components:
        compuid = db.getUniqueIdentifierStr(component)
            
        # button to insert before a component
        insertbuttoncontainer = sp.section()
        insertbutton = lc.button(id=button_id_formatter_for_insert_before%component.id)
        insertbuttoncontainer.add(insertbutton)
        insertbutton.Class='component-chain-insert-button'
        insertbutton.label = '==>'
        insertbutton.tip = 'click to insert component'
        insertbutton.onclick = load(
            actor=actorname, routine='onInsertComponent',
            id = instrument, before=compuid)

        # "button" of a comonent
        infocus = component_in_focus.id == component.id
        refresh_config_panel = refresh_component_configuration_panel(component)
        button = createComponentButton(
            component, 
            infocus=infocus, 
            buttonids = buttonids,
            refresh_config_panel = refresh_config_panel,
            )
        sp.section().add(button)
        continue

    # button to append before a component
    appendbuttoncontainer = sp.section()
    appendbutton = lc.button(id='append-component')
    appendbuttoncontainer.add(appendbutton)
    appendbutton.Class='component-chain-insert-button'
    appendbutton.label = '==>'
    appendbutton.tip = 'click to append component'
    appendbutton.onclick = load(
        actor=actorname, routine='onAppendComponent',
        id = instrument)

    return doc
Esempio n. 46
0
 def _selectorCores(self, director):
     "Special field: number of cores"
     cores           = lc.document(id=ID_SELECTOR_CORES)
     procfield       = FormSelectorField(name="numproc", entries = self._procOptions(director))
     cores.add(procfield)
     return cores
Esempio n. 47
0
    def create(self):
        #
        computation = self.computation
        actor = self.actor
        director = self.director
        on_all_results_retrieved = self.on_all_results_retrieved
        
        # utilities
        domaccess = director.retrieveDOMAccessor('computation')
        orm = domaccess.orm
        db = orm.db
    
        # 
        id = computation.id
        type = computation.getTableName()

        # the job
        job = computation.getJob(db)
        # always good to check the job
        from vnf.utils.job import check
        check(job, director)

        # the document to build
        doc = lc.document(Class='container', id='computation-results-container')

        # depending on retrieval status, we need to add some extra things to the document
        result_retrieval_status = computation.getResultRetrievalStatus(db)

        if result_retrieval_status is None:
            from vnf.utils.computation import start_results_retrieval
            start_results_retrieval(computation, director)
            result_retrieval_status = 'retrieving'

        refresh = select(element=doc).replaceBy(
            load(actor='loadvisual', visual='computation-results',
                 id=id, type=type,
                 on_all_results_retrieved = on_all_results_retrieved,
                 )
            )

        if result_retrieval_status == 'retrieving':
            p = doc.paragraph(text=['Still retrieving results...'])

            from vnf.utils.computation import get_results_retrieval_task
            task = get_results_retrieval_task(computation, db)
            if not task:
                raise RuntimeError, 'there should be an itask working at retrieving '+\
            'results for computation %s, but we found none' % computation.id

            pbar = lc.progressbar(
                id = 'itask-%s-pbar' % task.id,
                status = 'Retrieving results...',
                percentage = 0,
                skip = 1000,
                )
            pbar.onchecking = load(
                actor='itask',
                routine='checkProgress',
                id = task.id,
                )
            if on_all_results_retrieved:
                from vnf.content import safe_eval_action
                onfinished = safe_eval_action(on_all_results_retrieved)
            else:
                onfinished = refresh
            pbar.onfinished = onfinished
            pbar.oncanceled = refresh
            doc.add(pbar)

        elif result_retrieval_status.find('failed') != -1:
            p = doc.paragraph(text=['failed to retrieve results'])
            # the action to load this visual (type: string)
            refresh_action_in_str = 'select(id="computation-results-container").replaceBy(load(actor="loadvisual", visual="computation-results", id="%s", type="%s", on_all_results_retrieved = "%s"))' % (id, type, on_all_results_retrieved or '')
            # link to restart retrieval
            l = lc.link(
                label = 'restart results retrieval',
                onclick = [
                  load(actor='computation', routine='restartResultsRetrieval',
                       type = type, id = id,
                       posterior_action = refresh_action_in_str,
                       )
                  ],
                )
            doc.add(l)

        elif result_retrieval_status == 'retrieved':

            pass

        else:
            raise NotImplementedError, 'computation: %s, retrieval status: %s' % (
                type, result_retrieval_status)

        # display results 
        results = computation.results.dereference(db)
        for k, r in results:
    ##         alertdoc = doc.paragraph(
    ##             text=['loading computation result %s %s. please wait...' % (
    ##             r.getTableName(), r.id)]
    ##             )
            title = '%s %s: expand for details' % (r.__class__.__name__, r.id)
            doc1 = doc.document(
                id = 'resultdoc-%s' % r.id,
                Class='container', title=title, collapsable=True, collapsed=True)
            doc1.onexpand = [
                #select(element=alertdoc).hide(),
                select(element=doc1).replaceBy(
                load(actor='orm/%s' % r.getTableName(),
                     routine='createGraphicalView',
                     id = r.id)
                )
                ]
            continue

        return doc