Exemplo n.º 1
0
    def test_cells_context(self):
        class X:
            def __init__(self, x):
                self.x = x

        @registerDisplay(X, size="small")
        def small_x(X):
            return Text(X.x).tagged("small display " + str(X.x))

        @registerDisplay(X, size="large")
        def large_x(X):
            return Text(X.x).tagged("large display " + str(X.x))

        @registerDisplay(X, size=lambda size: size is not None)
        def sized_x(X):
            return Text(X.x).tagged("sized display " + str(X.x))

        @registerDisplay(X)
        def any_x(X):
            return Text(X.x).tagged("display " + str(X.x))

        self.cells.withRoot(
            Card(X(0)).withContext(size="small") +
            Card(X(1)).withContext(size="large") +
            Card(X(2)).withContext(size="something else") + Card(X(3)))

        self.cells.renderMessages()

        self.assertTrue(self.cells.findChildrenByTag("small display 0"))
        self.assertTrue(self.cells.findChildrenByTag("large display 1"))
        self.assertTrue(self.cells.findChildrenByTag("sized display 2"))
        self.assertTrue(self.cells.findChildrenByTag("display 3"))
Exemplo n.º 2
0
 def test_tabs_html_valid(self):
     cell = Tabs(Tab1=Card("Tab1 Content"), Tab2=Card("Tab2 Content"))
     cell.recalculate()
     html = cell.contents
     # TODO: placeholder text can't be in element <ul>
     html = html.replace("         ____header_0__  ____header_1__",
                         "<li>_content</li>")
     self.assertHTMLNotEmpty(html)
     self.assertHTMLValid(html)
Exemplo n.º 3
0
    def test_cells_reusable(self):
        c1 = Card(Text("HI"))
        c2 = Card(Text("HI2"))
        slot = Slot(0)

        self.cells.withRoot(Subscribed(lambda: c1 if slot.get() else c2))

        self.cells.renderMessages()
        slot.set(1)
        self.cells.renderMessages()
        slot.set(0)
        self.cells.renderMessages()

        self.assertFalse(self.cells.childrenWithExceptions())
    def serviceDisplay(serviceObject,
                       instance=None,
                       objType=None,
                       queryArgs=None):
        c = Configuration.lookupAny(service=serviceObject)

        return Card(Text("Host: " + c.hostname) + Text("Port: " + str(c.port)))
    def serviceDisplay(serviceObject,
                       instance=None,
                       objType=None,
                       queryArgs=None):
        if not current_transaction().db().isSubscribedToType(Happy):
            raise SubscribeAndRetry(lambda db: db.subscribeToType(Happy))

        if instance:
            return instance.display(queryArgs)

        return Card(
            Subscribed(lambda: Text(
                "There are %s happy objects <this should not have lessthans>" %
                len(Happy.lookupAll()))) +
            Expands(
                Text("Closed"),
                Subscribed(lambda: HappyService.serviceDisplay(serviceObject)))
        ) + Button("go to google", "http://google.com/") + SubscribedSequence(
            lambda: Happy.lookupAll(), lambda h: Button(
                "go to the happy", serviceObject.urlForObject(h, x=10))
        ) + Subscribed(lambda: ButtonGroup([
            Button(Octicon("list-unordered"),
                   lambda: None,
                   active=lambda: True),
            Button(Octicon("terminal"), lambda: None, active=lambda: True),
            Button(Octicon("graph"), lambda: None, active=lambda: True)
        ]).nowrap())
    def serviceDisplay(serviceObject,
                       instance=None,
                       objType=None,
                       queryArgs=None):
        ensureSubscribedType(TextEditor)

        toEval = Slot("{'x': [1,2,3,4,5], 'y': [1,5,1,5,1]}")

        def onEnter(buffer, selection):
            toEval.set(buffer)
            TextEditor.lookupAny().code = buffer

        def onTextChange(buffer, selection):
            if TextEditor.lookupAny() is not None:
                TextEditor.lookupAny().code = buffer

        ed = CodeEditor(keybindings={'Enter': onEnter},
                        noScroll=True,
                        minLines=50,
                        onTextChange=onTextChange)

        def makePlotData():
            # data must be a list or dict here, but this is checked/asserted
            # down the line in cells. Sending anything that is not a dict/list
            # will break the entire plot.
            try:
                data = ast.literal_eval(toEval.get())
            except (AttributeError, SyntaxError):
                data = {}
            return {'data': data}

        def onCodeChange():
            if TextEditor.lookupAny() is not None:
                if ed.getContents() != TextEditor.lookupAny().code:
                    ed.setContents(TextEditor.lookupAny().code)

        return Columns(ed, Card(
            Plot(makePlotData).height("100%").width("100%"))) + Subscribed(
                onCodeChange)
Exemplo n.º 7
0
 def test_card_html_valid(self):
     cell = Card("Some text body")
     cell.recalculate()
     html = cell.contents
     self.assertHTMLNotEmpty(html)
     self.assertHTMLValid(html)
Exemplo n.º 8
0
 def serviceDisplay(serviceObject,
                    instance=None,
                    objType=None,
                    queryArgs=None):
     return Card("No details provided for service '%s'" %
                 serviceObject.name)
 def serviceDisplay(serviceObject,
                    instance=None,
                    objType=None,
                    queryArgs=None):
     return Card(
         AsyncDropdown('Dropdown', DropdownTestService.delayAndDisplay))
    def serviceDisplay(serviceObject,
                       instance=None,
                       objType=None,
                       queryArgs=None):
        ensureSubscribedType(PointsToShow)
        ensureSubscribedType(Feigenbaum)
        depth = Slot(50)

        def twinned():
            data = {
                'PointsToShow': {
                    'timestamp': [1500000000 + x for x in range(1000)],
                    'y': [numpy.sin(x) for x in range(1000)]
                }
            }
            slot = Slot(None)
            p1 = Plot(lambda: data, xySlot=slot)
            p2 = Plot(lambda: data, xySlot=slot)

            def synchronize():
                if slot.get() is not None:
                    p1.setXRange(*slot.get()[0])
                    p2.setXRange(*slot.get()[0])

            return p1 + p2 + Subscribed(synchronize)

        return Tabs(
            Overlay=Card(
                Plot(
                    lambda: {
                        'single_array': [1, 2, 3, 1, 2, 3],
                        'xy': {
                            'x': [1, 2, 3, 1, 2, 3],
                            'y': [4, 5, 6, 7, 8, 9]
                        },
                    }).width(600).height(400) + Code("HI")),
            AGrid=Grid(colFun=lambda: ['A', 'B', 'B'],
                       rowFun=lambda: ['1', '2', '2'],
                       headerFun=lambda x: x,
                       rowLabelFun=None,
                       rendererFun=lambda row, col: row + col),
            ASheet=Sheet(
                ["A", "B", "C"], 1000000,
                lambda rowIx: ["(%s) ts" % rowIx, rowIx, rowIx + 1, rowIx + 2]
            ).width('calc(100vw - 70px)').height('calc(100vh - 150px)'),
            Timestamps=(
                Button("Add a point!", GraphDisplayService.addAPoint) +
                Card(Plot(
                    GraphDisplayService.chartData)).width(600).height(400)),
            Twinned=Subscribed(twinned),
            feigenbaum=(Dropdown("Depth", [
                (val, depth.setter(val))
                for val in [10, 50, 100, 250, 500, 750, 1000]
            ]) + Dropdown(
                "Polynomial", [1.0, 1.5, 2.0], lambda polyVal: setattr(
                    Feigenbaum.lookupAny(), 'y', float(polyVal))) + Dropdown(
                        "Density", list(range(100, 10000, 100)),
                        lambda polyVal: setattr(Feigenbaum.lookupAny(
                        ), 'density', float(polyVal))) + Card(
                            Plot(lambda graph: GraphDisplayService.feigenbaum(
                                graph, depth.get()))).width(600).height(400)))