예제 #1
0
    def AppState(self, fragment, state, node):
        def _onNewDoc(link, event):
            def handleNewDocumentFn(document, firstPageSubjectFn):
                name = _newDocumentName(openDocuments)
                document.setDocumentName(name)

                node.registerOpenDocument(document)

                subject = document.newSubject(fragment.subject, None,
                                              document.getDocumentName())
                subject = firstPageSubjectFn(subject)

                pageController = link.element.rootElement.pageController
                pageController.openSubject(
                    subject, PageController.OpenOperation.OPEN_IN_CURRENT_TAB)

            element = link.getElement()
            openDocuments = node.getOpenDocuments()
            DocumentManagement.promptNewDocument(fragment.subject.world,
                                                 element, handleNewDocumentFn)

            return True

        def _onOpenDoc(link, event):
            def handleOpenedDocumentFn(fullPath, document):
                appDoc = node.registerOpenDocument(document)

            element = link.getElement()
            DocumentManagement.promptOpenDocument(
                fragment.subject.world,
                element.getRootElement().getComponent(),
                handleOpenedDocumentFn)

            return True

        def _onFileListDrop(element, targetPosition, data, action):
            world = fragment.subject.world
            for filename in data:
                filename = str(filename)

                document = Document.readFile(world, filename)
                node.registerOpenDocument(document)
            return True

        def _onNewConsole(link, event):
            consoles = node.getConsoles()
            index = _newConsoleIndex(consoles)
            appConsole = Application.AppConsole(index)
            node.addConsole(appConsole)

            subject = appConsole.subject(fragment.subject)

            pageController = link.element.rootElement.pageController
            pageController.openSubject(
                subject, PageController.OpenOperation.OPEN_IN_CURRENT_TAB)

            return True

        openDocViews = Pres.mapCoerce(node.getOpenDocuments())
        consoles = Pres.mapCoerce(node.getConsoles())

        systemLink = Hyperlink('TEST PAGES', TestsRootPage.instanceSubject)
        configurationLink = Hyperlink(
            'CONFIGURATION PAGE',
            fragment.subject.world.configuration.subject())
        aboutLink = Hyperlink('ABOUT', fragment.subject.aboutPageSubject)
        linkHeader = SplitLinkHeaderBar([aboutLink],
                                        [configurationLink, systemLink])

        title = TitleBar('The Larch Environment')

        newLink = Hyperlink('NEW', _onNewDoc)
        openLink = Hyperlink('OPEN', _onOpenDoc)
        openDocumentsBox = _contentsList([newLink, openLink], openDocViews,
                                         'Documents')
        openDocumentsBox = openDocumentsBox.withNonLocalDropDest(
            DataFlavor.javaFileListFlavor, _onFileListDrop)
        openDocumentsBox = AttachTooltip(
            openDocumentsBox,
            'Click NEW to create a new document. To open from a file, click OPEN, or drag files from a file explorer application.',
            False)

        newConsoleLink = Hyperlink('NEW', _onNewConsole)
        consolesBox = _contentsList([newConsoleLink], consoles,
                                    'Python consoles')


        tip = TipBox( [ NormalText( [ StrongSpan( 'Getting started: ' ), 'To get programming quickly, create a new Python console by pressing ', EmphSpan( 'new' ), ', beneath', EmphSpan( ' Python consoles' ), '.' ] ),
          NormalText( [ 'For something more easily modifiable and something you can save, press ', EmphSpan( 'new' ), ' beneath ', EmphSpan( 'Documents' ), ' and choose the ', EmphSpan( 'Quickstart: worksheet' ), ' option.' ] ),
          NormalText( [ StrongSpan( 'Tips: ' ), 'You can highlight items that have help tips by pressing F2. Hover the pointer over them to display the tips. ' + \
                   'Some items do not display their tips unless highlighting is enabled, in order to reduce clutter.' ] ),
          NormalText( [ StrongSpan( 'Command bar: ' ), 'The command bar can be invoked by pressing the ', EmphSpan( 'escape' ), ' key. From there you can type abbreviated commands to invoke them. '
            'Alternatively, type in part of the full name of a command and autocomplete will show a list of commands that match. '
            'Press ', EmphSpan( 'tab' ), ' to switch between the entries in the autocomplete list and press ', EmphSpan( 'enter' ), ' to execute the highlighted command. '
            'Bold letters shown within command names indicate abbreviations, e.g. ', EmphSpan( 's' ), ' for ', EmphSpan( 'save' ), ' and ', EmphSpan( 'sa' ), ' for ', EmphSpan( 'save as' ), '. '
            'You can type these to execute them quickly.' ] )],
               'larchcore.mainapp.tooltiphighlights' )

        head = Head([linkHeader, title])
        body = Body([
            openDocumentsBox.pad(0.0, 10.0).alignHLeft(),
            consolesBox.pad(0.0, 10.0).alignHLeft(), tip
        ])
        return StyleSheet.style(Primitive.editable(False)).applyTo(
            Page([head, body]))
예제 #2
0
 def Body(self, fragment, inheritedState, node):
     contentViews = Pres.mapCoerce(
         [c for c in node.getContents() if c.isVisible()])
     return Body(contentViews).padX(_worksheetMargin)