def __present_contents__(self, fragment, inheritedState):
        self._incr.onAccess()

        dirPres = self._presentDir()
        note = NotesText([
            'Note: please choose the location of the GraphViz ',
            EmphSpan('bin'), ' directory.'
        ])
        columnContents = [note, dirPres]
        if self._config is not None:
            columnContents.append(self._presentConfig())
        pathContents = Column(columnContents)
        pathSection = Section(SectionHeading2('GraphViz path'), pathContents)

        downloadText = ''
        if self.__isConfigured():
            downloadText = 'GraphViz appears to be installed on this machine and configured. If it does not work correctly, you may need to install it. You can download it from the '
        else:
            downloadText = 'If GraphViz is not installed on this machine, please install it. You can download it from the '

        downloadLink = Hyperlink('GraphViz homepage',
                                 URI('http://www.graphviz.org/'))
        download = NormalText([downloadText, downloadLink, '.'])
        downloadSec = Section(
            SectionHeading2('GraphViz download/installation'), download)

        return Body([pathSection, downloadSec])
Exemplo n.º 2
0
 def _showEditorPopup(self, element, popupMenu):
     settingsPres = self._createSettingsPres()
     newEditorPres = self._createNewEditorPres()
     if settingsPres is not None or newEditorPres is not None:
         if settingsPres is not None:
             popupMenu.add(
                 Section(SectionHeading2('Settings'), settingsPres))
         if newEditorPres is not None:
             popupMenu.add(
                 Section(SectionHeading2('New editor'), newEditorPres))
         return True
     else:
         return False
def _documentContextMenuFactory(element, menu):
	region = element.getRegion()
	rootElement = element.getRootElement()
	
	def makeParagraphStyleFn(style):
		def setParagraphStyle(model):
			model.style = style
		
		def _onLink(link, event):
			caret = rootElement.getCaret()
			if caret is not None and caret.isValid():
				caretElement = caret.getElement()
				if caretElement.getRegion() is region:
					GUIRichTextController.instance.modifyParagraphAtMarker(caret.getMarker(), setParagraphStyle)
		return _onLink
	
	normalStyle = Hyperlink('Normal', makeParagraphStyleFn('normal'))
	h1Style = Hyperlink('H1', makeParagraphStyleFn('h1'))
	h2Style = Hyperlink('H2', makeParagraphStyleFn('h2'))
	h3Style = Hyperlink('H3', makeParagraphStyleFn('h3'))
	h4Style = Hyperlink('H4', makeParagraphStyleFn('h4'))
	h5Style = Hyperlink('H5', makeParagraphStyleFn('h5'))
	h6Style = Hyperlink('H6', makeParagraphStyleFn('h6'))
	titleStyle = Hyperlink('Title', makeParagraphStyleFn('title'))
	paraStyles = ControlsRow([normalStyle, h1Style, h2Style, h3Style, h4Style, h5Style, h6Style, titleStyle])
	menu.add(Section(SectionHeading2('Paragraph styles'), paraStyles))

	
	def makeStyleFn(attrName):
		def computeStyleValues(listOfSpanAttrs):
			value = bool(listOfSpanAttrs[0].getValue(attrName, 0))
			value = not value
			attrs = RichTextAttributes()
			attrs.putOverride(attrName, '1'   if value   else None)
			return attrs

		def onButton(button, event):
			selection = rootElement.getSelection()
			if isinstance(selection, TextSelection):
				if selection.getRegion() == region:
					GUIRichTextController.instance.applyStyleToSelection(selection, computeStyleValues)
		return onButton
	
	italicStyle = Button.buttonWithLabel('I', makeStyleFn('italic'))
	boldStyle = Button.buttonWithLabel('B', makeStyleFn('bold'))
	styles = ControlsRow([italicStyle, boldStyle]).alignHLeft()

	menu.add(Section(SectionHeading2('Selection styles'), styles))

	
	return True
	def currentComponentUI():
		component = currentComponent.getValue()
		if component is not None:
			editUI = component._editUI()
			return Section(SectionHeading3(component.componentName), editUI)
		else:
			return Blank()
Exemplo n.º 5
0
 def _onReset(button, event):
     project.reset()
     modules = document.unloadAllImportedModules()
     heading = SectionHeading2('Unloaded modules:')
     modules = Column([Label(module) for module in modules])
     report = Section(heading, modules)
     BubblePopup.popupInBubbleAdjacentTo(report, button.getElement(),
                                         Anchor.BOTTOM, True, True)
Exemplo n.º 6
0
def _worksheetContextMenuFactory(element, menu):
    def _onRefresh(button, event):
        model.refreshResults()

    model = element.getFragmentContext().getModel()

    refreshButton = Button.buttonWithLabel('Refresh', _onRefresh)
    worksheetControls = ControlsRow([refreshButton.alignHPack()])
    menu.add(Section(SectionHeading2('Worksheet'), worksheetControls))
    return True
Exemplo n.º 7
0
def _addPanelButtons(sourceElement, menu):
	# Side panel
	def _onShow(button, event):
		showSidePanel(sourceElement.rootElement)

	def _onHide(button, event):
		hideSidePanel(sourceElement.rootElement)

	panelButtons = ControlsRow([Button.buttonWithLabel('Show', _onShow), Button.buttonWithLabel('Hide', _onHide)])
	panelSection = Section(SectionHeading3('Side panel'), panelButtons)
	menu.add(panelSection)
def inspectFragment(fragment, sourceElement, triggeringEvent):
    selector = _FragmentSelector(fragment)

    title = SectionHeading1('Choose a fragment:')
    body = Section(title, selector)

    content = _inspectorStyle(SpaceBin(800.0, 0.0, body)).alignHExpand()
    content = DefaultPerspective.instance(content)

    BubblePopup.popupInBubbleAdjacentToMouse(content, sourceElement,
                                             Anchor.TOP, True, True)
    return True
Exemplo n.º 9
0
def componentContextMenu(element, menu):
	# Components under pointer
	guiEditorRootProp = element.findPropertyInAncestors(GUIEdProp.instance)
	guiEditorRootElement = guiEditorRootProp.element

	# Components under pointer
	menu.add(Section(SectionHeading3('Components under pointer'), _presentComponentsUnderPointer(element, guiEditorRootElement)))

	current = currentComponentEditor(element.rootElement)
	menu.add(current)


	# Side panel
	_addPanelButtons(element, menu)

	return True
Exemplo n.º 10
0
def _contentsList(controls, contentsLists, title):
    controlsBox = _appDocumentControlsStyle.applyTo(
        Row([c.padX(_controlsPadding) for c in controls]))
    controlsBorder = _appDocumentControlsBorder.surround(controlsBox)

    openDocumentsSeparator = HSeparator()

    docListBox = _documentListTableStyle.applyTo(RGrid(contentsLists))

    contentsBox = Column([
        controlsBorder.pad(2.0, 2.0), openDocumentsSeparator,
        docListBox.pad(12.0, 2.0)
    ])

    heading = SectionHeading1(title)

    return Section(heading, contentsBox)
Exemplo n.º 11
0
        def samplePage():
            label = Label('Sample page:')

            title = titleSample(self._title.getValue(), 'Example Page Title')
            heading = headingSample(self._heading.getValue(), 'Main heading')
            normal1 = normalSample(self._normal.getValue(),
                                   'Normal text will appear like this.')
            normal2 = normalSample(
                self._normal.getValue(),
                'Paragraphs of normal text are used for standard content.')
            ui1 = uiHeadingSample(self._uiHeading.getValue(), 'UI heading')
            genericLabel = Label(
                'Generic text (within controls, code, etc) will appear like this.'
            )
            buttons = self._buttonRowStyle(
                Row([
                    Button.buttonWithLabel('Button %d' % (i, ), None)
                    for i in xrange(0, 5)
                ]))
            ui = Section(ui1, Column([genericLabel,
                                      Spacer(0.0, 7.0), buttons]))
            page = Page([title, Body([heading, normal1, normal2, ui])])

            return Column([label, Spacer(0.0, 15.0), page])
Exemplo n.º 12
0
    def ProjectRoot(self, fragment, inheritedState, project):
        # Save and Save As
        def _onSave(control, buttonEvent):
            if document.hasFilename():
                document.save()
            else:

                def handleSaveDocumentAsFn(filename):
                    document.saveAs(filename)

                DocumentManagement.promptSaveDocumentAs(
                    world,
                    control.getElement().getRootElement().getComponent(),
                    handleSaveDocumentAsFn)

        def _onSaveAs(control, buttonEvent):
            def handleSaveDocumentAsFn(filename):
                document.saveAs(filename)

            DocumentManagement.promptSaveDocumentAs(
                world,
                control.getElement().getRootElement().getComponent(),
                handleSaveDocumentAsFn, document.getFilename())

        def _onReload(control, buttonEvent):
            if document.hasFilename():
                document.save()
                document.reload()
                project.reset()
            else:

                def handleSaveDocumentAsFn(filename):
                    document.saveAs(filename)
                    document.reload()
                    project.reset()

                DocumentManagement.promptSaveDocumentAs(
                    world,
                    control.getElement().getRootElement().getComponent(),
                    handleSaveDocumentAsFn)

        def _onExport(control, event):
            component = control.getElement().getRootElement().getComponent()
            openDialog = JFileChooser()
            openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
            response = openDialog.showDialog(component, 'Export')
            if response == JFileChooser.APPROVE_OPTION:
                sf = openDialog.getSelectedFile()
                if sf is not None:
                    filename = sf.getPath()
                    if filename is not None and os.path.isdir(filename):
                        response = JOptionPane.showOptionDialog(
                            component,
                            'Existing content will be overwritten. Proceed?',
                            'Overwrite existing content',
                            JOptionPane.YES_NO_OPTION,
                            JOptionPane.WARNING_MESSAGE, None,
                            ['Overwrite', 'Cancel'], 'Cancel')
                        if response == JFileChooser.APPROVE_OPTION:
                            exc = None
                            try:
                                project.export(filename)
                            except:
                                exc = JythonException.getCurrentException()
                            if exc is not None:
                                BubblePopup.popupInBubbleAdjacentTo(
                                    DefaultPerspective.instance(exc),
                                    control.getElement(), Anchor.BOTTOM, True,
                                    True)

        # Python package name
        class _PythonPackageNameListener(EditableLabel.EditableLabelListener):
            def onTextChanged(self, editableLabel, text):
                if text != '':
                    project.pythonPackageName = text
                else:
                    project.pythonPackageName = None

        # Project index
        def _addPackage(menuItem):
            project.append(ProjectPackage('NewPackage'))

        def _addPage(page):
            project.append(page)

        def _projectIndexContextMenuFactory(element, menu):
            menu.add(MenuItem.menuItemWithLabel('New package', _addPackage))
            newPageMenu = PageData.newPageMenu(_addPage)
            importPageMenu = PageData.importPageMenu(
                element.getRootElement().getComponent(), _addPage)
            menu.add(
                MenuItem.menuItemWithLabel(
                    'New page', newPageMenu,
                    MenuItem.SubmenuPopupDirection.RIGHT))
            menu.add(
                MenuItem.menuItemWithLabel(
                    'Import page', importPageMenu,
                    MenuItem.SubmenuPopupDirection.RIGHT))
            return True

        # Get some initial variables
        document = fragment.subject.document
        world = fragment.subject.world

        # Title
        title = TitleBar(document.getDocumentName())

        # Controls for 'save' and 'save as'
        saveExportHeader = SectionHeading1('Save/export')
        saveButton = Button.buttonWithLabel('Save', _onSave)
        saveAsButton = Button.buttonWithLabel('Save as', _onSaveAs)
        reloadButton = Button.buttonWithLabel('Save and reload', _onReload)
        reloadButton = AttachTooltip(
            reloadButton,
            'Saves and reloads the project from scratch\nCauses all embedded objects to be re-created.'
        )
        exportButton = Button.buttonWithLabel('Export', _onExport)
        exportButton = AttachTooltip(
            exportButton,
            'Exports project contents to text files where possible.')
        saveBox = Row([
            saveButton.padX(10.0),
            Spacer(30.0, 0.0),
            saveAsButton.padX(10.0),
            Spacer(30.0, 0.0),
            reloadButton.padX(10.0),
            Spacer(50.0, 0.0),
            exportButton.padX(10.0)
        ]).alignHLeft()
        saveExportSection = Section(saveExportHeader, saveBox)

        #
        # Project Section
        #

        # Python package name
        notSet = _pythonPackageNameNotSetStyle.applyTo(Label('<not set>'))
        pythonPackageNameLabel = EditableLabel(
            project.pythonPackageName, notSet,
            _PythonPackageNameListener()).regexValidated(
                _pythonPackageNameRegex,
                'Please enter a valid dotted identifier')
        pythonPackageNameLabel = AttachTooltip( pythonPackageNameLabel, 'The root python package name is the name under which the contents of the project can be imported using import statements within the project.\n' + \
         'If this is not set, pages from this project cannot be imported.', False )
        pythonPackageNameRow = Form.Section(
            'Root Python package name',
            'Pages will not be importable unless this is set',
            pythonPackageNameLabel)

        # Clear imported modules
        def _onReset(button, event):
            project.reset()
            modules = document.unloadAllImportedModules()
            heading = SectionHeading2('Unloaded modules:')
            modules = Column([Label(module) for module in modules])
            report = Section(heading, modules)
            BubblePopup.popupInBubbleAdjacentTo(report, button.getElement(),
                                                Anchor.BOTTOM, True, True)

        resetButton = Button.buttonWithLabel('Reset', _onReset)
        resetButton = AttachTooltip(
            resetButton,
            'Unloads all modules that were imported from this project from the Python module cache. This way they can be re-imported, allowing modifications to take effect.'
        )
        resetRow = Form.Section('Reset', 'Unload project modules', resetButton)

        projectSection = Form('Project', [pythonPackageNameRow, resetRow])

        # Project index
        indexHeader = SectionHeading1('Index')

        nameElement = _projectIndexNameStyle.applyTo(Label('Project root'))
        nameBox = _itemHoverHighlightStyle.applyTo(nameElement.alignVCentre())
        nameBox = nameBox.withContextMenuInteractor(
            _projectIndexContextMenuFactory)
        nameBox = _ProjectTreeController.instance.item(project, nameBox)
        nameBox = AttachTooltip( nameBox, 'Right click to access context menu, from which new pages and packages can be created.\n' + \
         'A page called index at the root will appear instead of the project page. A page called __startup__ will be executed at start time.', False )

        itemsBox = Column(project[:]).alignHExpand()
        itemsBox = _ProjectTreeController.instance.editableList(
            project, itemsBox)

        contentsView = Column([
            nameBox.alignHExpand(),
            itemsBox.padX(_packageContentsIndentation, 0.0).alignHExpand()
        ])

        indexSection = Section(indexHeader, contentsView)

        def _onBuildJar(button, event):
            _buildProjectJar(button.element, document)

        buildJarButton = Button.buttonWithLabel('Build JAR', _onBuildJar)
        jarRow = Form.Section('Build executable app',
                              'Export the project as an executable JAR',
                              buildJarButton)

        packagingSection = Form('Packaging', [jarRow])

        indexTip = TipBox([
            NormalText([
                StrongSpan('Index: '),
                'Larch projects act like Python programs. Packages act as directories/packages and pages act as Python source files. Pages can import code from one another as if they are modules.'
            ]),
            NormalText([
                'New pages and packages can be created by right clicking on the entries in the index or on ',
                EmphSpan('Project root'),
                ' (they will highlight as you hover over them).'
            ]),
            NormalText([
                StrongSpan('Front and startup pages: '),
                'If a page is set as the front page it will appear instead of the project page. In these cases, the project page can still be reached using the links in the location bar at the top of the window.'
            ]),
            'If a page is set as the startup page, code within it will be executed before all other pages. This can be used for registering editor extensions.',
            'To set a page as the front page or the startup page, right-click on it to show its context menu and choose the appropriate option.'
        ], 'larchcore.worksheet.worksheeteditor')

        # The page
        head = Head([title])
        body = Body([
            saveExportSection, projectSection, indexSection, packagingSection,
            indexTip
        ]).alignHPack()

        return StyleSheet.style(Primitive.editable(False)).applyTo(
            Page([head, body]))
Exemplo n.º 13
0
	def pathsSection(self, title, pathList):
		pathsPres = self.presentPathList( pathList )
		return Section( SectionHeading2( title ), pathsPres )
def _createTree():
    heading = SectionHeading1('Tree')
    return Section(heading, Blank())
Exemplo n.º 15
0
def _documentContextMenuFactory(element, menu):
	region = element.getRegion()
	rootElement = element.getRootElement()
	
	def makeParagraphStyleFn(style):
		def setStyle(model):
			model.setStyle(style)
		
		def _onLink(link, event):
			caret = rootElement.getCaret()
			if caret is not None and caret.isValid():
				caretElement = caret.getElement()
				if caretElement.getRegion() is region:
					_controller.modifyParagraphAtMarker(caret.getMarker(), setStyle)
		return _onLink
	
	def insertEmbedPara(link, event):
		def _newEmbedPara():
			img = _imageFileChooser(link.element, lambda f: _ParaImage(f))
			return embed.ParaEmbed(img)   if img is not None   else None
		
		caret = rootElement.getCaret()
		if caret is not None and caret.isValid():
			caretElement = caret.getElement()
			if caretElement.getRegion() is region:
				_controller.insertParagraphAtCaret(caret, _newEmbedPara)
	
	normalStyle = Hyperlink('Normal', makeParagraphStyleFn('normal'))
	h1Style = Hyperlink('H1', makeParagraphStyleFn('h1'))
	h2Style = Hyperlink('H2', makeParagraphStyleFn('h2'))
	h3Style = Hyperlink('H3', makeParagraphStyleFn('h3'))
	h4Style = Hyperlink('H4', makeParagraphStyleFn('h4'))
	h5Style = Hyperlink('H5', makeParagraphStyleFn('h5'))
	h6Style = Hyperlink('H6', makeParagraphStyleFn('h6'))
	titleStyle = Hyperlink('Title', makeParagraphStyleFn('title'))
	paraStyles = ControlsRow([normalStyle, h1Style, h2Style, h3Style, h4Style, h5Style, h6Style, titleStyle])
	embedPara = Hyperlink('Embed para', insertEmbedPara)
	paraEmbeds = ControlsRow([embedPara])
	menu.add(Section(SectionHeading2('Paragraph styles'), paraStyles))
	menu.add(Section(SectionHeading2('Paragraph embeds'), paraEmbeds))
	
	
	def makeStyleFn(attrName):
		def computeStyleValues(listOfSpanAttrs):
			value = listOfSpanAttrs[0].getValue(attrName, 0)
			value = not value
			attrs = RichTextAttributes()
			attrs.putOverride(attrName, value)
			return attrs
		
		def onButton(button, event):
			selection = rootElement.getSelection()
			if isinstance(selection, TextSelection):
				if selection.getRegion() == region:
					_controller.applyStyleToSelection(selection, computeStyleValues)
		return onButton
	
	def _onInsertInlineEmbed(button, event):
		def _newInlineEmbedValue():
			return _imageFileChooser(button.element, lambda f: _InlineImage(f))
		
		caret = rootElement.getCaret()
		if caret is not None and caret.isValid():
			caretElement = caret.getElement()
			if caretElement.getRegion() is region:
				_controller.insertInlineEmbedAtMarker(caret.getMarker(), _newInlineEmbedValue)
	
	def style_button(text, on_click, *style_values):
		sty = StyleSheet.instance.withValues(Primitive.fontFace(Primitive.monospacedFontName),
						     *style_values)
		return Button(sty.applyTo(Label(text)), on_click)

	italicStyle = style_button('I', makeStyleFn('i'), Primitive.fontItalic(True))
	boldStyle = style_button('B', makeStyleFn('b'), Primitive.fontBold(True))
	codeStyle = style_button('code', makeStyleFn('code'))
	cmdStyle = style_button('> cmd', makeStyleFn('cmd'))
	appStyle = style_button('app', makeStyleFn('app'))
	sysStyle = style_button('sys', makeStyleFn('sys'))
	styles = ControlsRow([italicStyle, boldStyle, codeStyle, cmdStyle, appStyle, sysStyle]).alignHLeft()
	insertInlineEmbed = Button.buttonWithLabel('Embed', _onInsertInlineEmbed)
	inlineEmbeds = ControlsRow([insertInlineEmbed]).alignHLeft()
	
	menu.add(Section(SectionHeading2('Selection styles'), styles))
	menu.add(Section(SectionHeading2('Inline embeds'), inlineEmbeds))
	
	
	return True
def registerPaletteSection(title, items):
    sec = Section(SectionHeading2(title), FlowGrid(4, items))
    _paletteSections.append(sec)