make everything work with screen manager
This commit is contained in:
parent
b32e93f2fc
commit
f1b078affc
@ -86,3 +86,14 @@ def update(playlist_id):
|
||||
|
||||
return jsonify(success=True)
|
||||
|
||||
@playlist.route('/<int:playlist_id>/activate', methods=["POST"])
|
||||
def activate(playlist_id):
|
||||
screen_manager = ScreenManager.getInstance()
|
||||
screen_manager.activate_playlist(playlist_id)
|
||||
return jsonify(success=True)
|
||||
|
||||
@playlist.route('/<int:playlist_id>/disactivate', methods=["POST"])
|
||||
def disactivate(playlist_id):
|
||||
screen_manager = ScreenManager.getInstance()
|
||||
screen_manager.disactivate_playlist()
|
||||
return jsonify(success=True)
|
||||
|
@ -1,10 +1,11 @@
|
||||
from api import create_api
|
||||
|
||||
|
||||
from screen.ScreenManager import ScreenManager
|
||||
|
||||
api = create_api()
|
||||
screen_manager = ScreenManager().getInstance()
|
||||
|
||||
if __name__ == '__main__':
|
||||
api.run(host="0.0.0.0", port=5500, debug=True)
|
||||
#api.run(host="0.0.0.0", port=5500, debug=True)
|
||||
api.run(host="0.0.0.0", port=5500)
|
||||
|
||||
|
||||
|
38
src/screen/ScreenManager.py
Normal file
38
src/screen/ScreenManager.py
Normal file
@ -0,0 +1,38 @@
|
||||
import tkinter as tk
|
||||
from .SlideShow import SlideShow
|
||||
from api.dao.Playlist import PlaylistDao
|
||||
from multiprocessing import Process
|
||||
|
||||
def create_slideshow(files):
|
||||
root = tk.Tk()
|
||||
root.title("Slideshow")
|
||||
SlideShow(root, files)
|
||||
root.mainloop()
|
||||
|
||||
class ScreenManager:
|
||||
__instance = None
|
||||
__slideshow_process = None
|
||||
|
||||
@staticmethod
|
||||
def getInstance():
|
||||
if ScreenManager.__instance == None:
|
||||
SreenManager()
|
||||
return ScreenManager.__instance
|
||||
|
||||
def __init__(self):
|
||||
if ScreenManager.__instance != None:
|
||||
raise Exception("Screen manager already exists!")
|
||||
else:
|
||||
ScreenManager.__instance = self
|
||||
|
||||
def activate_playlist(self, playlist_id):
|
||||
(_, files) = PlaylistDao.get_playlist(playlist_id)
|
||||
self.disactivate_playlist()
|
||||
x = Process(target=create_slideshow, args=(files,))
|
||||
x.start()
|
||||
self.__slideshow_process = x
|
||||
|
||||
def disactivate_playlist(self):
|
||||
if self.__slideshow_process:
|
||||
self.__slideshow_process.terminate()
|
||||
self.__slideshow_process = None
|
35
src/screen/SlideShow.py
Normal file
35
src/screen/SlideShow.py
Normal file
@ -0,0 +1,35 @@
|
||||
import tkinter as tk
|
||||
from PIL import ImageTk, Image
|
||||
import time
|
||||
|
||||
class SlideShow:
|
||||
def __init__(self, root, files):
|
||||
self.root = root
|
||||
self.files = files
|
||||
self.idx = 0
|
||||
|
||||
self.image_label = tk.Label(root)
|
||||
self.image_label.pack()
|
||||
self.image_label.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
self.root.after(100, self.next_file)
|
||||
|
||||
def next_file(self):
|
||||
file = self.files[self.idx]
|
||||
path = './data/' + file['name']
|
||||
image = Image.open(path)
|
||||
|
||||
# Get root window width and height
|
||||
screen_width = self.root.winfo_width()
|
||||
screen_height = self.root.winfo_height()
|
||||
|
||||
# Resize the image to fit the screen
|
||||
image = image.resize((screen_width, screen_height), Image.ANTIALIAS)
|
||||
|
||||
photo = ImageTk.PhotoImage(image)
|
||||
self.image_label.config(image=photo)
|
||||
self.image_label.image = photo
|
||||
|
||||
self.idx = (self.idx + 1) % len(self.files)
|
||||
self.root.after(file['seconds'] * 1000, self.next_file)
|
||||
|
@ -1,46 +0,0 @@
|
||||
import tkinter as tk
|
||||
from PIL import ImageTk, Image
|
||||
import os
|
||||
import time
|
||||
|
||||
class SlideshowApp:
|
||||
def __init__(self, root, image_paths):
|
||||
self.root = root
|
||||
self.paths = image_paths
|
||||
self.idx = 0
|
||||
|
||||
self.image_label = tk.Label(root)
|
||||
self.image_label.pack()
|
||||
self.image_label.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
self.show_next_image()
|
||||
|
||||
def show_next_image(self):
|
||||
img_path = self.paths[self.idx]
|
||||
image = Image.open(img_path)
|
||||
|
||||
# Get root window width and height
|
||||
screen_width = self.root.winfo_width()
|
||||
screen_height = self.root.winfo_height()
|
||||
|
||||
# Resize the image to fit the screen
|
||||
image = image.resize((screen_width, screen_height), Image.ANTIALIAS)
|
||||
|
||||
photo = ImageTk.PhotoImage(image)
|
||||
self.image_label.config(image=photo)
|
||||
self.image_label.image = photo
|
||||
|
||||
self.idx = (self.idx + 1) % len(self.paths)
|
||||
self.root.after(2000, self.show_next_image)
|
||||
|
||||
def main():
|
||||
root = tk.Tk()
|
||||
root.title("Image Slideshow")
|
||||
|
||||
|
||||
img_paths = ["./data/960x0-1053101061.jpg", "./data/my-linux-desktop-1131547615.png", "./data/glzrkk83f4621-1200x671-54057802.jpg", "./data/yjdoiycuw04lvrebijtw-605729284.jpg"]
|
||||
app = SlideshowApp(root, img_paths)
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user