Catch file open events before file loaders are loaded

The event is essentially delayed. The filename is put in a list by the event handler. The list of files is then loaded after all plug-ins are loaded.

Contributes to issue CURA-730.
This commit is contained in:
Ghostkeeper 2016-03-01 13:16:57 +01:00
parent 7b9ecd4aba
commit 232713a019

View file

@ -78,8 +78,13 @@ class CuraApplication(QtApplication):
if not hasattr(sys, "frozen"):
Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), ".."))
self._open_file_queue = [] #Files to open when plug-ins are loaded.
super().__init__(name = "cura", version = CuraVersion)
for file_name in self._open_file_queue: #Open all the files that were queued up while plug-ins were loading.
self._openFile(file_name)
self.setWindowIcon(QIcon(Resources.getPath(Resources.Images, "cura-icon.png")))
self.setRequiredPlugins([
@ -148,6 +153,8 @@ class CuraApplication(QtApplication):
if self.getBackend() == None:
raise RuntimeError("Could not load the backend plugin!")
self._plugins_loaded = True
def addCommandLineOptions(self, parser):
super().addCommandLineOptions(parser)
parser.add_argument("file", nargs="*", help="Files to load after starting the application.")
@ -211,8 +218,10 @@ class CuraApplication(QtApplication):
# Handle Qt events
def event(self, event):
if event.type() == QEvent.FileOpen:
Logger.log("i", "File open via Qt event: %s", event.file())
self._openFile(event.file())
if self._plugins_loaded:
self._openFile(event.file())
else:
self._open_file_queue.append(event.file())
return super().event(event)