Initial Commit
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -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/
|
||||
|
||||
|
||||
10
pyproject.toml
Normal file
10
pyproject.toml
Normal file
@@ -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"}
|
||||
]
|
||||
105
src/main.py
Normal file
105
src/main.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user