Пример #1
0
        def draw_text(offset_x, offset_y, width, height):
            canvas.paint.text_align = canvas.paint.TextAlign.CENTER
            for row in range(3):
                for col in range(3):
                    text_string = ""
                    text_string = f"{row*3+col+1}"
                    text_rect = canvas.paint.measure_text(text_string)[1]
                    center = Point2d(
                        offset_x + width / 6 + col * width / 3,
                        offset_y + height / 6 + row * height / 3,
                    )

                    background_rect = text_rect.copy()
                    background_rect.center = center
                    background_rect = background_rect.inset(-4)
                    paint.color = "9999995f"
                    paint.style = Paint.Style.FILL
                    canvas.draw_rect(background_rect)

                    paint.color = "00ff00ff"
                    canvas.draw_text(
                        text_string,
                        center.x,
                        center.y + text_rect.height / 2,
                    )
Пример #2
0
 def draw_text(offset_x, offset_y, width, height):
     canvas.paint.text_align = canvas.paint.TextAlign.CENTER
     for row in range(3):
         for col in range(3):
             text_string = ""
             if settings["user.grids_put_one_bottom_left"]:
                 text_string = f"{(2 - row)*3+col+1}"
             else:
                 text_string = f"{row*3+col+1}"
             text_rect = canvas.paint.measure_text(text_string)[1]
             background_rect = text_rect.copy()
             background_rect.center = Point2d(
                 offset_x + width / 6 + col * width / 3,
                 offset_y + height / 6 + row * height / 3,
             )
             background_rect = background_rect.inset(-4)
             paint.color = "9999995f"
             paint.style = Paint.Style.FILL
             canvas.draw_rect(background_rect)
             paint.color = "00ff00ff"
             canvas.draw_text(
                 text_string,
                 offset_x + width / 6 + col * width / 3,
                 offset_y + height / 6 + row * height / 3 +
                 text_rect.height / 2,
             )
 def draw_rulers():
     for (x_pos, align) in [(-3, canvas.paint.TextAlign.RIGHT),
                            (self.rect.width + 3,
                             canvas.paint.TextAlign.LEFT)]:
         canvas.paint.text_align = align
         canvas.paint.textsize = 17
         canvas.paint.color = "ffffffff"
         for row in range(0, self.rows + 1):
             text_string = letters[row % len(letters)] + "_"
             text_rect = canvas.paint.measure_text(text_string)[1]
             background_rect = text_rect.copy()
             background_rect.x = x_pos
             background_rect.y = row * self.field_size + self.field_size / 2 + text_rect.height / 2
             canvas.draw_text(text_string, background_rect.x,
                              background_rect.y)
     for y_pos in [-3, self.rect.height + 3 + 17]:
         canvas.paint.text_align = canvas.paint.TextAlign.CENTER
         canvas.paint.textsize = 17
         canvas.paint.color = "ffffffff"
         for col in range(0, self.columns + 1):
             text_string = "_" + letters[col % len(letters)]
             text_rect = canvas.paint.measure_text(text_string)[1]
             background_rect = text_rect.copy()
             background_rect.x = col * self.field_size + self.field_size / 2
             background_rect.y = y_pos
             canvas.draw_text(text_string, background_rect.x,
                              background_rect.y)
Пример #4
0
 def draw_text(offset_x, offset_y, width, height):
     canvas.paint.text_align = canvas.paint.TextAlign.CENTER
     for row in range(3):
         for col in range(3):
             text_string = f"{row*3+col+1}"
             text_rect = canvas.paint.measure_text(text_string)[1]
             canvas.draw_text(
                 text_string,
                 offset_x + width / 6 + col * width / 3,
                 offset_y + height / 6 + row * height / 3 + text_rect.height / 2,
             )
Пример #5
0
    def draw(self, canvas):
        paint = canvas.paint
        paint.color = "ff0000"
        # for i in range(1, self.cols+1):
        #     canvas.draw_line(self.offset_x + i * self.width // self.cols, self.offset_y, self.offset_x + i * self.width // self.cols,
        #                      self.offset_y + self.height)
        # for i in range(1, self.rows+1):
        #     canvas.draw_line(self.offset_x, self.offset_y + i * self.height // self.rows, self.offset_x + self.width,
        #                      self.offset_y + i * self.height // self.rows)

        for row in range(self.rows):
            for col in range(self.cols):
                canvas.draw_text(
                    f"{row:02d}{col:02d}",
                    self.offset_x + (col) * self.width // (self.cols),
                    self.offset_y + (row + 1) * self.height // (self.rows))
Пример #6
0
    def draw_rich_text(self,
                       canvas,
                       paint,
                       rich_text,
                       x,
                       y,
                       line_padding,
                       single_line=False):
        # Draw text line by line
        text_colour = paint.color
        error_colour = self.theme.get_colour("error_colour", "AA0000")
        warning_colour = self.theme.get_colour("warning_colour", "F75B00")
        success_colour = self.theme.get_colour("success_colour", "00CC00")
        info_colour = self.theme.get_colour("info_colour", "30AD9E")

        current_line = -1
        for index, text in enumerate(rich_text):
            paint.font.embolden = "bold" in text.styles
            paint.font.skew_x = -0.33 if "italic" in text.styles else 0
            paint.color = text_colour
            if "warning" in text.styles:
                paint.color = warning_colour
            elif "success" in text.styles:
                paint.color = success_colour
            elif "error" in text.styles:
                paint.color = error_colour
            elif "notice" in text.styles:
                paint.color = info_colour

            current_line = current_line + 1 if text.x == 0 else current_line
            if single_line and current_line > 0:
                return

            if text.x == 0:
                y += paint.textsize
                if index != 0:
                    y += line_padding

            # Keep this debugging code in here in case we need to test sizes again
            #paint_colour = paint.color
            #paint.color = self.get_random_colour() + "DD"
            #canvas.draw_rect( ui.Rect(x + text.x, y + text.y, text.width, paint.textsize) )
            #paint.color = paint_colour
            canvas.draw_text(text.text, x + text.x, y)
        def draw_text():
            canvas.paint.text_align = canvas.paint.TextAlign.CENTER
            canvas.paint.textsize = 17
            for row in range(0, self.rows + 1):
                skip_it = row % 2 == 0
                for col in range(0, self.columns + 1):
                    skip_it = not skip_it

                    center = Point2d(
                        col * self.field_size + self.field_size / 2,
                        row * self.field_size + self.field_size / 2,
                    )

                    if not skip_it or not self.checkers:
                        text_string = f"{letters[row % len(letters)]}{letters[col % len(letters)]}"
                        text_rect = canvas.paint.measure_text(text_string)[1]
                        background_rect = text_rect.copy()
                        background_rect.center = Point2d(
                            col * self.field_size + self.field_size / 2,
                            row * self.field_size + self.field_size / 2,
                        )
                        background_rect = background_rect.inset(-4)
                        if (self.input_so_far.startswith(
                                letters[row % len(letters)])
                                or len(self.input_so_far) > 1
                                and self.input_so_far.endswith(
                                    letters[col % len(letters)])):
                            canvas.paint.color = setting_row_highlighter.get(
                            ) + hx(self.label_transparency)
                        else:
                            canvas.paint.color = setting_letters_background_color.get(
                            ) + hx(self.label_transparency)
                            canvas.paint.style = Paint.Style.FILL
                        canvas.draw_rect(background_rect)
                        canvas.paint.color = setting_small_letters_color.get(
                        ) + hx(self.label_transparency)
                        #paint.style = Paint.Style.STROKE
                        canvas.draw_text(
                            text_string,
                            col * self.field_size + self.field_size / 2,
                            row * self.field_size + self.field_size / 2 +
                            text_rect.height / 2)
Пример #8
0
def draw_homophones(canvas):
    global active_word_list
    if active_word_list is None:
        return

    paint = canvas.paint
    paint.textsize = font_size
    paint.color = '000000'
    paint.style = paint.Style.FILL
    canvas.draw_rect(Rect(canvas.x, canvas.y, canvas.width, canvas.height))

    line_height = paint.get_fontmetrics(1.5)[0]

    h = active_word_list
    h_string = ['%d . %s' % (i + 1, h[i]) for i in range(len(h))]
    paint.color = 'ffffff'
    for i in range(len(h_string)):
        h = h_string[i]
        canvas.draw_text(h, canvas.x + padding_left,
                         canvas.y + line_height + (i * line_height))
Пример #9
0
    def draw_rich_text(self,
                       canvas,
                       paint,
                       rich_text,
                       x,
                       y,
                       line_padding,
                       single_line=False):
        # Draw text line by line
        text_colour = paint.color
        error_colour = self.theme.get_colour("error_colour", "AA0000")
        warning_colour = self.theme.get_colour("warning_colour", "F75B00")
        success_colour = self.theme.get_colour("success_colour", "00CC00")
        info_colour = self.theme.get_colour("info_colour", "30AD9E")

        current_line = -1
        for index, text in enumerate(rich_text):
            paint.font.embolden = "bold" in text.styles
            paint.font.skew_x = -0.33 if "italic" in text.styles else 0
            paint.color = text_colour
            if "warning" in text.styles:
                paint.color = warning_colour
            elif "success" in text.styles:
                paint.color = success_colour
            elif "error" in text.styles:
                paint.color = error_colour
            elif "notice" in text.styles:
                paint.color = info_colour

            current_line = current_line + 1 if text.x == 0 else current_line
            if single_line and current_line > 0:
                return

            if text.x == 0:
                y += paint.textsize
                if index != 0:
                    y += line_padding

            canvas.draw_text(text.text, x + text.x, y)
Пример #10
0
    def draw(self, canvas):
        paint = canvas.paint
        paint.color = "ff0000"
        canvas.draw_line(self.offset_x + self.width // 3, self.offset_y,
                         self.offset_x + self.width // 3,
                         self.offset_y + self.height)
        canvas.draw_line(self.offset_x + 2 * self.width // 3, self.offset_y,
                         self.offset_x + 2 * self.width // 3,
                         self.offset_y + self.height)

        canvas.draw_line(self.offset_x, self.offset_y + self.height // 3,
                         self.offset_x + self.width,
                         self.offset_y + self.height // 3)
        canvas.draw_line(self.offset_x, self.offset_y + 2 * self.height // 3,
                         self.offset_x + self.width,
                         self.offset_y + 2 * self.height // 3)

        for row in range(3):
            for col in range(3):
                canvas.draw_text(
                    f"{row*3+col+1}",
                    self.offset_x + self.width / 6 + col * self.width / 3,
                    self.offset_y + self.height / 6 + row * self.height / 3)
Пример #11
0
def draw_alphabet(canvas):
    paint = canvas.paint
    paint.textsize = font_size
    paint.color = '333'
    paint.style = paint.Style.FILL
    canvas.draw_rect(Rect(canvas.x, canvas.y, canvas.width, canvas.height))

    line_height = paint.get_fontmetrics(1.5)[0]

    paint.color = 'dedede'

    try:
        from user import std
        alnum = std.alpha_alt
    except:
        # TODO log an error
        alnum = []

    num = 1
    for k, v in zip(alnum, string.ascii_lowercase):
        canvas.draw_text('%s - %s' % (k, v), canvas.x + padding_left,
                         canvas.y + (num * line_height))
        num += 1
    def draw(self, canvas):
        paint = canvas.paint

        # for other-screen or individual-window grids
        canvas.translate(self.rect.x, self.rect.y)
        canvas.clip_rect(
            Rect(-self.field_size * 2, -self.field_size * 2,
                 self.rect.width + self.field_size * 4,
                 self.rect.height + self.field_size * 4))

        crosswidth = 6

        def draw_crosses():
            for row in range(1, self.rows):
                for col in range(1, self.columns):
                    cx = self.field_size * col
                    cy = self.field_size * row

                    canvas.save()
                    canvas.translate(0.5, 0.5)

                    canvas.draw_line(cx - crosswidth + 0.5, cy,
                                     cx + crosswidth - 0.5, cy)
                    canvas.draw_line(cx, cy + 0.5, cx, cy + crosswidth - 0.5)
                    canvas.draw_line(cx, cy - crosswidth + 0.5, cx, cy - 0.5)

                    canvas.restore()

        superblock_size = len(string.ascii_lowercase) * self.field_size

        colors = ["000055", "665566", "554444", "888855", "aa55aa", "55cccc"
                  ] * 100
        num = 1

        self.superblocks = []

        skipped_superblock = self.default_superblock + 1

        if int(self.rect.height) // superblock_size == 0 and int(
                self.rect.width) // superblock_size == 0:
            skipped_superblock = 1

        for row in range(0, int(self.rect.height) // superblock_size + 1):
            for col in range(0, int(self.rect.width) // superblock_size + 1):
                canvas.paint.color = colors[(row + col) % len(colors)] + hx(
                    self.bg_transparency)

                #canvas.paint.color = "ffffff"
                canvas.paint.style = Paint.Style.FILL
                blockrect = Rect(col * superblock_size, row * superblock_size,
                                 superblock_size, superblock_size)
                blockrect.right = min(blockrect.right, self.rect.width)
                blockrect.bot = min(blockrect.bot, self.rect.height)
                canvas.draw_rect(blockrect)

                if skipped_superblock != num:

                    # attempt to change backround color on the superblock chosen

                    #canvas.paint.color = colors[(row + col) % len(colors)] + hx(self.bg_transparency)

                    canvas.paint.color = setting_superblock_background_color.get(
                    ) + hx(self.bg_transparency)
                    canvas.paint.style = Paint.Style.FILL
                    blockrect = Rect(col * superblock_size,
                                     row * superblock_size, superblock_size,
                                     superblock_size)
                    blockrect.right = min(blockrect.right, self.rect.width)
                    blockrect.bot = min(blockrect.bot, self.rect.height)
                    canvas.draw_rect(blockrect)

                    canvas.paint.color = setting_superblock_stroke_color.get(
                    ) + hx(self.bg_transparency)
                    canvas.paint.style = Paint.Style.STROKE
                    canvas.paint.stroke_width = 5
                    blockrect = Rect(col * superblock_size,
                                     row * superblock_size, superblock_size,
                                     superblock_size)
                    blockrect.right = min(blockrect.right, self.rect.width)
                    blockrect.bot = min(blockrect.bot, self.rect.height)
                    canvas.draw_rect(blockrect)

                    #drawing the big number in the background

                    canvas.paint.style = Paint.Style.FILL
                    canvas.paint.textsize = int(superblock_size * 4 / 5)
                    text_rect = canvas.paint.measure_text(str(num))[1]
                    #text_rect.center = blockrect.center
                    text_rect.x = blockrect.x
                    text_rect.y = blockrect.y
                    canvas.paint.color = setting_large_number_color.get() + hx(
                        self.bg_transparency)
                    canvas.draw_text(str(num), text_rect.x,
                                     text_rect.y + text_rect.height)

                self.superblocks.append(blockrect.copy())

                num += 1

        def draw_text():
            canvas.paint.text_align = canvas.paint.TextAlign.CENTER
            canvas.paint.textsize = 17
            for row in range(0, self.rows + 1):
                skip_it = row % 2 == 0
                for col in range(0, self.columns + 1):
                    skip_it = not skip_it

                    center = Point2d(
                        col * self.field_size + self.field_size / 2,
                        row * self.field_size + self.field_size / 2,
                    )

                    if not skip_it or not self.checkers:
                        text_string = f"{letters[row % len(letters)]}{letters[col % len(letters)]}"
                        text_rect = canvas.paint.measure_text(text_string)[1]
                        background_rect = text_rect.copy()
                        background_rect.center = Point2d(
                            col * self.field_size + self.field_size / 2,
                            row * self.field_size + self.field_size / 2,
                        )
                        background_rect = background_rect.inset(-4)
                        if (self.input_so_far.startswith(
                                letters[row % len(letters)])
                                or len(self.input_so_far) > 1
                                and self.input_so_far.endswith(
                                    letters[col % len(letters)])):
                            canvas.paint.color = setting_row_highlighter.get(
                            ) + hx(self.label_transparency)
                        else:
                            canvas.paint.color = setting_letters_background_color.get(
                            ) + hx(self.label_transparency)
                            canvas.paint.style = Paint.Style.FILL
                        canvas.draw_rect(background_rect)
                        canvas.paint.color = setting_small_letters_color.get(
                        ) + hx(self.label_transparency)
                        #paint.style = Paint.Style.STROKE
                        canvas.draw_text(
                            text_string,
                            col * self.field_size + self.field_size / 2,
                            row * self.field_size + self.field_size / 2 +
                            text_rect.height / 2)

        def draw_rulers():
            for (x_pos, align) in [(-3, canvas.paint.TextAlign.RIGHT),
                                   (self.rect.width + 3,
                                    canvas.paint.TextAlign.LEFT)]:
                canvas.paint.text_align = align
                canvas.paint.textsize = 17
                canvas.paint.color = "ffffffff"
                for row in range(0, self.rows + 1):
                    text_string = letters[row % len(letters)] + "_"
                    text_rect = canvas.paint.measure_text(text_string)[1]
                    background_rect = text_rect.copy()
                    background_rect.x = x_pos
                    background_rect.y = row * self.field_size + self.field_size / 2 + text_rect.height / 2
                    canvas.draw_text(text_string, background_rect.x,
                                     background_rect.y)
            for y_pos in [-3, self.rect.height + 3 + 17]:
                canvas.paint.text_align = canvas.paint.TextAlign.CENTER
                canvas.paint.textsize = 17
                canvas.paint.color = "ffffffff"
                for col in range(0, self.columns + 1):
                    text_string = "_" + letters[col % len(letters)]
                    text_rect = canvas.paint.measure_text(text_string)[1]
                    background_rect = text_rect.copy()
                    background_rect.x = col * self.field_size + self.field_size / 2
                    background_rect.y = y_pos
                    canvas.draw_text(text_string, background_rect.x,
                                     background_rect.y)

        #paint.color = "00ff004f"
        #draw_crosses()
        paint.color = "ffffffff"

        #paint.stroke_width = 1
        #paint.color = "ff0000ff"

        draw_text()

        if self.rulers:
            draw_rulers()
Пример #13
0
def _draw(canvas: canvas.Canvas):
    paint = canvas.paint
    paint.textsize = 36
    canvas.clear("ffffff00")
    paint.color = "ffffffff"
    canvas.draw_text(text, canvas.x + 30, canvas.y + 30)