Esempio n. 1
0
    def __init__(self, labels=None, values=None, multi=False, default=None, caption=None):
        """Create a drop down.

        Parameters
        ----------
        labels : array-like, optional
            List of strings which will be visible to the user.
        values : array-like, optional
            List of values associated with the labels that are hidden from the user.
        multi : bool, optional
            If multiple selections are allowed.
        caption : str, optional
            Heading text.

        """
        super(Dropdown, self).__init__(caption=caption)

        if labels is None and values is None:
            labels = []
            values = []

        options = [dict(value=value, label=str(label)) for value, label in zip(values, labels)]

        self._comp = self._tag.format(
            options=jdumps(options),
            multi=jsbool(multi),
            default=jdumps(default),
        )
Esempio n. 2
0
    def __init__(self,
                 labels: Optional[Sequence[str]] = None,
                 values: Optional[Sequence[Union[str, int]]] = None,
                 multi: bool = False,
                 default: Optional[Union[str, int]] = None) -> None:
        """Create a drop down.

        Parameters
        ----------
        labels : array-like, optional
            List of strings which will be visible to the user.
        values : array-like, optional
            List of values associated with the labels that are hidden from the user.
        multi : bool, optional
            If multiple selections are allowed.
        default : str or int, optional
            The default selected value.

        """
        super().__init__()

        if values is not None and labels is not None:
            options = [{
                'value': value,
                'label': str(label)
            } for value, label in zip(values, labels)]
        else:
            options = []

        self._comp = self._tag.format(
            options=jdumps(options),
            multi=jsbool(multi),
            default=jdumps(default),
        )
Esempio n. 3
0
    def __init__(self, labels: Optional[Sequence[str]] = None,
                 values: Optional[Sequence[Union[str, int]]] = None, multi: bool = False,
                 default: Optional[Union[str, int]] = None) -> None:
        """Create a drop down.

        Parameters
        ----------
        labels : array-like, optional
            List of strings which will be visible to the user.
        values : array-like, optional
            List of values associated with the labels that are hidden from the user.
        multi : bool, optional
            If multiple selections are allowed.
        default : str or int, optional
            The default selected value.

        """
        super().__init__()

        if values is not None and labels is not None:
            options = [{'value': value, 'label': str(label)}
                       for value, label in zip(values, labels)]
        else:
            options = []

        self._comp = self._tag.format(
            options=jdumps(options),
            multi=jsbool(multi),
            default=jdumps(default),
        )
Esempio n. 4
0
    def __init__(self, options, multi=False, caption=''):
        super(DropDown, self).__init__()

        # options = [dict(value=x, label=str(x)) for x in options]

        self._instantiate = self._TAG.format(
            options=jdumps(options),
            multi='true' if multi else 'false',
            uuid="'{}'".format(self._uuid))
        self.caption = caption
Esempio n. 5
0
    def __init__(self,
                 labels=None,
                 values=None,
                 multi=False,
                 default=None,
                 caption=''):
        super(DropDown, self).__init__()

        if labels is None and values is None:
            labels = []
            values = []

        options = [
            dict(value=value, label=str(label))
            for value, label in zip(values, labels)
        ]

        self._instantiate = self._TAG.format(
            options=jdumps(options),
            multi='true' if multi else 'false',
            default=jdumps(default),
            uuid="'{}'".format(self._uuid))
        self.caption = caption
Esempio n. 6
0
    def __init__(self,
                 labels=None,
                 values=None,
                 multi=False,
                 default=None,
                 caption=''):
        """Create a drop down.

        Parameters
        ----------
        labels : array-like, optional
            List of strings which will be visible to the user.
        values : array-like, optional
            List of values associated with the labels that are hidden from the user.
        multi : bool, optional
            If multiple selections are allowed.
        caption : str, optional
            Heading text.

        """
        super(Dropdown, self).__init__()

        if labels is None and values is None:
            labels = []
            values = []

        options = [
            dict(value=value, label=str(label))
            for value, label in zip(values, labels)
        ]

        self._instantiate = self._TAG.format(
            options=jdumps(options),
            multi='true' if multi else 'false',
            default=jdumps(default),
            uuid="'{}'".format(self._uuid))
        self.caption = caption
Esempio n. 7
0
    def __init__(self, init: Optional[Dict] = None) -> None:
        """Create a Plotly component.

        Parameters
        ----------
        init : dict, optional
            Initial Plotly data to plot.

        """
        super().__init__()
        if init is None:
            init = dict(data=[], layout={'autosize': False})
        self.init = init

        self._comp = self._tag.format(init=jdumps(self.init))
Esempio n. 8
0
    def __init__(self, init: Optional[Dict] = None) -> None:
        """Create a Plotly component.

        Parameters
        ----------
        init : dict, optional
            Initial Plotly data to plot.

        """
        super().__init__()
        if init is None:
            init = dict(data=[], layout={'autosize': False})
        self.init = init

        self._comp = self._tag.format(
            init=jdumps(self.init)
        )
Esempio n. 9
0
    def __init__(self, columns=None, results_per_page=10):
        """Create the table, optionally set the columns.

        Parameters
        ----------
        columns : list, optional
            List of column names to display.
        results_per_page : int, optional
            Number of rows on each pagination of the table.

        """
        super(SmartGrid, self).__init__()
        if columns is None:
            columns = []
        self.columns = columns
        self.results_per_page = results_per_page

        self._comp = self._tag.format(columns=jdumps(self.columns),
                                      results_per_page=self.results_per_page)
Esempio n. 10
0
 def _instantiate(self):
     return self._TAG.format(
         uuid="'{}'".format(self._uuid),
         init=jdumps(self.init),
     )
Esempio n. 11
0
 def _instantiate(self):
     return self._TAG.format(uuid="'{}'".format(self._uuid),
                             columns=jdumps(self.columns),
                             results_per_page=self.results_per_page)
Esempio n. 12
0
def test_json():
    """Tests json encoding numpy and pandas."""
    assert jdumps(NPARRAY) == jdumps([5, 6])
    assert jdumps(NPSCALAR) == jdumps(5)
    assert jdumps(DATES) == jdumps(
        ['2017-01-01T00:00:00', '2017-01-02T00:00:00'])
Esempio n. 13
0
def test_json():
    """Tests json encoding numpy and pandas."""
    assert jdumps(NPARRAY) == jdumps([5, 6])
    assert jdumps(NPSCALAR) == jdumps(5)
    assert jdumps(DATES) == jdumps(['2017-01-01T00:00:00', '2017-01-02T00:00:00'])