def create_shadowed_background(self, *args):
     focus_window_pos, focus_window_size = self.calculate_focus_window_pos_n_size(
     )
     focus_window_width, focus_window_height = focus_window_size[
         0], focus_window_size[1]
     focus_window_x, focus_window_y = focus_window_pos[0], focus_window_pos[
         1]
     window_width, window_height = self.screen_utils.window.size[
         0], self.screen_utils.window.size[1]
     background = InstructionGroup()
     background.add(Color(0, 0, 0, 0.5))
     background.add(
         Rectangle(pos=(0, 0), size=(focus_window_x, window_height)))
     background.add(
         Rectangle(pos=(focus_window_x, 0),
                   size=(window_width - focus_window_x, focus_window_y)))
     background.add(
         Rectangle(pos=(focus_window_x,
                        focus_window_y + focus_window_height),
                   size=(window_width - focus_window_x, window_height -
                         focus_window_y - focus_window_height)))
     background.add(
         Rectangle(pos=(focus_window_x + focus_window_width,
                        focus_window_y),
                   size=(window_width - focus_window_width - focus_window_x,
                         focus_window_height)))
     self.background = background
     self.canvas.before.add(background)
Beispiel #2
0
    def show_solution(self, present):
        if present is None:
            self.add_widget(
                Label(text="No solution", color=(0, 1, 0, 1), size=self.size))
            return

        with self.canvas:
            Color(0, 0, 0, 1)

            Rectangle(pos=(0, 0), size=self.size)
            height = len(present)
            width = len(present[0])

            self.grid_layout.cols = height
            self.grid_layout.rows = width

            for x in range(width):
                for y in range(height):
                    symbol = present[y][x]

                    if symbol != '#':
                        Color(0, 1, 0, 1)
                        text = "" if symbol == "&&" else symbol
                        label = CoreLabel(text=text, font_size=20)
                        label.refresh()

                        coord_x = x * self.CELL_SIZE + self.OFFSET
                        top_offset = (y + 1) * self.CELL_SIZE
                        coord_y = self.height - top_offset + self.OFFSET

                        Rectangle(pos=(coord_x, coord_y),
                                  texture=label.texture,
                                  size=label.texture.size)
                        self.draw_empty_rectangle(x, self.height - top_offset)
Beispiel #3
0
    def update_canvas(
        self,
        instance_fadind_edge_effect,
        size: list[int, int],
        rectangle_top: Rectangle,
        rectangle_bottom: Rectangle,
        index: int,
    ) -> None:
        """
        Updates the position and size of the fade border on the canvas.
        Called when the application screen is resized.
        """

        height_segment = (self.fade_height if self.fade_height else
                          dp(100)) // self._height_segment

        if rectangle_top:
            rectangle_top.pos = (
                instance_fadind_edge_effect.x,
                size[1] -
                (index * height_segment - instance_fadind_edge_effect.y),
            )
            rectangle_top.size = (size[0], height_segment)
        if rectangle_bottom:
            rectangle_bottom.pos = (
                instance_fadind_edge_effect.x,
                index * height_segment + instance_fadind_edge_effect.y,
            )
            rectangle_bottom.size = (size[0], height_segment)
Beispiel #4
0
    def update(self, dt):
        self.gold = f'Gold: {self._game.current_level.gold}\n'
        self.hp = f'Hp: {self._game.current_level.hp}\n'
        self.wave = f'Wave: {self.game.current_level.current_wave}\n'

        with self.canvas:
            self.canvas.clear()
            Rectangle(pos=(0, 0), size=Window.size,
                      source=self._game.current_level.map_path)

            for obj in sorted(GameObject.objects, key=lambda o: -o.location.y):
                pos = obj.location
                img = Image(obj.sprite_path)
                offset = Vector(obj.direction * -img.width / 2,
                                -img.height / 2)

                offset += obj.graphics_offset
                size = (obj.direction * img.width, img.height)
                Rectangle(texture=img.texture, pos=pos + offset, size=size)

                if not obj.friendly:
                    hp_percent = obj.hp / obj.max_hp
                    offset_percent = (1 - hp_percent) / 2

                    hp_bar_size = (size[0] * hp_percent, 3)
                    hp_bar_pos = pos + (size[0] * offset_percent, -5)
                    self._set_hp_bar_color(hp_percent)
                    Rectangle(pos=hp_bar_pos + offset, size=hp_bar_size)
                    Color(1, 1, 1)
Beispiel #5
0
 def update_canvas(self, *args):
     self.canvas.after.clear()  # TODO mirar si es necesario si no pintamos
     self.canvas.before.clear()
     for p in self.horario.pasadas_widget():
         with self.canvas.before:
             y = self.y + self.height \
                 - p['start'] * self.height - p['len'] * self.height
             h = p['len'] * self.height
             pos = (self.x, y)
             size = (self.width, h)
             if p['task'] == 'Ejecutivo':
                 # color = get_color_from_hex('#FF880088')
                 color = get_color_from_hex('#888888')
             elif p['task'] == 'Ayudante':
                 # color = get_color_from_hex('#CC000088')
                 color = get_color_from_hex('#444444')
             if p['task'] != 'Libre':
                 Color(*color)
                 Rectangle(pos=pos, size=size)
         with self.canvas.after:
             Color(1, 1, 1)
             # Line(rectangle=pos+size)
     with self.canvas.before:
         h = 10
         pos = (self.x,
                self.y + self.height - self.timepos * self.height - h / 2)
         size = (self.width, h)
         self.tpc = Color(1, .1, .1, self.alpha)
         # Color(self.alpha, self.alpha, self.alpha, 1)
         self.tp = Rectangle(pos=pos, size=size)
 def set_state(self, *args):
     if self.state == 'down':
         with self.canvas.before:
             Color(50 / 255.0, 164 / 255.0, 206 / 255.0,
                   1)  # Button down colour
             Rectangle(pos=self.pos, size=self.size)
             Color(111 / 255.0, 111 / 255.0, 111 / 255.0,
                   1)  # Button hover outline colour
             Line(rectangle=(self.x + 1, self.y + 1, self.width - 1,
                             self.height - 1),
                  width=1)
     else:
         if self.hovered:
             with self.canvas.before:
                 Color(88 / 255.0, 88 / 255.0, 88 / 255.0,
                       1)  # Button hover colour
                 Rectangle(pos=self.pos, size=self.size)
                 Color(111 / 255.0, 111 / 255.0, 111 / 255.0,
                       1)  # Button hover outline colour
                 Line(rectangle=(self.x + 1, self.y + 1, self.width - 1,
                                 self.height - 1),
                      width=1)
         else:
             with self.canvas.before:  # Button up colour
                 Color(53 / 255.0, 53 / 255.0, 53 / 255.0, 1)
                 Rectangle(pos=self.pos, size=self.size)
Beispiel #7
0
 def __init__(self, app):
     super(World, self).__init__()
     self.size_hint = None, None
     self.size = SIZE
     self.pos_hint = {'center': (.5, 5)}
     self.hive = None
     self.rocks = []
     self.add_ground()
     w, h = SIZE
     with self.canvas:
         ground_fbo = Fbo(size=self.size)
         Rectangle(pos=(0, 0),
                   size=(w * 2, h * 2),
                   texture=ground_fbo.texture)
         Rectangle(pos=(0, 0), size=(w * 2, h * 2), texture=app.texture)
         Rectangle(pos=(0, 0),
                   size=(w * 2, h * 2),
                   texture=app.returning_paths_texture)
     with ground_fbo:
         Color(*STONE_COLOR_FLOAT)
         Line(rectangle=[0, 0, w, h], width=4)
         for rock in self.rocks:
             Line(points=rock.points, close=False, width=4)
         ground_fbo.draw()
     turn_to_world_array(ground_fbo.texture.pixels)
     self.populate()
Beispiel #8
0
def canvas_add(instance, color=None, pos=(0, 0), shift=None, source=None):
    '''Добавляет canvas в объект.

    :type shift: tuple;
    :param shift: например, (2.5, 3) - сдвиг по вертикали и горизонтали,
                  когда нужно создать имитацию тени;
    '''

    with instance.canvas.before:
        if color:
            Color(rgba=color)
        if not source:
            canvas_instance = Rectangle(pos=pos,
                                        size=(instance.width, instance.height))
        else:
            canvas_instance = Rectangle(pos=pos,
                                        size=(instance.width, instance.height),
                                        source=source)

        def on_canvas_pos(instance, value):
            if shift:
                x, y = value
                shift_x, shift_y = shift
                canvas_instance.pos = (x + shift_x, y - shift_y)
            else:
                canvas_instance.pos = value

        def on_canvas_size(instance, value):
            canvas_instance.size = value

        instance.bind(size=on_canvas_size, pos=on_canvas_pos)
Beispiel #9
0
 def draw_stone(self, x, y, player, alpha=1, innercol=None, evalcol=None, evalscale=1.0, scale=1.0):
     stone_size = self.stone_size * scale
     Color(1, 1, 1, alpha)
     Rectangle(
         pos=(self.gridpos_x[x] - stone_size, self.gridpos_y[y] - stone_size),
         size=(2 * stone_size, 2 * stone_size),
         source=f"img/{player}_stone.png",
     )
     if evalcol:
         eval_radius = math.sqrt(evalscale)  # scale area by evalscale
         evalsize = self.stone_size * (EVAL_DOT_MIN_SIZE + eval_radius * (EVAL_DOT_MAX_SIZE - EVAL_DOT_MIN_SIZE))
         Color(*evalcol)
         Rectangle(
             pos=(self.gridpos_x[x] - evalsize, self.gridpos_y[y] - evalsize),
             size=(2 * evalsize, 2 * evalsize),
             source=f"img/dot.png",
         )
     if innercol:
         Color(*innercol)
         inner_size = stone_size * 0.8
         Rectangle(
             pos=(self.gridpos_x[x] - inner_size, self.gridpos_y[y] - inner_size),
             size=(2 * inner_size, 2 * inner_size),
             source=f"img/inner.png",
         )
Beispiel #10
0
 def draw_stone(self, x, y, player, alpha=1, innercol=None, evalcol=None, evalscale=1.0, scale=1.0):
     stone_size = self.stone_size * scale
     Color(1, 1, 1, alpha)
     Rectangle(
         pos=(self.gridpos_x[x] - stone_size, self.gridpos_y[y] - stone_size),
         size=(2 * stone_size, 2 * stone_size),
         texture=cached_texture(Theme.STONE_TEXTURE[player]),
     )
     if evalcol:
         eval_radius = math.sqrt(evalscale)  # scale area by evalscale
         evalsize = self.stone_size * (
             Theme.EVAL_DOT_MIN_SIZE + eval_radius * (Theme.EVAL_DOT_MAX_SIZE - Theme.EVAL_DOT_MIN_SIZE)
         )
         Color(*evalcol)
         Rectangle(
             pos=(self.gridpos_x[x] - evalsize, self.gridpos_y[y] - evalsize),
             size=(2 * evalsize, 2 * evalsize),
             texture=cached_texture(Theme.EVAL_DOT_TEXTURE),
         )
     if innercol:
         Color(*innercol)
         inner_size = stone_size * 0.8
         Rectangle(
             pos=(self.gridpos_x[x] - inner_size, self.gridpos_y[y] - inner_size),
             size=(2 * inner_size, 2 * inner_size),
             texture=cached_texture(Theme.LAST_MOVE_TEXTURE),
         )
Beispiel #11
0
    def draw_field(self, i, j):
        # Picking color
        symbol = self.fields[i][j]
        c = self.colors[symbol]
        Color(c[0], c[1], c[2])

        qnt_x = len(self.fields[0])
        qnt_y = len(self.fields)
        win_w = float(window_size[0])
        win_h = float(window_size[1] - settings_height)
        if qnt_x > qnt_y:
            size = (win_w / qnt_x)
            center = (win_h - (size * qnt_y)) / 2
            Rectangle(pos=(j * size, (self.get_top() + 500 - size) -
                           (i * size) - center),
                      size=(size, size))
        elif qnt_x <= qnt_y:
            # scenes width is always greater than height
            size = (win_h / qnt_y)
            # Scaling down the enemies
            element_size = (size * 0.8) if symbol in ["0", "1", "2"] else size
            center = (win_w - (size * qnt_x)) / 2
            Rectangle(pos=(j * size + center,
                           (self.get_top() + 500 - size) - (i * size)),
                      size=(element_size, element_size))
Beispiel #12
0
 def apply_image(self, instance, *args):
     instance.canvas.before.clear()
     with instance.canvas.before:
         Rectangle(source=instance.id, pos=instance.pos, size=instance.size)
         if instance.background_color == [0, 0, 0, .5]:
             Rectangle(size=[50, 50],
                       pos=[instance.x + 30, instance.y + 30],
                       source='Icons/check.png')
Beispiel #13
0
 def __init__(self, **kwargs):
     super(SimulationWidget, self).__init__(**kwargs)
     self.nest_radius = 3
     self.old_window_size_x = 0
     self.old_window_size_y = 0
     self.cells = [[0 for y in range(HEIGHT)] for x in range(WIDTH + 1)]
     x, y = Window.size
     self.spacing_x = x / WIDTH
     self.spacing_y = y / HEIGHT
     self.meter_width = x / 2
     self.meter_bar = InstructionGroup()
     self.meter_bar.add(Color(1, 1, 1))
     self.meter_bar.add(
         RoundedRectangle(pos=[
             x / 2 - self.meter_width / 2, y - self.meter_height * 0.9
         ],
                          size=[self.meter_width, self.meter_height / 3]))
     self.meter_indicator.source = os.path.join(ROOT_PATH, "indicator.png")
     self.meter_backdrop.source = os.path.join(ROOT_PATH,
                                               "indicator_backdrop.png")
     self.meter_backdrop.pos = [
         x / 2 - self.meter_backdrop.size[0] / 2,
         y - self.meter_height * 1.2
     ]
     self.meter_indicator.pos = [
         x / 2 - self.meter_indicator.size[0] / 2,
         y - self.meter_height * 1.2
     ]
     self.meter_backdrop.size = [self.meter_height, self.meter_height]
     self.meter_indicator.size = [self.meter_height, self.meter_height]
     self.meter_backdrop.color = interpolate_color(self.p1_color,
                                                   self.p2_color, 0.5)
     self.sides = InstructionGroup()
     self.sides.add(Color(rgb=self.p1_color))
     self.sides.add(Rectangle(pos=[0, 0], size=[self.bar_width, y]))
     self.sides.add(Color(rgb=self.p2_color))
     self.sides.add(
         Rectangle(pos=[x - self.bar_width, 0], size=[self.bar_width, y]))
     x = 0
     y = -1
     count = 0
     for i in range(0, len(WORLD_DATA), INTS_PER_FIELD):
         x = (i - (count * INTS_PER_FIELD) + count) % WIDTH
         count += 1
         if x % WIDTH == 0:
             y += 1
         y_inverted = HEIGHT - y - 1
         g = InstructionGroup()
         g.add(Color(0, 0, 0, 1))  # black
         g.add(
             Rectangle(pos=(x * self.spacing_x,
                            y_inverted * self.spacing_y),
                       size=(self.spacing_x, self.spacing_y)))
         self.ids["grid_layout"].canvas.add(g)
         self.cells[x][y_inverted] = g
     self.ids["grid_layout"].canvas.add(self.sides)
     self.ids["grid_layout"].canvas.add(self.meter_bar)
Beispiel #14
0
 def update(self, dt):
     with self.canvas:
         for entity, mobile in self.entity_manager.pairs_for_type(Mobile):
             for n in mobile.path:
                 Color(0, 0, 0, 1)
                 Rectangle(pos=n.box.pos, size=(10, 10))
             if mobile.ndest:
                 Color(1, 0, 0, 1)
                 Rectangle(pos=mobile.ndest.box.pos, size=(10, 10))
Beispiel #15
0
    def draw(self):
        self.canvas.before.clear(
        )  # bug prevention. Preferably this would only do if not calling in init, which saves exactly one call, and isn't worth it.
        with self.canvas.before:
            Color(*self.main_color)
            self.main_rectangle = Rectangle(pos=self.pos, size=self.size)

            Color(*self.accent_color)
            self.accent_rectangle = Rectangle(pos=self.pos,
                                              size=(self.size[0],
                                                    8))  # draws on top
Beispiel #16
0
 def draw_rect(self, pos, sell, count, count2, umoney, dmoney):
     with self.canvas:
         #if sell>0:
         Color(0.0, 1.0, 0.0)
         #Rectangle(pos=(pos[0]+count*2, pos[1]+8), size=(2, 10))
         Rectangle(pos=(pos[0], pos[1] + 8), size=(count, 7))
         #Rectangle(pos=(pos[0], pos[1]+20), size=(umoney, 7))
         #else:
         Color(1.0, 0.0, 0.0)
         #Rectangle(pos=(pos[0]+count*2, pos[1]-13), size=(2, 10))
         Rectangle(pos=(pos[0], pos[1] - 13), size=(count2, 7))
 def draw(label, side, resources_configurations, *args):
     if (side == 'left'):
         with label.canvas.before:
             Color(1, 1, 1)
             print(label.pos)
             Rectangle(size=(2, 40), pos=(Window.width - 100, Window.height - 40))
     elif side == 'right':
         with label.canvas.before:
             Color(1, 1, 1)
             print(label.pos)
             Rectangle(size=(2, 40), pos=(label.x + 100, Window.height - 40))
Beispiel #18
0
 def _add_pause_sign(self):
     self.pause_sign = InstructionGroup()
     self.pause_sign.add(Color(1, 1, 1, 1))
     self.pause_sign.add(
         Rectangle(pos=(self.x + self.width * 0.35,
                        self.y + self.height * 0.25),
                   size=(self.width * 0.1, self.height * 0.5)))
     self.pause_sign.add(
         Rectangle(pos=(self.x + self.width * 0.55,
                        self.y + self.height * 0.25),
                   size=(self.width * 0.1, self.height * 0.5)))
     self.canvas.after.add(self.pause_sign)
Beispiel #19
0
 def draw(self):
     app = App.get_running_app()
     if not self.canvas:
         self.canvas = Canvas()
     self.canvas.clear()
     with self.canvas:
         Color(rgb=app.COLOR_PALETTE[self.bg_color])
         Rectangle(pos=self.pos, size=(self.width, self.height))
         Color(rgb=app.COLOR_PALETTE[self.fg_color])
         Rectangle(texture=self.texture,
                   pos=self.pos,
                   size=(self.width, self.height))
Beispiel #20
0
    def draw(self):

        with self.canvas:
            Color(0, 0, 1.)
            self.line = Line(points=self.transform_data(self.lat, self.lon),
                             width=self.PATH_WIDTH)
            Color(0, 1., 0)
            self.start = Rectangle(pos=self.transform_points(self.start_pos),
                                   size=self.MARKER_SIZE)
            Color(1., 0, 0)
            self.goal = Rectangle(pos=self.transform_points(self.end_pos),
                                  size=self.MARKER_SIZE)
Beispiel #21
0
 def render(self):
     self.rect = Rectangle(size=self.size, pos=self.pos)
     self.canvas.add(self.rect)
     label = CoreLabel(text="Text Lable here", font_size=20)
     label.refresh()
     text = label.texture
     #self.canvas.add(Color(self.colour, 1-self.colour,0, 1))
     pos = [
         150, 150
     ]  #self.pos[i] + (self.size[i] - text.size[i]) / 2 for i in range(2))
     self.canvas.add(Rectangle(size=text.size, pos=pos, texture=text))
     self.canvas.ask_update()
Beispiel #22
0
    def set_fade(self, interval: Union[int, float]) -> NoReturn:
        """Draws a bottom and top fade border on the canvas."""

        fade_color = (
            self.theme_cls.primary_color
            if not self.fade_color
            else self.fade_color
        )
        height_segment = (
            self.fade_height if self.fade_height else dp(100)
        ) // self._height_segment
        alpha = 1.1

        with self.canvas:
            for i in range(self._height_segment):
                alpha -= 0.1

                Color(rgba=(fade_color[:-1] + [round(alpha, 1)]))
                rectangle_top = (
                    Rectangle(
                        pos=(self.x, self.height - (i * height_segment)),
                        size=(self.width, height_segment),
                    )
                    if self.edge_top
                    else None
                )
                rectangle_bottom = (
                    Rectangle(
                        pos=(self.x, i * height_segment),
                        size=(self.width, height_segment),
                    )
                    if self.edge_bottom
                    else None
                )
                # How I hate lambda functions because of their length :(
                # But I don’t want to call the arguments by short,
                # incomprehensible names 'a', 'b', 'c'.
                self.bind(
                    pos=lambda instance_fadind_edge_effect, window_size, rectangle_top=rectangle_top, rectangle_bottom=rectangle_bottom, index=i: self.update_canvas(
                        instance_fadind_edge_effect,
                        window_size,
                        rectangle_top,
                        rectangle_bottom,
                        index,
                    ),
                    size=lambda instance_fadind_edge_effect, window_size, rectangle_top=rectangle_top, rectangle_bottom=rectangle_bottom, index=i: self.update_canvas(
                        instance_fadind_edge_effect,
                        window_size,
                        rectangle_top,
                        rectangle_bottom,
                        index,
                    ),
                )
Beispiel #23
0
    def __init__(self, **kwargs):
        Widget.__init__(self, **kwargs)
        # create keyboard
        self.keyboard = Window.request_keyboard(self.keyboard_closed, self)
        self.keyboard.bind(on_key_down=self.on_keyboard_down)

        # custom events
        self.register_event_type('on_land')
        self.bind(on_land=self.check_landing)

        # canvas core labels
        self.lose_label = CoreLabel(text='', font_size=40)
        self.lose_label.refresh()
        self.lose_instruction = Rectangle(texture=self.lose_label.texture,
                                          pos=(85, 430),
                                          size=self.lose_label.texture.size)

        self.aim_label = CoreLabel(text='', font_size=20)
        self.aim_label.refresh()
        self.aim_instruction = Rectangle(texture=self.aim_label.texture,
                                         pos=(415, 300),
                                         size=self.aim_label.texture.size)

        self.score_label = CoreLabel(text='Score: 0', font_size=20)
        self.score_label.refresh()
        self.score_instruction = Rectangle(texture=self.score_label.texture,
                                           pos=(400, 530),
                                           size=self.score_label.texture.size)

        self.speed_label = CoreLabel(text='Speed: 1.0', font_size=20)
        self.speed_label.refresh()
        self.speed_instruction = Rectangle(texture=self.speed_label.texture,
                                           pos=(400, 485),
                                           size=self.speed_label.texture.size)

        self.canvas.add(self.lose_instruction)
        self.canvas.add(self.score_instruction)
        self.canvas.add(self.aim_instruction)
        self.canvas.add(self.speed_instruction)

        # graphics
        line_instruction = InstructionGroup()
        line_instruction.add(Color(1, 1, 1, 1))
        line_instruction.add(Line(points=[0, 518, 500, 518], width=2))
        self.canvas.add(line_instruction)
        self.canvas.add(self.next_block.instruction)

        # run these functions continuously
        Clock.schedule_interval(self.move_tower, 0.02)
        Clock.schedule_interval(self.move_block, 0.04)
        Clock.schedule_interval(self.drop_block, 0)
        Clock.schedule_interval(self.check_tower, 0)
Beispiel #24
0
    def __init__(self, **kwargs):
        self.mem_table = kwargs.pop('mem_table')
        self.dpi = kwargs.pop('dpi')
        super(HexKeyboard, self).__init__(**kwargs)
        self.can_write = True
        self.queue = Queue(maxsize=10)
        self.lock = Lock()
        self.semaphore = Semaphore()
        self.condition = Condition()
        if self.dpi < 192:
            self.size_hint = (dp(0.4), dp(0.4))
            self.pos_hint = {'x': dp(0.10), 'y': dp(0.35)}
        else:
            self.size_hint = (dp(0.4), dp(0.2))
            self.pos_hint = {'x': dp(0.105), 'y': dp(0.1232)}

        with self.canvas.before:
            Color(.50, .50, .50, 1)
            Rectangle(pos=(dp(336), dp(249)), size=(dp(362), dp(208)))

        with self.canvas:
            Color(1, 1, 1, 1)
            Rectangle(pos=(dp(340), dp(254)), size=(dp(354), dp(199)))

            Color(.75, .75, .75, 1)
            Rectangle(pos=(dp(340), dp(250)), size=(dp(353), dp(143)))

            Color(.50, .50, .50, 1)
            for i in range(16):
                if i < 4:
                    Line(rectangle=(dp(340 + (89 * (i % 4))), dp(357), dp(87),
                                    dp(35)),
                         width=dp(0.8))
                elif i < 8:
                    Line(rectangle=(dp(340 + (89 * (i % 4))), dp(322), dp(87),
                                    dp(35)),
                         width=dp(0.8))
                elif i < 12:
                    Line(rectangle=(dp(340 + (89 * (i % 4))), dp(287), dp(87),
                                    dp(35)),
                         width=dp(0.8))
                else:
                    Line(rectangle=(dp(340 + (89 * (i % 4))), dp(252), dp(87),
                                    dp(35)),
                         width=dp(0.8))

        for i in range(16):
            if i > 9:
                i = str(chr(i + 55))
            self.add_widget(
                MDFlatButton(text=f'{i}', on_release=self.hex_key_press))
Beispiel #25
0
 def __init__(self, colors=(Color(1, 0, 1)), *args, **kwargs):
     if 'height' not in kwargs:
         kwargs['height'] = 32
     self.fbo = Fbo()
     with self.fbo:
         Color(1, 1, 1)
         self.fboscrollrect = Rectangle(pos=(-1, 0))
         Color(0, 0, 0)
         self.fboclearrect = Rectangle()
         self.points = []
         self.colors = []
         for color in colors:
             self.colors.append(Color(*color.rgba))
             self.points.append(Point(points=(), pointsize=0.5))
     super().__init__(*args, **kwargs)
Beispiel #26
0
def add_debug_rect(obj):
    kc = KivyConfig()

    if kc.debug:
        with obj.canvas.before:
            random_color()
            Rectangle(pos=obj.pos, size=obj.size)
Beispiel #27
0
 def set_shape(self, shape_index):
     self.text = self._convert_shape(shape_index)
     self._label.refresh()
     self.texture_buffer = numpy.fromstring(self._label.texture.pixels,
                                            dtype=numpy.uint8)
     alphas = self.texture_buffer[RGBA_SIZE - 1::RGBA_SIZE]
     # reset [in]visible pixels buffers
     self._invisible_pixels = []
     self._visible_pixels = []
     for index, item in enumerate(alphas):
         if item != 0:
             r_index = (index + 1) * RGBA_SIZE - 1
             self._visible_pixels.append(r_index)
     # shuffle the indexes so manipulation with visibility seems random
     random.shuffle(self._visible_pixels)
     if not self.shape_box:
         with self.canvas:
             self.shape_box = Rectangle(size=self.size,
                                        pos=self.pos,
                                        texture=self._label.texture)
         self.bind(pos=self.reposition_shape_box,
                   size=self.resize_shape_box)
     center_x = self.center_x - self._label.texture.size[0] / 2
     center_y = self.center_y - self._label.texture.size[1] / 2
     self.shape_visibility = self._init_visibility
     self.shape_box.pos = (center_x, center_y)
     self.shape_box.size = self._label.texture.size
     self.text = ""
Beispiel #28
0
    def update_once(self, dt):
        count = 0

        with self.search_text.canvas.before:
            Color(.96, .60, .61, 1)
            Rectangle(size=(197, 50), pos=(120, 100))

        self.base_widget.add_widget(self.search_grid)
        self.search_grid.add_widget(self.search_text)
        self.search_grid.add_widget(self.search_bar)
        self.search_bar.bind(on_text_validate=self.pressed)

        for bttn in self.button_keys.keys():
            bttn.size = bttn.texture_size
            bttn.pos = (self.base_widget.center_x - (bttn.width / 2),
                        280 - (85 * count))
            bttn.bind(on_press=self.pressed)
            while True:
                try:
                    self.base_widget.add_widget(bttn)
                    break
                except kivy.uix.widget.WidgetException:
                    self.base_widget.remove_widget(bttn)
                    self.base_widget.add_widget(bttn)
                    break
            count += 1
Beispiel #29
0
    def adjust_size(self, *args):
        if not self.parent or not self.image.texture:
            return

        (par_x, par_y) = self.parent.size

        if par_x == 0 or par_y == 0:
            with self.canvas:
                self.canvas.clear()
            return

        par_scale = par_x / par_y
        (img_x, img_y) = self.image.texture.size
        img_scale = img_x / img_y

        if par_scale > img_scale:
            (img_x_new, img_y_new) = (img_x, img_x / par_scale)
        else:
            (img_x_new, img_y_new) = (img_y * par_scale, img_y)

        crop_pos_x = (img_x - img_x_new) / 2
        crop_pos_y = (img_y - img_y_new) / 2

        subtexture = self.image.texture.get_region(crop_pos_x, crop_pos_y,
                                                   img_x_new, img_y_new)

        with self.canvas:
            self.canvas.clear()
            Color(1, 1, 1)
            Rectangle(texture=subtexture, pos=self.pos, size=(par_x, par_y))
 def reset_data(self):
     if App.get_running_app().apgar_current >= 7:
         with self.canvas.before:
             Color(0, 1, 0,
                   1)  # green; colors range from 0-1 instead of 0-255
             self.rect = Rectangle(size=self.size, pos=self.pos)
         for widget in self.widget_array:
             widget.reset_data()
         Clock.schedule_once(lambda dt: self.restore_bg(), .5)
     else:
         with self.canvas.before:
             Color(1, 0, 0,
                   1)  # green; colors range from 0-1 instead of 0-255
             self.rect = Rectangle(size=self.size, pos=self.pos)
         Clock.schedule_once(lambda dt: self.change_screen_to_reanimation(),
                             .5)