Esempio n. 1
0
    def draw(self, gc: wx.GraphicsContext):
        if not self.message:
            return
        alpha = 255
        if self.countdown <= 20:
            alpha = int(self.countdown * 12.5)
        self.set_alpha(alpha)

        width = self.right - self.left
        height = self.bottom - self.top
        text_size = height

        while self.text_height > height or self.text_width > width:
            # If we do not fit in the box, decrease size
            text_size *= 0.9
            try:
                self.font.SetFractionalPointSize(text_size)
            except AttributeError:
                self.font.SetPointSize(int(text_size))
            gc.SetFont(self.font, self.font_color)
            self.text_width, self.text_height = gc.GetTextExtent(self.message)
        if text_size == height:
            gc.SetFont(self.font, self.font_color)
        gc.SetPen(self.pen)
        gc.SetBrush(self.brush)
        gc.DrawRectangle(self.left, self.top, self.right - self.left,
                         self.bottom - self.top)

        toast_x = self.left + (width - self.text_width) / 2.0
        toast_y = self.top
        gc.DrawText(self.message, toast_x, toast_y)
Esempio n. 2
0
    def process_draw(self, gc: wx.GraphicsContext):
        # Draw Box
        gc.SetBrush(wx.TRANSPARENT_BRUSH)
        gc.SetPen(self.checkline_pen)
        gc.DrawRectangle(self.left, self.top, self.right - self.left,
                         self.bottom - self.top)
        if self.value:
            # Draw Check
            gc.SetPen(self.checkline_pen)
            check = [(0.2, 0.5), (0.4, 0.75), (0.8, 0.2)]
            for i in range(len(check)):
                x, y = check[i]
                check[i] = towards(self.left, self.right,
                                   x), towards(self.top, self.bottom, y)
            gc.DrawLines(check)

        if self.text:
            height = self.bottom - self.top
            width = self.right - self.left
            text_size = height * 3.0 / 4.0  # px to pt conversion
            try:
                self.font.SetFractionalPointSize(text_size)
            except AttributeError:
                self.font.SetPointSize(int(text_size))
            gc.SetFont(self.font, self.font_color)
            gc.DrawText(self.text, self.right + width * self._text_gap,
                        self.top)
Esempio n. 3
0
    def do_paint(self, gc: wx.GraphicsContext):
        if self.gfont is None or self.font_scale != cstate.scale:
            self.font_scale = cstate.scale
            font = wx.Font(wx.FontInfo(10 * cstate.scale))
            self.gfont = gc.CreateFont(font, wx.BLACK)
        gc.SetFont(self.gfont)

        s_aligned_rect = self.node.s_rect.aligned()
        aligned_border_width = max(
            even_round(self.node.border_width * cstate.scale), 2)
        width, height = s_aligned_rect.size
        draw_rect(
            gc,
            s_aligned_rect,
            fill=self.node.fill_color,
            border=self.node.border_color,
            border_width=aligned_border_width,
        )

        # draw text
        tw, th, _, _ = gc.GetFullTextExtent(
            self.node.id_)  # optimize by caching?
        tx = (width - tw) / 2
        ty = (height - th) / 2
        gc.DrawText(self.node.id_, self.node.s_position.x + tx,
                    self.node.s_position.y + ty)
Esempio n. 4
0
 def process_draw(self, gc: wx.GraphicsContext):
     if self.cam.frame_bitmap is None:
         font = wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)
         gc.SetFont(font, wx.BLACK)
         if self.cam.camera is None:
             gc.DrawText(
                 _("Camera backend failure...\nCannot attempt camera connection."
                   ),
                 0,
                 0,
             )
         else:
             gc.DrawText(_("Fetching Frame..."), 0, 0)