def _createSettingsPres(self):
        def _listener(attrName):
            class _Listener(TextEntry.TextEntryListener):
                def onTextChanged(listener, textEntry):
                    if textEntry.isDisplayedTextValid():
                        setattr(self, attrName,
                                int(textEntry.getDisplayedText()))
                        self._incr.onChanged()

            return _Listener()

        min = [
            Label('Min'),
            TextEntry(str(self._min), _listener('_min')).regexValidated(
                Tokens.decimalIntegerPattern, 'Please enter an integer value')
        ]
        max = [
            Label('Max'),
            TextEntry(str(self._max), _listener('_max')).regexValidated(
                Tokens.decimalIntegerPattern, 'Please enter an integer value')
        ]
        step = [
            Label('Step'),
            TextEntry(str(self._step), _listener('_step')).regexValidated(
                Tokens.decimalIntegerPattern, 'Please enter an integer value')
        ]
        page = [
            Label('Page'),
            TextEntry(str(self._page), _listener('_page')).regexValidated(
                Tokens.decimalIntegerPattern, 'Please enter an integer value')
        ]
        return Table([min, max, step, page])
Beispiel #2
0
 def __pair(self, kv):
     key, value = kv
     eq = self._punc_style.applyTo(Label('='))
     return Span([
         self._name_style(Label(key)), eq,
         self._value_style(Label(value))
     ])
 def __present__(self, fragment, inheritedState):
     self._incr.onAccess()
     open_tag = self._tag_border.surround(
         self._open_tag_style(Label(self._elem_tag_and_attrs.tag)))
     close_tag = self._tag_border.surround(
         self._close_tag_style(Label('/' + self._elem_tag_and_attrs.tag)))
     x = RichSpan([open_tag] + list(self.contents_query) + [close_tag])
     x = controller.MallardRichTextController.instance.editableSpan(self, x)
     return x
Beispiel #4
0
    def __present_contents__(self, fragment, inheritedState):
        def _onApply(button, event):
            self._config = self._userConfig.getStaticValue()
            self.apply()

        def _onRevert(button, event):
            self._userConfig.setLiteralValue(self._config)

        choices = [Label(c[1]) for c in _fontConfigChoices]
        choices.append(Label('Custom'))

        @LiveFunction
        def indexOfChoice():
            config = self._userConfig.getValue()
            if isinstance(config, FontConfiguration):
                return len(choices) - 1
            else:
                try:
                    return [c[0] for c in _fontConfigChoices
                            ].index(self._userConfig.getValue())
                except ValueError:
                    return 0

        @LiveFunction
        def footer():
            config = self._userConfig.getValue()
            if isinstance(config, FontConfiguration):
                return config
            else:
                return Blank()

        def _onChoice(menu, prevChoice, choice):
            if choice == len(choices) - 1:
                # Custom
                if prevChoice != choice:
                    prevConfig = _fontConfigChoices[prevChoice][0]
                    prevConfig = _fontConfigForName(prevConfig)
                    config = FontConfiguration()
                    config.copyFrom(prevConfig)
                    self._userConfig.setLiteralValue(config)
            else:
                self._userConfig.setLiteralValue(_fontConfigChoices[choice][0])

        applyButton = Button.buttonWithLabel('Apply', _onApply)
        revertButton = Button.buttonWithLabel('Revert', _onRevert)
        buttons = Row([applyButton,
                       Spacer(15.0, 0.0), revertButton]).alignHPack()

        configMenu = OptionMenu(choices, indexOfChoice, _onChoice)

        chooserHeader = Row([
            Label('Choose a font configuration:'),
            Spacer(25.0, 0.0), configMenu
        ]).alignHPack()

        return self._pageColumnStyle(Column([buttons, chooserHeader, footer]))
Beispiel #5
0
 def __present__(self, fragment, inheritedState):
     title = Label('Code stepper')
     header = _headerStyle(
         Row([
             title.alignVCentre().alignHPack(),
             Pres.coerce(self._stepButton).alignHPack(),
             Pres.coerce(self._runButton).alignHPack()
         ])).alignHExpand()
     main = Column([header, Pres.coerce(self._code).alignHExpand()])
     return _stepperBorder.surround(main).withCommands(_stepperCommands)
    def __present__(self, fragment, inheritedState):
        self._incr.onAccess()
        exprPres = self._expr

        header = Row([
            self._angleQuoteStyle(Label(u'\u00ab')),
            self._angleQuoteStyle(Label(u'\u00bb')),
            Spacer(9.0, 0.0)
        ]).withDragSource(_dragSource)

        return ObjectBorder(Row([header.alignVCentre(), exprPres]))
Beispiel #7
0
def enumSwitchButtonEditorWithLabels(live, enumType, labelTexts):
	return enumSwitchButtonEditor(live, enumType, [Label(t)   for t in labelTexts])
	@LiveFunction
	def displayLive():
		return live.getValue().ordinal()

	def _onChoice(control, prevChoice, choice):
		live.setLiteralValue(enumType.values()[choice])

	options = [Label(t)   for t in ['Larger', 'Smaller', 'Fixed', 'None']]

	return SwitchButton(options, options, SwitchButton.Orientation.HORIZONTAL, displayLive, _onChoice)
	def __present__(self, fragment, inheritedState):
		self._incr.onAccess()

		def _setName(editableLabel, text):
			self._name = text
			self._incr.onChanged()


		namePres = EditableLabel( self._name, self._nameNotSetStyle( Label( '<not set>' ) ), _setName ).regexValidated( Pattern.compile( '[a-zA-Z_][a-zA-Z0-9_]*' ), 'Please enter a valid identifier' )

		exprPres = self._expr

		contents = Row( [ namePres, Label( ': ' ), exprPres ] )
		return ObjectBox( 'Monitored exp.', contents )
Beispiel #9
0
 def _presentLeafContents(self, fragment, inheritedState):
     displayedText = self.displayedText.value
     if displayedText != '':
         return _liveEvalLabelStyle.applyTo(
             Label('=<' + displayedText + '>...'))
     else:
         return self.expr.editUI()
Beispiel #10
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)
 def __present__(self, fragment, inheritedState):
     self._listeners = PresentationStateListenerList.addListener(
         self._listeners, fragment)
     name = Label(self._name)
     kind = _objectKindMap[self._kind]
     contents = Column([name, Spacer(0.0, 2.0), kind.padX(10.0, 0.0)])
     return _fragSelectorEntryBorder.surround(
         contents).withElementInteractor(self._interactor)
 def _presentConfig(self):
     if self._config is not None:
         rows = []
         rows.append([SectionHeading3('Tool'), SectionHeading3('Path')])
         rows.append(
             [self._toolLabel('dot'),
              Label(self._config.getDotPath())])
         rows.append(
             [self._toolLabel('neato'),
              Label(self._config.getNeatoPath())])
         rows.append(
             [self._toolLabel('twopi'),
              Label(self._config.getTwopiPath())])
         rows.append(
             [self._toolLabel('circo'),
              Label(self._config.getCircoPath())])
         rows.append(
             [self._toolLabel('fdp'),
              Label(self._config.getFdpPath())])
         rows.append(
             [self._toolLabel('sfdp'),
              Label(self._config.getSfdpPath())])
         rows.append(
             [self._toolLabel('osage'),
              Label(self._config.getOsagePath())])
         return self._configTableStyle.applyTo(Table(rows)).pad(15.0, 5.0)
def _vAlignmentEditor(live):
    @LiveFunction
    def displayLive():
        x = live.getValue()
        if x is None:
            return 0
        else:
            return x.ordinal() + 1

    options = [
        _noAlignmentStyle(Label('None')),
        Label('Ref-Y'),
        Label('Ref-Y Exp'),
        Label('Top'),
        Label('Centre'),
        Label('Bottom'),
        Label('Expand')
    ]

    def _onChoice(control, prevChoice, choice):
        if choice == 0:
            live.setLiteralValue(None)
        else:
            live.setLiteralValue(VAlignment.values()[choice - 1])

    return SwitchButton(options, options, SwitchButton.Orientation.HORIZONTAL,
                        displayLive, _onChoice)
    def __present__(self, fragment, inheritedState):
        def _literateExpressionMenu(element, menu):
            def _onToggleExpanded(item):
                self.setExpanded(not self._expanded)

            menuItemName = 'Start as contracted' if self._expanded else 'Start as expanded'
            menu.add(
                MenuItem.menuItemWithLabel(menuItemName, _onToggleExpanded))

            return False

        self._incr.onAccess()
        self._definition._incr.onAccess()
        suitePres = self._definition._suite

        nameLabel = self._nameStyle(Label(self._definition._name))
        liveName = LiveValue(nameLabel)

        class _NameEntryListener(TextEntry.TextEntryListener):
            def onAccept(listener, textEntry, text):
                self.setName(text)

            def onCancel(listener, textEntry, orignalText):
                liveName.setLiteralValue(nameLabel)

        def _onNameButton(button, event):
            nameEntry = TextEntry(self._definition._name, _NameEntryListener())
            nameEntry.grabCaretOnRealise()
            nameEntry = self._nameStyle(nameEntry)
            liveName.setLiteralValue(nameEntry)

        renameButton = self._nameButtonStyle(
            Button.buttonWithLabel('...', _onNameButton))

        header = Row([
            self._angleQuoteStyle(Label(u'\u00ab')), liveName,
            self._angleQuoteStyle(Label(u'\u00bb')),
            Spacer(10.0, 0.0), renameButton
        ]).withDragSource(_dragSource)

        dropDown = self._dropDownStyle(
            DropDownExpander(header, suitePres, self._expanded, None))

        return ObjectBorder(dropDown).withContextMenuInteractor(
            _literateExpressionMenu)
Beispiel #15
0
def _fontSample(fontName, sampleFn):
    sample = sampleFn(fontName)
    name = Label(fontName)
    return _hoverStyle(
        Bin(
            Column([
                sample,
                _nameStyle(name).padX(10.0, 0.0),
            ]).pad(5.0, 5.0)))
	def editUI(self, setPaddingFn):
		box = _boxStyle(Bin(Label('Padded element'))).alignHExpand().alignVExpand()

		left = self.left.editUI(lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0))
		right = self.right.editUI(lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0))
		top = self.top.editUI(lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0))
		bottom = self.bottom.editUI(lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0))

		return _tableStyle(Table([[None, top, None], [left, box, right], [None, bottom, None]]))
	def __present__(self, fragment, inheritedState):
		def _embeddedDisplayMenu(element, menu):
			def _onClear(item):
				self._clear()

			menu.add( MenuItem.menuItemWithLabel( 'Clear collected values', _onClear ) )

			return False



		self._incr.onAccess()
		suitePres = self._suite

		valuesPres = TabbedBox( [ [ Label( 'Tree' ), self._treeView ],  [ Label( 'Table' ), self._tableView ] ], None )

		contents = Column( [ suitePres, valuesPres ] )
		return ObjectBox( 'Trace visualisation', contents ).withContextMenuInteractor( _embeddedDisplayMenu ).withCommands( _mxCommands )
Beispiel #18
0
		def pathItem(index):
			def _onDelete(menuItem):
				del pathList[index]
				self._incr.onChanged()

			def buildContextMenu(element, menu):
				menu.add( MenuItem.menuItemWithLabel( 'Delete', _onDelete ) )
				return True

			return _itemHoverHighlightStyle.applyTo( Label( pathList[index] ) ).withContextMenuInteractor( buildContextMenu )
Beispiel #19
0
    def __present__(self, fragment, inh):
        space = Label(' ')
        br = LineBreak()

        items = self.__attrs.items()

        contents = [self.__pair(items[0])]
        for x in items[1:]:
            contents.extend([space, br, self.__pair(x)])
        return Span(contents)
Beispiel #20
0
    def __present__(self, fragment, inh):
        space = Label(' ')
        open_angle = self._punc_style.applyTo(Label('<'))
        close_angle = self._punc_style.applyTo(Label('>'))
        slash = self._punc_style.applyTo(Label('/'))
        tag = self._tag_style.applyTo(Label(self.__tag))
        br = LineBreak()

        complex = False
        for x in self.__contents:
            if isinstance(x, XmlElem):
                complex = True
                break

        if complex:
            end = Row([open_angle, slash, tag, close_angle])
            content = Column(
                [NormalText([x]) for x in self.__contents if x != ''])
            if len(self.__attrs) == 0:
                start = Row([open_angle, tag, close_angle])
            else:
                start = Paragraph(
                    [open_angle, tag, space, br, self.__attrs, close_angle])
            return Column([start, content.padX(20.0, 0.0), end])
        else:
            if len(self.__contents) == 0:
                if len(self.__attrs) == 0:
                    return Row([open_angle, tag, slash, close_angle])
                else:
                    return Paragraph([
                        open_angle, tag, space, br, self.__attrs, slash,
                        close_angle
                    ])
            else:
                end = Row([open_angle, slash, tag, close_angle])
                content = [RichSpan([x]) for x in self.__contents]
                if len(self.__attrs) == 0:
                    start = Row([open_angle, tag, close_angle])
                else:
                    start = Span([
                        open_angle, tag, space, br, self.__attrs, close_angle
                    ])
                return Paragraph([start] + content + [end])
def _loadFontsFromJar():
    gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment()

    for fontName in _jarFontNames:
        stream = Label.getResourceAsStream('/' + fontName)
        if stream is None:
            print 'Warning: could not load font {0} from JAR'.format(fontName)
        else:
            font = Font.createFont(Font.TRUETYPE_FONT, stream)
            gEnv.registerFont(font)
Beispiel #22
0
	def __present__(self, fragment, inheritedState):
		self._incr.onAccess()

		title = SectionHeading2( 'Unit tests' )

		nameEntry = _nameBorder.surround( EditableLabel( self._name, _notSet ).regexValidated( Tokens.identifierPattern, 'Please enter a valid identifier' ) )

		header = Row( [ title, Spacer( 25.0, 0.0 ), nameEntry ] )

		contents = [ header.padY( 0.0, 5.0 ), _standardCodeBorder.surround( self._suite ).padY( 3.0 ).alignHExpand() ]

		if self.__passes is not None  and  self.__failures is not None:
			resultsTitle = SectionHeading3( 'Test results:' )
			passes = _standardPassStyle( Label( '%d / %d test(s) passed' % ( self.__passes, self.__passes + len( self.__failures ) ) ) )
			failuresLabel = _standardFailStyle( Label( '%d test(s) failed:' % len( self.__failures ) ) )
			failures = [ Column( [ _standardFailedTestStyle( Label( name ) ), Pres.coerce( exception ).padX( 5.0, 0.0 ) ] ).padX( 5.0, 0.0 )   for name, exception in self.__failures ]
			results = _standardResultsBorder.surround( Column( [ resultsTitle, passes, failuresLabel ] + failures ) ).pad( 3.0, 3.0 )
			contents.append( results )


		return _standardInlineTestBorder.surround( Column( contents ) )
Beispiel #23
0
 def __present__(self, fragment, inheritedState):
     current = self._isCurrent.getValue()
     label = _breakPointStyle(Label('BREAKPOINT'))
     if current:
         return _breakPointCurrentBorder.surround(
             Row([_breakPointArrow,
                  Spacer(
                      3.0,
                      0.0,
                  ), label]).alignVCentre())
     else:
         return _breakPointBorder.surround(label)
	def expected(self):
		expected = self._expected.getValue()
		if expected is not None:
			expectedKind, expectedData = expected
			if expectedKind == 'exception':
				return Label( 'Exception of type %s' % expectedData.__name__ )
			elif expectedKind == 'value':
				return expectedData
			else:
				raise TypeError, 'unknown expected result kind %s' % expectedKind
		else:
			return Blank()
Beispiel #25
0
def _collapsibleFontChooser(title, choiceValue, sampleFn):
    expanded = LiveValue(False)

    @LiveFunction
    def currentChoice():
        return _headerNameStyle(Label(choiceValue.getValue()))

    header = Row([Label(title), Spacer(25.0, 0.0), currentChoice]).alignHPack()

    return DropDownExpander(
        header,
        ScrolledViewport(_fontChooser(choiceValue, sampleFn), 800.0, 400.0,
                         None), expanded).alignHExpand()
    def __present__(self, fragment, inheritedState):
        def _explorerPres():
            return Pres.coerce(self._explorer)

        explorer = LazyPres(_explorerPres)

        def _log():
            l = self._fragment.view.log
            l.startRecording()
            return Pres.coerce(LogView(l))

        log = LazyPres(_log)

        tabs = [[Label('Console'),
                 _consoleStyle(self._console).alignVTop()],
                [Label('Element explorer'), explorer],
                [Label('Page log'), log],
                [
                    Label('Event errors'),
                    self._fragment.view.presentationRootElement.eventErrorLog
                ]]
        return TabbedBox(tabs, None).alignVTop()
Beispiel #27
0
def _presentComponentsUnderPointer(elementUnderPointer, guiEditorRootElement):
	propValues = elementUnderPointer.gatherPropertyInAncestryTo(GUICProp.instance, guiEditorRootElement)

	# Components under pointer
	components = []
	for p in propValues:
		component = p.value
		if not component.isRootGUIEditorComponent:
			interactor = ComponentHighlightInteractor(p.value, p.element)
			c = componentUnderPointerBorder.surround(Label(component.componentName).pad(4.0, 2.0)).alignHExpand()
			c = c.withElementInteractor(interactor)
			components.append(c)
	return FlowGrid(3, components)
    def _presentDir(self):
        def _onSet(hyperlink, event):
            component = hyperlink.getElement().getRootElement().getComponent()
            openDialog = JFileChooser()
            openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
            response = openDialog.showDialog(component, 'Choose path')
            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):
                        self._graphVizDir = filename
                        self._refreshConfig()
                        self._incr.onChanged()

        dirLabel = Label(
            self._graphVizDir
        ) if self._graphVizDir is not None else self._notSetStyle.applyTo(
            Label('<Not set>'))

        setLink = Hyperlink('CHANGE', _onSet)
        return self._dirBorderStyle.applyTo(
            Border(Row([dirLabel, Spacer(25.0, 0.0), setLink])))
Beispiel #29
0
	def editor():
		x = live.getValue()

		if x is None:
			def on_add(button, event):
				live.setLiteralValue(initialValue)
			return Button(_plusStyle(Label('+')), on_add).alignHPack()
		else:
			def on_delete(button, event):
				live.setLiteralValue(None)

			deleteButton = Button(Image.systemIcon('delete'), on_delete)

			return Row([deleteButton.alignHPack(), Spacer(5.0, 0.0).alignHPack(), valueEditor])
Beispiel #30
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])