Trying to fix opening files in MacOS.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9ab61a9c0f
commit
6682b75df3
2 changed files with 61 additions and 1 deletions
|
@ -44,7 +44,7 @@ if path.realpath(path.join(getcwd(), "..")) not in sys_path:
|
||||||
sys_path.append(path.realpath(path.join(getcwd(), "..")))
|
sys_path.append(path.realpath(path.join(getcwd(), "..")))
|
||||||
|
|
||||||
|
|
||||||
from LogarithmPlotter import config, __VERSION__
|
from LogarithmPlotter import config, native, __VERSION__
|
||||||
from LogarithmPlotter.update import check_for_updates
|
from LogarithmPlotter.update import check_for_updates
|
||||||
config.init()
|
config.init()
|
||||||
|
|
||||||
|
@ -165,6 +165,13 @@ def run():
|
||||||
app.setApplicationName("LogarithmPlotter")
|
app.setApplicationName("LogarithmPlotter")
|
||||||
app.setOrganizationName("Ad5001")
|
app.setOrganizationName("Ad5001")
|
||||||
app.setWindowIcon(QIcon(path.realpath(path.join(getcwd(), "logarithmplotter.svg"))))
|
app.setWindowIcon(QIcon(path.realpath(path.join(getcwd(), "logarithmplotter.svg"))))
|
||||||
|
|
||||||
|
# Installing macOS file handler.
|
||||||
|
macOSFileOpenHandler = None
|
||||||
|
if platform == "darwin":
|
||||||
|
macOSFileOpenHandler = native.MacOSFileOpenHandler()
|
||||||
|
app.installEventFilter(macOSFileOpenHandler)
|
||||||
|
|
||||||
engine = QQmlApplicationEngine()
|
engine = QQmlApplicationEngine()
|
||||||
helper = Helper()
|
helper = Helper()
|
||||||
engine.rootContext().setContextProperty("Helper", helper)
|
engine.rootContext().setContextProperty("Helper", helper)
|
||||||
|
@ -183,6 +190,9 @@ def run():
|
||||||
print("No root object")
|
print("No root object")
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
|
if platform == "darwin":
|
||||||
|
macOSFileOpenHandler.init_graphics(engine.rootObjects()[0])
|
||||||
|
|
||||||
# Check for updates
|
# Check for updates
|
||||||
if config.getSetting("check_for_updates"):
|
if config.getSetting("check_for_updates"):
|
||||||
check_for_updates(__VERSION__, engine.rootObjects()[0])
|
check_for_updates(__VERSION__, engine.rootObjects()[0])
|
||||||
|
|
50
LogarithmPlotter/native.py
Normal file
50
LogarithmPlotter/native.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
"""
|
||||||
|
* LogarithmPlotter - Create graphs with logarithm scales.
|
||||||
|
* Copyright (C) 2021 Ad5001
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# This file contains stuff for native interactions with each OS.
|
||||||
|
|
||||||
|
from PySide2.QtCore import QObject, QEvent
|
||||||
|
|
||||||
|
# On macOS, opening a file through finder can only be fetched through the
|
||||||
|
# QFileOpenEvent and NOT throught command line parameters.
|
||||||
|
class MacOSFileOpenHandler(QObject):
|
||||||
|
def __init__(self):
|
||||||
|
self.initilized = False
|
||||||
|
self.mainwindow = None
|
||||||
|
self.opened_file = ""
|
||||||
|
QObject.__init__(self)
|
||||||
|
|
||||||
|
def init_graphics(self, mainwindow):
|
||||||
|
self.mainwindow = mainwindow
|
||||||
|
self.initilized = True
|
||||||
|
if self.opened_file != "":
|
||||||
|
self.open_file()
|
||||||
|
|
||||||
|
def open_file(self):
|
||||||
|
self.mainwindow.loadDiagram(self.opened_file)
|
||||||
|
|
||||||
|
def eventFilter(self, obj, event):
|
||||||
|
if event.type() == QEvent.FileOpen:
|
||||||
|
print("Got file", event.file(), self.initilized)
|
||||||
|
self.opened_file = event.file()
|
||||||
|
if self.initilized:
|
||||||
|
self.open_file()
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
# standard event processing
|
||||||
|
return QObject.eventFilter(self, obj, event)
|
Loading…
Reference in a new issue