107 lines
2.4 KiB
Python
107 lines
2.4 KiB
Python
#!~/.pyenv/versions/3.12.9/bin/python
|
|
#
|
|
# Copyright (c) 2025 Cutieguwu | Olivia Brooks
|
|
#
|
|
# -*- coding:utf-8 -*-
|
|
# @Title: digital_photo_frame
|
|
# @Author: Cutieguwu | Olivia Brooks
|
|
# @Email: owen.brooks77@gmail.com
|
|
# @Description: Getting started with using PyGame engine.
|
|
#
|
|
# @Script: main.py
|
|
# @Date Created: 28 Jun, 2025
|
|
# @Last Modified: 28 Jun, 2025
|
|
# @Last Modified by: Cutieguwu | Olivia Brooks
|
|
# ----------------------------------------------------------
|
|
|
|
from __future__ import annotations
|
|
from typing import TYPE_CHECKING
|
|
if TYPE_CHECKING:
|
|
from _typeshed import StrPath
|
|
import pygame as pyg
|
|
#import random
|
|
import os
|
|
from icecream import ic
|
|
import time
|
|
|
|
|
|
IMG_DIR: StrPath = os.path.dirname(__file__) + '/../images/'
|
|
|
|
def main() -> None:
|
|
pyg.init()
|
|
|
|
pyg.display.set_caption('')
|
|
window = pyg.display.set_mode((720, 480))
|
|
pyg.display.toggle_fullscreen()
|
|
|
|
reel = imgReel(IMG_DIR, window)
|
|
|
|
running = True
|
|
while running:
|
|
reel.draw_next()
|
|
|
|
time.sleep(10)
|
|
|
|
for event in pyg.event.get():
|
|
if event.type == pyg.QUIT:
|
|
running = False
|
|
break
|
|
|
|
pyg.quit()
|
|
print('Exited.')
|
|
|
|
class imgReel:
|
|
def __init__(self, path: StrPath, window: pyg.Surface) -> None:
|
|
self.window = window
|
|
|
|
self.idx = 0
|
|
self.images = []
|
|
|
|
for path in os.listdir(IMG_DIR):
|
|
ic(path)
|
|
self.images.append(pyg.image.load(str(IMG_DIR) + path))
|
|
|
|
ic(self.images)
|
|
|
|
def _randomize(self) -> None:
|
|
...
|
|
|
|
def draw_next(self) -> None:
|
|
|
|
# Clear screen
|
|
self.window.fill((0, 0, 0))
|
|
|
|
# Get img or loop and get img if needed.
|
|
if self.idx < self.images.__len__() - 1:
|
|
self.idx += 1
|
|
else:
|
|
self.idx = 0
|
|
|
|
img = self.images[self.idx]
|
|
|
|
# Scale img proportionally to window.
|
|
|
|
scalar = (
|
|
(self.window.get_height() / img.get_height())
|
|
if (img.get_height() > img.get_width())
|
|
else (self.window.get_width() / img.get_width())
|
|
)
|
|
|
|
img = pyg.transform.scale_by(img, scalar)
|
|
|
|
# Draw img at centre.
|
|
self.window.blit(
|
|
img,
|
|
((
|
|
(self.window.get_width() / 2)
|
|
- (img.get_width() / 2),
|
|
(self.window.get_height() / 2)
|
|
- (img.get_height() / 2)
|
|
))
|
|
)
|
|
pyg.display.flip()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|