prelom strani glede na split_by_stanza nastavitev #3
This commit is contained in:
42
projector.py
42
projector.py
@@ -336,17 +336,21 @@ class SongProjector:
|
|||||||
max_height = self.screen_height * 0.85
|
max_height = self.screen_height * 0.85
|
||||||
|
|
||||||
# 1. Razdelimo na kitice (stanzas)
|
# 1. Razdelimo na kitice (stanzas)
|
||||||
# Kitice so ločene z eno ali več praznimi vrsticami
|
# Kitice so ločene z dvojno prazno vrstico (\n\n\n ali \n\s*\n\s*\n)
|
||||||
import re
|
import re
|
||||||
stanzas_raw = re.split(r'\n\s*\n', lyrics.strip())
|
# Razdelimo po vsaj dveh praznih vrsticah (trije ali več \n)
|
||||||
|
stanzas_raw = re.split(r'\n\s*\n\s*\n+', lyrics.strip())
|
||||||
|
|
||||||
processed_stanzas = []
|
processed_stanzas = []
|
||||||
for stanza in stanzas_raw:
|
for stanza in stanzas_raw:
|
||||||
|
# Znotraj kitice ohranimo enojne prazne vrstice kot razmike
|
||||||
lines = stanza.splitlines()
|
lines = stanza.splitlines()
|
||||||
stanza_lines = []
|
stanza_lines = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.strip():
|
if line.strip():
|
||||||
stanza_lines.extend(self.split_long_line(line))
|
stanza_lines.extend(self.split_long_line(line))
|
||||||
|
else:
|
||||||
|
stanza_lines.append("") # Enojna prazna vrstica znotraj kitice
|
||||||
if stanza_lines:
|
if stanza_lines:
|
||||||
processed_stanzas.append(stanza_lines)
|
processed_stanzas.append(stanza_lines)
|
||||||
|
|
||||||
@@ -354,19 +358,43 @@ class SongProjector:
|
|||||||
pages = []
|
pages = []
|
||||||
current_page_lines = []
|
current_page_lines = []
|
||||||
current_height = 0
|
current_height = 0
|
||||||
|
split_by_stanza = self.settings.get("split_by_stanza", False)
|
||||||
|
|
||||||
for stanza in processed_stanzas:
|
for stanza in processed_stanzas:
|
||||||
stanza_height = len(stanza) * self.line_height
|
stanza_height = len(stanza) * self.line_height
|
||||||
|
|
||||||
# Če kitica sama po sebi presega max_height, jo moramo razdeliti
|
# Če je vklopljen split_by_stanza, vsaka kitica dobi svojo stran
|
||||||
if stanza_height > max_height:
|
if split_by_stanza:
|
||||||
# Če imamo že kaj na strani, to zaključimo
|
if current_page_lines:
|
||||||
|
pages.append("\n".join(current_page_lines))
|
||||||
|
current_page_lines = []
|
||||||
|
current_height = 0
|
||||||
|
|
||||||
|
# Če je kitica predolga za eno stran, jo še vedno moramo razdeliti
|
||||||
|
if stanza_height > max_height:
|
||||||
|
temp_stanza_lines = []
|
||||||
|
temp_height = 0
|
||||||
|
for line in stanza:
|
||||||
|
if temp_height + self.line_height > max_height:
|
||||||
|
pages.append("\n".join(temp_stanza_lines))
|
||||||
|
temp_stanza_lines = [line]
|
||||||
|
temp_height = self.line_height
|
||||||
|
else:
|
||||||
|
temp_stanza_lines.append(line)
|
||||||
|
temp_height += self.line_height
|
||||||
|
if temp_stanza_lines:
|
||||||
|
pages.append("\n".join(temp_stanza_lines))
|
||||||
|
else:
|
||||||
|
pages.append("\n".join(stanza))
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Standardna logika (več kitic na stran, če grejo)
|
||||||
|
if stanza_height > max_height:
|
||||||
if current_page_lines:
|
if current_page_lines:
|
||||||
pages.append("\n".join(current_page_lines))
|
pages.append("\n".join(current_page_lines))
|
||||||
current_page_lines = []
|
current_page_lines = []
|
||||||
current_height = 0
|
current_height = 0
|
||||||
|
|
||||||
# Razdelimo predolgo kitico na več strani
|
|
||||||
temp_stanza_lines = []
|
temp_stanza_lines = []
|
||||||
temp_height = 0
|
temp_height = 0
|
||||||
for line in stanza:
|
for line in stanza:
|
||||||
@@ -381,13 +409,11 @@ class SongProjector:
|
|||||||
current_page_lines = temp_stanza_lines
|
current_page_lines = temp_stanza_lines
|
||||||
current_height = temp_height
|
current_height = temp_height
|
||||||
|
|
||||||
# Če kitica ne gre več na trenutno stran
|
|
||||||
elif current_height + stanza_height + (self.line_height if current_page_lines else 0) > max_height:
|
elif current_height + stanza_height + (self.line_height if current_page_lines else 0) > max_height:
|
||||||
pages.append("\n".join(current_page_lines))
|
pages.append("\n".join(current_page_lines))
|
||||||
current_page_lines = stanza
|
current_page_lines = stanza
|
||||||
current_height = stanza_height
|
current_height = stanza_height
|
||||||
|
|
||||||
# Kitica gre na trenutno stran
|
|
||||||
else:
|
else:
|
||||||
if current_page_lines:
|
if current_page_lines:
|
||||||
current_page_lines.append("") # Razmik med kiticami
|
current_page_lines.append("") # Razmik med kiticami
|
||||||
|
|||||||
Reference in New Issue
Block a user