This commit is contained in:
Benjamín 2021-08-31 22:22:56 +02:00
parent 5a2693bd9f
commit fd623245b9
12 changed files with 239 additions and 0 deletions

3
.idea/.gitignore vendored Normal file

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

8
.idea/Info_edupage.iml Normal file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,23 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="list.__sub__" />
<option value="str.counter" />
<option value="str.left" />
<option value="str.right" />
<option value="str.value" />
</list>
</option>
</inspection_tool>
</profile>
</component>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Info_edupage.iml" filepath="$PROJECT_DIR$/.idea/Info_edupage.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

40
UI/board.py Normal file

@ -0,0 +1,40 @@
import pygame.draw
from rounded_rect import draw_rounded_rect
class Board:
def __init__(self, size, bg_image):
self.fs = False
self.dp = [0, 0]
self.bg_image = bg_image
self.size = size
self.width = size[0]
self.height = size[1]
self.width_fifth = self.width / 5
self.small_size_fraction = sum(self.size) / 60
self.mid_width = self.width - self.width_fifth - 2 * self.small_size_fraction
self.height_sixth = self.height / 6
self.transparent_objects_color = (237, 237, 250)
def draw_bg(self, display):
# drawing left rect
pygame.draw.rect(display, (49, 49, 54), pygame.Rect(0, 0, self.width_fifth, self.height))
# drawing bg image
display.blit(self.bg_image, [self.width_fifth, 0])
# drawing top and bottom rect
surf = pygame.Surface(self.size)
surf.fill((0, 0, 0))
draw_rounded_rect(surf, pygame.Rect(self.width_fifth + self.small_size_fraction,
self.small_size_fraction, self.mid_width,
100),
self.transparent_objects_color, int(self.height / 20))
pygame.draw.rect(surf, self.transparent_objects_color, pygame.Rect(self.width_fifth, self.height - self.height_sixth,
self.width, self.height_sixth))
surf.set_colorkey((0, 0, 0))
surf.set_alpha(100)
display.blit(surf, [0, 0])

BIN
UI/board_bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
UI/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

82
UI/main.py Normal file

@ -0,0 +1,82 @@
import pygame
from pygame.locals import *
import math
import numpy as np
import random
import time
import json
import os
import sys
import copy
from board import Board
# basic config
pygame.mixer.pre_init(48000, -16, 2, 512)
pygame.init()
pygame.mixer.set_num_channels(16)
available = pygame.font.get_fonts()
monitor_size = [pygame.display.Info().current_w, pygame.display.Info().current_h]
font = pygame.font.SysFont('calibri', 60, True)
small_font = pygame.font.SysFont('calibri', 40, True)
tiny_font = pygame.font.SysFont('calibri', 20, True)
Window_size = [1200, 800]
Default_size = Window_size
screen = pygame.display.set_mode(Window_size)
display = pygame.Surface(Window_size)
pygame.display.set_caption("School_board")
pygame.display.set_icon(pygame.image.load("logo.png").convert())
clock = pygame.time.Clock()
Win_size = Window_size
alive = True
board = Board(Window_size, pygame.image.load("board_bg.png"))
while alive:
board.draw_bg(display)
# event loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit(0)
# keydown
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit(0)
elif event.key == K_f:
board.fs = not board.fs
if board.fs is False:
Win_size = Default_size
screen = pygame.display.set_mode(Win_size)
board.dp = [0, 0]
else:
screen = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN)
d = screen
ratio = [Default_size[1] / Default_size[0], Default_size[0] / Default_size[1]]
# u chose width or height here
if Default_size[0] > Default_size[1]:
Win_size = [d.get_width(), int(d.get_width() * ratio[0])]
d = d.get_height()
dd = Win_size[1]
else:
Win_size = [int(d.get_height() * ratio[1]), d.get_height()]
d = pygame.display.get_surface().get_width()
dd = Win_size[0]
board.dp[0] = (d - dd) / 2
screen = screen
# basic loop config
screen.blit(pygame.transform.scale(display, Win_size), board.dp)
pygame.display.update()
clock.tick(10)

59
UI/rounded_rect.py Normal file

@ -0,0 +1,59 @@
import pygame.gfxdraw
def draw_rounded_rect(surface, rect, color, corner_radius):
''' Draw a rectangle with rounded corners.
Would prefer this:
pygame.draw.rect(surface, color, rect, border_radius=corner_radius)
but this option is not yet supported in my version of pygame so do it ourselves.
We use anti-aliased circles to make the corners smoother
'''
if rect.width < 2 * corner_radius or rect.height < 2 * corner_radius:
raise ValueError(f"Both height (rect.height) and width (rect.width) must be > 2 * corner radius ({corner_radius})")
# need to use anti aliasing circle drawing routines to smooth the corners
pygame.gfxdraw.aacircle(surface, rect.left+corner_radius, rect.top+corner_radius, corner_radius, color)
pygame.gfxdraw.aacircle(surface, rect.right-corner_radius-1, rect.top+corner_radius, corner_radius, color)
pygame.gfxdraw.aacircle(surface, rect.left+corner_radius, rect.bottom-corner_radius-1, corner_radius, color)
pygame.gfxdraw.aacircle(surface, rect.right-corner_radius-1, rect.bottom-corner_radius-1, corner_radius, color)
pygame.gfxdraw.filled_circle(surface, rect.left+corner_radius, rect.top+corner_radius, corner_radius, color)
pygame.gfxdraw.filled_circle(surface, rect.right-corner_radius-1, rect.top+corner_radius, corner_radius, color)
pygame.gfxdraw.filled_circle(surface, rect.left+corner_radius, rect.bottom-corner_radius-1, corner_radius, color)
pygame.gfxdraw.filled_circle(surface, rect.right-corner_radius-1, rect.bottom-corner_radius-1, corner_radius, color)
rect_tmp = pygame.Rect(rect)
rect_tmp.width -= 2 * corner_radius
rect_tmp.center = rect.center
pygame.draw.rect(surface, color, rect_tmp)
rect_tmp.width = rect.width
rect_tmp.height -= 2 * corner_radius
rect_tmp.center = rect.center
pygame.draw.rect(surface, color, rect_tmp)
def draw_bordered_rounded_rect(surface, rect, color, border_color, corner_radius, border_thickness):
if corner_radius < 0:
raise ValueError(f"border radius ({corner_radius}) must be >= 0")
rect_tmp = pygame.Rect(rect)
center = rect_tmp.center
if border_thickness:
if corner_radius <= 0:
pygame.draw.rect(surface, border_color, rect_tmp)
else:
draw_rounded_rect(surface, rect_tmp, border_color, corner_radius)
rect_tmp.inflate_ip(-2*border_thickness, -2*border_thickness)
inner_radius = corner_radius - border_thickness + 1
else:
inner_radius = corner_radius
if inner_radius <= 0:
pygame.draw.rect(surface, color, rect_tmp)
else:
draw_rounded_rect(surface, rect_tmp, color, inner_radius)