Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 53b69f95cb | |||
| df7dfe302e | |||
| 0f8f9094b6 | |||
| 06aed9bed3 | |||
| 958084ede1 | |||
| c198ce3640 | |||
| 03fc72f54f | |||
| 8fd9d1f55b | |||
| 7e01723901 | |||
| dcc2697176 | |||
| 83d69f7c2d | |||
| 8d23d0170f | |||
| 0d386b08b6 | |||
| 209a020418 |
BIN
cloudflared.zip
BIN
cloudflared.zip
Binary file not shown.
BIN
dashboard_app.png
Normal file
BIN
dashboard_app.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 128 KiB |
545
dashboard_app.py
Normal file
545
dashboard_app.py
Normal file
@@ -0,0 +1,545 @@
|
|||||||
|
import ctypes
|
||||||
|
import io
|
||||||
|
import math
|
||||||
|
import queue
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import tkinter as tk
|
||||||
|
from datetime import datetime
|
||||||
|
from flask import Flask, jsonify, request
|
||||||
|
from PIL import Image, ImageTk
|
||||||
|
import requests
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# SÍŤOVÝ SERVER & GLOBÁLNÍ PAMĚŤ
|
||||||
|
# ==============================================================================
|
||||||
|
SPOTIFY_SERVER_URL = "http://localhost:8080/endpoint"
|
||||||
|
|
||||||
|
order_queue = queue.Queue()
|
||||||
|
ORDERS = {}
|
||||||
|
|
||||||
|
flask_app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@flask_app.route('/api/order', methods=['POST'])
|
||||||
|
def receive_order():
|
||||||
|
"""Přijme novou objednávku a uloží ji."""
|
||||||
|
try:
|
||||||
|
data = request.json or {}
|
||||||
|
order_id = str(random.randint(1000, 9999))
|
||||||
|
data['id'] = order_id
|
||||||
|
data['status'] = 'čaká na potvrzení'
|
||||||
|
|
||||||
|
ORDERS[order_id] = data
|
||||||
|
order_queue.put(data)
|
||||||
|
|
||||||
|
return (
|
||||||
|
jsonify(
|
||||||
|
{'status': 'success', 'order_id': order_id, 'message': 'Doručeno'}
|
||||||
|
),
|
||||||
|
200,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({'status': 'error', 'message': str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@flask_app.route('/api/order/<order_id>/status', methods=['GET'])
|
||||||
|
def get_order_status(order_id):
|
||||||
|
"""Vzdálený PC zjišťuje, zda byla objednávka na stánku potvrzena."""
|
||||||
|
order = ORDERS.get(str(order_id))
|
||||||
|
if not order:
|
||||||
|
return jsonify({'error': 'Nenalezeno'}), 404
|
||||||
|
return jsonify({'order_id': order_id, 'status': order['status']})
|
||||||
|
|
||||||
|
|
||||||
|
def run_flask():
|
||||||
|
flask_app.run(host='0.0.0.0', port=5000, debug=False, use_reloader=False)
|
||||||
|
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# WINDOWS MULTIMEDIÁLNÍ KLÁVESY
|
||||||
|
# ==============================================================================
|
||||||
|
VK_MEDIA_NEXT = 0xB0
|
||||||
|
VK_MEDIA_PREV = 0xB1
|
||||||
|
VK_MEDIA_PLAY_PAUSE = 0xCD
|
||||||
|
KEYEVENTF_EXTENDEDKEY = 0x0001
|
||||||
|
KEYEVENTF_KEYUP = 0x0002
|
||||||
|
|
||||||
|
|
||||||
|
def send_media_key(key_code):
|
||||||
|
"""Simuluje stisknutí hardwarové klávesy ve Windows."""
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
ctypes.windll.user32.keybd_event(key_code, 0, KEYEVENTF_EXTENDEDKEY, 0)
|
||||||
|
ctypes.windll.user32.keybd_event(
|
||||||
|
key_code, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ==============================================================================
|
||||||
|
# MAIN DASHBOARD GUI
|
||||||
|
# ==============================================================================
|
||||||
|
class ParticleDashboard(tk.Tk):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.title("Příchozí Objednávky & Spotify Dashboard")
|
||||||
|
self.attributes("-fullscreen", True)
|
||||||
|
self.configure(bg="#0a0e17")
|
||||||
|
|
||||||
|
self.bind("<Escape>", lambda e: self.attributes("-fullscreen", False))
|
||||||
|
self.bind(
|
||||||
|
"<F11>",
|
||||||
|
lambda e: self.attributes(
|
||||||
|
"-fullscreen", not self.attributes("-fullscreen")
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.width = self.winfo_screenwidth()
|
||||||
|
self.height = self.winfo_screenheight()
|
||||||
|
|
||||||
|
self.canvas = tk.Canvas(
|
||||||
|
self,
|
||||||
|
width=self.width,
|
||||||
|
height=self.height,
|
||||||
|
bg="#0a0e17",
|
||||||
|
highlightthickness=0,
|
||||||
|
)
|
||||||
|
self.canvas.pack(fill="both", expand=True)
|
||||||
|
|
||||||
|
# Částice na pozadí
|
||||||
|
self.num_particles = 50
|
||||||
|
self.particles = []
|
||||||
|
colors = ["#00f2fe", "#4facfe", "#1db954", "#7b2cbf", "#38bdf8"]
|
||||||
|
for _ in range(self.num_particles):
|
||||||
|
self.particles.append({
|
||||||
|
"x": random.uniform(0, self.width),
|
||||||
|
"y": random.uniform(0, self.height),
|
||||||
|
"vx": random.uniform(-0.5, 0.5),
|
||||||
|
"vy": random.uniform(-0.5, 0.5),
|
||||||
|
"radius": random.uniform(2, 4),
|
||||||
|
"color": random.choice(colors),
|
||||||
|
})
|
||||||
|
|
||||||
|
self.orders_list = []
|
||||||
|
self.current_img_url = None
|
||||||
|
self.cover_photo = None
|
||||||
|
self.is_running = True
|
||||||
|
|
||||||
|
self.create_ui_overlays()
|
||||||
|
self.animate_particles()
|
||||||
|
self.update_clock()
|
||||||
|
self.check_new_orders()
|
||||||
|
|
||||||
|
# Vlákno pro Spotify polling
|
||||||
|
threading.Thread(target=self._spotify_poll_loop, daemon=True).start()
|
||||||
|
|
||||||
|
def create_ui_overlays(self):
|
||||||
|
self.main_container = tk.Frame(self.canvas, bg="#0a0e17")
|
||||||
|
self.canvas.create_window(
|
||||||
|
self.width // 2,
|
||||||
|
self.height // 2,
|
||||||
|
window=self.main_container,
|
||||||
|
width=self.width - 60,
|
||||||
|
height=self.height - 60,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.main_container.columnconfigure(0, weight=3)
|
||||||
|
self.main_container.columnconfigure(1, weight=1)
|
||||||
|
self.main_container.rowconfigure(1, weight=1)
|
||||||
|
|
||||||
|
# HEADER
|
||||||
|
header = tk.Frame(
|
||||||
|
self.main_container,
|
||||||
|
bg="#111827",
|
||||||
|
highlightbackground="#1f2937",
|
||||||
|
highlightthickness=1,
|
||||||
|
)
|
||||||
|
header.grid(
|
||||||
|
row=0, column=0, columnspan=2, sticky="ew", pady=(0, 15), ipady=10
|
||||||
|
)
|
||||||
|
|
||||||
|
title = tk.Label(
|
||||||
|
header,
|
||||||
|
text="⚡ PŘÍCHOZÍ OBJEDNÁVKY (STÁNEK)",
|
||||||
|
font=("Segoe UI", 20, "bold"),
|
||||||
|
fg="#00f2fe",
|
||||||
|
bg="#111827",
|
||||||
|
)
|
||||||
|
title.pack(side="left", padx=20)
|
||||||
|
|
||||||
|
self.time_lbl = tk.Label(
|
||||||
|
header, text="", font=("Segoe UI", 15, "bold"), fg="#9ca3af", bg="#111827"
|
||||||
|
)
|
||||||
|
self.time_lbl.pack(side="right", padx=20)
|
||||||
|
|
||||||
|
# LEVÝ PANEL - FRONTA OBJEDNÁVEK
|
||||||
|
self.orders_box = tk.Frame(
|
||||||
|
self.main_container,
|
||||||
|
bg="#111827",
|
||||||
|
highlightbackground="#1f2937",
|
||||||
|
highlightthickness=1,
|
||||||
|
)
|
||||||
|
self.orders_box.grid(row=1, column=0, sticky="nsew", padx=(0, 12))
|
||||||
|
|
||||||
|
tk.Label(
|
||||||
|
self.orders_box,
|
||||||
|
text="AKTUÁLNÍ FRONTA ZÁSILEK (ŽIVĚ)",
|
||||||
|
font=("Segoe UI", 11, "bold"),
|
||||||
|
fg="#6b7280",
|
||||||
|
bg="#111827",
|
||||||
|
).pack(anchor="w", padx=20, pady=(15, 10))
|
||||||
|
|
||||||
|
self.orders_scroll = tk.Frame(self.orders_box, bg="#111827")
|
||||||
|
self.orders_scroll.pack(fill="both", expand=True, padx=15, pady=5)
|
||||||
|
|
||||||
|
self.empty_lbl = tk.Label(
|
||||||
|
self.orders_scroll,
|
||||||
|
text="⏳ Čekám na první příchozí objednávku...",
|
||||||
|
font=("Segoe UI", 13, "italic"),
|
||||||
|
fg="#4b5563",
|
||||||
|
bg="#111827",
|
||||||
|
)
|
||||||
|
self.empty_lbl.pack(pady=50)
|
||||||
|
|
||||||
|
# PRAVÝ PANEL - STATISTIKY & SPOTIFY
|
||||||
|
right_panel = tk.Frame(self.main_container, bg="#0a0e17")
|
||||||
|
right_panel.grid(row=1, column=1, sticky="nsew")
|
||||||
|
|
||||||
|
stats_card = tk.Frame(
|
||||||
|
right_panel,
|
||||||
|
bg="#111827",
|
||||||
|
highlightbackground="#1f2937",
|
||||||
|
highlightthickness=1,
|
||||||
|
)
|
||||||
|
stats_card.pack(fill="x", pady=(0, 15), ipady=10)
|
||||||
|
|
||||||
|
tk.Label(
|
||||||
|
stats_card,
|
||||||
|
text="DNEŠNÍ PŘEHLED",
|
||||||
|
font=("Segoe UI", 11, "bold"),
|
||||||
|
fg="#6b7280",
|
||||||
|
bg="#111827",
|
||||||
|
).pack(anchor="w", padx=15, pady=(5, 5))
|
||||||
|
self.stats_total_lbl = tk.Label(
|
||||||
|
stats_card,
|
||||||
|
text="Celkem objednávek: 0 ks",
|
||||||
|
font=("Segoe UI", 13),
|
||||||
|
fg="#e5e7eb",
|
||||||
|
bg="#111827",
|
||||||
|
)
|
||||||
|
self.stats_total_lbl.pack(anchor="w", padx=15)
|
||||||
|
self.stats_money_lbl = tk.Label(
|
||||||
|
stats_card,
|
||||||
|
text="Tržba celkem: 0 Kč",
|
||||||
|
font=("Segoe UI", 13, "bold"),
|
||||||
|
fg="#38bdf8",
|
||||||
|
bg="#111827",
|
||||||
|
)
|
||||||
|
self.stats_money_lbl.pack(anchor="w", padx=15)
|
||||||
|
|
||||||
|
# SPOTIFY WIDGET
|
||||||
|
sp_card = tk.Frame(
|
||||||
|
right_panel,
|
||||||
|
bg="#121212",
|
||||||
|
highlightbackground="#1db954",
|
||||||
|
highlightthickness=1,
|
||||||
|
)
|
||||||
|
sp_card.pack(fill="x", side="bottom", ipady=10)
|
||||||
|
|
||||||
|
sp_head = tk.Frame(sp_card, bg="#121212")
|
||||||
|
sp_head.pack(fill="x", padx=15, pady=(10, 5))
|
||||||
|
tk.Label(
|
||||||
|
sp_head,
|
||||||
|
text="♫ SPOTIFY PLAYER",
|
||||||
|
font=("Segoe UI", 11, "bold"),
|
||||||
|
fg="#1db954",
|
||||||
|
bg="#121212",
|
||||||
|
).pack(side="left")
|
||||||
|
|
||||||
|
info_frame = tk.Frame(sp_card, bg="#121212")
|
||||||
|
info_frame.pack(fill="x", padx=15, pady=5)
|
||||||
|
|
||||||
|
self.sp_title_lbl = tk.Label(
|
||||||
|
info_frame,
|
||||||
|
text="Načítám Spotify...",
|
||||||
|
font=("Segoe UI", 15, "bold"),
|
||||||
|
fg="#ffffff",
|
||||||
|
bg="#121212",
|
||||||
|
anchor="w",
|
||||||
|
)
|
||||||
|
self.sp_title_lbl.pack(fill="x")
|
||||||
|
|
||||||
|
self.sp_artist_lbl = tk.Label(
|
||||||
|
info_frame,
|
||||||
|
text="Připojování k serveru",
|
||||||
|
font=("Segoe UI", 11),
|
||||||
|
fg="#b3b3b3",
|
||||||
|
bg="#121212",
|
||||||
|
anchor="w",
|
||||||
|
)
|
||||||
|
self.sp_artist_lbl.pack(fill="x")
|
||||||
|
|
||||||
|
self.sp_progress_lbl = tk.Label(
|
||||||
|
info_frame,
|
||||||
|
text="0:00 / 0:00",
|
||||||
|
font=("Segoe UI", 9),
|
||||||
|
fg="#6b7280",
|
||||||
|
bg="#121212",
|
||||||
|
anchor="w",
|
||||||
|
)
|
||||||
|
self.sp_progress_lbl.pack(fill="x", pady=(2, 0))
|
||||||
|
|
||||||
|
ctrls = tk.Frame(sp_card, bg="#121212")
|
||||||
|
ctrls.pack(pady=10)
|
||||||
|
|
||||||
|
tk.Button(
|
||||||
|
ctrls,
|
||||||
|
text="⏮",
|
||||||
|
font=("Segoe UI", 14),
|
||||||
|
fg="#ffffff",
|
||||||
|
bg="#282828",
|
||||||
|
bd=0,
|
||||||
|
padx=12,
|
||||||
|
cursor="hand2",
|
||||||
|
command=lambda: send_media_key(VK_MEDIA_PREV),
|
||||||
|
).pack(side="left", padx=8)
|
||||||
|
|
||||||
|
tk.Button(
|
||||||
|
ctrls,
|
||||||
|
text="⏯",
|
||||||
|
font=("Segoe UI", 16, "bold"),
|
||||||
|
fg="#000000",
|
||||||
|
bg="#1db954",
|
||||||
|
bd=0,
|
||||||
|
padx=14,
|
||||||
|
pady=2,
|
||||||
|
cursor="hand2",
|
||||||
|
command=lambda: send_media_key(VK_MEDIA_PLAY_PAUSE),
|
||||||
|
).pack(side="left", padx=8)
|
||||||
|
|
||||||
|
tk.Button(
|
||||||
|
ctrls,
|
||||||
|
text="⏭",
|
||||||
|
font=("Segoe UI", 14),
|
||||||
|
fg="#ffffff",
|
||||||
|
bg="#282828",
|
||||||
|
bd=0,
|
||||||
|
padx=12,
|
||||||
|
cursor="hand2",
|
||||||
|
command=lambda: send_media_key(VK_MEDIA_NEXT),
|
||||||
|
).pack(side="left", padx=8)
|
||||||
|
|
||||||
|
# ==========================================================================
|
||||||
|
# LOGIKA OBJEDNÁVEK A POTVRZOVÁNÍ
|
||||||
|
# ==========================================================================
|
||||||
|
def add_order_to_ui(self, order_data):
|
||||||
|
if self.empty_lbl:
|
||||||
|
self.empty_lbl.destroy()
|
||||||
|
self.empty_lbl = None
|
||||||
|
|
||||||
|
order_id = str(order_data.get("id"))
|
||||||
|
customer = order_data.get("customer", "Neznámý")
|
||||||
|
product = order_data.get("product", "Zboží")
|
||||||
|
quantity = order_data.get("quantity", 1)
|
||||||
|
price_unit = order_data.get("price", 0)
|
||||||
|
dobirka = order_data.get("dobirka", 0)
|
||||||
|
time_str = order_data.get("time", datetime.now().strftime("%H:%M:%S"))
|
||||||
|
|
||||||
|
total_price = quantity * price_unit
|
||||||
|
self.orders_list.append({"total": total_price, "qty": quantity})
|
||||||
|
|
||||||
|
# Řádek objednávky
|
||||||
|
row = tk.Frame(
|
||||||
|
self.orders_scroll,
|
||||||
|
bg="#1f2937",
|
||||||
|
highlightbackground="#374151",
|
||||||
|
highlightthickness=1,
|
||||||
|
)
|
||||||
|
row.pack(fill="x", pady=4, ipady=6)
|
||||||
|
|
||||||
|
left_info = tk.Frame(row, bg="#1f2937")
|
||||||
|
left_info.pack(side="left", padx=10)
|
||||||
|
|
||||||
|
tk.Label(
|
||||||
|
left_info,
|
||||||
|
text=f"#{order_id}",
|
||||||
|
font=("Segoe UI", 13, "bold"),
|
||||||
|
fg="#00f2fe",
|
||||||
|
bg="#1f2937",
|
||||||
|
).pack(anchor="w")
|
||||||
|
tk.Label(
|
||||||
|
left_info,
|
||||||
|
text=time_str,
|
||||||
|
font=("Segoe UI", 10),
|
||||||
|
fg="#9ca3af",
|
||||||
|
bg="#1f2937",
|
||||||
|
).pack(anchor="w")
|
||||||
|
|
||||||
|
mid_info = tk.Frame(row, bg="#1f2937")
|
||||||
|
mid_info.pack(side="left", padx=15, fill="x", expand=True)
|
||||||
|
|
||||||
|
title_text = f"{customer} • {quantity}x {product}"
|
||||||
|
tk.Label(
|
||||||
|
mid_info,
|
||||||
|
text=title_text,
|
||||||
|
font=("Segoe UI", 12, "bold"),
|
||||||
|
fg="#f3f4f6",
|
||||||
|
bg="#1f2937",
|
||||||
|
anchor="w",
|
||||||
|
).pack(fill="x")
|
||||||
|
|
||||||
|
detail_text = f"Celkem: {total_price:.0f} Kč ({price_unit:.0f} Kč/ks)"
|
||||||
|
if dobirka > 0:
|
||||||
|
detail_text += f" | ⚠️ Dobírka: {dobirka:.0f} Kč"
|
||||||
|
else:
|
||||||
|
detail_text += " | Zaplaceno"
|
||||||
|
|
||||||
|
tk.Label(
|
||||||
|
mid_info,
|
||||||
|
text=detail_text,
|
||||||
|
font=("Segoe UI", 11),
|
||||||
|
fg="#38bdf8" if dobirka == 0 else "#fbbf24",
|
||||||
|
bg="#1f2937",
|
||||||
|
anchor="w",
|
||||||
|
).pack(fill="x")
|
||||||
|
|
||||||
|
# Odznak stavu + Tlačítko Potvrdit
|
||||||
|
badge = tk.Label(
|
||||||
|
row,
|
||||||
|
text="ČEKÁ",
|
||||||
|
font=("Segoe UI", 10, "bold"),
|
||||||
|
fg="#ffffff",
|
||||||
|
bg="#ef4444",
|
||||||
|
padx=10,
|
||||||
|
pady=4,
|
||||||
|
)
|
||||||
|
badge.pack(side="right", padx=(5, 12))
|
||||||
|
|
||||||
|
btn_confirm = tk.Button(
|
||||||
|
row,
|
||||||
|
text="POTVRDIT",
|
||||||
|
font=("Segoe UI", 10, "bold"),
|
||||||
|
fg="#ffffff",
|
||||||
|
bg="#10b981",
|
||||||
|
activebackground="#059669",
|
||||||
|
activeforeground="#ffffff",
|
||||||
|
bd=0,
|
||||||
|
padx=10,
|
||||||
|
pady=3,
|
||||||
|
cursor="hand2",
|
||||||
|
)
|
||||||
|
btn_confirm.pack(side="right", padx=5)
|
||||||
|
|
||||||
|
def confirm_action():
|
||||||
|
ORDERS[order_id]["status"] = "potvrzeno"
|
||||||
|
badge.config(text="POTVRZENO", bg="#10b981")
|
||||||
|
btn_confirm.config(
|
||||||
|
text="✓ HOTOVO", bg="#374151", state="disabled", cursor="default"
|
||||||
|
)
|
||||||
|
|
||||||
|
btn_confirm.config(command=confirm_action)
|
||||||
|
|
||||||
|
# Aktualizace statistik
|
||||||
|
total_cnt = len(self.orders_list)
|
||||||
|
sum_money = sum(o["total"] for o in self.orders_list)
|
||||||
|
self.stats_total_lbl.config(text=f"Celkem objednávek: {total_cnt} ks")
|
||||||
|
self.stats_money_lbl.config(text=f"Tržba celkem: {sum_money:.0f} Kč")
|
||||||
|
|
||||||
|
def check_new_orders(self):
|
||||||
|
while not order_queue.empty():
|
||||||
|
order = order_queue.get()
|
||||||
|
self.add_order_to_ui(order)
|
||||||
|
self.after(300, self.check_new_orders)
|
||||||
|
|
||||||
|
# ==========================================================================
|
||||||
|
# SPOTIFY POLLING LOGIKA
|
||||||
|
# ==========================================================================
|
||||||
|
def _spotify_poll_loop(self):
|
||||||
|
while self.is_running:
|
||||||
|
try:
|
||||||
|
res = requests.get(SPOTIFY_SERVER_URL, timeout=2)
|
||||||
|
if res.status_code == 200:
|
||||||
|
data = res.json()
|
||||||
|
artist = str(data.get("artist", "Neznámý interpret")).strip()
|
||||||
|
title = str(data.get("title", "Žádná skladba")).strip()
|
||||||
|
progress = str(data.get("progressTime", "0:00 / 0:00"))
|
||||||
|
|
||||||
|
def apply():
|
||||||
|
self.sp_title_lbl.config(text=title if title else "Žádná skladba")
|
||||||
|
self.sp_artist_lbl.config(
|
||||||
|
text=artist if artist else "Spotify nehraje"
|
||||||
|
)
|
||||||
|
self.sp_progress_lbl.config(text=progress)
|
||||||
|
|
||||||
|
self.after(0, apply)
|
||||||
|
except Exception:
|
||||||
|
def apply_err():
|
||||||
|
self.sp_title_lbl.config(text="Spotify odpojeno")
|
||||||
|
self.sp_artist_lbl.config(text="Nelze načíst z localhost:8080")
|
||||||
|
|
||||||
|
self.after(0, apply_err)
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
# ==========================================================================
|
||||||
|
# ANIMACE ČÁSTIC A HODINY
|
||||||
|
# ==========================================================================
|
||||||
|
def animate_particles(self):
|
||||||
|
self.canvas.delete("particle")
|
||||||
|
self.canvas.delete("line")
|
||||||
|
|
||||||
|
for p in self.particles:
|
||||||
|
p["x"] += p["vx"]
|
||||||
|
p["y"] += p["vy"]
|
||||||
|
|
||||||
|
if p["x"] <= 0 or p["x"] >= self.width:
|
||||||
|
p["vx"] *= -1
|
||||||
|
if p["y"] <= 0 or p["y"] >= self.height:
|
||||||
|
p["vy"] *= -1
|
||||||
|
|
||||||
|
x, y, r = p["x"], p["y"], p["radius"]
|
||||||
|
self.canvas.create_oval(
|
||||||
|
x - r,
|
||||||
|
y - r,
|
||||||
|
x + r,
|
||||||
|
y + r,
|
||||||
|
fill=p["color"],
|
||||||
|
outline="",
|
||||||
|
tags="particle",
|
||||||
|
)
|
||||||
|
|
||||||
|
for i in range(len(self.particles)):
|
||||||
|
for j in range(i + 1, len(self.particles)):
|
||||||
|
p1 = self.particles[i]
|
||||||
|
p2 = self.particles[j]
|
||||||
|
dist = math.hypot(p1["x"] - p2["x"], p1["y"] - p2["y"])
|
||||||
|
|
||||||
|
if dist < 110:
|
||||||
|
self.canvas.create_line(
|
||||||
|
p1["x"],
|
||||||
|
p1["y"],
|
||||||
|
p2["x"],
|
||||||
|
p2["y"],
|
||||||
|
fill="#1e293b",
|
||||||
|
width=1,
|
||||||
|
tags="line",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.after(25, self.animate_particles)
|
||||||
|
|
||||||
|
def update_clock(self):
|
||||||
|
now = datetime.now().strftime("%H:%M:%S | %d.%m.%Y")
|
||||||
|
self.time_lbl.config(text=now)
|
||||||
|
self.after(1000, self.update_clock)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 1. Spuštění Flasku v pozadí
|
||||||
|
t = threading.Thread(target=run_flask, daemon=True)
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
# 2. Spuštění Tkinter GUI
|
||||||
|
app = ParticleDashboard()
|
||||||
|
app.mainloop()
|
||||||
BIN
katalog+zvuky.zip
Normal file
BIN
katalog+zvuky.zip
Normal file
Binary file not shown.
BIN
sender_app.png
BIN
sender_app.png
Binary file not shown.
|
Before Width: | Height: | Size: 104 KiB |
396
sender_app.py
396
sender_app.py
@@ -1,396 +0,0 @@
|
|||||||
import datetime
|
|
||||||
import queue
|
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
import tkinter as tk
|
|
||||||
from tkinter import messagebox
|
|
||||||
from datetime import datetime
|
|
||||||
import requests
|
|
||||||
|
|
||||||
|
|
||||||
class OrderSenderApp(tk.Tk):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.title("Odesílač zásilek na stánek")
|
|
||||||
self.geometry("960x640") # Rozšířeno pro pravý katalog
|
|
||||||
self.resizable(False, False)
|
|
||||||
self.configure(bg="#0f172a")
|
|
||||||
|
|
||||||
# Paměť pro sledování odeslaných zásilek
|
|
||||||
self.sent_orders = (
|
|
||||||
{}
|
|
||||||
) # { order_id: {'badge': widget, 'status': 'čaká na potvrzení'} }
|
|
||||||
|
|
||||||
# Hlavička
|
|
||||||
header = tk.Frame(self, bg="#1e293b")
|
|
||||||
header.pack(fill="x", ipady=12)
|
|
||||||
tk.Label(
|
|
||||||
header,
|
|
||||||
text="📦 ODESLÁNÍ ZÁSILKY & KATALOG ODESLANÝCH",
|
|
||||||
font=("Segoe UI", 14, "bold"),
|
|
||||||
fg="#38bdf8",
|
|
||||||
bg="#1e293b",
|
|
||||||
).pack()
|
|
||||||
|
|
||||||
# Hlavní rozdělený kontejner (Vlevo formulář, vpravo katalog)
|
|
||||||
main_container = tk.Frame(self, bg="#0f172a")
|
|
||||||
main_container.pack(fill="both", expand=True, padx=20, pady=15)
|
|
||||||
|
|
||||||
# ==========================================================================
|
|
||||||
# LEVÝ PANEL - FORMULÁŘ
|
|
||||||
# ==========================================================================
|
|
||||||
form = tk.Frame(main_container, bg="#0f172a", width=420)
|
|
||||||
form.pack(side="left", fill="both", padx=(0, 15))
|
|
||||||
|
|
||||||
tk.Label(
|
|
||||||
form,
|
|
||||||
text="NOVÁ OBJEDNÁVKA",
|
|
||||||
font=("Segoe UI", 11, "bold"),
|
|
||||||
fg="#94a3b8",
|
|
||||||
bg="#0f172a",
|
|
||||||
).pack(anchor="w", pady=(0, 5))
|
|
||||||
|
|
||||||
self.create_label(form, "Cloudflare URL Adresa serveru:")
|
|
||||||
self.url_entry = self.create_entry(form)
|
|
||||||
self.url_entry.insert(
|
|
||||||
0, "https://protein-floyd-trance-affiliates.trycloudflare.com"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.create_label(form, "Jméno a příjmení zákazníka:")
|
|
||||||
self.customer_entry = self.create_entry(form)
|
|
||||||
self.customer_entry.insert(0, "Jan Novák")
|
|
||||||
|
|
||||||
self.create_label(form, "Název produktu / zboží:")
|
|
||||||
self.product_entry = self.create_entry(form)
|
|
||||||
self.product_entry.insert(0, "Párek v rohlíku + Kofola")
|
|
||||||
|
|
||||||
row_frame = tk.Frame(form, bg="#0f172a")
|
|
||||||
row_frame.pack(fill="x", pady=5)
|
|
||||||
|
|
||||||
f1 = tk.Frame(row_frame, bg="#0f172a")
|
|
||||||
f1.pack(side="left", fill="x", expand=True, padx=(0, 5))
|
|
||||||
tk.Label(
|
|
||||||
f1,
|
|
||||||
text="Počet kusů:",
|
|
||||||
font=("Segoe UI", 10, "bold"),
|
|
||||||
fg="#94a3b8",
|
|
||||||
bg="#0f172a",
|
|
||||||
anchor="w",
|
|
||||||
).pack(fill="x")
|
|
||||||
self.qty_entry = tk.Entry(
|
|
||||||
f1,
|
|
||||||
font=("Segoe UI", 11),
|
|
||||||
bg="#1e293b",
|
|
||||||
fg="#ffffff",
|
|
||||||
insertbackground="white",
|
|
||||||
bd=1,
|
|
||||||
relief="solid",
|
|
||||||
)
|
|
||||||
self.qty_entry.pack(fill="x", ipady=4)
|
|
||||||
self.qty_entry.insert(0, "2")
|
|
||||||
|
|
||||||
f2 = tk.Frame(row_frame, bg="#0f172a")
|
|
||||||
f2.pack(side="left", fill="x", expand=True, padx=(5, 0))
|
|
||||||
tk.Label(
|
|
||||||
f2,
|
|
||||||
text="Cena za ks (Kč):",
|
|
||||||
font=("Segoe UI", 10, "bold"),
|
|
||||||
fg="#94a3b8",
|
|
||||||
bg="#0f172a",
|
|
||||||
anchor="w",
|
|
||||||
).pack(fill="x")
|
|
||||||
self.price_entry = tk.Entry(
|
|
||||||
f2,
|
|
||||||
font=("Segoe UI", 11),
|
|
||||||
bg="#1e293b",
|
|
||||||
fg="#ffffff",
|
|
||||||
insertbackground="white",
|
|
||||||
bd=1,
|
|
||||||
relief="solid",
|
|
||||||
)
|
|
||||||
self.price_entry.pack(fill="x", ipady=4)
|
|
||||||
self.price_entry.insert(0, "45")
|
|
||||||
|
|
||||||
self.create_label(form, "Částka dobírky v Kč (0 = zaplaceno předem):")
|
|
||||||
self.dobirka_entry = self.create_entry(form)
|
|
||||||
self.dobirka_entry.insert(0, "0")
|
|
||||||
|
|
||||||
btn = tk.Button(
|
|
||||||
form,
|
|
||||||
text="🚀 ODESLAT ZÁSILKU NA STÁNEK",
|
|
||||||
font=("Segoe UI", 11, "bold"),
|
|
||||||
bg="#10b981",
|
|
||||||
fg="#ffffff",
|
|
||||||
activebackground="#059669",
|
|
||||||
activeforeground="#ffffff",
|
|
||||||
bd=0,
|
|
||||||
cursor="hand2",
|
|
||||||
command=self.send_order,
|
|
||||||
)
|
|
||||||
btn.pack(fill="x", pady=(15, 8), ipady=10)
|
|
||||||
|
|
||||||
self.status_lbl = tk.Label(
|
|
||||||
form,
|
|
||||||
text="Přípraveno k odeslání",
|
|
||||||
font=("Segoe UI", 9),
|
|
||||||
fg="#94a3b8",
|
|
||||||
bg="#0f172a",
|
|
||||||
)
|
|
||||||
self.status_lbl.pack()
|
|
||||||
|
|
||||||
# ==========================================================================
|
|
||||||
# PRAVÝ PANEL - KATALOG ODESLANÝCH ZÁSILEK
|
|
||||||
# ==========================================================================
|
|
||||||
catalog_panel = tk.Frame(
|
|
||||||
main_container,
|
|
||||||
bg="#1e293b",
|
|
||||||
highlightbackground="#334155",
|
|
||||||
highlightthickness=1,
|
|
||||||
)
|
|
||||||
catalog_panel.pack(side="right", fill="both", expand=True)
|
|
||||||
|
|
||||||
tk.Label(
|
|
||||||
catalog_panel,
|
|
||||||
text="📋 ODESLANÉ ZÁSILKY & STAV POTVRZENÍ",
|
|
||||||
font=("Segoe UI", 11, "bold"),
|
|
||||||
fg="#38bdf8",
|
|
||||||
bg="#1e293b",
|
|
||||||
).pack(anchor="w", padx=15, pady=(15, 10))
|
|
||||||
|
|
||||||
self.catalog_scroll = tk.Frame(catalog_panel, bg="#1e293b")
|
|
||||||
self.catalog_scroll.pack(fill="both", expand=True, padx=10, pady=5)
|
|
||||||
|
|
||||||
self.empty_catalog_lbl = tk.Label(
|
|
||||||
self.catalog_scroll,
|
|
||||||
text="Zatím jste neodeslali žádnou zásilku.",
|
|
||||||
font=("Segoe UI", 11, "italic"),
|
|
||||||
fg="#64748b",
|
|
||||||
bg="#1e293b",
|
|
||||||
)
|
|
||||||
self.empty_catalog_lbl.pack(pady=50)
|
|
||||||
|
|
||||||
# Spuštění automatické kontroly stavů na pozadí
|
|
||||||
self.poll_order_statuses()
|
|
||||||
|
|
||||||
def create_label(self, parent, text):
|
|
||||||
lbl = tk.Label(
|
|
||||||
parent,
|
|
||||||
text=text,
|
|
||||||
font=("Segoe UI", 10, "bold"),
|
|
||||||
fg="#94a3b8",
|
|
||||||
bg="#0f172a",
|
|
||||||
anchor="w",
|
|
||||||
)
|
|
||||||
lbl.pack(fill="x", pady=(6, 2))
|
|
||||||
return lbl
|
|
||||||
|
|
||||||
def create_entry(self, parent):
|
|
||||||
entry = tk.Entry(
|
|
||||||
parent,
|
|
||||||
font=("Segoe UI", 10),
|
|
||||||
bg="#1e293b",
|
|
||||||
fg="#ffffff",
|
|
||||||
insertbackground="white",
|
|
||||||
bd=1,
|
|
||||||
relief="solid",
|
|
||||||
)
|
|
||||||
entry.pack(fill="x", ipady=4)
|
|
||||||
return entry
|
|
||||||
|
|
||||||
# ==========================================================================
|
|
||||||
# LOGIKA ODESÍLÁNÍ
|
|
||||||
# ==========================================================================
|
|
||||||
def send_order(self):
|
|
||||||
base_url = self.url_entry.get().strip().rstrip("/")
|
|
||||||
if not base_url.startswith("http"):
|
|
||||||
base_url = "https://" + base_url
|
|
||||||
|
|
||||||
target_url = f"{base_url}/api/order"
|
|
||||||
|
|
||||||
try:
|
|
||||||
customer = self.customer_entry.get().strip()
|
|
||||||
product = self.product_entry.get().strip()
|
|
||||||
quantity = int(self.qty_entry.get().strip())
|
|
||||||
price = float(self.price_entry.get().strip())
|
|
||||||
dobirka = float(self.dobirka_entry.get().strip())
|
|
||||||
time_str = datetime.now().strftime("%H:%M:%S")
|
|
||||||
|
|
||||||
payload = {
|
|
||||||
"customer": customer,
|
|
||||||
"product": product,
|
|
||||||
"quantity": quantity,
|
|
||||||
"price": price,
|
|
||||||
"dobirka": dobirka,
|
|
||||||
"time": time_str,
|
|
||||||
}
|
|
||||||
|
|
||||||
self.status_lbl.config(text="Odesílám...", fg="#eab308")
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
resp = requests.post(target_url, json=payload, timeout=8)
|
|
||||||
|
|
||||||
if resp.status_code == 200:
|
|
||||||
data = resp.json()
|
|
||||||
order_id = str(data.get("order_id", "???"))
|
|
||||||
|
|
||||||
self.status_lbl.config(
|
|
||||||
text="✅ Objednávka doručena na stánek!", fg="#4ade80"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Přidání položky do pravého katalogu
|
|
||||||
self.add_to_catalog(
|
|
||||||
order_id,
|
|
||||||
customer,
|
|
||||||
product,
|
|
||||||
quantity,
|
|
||||||
quantity * price,
|
|
||||||
dobirka,
|
|
||||||
time_str,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.status_lbl.config(
|
|
||||||
text=f"❌ Server vrátil chybu {resp.status_code}", fg="#f87171"
|
|
||||||
)
|
|
||||||
messagebox.showerror(
|
|
||||||
"Chyba serveru", f"Chybová odpověď:\n{resp.text[:200]}"
|
|
||||||
)
|
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
messagebox.showwarning(
|
|
||||||
"Chybná data", "Zkontrolujte zadaná čísla v polích Počet, Cena a Dobírka."
|
|
||||||
)
|
|
||||||
self.status_lbl.config(text="❌ Chyba v zadání údajů", fg="#f87171")
|
|
||||||
except Exception as e:
|
|
||||||
self.status_lbl.config(
|
|
||||||
text="❌ Nepodařilo se připojit k serveru", fg="#f87171"
|
|
||||||
)
|
|
||||||
messagebox.showerror(
|
|
||||||
"Chyba připojení",
|
|
||||||
"Ujistěte se, že běží server na stánku a Cloudflare"
|
|
||||||
f" tunel!\n\nDetail: {e}",
|
|
||||||
)
|
|
||||||
|
|
||||||
# ==========================================================================
|
|
||||||
# VKLÁDÁNÍ DO KATALOGU A KONTROLA STAVU
|
|
||||||
# ==========================================================================
|
|
||||||
def add_to_catalog(
|
|
||||||
self, order_id, customer, product, quantity, total_price, dobirka, time_str
|
|
||||||
):
|
|
||||||
if self.empty_catalog_lbl:
|
|
||||||
self.empty_catalog_lbl.destroy()
|
|
||||||
self.empty_catalog_lbl = None
|
|
||||||
|
|
||||||
row = tk.Frame(
|
|
||||||
self.catalog_scroll,
|
|
||||||
bg="#0f172a",
|
|
||||||
highlightbackground="#334155",
|
|
||||||
highlightthickness=1,
|
|
||||||
)
|
|
||||||
row.pack(fill="x", pady=4, ipady=5)
|
|
||||||
|
|
||||||
left_info = tk.Frame(row, bg="#0f172a")
|
|
||||||
left_info.pack(side="left", padx=10)
|
|
||||||
|
|
||||||
tk.Label(
|
|
||||||
left_info,
|
|
||||||
text=f"#{order_id}",
|
|
||||||
font=("Segoe UI", 11, "bold"),
|
|
||||||
fg="#00f2fe",
|
|
||||||
bg="#0f172a",
|
|
||||||
).pack(anchor="w")
|
|
||||||
tk.Label(
|
|
||||||
left_info,
|
|
||||||
text=time_str,
|
|
||||||
font=("Segoe UI", 9),
|
|
||||||
fg="#94a3b8",
|
|
||||||
bg="#0f172a",
|
|
||||||
).pack(anchor="w")
|
|
||||||
|
|
||||||
mid_info = tk.Frame(row, bg="#0f172a")
|
|
||||||
mid_info.pack(side="left", padx=10, fill="x", expand=True)
|
|
||||||
|
|
||||||
tk.Label(
|
|
||||||
mid_info,
|
|
||||||
text=f"{customer} ({quantity}x {product})",
|
|
||||||
font=("Segoe UI", 10, "bold"),
|
|
||||||
fg="#f8fafc",
|
|
||||||
bg="#0f172a",
|
|
||||||
anchor="w",
|
|
||||||
).pack(fill="x")
|
|
||||||
|
|
||||||
sub_text = f"{total_price:.0f} Kč"
|
|
||||||
if dobirka > 0:
|
|
||||||
sub_text += f" | Dobírka {dobirka:.0f} Kč"
|
|
||||||
tk.Label(
|
|
||||||
mid_info,
|
|
||||||
text=sub_text,
|
|
||||||
font=("Segoe UI", 9),
|
|
||||||
fg="#cbd5e1",
|
|
||||||
bg="#0f172a",
|
|
||||||
anchor="w",
|
|
||||||
).pack(fill="x")
|
|
||||||
|
|
||||||
# Odznak stavu (výchozí: ČEKÁ)
|
|
||||||
badge = tk.Label(
|
|
||||||
row,
|
|
||||||
text="⏳ ČEKÁ",
|
|
||||||
font=("Segoe UI", 9, "bold"),
|
|
||||||
fg="#ffffff",
|
|
||||||
bg="#ef4444",
|
|
||||||
padx=8,
|
|
||||||
pady=3,
|
|
||||||
)
|
|
||||||
badge.pack(side="right", padx=10)
|
|
||||||
|
|
||||||
self.sent_orders[str(order_id)] = {
|
|
||||||
"badge": badge,
|
|
||||||
"status": "čaká na potvrzení",
|
|
||||||
}
|
|
||||||
|
|
||||||
def poll_order_statuses(self):
|
|
||||||
"""Pravidelně na pozadí zjišťuje, zda stánkový server nepotvrdil zásilky."""
|
|
||||||
base_url = self.url_entry.get().strip().rstrip("/")
|
|
||||||
|
|
||||||
if base_url:
|
|
||||||
if not base_url.startswith("http"):
|
|
||||||
base_url = "https://" + base_url
|
|
||||||
|
|
||||||
# Vyfiltrování zásilek, které ještě nejsou potvrzené
|
|
||||||
unconfirmed = [
|
|
||||||
oid
|
|
||||||
for oid, item in self.sent_orders.items()
|
|
||||||
if item["status"] != "potvrzeno"
|
|
||||||
]
|
|
||||||
|
|
||||||
if unconfirmed:
|
|
||||||
|
|
||||||
def check_async():
|
|
||||||
for oid in unconfirmed:
|
|
||||||
try:
|
|
||||||
res = requests.get(f"{base_url}/api/order/{oid}/status", timeout=3)
|
|
||||||
if res.status_code == 200:
|
|
||||||
st = res.json().get("status")
|
|
||||||
if st == "potvrzeno":
|
|
||||||
|
|
||||||
def apply(target_oid=oid):
|
|
||||||
self.sent_orders[target_oid]["status"] = "potvrzeno"
|
|
||||||
badge = self.sent_orders[target_oid]["badge"]
|
|
||||||
badge.config(
|
|
||||||
text="✅ POTVRZENO", bg="#10b981", fg="#ffffff"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.after(0, apply)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
threading.Thread(target=check_async, daemon=True).start()
|
|
||||||
|
|
||||||
# Kontrola každé 2 sekundy
|
|
||||||
self.after(2000, self.poll_order_statuses)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app = OrderSenderApp()
|
|
||||||
app.mainloop()
|
|
||||||
44
server.js
Normal file
44
server.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const cors = require('cors');
|
||||||
|
const app = express();
|
||||||
|
const PORT = 8080;
|
||||||
|
|
||||||
|
app.use(cors());
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
// Úložiště pro aktuální stav přehrávání
|
||||||
|
let currentSongData = {
|
||||||
|
artist: "Čekám na Spotify...",
|
||||||
|
title: "Spusťte hudbu",
|
||||||
|
coverImg: null,
|
||||||
|
progressTime: "0:00/0:00",
|
||||||
|
isAd: false
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. Endpoint pro příjem dat z Chrome / Tampermonkey (POST)
|
||||||
|
app.post('/endpoint', (req, res) => {
|
||||||
|
if (req.body) {
|
||||||
|
// Přepíšeme celá přijatá data
|
||||||
|
currentSongData = req.body;
|
||||||
|
|
||||||
|
// Sjednocení klíče pro reklamu (kdyby rozšíření poslalo 'ad' i 'isAd')
|
||||||
|
if (req.body.ad !== undefined && req.body.isAd === undefined) {
|
||||||
|
currentSongData.isAd = (req.body.ad === true || req.body.ad === "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("--- New Event Received ---");
|
||||||
|
console.log(`Interpret: ${currentSongData.artist}`);
|
||||||
|
console.log(`Skladba: ${currentSongData.title}`);
|
||||||
|
console.log(`Čas: ${currentSongData.progressTime} | Reklama: ${currentSongData.isAd}`);
|
||||||
|
}
|
||||||
|
res.sendStatus(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Endpoint pro Python widget (GET)
|
||||||
|
app.get('/endpoint', (req, res) => {
|
||||||
|
res.json(currentSongData);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(PORT, '0.0.0.0', () => {
|
||||||
|
console.log(`Server běží a poslouchá na portu ${PORT}...`);
|
||||||
|
});
|
||||||
BIN
spotify_widget.png
Normal file
BIN
spotify_widget.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
978
spotify_widget.py
Normal file
978
spotify_widget.py
Normal file
@@ -0,0 +1,978 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import math
|
||||||
|
import random
|
||||||
|
import datetime
|
||||||
|
import threading
|
||||||
|
import subprocess
|
||||||
|
import ctypes
|
||||||
|
import warnings
|
||||||
|
import requests
|
||||||
|
from io import BytesIO
|
||||||
|
import tkinter as tk
|
||||||
|
from PIL import Image, ImageTk, ImageDraw, ImageChops
|
||||||
|
import pythoncom
|
||||||
|
|
||||||
|
warnings.filterwarnings("ignore", category=UserWarning, module="pycaw")
|
||||||
|
|
||||||
|
# Zapnutí DPI awareness ve Windows, aby tkinter neškáloval rozhraní do rohu
|
||||||
|
if sys.platform == "win32":
|
||||||
|
try:
|
||||||
|
ctypes.windll.shcore.SetProcessDpiAwareness(1)
|
||||||
|
except Exception:
|
||||||
|
try:
|
||||||
|
ctypes.windll.user32.SetProcessDPIAware()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Pokus o automatickou instalaci pycaw, pokud chybí
|
||||||
|
try:
|
||||||
|
from pycaw.pycaw import AudioUtilities
|
||||||
|
HAS_PYCAW = True
|
||||||
|
except ImportError:
|
||||||
|
print("📦 Instaluji potřebnou knihovnu 'pycaw' pro okamžité ztlumení Windows...")
|
||||||
|
try:
|
||||||
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "pycaw", "comtypes"],
|
||||||
|
creationflags=getattr(subprocess, 'CREATE_NO_WINDOW', 0))
|
||||||
|
from pycaw.pycaw import AudioUtilities
|
||||||
|
HAS_PYCAW = True
|
||||||
|
print("✅ Knihovna pycaw byla úspěšně nainstalována!")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Automatická instalace pycaw se nezdařila: {e}")
|
||||||
|
HAS_PYCAW = False
|
||||||
|
|
||||||
|
# Pokus o import winsound (standardně na Windows)
|
||||||
|
try:
|
||||||
|
import winsound
|
||||||
|
HAS_WINSOUND = True
|
||||||
|
except ImportError:
|
||||||
|
HAS_WINSOUND = False
|
||||||
|
|
||||||
|
# Pokus o import pygame
|
||||||
|
try:
|
||||||
|
import pygame
|
||||||
|
pygame.mixer.init()
|
||||||
|
HAS_PYGAME = True
|
||||||
|
except Exception:
|
||||||
|
HAS_PYGAME = False
|
||||||
|
|
||||||
|
SERVER_URL = "http://localhost:8080/endpoint"
|
||||||
|
CYCLE_INTERVAL_MS = 10000 # Doba zobrazení produktu (10 sekund)
|
||||||
|
FRAME_INTERVAL_MS = 120 # Rychlost 3D rotace fotek (120 ms)
|
||||||
|
PARTICLE_COUNT = 60 # Počet bokeh částic
|
||||||
|
POPUP_INTERVAL_MS = 30000 # Interval zobrazení fotka.png (5 minut = 300 000 ms)
|
||||||
|
POPUP_DURATION_MS = 3000 # Doba zobrazení fotka.png (3 sekundy = 3 000 ms)
|
||||||
|
|
||||||
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
POPUP_IMAGE_PATH = os.path.join(SCRIPT_DIR, "fotka.png")
|
||||||
|
|
||||||
|
KATALOG_DIR = os.path.join(SCRIPT_DIR, "katalog")
|
||||||
|
if not os.path.exists(KATALOG_DIR):
|
||||||
|
KATALOG_DIR = os.path.join(SCRIPT_DIR, "documents", "katalog")
|
||||||
|
|
||||||
|
# Složka se zvuky pro reklamy
|
||||||
|
SOUNDS_DIR = os.path.join(SCRIPT_DIR, "zvuky_reklama")
|
||||||
|
if not os.path.exists(SOUNDS_DIR):
|
||||||
|
os.makedirs(SOUNDS_DIR, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
def natural_sort_key(s):
|
||||||
|
""" Řazení souborů podle čísel (image1, image2, ..., image10) """
|
||||||
|
return [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', s)]
|
||||||
|
|
||||||
|
|
||||||
|
def set_spotify_mute(mute=True):
|
||||||
|
""" Bleskově ztlumí VŠECHNY aplikace ve Windows kromě samotného Pythonu """
|
||||||
|
pythoncom.CoInitialize()
|
||||||
|
if HAS_PYCAW:
|
||||||
|
try:
|
||||||
|
sessions = AudioUtilities.GetAllSessions()
|
||||||
|
for session in sessions:
|
||||||
|
try:
|
||||||
|
pname = session.Process.name().lower() if session.Process else ""
|
||||||
|
if not any(keep in pname for keep in ["python", "wmplayer"]):
|
||||||
|
volume = session.SimpleAudioVolume
|
||||||
|
volume.SetMute(1 if mute else 0, None)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Pycaw chyba: {e}")
|
||||||
|
|
||||||
|
nircmd_path = os.path.join(SCRIPT_DIR, "nircmd.exe")
|
||||||
|
if os.path.exists(nircmd_path):
|
||||||
|
try:
|
||||||
|
val = "1" if mute else "0"
|
||||||
|
for proc in ["spotify.exe", "chrome.exe", "msedge.exe", "brave.exe", "firefox.exe", "opera.exe"]:
|
||||||
|
subprocess.run(
|
||||||
|
[nircmd_path, "muteappvolume", proc, val],
|
||||||
|
creationflags=getattr(subprocess, 'CREATE_NO_WINDOW', 0)
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"NirCmd chyba: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
class AdvancedParticle:
|
||||||
|
""" Třída pro vícevrstvé animované bokeh částice """
|
||||||
|
def __init__(self, w=1920, h=1080):
|
||||||
|
self.w = w
|
||||||
|
self.h = h
|
||||||
|
self.reset(random_y=True)
|
||||||
|
|
||||||
|
def reset(self, random_y=False):
|
||||||
|
self.x = random.uniform(0, self.w)
|
||||||
|
self.y = random.uniform(0, self.h) if random_y else self.h + random.uniform(20, 80)
|
||||||
|
|
||||||
|
self.p_type = random.choice(['bokeh_large', 'bokeh_medium', 'spark'])
|
||||||
|
|
||||||
|
if self.p_type == 'bokeh_large':
|
||||||
|
self.base_radius = random.uniform(40, 90)
|
||||||
|
self.speed_y = random.uniform(0.2, 0.6)
|
||||||
|
self.sway_amp = random.uniform(1.0, 3.0)
|
||||||
|
self.sway_freq = random.uniform(0.005, 0.015)
|
||||||
|
self.color_outer = random.choice(["#2a0845", "#3c096c", "#1e0034", "#480ca8", "#38040e"])
|
||||||
|
self.color_inner = random.choice(["#5a189a", "#7b2cbf", "#9d4edd", "#7209b7", "#9e2a2b"])
|
||||||
|
elif self.p_type == 'bokeh_medium':
|
||||||
|
self.base_radius = random.uniform(18, 38)
|
||||||
|
self.speed_y = random.uniform(0.5, 1.2)
|
||||||
|
self.sway_amp = random.uniform(1.5, 4.0)
|
||||||
|
self.sway_freq = random.uniform(0.01, 0.025)
|
||||||
|
self.color_outer = random.choice(["#5a189a", "#7209b7", "#b5179e", "#480ca8"])
|
||||||
|
self.color_inner = random.choice(["#e0aaff", "#f72585", "#c77dff", "#ffb703"])
|
||||||
|
else: # spark
|
||||||
|
self.base_radius = random.uniform(2, 5)
|
||||||
|
self.speed_y = random.uniform(0.8, 2.2)
|
||||||
|
self.sway_amp = random.uniform(0.5, 2.0)
|
||||||
|
self.sway_freq = random.uniform(0.02, 0.05)
|
||||||
|
self.color_outer = "#ffffff"
|
||||||
|
self.color_inner = random.choice(["#ffffff", "#ffee83", "#4cc9f0", "#ffb703"])
|
||||||
|
|
||||||
|
self.radius = self.base_radius
|
||||||
|
self.pulse_phase = random.uniform(0, 2 * math.pi)
|
||||||
|
self.pulse_speed = random.uniform(0.015, 0.04)
|
||||||
|
self.phase = random.uniform(0, 2 * math.pi)
|
||||||
|
|
||||||
|
def update(self, w, h):
|
||||||
|
self.w = w
|
||||||
|
self.h = h
|
||||||
|
self.y -= self.speed_y
|
||||||
|
self.phase += self.sway_freq
|
||||||
|
self.x += math.sin(self.phase) * self.sway_amp
|
||||||
|
|
||||||
|
self.pulse_phase += self.pulse_speed
|
||||||
|
pulse_factor = 1.0 + 0.22 * math.sin(self.pulse_phase)
|
||||||
|
self.radius = self.base_radius * pulse_factor
|
||||||
|
|
||||||
|
if self.y < -self.radius * 2 or self.x < -self.radius or self.x > self.w + self.radius:
|
||||||
|
self.reset(random_y=False)
|
||||||
|
|
||||||
|
|
||||||
|
class FullscreenJarmarkDisplay:
|
||||||
|
def __init__(self, root):
|
||||||
|
self.root = root
|
||||||
|
self.root.title("Jarmark Display Kiosk")
|
||||||
|
self.root.attributes("-fullscreen", True)
|
||||||
|
self.root.update_idletasks()
|
||||||
|
|
||||||
|
self.w = max(1, self.root.winfo_width() or self.root.winfo_screenwidth() or 1920)
|
||||||
|
self.h = max(1, self.root.winfo_height() or self.root.winfo_screenheight() or 1080)
|
||||||
|
|
||||||
|
# Klávesové zkratky
|
||||||
|
self.root.bind("<Escape>", lambda e: self.check_escape())
|
||||||
|
self.root.bind("<Right>", lambda e: self.next_product())
|
||||||
|
self.root.bind("<Left>", lambda e: self.prev_product())
|
||||||
|
self.root.bind("<space>", lambda e: self.toggle_pause())
|
||||||
|
self.root.bind("<r>", lambda e: self.reload_catalog_action())
|
||||||
|
self.root.bind("<R>", lambda e: self.reload_catalog_action())
|
||||||
|
self.root.bind("<F2>", lambda e: self.toggle_msg_input())
|
||||||
|
self.root.bind("<Unmap>", self.on_minimize)
|
||||||
|
|
||||||
|
# Plátno s čistým tmavým pozadím
|
||||||
|
self.canvas = tk.Canvas(root, bg="#07010f", highlightthickness=0)
|
||||||
|
self.canvas.pack(fill=tk.BOTH, expand=True)
|
||||||
|
|
||||||
|
self.canvas.bind("<Configure>", self.on_resize)
|
||||||
|
|
||||||
|
# Částice
|
||||||
|
self.particles = [AdvancedParticle(self.w, self.h) for _ in range(PARTICLE_COUNT)]
|
||||||
|
self.particle_draw_ids = []
|
||||||
|
self.init_particles_canvas()
|
||||||
|
|
||||||
|
# Canvas Prvky - Název produktu se stínem
|
||||||
|
self.title_shadow_id = self.canvas.create_text(0, 0, text="", fill="#000000", font=("Impact", 42, "bold"), anchor="center")
|
||||||
|
self.title_text_id = self.canvas.create_text(0, 0, text="", fill="#ffffff", font=("Impact", 42, "bold"), anchor="center")
|
||||||
|
|
||||||
|
self.badge_bg_id = self.canvas.create_rectangle(0, 0, 0, 0, fill="", outline="", state="hidden")
|
||||||
|
self.badge_text_id = self.canvas.create_text(0, 0, text="", fill="white", font=("Segoe UI", 13, "bold"), state="hidden")
|
||||||
|
|
||||||
|
# Produkt fotka
|
||||||
|
self.prod_image_id = self.canvas.create_image(0, 0, anchor="center")
|
||||||
|
|
||||||
|
# Cenovka vpravo
|
||||||
|
self.price_bg_id = self.canvas.create_rectangle(0, 0, 0, 0, fill="#120521", outline="#9d4edd", width=2)
|
||||||
|
self.price_shadow_id = self.canvas.create_text(0, 0, text="", fill="#000000", font=("Segoe UI", 38, "bold"), anchor="center")
|
||||||
|
self.price_text_id = self.canvas.create_text(0, 0, text="", fill="#ffb703", font=("Segoe UI", 38, "bold"), anchor="center")
|
||||||
|
|
||||||
|
# Hodiny & Datum
|
||||||
|
self.clock_time_id = self.canvas.create_text(0, 0, text="", fill="#ffffff", font=("Segoe UI", 26, "bold"), anchor="e")
|
||||||
|
self.clock_date_id = self.canvas.create_text(0, 0, text="", fill="#9d4edd", font=("Segoe UI", 13, "bold"), anchor="e")
|
||||||
|
|
||||||
|
# Indikátor pauzy
|
||||||
|
self.pause_indicator_id = self.canvas.create_text(0, 0, text="", fill="#ff0055", font=("Segoe UI", 13, "bold"), anchor="w")
|
||||||
|
|
||||||
|
# Spotify Karta (vlevo dole)
|
||||||
|
self.card_x1, self.card_y1 = 0, 0
|
||||||
|
self.card_w, self.card_h = 360, 150
|
||||||
|
self.card_bg_photo = None
|
||||||
|
self.card_bg_id = self.canvas.create_image(0, 0, anchor="nw")
|
||||||
|
|
||||||
|
self.cover_img_id = self.canvas.create_image(0, 0, anchor="center")
|
||||||
|
self.spotify_title_id = self.canvas.create_text(0, 0, text="Načítám...", fill="white", font=("Segoe UI", 13, "bold"), anchor="w")
|
||||||
|
self.spotify_subtitle_id = self.canvas.create_text(0, 0, text="Čekám na Spotify", fill="#c77dff", font=("Segoe UI", 10), anchor="w")
|
||||||
|
|
||||||
|
self.time_curr_id = self.canvas.create_text(0, 0, text="0:00", fill="#aaaaaa", font=("Segoe UI", 9), anchor="w")
|
||||||
|
self.time_total_id = self.canvas.create_text(0, 0, text="0:00", fill="#aaaaaa", font=("Segoe UI", 9), anchor="e")
|
||||||
|
|
||||||
|
self.pbar_bg = self.canvas.create_line(0, 0, 0, 0, fill="#3c096c", width=5, capstyle=tk.ROUND)
|
||||||
|
self.pbar_fg = self.canvas.create_line(0, 0, 0, 0, fill="#f72585", width=5, capstyle=tk.ROUND)
|
||||||
|
|
||||||
|
# Vizuální banner pro zobrazení čistého textu zprávy – odlišný font (Segoe UI bold) bez rámečku
|
||||||
|
self.msg_banner_text = self.canvas.create_text(0, 0, text="", fill="#ffffff", font=("Segoe UI", 36, "bold"), anchor="center", state="hidden")
|
||||||
|
self.banner_hide_job = None
|
||||||
|
|
||||||
|
# Překrytí na hlavním canvasu pro fotka.png (každých 5 minut na 3 sekundy, jen když není okno minimalizované)
|
||||||
|
self.popup_bg_id = self.canvas.create_rectangle(0, 0, self.w, self.h, fill="#07010f", outline="", state="hidden")
|
||||||
|
self.popup_img_id = self.canvas.create_image(self.w // 2, self.h // 2, anchor="center", state="hidden")
|
||||||
|
self.canvas.tag_bind(self.popup_bg_id, "<Button-1>", lambda e: self.hide_fullscreen_popup())
|
||||||
|
self.canvas.tag_bind(self.popup_img_id, "<Button-1>", lambda e: self.hide_fullscreen_popup())
|
||||||
|
self.popup_photo = None
|
||||||
|
self.is_popup_visible = False
|
||||||
|
self.popup_hide_job = None
|
||||||
|
|
||||||
|
# === SKRYTÉ VSTUPNÍ POLE PRO ZPRÁVY (Aktivuje se klávesou F2) ===
|
||||||
|
self.msg_frame = tk.Frame(root, bg="#120521", highlightbackground="#9d4edd", highlightthickness=2)
|
||||||
|
self.msg_entry = tk.Entry(self.msg_frame, font=("Segoe UI", 16), bg="#120521", fg="#ffffff", insertbackground="white", relief=tk.FLAT)
|
||||||
|
self.msg_entry.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=10, pady=5)
|
||||||
|
self.msg_entry.bind("<Return>", self.handle_user_message)
|
||||||
|
self.msg_entry.bind("<Escape>", lambda e: self.hide_msg_input())
|
||||||
|
|
||||||
|
# Nápověda v poli
|
||||||
|
self.msg_entry.insert(0, "Napište zprávu a stiskněte Enter...")
|
||||||
|
self.msg_entry.bind("<FocusIn>", self.clear_placeholder)
|
||||||
|
self.is_msg_visible = False
|
||||||
|
|
||||||
|
# DŮLEŽITÉ: Okamžité skrytí prvku při inicializaci, aby nepřetékal na plochu
|
||||||
|
self.msg_frame.place_forget()
|
||||||
|
|
||||||
|
# Stavové proměnné
|
||||||
|
self.running = True
|
||||||
|
self.is_paused = False
|
||||||
|
self.is_ad_active = False
|
||||||
|
self.ad_sound_process = None
|
||||||
|
self.current_img_url = None
|
||||||
|
self.photo_cover = None
|
||||||
|
self.raw_cover_img = None
|
||||||
|
self.current_card_rgba = (25, 10, 40, 230)
|
||||||
|
self.current_prod_photo = None
|
||||||
|
|
||||||
|
self.catalog_items = []
|
||||||
|
self.active_item = None
|
||||||
|
self.current_catalog_index = 0
|
||||||
|
self.current_frame_index = 0
|
||||||
|
|
||||||
|
# Pro plynulý fade efekt
|
||||||
|
self.fade_anim_job = None
|
||||||
|
|
||||||
|
# Spuštění procesů
|
||||||
|
self.load_catalog()
|
||||||
|
self.reposition_all()
|
||||||
|
self.cycle_product()
|
||||||
|
self.animate_product_3d()
|
||||||
|
self.animate_particles()
|
||||||
|
self.update_clock()
|
||||||
|
self.schedule_popup_image()
|
||||||
|
|
||||||
|
threading.Thread(target=self.poll_data, daemon=True).start()
|
||||||
|
|
||||||
|
def on_minimize(self, event):
|
||||||
|
""" Při minimalizaci hlavního okna skryje popup, aby nepřekrýval jiná okna """
|
||||||
|
if event.widget is self.root and self.is_popup_visible:
|
||||||
|
self.hide_fullscreen_popup()
|
||||||
|
|
||||||
|
def is_window_minimized(self):
|
||||||
|
try:
|
||||||
|
return self.root.state() == "iconic" or not self.root.winfo_viewable()
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def schedule_popup_image(self):
|
||||||
|
""" Naplánuje zobrazení fotka.png každých 5 minut """
|
||||||
|
self.root.after(POPUP_INTERVAL_MS, self.trigger_popup_image)
|
||||||
|
|
||||||
|
def trigger_popup_image(self):
|
||||||
|
""" Zobrazí fotka.png na celou obrazovku na 3 sekundy (pokud není okno minimalizované) """
|
||||||
|
if not self.is_window_minimized():
|
||||||
|
self.show_fullscreen_popup()
|
||||||
|
self.schedule_popup_image()
|
||||||
|
|
||||||
|
def _build_popup_photo(self, target_w, target_h):
|
||||||
|
""" Načte a přizpůsobí fotka.png na zadané rozměry """
|
||||||
|
if not os.path.exists(POPUP_IMAGE_PATH):
|
||||||
|
print(f"⚠️ Obrázek '{POPUP_IMAGE_PATH}' nebyl nalezen.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
raw_img = Image.open(POPUP_IMAGE_PATH).convert("RGB")
|
||||||
|
img_w, img_h = raw_img.size
|
||||||
|
if img_w <= 0 or img_h <= 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
scale = min(target_w / img_w, target_h / img_h)
|
||||||
|
new_w = max(1, int(img_w * scale))
|
||||||
|
new_h = max(1, int(img_h * scale))
|
||||||
|
|
||||||
|
resized = raw_img.resize((new_w, new_h), Image.Resampling.LANCZOS)
|
||||||
|
return ImageTk.PhotoImage(resized)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Chyba při načítání {POPUP_IMAGE_PATH}: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def show_fullscreen_popup(self):
|
||||||
|
""" Zobrazí fotka.png přes celou obrazovku na POPUP_DURATION_MS (3 s) na hlavním canvasu """
|
||||||
|
if self.is_window_minimized():
|
||||||
|
return
|
||||||
|
|
||||||
|
self.hide_fullscreen_popup()
|
||||||
|
|
||||||
|
w = max(1, self.canvas.winfo_width() or self.w)
|
||||||
|
h = max(1, self.canvas.winfo_height() or self.h)
|
||||||
|
photo = self._build_popup_photo(w, h)
|
||||||
|
if not photo:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.is_popup_visible = True
|
||||||
|
self.popup_photo = photo
|
||||||
|
|
||||||
|
self.canvas.coords(self.popup_bg_id, 0, 0, w, h)
|
||||||
|
self.canvas.coords(self.popup_img_id, w // 2, h // 2)
|
||||||
|
self.canvas.itemconfig(self.popup_img_id, image=self.popup_photo)
|
||||||
|
|
||||||
|
self.canvas.itemconfig(self.popup_bg_id, state="normal")
|
||||||
|
self.canvas.itemconfig(self.popup_img_id, state="normal")
|
||||||
|
self.canvas.tag_raise(self.popup_bg_id)
|
||||||
|
self.canvas.tag_raise(self.popup_img_id)
|
||||||
|
|
||||||
|
self.popup_hide_job = self.root.after(POPUP_DURATION_MS, self.hide_fullscreen_popup)
|
||||||
|
|
||||||
|
def hide_fullscreen_popup(self):
|
||||||
|
""" Skryje obrázek fotka.png z hlavního canvasu """
|
||||||
|
if self.popup_hide_job:
|
||||||
|
try:
|
||||||
|
self.root.after_cancel(self.popup_hide_job)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
self.popup_hide_job = None
|
||||||
|
|
||||||
|
self.is_popup_visible = False
|
||||||
|
self.canvas.itemconfig(self.popup_img_id, state="hidden")
|
||||||
|
self.canvas.itemconfig(self.popup_bg_id, state="hidden")
|
||||||
|
self.popup_photo = None
|
||||||
|
|
||||||
|
def toggle_msg_input(self):
|
||||||
|
""" Zobrazí nebo schová skryté zprávové pole po stisknutí F2 """
|
||||||
|
if self.is_msg_visible:
|
||||||
|
self.hide_msg_input()
|
||||||
|
else:
|
||||||
|
self.show_msg_input()
|
||||||
|
|
||||||
|
def show_msg_input(self):
|
||||||
|
self.is_msg_visible = True
|
||||||
|
box_w, box_h = 500, 50
|
||||||
|
bx = (self.w - box_w) // 2
|
||||||
|
by = self.h - 120
|
||||||
|
self.msg_frame.place(x=bx, y=by, width=box_w, height=box_h)
|
||||||
|
|
||||||
|
current_text = self.msg_entry.get()
|
||||||
|
if not current_text or current_text == "✓ Zpráva uložena!":
|
||||||
|
self.msg_entry.delete(0, tk.END)
|
||||||
|
self.msg_entry.insert(0, "Napište zprávu a stiskněte Enter...")
|
||||||
|
|
||||||
|
self.msg_entry.focus_set()
|
||||||
|
self.msg_entry.selection_range(0, tk.END)
|
||||||
|
|
||||||
|
def hide_msg_input(self):
|
||||||
|
self.is_msg_visible = False
|
||||||
|
self.msg_frame.place_forget()
|
||||||
|
self.canvas.focus_set()
|
||||||
|
|
||||||
|
def clear_placeholder(self, event):
|
||||||
|
current_text = self.msg_entry.get()
|
||||||
|
if current_text in ["Napište zprávu a stiskněte Enter...", "✓ Zpráva uložena!"]:
|
||||||
|
self.msg_entry.delete(0, tk.END)
|
||||||
|
|
||||||
|
def handle_user_message(self, event):
|
||||||
|
msg = self.msg_entry.get().strip()
|
||||||
|
# Pokud je zpráva prázdná, odstraníme starou zprávu z obrazovky
|
||||||
|
if not msg or msg == "Napište zprávu a stiskněte Enter..." or msg == "✓ Zpráva uložena!":
|
||||||
|
self.hide_onscreen_notification()
|
||||||
|
self.hide_msg_input()
|
||||||
|
else:
|
||||||
|
print(f"💬 [UŽIVATELSKÁ ZPRÁVA]: {msg}")
|
||||||
|
with open(os.path.join(SCRIPT_DIR, "user_messages.txt"), "a", encoding="utf-8") as f:
|
||||||
|
f.write(f"[{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {msg}\n")
|
||||||
|
|
||||||
|
# Zobrazení čistého textu s odlišným fontem přímo na obrazovce
|
||||||
|
self.show_onscreen_notification(msg)
|
||||||
|
|
||||||
|
self.msg_entry.delete(0, tk.END)
|
||||||
|
self.msg_entry.insert(0, "✓ Zpráva uložena!")
|
||||||
|
self.root.after(1000, self.hide_msg_input)
|
||||||
|
|
||||||
|
def show_onscreen_notification(self, message):
|
||||||
|
""" Zobrazí čistý velký text zprávy s jiným fontem (Segoe UI) zcela bez rámečku """
|
||||||
|
if self.banner_hide_job:
|
||||||
|
self.root.after_cancel(self.banner_hide_job)
|
||||||
|
self.banner_hide_job = None
|
||||||
|
|
||||||
|
display_text = message
|
||||||
|
self.canvas.itemconfig(self.msg_banner_text, text=display_text)
|
||||||
|
|
||||||
|
# Změna fontu na Segoe UI (odlišné od produktu)
|
||||||
|
font_msg_sz = max(28, int(self.h * 0.050))
|
||||||
|
self.canvas.itemconfig(self.msg_banner_text, font=("Segoe UI", font_msg_sz, "bold"), fill="#ffffff")
|
||||||
|
|
||||||
|
bx = self.w // 2
|
||||||
|
by = self.h - 180
|
||||||
|
|
||||||
|
self.canvas.coords(self.msg_banner_text, bx, by)
|
||||||
|
self.canvas.itemconfig(self.msg_banner_text, state="normal")
|
||||||
|
self.canvas.tag_raise(self.msg_banner_text)
|
||||||
|
|
||||||
|
def hide_onscreen_notification(self):
|
||||||
|
self.canvas.itemconfig(self.msg_banner_text, state="hidden")
|
||||||
|
|
||||||
|
def check_escape(self):
|
||||||
|
if self.is_popup_visible:
|
||||||
|
self.hide_fullscreen_popup()
|
||||||
|
elif self.is_msg_visible:
|
||||||
|
self.hide_msg_input()
|
||||||
|
else:
|
||||||
|
self.running = False
|
||||||
|
self.hide_fullscreen_popup()
|
||||||
|
self.root.destroy()
|
||||||
|
|
||||||
|
def trigger_ad_sound(self):
|
||||||
|
print("🔇 Ztlumuji vše kromě Pythonu...")
|
||||||
|
set_spotify_mute(True)
|
||||||
|
|
||||||
|
if not os.path.exists(SOUNDS_DIR):
|
||||||
|
return
|
||||||
|
|
||||||
|
valid_exts = ('.wav', '.mp3', '.wma', '.ogg')
|
||||||
|
sounds = [os.path.join(SOUNDS_DIR, f) for f in os.listdir(SOUNDS_DIR) if f.lower().endswith(valid_exts)]
|
||||||
|
|
||||||
|
if not sounds:
|
||||||
|
return
|
||||||
|
|
||||||
|
chosen_sound = random.choice(sounds)
|
||||||
|
|
||||||
|
def _play():
|
||||||
|
try:
|
||||||
|
if HAS_PYGAME:
|
||||||
|
pygame.mixer.music.load(chosen_sound)
|
||||||
|
pygame.mixer.music.play()
|
||||||
|
elif chosen_sound.lower().endswith('.wav') and HAS_WINSOUND:
|
||||||
|
winsound.PlaySound(chosen_sound, winsound.SND_FILENAME | winsound.SND_ASYNC)
|
||||||
|
else:
|
||||||
|
ps_script = f"$m = New-Object -ComObject WMPlayer.OCX; $m.URL = '{chosen_sound}'; $m.controls.play(); Start-Sleep -s 60"
|
||||||
|
self.ad_sound_process = subprocess.Popen(
|
||||||
|
["powershell", "-Command", ps_script],
|
||||||
|
creationflags=getattr(subprocess, 'CREATE_NO_WINDOW', 0)
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Chyba při přehrávání zvuku: {e}")
|
||||||
|
|
||||||
|
threading.Thread(target=_play, daemon=True).start()
|
||||||
|
|
||||||
|
def stop_ad_sound(self):
|
||||||
|
print("🔊 REKLAMA SKONČILA: Vracím hlasitost zpět.")
|
||||||
|
try:
|
||||||
|
if HAS_PYGAME and pygame.mixer.music.get_busy():
|
||||||
|
pygame.mixer.music.stop()
|
||||||
|
if HAS_WINSOUND:
|
||||||
|
winsound.PlaySound(None, winsound.SND_PURGE)
|
||||||
|
if self.ad_sound_process:
|
||||||
|
self.ad_sound_process.kill()
|
||||||
|
self.ad_sound_process = None
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Chyba při zastavování: {e}")
|
||||||
|
|
||||||
|
set_spotify_mute(False)
|
||||||
|
|
||||||
|
def on_resize(self, event):
|
||||||
|
if event.width <= 10 or event.height <= 10:
|
||||||
|
return
|
||||||
|
if self.w == event.width and self.h == event.height:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.w = event.width
|
||||||
|
self.h = event.height
|
||||||
|
self.reposition_all()
|
||||||
|
|
||||||
|
def reposition_all(self):
|
||||||
|
w, h = self.w, self.h
|
||||||
|
|
||||||
|
# 1. Název produktu + stín
|
||||||
|
font_title_sz = max(24, int(h * 0.055))
|
||||||
|
self.canvas.itemconfig(self.title_text_id, font=("Impact", font_title_sz, "bold"))
|
||||||
|
self.canvas.itemconfig(self.title_shadow_id, font=("Impact", font_title_sz, "bold"))
|
||||||
|
self.canvas.coords(self.title_text_id, w * 0.5, h * 0.09)
|
||||||
|
self.canvas.coords(self.title_shadow_id, w * 0.5 + 2, h * 0.09 + 2)
|
||||||
|
|
||||||
|
# 2. Produkt
|
||||||
|
self.canvas.coords(self.prod_image_id, w * 0.5, h * 0.48)
|
||||||
|
self.update_product_frame(smooth_fade=False)
|
||||||
|
|
||||||
|
# 3. Cenovka vpravo
|
||||||
|
font_price_sz = max(22, int(h * 0.050))
|
||||||
|
price_w, price_h = int(w * 0.20), int(h * 0.10)
|
||||||
|
px1, py1 = int(w * 0.74), int(h * 0.46)
|
||||||
|
px2, py2 = px1 + price_w, py1 + price_h
|
||||||
|
|
||||||
|
self.canvas.coords(self.price_bg_id, px1, py1, px2, py2)
|
||||||
|
self.canvas.coords(self.price_shadow_id, px1 + price_w / 2 + 2, py1 + price_h / 2 + 2)
|
||||||
|
self.canvas.coords(self.price_text_id, px1 + price_w / 2, py1 + price_h / 2)
|
||||||
|
|
||||||
|
self.canvas.itemconfig(self.price_shadow_id, font=("Segoe UI", font_price_sz, "bold"))
|
||||||
|
self.canvas.itemconfig(self.price_text_id, font=("Segoe UI", font_price_sz, "bold"))
|
||||||
|
|
||||||
|
# 4. Hodiny & Datum
|
||||||
|
font_time_sz = max(18, int(h * 0.032))
|
||||||
|
font_date_sz = max(11, int(h * 0.016))
|
||||||
|
self.canvas.itemconfig(self.clock_time_id, font=("Segoe UI", font_time_sz, "bold"))
|
||||||
|
self.canvas.itemconfig(self.clock_date_id, font=("Segoe UI", font_date_sz, "bold"))
|
||||||
|
self.canvas.coords(self.clock_time_id, w * 0.97, h * 0.04)
|
||||||
|
self.canvas.coords(self.clock_date_id, w * 0.97, h * 0.08)
|
||||||
|
|
||||||
|
# 5. Indikátor pauzy
|
||||||
|
self.canvas.coords(self.pause_indicator_id, w * 0.03, h * 0.04)
|
||||||
|
|
||||||
|
# 6. Spotify Karta vlevo dole
|
||||||
|
self.card_w = max(320, int(w * 0.23))
|
||||||
|
self.card_h = max(135, int(h * 0.16))
|
||||||
|
self.card_x1 = int(w * 0.03)
|
||||||
|
self.card_y1 = int(h - self.card_h - (h * 0.03))
|
||||||
|
|
||||||
|
self.canvas.coords(self.card_bg_id, self.card_x1, self.card_y1)
|
||||||
|
self.update_card_background(self.current_card_rgba)
|
||||||
|
|
||||||
|
cover_size = int(self.card_h * 0.58)
|
||||||
|
cover_cx = self.card_x1 + int(self.card_h * 0.42)
|
||||||
|
cover_cy = self.card_y1 + int(self.card_h * 0.50)
|
||||||
|
self.canvas.coords(self.cover_img_id, cover_cx, cover_cy)
|
||||||
|
|
||||||
|
if self.raw_cover_img:
|
||||||
|
resized_cover = self.raw_cover_img.resize((cover_size, cover_size), Image.Resampling.LANCZOS)
|
||||||
|
self.photo_cover = ImageTk.PhotoImage(resized_cover)
|
||||||
|
self.canvas.itemconfig(self.cover_img_id, image=self.photo_cover)
|
||||||
|
|
||||||
|
text_x = self.card_x1 + int(self.card_h * 0.82)
|
||||||
|
font_sp_title = max(11, int(self.card_h * 0.11))
|
||||||
|
font_sp_sub = max(9, int(self.card_h * 0.085))
|
||||||
|
|
||||||
|
self.canvas.itemconfig(self.spotify_title_id, font=("Segoe UI", font_sp_title, "bold"))
|
||||||
|
self.canvas.itemconfig(self.spotify_subtitle_id, font=("Segoe UI", font_sp_sub, "bold"))
|
||||||
|
|
||||||
|
self.canvas.coords(self.spotify_title_id, text_x, self.card_y1 + int(self.card_h * 0.22))
|
||||||
|
self.canvas.coords(self.spotify_subtitle_id, text_x, self.card_y1 + int(self.card_h * 0.40))
|
||||||
|
|
||||||
|
bar_x1 = text_x
|
||||||
|
bar_x2 = self.card_x1 + self.card_w - int(self.card_h * 0.12)
|
||||||
|
bar_y = self.card_y1 + int(self.card_h * 0.68)
|
||||||
|
|
||||||
|
self.canvas.coords(self.pbar_bg, bar_x1, bar_y, bar_x2, bar_y)
|
||||||
|
self.canvas.coords(self.time_curr_id, bar_x1, bar_y + int(self.card_h * 0.18))
|
||||||
|
self.canvas.coords(self.time_total_id, bar_x2, bar_y + int(self.card_h * 0.18))
|
||||||
|
|
||||||
|
if self.active_item:
|
||||||
|
self.show_product_by_index(self.current_catalog_index - 1)
|
||||||
|
|
||||||
|
if self.is_popup_visible:
|
||||||
|
self.canvas.coords(self.popup_bg_id, 0, 0, w, h)
|
||||||
|
self.canvas.coords(self.popup_img_id, w // 2, h // 2)
|
||||||
|
photo = self._build_popup_photo(w, h)
|
||||||
|
if photo:
|
||||||
|
self.popup_photo = photo
|
||||||
|
self.canvas.itemconfig(self.popup_img_id, image=self.popup_photo)
|
||||||
|
self.canvas.tag_raise(self.popup_bg_id)
|
||||||
|
self.canvas.tag_raise(self.popup_img_id)
|
||||||
|
|
||||||
|
def update_clock(self):
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
time_str = now.strftime("%H:%M:%S")
|
||||||
|
|
||||||
|
days_cz = ["Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota", "Neděle"]
|
||||||
|
months_cz = ["ledna", "února", "března", "dubna", "května", "června", "července", "srpna", "září", "října", "listopadu", "prosince"]
|
||||||
|
|
||||||
|
day_name = days_cz[now.weekday()]
|
||||||
|
month_name = months_cz[now.month - 1]
|
||||||
|
date_str = f"{day_name}, {now.day}. {month_name} {now.year}"
|
||||||
|
|
||||||
|
self.canvas.itemconfig(self.clock_time_id, text=time_str)
|
||||||
|
self.canvas.itemconfig(self.clock_date_id, text=date_str)
|
||||||
|
self.root.after(1000, self.update_clock)
|
||||||
|
|
||||||
|
def init_particles_canvas(self):
|
||||||
|
for p in self.particles:
|
||||||
|
if p.p_type in ['bokeh_large', 'bokeh_medium']:
|
||||||
|
outer_id = self.canvas.create_oval(p.x - p.radius, p.y - p.radius, p.x + p.radius, p.y + p.radius, fill=p.color_outer, outline="")
|
||||||
|
r_in = p.radius * 0.45
|
||||||
|
inner_id = self.canvas.create_oval(p.x - r_in, p.y - r_in, p.x + r_in, p.y + r_in, fill=p.color_inner, outline="")
|
||||||
|
self.particle_draw_ids.append((outer_id, inner_id))
|
||||||
|
else:
|
||||||
|
draw_id = self.canvas.create_oval(p.x - p.radius, p.y - p.radius, p.x + p.radius, p.y + p.radius, fill=p.color_inner, outline="")
|
||||||
|
self.particle_draw_ids.append((draw_id, None))
|
||||||
|
|
||||||
|
def animate_particles(self):
|
||||||
|
for p, draw_ids in zip(self.particles, self.particle_draw_ids):
|
||||||
|
p.update(self.w, self.h)
|
||||||
|
outer_id, inner_id = draw_ids
|
||||||
|
|
||||||
|
if inner_id is not None:
|
||||||
|
self.canvas.coords(outer_id, p.x - p.radius, p.y - p.radius, p.x + p.radius, p.y + p.radius)
|
||||||
|
r_in = p.radius * 0.45
|
||||||
|
self.canvas.coords(inner_id, p.x - r_in, p.y - r_in, p.x + r_in, p.y + r_in)
|
||||||
|
else:
|
||||||
|
self.canvas.coords(outer_id, p.x - p.radius, p.y - p.radius, p.x + p.radius, p.y + p.radius)
|
||||||
|
self.root.after(35, self.animate_particles)
|
||||||
|
|
||||||
|
def toggle_pause(self):
|
||||||
|
self.is_paused = not self.is_paused
|
||||||
|
text = "⏸ PAUZA" if self.is_paused else ""
|
||||||
|
self.canvas.itemconfig(self.pause_indicator_id, text=text)
|
||||||
|
|
||||||
|
def next_product(self):
|
||||||
|
if self.catalog_items:
|
||||||
|
self.show_product_by_index(self.current_catalog_index, smooth=True)
|
||||||
|
self.current_catalog_index = (self.current_catalog_index + 1) % len(self.catalog_items)
|
||||||
|
|
||||||
|
def prev_product(self):
|
||||||
|
if self.catalog_items:
|
||||||
|
prev_idx = (self.current_catalog_index - 2) % len(self.catalog_items)
|
||||||
|
self.show_product_by_index(prev_idx, smooth=True)
|
||||||
|
self.current_catalog_index = (prev_idx + 1) % len(self.catalog_items)
|
||||||
|
|
||||||
|
def reload_catalog_action(self):
|
||||||
|
self.load_catalog()
|
||||||
|
if self.catalog_items:
|
||||||
|
self.show_product_by_index(0, smooth=True)
|
||||||
|
self.current_catalog_index = 1 % len(self.catalog_items)
|
||||||
|
|
||||||
|
def update_card_background(self, rgba_color):
|
||||||
|
self.current_card_rgba = rgba_color
|
||||||
|
img = Image.new("RGBA", (self.card_w, self.card_h), (0, 0, 0, 0))
|
||||||
|
draw = ImageDraw.Draw(img)
|
||||||
|
|
||||||
|
r, g, b, a = rgba_color
|
||||||
|
border_color = (min(r + 80, 255), min(g + 80, 255), min(b + 80, 255), 200)
|
||||||
|
|
||||||
|
draw.rounded_rectangle([0, 0, self.card_w - 1, self.card_h - 1], radius=16, fill=rgba_color, outline=border_color, width=2)
|
||||||
|
|
||||||
|
self.card_bg_photo = ImageTk.PhotoImage(img)
|
||||||
|
self.canvas.itemconfig(self.card_bg_id, image=self.card_bg_photo)
|
||||||
|
|
||||||
|
def load_catalog(self):
|
||||||
|
global KATALOG_DIR
|
||||||
|
if not os.path.exists(KATALOG_DIR):
|
||||||
|
KATALOG_DIR = os.path.join(SCRIPT_DIR, "katalog")
|
||||||
|
if not os.path.exists(KATALOG_DIR):
|
||||||
|
KATALOG_DIR = os.path.join(SCRIPT_DIR, "documents", "katalog")
|
||||||
|
|
||||||
|
self.catalog_items = []
|
||||||
|
if not os.path.exists(KATALOG_DIR):
|
||||||
|
return
|
||||||
|
|
||||||
|
valid_extensions = ('.png', '.jpg', '.jpeg', '.webp')
|
||||||
|
|
||||||
|
for folder_name in sorted(os.listdir(KATALOG_DIR)):
|
||||||
|
folder_path = os.path.join(KATALOG_DIR, folder_name)
|
||||||
|
if os.path.isdir(folder_path):
|
||||||
|
info_path = os.path.join(folder_path, "info.txt")
|
||||||
|
|
||||||
|
title = folder_name
|
||||||
|
price = ""
|
||||||
|
badge = ""
|
||||||
|
|
||||||
|
if os.path.exists(info_path):
|
||||||
|
try:
|
||||||
|
with open(info_path, "r", encoding="utf-8") as f:
|
||||||
|
lines = [line.strip() for line in f.readlines() if line.strip()]
|
||||||
|
if len(lines) >= 1:
|
||||||
|
title = lines[0]
|
||||||
|
if len(lines) >= 2:
|
||||||
|
price = lines[1]
|
||||||
|
if len(lines) >= 3:
|
||||||
|
badge = lines[2]
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Chyba při čtení {info_path}: {e}")
|
||||||
|
|
||||||
|
images = [f for f in os.listdir(folder_path) if f.lower().endswith(valid_extensions)]
|
||||||
|
images.sort(key=natural_sort_key)
|
||||||
|
image_paths = [os.path.join(folder_path, img) for img in images]
|
||||||
|
|
||||||
|
self.catalog_items.append({
|
||||||
|
"title": title,
|
||||||
|
"price": price,
|
||||||
|
"badge": badge,
|
||||||
|
"image_paths": image_paths
|
||||||
|
})
|
||||||
|
|
||||||
|
def cycle_product(self):
|
||||||
|
if not self.is_paused:
|
||||||
|
if not self.catalog_items:
|
||||||
|
self.load_catalog()
|
||||||
|
|
||||||
|
if self.catalog_items:
|
||||||
|
self.show_product_by_index(self.current_catalog_index, smooth=True)
|
||||||
|
self.current_catalog_index = (self.current_catalog_index + 1) % len(self.catalog_items)
|
||||||
|
|
||||||
|
self.root.after(CYCLE_INTERVAL_MS, self.cycle_product)
|
||||||
|
|
||||||
|
def show_product_by_index(self, index, smooth=False):
|
||||||
|
if not self.catalog_items:
|
||||||
|
return
|
||||||
|
|
||||||
|
idx = index % len(self.catalog_items)
|
||||||
|
self.active_item = self.catalog_items[idx]
|
||||||
|
|
||||||
|
self.canvas.itemconfig(self.title_text_id, text=self.active_item["title"])
|
||||||
|
self.canvas.itemconfig(self.title_shadow_id, text=self.active_item["title"])
|
||||||
|
|
||||||
|
price_val = self.active_item["price"]
|
||||||
|
self.canvas.itemconfig(self.price_text_id, text=price_val)
|
||||||
|
self.canvas.itemconfig(self.price_shadow_id, text=price_val)
|
||||||
|
if price_val:
|
||||||
|
self.canvas.itemconfig(self.price_bg_id, state="normal")
|
||||||
|
self.canvas.itemconfig(self.price_shadow_id, state="normal")
|
||||||
|
self.canvas.itemconfig(self.price_text_id, state="normal")
|
||||||
|
else:
|
||||||
|
self.canvas.itemconfig(self.price_bg_id, state="hidden")
|
||||||
|
self.canvas.itemconfig(self.price_shadow_id, state="hidden")
|
||||||
|
self.canvas.itemconfig(self.price_text_id, state="hidden")
|
||||||
|
|
||||||
|
badge_val = self.active_item["badge"]
|
||||||
|
if badge_val:
|
||||||
|
badge_upper = badge_val.upper()
|
||||||
|
if any(w in badge_upper for w in ["VYPRODÁNO", "NENÍ", "OUT"]):
|
||||||
|
bg_color, text_color = "#e63946", "#ffffff"
|
||||||
|
elif any(w in badge_upper for w in ["AKCE", "SLEVA", "SALE", "%"]):
|
||||||
|
bg_color, text_color = "#f77f00", "#ffffff"
|
||||||
|
elif any(w in badge_upper for w in ["NOVINKA", "NEW", "TOP"]):
|
||||||
|
bg_color, text_color = "#2a9d8f", "#ffffff"
|
||||||
|
else:
|
||||||
|
bg_color, text_color = "#7209b7", "#ffffff"
|
||||||
|
|
||||||
|
self.canvas.itemconfig(self.badge_text_id, text=f" {badge_val.upper()} ", fill=text_color, state="normal")
|
||||||
|
|
||||||
|
badge_y = self.h * 0.14
|
||||||
|
self.canvas.coords(self.badge_text_id, self.w * 0.5, badge_y)
|
||||||
|
|
||||||
|
bbox = self.canvas.bbox(self.badge_text_id)
|
||||||
|
if bbox:
|
||||||
|
x1, y1, x2, y2 = bbox
|
||||||
|
self.canvas.coords(self.badge_bg_id, x1 - 12, y1 - 5, x2 + 12, y2 + 5)
|
||||||
|
self.canvas.itemconfig(self.badge_bg_id, fill=bg_color, outline="#ffffff", width=1, state="normal")
|
||||||
|
else:
|
||||||
|
self.canvas.itemconfig(self.badge_text_id, state="hidden")
|
||||||
|
self.canvas.itemconfig(self.badge_bg_id, state="hidden")
|
||||||
|
|
||||||
|
self.current_frame_index = 0
|
||||||
|
self.update_product_frame(smooth_fade=smooth)
|
||||||
|
|
||||||
|
def animate_product_3d(self):
|
||||||
|
if self.active_item:
|
||||||
|
paths = self.active_item["image_paths"]
|
||||||
|
if len(paths) > 1:
|
||||||
|
self.current_frame_index = (self.current_frame_index + 1) % len(paths)
|
||||||
|
self.update_product_frame(smooth_fade=False)
|
||||||
|
|
||||||
|
self.root.after(FRAME_INTERVAL_MS, self.animate_product_3d)
|
||||||
|
|
||||||
|
def update_product_frame(self, smooth_fade=False):
|
||||||
|
if not self.active_item:
|
||||||
|
return
|
||||||
|
|
||||||
|
paths = self.active_item["image_paths"]
|
||||||
|
if paths:
|
||||||
|
img_path = paths[self.current_frame_index % len(paths)]
|
||||||
|
try:
|
||||||
|
raw_img = Image.open(img_path).convert("RGBA")
|
||||||
|
max_w = int(self.w * 0.42)
|
||||||
|
max_h = int(self.h * 0.52)
|
||||||
|
|
||||||
|
raw_img.thumbnail((max_w, max_h), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
|
if smooth_fade:
|
||||||
|
self.run_fade_animation(raw_img)
|
||||||
|
else:
|
||||||
|
target_padded = Image.new("RGBA", (max_w, max_h), (0, 0, 0, 0))
|
||||||
|
tw, th = raw_img.size
|
||||||
|
target_padded.paste(raw_img, ((max_w - tw) // 2, (max_h - th) // 2), raw_img)
|
||||||
|
|
||||||
|
self.current_prod_photo = ImageTk.PhotoImage(target_padded)
|
||||||
|
self.canvas.itemconfig(self.prod_image_id, image=self.current_prod_photo)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Chyba při načítání snímku {img_path}: {e}")
|
||||||
|
self.canvas.itemconfig(self.prod_image_id, image="")
|
||||||
|
else:
|
||||||
|
self.canvas.itemconfig(self.prod_image_id, image="")
|
||||||
|
|
||||||
|
def run_fade_animation(self, target_img):
|
||||||
|
""" Provede plynulý přechod (fade) na novou fotografii produktu """
|
||||||
|
if self.fade_anim_job:
|
||||||
|
self.root.after_cancel(self.fade_anim_job)
|
||||||
|
|
||||||
|
max_w = int(self.w * 0.42)
|
||||||
|
max_h = int(self.h * 0.52)
|
||||||
|
|
||||||
|
target_padded = Image.new("RGBA", (max_w, max_h), (0, 0, 0, 0))
|
||||||
|
tw, th = target_img.size
|
||||||
|
target_padded.paste(target_img, ((max_w - tw) // 2, (max_h - th) // 2), target_img)
|
||||||
|
|
||||||
|
base_bg = Image.new("RGBA", (max_w, max_h), (7, 1, 15, 0))
|
||||||
|
|
||||||
|
steps = 5
|
||||||
|
delay = 25
|
||||||
|
|
||||||
|
def step_fade(current_step):
|
||||||
|
faded_img = Image.blend(base_bg, target_padded, current_step / steps)
|
||||||
|
|
||||||
|
self.current_prod_photo = ImageTk.PhotoImage(faded_img)
|
||||||
|
self.canvas.itemconfig(self.prod_image_id, image=self.current_prod_photo)
|
||||||
|
|
||||||
|
if current_step < steps:
|
||||||
|
self.fade_anim_job = self.root.after(delay, lambda: step_fade(current_step + 1))
|
||||||
|
|
||||||
|
step_fade(1)
|
||||||
|
|
||||||
|
def poll_data(self):
|
||||||
|
pythoncom.CoInitialize()
|
||||||
|
while self.running:
|
||||||
|
try:
|
||||||
|
res = requests.get(SERVER_URL, timeout=1)
|
||||||
|
if res.status_code == 200:
|
||||||
|
data = res.json()
|
||||||
|
|
||||||
|
artist = str(data.get("artist", "")).strip()
|
||||||
|
title = str(data.get("title", "")).strip()
|
||||||
|
progress = str(data.get("progressTime", "0:00/0:00"))
|
||||||
|
img_url = data.get("coverImg", None)
|
||||||
|
|
||||||
|
raw_ad = data.get("isAd", data.get("is_ad", data.get("ad", False)))
|
||||||
|
if isinstance(raw_ad, str):
|
||||||
|
is_ad_flag = raw_ad.strip().lower() in ("true", "1", "yes")
|
||||||
|
else:
|
||||||
|
is_ad_flag = bool(raw_ad)
|
||||||
|
|
||||||
|
text_to_check = f"{artist} {title} {progress}".lower()
|
||||||
|
|
||||||
|
ad_phrases = [
|
||||||
|
"advertisement",
|
||||||
|
"reklama",
|
||||||
|
"sponzorované",
|
||||||
|
"sponzorovano",
|
||||||
|
"spotify partner",
|
||||||
|
"přetvoř svůj poslech",
|
||||||
|
"pretvor svoj poslech",
|
||||||
|
"tvoje uši si zaslouží",
|
||||||
|
"tvoje usi si zaslouzi"
|
||||||
|
]
|
||||||
|
|
||||||
|
is_ad_detected = is_ad_flag or any(p in text_to_check for p in ad_phrases)
|
||||||
|
|
||||||
|
if is_ad_detected:
|
||||||
|
if not self.is_ad_active:
|
||||||
|
self.is_ad_active = True
|
||||||
|
self.trigger_ad_sound()
|
||||||
|
else:
|
||||||
|
if self.is_ad_active:
|
||||||
|
self.is_ad_active = False
|
||||||
|
self.stop_ad_sound()
|
||||||
|
|
||||||
|
self.root.after(0, self.update_gui, artist, title, progress, img_url, self.is_ad_active)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
time.sleep(0.4)
|
||||||
|
|
||||||
|
def parse_time_to_seconds(self, time_str):
|
||||||
|
try:
|
||||||
|
parts = time_str.split(':')
|
||||||
|
return int(parts[0]) * 60 + int(parts[1])
|
||||||
|
except Exception:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def update_gui(self, artist, title, progress, img_url, is_ad=False):
|
||||||
|
if is_ad:
|
||||||
|
title_disp = "📢 REKLAMA"
|
||||||
|
artist_disp = "Spotify Partner"
|
||||||
|
else:
|
||||||
|
title_disp = title if len(title) <= 22 else title[:20] + "..."
|
||||||
|
artist_disp = artist if len(artist) <= 26 else artist[:24] + "..."
|
||||||
|
|
||||||
|
self.canvas.itemconfig(self.spotify_title_id, text=title_disp)
|
||||||
|
self.canvas.itemconfig(self.spotify_subtitle_id, text=artist_disp)
|
||||||
|
|
||||||
|
if "/" in progress:
|
||||||
|
curr, dur = progress.split("/")
|
||||||
|
self.canvas.itemconfig(self.time_curr_id, text=curr)
|
||||||
|
self.canvas.itemconfig(self.time_total_id, text=dur)
|
||||||
|
|
||||||
|
c_sec = self.parse_time_to_seconds(curr)
|
||||||
|
d_sec = self.parse_time_to_seconds(dur)
|
||||||
|
percent = (c_sec / d_sec) if d_sec > 0 else 0
|
||||||
|
|
||||||
|
text_x = self.card_x1 + int(self.card_h * 0.82)
|
||||||
|
bar_x1 = text_x
|
||||||
|
bar_x2 = self.card_x1 + self.card_w - int(self.card_h * 0.12)
|
||||||
|
bar_y = self.card_y1 + int(self.card_h * 0.68)
|
||||||
|
|
||||||
|
max_w = bar_x2 - bar_x1
|
||||||
|
fill_x = bar_x1 + int(max_w * percent)
|
||||||
|
self.canvas.coords(self.pbar_fg, bar_x1, bar_y, fill_x, bar_y)
|
||||||
|
|
||||||
|
if img_url and img_url != self.current_img_url:
|
||||||
|
self.current_img_url = img_url
|
||||||
|
threading.Thread(target=self.download_cover, args=(img_url,), daemon=True).start()
|
||||||
|
|
||||||
|
def download_cover(self, url):
|
||||||
|
try:
|
||||||
|
res = requests.get(url, timeout=3)
|
||||||
|
if res.status_code == 200:
|
||||||
|
self.raw_cover_img = Image.open(BytesIO(res.content)).convert("RGBA")
|
||||||
|
|
||||||
|
small_img = self.raw_cover_img.resize((1, 1), Image.Resampling.BILINEAR)
|
||||||
|
dom_color = small_img.getpixel((0, 0))
|
||||||
|
|
||||||
|
dark_r = int(dom_color[0] * 0.35)
|
||||||
|
dark_g = int(dom_color[1] * 0.35)
|
||||||
|
dark_b = int(dom_color[2] * 0.35)
|
||||||
|
card_rgba = (dark_r, dark_g, dark_b, 225)
|
||||||
|
|
||||||
|
cover_size = int(self.card_h * 0.58)
|
||||||
|
cover_img = self.raw_cover_img.resize((cover_size, cover_size), Image.Resampling.LANCZOS)
|
||||||
|
self.photo_cover = ImageTk.PhotoImage(cover_img)
|
||||||
|
|
||||||
|
self.root.after(0, lambda: [
|
||||||
|
self.canvas.itemconfig(self.cover_img_id, image=self.photo_cover),
|
||||||
|
self.update_card_background(card_rgba)
|
||||||
|
])
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Chyba při načítání obalu alba: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
root = tk.Tk()
|
||||||
|
app = FullscreenJarmarkDisplay(root)
|
||||||
|
root.mainloop()
|
||||||
Reference in New Issue
Block a user