From 51d08f8558ca2dc4830924e7085d5479ccfd3260 Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Sat, 28 Jun 2025 14:20:21 -0400 Subject: [PATCH] Initial Commit --- .gitignore | 4 +- pyproject.toml | 10 +++++ src/main.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml create mode 100644 src/main.py diff --git a/.gitignore b/.gitignore index 0dbf2f2..5fe9db2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +images/* + + # ---> Python # Byte-compiled / optimized / DLL files __pycache__/ @@ -167,4 +170,3 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..408b2d1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "digital_photo_frame" +version = "0.0.1" +dependencies = [ + "pygame>=1.0.0; os_name == 'Linux'" + "pygame>=2.0.0; os_name != 'Linux'" +] +authors = [ + {name = "Olivia Brooks", email = "owen.brooks77@gmail.com"} +] diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..a7b6b5e --- /dev/null +++ b/src/main.py @@ -0,0 +1,105 @@ +#!~/.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(0.5) + + 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): + 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()