62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
import os
|
|
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
|
|
import pygame
|
|
import sys
|
|
|
|
pygame.init()
|
|
|
|
width = 600
|
|
height = 900
|
|
num_display = 0
|
|
old_num_display = 0
|
|
num_float = False
|
|
float_precision = 1
|
|
|
|
screen = pygame.display.set_mode((width, height))
|
|
pygame.display.set_caption('CheesyCalc')
|
|
icon = pygame.image.load(os.path.join("img", "cheesy_icon_32x32.png"))
|
|
icon.convert_alpha()
|
|
pygame.display.set_icon(icon)
|
|
logo = pygame.image.load(os.path.join("img", "cheesy.png"))
|
|
logo.convert_alpha()
|
|
screen.blit(logo, (30, 20))
|
|
cheesy_font = pygame.font.Font(os.path.join("font", "Cheese.ttf"), 60)
|
|
logo_text_1 = cheesy_font.render("Cheesy", True, (240, 240, 20))
|
|
logo_text_2 = cheesy_font.render("Calculator", True, (240, 240, 20))
|
|
screen.blit(logo_text_1, (width // 2 - logo_text_1.get_width() // 2 + 80, -15))
|
|
screen.blit(logo_text_2, (width // 2 - logo_text_2.get_width() // 2 + 80, 30))
|
|
sevenseg_font = pygame.font.Font(os.path.join("font", "Seven Segment.ttf"), 80)
|
|
|
|
while True:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
|
|
pygame.quit()
|
|
sys.exit()
|
|
elif event.type == pygame.KEYDOWN and event.key == pygame.K_c:
|
|
num_display = 0
|
|
float_precision = 1
|
|
elif event.type == pygame.KEYDOWN and (event.key == pygame.K_PERIOD or event.key == pygame.K_KP_PERIOD):
|
|
#num_float = True
|
|
pass
|
|
elif event.type == pygame.KEYDOWN \
|
|
and ((event.key >= pygame.K_0 and event.key <= pygame.K_9) or (event.key >= pygame.K_KP1 and event.key <= pygame.K_KP0)) \
|
|
and len(str(num_display)) < 14:
|
|
if event.key == pygame.K_KP0:
|
|
actual_key = pygame.K_0
|
|
elif event.key >= pygame.K_KP1 and event.key <= pygame.K_KP9:
|
|
actual_key = event.key - 1073741864
|
|
else:
|
|
actual_key = event.key
|
|
if num_display == 0 and actual_key != pygame.K_0:
|
|
num_display = int(chr(actual_key))
|
|
else:
|
|
num_display = (num_display * 10) + int(chr(actual_key))
|
|
if num_display != old_num_display:
|
|
print(f"Number: {num_display}")
|
|
old_num_display = num_display
|
|
pygame.draw.rect(screen, (0, 0, 0), pygame.Rect(12, 97, 576, 126))
|
|
num_show = (num_float == False)
|
|
text = sevenseg_font.render(str(num_display) + ".", True, (255, 255, 255))
|
|
screen.blit(text, (580 - text.get_width(), 110))
|
|
pygame.draw.rect(screen, (240, 240, 20), pygame.Rect(10, 100, 580, 110), 2)
|
|
pygame.display.flip() |