feat: LiveSub 2차 — 자막 on/off, 모니터·위치 선택, GPU 저부하, 게임 용어집
이름을 Hearo → LiveSub 로 변경. 말장난보다 하는 일이 바로 보이는 쪽이 낫다. 자막 on/off - 전역 단축키 Ctrl+Alt+S (자막) / Ctrl+Alt+D (번역) — Windows RegisterHotKey + 네이티브 이벤트 필터라 게임 창이 떠 있어도 동작. 다른 OS 에서는 no-op - 단축키·체크박스·우클릭 메뉴가 모두 같은 경로를 타도록 통합 모니터 선택 + 디스코드식 배치 - placement.py: Qt 비의존 배치 계산 (모니터 목록 → 9분할 좌표) - AnchorGrid 위젯으로 3x3 위치 선택, 드래그하면 자유 배치로 전환 - 모니터 구성이 바뀌어도 자막이 화면 밖으로 사라지지 않도록 클램프 GPU 저부하 모드 (기본 켜짐) - 연산 정밀도 int8 강등, VRAM 상한 35%, 추론 후 60ms 양보, 300초 무음 시 모델 언로드, 중간 결과 비활성 - 기본 티어를 균형(6GB) → 신속(4GB) 으로 하향 - 8GB GPU 기준 자막 2.8GB / 게임 5.2GB 게임 용어집 번들 (304개) - 롤 74 · 발로란트 59 · 오버워치2 49 · FPS공통 46 · 마크 38 · 방송 38 - 체크박스로 켜고 끄며, 사용자가 직접 등록한 항목이 항상 우선 검증: pytest 91개 통과 (배치 14 + 팩 12 + UI 6 신규), ruff clean Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -12,10 +12,12 @@ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
from PySide6.QtGui import QImage, QPainter # noqa: E402
|
||||
from PySide6.QtWidgets import QApplication # noqa: E402
|
||||
|
||||
from hearo.config import AppConfig # noqa: E402
|
||||
from hearo.core.events import EngineState, EngineStatus, TranslationLine # noqa: E402
|
||||
from hearo.ui.main_window import MainWindow # noqa: E402
|
||||
from hearo.ui.overlay import paint_subtitle # noqa: E402
|
||||
from livesub.config import AppConfig # noqa: E402
|
||||
from livesub.core.events import EngineState, EngineStatus, TranslationLine # noqa: E402
|
||||
from livesub.models import ModelManager # noqa: E402
|
||||
from livesub.ui.main_window import MainWindow # noqa: E402
|
||||
from livesub.ui.overlay import paint_subtitle # noqa: E402
|
||||
from livesub.ui.placement import ANCHOR_CUSTOM, list_screens, resolve_rect # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@@ -26,7 +28,7 @@ def qapp():
|
||||
|
||||
@pytest.fixture
|
||||
def window(qapp, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr("hearo.constants.user_data_dir", lambda: tmp_path)
|
||||
monkeypatch.setattr("livesub.constants.user_data_dir", lambda: tmp_path)
|
||||
config = AppConfig()
|
||||
config.models.preload_on_start = False
|
||||
config.glossary.path = str(tmp_path / "glossary.json")
|
||||
@@ -79,6 +81,82 @@ def test_subtitle_style_edit_propagates(window):
|
||||
assert window.config.subtitle.font_size == 60
|
||||
|
||||
|
||||
def test_subtitle_toggle_turns_overlay_on_and_off(window):
|
||||
"""자막 on/off — 단축키와 체크박스가 같은 경로를 탄다."""
|
||||
window.config.overlay.visible = True
|
||||
window.overlay.set_subtitle_visible(True)
|
||||
|
||||
window.toggle_subtitle()
|
||||
assert window.config.overlay.visible is False
|
||||
assert window.overlay.isVisible() is False
|
||||
# 체크박스가 따라와야 한다 (시그널 연결 확인)
|
||||
assert window.subtitle_page.overlay_check.isChecked() is False
|
||||
|
||||
window.toggle_subtitle()
|
||||
assert window.config.overlay.visible is True
|
||||
assert window.subtitle_page.overlay_check.isChecked() is True
|
||||
|
||||
|
||||
def test_turning_subtitle_off_clears_leftover_text(window):
|
||||
window.config.log_transcripts = False
|
||||
window.overlay.set_subtitle_visible(True)
|
||||
window._on_line(TranslationLine("hello", "안녕", "en", "ko", is_final=True))
|
||||
assert window.overlay._final_text
|
||||
|
||||
window.toggle_subtitle()
|
||||
assert window.overlay._final_text == ""
|
||||
|
||||
|
||||
def test_checkbox_and_hotkey_do_not_fight_each_other(window):
|
||||
"""체크박스 → 오버레이 → 체크박스 되먹임이 무한루프가 되면 안 된다."""
|
||||
window.config.overlay.visible = True
|
||||
window.overlay.set_subtitle_visible(True)
|
||||
window.subtitle_page.overlay_check.setChecked(False)
|
||||
assert window.config.overlay.visible is False
|
||||
assert window.overlay.isVisible() is False
|
||||
|
||||
|
||||
def test_anchor_selection_moves_the_overlay(window):
|
||||
window.subtitle_page._on_anchor_selected("top-left")
|
||||
assert window.config.overlay.anchor == "top-left"
|
||||
|
||||
screens = list_screens()
|
||||
if screens: # offscreen 플랫폼에도 가상 화면이 하나 있다
|
||||
expected = resolve_rect(
|
||||
screens[0], "top-left",
|
||||
window.config.overlay.width, window.config.overlay.height,
|
||||
window.config.overlay.margin,
|
||||
)
|
||||
assert (window.config.overlay.x, window.config.overlay.y) == expected[:2]
|
||||
|
||||
|
||||
def test_dragging_switches_to_custom_placement(window):
|
||||
window.subtitle_page._on_anchor_selected("bottom-center")
|
||||
assert window.config.overlay.anchor == "bottom-center"
|
||||
|
||||
window.overlay.move(123, 456)
|
||||
window.overlay._drag_from = window.overlay.pos()
|
||||
window.overlay.mouseReleaseEvent(None)
|
||||
assert window.config.overlay.anchor == ANCHOR_CUSTOM
|
||||
|
||||
|
||||
def test_glossary_packs_reach_the_engine(window):
|
||||
window.config.glossary.enabled_packs = ["lol"]
|
||||
window._on_glossary_changed()
|
||||
_, repl = window.engine.glossary.protect("the Nexus", "ko")
|
||||
assert repl == ["넥서스"]
|
||||
|
||||
|
||||
def test_game_mode_lowers_precision(window):
|
||||
window.config.performance.game_mode = True
|
||||
manager = ModelManager(window.config.models, low_power=True)
|
||||
assert "int8" in manager.effective_asr_spec().compute_type
|
||||
assert manager.effective_asr_spec().beam_size == 1
|
||||
|
||||
normal = ModelManager(window.config.models, low_power=False)
|
||||
assert normal.effective_asr_spec() == normal.tier.asr
|
||||
|
||||
|
||||
def test_paint_subtitle_actually_draws_pixels(qapp):
|
||||
"""자막 글씨가 투명 이미지 위에 실제로 그려지는지 (빈 화면이면 실패).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user