예제 #1
0
 def _editUIFormSections(self):
     expr = Form.SmallSection('Expression', None, self.expr.editUI())
     displayedText = Form.SmallSection(
         'Displayed text', None,
         TextEntry.textEntryCommitOnChange(self.displayedText.live))
     superSections = super(GUIEval, self)._editUIFormSections()
     return [expr, displayedText] + superSections
예제 #2
0
 def _editUIFormSections(self):
     direction = Form.SmallSection(
         'Direction', None,
         self.direction.editUI(self._arrowDirectionEditor))
     size = Form.SmallSection(
         'Size', None,
         self.size.editUI(
             lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
     superSections = super(GUIArrow, self)._editUIFormSections()
     return [direction, size] + superSections
예제 #3
0
 def _editUIFormSections(self):
     width = Form.SmallSection(
         'Width', None,
         self.width.editUI(
             lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
     height = Form.SmallSection(
         'Height', None,
         self.height.editUI(
             lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
     superSections = super(GUISpacer, self)._editUIFormSections()
     return [width, height] + superSections
	def _editUIFormSections(self):
		sections = []
		sections.extend( unaryBranchChildEditUIFormSections(self) )
		sections.append(Form.SmallSection('On click', None, exprBorder.surround( self.onClick.editUI() )))

		superSections = super(GUIButton, self)._editUIFormSections()
		return sections + superSections
예제 #5
0
 def _editUIFormSections(self):
     text = Form.SmallSection(
         'Text', None,
         self.text.editUI(
             lambda live: TextEntry.textEntryCommitOnChange(live)))
     superSections = super(GUIText, self)._editUIFormSections()
     return [text] + superSections
예제 #6
0
def unaryBranchChildEditUIFormSections(branch):
	child = branch.child.node
	if child is not None:
		if isinstance(child, GUIEditor.PrimitiveComponents.GUILabel):
			textField = child.text
			if textField.isConstant():
				textLive = textField.constantValueLive
				return [Form.SmallSection('Label text', None, TextEntry.textEntryCommitOnChange(textLive))]
	return []
예제 #7
0
 def _editUIFormSections(self):
     width = Form.SmallSection(
         'Width', None,
         self.width.editUI(
             lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
     height = Form.SmallSection(
         'Height', None,
         self.height.editUI(
             lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
     sizeConstraintX = Form.SmallSection(
         'Constraint-X', None,
         self.sizeConstraintX.editUI(_sizeConstraintEditor))
     sizeConstraintY = Form.SmallSection(
         'Constraint-Y', None,
         self.sizeConstraintY.editUI(_sizeConstraintEditor))
     superSections = super(GUISpaceBin, self)._editUIFormSections()
     return [width, height, sizeConstraintX, sizeConstraintY
             ] + superSections
    def _editUIFormSections(self):
        hAlign = Form.SmallSection('H alignment', None,
                                   self.hAlignment.editUI(_hAlignmentEditor))
        vAlign = Form.SmallSection('V alignment', None,
                                   self.vAlignment.editUI(_vAlignmentEditor))

        @LiveFunction
        def paddingUI():
            padding = self.padding.value

            if padding is None:

                def onPadUniform(button, event):
                    self.padding.value = UniformPadding()

                def onPadNonUniform(button, event):
                    self.padding.value = NonUniformPadding()

                return ControlsRow([
                    Button.buttonWithLabel('Uniform', onPadUniform),
                    Button.buttonWithLabel('Non-uniform', onPadNonUniform)
                ]).alignHPack()
            else:

                def onRemove(button, event):
                    self.padding.value = None

                def setPadding(padding):
                    self.padding.value = padding

                removeButton = Button.buttonWithLabel('Remove padding',
                                                      onRemove).alignHPack()

                return Column([
                    removeButton.alignHPack(),
                    Spacer(0.0, 5.0),
                    padding.editUI(setPadding)
                ])

        padding = Form.SmallSection('Padding', None, paddingUI)

        return [hAlign, vAlign, padding]
 def formSections(self):
     return [
         Form.SmallSection(
             'Thickness', None,
             self.thickness.editUI(lambda live: RealSpinEntry(
                 live, 0.0, 10240.0, 0.1, 10.0))),
         Form.SmallSection(
             'Inset', None,
             self.inset.editUI(lambda live: RealSpinEntry(
                 live, 0.0, 10240.0, 0.1, 10.0))),
         Form.SmallSection(
             'Round-X', None,
             self.roundingX.editUI(lambda live: RealSpinEntry(
                 live, 0.0, 10240.0, 0.1, 10.0))),
         Form.SmallSection(
             'Round-Y', None,
             self.roundingY.editUI(lambda live: RealSpinEntry(
                 live, 0.0, 10240.0, 0.1, 10.0))),
         Form.SmallSection(
             'Border colour', None,
             self.borderPaint.editUI(
                 lambda live: ColourPicker(live).alignHPack())),
         Form.SmallSection(
             'Background colour', None,
             self.backgroundPaint.editUI(lambda live: optionalTypedEditor(
                 live, Color.WHITE, lambda live: ColourPicker(live).
                 alignHPack()))),
         Form.SmallSection(
             'Hover border colour', None,
             self.highlightBorderPaint.editUI(
                 lambda live: optionalTypedEditor(
                     live, Color.BLACK, lambda live: ColourPicker(live).
                     alignHPack()))),
         Form.SmallSection(
             'Hover background colour', None,
             self.highlightBackgroundPaint.editUI(
                 lambda live: optionalTypedEditor(
                     live, Color.WHITE, lambda live: ColourPicker(live).
                     alignHPack()))),
     ]
예제 #10
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]))
 def _editUIForm(self):
     sections = self._editUIFormSections()
     if len(sections) > 0:
         return Form(None, sections)
     else:
         return Blank()