2025-06-01 12:38:41 -07:00
|
|
|
# Main application file for MacroPad Server
|
2026-01-03 16:57:14 -08:00
|
|
|
# PySide6 version
|
2025-06-01 12:38:41 -07:00
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
2026-01-03 16:57:14 -08:00
|
|
|
import multiprocessing
|
2025-06-01 12:38:41 -07:00
|
|
|
|
|
|
|
|
|
2026-01-03 16:57:14 -08:00
|
|
|
def get_app_dir():
|
2026-01-03 17:12:39 -08:00
|
|
|
"""Get the application directory (where macros.json and macro_images are stored)."""
|
2026-01-03 16:57:14 -08:00
|
|
|
if getattr(sys, 'frozen', False):
|
2026-01-03 17:12:39 -08:00
|
|
|
# Running as compiled executable - use executable's directory for user data
|
2026-01-03 16:57:14 -08:00
|
|
|
return os.path.dirname(sys.executable)
|
|
|
|
|
else:
|
|
|
|
|
# Running as script
|
|
|
|
|
return os.path.dirname(os.path.abspath(__file__))
|
2025-06-01 12:38:41 -07:00
|
|
|
|
|
|
|
|
|
2026-01-03 17:12:39 -08:00
|
|
|
def get_resource_path(relative_path):
|
|
|
|
|
"""Get the path to a bundled resource file."""
|
|
|
|
|
if getattr(sys, 'frozen', False):
|
|
|
|
|
# Running as compiled executable - resources are in _MEIPASS
|
|
|
|
|
base_path = sys._MEIPASS
|
|
|
|
|
else:
|
|
|
|
|
# Running as script - resources are in the script directory
|
|
|
|
|
base_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
return os.path.join(base_path, relative_path)
|
|
|
|
|
|
|
|
|
|
|
2026-01-03 16:57:14 -08:00
|
|
|
def main():
|
|
|
|
|
"""Main entry point."""
|
|
|
|
|
# Required for multiprocessing on Windows
|
|
|
|
|
multiprocessing.freeze_support()
|
2025-06-01 12:38:41 -07:00
|
|
|
|
2026-01-03 17:12:39 -08:00
|
|
|
# Get directories
|
2026-01-03 16:57:14 -08:00
|
|
|
app_dir = get_app_dir()
|
2025-06-01 12:38:41 -07:00
|
|
|
|
2026-01-03 16:57:14 -08:00
|
|
|
# Import PySide6 after freeze_support
|
|
|
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
|
from PySide6.QtCore import Qt
|
|
|
|
|
from PySide6.QtGui import QIcon
|
2025-06-01 12:38:41 -07:00
|
|
|
|
2026-01-03 16:57:14 -08:00
|
|
|
# Create application
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
app.setApplicationName("MacroPad Server")
|
|
|
|
|
app.setOrganizationName("MacroPad")
|
2025-06-01 12:38:41 -07:00
|
|
|
|
2026-01-03 17:12:39 -08:00
|
|
|
# Set application icon (from bundled resources)
|
|
|
|
|
icon_path = get_resource_path("Macro Pad.png")
|
2026-01-03 16:57:14 -08:00
|
|
|
if os.path.exists(icon_path):
|
|
|
|
|
app.setWindowIcon(QIcon(icon_path))
|
2025-06-01 12:38:41 -07:00
|
|
|
|
2026-01-03 16:57:14 -08:00
|
|
|
# Import and create main window
|
|
|
|
|
from gui.main_window import MainWindow
|
|
|
|
|
window = MainWindow(app_dir)
|
|
|
|
|
window.show()
|
2025-06-01 12:38:41 -07:00
|
|
|
|
2026-01-03 16:57:14 -08:00
|
|
|
# Run application
|
|
|
|
|
sys.exit(app.exec())
|
2025-06-01 12:38:41 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-01-03 16:57:14 -08:00
|
|
|
main()
|