From 90a6a61c6c91a18b2e81e6cd6f721c38aae82e0e Mon Sep 17 00:00:00 2001 From: Seth-Revz Date: Sun, 10 Nov 2024 10:33:40 -0500 Subject: [PATCH] prepare for release build --- .gitignore | 6 +++++- pokatlas.py | 27 ++++++++++++++++++++++----- ui/mainwindow.py | 11 ++++++----- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index d0d1bd1..2901932 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ __pycache__ atlas/ -.venv \ No newline at end of file +.venv + +pokatlas.spec +build/ +dist/ \ No newline at end of file diff --git a/pokatlas.py b/pokatlas.py index 3c09c18..7fca5f3 100644 --- a/pokatlas.py +++ b/pokatlas.py @@ -1,6 +1,7 @@ import hashlib import pathlib import shutil +import sys import zipfile from collections import Counter from textwrap import dedent @@ -116,7 +117,7 @@ def rebuild(atlas: Atlas): canvas.save(output_dir / atlas.img_name) -def export_mod_full(atlas: Atlas): +def export_mod_full(atlas: Atlas, icon_path: pathlib.Path): rebuild(atlas) atlas_dir = atlas.atlas_path.parent @@ -162,7 +163,7 @@ def export_mod_full(atlas: Atlas): """\n""" ) - shutil.copy('ui/icon.png', str(pathlib.Path(mod_dir / 'icon.png'))) + shutil.copy(icon_path, str(pathlib.Path(mod_dir / 'icon.png'))) with zipfile.ZipFile(str(output_dir / 'FullAtlas.mod'), 'w') as zipf: for file_path in mod_dir.rglob('*'): @@ -170,7 +171,7 @@ def export_mod_full(atlas: Atlas): zipf.write(file_path, arcname=file_path.relative_to(mod_dir)) -def export_mod_modified(atlas: Atlas): +def export_mod_modified(atlas: Atlas, icon_path: pathlib.Path): atlas_dir = atlas.atlas_path.parent sprites_dir = atlas_dir / 'sprites' output_dir = atlas.atlas_path.parent / 'output' @@ -235,20 +236,36 @@ def export_mod_modified(atlas: Atlas): """\n""" ) - shutil.copy('ui/icon.png', str(pathlib.Path(mod_dir / 'icon.png'))) + shutil.copy(icon_path, str(pathlib.Path(mod_dir / 'icon.png'))) with zipfile.ZipFile(str(output_dir / 'PartialAtlas.mod'), 'w') as zipf: for file_path in mod_dir.rglob('*'): if file_path.is_file(): zipf.write(file_path, arcname=file_path.relative_to(mod_dir)) +def resource_path(relative: pathlib.Path): + try: + base_path = pathlib.Path(sys._MEIPASS) + except Exception: + base_path = pathlib.Path('.') + + return base_path / relative + if __name__ == '__main__': from ui.mainwindow import MainWindow from PySide6.QtWidgets import QApplication import qdarktheme + try: + from ctypes import windll + windll.shell32.SetCurrentProcessExplicitAppUserModelID('com.revz.pokatlas') + except ImportError: + pass + + icon_path = resource_path(pathlib.Path('ui/icon.png')) + app = QApplication() qdarktheme.setup_theme('dark') - mainwindow = MainWindow() + mainwindow = MainWindow(icon_path=icon_path) mainwindow.show() app.exec() \ No newline at end of file diff --git a/ui/mainwindow.py b/ui/mainwindow.py index 802f582..582b18d 100644 --- a/ui/mainwindow.py +++ b/ui/mainwindow.py @@ -108,19 +108,20 @@ def icon(self, _): return QIcon() class MainWindow(QMainWindow): - def __init__(self): + def __init__(self, icon_path: pathlib.Path): super().__init__() self.atlas_dir = None self.sprites_dir = None self.output_dir = None self.atlas = None + self.icon_path = icon_path self.selected_sprite_filename = None self.setupUI() def setupUI(self): - self.setWindowIcon(QIcon('./ui/icon.png')) + self.setWindowIcon(QIcon(str(self.icon_path))) self.setWindowTitle('Pokatlas') self.setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT) @@ -305,11 +306,11 @@ def saveAtlas(self): def saveFullMod(self): check_duplicates(self.atlas) - export_mod_full(self.atlas) + export_mod_full(self.atlas, self.icon_path) self.openDirectory(self.output_dir) def saveModifiedMod(self): - export_mod_modified(self.atlas) + export_mod_modified(self.atlas, self.icon_path) self.openDirectory(self.output_dir) def searchList(self, text): @@ -372,7 +373,7 @@ def openSpriteFolder(self): def replaceMultipleSprites(self): msgbox = QMessageBox() - msgbox.setWindowIcon(QIcon('./ui/icon.png')) + msgbox.setWindowIcon(QIcon(str(self.icon_path))) msgbox.setWindowTitle('Warning') msgbox.setText('Matching Sprite File Names' + ' '*30) msgbox.setInformativeText('Only files in the selected folder with names matching the dumped sprites will be replaced.')