class ExecutionStyle(object):
    pythonExecution = AttributeNamespace('pythonExecution')

    labelStyle = InheritedAttributeNonNull(
        pythonExecution, 'labelStyle', StyleSheet,
        StyleSheet.style(Primitive.fontSize(10)))

    stdOutStyle = InheritedAttributeNonNull(
        pythonExecution, 'stdOutStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 7.0, 7.0, Color(0.5, 1.0, 0.5),
                            Color(0.9, 1.0, 0.9))),
            Primitive.foreground(Color(0.0, 0.5, 0.0))))
    stdErrStyle = InheritedAttributeNonNull(
        pythonExecution, 'stdErrStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 7.0, 7.0, Color(1.0, 0.75, 0.5),
                            Color(1.0, 0.95, 0.9))),
            Primitive.foreground(Color(0.75, 0.375, 0.0))))
    exceptionBorderStyle = InheritedAttributeNonNull(
        pythonExecution, 'exceptionBorderStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 7.0, 7.0, Color(0.8, 0.0, 0.0),
                            Color(1.0, 0.9, 0.9)))))
    resultBorderStyle = InheritedAttributeNonNull(
        pythonExecution, 'resultBorderStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 10.0, 10.0, Color(0.0, 0.0, 0.8),
                            Color.WHITE))))

    resultBoxStyle = InheritedAttributeNonNull(
        pythonExecution, 'resultSpacing', StyleSheet,
        StyleSheet.style(Primitive.columnSpacing(5.0)))

    @PyDerivedValueTable(pythonExecution)
    def _resultBoxStyle(style):
        resultSpacing = style.get(ExecutionStyle.resultSpacing)
        return style.withValues(Primitive.columnSpacing(resultSpacing))
class XmlElemSpan(abstract_text.MRTAbstractText):
    contents_query = elem_query.children()\
     .map(abstract_text.remove_whitespace, elem.identity)\
     .project_to_objects(mappings.text_mapping)

    def __init__(self, projection_table, elem, contents=None):
        super(XmlElemSpan, self).__init__(projection_table, elem, contents)
        elem_tag_and_attrs = XmlElemTagAndAttrs.from_xml_elem(elem)
        self._elem_tag_and_attrs = elem_tag_and_attrs
        self._editorModel = controller.MallardRichTextController.instance.editorModelSpan(
            [], self._span_attrs(elem_tag_and_attrs))

    def node_init(self):
        self._editorModel.setModelContents(
            controller.MallardRichTextController.instance,
            list(self.contents_query))

    def setElementTagAndAttrs(self, elem_tag_and_attrs):
        self._elem_tag_and_attrs = elem_tag_and_attrs
        self._editorModel.setSpanAttrs(self._span_attrs(elem_tag_and_attrs))
        self._incr.onChanged()

    def getElementTagAndAttrs(self):
        self._incr.onAccess()
        return self._elem_tag_and_attrs

    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

    @staticmethod
    def _span_attrs(elem_tag_and_attrs):
        return RichTextAttributes.fromValues(None,
                                             {XML_ELEM: [elem_tag_and_attrs]})

    @staticmethod
    def new_span(mapping, contents, elem_tag_and_attrs):
        return XmlElemSpan(mapping, elem_tag_and_attrs.create_xml_elem(),
                           contents)

    _tag_border = SolidBorder(1.0, 1.0, 4.0, 4.0, Color(0.4, 0.42, 0.45),
                              Color(0.95, 0.975, 1.0))
    _open_tag_style = StyleSheet.style(
        Primitive.fontSize(10), Primitive.foreground(Color(0.0, 0.3, 0.8)),
        Primitive.fontFace('Monospaced'))
    _close_tag_style = StyleSheet.style(
        Primitive.fontSize(10), Primitive.foreground(Color(0.3, 0.35, 0.4)),
        Primitive.fontFace('Monospaced'))
 def makeBorder(self):
     thickness = self.thickness.getValueForEditor()
     inset = self.inset.getValueForEditor()
     roundingX = self.roundingX.getValueForEditor()
     roundingY = self.roundingY.getValueForEditor()
     borderPaint = self.borderPaint.getValueForEditor()
     backgroundPaint = self.backgroundPaint.getValueForEditor()
     highlightBorderPaint = self.highlightBorderPaint.getValueForEditor()
     highlightBackgroundPaint = self.highlightBackgroundPaint.getValueForEditor(
     )
     return SolidBorder(thickness, inset, roundingX, roundingY, borderPaint,
                        backgroundPaint).highlight(
                            highlightBorderPaint, highlightBackgroundPaint)
Example #4
0
		componentHighlighter.highlight(self.__componentElement)

	def pointerLeave(self, element, event):
		componentHighlighter.unhighlight(self.__componentElement)


	def testClickEvent(self, element, event):
		return event.button == 1

	def buttonClicked(self, element, event):
		rootElement = self.__componentElement.rootElement
		rootElement.setTarget(GUIEditorTarget(self.__component, self.__componentElement))



componentUnderPointerBorder = SolidBorder(1.0, 2.0, Color(0.8, 0.8, 0.8), None, Color(0.6, 0.6, 0.6), Color(0.9, 0.9, 0.9))


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)
Example #5
0
from BritefuryJ.DocModel import DMNode

from BritefuryJ.Graphics import SolidBorder

from BritefuryJ.Pres.Primitive import Paragraph, HiddenText

from LarchCore.Languages.Python2.PythonCommands import pythonCommandSet, EmbeddedExpressionAtCaretAction, chainActions
from LarchCore.Languages.Python2 import Schema as Py

from LarchTools.PythonTools.VisualRegex import Schema
from LarchTools.PythonTools.VisualRegex.Parser import VisualRegexGrammar
from LarchTools.PythonTools.VisualRegex.View import perspective as VREPerspective
from LarchTools.PythonTools.VisualRegex.CodeGenerator import VisualRegexCodeGenerator

_vreBorder = SolidBorder(2.0, 4.0, 10.0, 10.0, Color(0.7, 0.8, 0.7), None)


class VisualPythonRegex(object):
    _codeGen = VisualRegexCodeGenerator()

    def __init__(self, regex=None):
        if regex is None:
            regex = Schema.PythonRegEx(expr=Schema.UNPARSED(value=['']))

        if isinstance(regex, re._pattern_type):
            # Extract pattern string
            regex = regex.pattern

        if isinstance(regex, str) or isinstance(regex, unicode):
            # Convert to structural form

	@expected.setter
	def expected(self, x):
		if x is None:
			self._expected.setLiteralValue( None )




AbstractInlineTestTableRow._resultColumn = AttributeColumn( 'Result', 'result' )
AbstractInlineTestTableRow._expectedColumn = AttributeColumn( 'Expected', 'expected', None, None )



_nameBorder = SolidBorder( 1.0, 2.0, 5.0, 5.0, Color( 0.6, 0.6, 0.6 ), Color( 0.95, 0.95, 0.95 ) )
_notSet = StyleSheet.style( Primitive.fontItalic( True ) )( Label( 'not set' ) )
_inlineTestTableBorder = SolidBorder( 1.5, 3.0, 5.0, 5.0, Color( 0.4, 0.4, 0.5 ), None )


class AbstractInlineTestTable (AbstractInlineTest):
	_tableEditor = NotImplemented


	def __init__(self, name='test'):
		super( AbstractInlineTestTable, self ).__init__()
		self._name = TrackedLiveValue( name )
		self._tests = LiveList()
		self.__change_history__ = None

		self.__methodNames = UniqueNameTable()
from BritefuryJ.Graphics import SolidBorder

from BritefuryJ.Pres import Pres
from BritefuryJ.Pres.Primitive import Blank, Spacer

from LarchCore.Languages.Python2 import Schema as Py
from LarchCore.Languages.Python2.PythonCommands import pythonCommandSet, EmbeddedExpressionAtCaretAction

from LarchTools.PythonTools.GUIEditor.Properties import GUIEdProp, GUICProp
from LarchTools.PythonTools.GUIEditor.ContextMenu import guiEditorContextMenu, componentContextMenu
from LarchTools.PythonTools.GUIEditor.Target import GUITargetInteractor, GUIScrollInteractor
from LarchTools.PythonTools.GUIEditor.ComponentPalette import PaletteComponentDrag
from LarchTools.PythonTools.GUIEditor.BranchComponent import GUIUnaryBranchComponent

_guiEditorBorder = SolidBorder(1.5, 3.0, 5.0, 5.0, Color(0.6, 0.5, 0.7), None)


class GUIEditorRootComponent(GUIUnaryBranchComponent):
    isRootGUIEditorComponent = True

    def __init__(self, contents=None):
        super(GUIEditorRootComponent, self).__init__(child=contents)
        self._guiEditor = None

    @property
    def guiEditor(self):
        return self._guiEditor

    def __component_py_evalmodel__(self, codeGen):
        child = self.child
Example #8
0
from BritefuryJ.Pres.Primitive import Primitive, Label, Row, Column, Paragraph, LineBreak, Span
from BritefuryJ.Pres.RichText import NormalText, RichSpan, Heading2
from BritefuryJ.Pres.UI import SectionHeading1, SectionHeading3
from BritefuryJ.StyleSheet import StyleSheet

from BritefuryJ.Graphics import SolidBorder

from BritefuryJ.Live import LiveFunction

from datamodel import xmlmodel, node
from datamodel.elem_fields import elem_query
from controls import text_entry

from . import mappings, title, rich_text

_section_border = SolidBorder(1.0, 3.0, 5.0, 5.0, Color(1.0, 0.75, 0.0),
                              Color(1.0, 1.0, 0.95))


class Note(node.Node):
    title_elem = elem_query.child('title').project_to_object(
        mappings.title_mapping)
    text = elem_query.project_to_object(mappings.as_document_mapping)

    def __present__(self, fragment, inh):
        title = Row([SectionHeading3('Note: '), self.title_elem])
        return _section_border.surround(Column([title, self.text]))

    @staticmethod
    def for_elem(elem):
        mapping = node.ElementToObjectProjectionTable()
        return Note(mapping, elem)
Example #9
0
    Primitive.fontFace(Primitive.lightFontName))
_packageNameStyle = StyleSheet.style(
    Primitive.foreground(Color(0.0, 0.0, 0.5)), Primitive.fontSize(14),
    Primitive.fontFace(Primitive.lightFontName))
_itemHoverHighlightStyle = StyleSheet.style(
    Primitive.hoverBackground(
        FilledOutlinePainter(Color(0.8, 0.825, 0.9),
                             Color(0.125, 0.341, 0.574), BasicStroke(1.0))))
_pythonPackageNameStyle = StyleSheet.style(
    Primitive.foreground(Color(0.0, 0.0, 0.5)))
_pythonPackageNameNotSetStyle = StyleSheet.style(
    Primitive.foreground(Color(0.5, 0.0, 0.0)))
_pythonPackageNameNotSetCommentStyle = StyleSheet.style(
    Primitive.foreground(Color(0.2, 0.2, 0.2)), Primitive.fontItalic(True))

_frontPageNoteBorder = SolidBorder(1.0, 1.0, 3.0, 3.0, Color(0.0, 1.0, 0.0),
                                   Color(0.85, 0.95, 0.85))
_frontPageNoteStyle = StyleSheet.style(
    Primitive.foreground(Color(0.0, 0.5, 0.0)), Primitive.fontSize(10))
_startupPageNoteBorder = SolidBorder(1.0, 1.0, 3.0, 3.0, Color(0.75, 0.5, 1.0),
                                     Color(0.925, 0.9, 0.95))
_startupPageNoteStyle = StyleSheet.style(
    Primitive.foreground(Color(0.25, 0.0, 0.5)), Primitive.fontSize(10))
_notesRowStyle = StyleSheet.style(Primitive.rowSpacing(10.0))
_notesGap = 15.0

_packageContentsIndentation = 20.0

_packageIcon = Image(
    Image.getResource('/LarchCore/Project/images/Package.png'))

_nameRegex = Pattern.compile('[a-zA-Z_][a-zA-Z0-9_]*')
Example #10
0
		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






exprBorder = SolidBorder( 1.0, 2.0, 5.0, 5.0, Color( 0.0, 0.25, 0.75 ), None )




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 []

from BritefuryJ.Pres.Primitive import Primitive, Blank, Label, Spacer, Row, Column
from BritefuryJ.Pres.UI import Form, ControlsRow

from BritefuryJ.StyleSheet import StyleSheet

from BritefuryJ.Live import LiveFunction

from LarchCore.Languages.Python2 import Schema as Py

from LarchTools.PythonTools.GUIEditor.DataModel import GUINode, TypedEvalField, TypedField
from LarchTools.PythonTools.GUIEditor.Properties import GUICProp
from LarchTools.PythonTools.GUIEditor.Target import GUITargetInteractor, GUIScrollInteractor
from LarchTools.PythonTools.GUIEditor.ContextMenu import componentContextMenu
from LarchTools.PythonTools.GUIEditor.Padding import AbstractPadding, UniformPadding, NonUniformPadding

componentBorder = SolidBorder(1.0, 2.0, Color(0.8, 0.8, 0.8), None)


def blankCallModel(codeGen):
    blank = codeGen.embeddedValue(Blank)
    return Py.Call(target=blank, args=[])


_noAlignmentStyle = StyleSheet.style(
    Primitive.foreground(Color(0.4, 0.4, 0.4)), Primitive.fontSize(11))


def _hAlignmentEditor(live):
    @LiveFunction
    def displayLive():
        x = live.getValue()
Example #12
0
from BritefuryJ.Pres.Primitive import Primitive, Label, Row, Column, Paragraph, LineBreak, Span
from BritefuryJ.Pres.RichText import NormalText, RichSpan, Heading2
from BritefuryJ.Pres.UI import SectionHeading1, SectionHeading2
from BritefuryJ.StyleSheet import StyleSheet

from BritefuryJ.Graphics import SolidBorder

from BritefuryJ.Live import LiveFunction

from datamodel import xmlmodel, node
from datamodel.elem_fields import elem_query
from controls import text_entry

from . import mappings, title, rich_text

_section_border = SolidBorder(1.0, 3.0, 5.0, 5.0, Color(0.3, 0.3, 0.3), None)


class Section(node.Node):
    title_elem = elem_query.child('title').project_to_object(
        mappings.title_mapping)
    text = elem_query.project_to_object(mappings.as_document_mapping)

    def __present__(self, fragment, inh):
        title = Row([SectionHeading2('Section: '), self.title_elem])
        return _section_border.surround(Column([title, self.text]))

    @staticmethod
    def for_elem(elem):
        mapping = node.ElementToObjectProjectionTable()
        return Section(mapping, elem)
from LarchCore.Languages.Python2 import Python2
from LarchCore.Languages.Python2.Execution.ExecutionPresCombinators import execStdout, execStderr, execException, execResult
from LarchCore.Languages.Python2.Execution import Execution




_executeShortcut = Shortcut( KeyEvent.VK_ENTER, Modifier.CTRL )
_executeNoEvalShortcut = Shortcut( KeyEvent.VK_ENTER, Modifier.CTRL | Modifier.SHIFT )
_historyPreviousShortcut = Shortcut( KeyEvent.VK_UP, Modifier.ALT )
_historyNextShortcut = Shortcut( KeyEvent.VK_DOWN, Modifier.ALT )

_bannerTextStyle = StyleSheet.style( Primitive.fontFace( 'Serif' ), Primitive.fontSmallCaps( True ), Primitive.editable( False ) )
_bannerHelpKeyTextStyle = StyleSheet.style( Primitive.fontFace( 'Serif' ), Primitive.fontSmallCaps( True ), Primitive.fontItalic( True ), Primitive.foreground( Color( 0.25, 0.25, 0.25 ) ) )
_bannerHelpTextStyle = StyleSheet.style( Primitive.fontFace( 'Serif' ), Primitive.fontItalic( True ), Primitive.foreground( Color( 0.25, 0.25, 0.25 ) ) )
_bannerBorder = SolidBorder( 2.0, 5.0, 8.0, 8.0, Color( 0.3, 0.5, 0.3 ), Color( 0.875, 0.9, 0.875 ) )


_labelStyle = StyleSheet.style( Primitive.fontSize( 10 ) )

#_blockStyle = StyleSheet.style( Primitive.columnSpacing( 2.0 ), Primitive.border( SolidBorder( 1.0, 5.0, 15.0, 15.0, Color( 0.25, 0.25, 0.25 ), Color( 0.8, 0.8, 0.8 ) ) ) )
_blockStyle = StyleSheet.style( Primitive.columnSpacing( 3.0 ), Primitive.border( SolidBorder( 1.0, 3.0, 13.0, 13.0, Color( 0.6, 0.6, 0.6 ), Color( 0.9, 0.9, 0.9 ) ) ) )
_blockOutputStyle = StyleSheet.style( Primitive.columnSpacing( 2.0 ) )

_pythonModuleBorderStyle = StyleSheet.style( Primitive.border( SolidBorder( 1.5, 5.0, 10.0, 10.0, Color( 0.65, 0.65, 0.65 ), Color.WHITE ) ) )
_dropPromptStyle = StyleSheet.style( Primitive.border( SolidBorder( 1.0, 3.0, 10.0, 10.0, Color( 0.0, 0.8, 0.0 ), None ) ) )

_varAssignVarNameStyle = StyleSheet.style( Primitive.fontItalic( True ), Primitive.foreground( Color( 0.0, 0.0, 0.5 ) ) )
_varAssignTypeNameStyle = StyleSheet.style( Primitive.foreground( Color( 0.3, 0.0, 0.3 ) ) )
_varAssignJavaKindStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.0, 0.4 ) ), Primitive.fontItalic( True ) )
_varAssignPythonKindStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.4, 0.0 ) ), Primitive.fontItalic( True ) )
from BritefuryJ.Pres import LazyPres, Pres
from BritefuryJ.Pres.Primitive import Primitive, Label, Spacer, LineBreak, SpaceBin, Column, Paragraph
from BritefuryJ.Pres.UI import Section, SectionHeading1, BubblePopup
from BritefuryJ.StyleSheet import StyleSheet
from BritefuryJ.Controls import TabbedBox
from BritefuryJ.Util import TypeUtils
from BritefuryJ.Logging import LogView

from BritefuryJ.ObjectPresentation import PresentationStateListenerList

from BritefuryJ.DefaultPerspective import DefaultPerspective

from LarchCore.PythonConsole import Console

_fragSelectorEntryBorder = SolidBorder(1.0, 3.0, 6.0, 6.0,
                                       Color(0.8, 0.8, 0.8), None,
                                       Color(0.5, 0.5, 0.5),
                                       Color(0.9, 0.9, 0.9))

_fragContentHighlighter = ElementHighlighter(
    FilledOutlinePainter(Color(0.0, 1.0, 0.0, 0.1), Color(0.0, 0.5, 0.0, 0.5)))
_objectKindStyleJava = StyleSheet.style(
    Primitive.fontSize(10), Primitive.foreground(Color(0.0, 0.0, 0.5)))
_objectKindStylePython = StyleSheet.style(
    Primitive.fontSize(10), Primitive.foreground(Color(0.0, 0.5, 0.0)))
_objectKindStyleDocModel = StyleSheet.style(
    Primitive.fontSize(10), Primitive.foreground(Color(0.5, 0.5, 0.5)))
_consoleStyle = StyleSheet.style(Primitive.editable(True),
                                 Primitive.selectable(True))
_inspectorStyle = StyleSheet.style(Primitive.editable(False),
                                   Primitive.selectable(False))
Example #15
0
from BritefuryJ.Pres.Primitive import Primitive, Label, Spacer, Row, Column
from BritefuryJ.Pres.UI import SectionHeading2, SectionHeading3

from BritefuryJ.Parser.Utils import Tokens

from BritefuryJ.StyleSheet import StyleSheet

from Britefury.Util.UniqueNameTable import UniqueNameTable
from BritefuryJ.Util.Jython import JythonException

from LarchCore.Languages.Python2.PythonCommands import pythonCommandSet, EmbeddedStatementAtCaretAction, WrapSelectedStatementRangeInEmbeddedObjectAction, chainActions
from LarchCore.Languages.Python2.Embedded import EmbeddedPython2Suite
from LarchCore.Languages.Python2 import Schema


_nameBorder = SolidBorder( 1.0, 2.0, 5.0, 5.0, Color( 0.6, 0.6, 0.6 ), Color( 0.95, 0.95, 0.95 ) )

_notSet = StyleSheet.style( Primitive.fontItalic( True ) )( Label( 'not set' ) )




_testValueBorder = SolidBorder( 1.5, 2.5, 4.0, 4.0, Color( 0.75, 0.0, 0.0 ), None )


_comparisonStyle = StyleSheet.style( Primitive.fontBold( True ), Primitive.foreground( Color( 0.75, 0.0, 0.0 ) ) )


class TestCase (object):
	def assertEqual(self, first, second):
		if not ( first == second ):
Example #16
0
from java.awt import Color

from BritefuryJ.Pres.Primitive import Primitive, Label
from BritefuryJ.StyleSheet import StyleSheet
from BritefuryJ.Graphics import SolidBorder

_error_border = SolidBorder(1.0, 4.0, 5.0, 5.0, Color(1.0, 0.5, 0.5),
                            Color(1.0, 0.95, 0.95))
_error_style = StyleSheet.style(Primitive.foreground(Color(0.3, 0.0, 0.0)))


def error_message(message):
    return _error_border.surround(_error_style(Label(message)))


# Error sentinel value


class ErrorSentinel(object):
    error_message = 'Generic error'

    def __present__(self, fragment, inh):
        return error_message(self.error_message)
Example #17
0
from BritefuryJ.StyleSheet import StyleSheet

from BritefuryJ.DefaultPerspective import DefaultPerspective
from BritefuryJ.Projection import TransientSubject
from Britefury.Kernel.Document import Document

from LarchCore.MainApp.MainAppViewer.View import perspective
from LarchCore.MainApp.MainAppViewer.AboutPage import AboutPage


_info_style = StyleSheet.style(Primitive.selectable(False), Primitive.editable(False))
_editable_style = StyleSheet.style(Primitive.selectable(True), Primitive.editable(True))

_section_heading_style = StyleSheet.style(Primitive.background(FillPainter(Color(0.925, 0.925, 0.925))))

_section_border = SolidBorder(1.0, 3.0, 4.0, 4.0, Color(0.4, 0.4, 0.4), None)


def unload_modules_starting_with(prefixes):
	to_remove = []
	for m in sys.modules:
		for prefix in prefixes:
			if m.startswith(prefix):
				to_remove.append(m)
	for m in to_remove:
		del sys.modules[m]


class EditorPage (object):
	def __init__(self, filename, xml_path=None, xml_bytes=None):
		self._filename = filename
Example #18
0
class PythonEditorStyle(object):
    pythonEditor = AttributeNamespace('pythonEditor')

    _pythonCodeFont = 'Noto Sans; SansSerif'

    #keywordStyle = InheritedAttributeNonNull( pythonEditor, 'keywordStyle', StyleSheet,
    #StyleSheet.style( Primitive.fontFace( _pythonCodeFont ), Primitive.fontSize( 14 ), Primitive.fontBold( True ),
    #Primitive.foreground( Color( 0.25, 0.0, 0.5 ) ), Primitive.fontSmallCaps( True ) )

    keywordStyle = InheritedAttributeNonNull(
        pythonEditor, 'keywordStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14), Primitive.fontBold(True),
                         Primitive.foreground(Color(0.25, 0.0, 0.5))))
    literalFormatStyle = InheritedAttributeNonNull(
        pythonEditor, 'literalFormatStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.25, 0.25))))
    quotationStyle = InheritedAttributeNonNull(
        pythonEditor, 'quotationStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.0, 0.5))))
    stringLiteralStyle = InheritedAttributeNonNull(
        pythonEditor, 'stringLiteralStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.25, 0.0, 0.5))))
    stringLiteralEscapeStyle = InheritedAttributeNonNull(
        pythonEditor, 'stringLiteralEscapeStyle', StyleSheet,
        StyleSheet.style(
            Primitive.fontFace(_pythonCodeFont), Primitive.fontSize(14),
            Primitive.foreground(Color(0.25, 0.2, 0.15)),
            Primitive.border(
                SolidBorder(1.0, 1.0, 4.0, 4.0, Color(0.75, 0.6, 0.5),
                            Color(1.0, 0.85, 0.75)))))
    numLiteralStyle = InheritedAttributeNonNull(
        pythonEditor, 'numLiteralStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.5, 0.5))))
    punctuationStyle = InheritedAttributeNonNull(
        pythonEditor, 'punctuationStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.0, 1.0))))
    delimStyle = InheritedAttributeNonNull(
        pythonEditor, 'delimStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.0, 1.0))))
    targetStyle = InheritedAttributeNonNull(
        pythonEditor, 'targetStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    varStyle = InheritedAttributeNonNull(
        pythonEditor, 'varStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    attributeStyle = InheritedAttributeNonNull(
        pythonEditor, 'attributeStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    kwNameStyle = InheritedAttributeNonNull(
        pythonEditor, 'kwNameStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    operatorStyle = InheritedAttributeNonNull(
        pythonEditor, 'operatorStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontBold(True), Primitive.fontSize(14),
                         Primitive.foreground(Color(0.0, 0.5, 0.0))))
    paramStyle = InheritedAttributeNonNull(
        pythonEditor, 'paramStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    importStyle = InheritedAttributeNonNull(
        pythonEditor, 'importStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black)))
    commentStyle = InheritedAttributeNonNull(
        pythonEditor, 'commentStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color(0.4, 0.4, 0.4))))
    unparseableStyle = InheritedAttributeNonNull(
        pythonEditor, 'unparseableStyle', StyleSheet,
        StyleSheet.style(Primitive.fontFace(_pythonCodeFont),
                         Primitive.fontSize(14),
                         Primitive.foreground(Color.black),
                         Primitive.textSquiggleUnderlinePaint(Color.red)))

    sequenceStyle = InheritedAttributeNonNull(
        pythonEditor, 'sequenceStyle', StyleSheet,
        StyleSheet.style(Sequence.addLineBreaks(True),
                         Sequence.matchOuterIndentation(True),
                         Sequence.addLineBreakCost(True)))

    quoteBorderStyle = InheritedAttributeNonNull(
        pythonEditor, 'quoteBorderStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 5.0, 5.0, Color(0.5, 0.3, 0.7), None))))
    quoteTitleStyle = InheritedAttributeNonNull(
        pythonEditor, 'quoteTitleStyle', StyleSheet,
        StyleSheet.style(Primitive.foreground(Color(0.3, 0.1, 0.5)),
                         Primitive.fontSize(10)))

    unquoteBorderStyle = InheritedAttributeNonNull(
        pythonEditor, 'unquoteBorderStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 5.0, 5.0, Color(1.0, 0.5, 0.3), None))))
    unquoteTitleStyle = InheritedAttributeNonNull(
        pythonEditor, 'unquoteTitleStyle', StyleSheet,
        StyleSheet.style(Primitive.foreground(Color(0.7, 0.35, 0.0)),
                         Primitive.fontSize(10)))

    externalExprBorderStyle = InheritedAttributeNonNull(
        pythonEditor, 'externalExprBorderStyle', StyleSheet,
        StyleSheet.style(
            Primitive.border(
                SolidBorder(1.0, 3.0, 5.0, 5.0, Color(0.3, 0.7, 1.0), None))))
    externalExprTitleStyle = InheritedAttributeNonNull(
        pythonEditor, 'externalExprTitleStyle', StyleSheet,
        StyleSheet.style(Primitive.foreground(Color(0.0, 0.5, 1.0)),
                         Primitive.fontSize(10)))

    embeddedObjectBorder = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectBorder', AbstractBorder,
        SolidBorder(1.5, 1.5, 4.0, 4.0, Color(0.6, 0.65, 0.8), None))
    embeddedObjectLiteralBorder = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectLiteralBorder', AbstractBorder,
        SolidBorder(1.5, 1.5, 4.0, 4.0, Color(0.4, 0.433, 0.533), None))
    embeddedObjectTagLabelStyle = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectTagLabelStyle', StyleSheet,
        StyleSheet.style(Primitive.foreground(Color(0.0, 0.0, 0.0, 0.6)),
                         Primitive.fontSize(9)))
    embeddedObjectTagBorder = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectTagBorder', AbstractBorder,
        SolidBorder(1.0, 1.0, 3.0, 3.0, Color(0.45, 0.4, 0.533),
                    Color(0.925, 0.9, 0.95)))
    embeddedObjectLineStyle = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectLineStyle', StyleSheet,
        StyleSheet.style(
            Primitive.shapePainter(FillPainter(Color(0.1, 0.2, 0.3)))))
    embeddedObjectExpansionLabelStyle = InheritedAttributeNonNull(
        pythonEditor, 'embeddedObjectExpansionLabelStyle', StyleSheet,
        StyleSheet.style(Primitive.fontSize(10)))

    paragraphIndentationStyle = InheritedAttributeNonNull(
        pythonEditor, 'paragraphIndentationStyle', StyleSheet,
        StyleSheet.style(Primitive.paragraphIndentation(40.0)))

    solidHighlightRounding = InheritedAttributeNonNull(
        pythonEditor, 'solidHighlightRounding', float, 3.0)
    outlineHighlightThickness = InheritedAttributeNonNull(
        pythonEditor, 'outlineHighlightThickness', float, 1.5)
    outlineHighlightInset = InheritedAttributeNonNull(pythonEditor,
                                                      'outlineHighlightInset',
                                                      float, 2.0)
    outlineHighlightRounding = InheritedAttributeNonNull(
        pythonEditor, 'outlineHighlightRounding', float, 5.0)

    defStmtHighlightColour = InheritedAttributeNonNull(
        pythonEditor, 'defStmtHighlightColour', Color,
        Color(0.420, 0.620, 0.522))
    classStmtHighlightColour = InheritedAttributeNonNull(
        pythonEditor, 'classStmtHighlightColour', Color,
        Color(0.522, 0.420, 0.620))
    badIndentationRectanglePainter = InheritedAttributeNonNull(
        pythonEditor, 'badIndentationRectanglePainter', Painter,
        FilledOutlinePainter(lerpColour(Color.RED, Color.WHITE, 0.75),
                             lerpColour(Color.RED, Color.WHITE, 0.5)))

    comprehensionSpacing = InheritedAttributeNonNull(pythonEditor,
                                                     'comprehensionSpacing',
                                                     float, 15.0)
    conditionalSpacing = InheritedAttributeNonNull(pythonEditor,
                                                   'conditionalSpacing', float,
                                                   15.0)
    blockIndentation = InheritedAttributeNonNull(pythonEditor,
                                                 'blockIndentation', float,
                                                 30.0)

    @PyDerivedValueTable(pythonEditor)
    def _defStmtHeaderHighlightStyle(style):
        border = _solidHighlightBorder(
            style, style.get(PythonEditorStyle.defStmtHighlightColour))
        return style.withValues(Primitive.border(border))

    @PyDerivedValueTable(pythonEditor)
    def _defStmtHighlightStyle(style):
        border = _outlineHighlightBorder(
            style, style.get(PythonEditorStyle.defStmtHighlightColour))
        return style.withValues(Primitive.border(border))

    @PyDerivedValueTable(pythonEditor)
    def _classStmtHeaderHighlightStyle(style):
        border = _solidHighlightBorder(
            style, style.get(PythonEditorStyle.classStmtHighlightColour))
        return style.withValues(Primitive.border(border))

    @PyDerivedValueTable(pythonEditor)
    def _classStmtHighlightStyle(style):
        border = _outlineHighlightBorder(
            style, style.get(PythonEditorStyle.classStmtHighlightColour))
        return style.withValues(Primitive.border(border))

    @PyDerivedValueTable(pythonEditor)
    def _badIndentationRectangleStyle(style):
        painter = style.get(PythonEditorStyle.badIndentationRectanglePainter)
        return style.withValues(Primitive.shapePainter(painter))
from BritefuryJ.Projection import Perspective, Subject, SubjectPathEntry

from LarchCore.Languages.Python2 import Python2
from LarchCore.Languages.Python2.CodeGenerator import compileForModuleExecution

from LarchCore.Worksheet import Schema
from LarchCore.Worksheet.WorksheetViewer import ViewSchema
from LarchCore.Worksheet.WorksheetEditor.View import WorksheetEditorSubject

_editableStyle = StyleSheet.style(Primitive.editable(True))

_worksheetMargin = 10.0

_pythonCodeBorderStyle = StyleSheet.style(
    Primitive.border(
        SolidBorder(1.0, 5.0, 10.0, 10.0, Color(0.2, 0.4, 0.8), None)))
_pythonCodeEditorBorderStyle = StyleSheet.style(
    Primitive.border(
        SolidBorder(1.5, 4.0, 10.0, 10.0, Color(0.4, 0.4, 0.5), None)))


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
Example #20
0
def _outlineHighlightBorder(style, colour):
    thickness = style.get(PythonEditorStyle.outlineHighlightThickness)
    inset = style.get(PythonEditorStyle.outlineHighlightInset)
    rounding = style.get(PythonEditorStyle.outlineHighlightRounding)
    return SolidBorder(thickness, inset, rounding, rounding, colour, None)
Example #21
0
from BritefuryJ.Pres.Primitive import Primitive, Label, Arrow, Spacer, Box, Row, Column
from BritefuryJ.StyleSheet import StyleSheet

from BritefuryJ.Util.Coroutine import Coroutine

from BritefuryJ.Live import LiveValue

from LarchCore.Languages.Python2.PythonCommands import pythonCommandSet, WrapSelectedStatementRangeInEmbeddedObjectAction, EmbeddedStatementAtCaretAction, chainActions
from LarchCore.Languages.Python2.Embedded import EmbeddedPython2Suite

_headerStyle = StyleSheet.style(
    Primitive.fontBold(True),
    Primitive.background(FillPainter(Color(1.0, 0.95, 0.8))),
    Primitive.rowSpacing(5.0))
_forwardArrow = Arrow(Arrow.Direction.RIGHT, 12.0)
_codeBorder = SolidBorder(1.0, 2.0, 8.0, 8.0, Color(0.75, 0.737, 0.675), None)
_stepperBorder = SolidBorder(2.0, 2.0, 8.0, 8.0, Color(0.55, 0.52, 0.4), None)
_breakPointBorder = SolidBorder(1.0, 1.0, 5.0, 5.0, Color(0.3, 0.3, 0.3),
                                Color(0.85, 0.85, 0.85))
_breakPointCurrentBorder = SolidBorder(1.0, 1.0, 5.0, 5.0,
                                       Color(0.0, 0.4, 0.0),
                                       Color(0.85, 1.0, 0.85))
_breakPointStyle = StyleSheet.style(Primitive.fontSize(10))
_breakPointArrow = Arrow(Arrow.Direction.RIGHT, 8.0)


class StepperCode(object):
    def __init__(self, stepper, suite):
        self._stepper = stepper
        self._suite = EmbeddedPython2Suite(suite)
        self.__change_history__ = None
class GraphVizConfigurationPage(ConfigurationPage):
    def __init__(self):
        super(GraphVizConfigurationPage, self).__init__()
        self._graphVizDir = None
        self._config = None
        self._incr = IncrementalValueMonitor()

    def initPage(self, config):
        super(GraphVizConfigurationPage, self).initPage(config)
        GraphVizConfiguration.setConfigurationPageSubject(self.subject())

    def __getstate__(self):
        state = super(GraphVizConfigurationPage, self).__getstate__()
        state['graphVizDir'] = self._graphVizDir
        return state

    def __setstate__(self, state):
        super(GraphVizConfigurationPage, self).__setstate__(state)
        self._graphVizDir = state['graphVizDir']
        self._config = None
        self._incr = IncrementalValueMonitor()

        self._refreshConfig()

    def _checkedToolPath(self, name):
        path = os.path.join(self._graphVizDir, name + _exeExtension)
        if os.path.exists(path):
            return path
        else:
            return None

    def _setGraphVizDir(self, dir):
        self._graphVizDir = dir
        self._refreshConfig()
        self._incr.onChanged()

    def __isConfigured(self):
        if self._graphVizDir is not None and os.path.isdir(self._graphVizDir):
            dotPath = self._checkedToolPath('dot')
            neatoPath = self._checkedToolPath('neato')
            twopiPath = self._checkedToolPath('twopi')
            circoPath = self._checkedToolPath('circo')
            fdpPath = self._checkedToolPath('fdp')
            sfdpPath = self._checkedToolPath('sfdp')
            osagePath = self._checkedToolPath('osage')
            return dotPath is not None and neatoPath is not None and twopiPath is not None and circoPath is not None and fdpPath is not None and sfdpPath is not None and osagePath is not None
        return False

    def _refreshConfig(self):
        if self._graphVizDir is not None and os.path.isdir(self._graphVizDir):
            dotPath = self._checkedToolPath('dot')
            neatoPath = self._checkedToolPath('neato')
            twopiPath = self._checkedToolPath('twopi')
            circoPath = self._checkedToolPath('circo')
            fdpPath = self._checkedToolPath('fdp')
            sfdpPath = self._checkedToolPath('sfdp')
            osagePath = self._checkedToolPath('osage')
            self._config = GraphVizConfiguration(dotPath, neatoPath, twopiPath,
                                                 circoPath, fdpPath, sfdpPath,
                                                 osagePath)
            GraphVizConfiguration.setInstance(self._config)
        else:
            self._config = None
            GraphVizConfiguration.setInstance(None)
        self._incr.onChanged()

    def getSubjectTitle(self):
        return '[CFG] GraphViz'

    def getTitleText(self):
        return 'GraphViz Configuration'

    def getLinkText(self):
        return 'GraphViz'

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

    def _toolLabel(self, name):
        return self._configTableToolNameStyle.applyTo(Label(name))

    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 __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])

    _dirBorderStyle = StyleSheet.style(
        Primitive.border(
            SolidBorder(1.0, 3.0, 10.0, 10.0, Color(1.0, 0.85, 0.0),
                        Color(1.0, 1.0, 0.85))))
    _notSetStyle = StyleSheet.style(Primitive.fontItalic(True))
    _configTableStyle = StyleSheet.style(Primitive.tableColumnSpacing(10.0))
    _configTableToolNameStyle = StyleSheet.style(
        Primitive.foreground(Color(0.25, 0.0, 0.5)))
from LarchTools.PythonTools.VisualRegex import Schema
from LarchTools.PythonTools.VisualRegex.Parser import VisualRegexGrammar
from LarchTools.PythonTools.VisualRegex.SRController import VisualRegexSyntaxRecognizingController


PRECEDENCE_NONE = -1




_unparsedTextStyle = StyleSheet.style( Primitive.textSquiggleUnderlinePaint( Color.RED ) )
_controlCharStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.0, 0.0, 0.5 ) ) )
_invertControlCharStyle = StyleSheet.style( Primitive.foreground( Color( 1.0, 0.0, 0.0, 0.5 ) ) )

_specialCharStyle = StyleSheet.style( Primitive.foreground( Color( 0.25, 0.25, 0.35 ) ), Primitive.fontSize( 10 ) )
_specialBorder = SolidBorder( 1.0, 1.0, 4.0, 4.0, Color( 0.6, 0.6, 0.7 ), Color( 0.75, 0.75, 0.85 ) )

_charClassStyle = StyleSheet.style( Primitive.foreground( Color( 0.2, 0.3, 0.4 ) ), Primitive.fontSize( 10 ) )
_charClassBorder = SolidBorder( 1.0, 1.0, 4.0, 4.0, Color( 0.6, 0.65, 0.7 ), Color( 0.8, 0.85, 0.9 ) )


#_charClassStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.25, 0.5 ) ) )
#_charClassEscapeStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.25, 0.5, 0.5 ) ) )
#_charClassBorder = SolidBorder( 1.0, 2.0, 4.0, 4.0, Color( 0.0, 0.25, 0.5 ), Color( 0.8, 0.9, 1.0 ) )

_groupNameStyle = StyleSheet.style( Primitive.foreground( Color( 0.0, 0.65, 0.0 ) ) )
_groupNumberStyle = StyleSheet.style( Primitive.foreground( Color( 0.1, 0.45, 0.1 ) ) )
_commentStyle = StyleSheet.style( Primitive.foreground( Color( 0.3, 0.3, 0.3 ) ) )
_flagsStyle = StyleSheet.style( Primitive.foreground( Color( 1.0, 0.5, 0.0 ) ) )

_escapeBorder = SolidBorder( 1.0, 2.0, 4.0, 4.0, Color( 0.5, 0.6, 0.75 ), Color( 0.75, 0.85, 1.0 ) )
    def __init__(self, factory):
        self.factory = factory

    def getItem(self):
        return self.factory()


#
#
#Control palette:
_paletteItemStyle = StyleSheet.style(
    Primitive.fontSize(11), Primitive.foreground(Color(0.3, 0.3, 0.3)),
    Primitive.background(
        FilledOutlinePainter(Color.white, Color(0.8, 0.8, 0.8))))
_paletteItemBorder = SolidBorder(1.0, 2.0, Color(0.7, 0.7, 0.7),
                                 None).highlight(Color(0.6, 0.6, 0.6),
                                                 Color(0.9, 0.9, 0.9))

_paletteSections = []


def paletteItem(contents, factoryCallable):
    p = _paletteItemStyle(_paletteItemBorder.surround(
        contents)).alignHExpand().alignVRefYExpand()
    p = p.withDragSource(
        PaletteComponentDrag,
        lambda element, aspect: PaletteComponentDrag(factoryCallable))
    p = p.withDragSource(
        PaletteComponentIntoListDrag,
        lambda element, aspect: PaletteComponentIntoListDrag(
            GUIEditor.BranchComponent.SequentialGUIController.instance,