added simple blank slate to build on
This commit is contained in:
parent
4c206a2342
commit
e936b835e1
4
thermostat/__init__.py
Normal file
4
thermostat/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
"""Smart thermostat for local CITRUxx use."""
|
||||
__version__ = '0.0.1'
|
||||
|
||||
from . import mainloop
|
17
thermostat/__main__.py
Normal file
17
thermostat/__main__.py
Normal file
@ -0,0 +1,17 @@
|
||||
"""
|
||||
Launch script for Pocket Friends.
|
||||
"""
|
||||
import sys
|
||||
import thermostat
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
is_windowed = False
|
||||
if len(sys.argv) > 0:
|
||||
for arg in sys.argv:
|
||||
print(arg)
|
||||
if arg == '--windowed':
|
||||
is_windowed = True
|
||||
|
||||
thermostat.mainloop.main(is_windowed=is_windowed)
|
||||
|
45
thermostat/mainloop.py
Normal file
45
thermostat/mainloop.py
Normal file
@ -0,0 +1,45 @@
|
||||
import pygame
|
||||
import os
|
||||
import thermostat.surfaces as surfaces
|
||||
|
||||
# Global variables
|
||||
SCREEN_SIZE = (720, 720)
|
||||
FPS = 60
|
||||
VALID_SURFACES = [
|
||||
'button_pad',
|
||||
'screensaver'
|
||||
]
|
||||
|
||||
|
||||
def main(is_windowed=False):
|
||||
"""
|
||||
Main scene manager to display the scenes of the application
|
||||
:param is_windowed: boolean to start the game in windowed mode
|
||||
"""
|
||||
pygame.init()
|
||||
clock = pygame.time.Clock()
|
||||
if is_windowed:
|
||||
window = pygame.display.set_mode(SCREEN_SIZE)
|
||||
else:
|
||||
window = pygame.display.set_mode(SCREEN_SIZE, pygame.FULLSCREEN)
|
||||
|
||||
# Starts the program with the surface 'dial' as the default
|
||||
surface = getattr(globals()['surfaces'], 'button_pad').Surface(SCREEN_SIZE)
|
||||
running = True
|
||||
while running:
|
||||
clock.tick(FPS)
|
||||
surface.update()
|
||||
|
||||
window.blit(surface, surface.get_rect())
|
||||
|
||||
if not surface.running:
|
||||
if surface.quit:
|
||||
break
|
||||
# Switch the surface to a new surface
|
||||
next_surface = surface.next_surface
|
||||
if next_surface not in VALID_SURFACES:
|
||||
raise Exception('Given surface is not a valid surface!')
|
||||
surface = getattr(globals()['surfaces'], next_surface).Surface(SCREEN_SIZE)
|
||||
|
||||
pygame.display.flip()
|
||||
pygame.quit()
|
4
thermostat/surfaces/__init__.py
Normal file
4
thermostat/surfaces/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
"""Smart thermostat for local CITRUxx use."""
|
||||
__version__ = '0.0.1'
|
||||
|
||||
from . import button_pad
|
72
thermostat/surfaces/button_pad.py
Normal file
72
thermostat/surfaces/button_pad.py
Normal file
@ -0,0 +1,72 @@
|
||||
import math
|
||||
import pygame
|
||||
import os
|
||||
|
||||
DIAL_SCALING = 0.9
|
||||
QUIT_BUTTON_SIZE = 50
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class MouseHandler:
|
||||
def __init__(self):
|
||||
self.prev_mouse_pos = pygame.mouse.get_pos()
|
||||
self.mouse_pos = pygame.mouse.get_pos()
|
||||
self.active = False
|
||||
self.click = False
|
||||
|
||||
def update(self):
|
||||
self.prev_mouse_pos = self.mouse_pos
|
||||
self.mouse_pos = pygame.mouse.get_pos()
|
||||
self.click = False
|
||||
|
||||
|
||||
class QuitButton(pygame.Surface):
|
||||
def __init__(self):
|
||||
super().__init__((QUIT_BUTTON_SIZE, QUIT_BUTTON_SIZE), pygame.SRCALPHA)
|
||||
self.rect = self.get_rect()
|
||||
pygame.draw.rect(self, (255, 0, 0), self.rect, 3)
|
||||
pygame.draw.line(self, (255, 0, 0), (0, 0), (QUIT_BUTTON_SIZE, QUIT_BUTTON_SIZE), 3)
|
||||
pygame.draw.line(self, (255, 0, 0), (0, QUIT_BUTTON_SIZE), (QUIT_BUTTON_SIZE, 0), 3)
|
||||
|
||||
|
||||
class Surface(pygame.Surface):
|
||||
def __init__(self, window_size):
|
||||
super().__init__(window_size, pygame.SRCALPHA)
|
||||
self.running = True
|
||||
self.quit = False
|
||||
self.next_surface = ''
|
||||
self.mouse_frames = 0
|
||||
|
||||
dial_size = int(min(window_size[0], window_size[1]) * 0.9)
|
||||
self.quit_button = QuitButton()
|
||||
|
||||
self.mouse_handler = MouseHandler()
|
||||
self.font = pygame.font.Font(SCRIPT_DIR + '/resources/tuffy.ttf', 128)
|
||||
|
||||
def update(self):
|
||||
self.fill((32, 32, 32))
|
||||
self.mouse_handler.update()
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
self.running = False
|
||||
self.quit = True
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
self.running = False
|
||||
self.quit = True
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
self.mouse_handler.active = True
|
||||
self.mouse_handler.update()
|
||||
self.mouse_handler.prev_mouse_pos = self.mouse_handler.mouse_pos
|
||||
self.mouse_handler.click = True
|
||||
|
||||
if event.type == pygame.MOUSEBUTTONUP:
|
||||
self.mouse_handler.active = False
|
||||
|
||||
if self.mouse_handler.click:
|
||||
if self.mouse_handler.mouse_pos[0] <= QUIT_BUTTON_SIZE and \
|
||||
self.mouse_handler.mouse_pos[1] <= QUIT_BUTTON_SIZE:
|
||||
self.running = False
|
||||
self.quit = True
|
||||
|
||||
self.blit(self.quit_button, self.quit_button.rect)
|
Loading…
Reference in New Issue
Block a user