4 Commits

7 changed files with 292 additions and 13 deletions

View File

@@ -49,14 +49,16 @@ Projekcija/
### Requirements ### Requirements
- Python 3.8+ - Python 3.8+
- Flask (for web interface) - **Tkinter** (usually included with Python, but may require `python3-tk` on some Linux distributions)
- **Flask** (for web interface)
- `sqlite3` (included with Python) - `sqlite3` (included with Python)
- `requests` (for remote database updates and notifications)
### Setup ### Setup
1. **Install Dependencies**: 1. **Install Dependencies**:
```bash ```bash
pip install flask pip install flask requests
``` ```
2. **Configure Settings**: 2. **Configure Settings**:
@@ -96,11 +98,12 @@ python projector.py
### Special Commands (Input as song number) ### Special Commands (Input as song number)
- **9999**: Shutdown system - **9999**: Shutdown system (Windows/Linux)
- **9998**: Restart system - **9998**: Restart system (Windows/Linux)
- **9997**: Restart application - **9997**: Restart application
- **9988**: Exit application - **9988**: Exit application
- **9901**: Update songs database from `db_update_url` - **9901**: Update songs database from `db_update_url`
- **9900**: Show application information (version, author, license)
### Configuration ### Configuration
@@ -112,8 +115,11 @@ Edit `settings.json` to customize:
- **screen_width_percent**: Width of the text area (e.g., 60) - **screen_width_percent**: Width of the text area (e.g., 60)
- **font_bold**: Use bold font (true/false) - **font_bold**: Use bold font (true/false)
- **show_song_info**: Show song number and page info at bottom (true/false) - **show_song_info**: Show song number and page info at bottom (true/false)
- **split_by_stanza**: If true, each stanza starts on a new page (true/false)
- **web_port**: Port for web interface (0 to disable) - **web_port**: Port for web interface (0 to disable)
- **db_update_url**: URL for remote database synchronization - **db_update_url**: URL for remote database synchronization
- **ntfy_topic**: Topic for ntfy.sh notifications
- **installation_label**: Custom label for the installation (shown in app info)
### Web Interface ### Web Interface
@@ -132,14 +138,17 @@ Features:
## API Endpoints ## API Endpoints
- `GET /api/state` Current projector state - `GET /api/state` Current projector state (text, page info, modes)
- `GET /api/events` SSE endpoint for real-time update notifications
- `GET /api/app_info` Application metadata (version, author, song count)
- `POST /api/load_song` Load a song by number - `POST /api/load_song` Load a song by number
- `POST /api/next_page` Next page - `POST /api/next_page` Next page
- `POST /api/prev_page` Previous page - `POST /api/prev_page` Previous page
- `POST /api/clear_screen` Clear display - `POST /api/clear_screen` Clear display
- `POST /api/toggle_caps` Toggle uppercase - `POST /api/toggle_caps` Toggle uppercase
- `POST /api/search_songs` Search songs - `POST /api/toggle_split` Toggle stanza split mode
- `GET /api/get_song_details` Get lyrics for editing - `POST /api/search_songs` Search songs by title
- `GET /api/get_song_details` Get lyrics and title for editing
- `POST /api/update_song` Save song changes or create new - `POST /api/update_song` Save song changes or create new
## Testing ## Testing

10
appinfo.json Normal file
View File

@@ -0,0 +1,10 @@
{
"name": "Projekcija",
"description": "Aplikacija za projekcijo besedil pesmi na zaslon.",
"version": "0.7.0",
"authors": [
"Uroš Urbanija (izvorna zasnova)",
"Valentin Korenjak (nadgradnje in vzdrževanje)"
],
"license": "GPLv3"
}

View File

@@ -29,7 +29,7 @@ import subprocess
import sys import sys
import ctypes import ctypes
import tkinter.messagebox as messagebox import tkinter.messagebox as messagebox
from web.server import start_server_thread from web.server import start_server_thread, notify_clients
import urllib.request import urllib.request
import tempfile import tempfile
from db_schema import create_tables from db_schema import create_tables
@@ -343,6 +343,9 @@ class SongProjector:
elif self.song_number == "9901": elif self.song_number == "9901":
self.update_songs_database() self.update_songs_database()
return return
elif self.song_number == "9900":
self.show_app_info_tkinter()
return
try: try:
song_id = int(self.song_number) song_id = int(self.song_number)
self.cursor.execute("SELECT lyrics FROM songs WHERE id=?", (song_id,)) self.cursor.execute("SELECT lyrics FROM songs WHERE id=?", (song_id,))
@@ -476,6 +479,7 @@ class SongProjector:
self.song_info_label.lift() self.song_info_label.lift()
else: else:
self.song_info_label.config(text="") self.song_info_label.config(text="")
notify_clients()
# ------------------------------------------------------ # ------------------------------------------------------
# Navigacija po straneh # Navigacija po straneh
@@ -504,6 +508,7 @@ class SongProjector:
self.color_frame.config(bg="black", width=self.color_width, height=self.screen_height) self.color_frame.config(bg="black", width=self.color_width, height=self.screen_height)
self.color_frame.place(relx=0.5, rely=0.5, anchor="center") self.color_frame.place(relx=0.5, rely=0.5, anchor="center")
self.song_info_label.config(text="") self.song_info_label.config(text="")
notify_clients()
# ------------------------------------------------------ # ------------------------------------------------------
# Iskanje po naslovu # Iskanje po naslovu
@@ -715,6 +720,49 @@ class SongProjector:
except Exception as e: except Exception as e:
print(f"Napaka pri pošiljanju ntfy obvestila: {e}") print(f"Napaka pri pošiljanju ntfy obvestila: {e}")
# ------------------------------------------------------
# Prikaži informacije o aplikaciji v Tkinter oknu
# ------------------------------------------------------
def show_app_info_tkinter(self):
"""Prikaže informacije o aplikaciji v glavnem oknu (ukaz 9900)."""
try:
with open('appinfo.json', 'r', encoding='utf-8') as f:
info = json.load(f)
self.cursor.execute("SELECT COUNT(*) FROM songs")
count = self.cursor.fetchone()[0]
authors = ", ".join(info.get("authors", []))
display_text = (
f"{info.get('name', 'Projekcija')}\n"
f"Verzija: {info.get('version', 'neznana')}\n\n"
f"{info.get('description', '')}\n\n"
f"Avtorji: {authors}\n\n"
f"Število pesmi v bazi: {count}"
)
# Ponastavitev izgleda barvnega območja za prikaz informacij
self.color_frame.config(bg=self.settings["bg_color"], width=self.color_width, height=self.screen_height)
self.color_frame.place(relx=0.5, rely=0.5, anchor="center")
self.display_text.config(bg=self.settings["bg_color"], fg=self.settings["fg_color"], text=display_text)
self.display_text.pack(expand=True)
# self.song_number_last = "9900"
self.song_info_label.config(text="Informacije o programu")
self.song_info_label.lift()
self.pages = []
self.current_page_index = 0
self.waiting_for_song = True
notify_clients()
except Exception as e:
self.display_text.config(text=f"Napaka pri branju informacij: {e}")
finally:
self.song_number = ""
# ---------------------------------------------------------- # ----------------------------------------------------------
# Zagon aplikacije # Zagon aplikacije
# ---------------------------------------------------------- # ----------------------------------------------------------

View File

@@ -27,8 +27,11 @@ than being generated inside Python code.
import threading import threading
import os import os
import json
import queue
import time
from flask import Flask, render_template, request, jsonify from flask import Flask, render_template, request, jsonify, Response
# create Flask app with proper folders relative to this file # create Flask app with proper folders relative to this file
app = Flask(__name__, static_folder="static", template_folder="templates") app = Flask(__name__, static_folder="static", template_folder="templates")
@@ -36,6 +39,17 @@ app = Flask(__name__, static_folder="static", template_folder="templates")
# Globalna referenca na SongProjector aplikaciju # Globalna referenca na SongProjector aplikaciju
_projector_app = None _projector_app = None
# List of queues for SSE clients
_sse_clients = []
_sse_lock = threading.Lock()
def notify_clients():
"""Notify all connected SSE clients to refresh content"""
with _sse_lock:
for q in _sse_clients:
q.put("refresh content")
def set_projector_app(projector_app): def set_projector_app(projector_app):
"""Postavi referenco na SongProjector aplikacijo""" """Postavi referenco na SongProjector aplikacijo"""
@@ -96,6 +110,26 @@ def get_state():
}) })
@app.route('/api/events')
def sse_events():
"""SSE endpoint for real-time updates"""
def event_stream():
q = queue.Queue()
with _sse_lock:
_sse_clients.append(q)
try:
# Send initial refresh command on connection
yield "data: refresh content\n\n"
while True:
msg = q.get()
yield f"data: {msg}\n\n"
finally:
with _sse_lock:
_sse_clients.remove(q)
return Response(event_stream(), mimetype="text/event-stream")
@app.route('/api/load_song', methods=['POST']) @app.route('/api/load_song', methods=['POST'])
def load_song(): def load_song():
"""Naloži pesem po številki""" """Naloži pesem po številki"""
@@ -110,6 +144,7 @@ def load_song():
_projector_app.load_song() _projector_app.load_song()
if hasattr(_projector_app, 'show_page'): if hasattr(_projector_app, 'show_page'):
_projector_app.show_page() _projector_app.show_page()
notify_clients()
return jsonify({'status': 'ok'}) return jsonify({'status': 'ok'})
@@ -119,6 +154,7 @@ def next_page():
"""Naslednja stran""" """Naslednja stran"""
if _projector_app is not None: if _projector_app is not None:
_projector_app.next_page() _projector_app.next_page()
notify_clients()
return jsonify({'status': 'ok'}) return jsonify({'status': 'ok'})
@@ -128,6 +164,7 @@ def prev_page():
"""Prejšnja stran""" """Prejšnja stran"""
if _projector_app is not None: if _projector_app is not None:
_projector_app.prev_page() _projector_app.prev_page()
notify_clients()
return jsonify({'status': 'ok'}) return jsonify({'status': 'ok'})
@@ -137,6 +174,7 @@ def clear_screen():
"""Zatemniti ekran""" """Zatemniti ekran"""
if _projector_app is not None: if _projector_app is not None:
_projector_app.clear_screen() _projector_app.clear_screen()
notify_clients()
return jsonify({'status': 'ok'}) return jsonify({'status': 'ok'})
@@ -147,6 +185,7 @@ def toggle_caps():
if _projector_app is not None: if _projector_app is not None:
_projector_app.all_caps_mode = not _projector_app.all_caps_mode _projector_app.all_caps_mode = not _projector_app.all_caps_mode
_projector_app.show_page() _projector_app.show_page()
notify_clients()
return jsonify({'status': 'ok'}) return jsonify({'status': 'ok'})
@@ -156,10 +195,30 @@ def toggle_split():
"""Preklop med načinom preloma po kiticah in prostim prelomom""" """Preklop med načinom preloma po kiticah in prostim prelomom"""
if _projector_app is not None: if _projector_app is not None:
_projector_app.toggle_split_mode() _projector_app.toggle_split_mode()
notify_clients()
return jsonify({'status': 'ok'}) return jsonify({'status': 'ok'})
@app.route('/api/app_info', methods=['GET'])
def get_app_info():
"""Vrne informacije o aplikaciji iz appinfo.json"""
try:
# appinfo.json je v korenskem imeniku projekta
with open('appinfo.json', 'r', encoding='utf-8') as f:
info = json.load(f)
# Dodaj število pesmi v bazi
if _projector_app is not None:
_projector_app.cursor.execute("SELECT COUNT(*) FROM songs")
count = _projector_app.cursor.fetchone()[0]
info['song_count'] = count
return jsonify(info)
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/api/search_songs', methods=['POST']) @app.route('/api/search_songs', methods=['POST'])
def search_songs(): def search_songs():
"""Iskanje besedil po naslovu""" """Iskanje besedil po naslovu"""
@@ -270,6 +329,7 @@ def update_song():
if str(_projector_app.song_number_last) == str(song_id): if str(_projector_app.song_number_last) == str(song_id):
_projector_app.song_number = str(song_id) _projector_app.song_number = str(song_id)
_projector_app.load_song() _projector_app.load_song()
notify_clients()
return jsonify({'status': 'ok'}) return jsonify({'status': 'ok'})
except Exception as e: except Exception as e:

View File

@@ -10,6 +10,9 @@ const darkBtn = document.getElementById('dark-btn');
const splitBtn = document.getElementById('split-btn'); const splitBtn = document.getElementById('split-btn');
const pageInfo = document.getElementById('page-info'); const pageInfo = document.getElementById('page-info');
const clearBtn = document.getElementById('clear-btn'); const clearBtn = document.getElementById('clear-btn');
const aboutBtn = document.getElementById('about-btn');
const aboutModal = document.getElementById('about-modal');
const aboutCloseBtn = document.getElementById('about-close-btn');
const keypadButtons = document.querySelectorAll('.btn-key'); const keypadButtons = document.querySelectorAll('.btn-key');
const keypadWrapper = document.getElementById('keypad-wrapper'); const keypadWrapper = document.getElementById('keypad-wrapper');
const toggleKeypadBtn = document.getElementById('toggle-keypad-btn'); const toggleKeypadBtn = document.getElementById('toggle-keypad-btn');
@@ -345,6 +348,41 @@ async function saveSongEdit() {
} }
} }
// Odpri About dialog
async function openAbout() {
try {
const response = await fetch('/api/app_info');
const data = await response.json();
if (data.error) {
alert('Napaka pri pridobivanju informacij o programu.');
return;
}
document.getElementById('about-name').textContent = data.name;
document.getElementById('about-version').textContent = 'Verzija ' + data.version;
document.getElementById('about-description').textContent = data.description;
// Dodaj število pesmi
if (data.song_count !== undefined) {
document.getElementById('about-description').innerHTML += `<br><br>Število pesmi v bazi: <strong>${data.song_count}</strong>`;
}
const authorsList = document.getElementById('about-authors');
authorsList.innerHTML = '';
data.authors.forEach(author => {
const li = document.createElement('li');
li.textContent = author;
authorsList.appendChild(li);
});
aboutModal.classList.add('show');
menuDropdown.classList.remove('show');
} catch (error) {
console.error('Napaka pri pridobivanju informacij o programu:', error);
}
}
// skrij/pokaži tipkovnico // skrij/pokaži tipkovnico
function toggleKeypad() { function toggleKeypad() {
if (!keypadWrapper || !toggleKeypadBtn) return; if (!keypadWrapper || !toggleKeypadBtn) return;
@@ -419,6 +457,20 @@ if (toggleKeypadBtn) {
}); });
} }
// O programu
if (aboutBtn) {
aboutBtn.addEventListener('click', () => {
vibrate();
openAbout();
});
}
if (aboutCloseBtn) {
aboutCloseBtn.addEventListener('click', () => {
aboutModal.classList.remove('show');
});
}
// Uredi besedilo // Uredi besedilo
if (editSongBtn) { if (editSongBtn) {
editSongBtn.addEventListener('click', () => { editSongBtn.addEventListener('click', () => {
@@ -489,6 +541,10 @@ document.addEventListener('click', (e) => {
if (menuDropdown && !menuDropdown.contains(e.target) && e.target !== menuToggle) { if (menuDropdown && !menuDropdown.contains(e.target) && e.target !== menuToggle) {
menuDropdown.classList.remove('show'); menuDropdown.classList.remove('show');
} }
// Zapri About modal ob kliku izven vsebine
if (e.target === aboutModal) {
aboutModal.classList.remove('show');
}
}); });
// Iskanje dogodki // Iskanje dogodki
@@ -597,9 +653,24 @@ document.addEventListener('keydown', (e) => {
updateState(true); updateState(true);
requestWakeLock(); requestWakeLock();
// osveževanje za sinhronizacijo med več napravami // SSE osveževanje za sinhronizacijo med več napravami
setInterval(() => { function setupSSE() {
updateState(false); const evtSource = new EventSource("/api/events");
}, 1000);
evtSource.onmessage = function(event) {
console.log("SSE dogodek:", event.data);
if (event.data === "refresh content") {
updateState(false);
}
};
evtSource.onerror = function(err) {
console.error("SSE napaka, ponovni poskus čez 5s...", err);
evtSource.close();
setTimeout(setupSSE, 5000);
};
}
setupSSE();
console.log('JavaScript inicializacija zaključena'); console.log('JavaScript inicializacija zaključena');

View File

@@ -429,6 +429,12 @@ body {
height: 100%; height: 100%;
background-color: rgba(0,0,0,0.8); background-color: rgba(0,0,0,0.8);
overflow-y: auto; overflow-y: auto;
align-items: center;
justify-content: center;
}
.modal.show {
display: flex !important;
} }
.modal-content { .modal-content {
@@ -474,6 +480,59 @@ textarea.form-control {
margin-top: 20px; margin-top: 20px;
} }
/* About Modal Styles */
.about-content {
text-align: center;
padding: 30px;
}
.about-header {
margin-bottom: 25px;
}
.about-logo {
width: 96px;
height: 96px;
margin-bottom: 15px;
}
.about-version {
color: var(--text-muted);
font-size: 0.9rem;
margin-top: 5px;
}
.about-description {
font-size: 1.1rem;
margin-bottom: 25px;
line-height: 1.5;
}
.about-authors-section {
text-align: left;
background: rgba(255, 255, 255, 0.05);
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
}
.about-authors-section h3 {
margin-top: 0;
font-size: 1rem;
color: #1f8a46;
}
.about-authors-list {
list-style: none;
padding: 0;
margin: 10px 0 0 0;
}
.about-authors-list li {
margin-bottom: 5px;
font-size: 0.95rem;
}
.btn-primary { .btn-primary {
background-color: #1f8a46; background-color: #1f8a46;
color: white; color: white;

View File

@@ -28,6 +28,7 @@
<button id="dark-btn" class="menu-item" type="button">Velike/male črke (AAaa)</button> <button id="dark-btn" class="menu-item" type="button">Velike/male črke (AAaa)</button>
<button id="split-btn" class="menu-item" type="button">Prelom po kiticah</button> <button id="split-btn" class="menu-item" type="button">Prelom po kiticah</button>
<button id="edit-song-btn" class="menu-item" type="button">Uredi besedilo</button> <button id="edit-song-btn" class="menu-item" type="button">Uredi besedilo</button>
<button id="about-btn" class="menu-item" type="button">O programu</button>
</div> </div>
</div> </div>
</div> </div>
@@ -80,6 +81,27 @@
</div> </div>
</div> </div>
<!-- About Modal -->
<div id="about-modal" class="modal">
<div class="modal-content about-content">
<div class="about-header">
<img src="{{ url_for('static', filename='favicon.svg') }}" alt="Logo" class="about-logo">
<h1 id="about-name">Projekcija</h1>
<p id="about-version" class="about-version"></p>
</div>
<div class="about-body">
<p id="about-description" class="about-description"></p>
<div class="about-authors-section">
<h3>Avtorji:</h3>
<ul id="about-authors" class="about-authors-list"></ul>
</div>
</div>
<div class="modal-footer">
<button id="about-close-btn" class="btn-primary">Zapri</button>
</div>
</div>
</div>
<div class="content"> <div class="content">
<div id="display-area" class="lyrics-display"> <div id="display-area" class="lyrics-display">
<span class="status-message">Pripravljeno. Vpiši številko pesmi ali drugega besedila.</span> <span class="status-message">Pripravljeno. Vpiši številko pesmi ali drugega besedila.</span>