Example #1
0
def main(event):
    """Main UI initialization code that generates the base HTML for the web application"""

    # Create the view and container that will parent our widgets
    v = View()
    c = Container()

    # Create a row with a little spacing from the top
    r = Row(style="padding-top:20px;")

    # Make the toolbar that will contain the Step Into / Next, Stop and Step Over / Out buttons
    tb = ButtonToolbar(cl="pull-right", style="margin-top:-7px;")
    tb.addelement(Button("Next", ident="code-next-button"))
    tb.addelement(Button("Stop", ident="code-stop-button"))
    tb.addelement(Button("Step Over", ident="code-over-button"))

    # Create the span that will contain the short description of where we're at in code execution
    title = Span("", ident="code-panel-title")

    # Add the panel with the previous title and space for showing the code
    p = Panel(heading=True, ident="code")
    p.setheading(str(title) + str(tb))
    p.addelement(Paragraph())

    # Make a large 8-wide Bootstrap column to house our panel
    col = Column('lg', 8)

    # Add the panel to the column, to the row, to the container and view
    col.addelement(p)
    r.addelement(col)
    c.addelement(r)
    v.addelement(c)

    # Load the HTML generated from this widget structure onto the browser
    app.load(str(v))
Example #2
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.label_text = kwargs.get('label', '')
        self.initial = kwargs.get('initial', '')
        self.hidden = kwargs.get('hidden', True)
        self.input_type = kwargs.get('input_type', 'text')
        if self.hidden:
            cl = 'panel hidden'
        else:
            cl = 'panel'
        self.widget = Div(cl=cl, attrs=self.get_data_id_attr())
        body = Div(cl='panel-body')

        grp = Div(cl='input-group')
        self.label_widget = Span(
            text=self.label_text,
            cl='input-group-addon',
            attrs=self.get_data_id_attr('label'),
        )
        attrs = self.get_data_id_attr('input')
        attrs['value'] = self.initial
        self.input_widget = Input(
            inputtype=self.input_type,
            attrs=attrs,
        )
        grp.addelement(self.label_widget)
        grp.addelement(self.input_widget)
        body.addelement(grp)

        btngrp = ButtonGroup()
        self.ok_btn = Button(text='Ok',
                             cl='text-edit-btn',
                             severity='primary',
                             attrs=self.get_data_id_attr('ok'))
        self.cancel_btn = Button(text='Cancel',
                                 cl='text-edit-btn',
                                 attrs=self.get_data_id_attr('cancel'))
        btngrp.addelement(self.ok_btn)
        btngrp.addelement(self.cancel_btn)
        body.addelement(btngrp)

        self.widget.addelement(body)

        self.bind(
            label_text=self.on_label_text,
            initial=self.on_initial,
            hidden=self.on_hidden,
        )
        self.app.register('load', self.on_app_load)
Example #3
0
    def build_view(self):
        self.input_buttons = InputButtons(vidhub_view=self,
                                          vidhub=self.vidhub,
                                          app=self.app)
        self.output_buttons = OutputButtons(vidhub_view=self,
                                            vidhub=self.vidhub,
                                            app=self.app)
        self.preset_buttons = PresetButtons(vidhub=self.vidhub, app=self.app)

        row = Row()
        col = Column(count=4)
        h = PageHeader(text=str(self.vidhub.device_id),
                       ident='vidhub_device_name')
        col.addelement(h)
        row.addelement(col)

        col = Column(count=4)
        col.addelement(self.edit_widget.widget)
        col.addelement(self.edit_vidhub_btn)
        row.addelement(col)

        col = Column(count=4, ident='connection_container')
        if self.vidhub.connected:
            cl = 'glyphicon glyphicon-ok-circle'
        else:
            cl = 'glyphicon glyphicon-ban-circle'
        ico = self.connection_icon = Span(cl=cl,
                                          ident='connection_icon',
                                          attrs={'aria-hidden': 'true'})
        btn = self.connection_btn = Button(
            severity='warning' if not self.vidhub.connected else 'success',
            ident='connection_btn',
        )
        btn._parent = col
        btn._children.append(
            'Connect ' if not self.vidhub.connected else 'Disconnect ')
        btn.addelement(ico)
        col.addelement(btn)
        row.addelement(col)
        self.widget.addelement(row)

        row = Row()
        col = Column(count=12)
        row.addelement(col)
        col.addelement(self.input_buttons.widget)
        self.widget.addelement(row)
        row = Row()
        col = Column(count=12)
        row.addelement(col)
        col.addelement(self.output_buttons.widget)
        self.widget.addelement(row)
        row = Row()
        col = Column(count=12)
        row.addelement(col)
        col.addelement(self.preset_buttons.widget)
        self.widget.addelement(row)
        if self.app.loaded:
            self.app.replace(self.get_selector(), str(self.widget))
Example #4
0
    def build_buttons(self):
        assert len(self.buttons) == 0
        num_buttons = getattr(self.vidhub, self.num_buttons_property)
        if len(self.button_states) != num_buttons:
            self.button_states = [False] * num_buttons
        btns_per_row = int(num_buttons // 2)
        btngrp = ButtonGroup(justified=True)
        self.widget.addelement(btngrp)
        for i in range(num_buttons):
            if i % btns_per_row == 0:
                btngrp = ButtonGroup(justified=True)
                self.widget.addelement(btngrp)
            try:
                lbl = getattr(self.vidhub, self.label_property)[i]
            except IndexError:
                lbl = ''
            state = self.button_states[i]
            if state:
                severity = 'primary'
            else:
                severity = 'default'
            btn = Button(text=lbl,
                         severity=severity,
                         attrs=self.get_data_id_attr(i))
            self.buttons.append(btn)
            btngrp.addelement(btn)

        btngrp = ButtonGroup()
        self.edit_enable_btn = Button(text='Edit Name',
                                      attrs=self.get_data_id_attr('edit'))
        btngrp.addelement(self.edit_enable_btn)
        self.widget.addelement(btngrp)

        self.edit_widget = InlineTextEdit(app=self.app)
        self.edit_widget.bind(
            value=self.on_edit_widget_value,
            hidden=self.on_edit_widget_hidden,
        )
        self.widget.addelement(self.edit_widget.widget)

        self.bind(
            button_states=self.on_button_state,
            edit_enable=self.on_edit_enable,
        )
Example #5
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.input_buttons = None
     self.output_buttons = None
     self.preset_buttons = None
     self.widget = Container(attrs=self.get_data_id_attr())
     self.edit_widget = InlineTextEdit(app=self.app)
     self.edit_widget.bind(
         value=self.on_edit_widget_value,
         hidden=self.on_edit_widget_hidden,
     )
     self.edit_vidhub_btn = Button(text='Rename', ident='edit_vidhub_btn')
     self.connection_icon = None
     self.connection_btn = None
     self.bind(
         vidhub=self.on_vidhub,
         edit_enable=self.on_edit_enable,
     )
     self.vidhub = kwargs.get('vidhub')
Example #6
0
async def oninit(event):
    logging.info("INIT")
    v = View("Sample Sofi Widget Application")

    n = Navbar(brand="SOFI", fixed='top')
    n.addlink("LINK 1")
    n.addlink("LINK 2")
    n.addtext("Just some Text with a " + str(Anchor("link", cl='navbar-link')))
    n.addlink("LINK 2", active=True)

    b = Dropdown("Dropdown", align='right')
    b.addelement(DropdownItem('Item Header', header=True))
    b.addelement(DropdownItem('Item 1'))
    b.addelement(DropdownItem('Item 2', disabled=True))
    b.addelement(DropdownItem('', divider=True))
    b.addelement(DropdownItem('Item 3'))

    n.adddropdown(b)

    v.addelement(n)

    c = Container()
    tb = ButtonToolbar()
    bgrp = ButtonGroup()
    btnDe = Button("Default")
    btnP = Button("Primary", "primary", ident='primary')
    btnI = Button("Info", "info")
    bgrp2 = ButtonGroup()
    btnS = Button("Success", "success", ident='secondary')
    btnW = Button("Warning", "warning")
    btnDa = Button("Danger", "danger")

    r = Row()
    bgrp.addelement(btnDe)
    bgrp.addelement(btnP)
    bgrp.addelement(btnI)
    bgrp2.addelement(btnS)
    bgrp2.addelement(btnW)
    bgrp2.addelement(btnDa)
    tb.addelement(bgrp)
    tb.addelement(bgrp2)
    r.addelement(tb)
    c.addelement(r)

    c.newrow(Heading(2, "Dude!"))
    c.newrow(Paragraph("Where's My Car?", ident="fiddle"))

    bd = ButtonDropdown('A Dropdown', size='xs', dropup=True, split=True, severity="success")
    bd.addelement(DropdownItem('Item Header', header=True))
    bd.addelement(DropdownItem('Item 1'))
    bd.addelement(DropdownItem('Item 2', disabled=True))
    bd.addelement(DropdownItem('', divider=True))
    bd.addelement(DropdownItem('Item 3'))
    c.newrow(bd)

    r = Row()
    col = Column(count=3)
    p = Panel("Panel 1")
    col.addelement(p)
    r.addelement(col)

    col = Column(count=3)
    p = Panel("Panel 2", 'danger')
    col.addelement(p)
    r.addelement(col)

    c.newrow(Paragraph())
    c.addelement(r)

    v.addelement(c)

    app.load(str(v), event['client'])
Example #7
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.vidhub = kwargs.get('vidhub')
        self.widget = Container(attrs=self.get_data_id_attr())
        h = Heading(text='Presets')
        self.widget.addelement(h)
        row = Row()
        col = Column(count=12)
        btngrp = ButtonGroup(justified=True)
        for i in range(self.num_presets):
            try:
                preset = self.vidhub.presets[i]
                preset.bind(name=self.on_preset_name)
                name = preset.name
                active = preset.active
            except IndexError:
                name = str(i + 1)
                active = False
            attrs = self.get_data_id_attr(i)
            if active:
                severity = 'primary'
            else:
                severity = 'default'
            btn = Button(text=name,
                         cl='preset-btn',
                         severity=severity,
                         attrs=attrs)
            btngrp.addelement(btn)
            self.preset_buttons.append(btn)
        col.addelement(btngrp)
        row.addelement(col)
        self.widget.addelement(row)

        row = Row()
        col = Column(count=4)
        btngrp = ButtonGroup()
        self.edit_enable_btn = Button(text='Edit Name',
                                      attrs=self.get_data_id_attr('edit'))
        self.record_enable_btn = Button(text='Record',
                                        attrs=self.get_data_id_attr('record'))
        btngrp.addelement(self.edit_enable_btn)
        btngrp.addelement(self.record_enable_btn)
        col.addelement(btngrp)
        row.addelement(col)

        col = Column(count=4)
        self.edit_widget = InlineTextEdit(app=self.app)
        self.edit_widget.bind(
            value=self.on_edit_widget_value,
            hidden=self.on_edit_widget_hidden,
        )
        col.addelement(self.edit_widget.widget)
        row.addelement(col)

        self.widget.addelement(row)

        self.bind(
            edit_enable=self.on_edit_enable,
            record_enable=self.on_record_enable,
        )
        self.vidhub.bind(
            on_preset_added=self.on_preset_added,
            on_preset_active=self.on_preset_active,
        )
Example #8
0
def test_danger_severity_large():
    assert(str(Button("text", "danger", "large")) == "<button class=\"btn btn-danger btn-lg\" type=\"button\">text</button>")
Example #9
0
def test_info_severity_small():
    assert(str(Button("text", "info", "small")) == "<button class=\"btn btn-info btn-sm\" type=\"button\">text</button>")
Example #10
0
def test_custom_class_ident_and_style():
    assert(str(Button("text", cl='abclass', ident='123', style="font-size:0.9em;"))
           == "<button id=\"123\" class=\"btn btn-default abclass\" type=\"button\" style=\"font-size:0.9em;\">text</button>")
Example #11
0
def test_basic():
    assert(str(Button("text")) == "<button class=\"btn btn-default\" type=\"button\">text</button>")
Example #12
0
def test_warning_severity():
    assert(str(Button("text", "warning")) == "<button class=\"btn btn-warning\" type=\"button\">text</button>")
Example #13
0
def test_success_severity():
    assert(str(Button("text", "success")) == "<button class=\"btn btn-success\" type=\"button\">text</button>")
Example #14
0
def test_primary_severity_xsmall():
    assert(str(Button("text", "primary", "xsmall")) == "<button class=\"btn btn-primary btn-xs\" type=\"button\">text</button>")