Feat: Add Status Bar with Progress Bar for Load on Save operations

This commit is contained in:
2025-12-30 21:20:27 +01:00
parent 5a86936e54
commit e624659c90
2 changed files with 59 additions and 14 deletions

View File

@@ -1,10 +1,15 @@
import os
from typing import List
from typing import List, Callable, Optional
from .models import Packet, Page, TeletextService
def load_t42(file_path: str) -> TeletextService:
def load_t42(file_path: str, progress_callback: Optional[Callable[[int, int], None]] = None) -> TeletextService:
service = TeletextService()
total_bytes = os.path.getsize(file_path)
# Each packet is 42 bytes
total_packets = total_bytes // 42
processed_packets = 0
with open(file_path, 'rb') as f:
while True:
chunk = f.read(42)
@@ -13,6 +18,10 @@ def load_t42(file_path: str) -> TeletextService:
if len(chunk) < 42:
# Should not happen in a valid T42 stream, or we just ignore incomplete tail
break
processed_packets += 1
if progress_callback and processed_packets % 100 == 0:
progress_callback(processed_packets, total_packets)
packet = Packet(chunk)
service.all_packets.append(packet)
@@ -114,9 +123,16 @@ def decode_packet_header(b1, b2):
row = (d2 << 1) | ((d1 >> 3) & 1)
return mag, row
def save_t42(file_path: str, service: TeletextService):
def save_t42(file_path: str, service: TeletextService, progress_callback: Optional[Callable[[int, int], None]] = None):
total_packets = len(service.all_packets)
processed = 0
with open(file_path, 'wb') as f:
for packet in service.all_packets:
processed += 1
if progress_callback and processed % 100 == 0:
progress_callback(processed, total_packets)
# Check if we can reuse the original header (preserving parity/integrity)
use_original_header = False