Skip to content

Commit

Permalink
Stash
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Nov 20, 2023
1 parent f247a87 commit e8a64c0
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 115 deletions.
8 changes: 5 additions & 3 deletions testing/sprites/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def randomise_state_rare(state: Dict):
"sensor.speedtest_upload_average": speedtest_upload,
"sensor.speedtest_ping_average": speedtest_ping,
"sensor.ds920plus_volume_used": ds920plus_volume_used,
"switch.lounge_fans": "on" if random.choice([True, False]) else "off",
}
)

Expand All @@ -111,16 +112,17 @@ def randomise_state_rare(state: Dict):
if event.type == pygame.QUIT:
running = False

if frame % 100 == 0:
if frame % 300 == 0:
randomise_state_common(state)
print(f"State: {state}")
if frame % 300 == 0:
if frame % 1000 == 0:
randomise_state_rare(state)
print(f"State: {state}")

screen.fill((0, 0, 0, 255))
sprite_group.update()
tile_grid.rect.topleft = (SCREEN_WIDTH - tile_grid.rect.width, 0)
if tile_grid.rect:
tile_grid.rect.topleft = (SCREEN_WIDTH - tile_grid.rect.width, 0)
sprite_group.draw(screen)
pygame.display.flip()
clock.tick(FPS)
Expand Down
26 changes: 26 additions & 0 deletions testing/sprites/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@
LABEL_FONT_FILENAME = "fonts/bitstream-vera.ttf"
LABEL_FONT_SIZE = 10

# CUSTOM COLORS


class CommonColors:
COLOR_RED_DARK = pygame.Color(64, 0, 0, 255)
COLOR_RED = pygame.Color(255, 0, 0, 255)
COLOR_BLUE_DARK = pygame.Color(0, 0, 64, 255)
COLOR_BLUE = pygame.Color(0, 0, 255, 255)
COLOR_GREEN_DARK = pygame.Color(0, 64, 0, 255)
COLOR_GREEN = pygame.Color(0, 255, 0, 255)
COLOR_YELLOW_DARK = pygame.Color(64, 64, 0, 255)
COLOR_YELLOW = pygame.Color(255, 255, 0, 255)
COLOR_ORANGE_DARK = pygame.Color(64, 32, 0, 255)
COLOR_ORANGE = pygame.Color(255, 128, 0, 255)
COLOR_PURPLE_DARK = pygame.Color(64, 0, 64, 255)
COLOR_PURPLE = pygame.Color(255, 0, 255, 255)
COLOR_PINK_DARK = pygame.Color(64, 0, 32, 255)
COLOR_PINK = pygame.Color(255, 0, 128, 255)
COLOR_CYAN_DARK = pygame.Color(0, 64, 64, 255)
COLOR_CYAN = pygame.Color(0, 255, 255, 255)
COLOR_WHITE = pygame.Color(255, 255, 255, 255)
COLOR_BLACK = pygame.Color(0, 0, 0, 255)
COLOR_GREY = pygame.Color(64, 64, 64, 255)
COLOR_GREY_DARK = pygame.Color(16, 16, 16, 255)
COLOR_TRANSPARENT = pygame.Color(0, 0, 0, 0)


# FONTAWESOME CODEPOINTS

Expand Down
40 changes: 13 additions & 27 deletions testing/sprites/lib/tile_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
from datetime import datetime
from typing import Any, Callable, List, Dict, Optional, Tuple, Type, TypeVar, cast

from .helpers import Animator, AnimatorState, FontAwesomeIcons, render_icon, render_text
from .helpers import LABEL_FONT_FILENAME, LABEL_FONT_SIZE # TO BE REMOVED
from .helpers import (
Animator,
AnimatorState,
FontAwesomeIcons,
CommonColors,
render_icon,
render_text,
)

# NOTES

Expand All @@ -16,28 +22,6 @@
logger.setLevel(logging.DEBUG)


# STYLE CLASSES

"""
TILE_GRID_STYLE_DEFAULT = {
"cell_color_background": pygame.Color(16, 16, 16, 255),
"cell_color_border": pygame.Color(0, 0, 0, 0),
"label_color_text": pygame.Color(255, 255, 255, 255),
"label_color_outline": pygame.Color(0, 0, 0, 255),
"label_font": LABEL_FONT_FILENAME,
"label_size": LABEL_FONT_SIZE,
"label_padding": (2, 1),
"label_outline": True,
"label_antialias": True,
"icon_visible": True,
"icon_width": TILE_GRID_CELL_ICON_WIDTH,
"icon_height": TILE_GRID_CELL_ICON_HEIGHT,
"icon_color_background": pygame.Color(32, 32, 32, 255),
"icon_color_foreground": pygame.Color(255, 255, 255, 255),
"icon_codepoint": None,
}
"""

# CONSTANTS

TILE_GRID_CELL_WIDTH = 64
Expand Down Expand Up @@ -206,20 +190,22 @@ def render(self):


class VerticalCollapseTileGridCell(TileGridCell):
open: bool = True
width: int = TILE_GRID_CELL_WIDTH
height_animator: Animator

def __init__(self, state):
super().__init__(state)
self.height_animator = Animator(range=(0.0, 12.0), open=True, speed=1.0)
self.height_animator = Animator(range=(0.0, 12.0), open=self.open, speed=1.0)

def update(self):
self.height_animator.set(self.open)
self.height_animator.update()
self.rect.height = self.height_animator.value
super().update()

@property
def open(self):
def open_finished(self):
return self.height_animator.state != AnimatorState.CLOSED

def __repr__(self):
Expand All @@ -242,7 +228,7 @@ def update(self):

@property
def open(self):
return any([cell.open for cell in self.cells_inst])
return any([cell.open_finished for cell in self.cells_inst])

def __repr__(self):
return f"HorizontalCollapseTileGridColumn(open={self.open}, width={self.width_animator.value}, cells={len(self.cells_inst)})"
Loading

0 comments on commit e8a64c0

Please sign in to comment.