示例#1
0
    def powered(self,
                by=None,
                width=(100, "%"),
                height=(None, "px"),
                options=None,
                profile=None):
        """
    Description:
    ------------
    Display badges for the specifies JavaScript modules.

    Tip: If by is None. This will display only the main JavaScript module with the current version.
    It will not display the underlying components.

    This component needs to be called at the end to ensure all the imported will be registered.

    :tags:
    :categories:

    Attributes:
    ----------
    :param by: List. Optional. Name of JavaScript library aliases.
    :param width: Tuple. Optional. A tuple with the integer for the component width and its unit.
    :param height: Tuple. Optional. A tuple with the integer for the component height and its unit.
    :param options: Dictionary. Optional. Specific Python options available for this component.
    :param profile: Boolean | Dictionary. Optional. A flag to set the component performance storage.
    """
        container = self.page.ui.div(width=width,
                                     options=options,
                                     profile=profile)
        container.style.css.font_factor(-4)
        if by is None:
            by = sorted(list(self.page.jsImports))
        elif by is True:
            by = []
            for alias, pkg in Imports.JS_IMPORTS.items():
                if "node_folder" not in pkg:
                    by.append(alias)
        for i, b in enumerate(by):
            if b in self.page.imports.jsImports:
                if not self.page.imports.jsImports[b]["versions"]:
                    continue

                badge = self.page.ui.div([
                    self.page.ui.text(
                        b.capitalize(), height=height, profile=profile),
                    self.page.ui.text(
                        "v%s" % self.page.imports.jsImports[b]["versions"][0],
                        height=height,
                        profile=profile)
                ],
                                         width="auto",
                                         profile=profile)
                badge[0].style.css.margin_right = 5
                badge[0].goto(self.page.imports.website(b), target="_blank")
                badge[0].style.css.background = Colors.randColor(
                    self.page.py.hash(b))
                badge[0].style.css.color = "white"
                badge[0].style.css.text_shadow = "1px 1px black"
                badge[0].style.css.padding = "0 5px"
                badge[0].style.css.border_right = "1px solid black"
                badge[1].style.css.padding = "0 5px 0 0"
                badge.style.css.border = "1px solid %s" % self.page.theme.greys[
                    5]
                badge.style.css.margin = 2
                badge.style.css.border_radius = "0 10px 10px 0"
                container.add(badge)
        html.Html.set_component_skin(container)
        return container
示例#2
0
    def avatar(self,
               text="",
               image="",
               path=None,
               status=None,
               width=(30, "px"),
               height=(30, "px"),
               align="center",
               htmlCode=None,
               profile=None,
               options=None):
        """
    Description:
    ------------
    Generate or load an avatar

    Usage::

      rptObj.ui.images.avatar("Epyk", status='out')
      rptObj.ui.images.avatar(image="epykIcon.PNG", path=config.IMG_PATH, status=False)

    Underlying HTML Objects:

      - :class:`epyk.core.html.HtmlContainer.Div`
      - :class:`epyk.core.html.HtmlImage.Image`

    Templates:

      https://github.com/epykure/epyk-templates/blob/master/locals/components/image.py

    Attributes:
    ----------
    :param text:
    :param image:
    :param path:
    :param status:
    :param width: Optional. Tuple. The component width in pixel or percentage
    :param height: Optional. Tuple. The component height in pixel or percentage
    :param align: String. Optional. A string with the horizontal position of the component
    :param htmlCode: String. Optional. An identifier for this component (on both Python and Javascript side)
    :param profile: Boolean or Dictionary. Optional. A flag to set the component performance storage
    :param options: Dictionary. Optional. Specific Python options available for this component
    """
        width = Arguments.size(width, "px")
        height = Arguments.size(height, "px")
        options = options or {}
        status_map = {
            True: self.context.rptObj.theme.success[1],
            'available': self.context.rptObj.theme.success[1],
            False: self.context.rptObj.theme.danger[1],
            'busy': self.context.rptObj.theme.danger[1],
            'out': self.context.rptObj.theme.warning[1]
        }

        bgcolor, margin_top = None, -5
        if image is not None:
            img = self.img(image,
                           path, (width[0] - 5, width[1]),
                           (height[0] - 5, height[1]),
                           align="center",
                           htmlCode=htmlCode,
                           profile=profile,
                           options=options)
            img.style.css.border_radius = width[0]
            img.style.css.margin = 2
            margin_top = -8
        else:
            bgcolor = Colors.randColor(self.context.rptObj.py.hash(text))
            img = self.context.rptObj.ui.layouts.div(text[0].upper())
            img.style.css.line_height = width[0] - 5
            img.style.css.color = "white"
            img.style.css.font_size = width[0]
            img.style.css.font_weight = 'bold'
            img.style.css.padding = 0
        img.style.css.middle()
        if options.get('status', True):
            status_o = self.context.rptObj.ui.layouts.div(" ",
                                                          width=(10, "px"),
                                                          height=(10, "px"))
            status_o.style.css.position = 'relative'

            status_o.style.css.background_color = status_map.get(
                status, self.context.rptObj.theme.greys[5])
            status_o.style.css.border_radius = 10
            status_o.style.css.margin_top = margin_top
            status_o.style.css.float = 'right'

            div = self.context.rptObj.ui.layouts.div([img, status_o],
                                                     width=width,
                                                     height=height)
            div.status = status_o
        else:
            div = self.context.rptObj.ui.layouts.div([img],
                                                     width=width,
                                                     height=height)
        if bgcolor is not None:
            div.style.css.background_color = bgcolor
            div.style.css.text_stoke = "1px %s" % bgcolor
        div.img = img
        div.style.css.borders_light()
        div.style.css.border_radius = width[0]
        div.img = img
        if align == 'center':
            div.style.css.margin = "auto"
            div.style.css.display = "block"
        return div