Exemplo n.º 1
0
    def on_draw(self, widget, ctx):
        try:
            rect = self.get_allocation()

            # setup the clipping area
            utils_gui.rounded_rectangle(ctx,
                                        0, 0,
                                        rect.width, rect.height,
                                        self.corner_rounding)
            ctx.clip()

            # I don't want to copy-paste draw_background() and draw-label()
            # from the base class there, so coalesce both "hover" and
            # "popup_open" states in one so that the hover background stays
            # active even when the popup menu is open.
            old_hover = self.hover
            self.hover = self.hover or self.__popup_open

            self.draw_background(ctx, rect)
            self.draw_icon(ctx)
            self.draw_label(ctx)

            # Restore old state
            self.hover = old_hover

            # Draw the custom popup indicator
            if self.__enable_popup and (self.hover or self.__popup_open):
                self.__draw_popup_indicator(ctx)

        except Exception as exception:
            logging.error('Could not draw a ProgramButton widget: %s',
                          str(exception))

        # return True to prevent default event processing
        return True
Exemplo n.º 2
0
 def draw_background(self, ctx, rect):
     if not self.disabled and self.hover:
         utils_gui.rounded_rectangle(ctx, 0, 0, rect.width, rect.height,
                                     self.corner_rounding)
         ctx.set_source_rgba(self.background_color[0],
                             self.background_color[1],
                             self.background_color[2], 1.0)
         ctx.fill()
Exemplo n.º 3
0
    def on_draw(self, widget, ctx):
        try:
            rect = self.get_allocation()

            # setup the clipping area
            utils_gui.rounded_rectangle(ctx, 0, 0, rect.width, rect.height,
                                        self.corner_rounding)
            ctx.clip()

            self.draw_background(ctx, rect)
            self.draw_icon(ctx)
            self.draw_label(ctx)
        except Exception as exception:
            logging.error('Could not draw a HoverIconButton widget: %s',
                          str(exception))

        # return True to prevent default event processing
        return True
Exemplo n.º 4
0
    def __draw_popup_indicator(self, ctx):
        # Background
        ctx.save()

        if self.__popup_hover:
            ctx.set_source_rgba(0.0, 1.0, 1.0, 1.0)
        else:
            ctx.set_source_rgba(0.0, 1.0, 1.0, 0.25)

        utils_gui.rounded_rectangle(ctx,
                                    x=self.__indicator_x1,
                                    y=self.__indicator_y1,
                                    width=self.INDICATOR_WIDTH,
                                    height=self.INDICATOR_HEIGHT,
                                    radius=3.0)
        ctx.fill()
        ctx.restore()

        # Foreground
        ctx.save()

        if self.__popup_hover:
            ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
        else:
            ctx.set_source_rgba(0.0, 0.0, 0.0, 0.5)

        dot_radius = 2
        dot_spacing = 5.0
        dots_x = self.__indicator_x1 + (self.INDICATOR_WIDTH / 2)
        dots_y = self.__indicator_y1 + (self.INDICATOR_HEIGHT / 4) + 1

        ctx.arc(dots_x, dots_y, dot_radius, 0.0, math.pi * 2.0)
        dots_y += dot_radius + dot_spacing
        ctx.arc(dots_x, dots_y, dot_radius, 0.0, math.pi * 2.0)
        dots_y += dot_radius + dot_spacing
        ctx.arc(dots_x, dots_y, dot_radius, 0.0, math.pi * 2.0)
        ctx.fill()

        ctx.restore()