Пример #1
0
 def __init__(self,
              generic=Primitive.genericFontName,
              normal=Primitive.normalTextFontName,
              heading=Primitive.headingFontName,
              title=Primitive.titleFontName,
              uiHeading=Primitive.lightFontName):
     self._generic = LiveValue(generic)
     self._normal = LiveValue(normal)
     self._heading = LiveValue(heading)
     self._title = LiveValue(title)
     self._uiHeading = LiveValue(uiHeading)
	def __setstate__(self, state):
		self.__change_history__ = None
		self.__testTable = None
		self.__result = LiveValue( _resultNone )
		self.__testMethodName = None
		self._expected = TrackedLiveValue( state['expected'] )
		self._actual = TrackedLiveValue( None )
def currentComponentEditor(rootElement):
	# Components under pointer
	target = rootElement.getTarget()
	target = target   if target.isValid()  and  isinstance(target, GUIEditorTarget)   else None

	currentComponent = LiveValue()

	# Component UI
	def refreshComponent(component):
		currentComponent.setLiteralValue(component)

	targetListener = GUITargetListener(refreshComponent)

	refreshComponent(target.component   if target is not None   else None)


	@LiveFunction
	def currentComponentUI():
		component = currentComponent.getValue()
		if component is not None:
			editUI = component._editUI()
			return Section(SectionHeading3(component.componentName), editUI)
		else:
			return Blank()


	componentUI = targetListener.tieToLifeTimeOf(currentComponentUI, rootElement)
	return componentUI
	def __init__(self):
		self.__testTable = None
		self.__result = LiveValue( _resultNone )
		self.__testMethodName = None
		# Form: either ( 'value', value )  or  ( 'exception', exceptionType )  or  None
		self._expected = TrackedLiveValue( None )
		self._actual = TrackedLiveValue( None )

		self.__change_history__ = None
Пример #5
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 _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)
Пример #7
0
def optionalTypedEditor(live, initialValue, editorFn):
	valueEditor = LiveValue(editorFn(live))

	@LiveFunction
	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])

	return editor
Пример #8
0
 def __setstate__(self, state):
     super(FontConfigurationPage, self).__setstate__(state)
     self._config = state.get('config')
     self._userConfig = LiveValue(self._config)
Пример #9
0
 def __setstate__(self, state):
     self._generic = LiveValue(state.get('generic', 'SansSerif'))
     self._normal = LiveValue(state.get('normal', 'SansSerif'))
     self._heading = LiveValue(state.get('heading', 'Serif'))
     self._title = LiveValue(state.get('title', 'Serif'))
     self._uiHeading = LiveValue(state.get('uiHeading', 'SansSerif'))
Пример #10
0
 def __init__(self):
     super(FontConfigurationPage, self).__init__()
     self._config = None
     self._userConfig = LiveValue(self._config)
Пример #11
0
    def Page(self, fragment, inheritedState, page):
        root = page.rootNode
        if root is None:
            raise RuntimeError, 'No root node'
        isFrontPage = root.frontPage is page
        isStartupPage = root.startupPage is page

        class _RenameListener(TextEntry.TextEntryListener):
            def onAccept(self, textEntry, text):
                page.name = text

            def onCancel(self, textEntry, originalText):
                nameLive.setLiteralValue(nameBox)

        def _onRename(menuItem):
            textEntry = TextEntry(page.name, _RenameListener()).regexValidated(
                _nameRegex, 'Please enter a valid identifier')
            textEntry.grabCaretOnRealise()
            nameLive.setLiteralValue(textEntry)

        def _onDelete(menuItem):
            if page.parent is not None:
                page.parent.remove(page)

        def _onClearFrontPage(menuItem):
            root.frontPage = None

        def _onSetAsFrontPage(menuItem):
            root.frontPage = page

        def _onClearStartupPage(menuItem):
            root.startupPage = None

        def _onSetAsStartupPage(menuItem):
            root.startupPage = page

        def _pageContextMenuFactory(element, menu):
            menu.add(MenuItem.menuItemWithLabel('Rename', _onRename))
            menu.add(HSeparator())
            menu.add(MenuItem.menuItemWithLabel('Delete', _onDelete))
            menu.add(HSeparator())

            if isFrontPage:
                menu.add(
                    MenuItem.menuItemWithLabel('Clear front page',
                                               _onClearFrontPage))
            else:
                menu.add(
                    MenuItem.menuItemWithLabel('Set as front page',
                                               _onSetAsFrontPage))

            if isStartupPage:
                menu.add(
                    MenuItem.menuItemWithLabel('Clear startup page',
                                               _onClearStartupPage))
            else:
                menu.add(
                    MenuItem.menuItemWithLabel('Set as startup page',
                                               _onSetAsStartupPage))

            return True

        pageSubject = fragment.subject._pageSubject(page)

        link = Hyperlink(page.name, pageSubject)
        link = link.withContextMenuInteractor(_pageContextMenuFactory)
        nameBox = _itemHoverHighlightStyle.applyTo(Row([link]))
        nameBox = _ProjectTreeController.instance.item(page, nameBox)
        nameBox = nameBox.withDragSource(_linkDragSource)
        nameBox = AttachTooltip(
            nameBox,
            'Click to enter page.\nRight click to access context menu.', False)

        nameLive = LiveValue(nameBox)

        if isFrontPage or isStartupPage:
            notes = []
            if isFrontPage:
                notes.append(
                    _frontPageNoteBorder.surround(
                        _frontPageNoteStyle.applyTo(Label('Front page'))))
            if isStartupPage:
                notes.append(
                    _startupPageNoteBorder.surround(
                        _startupPageNoteStyle.applyTo(Label('Startup page'))))
            notesPres = _notesRowStyle.applyTo(Row(notes))
            pagePres = Row([nameLive, notesPres.padX(_notesGap, 0.0)])
        else:
            pagePres = nameLive

        return pagePres
Пример #12
0
	def __present__(self, fragment, inheritedState):
		blocks = self.getBlocks()
		currentModule = Python2.python2EditorPerspective.applyTo( self.getCurrentPythonModule() )

		def _onDrop(element, pos, data, action):
			class _VarNameEntryListener (TextEntry.TextEntryListener):
				def onAccept(listenerSelf, entry, text):
					self.assignVariable( text, data.getModel() )
					_finish( entry )

				def onCancel(listenerSelf, entry, text):
					_finish( entry )

			def _finish(entry):
				caret.moveTo( marker )
				dropPromptLive.setLiteralValue( Blank() )

			dropPrompt = _dropPrompt( _VarNameEntryListener() )
			rootElement = element.getRootElement()
			caret = rootElement.getCaret()
			marker = caret.getMarker().copy()
			dropPromptLive.setLiteralValue( dropPrompt )
			rootElement.grabFocus()

			return True



		# Header
		if self._showBanner:
			bannerVersionText = [ _bannerTextStyle.applyTo( NormalText( v ) )   for v in sys.version.split( '\n' ) ]
			helpText1 = Row( [ _bannerHelpKeyTextStyle.applyTo( Label( 'Ctrl+Enter' ) ),
					   _bannerHelpTextStyle.applyTo( Label( ' - execute and evaluate, ' ) ),
					   _bannerHelpKeyTextStyle.applyTo( Label( 'Ctrl+Shift+Enter' ) ),
					   _bannerHelpTextStyle.applyTo( Label( ' - execute only' ) ) ] )
			helpText2 = Row( [ _bannerHelpKeyTextStyle.applyTo( Label( 'Alt+Up' ) ),
					   _bannerHelpTextStyle.applyTo( Label( ' - previous, ' ) ),
					   _bannerHelpKeyTextStyle.applyTo( Label( 'Alt+Down' ) ),
					   _bannerHelpTextStyle.applyTo( Label( ' - next' ) ) ] )
			bannerText = Column( bannerVersionText + [ helpText1, helpText2 ] ).alignHPack()

			banner = _bannerBorder.surround( bannerText )
		else:
			banner = None


		dropDest = ObjectDndHandler.DropDest( FragmentData, _onDrop )

		def _onExecute(element):
			self.execute( True )

		def _onExecuteNoEval(element):
			self.execute( False )

		def _onHistoryPrev(element):
			self.backwards()

		def _onHistoryNext(element):
			self.forwards()

		currentModule = Span( [ currentModule ] )
		currentModule = currentModule.withShortcut( _executeShortcut, _onExecute )
		currentModule = currentModule.withShortcut( _executeNoEvalShortcut, _onExecuteNoEval )
		currentModule = currentModule.withShortcut( _historyPreviousShortcut, _onHistoryPrev )
		currentModule = currentModule.withShortcut( _historyNextShortcut, _onHistoryNext )

		m = _pythonModuleBorderStyle.applyTo( Border( currentModule.alignHExpand() ) ).alignHExpand()
		m = m.withDropDest( dropDest )
		def _ensureCurrentModuleVisible(element, ctx, style):
			element.ensureVisible()
		m = m.withCustomElementAction( _ensureCurrentModuleVisible )

		dropPromptLive = LiveValue( Span( [] ) )
		dropPromptView = dropPromptLive

		consoleColumnContents = [ banner.alignVRefY() ]   if self._showBanner   else []
		if len( blocks ) > 0:
			blockList = _consoleBlockListStyle.applyTo( Column( blocks ) ).alignHExpand()
			consoleColumnContents += [ blockList.alignVRefY(), dropPromptView.alignVRefY(), m.alignVRefY() ]
		else:
			consoleColumnContents += [ dropPromptView.alignVRefY(), m.alignVRefY() ]
		return _consoleStyle.applyTo( Column( consoleColumnContents ) ).alignHExpand().alignVTop()
	def __present__(self, fragment, inheritedState):
		self._incr.onAccess()
		valuesLive = LiveValue( Blank() )
		tree = Column( [ x._presentFrameSubtree( valuesLive )   for x in self._rootFrames ] )
		return Column( [ tree, Spacer( 0.0, 10.0 ), valuesLive ] )
Пример #14
0
    def Package(self, fragment, inheritedState, package):
        def _addPackage(menuItem):
            package.append(ProjectPackage('NewPackage'))

        class _RenameListener(TextEntry.TextEntryListener):
            def onAccept(self, textEntry, text):
                package.name = text

            def onCancel(self, textEntry, originalText):
                nameLive.setLiteralValue(nameBox)

        def _onRename(menuItem):
            textEntry = TextEntry(package.name,
                                  _RenameListener()).regexValidated(
                                      _nameRegex,
                                      'Please enter a valid identifier')
            textEntry.grabCaretOnRealise()
            nameLive.setLiteralValue(textEntry)

        def _onDelete(menuItem):
            if package.parent is not None:
                package.parent.remove(package)

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

        def _packageContextMenuFactory(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))
            menu.add(HSeparator())
            menu.add(MenuItem.menuItemWithLabel('Rename', _onRename))
            menu.add(HSeparator())
            menu.add(MenuItem.menuItemWithLabel('Delete', _onDelete))
            return True

        nameElement = _packageNameStyle.applyTo(StaticText(package.name))
        nameBox = _itemHoverHighlightStyle.applyTo(
            Row([
                _packageIcon.padX(5.0).alignHPack().alignVCentre(),
                nameElement.alignVCentre()
            ]))

        # Set drop destination and place in box that is h-packed, otherwise attempting to drop items as children could require the user to
        # drop somewhere off to the right of the package, since the h-expand applied further up the presentation tree will expand it beyond
        # its visible bounds
        nameBox = Bin(nameBox).alignHPack()

        nameBox = nameBox.withContextMenuInteractor(_packageContextMenuFactory)
        nameBox = _ProjectTreeController.instance.nestedListItem(
            package, package, nameBox)
        nameBox = AttachTooltip(nameBox, 'Right click to access context menu.',
                                False)

        nameLive = LiveValue(nameBox)
        itemsBox = Column(package[:])
        itemsBox = _ProjectTreeController.instance.editableList(
            package, itemsBox)

        return Column([
            nameLive,
            itemsBox.padX(_packageContentsIndentation, 0.0).alignHExpand()
        ])
Пример #15
0
	def __init__(self, value=None):
		self._live = LiveValue( value )
Пример #16
0
	def __setstate__(self, state):
		value = state['value']
		self._live = LiveValue( value )
Пример #17
0
 def __init__(self, targetNumColumns=None):
     super(GUIFlowGrid, self).__init__()
     self._targetNumColumns = LiveValue(targetNumColumns)
Пример #18
0
 def __init__(self, model=None, value=''):
     super(StringEditorTextArea, self).__init__(model, value)
     self._commitOnChange = LiveValue(True)
Пример #19
0
 def __setstate__(self, state):
     super(StringEditorTextArea, self).__setstate__(state)
     self._commitOnChange = LiveValue(state.get('commitOnChange', True))
Пример #20
0
 def __setstate__(self, state):
     self.__change_history__ = None
     self._isCurrent = LiveValue(False)
Пример #21
0
 def __init__(self):
     self.__change_history__ = None
     self._isCurrent = LiveValue(False)