file association fixes macOS
This commit is contained in:
@@ -28,7 +28,7 @@ from PySide6.QtWidgets import (
|
||||
QApplication, QWidget, QMessageBox, QVBoxLayout, QHBoxLayout, QTextEdit, QScrollArea, QComboBox, QGridLayout, QSplitter, QDialogButtonBox, QHeaderView,
|
||||
QPushButton, QMainWindow, QLabel, QLineEdit, QGroupBox, QDialog, QMenu, QSpinBox, QTableWidget, QTableWidgetItem
|
||||
)
|
||||
from PySide6.QtCore import Signal, Qt, QTimer
|
||||
from PySide6.QtCore import QEvent, Signal, Qt, QTimer
|
||||
from PySide6.QtGui import QAction, QFontMetrics, QKeySequence, QIcon
|
||||
from PySide6.QtSvgWidgets import QSvgWidget # needed to show svgs when app is not frozen
|
||||
|
||||
@@ -488,7 +488,26 @@ class GroupAssignmentDialog(QDialog):
|
||||
return mappings
|
||||
|
||||
|
||||
|
||||
class CustomApplication(QApplication):
|
||||
"""
|
||||
macOS delivers a file-open request (double-clicking a registered
|
||||
file, or dropping one on the Dock icon — whether the app is already
|
||||
running or being launched fresh) as an Apple Event, which Qt exposes
|
||||
as QEvent.Type.FileOpen. Windows/Linux never send this; they pass
|
||||
the path as a normal argv argument, which startup_args.initial_file
|
||||
already handles. Without this override, double-clicking a project
|
||||
file on macOS launches the app but it never learns which file to open.
|
||||
"""
|
||||
file_open_requested = Signal(str)
|
||||
|
||||
def event(self, e: QEvent) -> bool:
|
||||
if e.type() == QEvent.Type.FileOpen:
|
||||
self.file_open_requested.emit(e.file())
|
||||
return True
|
||||
return super().event(e)
|
||||
|
||||
|
||||
|
||||
class MainApplication(QMainWindow):
|
||||
"""
|
||||
@@ -1334,7 +1353,6 @@ class MainApplication(QMainWindow):
|
||||
def apply_splitter_ratios(self):
|
||||
"""Applies saved ratio positions to main_h_splitter and left_v_splitter."""
|
||||
if hasattr(self, 'main_h_splitter'):
|
||||
print("Splitter actual width:", self.main_h_splitter.width())
|
||||
total_width = self.main_h_splitter.width()
|
||||
if total_width > 0:
|
||||
left_w = int(total_width * self.main_h_ratio)
|
||||
@@ -2648,11 +2666,12 @@ if __name__ == "__main__":
|
||||
|
||||
# Only run GUI in the main process
|
||||
if current_process().name == 'MainProcess':
|
||||
app = QApplication(sys.argv)
|
||||
app = CustomApplication(sys.argv)
|
||||
finish_update_if_needed(PLATFORM_NAME, APP_NAME, cfg_path, startup_args.finish_update)
|
||||
icon_ext = "icns" if PLATFORM_NAME == "darwin" else "ico"
|
||||
app.setWindowIcon(QIcon(resource_path(f"icons/main.{icon_ext}")))
|
||||
window = MainApplication(file_to_open=startup_args.initial_file)
|
||||
app.file_open_requested.connect(window.project_manager.load_project)
|
||||
window.setWindowIcon(QIcon(resource_path(f"icons/main.{icon_ext}")))
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
|
||||
Reference in New Issue
Block a user