From 6168798d198bdb2dfe31bc4ab6bed6103e5e8b31 Mon Sep 17 00:00:00 2001 From: Linus Vogel Date: Sun, 30 Nov 2025 12:52:55 +0100 Subject: [PATCH] some updates --- .idea/misc.xml | 7 +++ .idea/workspace.xml | 7 ++- pyproject.toml | 9 ++- .../controller/controller.py | 7 ++- src/starsky_presenter/controller/window.py | 9 +-- src/starsky_presenter/entry.py | 52 +++++++++++++----- src/starsky_presenter/projection/screen.py | 17 +++++- .../resources}/main_window.qml | 0 src/starsky_presenter/resources/objects.yml | 17 ++++++ src/starsky_presenter/resources/scenes.yml | 5 ++ .../starsky_presenter/resources}/star.png | Bin .../starsky_presenter/resources}/test.png | Bin uv.lock | 38 +++++++++++++ 13 files changed, 138 insertions(+), 30 deletions(-) create mode 100644 .idea/misc.xml rename {resources => src/starsky_presenter/resources}/main_window.qml (100%) create mode 100644 src/starsky_presenter/resources/objects.yml create mode 100644 src/starsky_presenter/resources/scenes.yml rename {resources => src/starsky_presenter/resources}/star.png (100%) rename {resources => src/starsky_presenter/resources}/test.png (100%) diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b244a30 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d62088c..a42b483 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -48,6 +48,7 @@ + @@ -58,12 +59,12 @@ - - diff --git a/pyproject.toml b/pyproject.toml index f351239..11c1027 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "starsky-presenter" version = "0.1.0" -description = "Add your description here" +description = "Small utility for projecting a sky full of stars" readme = "README.md" authors = [ { name = "Linus Vogel", email = "linus@linvogel.ch" } @@ -10,11 +10,14 @@ requires-python = ">=3.13" dependencies = [ "pygame>=2.6.1", "pyqt6>=6.10.0", + "pyyaml>=6.0.3", ] [project.scripts] starsky-presenter = "starsky_presenter:main" [build-system] -requires = ["uv_build>=0.9.7,<0.10.0"] -build-backend = "uv_build" +requires = ["hatchling"] +build-backend = "hatchling.build" + + diff --git a/src/starsky_presenter/controller/controller.py b/src/starsky_presenter/controller/controller.py index 868e497..945abad 100644 --- a/src/starsky_presenter/controller/controller.py +++ b/src/starsky_presenter/controller/controller.py @@ -4,11 +4,12 @@ from time import time class Controller(QObject): - def __init__(self, window, parent=None): + def __init__(self, window, screen, parent=None): super().__init__(parent) self.window = window self.last_close_press = 0 self.successful_clicks = 0 + self.screen = screen @pyqtSlot() def close_application(self): @@ -25,4 +26,6 @@ class Controller(QObject): @pyqtSlot(int) def select_scene(self, scene: int): - self.window.selected_scene = scene \ No newline at end of file + self.screen.last_scene = self.screen.active_scene + self.screen.active_scene = scene + self.screen.scene_time = 0 \ No newline at end of file diff --git a/src/starsky_presenter/controller/window.py b/src/starsky_presenter/controller/window.py index f15b8ae..8bf8fb7 100644 --- a/src/starsky_presenter/controller/window.py +++ b/src/starsky_presenter/controller/window.py @@ -1,3 +1,5 @@ +from pathlib import Path + from PyQt6.QtGui import QGuiApplication from PyQt6.QtQml import QQmlApplicationEngine @@ -6,16 +8,15 @@ from starsky_presenter.projection.screen import Screen class ControlWindow: - def __init__(self): + def __init__(self, screen): self.app = QGuiApplication([]) self.running = True self.engine = QQmlApplicationEngine(self.app) - self.controller = Controller(self) + self.controller = Controller(self, screen) self.engine.quit.connect(self.app.quit) self.engine.rootContext().setContextProperty("controller_backend", self.controller) - self.engine.load("resources/main_window.qml") - + self.engine.load(f"{Path(__file__).parent.parent}/resources/main_window.qml") def process_events(self): return self.app.processEvents() diff --git a/src/starsky_presenter/entry.py b/src/starsky_presenter/entry.py index 419f8a8..1015e82 100644 --- a/src/starsky_presenter/entry.py +++ b/src/starsky_presenter/entry.py @@ -1,7 +1,15 @@ import sys import json +from importlib.resources import open_text, open_binary +from importlib.readers import FileReader +from importlib.machinery import SourcelessFileLoader +from io import BufferedReader +from pathlib import Path + +import yaml from random import random, seed +from copy import deepcopy from pygame.transform import scale import pygame @@ -12,28 +20,42 @@ from starsky_presenter.projection.screen import Screen, Star def cli_main(): seed(43) - image = pygame.image.load('resources/star.png') + reader = FileReader(SourcelessFileLoader("resource_loader", f"{Path(__file__).parent}/resources")) - stars = [ - Star(**{ - "_id": i, - "x": random(), - "y": random(), - "alpha": random() * 360, - "rot": random() * 360, - "scale": random() * 0.5 + 0.25, - "offset": random(), - "image": image - }) - for i in range(4) + scenes = yaml.safe_load(reader.open_resource('resources/scenes.yml')) + objects = yaml.safe_load(reader.open_resource('resources/objects.yml')) + + print(json.dumps(objects, indent=4)) + print(objects['stars'][0]['sid']) + + scene_data = [ + { obj['sid']: deepcopy(obj).update(scene[obj['sid']]) if scene and obj['sid'] in scene else deepcopy(obj) for obj in objects["stars"] } + for scene in scenes ] - control_window = ControlWindow() + star_references = {} + + print(json.dumps(scenes, indent=4)) + print(json.dumps(objects, indent=4)) + + def setup_star_instance(data: dict) -> Star: + image_path = f"resources/{data['image']}" + image = pygame.image.load(reader.open_resource(image_path)) + data['image'] = image + star = Star(**data) + star_references[data['sid']] = star + return star + + + stars = [ setup_star_instance(star) for star in objects["stars"] ] + screen = Screen(stars) + control_window = ControlWindow(screen) while control_window.is_running(): control_window.process_events() - screen.update() + screen.update(scene_data) + screen.close() control_window.close() diff --git a/src/starsky_presenter/projection/screen.py b/src/starsky_presenter/projection/screen.py index 17000c8..3f00fd9 100644 --- a/src/starsky_presenter/projection/screen.py +++ b/src/starsky_presenter/projection/screen.py @@ -6,8 +6,8 @@ from time import time, sleep from random import random class Star: - def __init__(self, _id: int, x: int, y: int, alpha: float, rot: float, scale: float, offset: float, image: pygame.Surface): - self.id = _id + def __init__(self, sid: str, x: int, y: int, alpha: float, rot: float, scale: float, offset: float, image: pygame.Surface): + self.sid = sid self.x = x self.y = y self.rot = rot @@ -25,13 +25,24 @@ class Screen: self.stars = stars self.last = time() self.brightness = 1.0 + self.active_scene = 0 + self.last_scene = 0 + self.scene_time: float = 0 - def update(self): + def update(self, scene_data): self.screen.fill((0, 0, 0)) now = time() delta = now - self.last self.last = now + + self.scene_time += delta + weight = sin(min(self.scene_time, pi/2)) ** 2 + + def update_star_scene(star, old, new, weight): + star.x = weight*new['x'] + (1-weight)*old['x'] + + for star in self.stars: star.alpha += star.rot * delta scaled = transform.rotozoom(star.image, star.alpha, star.scale) diff --git a/resources/main_window.qml b/src/starsky_presenter/resources/main_window.qml similarity index 100% rename from resources/main_window.qml rename to src/starsky_presenter/resources/main_window.qml diff --git a/src/starsky_presenter/resources/objects.yml b/src/starsky_presenter/resources/objects.yml new file mode 100644 index 0000000..eedc835 --- /dev/null +++ b/src/starsky_presenter/resources/objects.yml @@ -0,0 +1,17 @@ +stars: + - sid: star-bg-01 + x: 0.1 + y: 0.1 + scale: 0.6 + alpha: 0 + rot: 30 + offset: 0 + image: star.png + - sid: star-bg-02 + x: 0.3 + y: 0.4 + scale: 0.8 + alpha: 25 + rot: 29 + offset: 0 + image: star.png diff --git a/src/starsky_presenter/resources/scenes.yml b/src/starsky_presenter/resources/scenes.yml new file mode 100644 index 0000000..a5e78fd --- /dev/null +++ b/src/starsky_presenter/resources/scenes.yml @@ -0,0 +1,5 @@ +- +- star-bg-01: + x: 0.6 + star-bg-02: + y: 0.6 diff --git a/resources/star.png b/src/starsky_presenter/resources/star.png similarity index 100% rename from resources/star.png rename to src/starsky_presenter/resources/star.png diff --git a/resources/test.png b/src/starsky_presenter/resources/test.png similarity index 100% rename from resources/test.png rename to src/starsky_presenter/resources/test.png diff --git a/uv.lock b/uv.lock index 7c65349..345165b 100644 --- a/uv.lock +++ b/uv.lock @@ -66,6 +66,42 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/e2/91/357e9fcef5d830c3d50503d35e0357818aca3540f78748cc214dfa015d00/pyqt6_sip-13.10.2-cp314-cp314-win_arm64.whl", hash = "sha256:ce33ff1f94960ad4b08035e39fa0c3c9a67070bec39ffe3e435c792721504726", size = 46088, upload-time = "2025-10-08T08:44:10.014Z" }, ] +[[package]] +name = "pyyaml" +version = "6.0.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f", size = 130960, upload-time = "2025-09-25T21:33:16.546Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/11/0fd08f8192109f7169db964b5707a2f1e8b745d4e239b784a5a1dd80d1db/pyyaml-6.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:8da9669d359f02c0b91ccc01cac4a67f16afec0dac22c2ad09f46bee0697eba8", size = 181669, upload-time = "2025-09-25T21:32:23.673Z" }, + { url = "https://files.pythonhosted.org/packages/b1/16/95309993f1d3748cd644e02e38b75d50cbc0d9561d21f390a76242ce073f/pyyaml-6.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:2283a07e2c21a2aa78d9c4442724ec1eb15f5e42a723b99cb3d822d48f5f7ad1", size = 173252, upload-time = "2025-09-25T21:32:25.149Z" }, + { url = "https://files.pythonhosted.org/packages/50/31/b20f376d3f810b9b2371e72ef5adb33879b25edb7a6d072cb7ca0c486398/pyyaml-6.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ee2922902c45ae8ccada2c5b501ab86c36525b883eff4255313a253a3160861c", size = 767081, upload-time = "2025-09-25T21:32:26.575Z" }, + { url = "https://files.pythonhosted.org/packages/49/1e/a55ca81e949270d5d4432fbbd19dfea5321eda7c41a849d443dc92fd1ff7/pyyaml-6.0.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a33284e20b78bd4a18c8c2282d549d10bc8408a2a7ff57653c0cf0b9be0afce5", size = 841159, upload-time = "2025-09-25T21:32:27.727Z" }, + { url = "https://files.pythonhosted.org/packages/74/27/e5b8f34d02d9995b80abcef563ea1f8b56d20134d8f4e5e81733b1feceb2/pyyaml-6.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0f29edc409a6392443abf94b9cf89ce99889a1dd5376d94316ae5145dfedd5d6", size = 801626, upload-time = "2025-09-25T21:32:28.878Z" }, + { url = "https://files.pythonhosted.org/packages/f9/11/ba845c23988798f40e52ba45f34849aa8a1f2d4af4b798588010792ebad6/pyyaml-6.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:f7057c9a337546edc7973c0d3ba84ddcdf0daa14533c2065749c9075001090e6", size = 753613, upload-time = "2025-09-25T21:32:30.178Z" }, + { url = "https://files.pythonhosted.org/packages/3d/e0/7966e1a7bfc0a45bf0a7fb6b98ea03fc9b8d84fa7f2229e9659680b69ee3/pyyaml-6.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:eda16858a3cab07b80edaf74336ece1f986ba330fdb8ee0d6c0d68fe82bc96be", size = 794115, upload-time = "2025-09-25T21:32:31.353Z" }, + { url = "https://files.pythonhosted.org/packages/de/94/980b50a6531b3019e45ddeada0626d45fa85cbe22300844a7983285bed3b/pyyaml-6.0.3-cp313-cp313-win32.whl", hash = "sha256:d0eae10f8159e8fdad514efdc92d74fd8d682c933a6dd088030f3834bc8e6b26", size = 137427, upload-time = "2025-09-25T21:32:32.58Z" }, + { url = "https://files.pythonhosted.org/packages/97/c9/39d5b874e8b28845e4ec2202b5da735d0199dbe5b8fb85f91398814a9a46/pyyaml-6.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:79005a0d97d5ddabfeeea4cf676af11e647e41d81c9a7722a193022accdb6b7c", size = 154090, upload-time = "2025-09-25T21:32:33.659Z" }, + { url = "https://files.pythonhosted.org/packages/73/e8/2bdf3ca2090f68bb3d75b44da7bbc71843b19c9f2b9cb9b0f4ab7a5a4329/pyyaml-6.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:5498cd1645aa724a7c71c8f378eb29ebe23da2fc0d7a08071d89469bf1d2defb", size = 140246, upload-time = "2025-09-25T21:32:34.663Z" }, + { url = "https://files.pythonhosted.org/packages/9d/8c/f4bd7f6465179953d3ac9bc44ac1a8a3e6122cf8ada906b4f96c60172d43/pyyaml-6.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:8d1fab6bb153a416f9aeb4b8763bc0f22a5586065f86f7664fc23339fc1c1fac", size = 181814, upload-time = "2025-09-25T21:32:35.712Z" }, + { url = "https://files.pythonhosted.org/packages/bd/9c/4d95bb87eb2063d20db7b60faa3840c1b18025517ae857371c4dd55a6b3a/pyyaml-6.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:34d5fcd24b8445fadc33f9cf348c1047101756fd760b4dacb5c3e99755703310", size = 173809, upload-time = "2025-09-25T21:32:36.789Z" }, + { url = "https://files.pythonhosted.org/packages/92/b5/47e807c2623074914e29dabd16cbbdd4bf5e9b2db9f8090fa64411fc5382/pyyaml-6.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:501a031947e3a9025ed4405a168e6ef5ae3126c59f90ce0cd6f2bfc477be31b7", size = 766454, upload-time = "2025-09-25T21:32:37.966Z" }, + { url = "https://files.pythonhosted.org/packages/02/9e/e5e9b168be58564121efb3de6859c452fccde0ab093d8438905899a3a483/pyyaml-6.0.3-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:b3bc83488de33889877a0f2543ade9f70c67d66d9ebb4ac959502e12de895788", size = 836355, upload-time = "2025-09-25T21:32:39.178Z" }, + { url = "https://files.pythonhosted.org/packages/88/f9/16491d7ed2a919954993e48aa941b200f38040928474c9e85ea9e64222c3/pyyaml-6.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c458b6d084f9b935061bc36216e8a69a7e293a2f1e68bf956dcd9e6cbcd143f5", size = 794175, upload-time = "2025-09-25T21:32:40.865Z" }, + { url = "https://files.pythonhosted.org/packages/dd/3f/5989debef34dc6397317802b527dbbafb2b4760878a53d4166579111411e/pyyaml-6.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7c6610def4f163542a622a73fb39f534f8c101d690126992300bf3207eab9764", size = 755228, upload-time = "2025-09-25T21:32:42.084Z" }, + { url = "https://files.pythonhosted.org/packages/d7/ce/af88a49043cd2e265be63d083fc75b27b6ed062f5f9fd6cdc223ad62f03e/pyyaml-6.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5190d403f121660ce8d1d2c1bb2ef1bd05b5f68533fc5c2ea899bd15f4399b35", size = 789194, upload-time = "2025-09-25T21:32:43.362Z" }, + { url = "https://files.pythonhosted.org/packages/23/20/bb6982b26a40bb43951265ba29d4c246ef0ff59c9fdcdf0ed04e0687de4d/pyyaml-6.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:4a2e8cebe2ff6ab7d1050ecd59c25d4c8bd7e6f400f5f82b96557ac0abafd0ac", size = 156429, upload-time = "2025-09-25T21:32:57.844Z" }, + { url = "https://files.pythonhosted.org/packages/f4/f4/a4541072bb9422c8a883ab55255f918fa378ecf083f5b85e87fc2b4eda1b/pyyaml-6.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:93dda82c9c22deb0a405ea4dc5f2d0cda384168e466364dec6255b293923b2f3", size = 143912, upload-time = "2025-09-25T21:32:59.247Z" }, + { url = "https://files.pythonhosted.org/packages/7c/f9/07dd09ae774e4616edf6cda684ee78f97777bdd15847253637a6f052a62f/pyyaml-6.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:02893d100e99e03eda1c8fd5c441d8c60103fd175728e23e431db1b589cf5ab3", size = 189108, upload-time = "2025-09-25T21:32:44.377Z" }, + { url = "https://files.pythonhosted.org/packages/4e/78/8d08c9fb7ce09ad8c38ad533c1191cf27f7ae1effe5bb9400a46d9437fcf/pyyaml-6.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:c1ff362665ae507275af2853520967820d9124984e0f7466736aea23d8611fba", size = 183641, upload-time = "2025-09-25T21:32:45.407Z" }, + { url = "https://files.pythonhosted.org/packages/7b/5b/3babb19104a46945cf816d047db2788bcaf8c94527a805610b0289a01c6b/pyyaml-6.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6adc77889b628398debc7b65c073bcb99c4a0237b248cacaf3fe8a557563ef6c", size = 831901, upload-time = "2025-09-25T21:32:48.83Z" }, + { url = "https://files.pythonhosted.org/packages/8b/cc/dff0684d8dc44da4d22a13f35f073d558c268780ce3c6ba1b87055bb0b87/pyyaml-6.0.3-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a80cb027f6b349846a3bf6d73b5e95e782175e52f22108cfa17876aaeff93702", size = 861132, upload-time = "2025-09-25T21:32:50.149Z" }, + { url = "https://files.pythonhosted.org/packages/b1/5e/f77dc6b9036943e285ba76b49e118d9ea929885becb0a29ba8a7c75e29fe/pyyaml-6.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:00c4bdeba853cc34e7dd471f16b4114f4162dc03e6b7afcc2128711f0eca823c", size = 839261, upload-time = "2025-09-25T21:32:51.808Z" }, + { url = "https://files.pythonhosted.org/packages/ce/88/a9db1376aa2a228197c58b37302f284b5617f56a5d959fd1763fb1675ce6/pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:66e1674c3ef6f541c35191caae2d429b967b99e02040f5ba928632d9a7f0f065", size = 805272, upload-time = "2025-09-25T21:32:52.941Z" }, + { url = "https://files.pythonhosted.org/packages/da/92/1446574745d74df0c92e6aa4a7b0b3130706a4142b2d1a5869f2eaa423c6/pyyaml-6.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:16249ee61e95f858e83976573de0f5b2893b3677ba71c9dd36b9cf8be9ac6d65", size = 829923, upload-time = "2025-09-25T21:32:54.537Z" }, + { url = "https://files.pythonhosted.org/packages/f0/7a/1c7270340330e575b92f397352af856a8c06f230aa3e76f86b39d01b416a/pyyaml-6.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4ad1906908f2f5ae4e5a8ddfce73c320c2a1429ec52eafd27138b7f1cbe341c9", size = 174062, upload-time = "2025-09-25T21:32:55.767Z" }, + { url = "https://files.pythonhosted.org/packages/f1/12/de94a39c2ef588c7e6455cfbe7343d3b2dc9d6b6b2f40c4c6565744c873d/pyyaml-6.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b", size = 149341, upload-time = "2025-09-25T21:32:56.828Z" }, +] + [[package]] name = "starsky-presenter" version = "0.1.0" @@ -73,10 +109,12 @@ source = { editable = "." } dependencies = [ { name = "pygame" }, { name = "pyqt6" }, + { name = "pyyaml" }, ] [package.metadata] requires-dist = [ { name = "pygame", specifier = ">=2.6.1" }, { name = "pyqt6", specifier = ">=6.10.0" }, + { name = "pyyaml", specifier = ">=6.0.3" }, ]