Skip to content

Commit

Permalink
Add icon and GitHub actions to build exe
Browse files Browse the repository at this point in the history
  • Loading branch information
yngwi committed Sep 25, 2024
1 parent e523ec4 commit 314c559
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and Release Executable

on:
push:
tags:
- "v*.*.*" # Matches tags like v1.0.0
- "v*.*.*-*" # Matches tags like v1.0.0-beta1

jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Build executable with PyInstaller
run: |
pyinstaller --onefile --windowed --icon=resources/icon.ico --add-data "resources/icon.ico;resources" matricula-convert.py
- name: Create GitHub Release
id: create_release
uses: ncipollo/release-action@v1
with:
tag: ${{ github.ref_name }}
name: ${{ github.ref_name }}
artifacts: dist/matricula-convert.exe
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: ${{ contains(github.ref_name, '-') }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.log
testfiles/
matricula-convert.ini
build/
dist/
File renamed without changes.
20 changes: 14 additions & 6 deletions modules/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import webbrowser

from PySide6.QtCore import QSettings
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import (
QFileDialog,
QHBoxLayout,
Expand All @@ -30,22 +31,29 @@
log = Logger()


def get_root_dir() -> str:
root_dir = os.path.dirname(os.path.abspath(sys.modules["__main__"].__file__))
if not isinstance(root_dir, str):
log.error("Executable directory not found.")
exit(1)
return root_dir


class MainWindow(QWidget):
def __init__(self):
super().__init__()
if getattr(
sys, "frozen", False
): # If the application is bundled using PyInstaller or similar
main_dir = os.path.dirname(sys.executable)
icon_dir = str(sys._MEIPASS)
else:
main_dir = os.path.dirname(
os.path.abspath(sys.modules["__main__"].__file__)
)
if not isinstance(main_dir, str):
log.error("Executable directory not found.")
exit(1)
main_dir = get_root_dir()
icon_dir = main_dir

settings_path = os.path.join(main_dir, "matricula-convert.ini")
icon_path = os.path.join(icon_dir, "resources", "icon.ico")
self.setWindowIcon(QIcon(icon_path))
self.settings = QSettings(settings_path, QSettings.Format.IniFormat)

self.selected_file_path = str(self.settings.value("last_file_path", ""))
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
construct
pandas
pandas-stubs
PySide6
pyinstaller
pypyodbc
PySide6
Binary file added resources/icon.ico
Binary file not shown.

0 comments on commit 314c559

Please sign in to comment.