Skip to content

Commit

Permalink
refactor into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cbusillo committed Jun 12, 2024
1 parent 79408a6 commit 3aec6c5
Show file tree
Hide file tree
Showing 7 changed files with 491 additions and 469 deletions.
471 changes: 2 additions & 469 deletions bd_to_avp/app.py

Large diffs are not rendered by default.

File renamed without changes.
401 changes: 401 additions & 0 deletions bd_to_avp/gui/main_window.py

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions bd_to_avp/gui/processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
from typing import TYPE_CHECKING

from PySide6.QtCore import QObject, QThread, Signal
from PySide6.QtWidgets import QWidget

from bd_to_avp.modules.disc import MKVCreationError
from bd_to_avp.modules.util import OutputHandler, terminate_process
from bd_to_avp.process import process

if TYPE_CHECKING:
from bd_to_avp.gui.main_window import MainWindow


class ProcessingSignals(QObject):
progress_updated = Signal(str)


class ProcessingThread(QThread):
error_occurred = Signal(Exception)
mkv_creation_error = Signal(MKVCreationError)

def __init__(self, main_window: "MainWindow", parent: QWidget | None = None) -> None:
super().__init__(parent)
self.signals = ProcessingSignals()
self.output_handler = OutputHandler(self.signals.progress_updated.emit)
self.main_window = main_window

def run(self) -> None:
sys.stdout = self.output_handler # type: ignore

try:
process()
except MKVCreationError as error:
self.mkv_creation_error.emit(error)
except (RuntimeError, ValueError) as error:
self.error_occurred.emit(error)
finally:
sys.stdout = sys.__stdout__
self.signals.progress_updated.emit("Process Completed.")
self.main_window.process_button.setText(self.main_window.START_PROCESSING_TEXT)

def terminate(self) -> None:
terminate_process()
super().terminate()
31 changes: 31 additions & 0 deletions bd_to_avp/gui/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pathlib import Path

from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication

from bd_to_avp.modules.config import config
from bd_to_avp.modules.util import load_data_from_pyproject


def load_app_info_from_pyproject(app: QApplication) -> None:
pyproject_data = load_data_from_pyproject()
if not pyproject_data:
return

tool = pyproject_data.get("tool", {})
poetry = tool.get("poetry", {})
briefcase = tool.get("briefcase", {})

app.setApplicationName(poetry.get("name"))
app.setOrganizationName(briefcase.get("organization"))
app.setApplicationVersion(config.code_version)
app.setOrganizationDomain(briefcase.get("bundle"))
app.setApplicationDisplayName(briefcase.get("project_name"))

briefcase_icon_path = Path(briefcase.get("icon"))
icon_path = Path(*briefcase_icon_path.parts[1:]).with_suffix(".icns")
icon_absolute_path = Path(__file__).parent / icon_path
app.setWindowIcon(QIcon(icon_absolute_path.as_posix()))

app.setProperty("authors", poetry.get("authors", []))
app.setProperty("url", poetry.get("homepage"))
File renamed without changes.
12 changes: 12 additions & 0 deletions bd_to_avp/modules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import threading
import time
import tomllib

from pathlib import Path
from typing import Any, Callable, Iterable
Expand Down Expand Up @@ -187,3 +188,14 @@ def flush(self) -> None:

def close(self) -> None:
pass


def load_data_from_pyproject() -> dict[str, dict] | None:
project_root = Path(__file__).parent.parent.parent
pyproject_path = project_root / "pyproject.toml"
if not pyproject_path.exists():
return None

with open(pyproject_path, "rb") as pyproject_file:
pyproject_data = tomllib.load(pyproject_file)
return pyproject_data

0 comments on commit 3aec6c5

Please sign in to comment.