|
@@ -1,5 +1,3 @@
|
|
|
-#!/usr/bin/env python
|
|
|
-
|
|
|
import copy
|
|
|
import json
|
|
|
import os
|
|
@@ -46,16 +44,18 @@ class MainWindow:
|
|
|
|
|
|
# Constructor
|
|
|
def __init__(self, **kwargs):
|
|
|
+ # initialize window
|
|
|
self.ui = QtWidgets.QMainWindow(**kwargs)
|
|
|
|
|
|
- # Properties
|
|
|
+ # set object properties
|
|
|
self.__project = None
|
|
|
self.__predictions = []
|
|
|
|
|
|
- # UI
|
|
|
+ # load ui from corresponding file
|
|
|
spath = os.path.dirname(__file__)
|
|
|
uic.loadUi(os.path.join(spath, 'MainWindow.ui'), self.ui)
|
|
|
|
|
|
+ # prepare some more ui stuff
|
|
|
self.ui.statusLabel = QtWidgets.QLabel(self.ui)
|
|
|
self.ui.statusBar.addPermanentWidget(self.ui.statusLabel)
|
|
|
|
|
@@ -65,10 +65,10 @@ class MainWindow:
|
|
|
self.ui.timer.setInterval(2000)
|
|
|
self.ui.timer.moveToThread(self.ui.timerThread)
|
|
|
|
|
|
- # Actions
|
|
|
+ # connect actions
|
|
|
# File
|
|
|
self.ui.actionNew.triggered.connect(self._project_new)
|
|
|
- self.ui.actionOpen.triggered.connect(self._project_open)
|
|
|
+ self.ui.actionOpen.triggered.connect(self.project_open)
|
|
|
self.ui.actionClose.triggered.connect(self._project_try_closing)
|
|
|
self.ui.actionSave.triggered.connect(self._project_save)
|
|
|
self.ui.actionQuit.triggered.connect(self._file_quit)
|
|
@@ -159,23 +159,39 @@ class MainWindow:
|
|
|
if w_retval:
|
|
|
self._project = Project(w.project_root, w.project_config)
|
|
|
|
|
|
- def _project_open(self):
|
|
|
+ def project_open(self, path=None):
|
|
|
+ """
|
|
|
+ opens a project by either using the optional parameter path or
|
|
|
+ or the value the user enters using the ui file dialog
|
|
|
+
|
|
|
+ :param path: path to project.json
|
|
|
+ """
|
|
|
+
|
|
|
+ # check if there is an open project with unsaved changes
|
|
|
retval = self._project_try_closing()
|
|
|
- if retval:
|
|
|
- selection = QtWidgets.QFileDialog.getExistingDirectory(self.ui, 'Select Project Folder')
|
|
|
- if len(selection) > 0 and os.path.exists(os.path.join(selection, 'project.json')):
|
|
|
- self._project = Project(selection)
|
|
|
- if self._project.last_error is not None:
|
|
|
- error_string = self._project.last_error
|
|
|
- try:
|
|
|
- QtWidgets.QMessageBox.warning(self.ui, 'Error', 'Error while opening (see log for details): %s'
|
|
|
- % error_string)
|
|
|
- self._project.close()
|
|
|
- except:
|
|
|
- pass
|
|
|
- self._project = None
|
|
|
- elif len(selection) > 0: # Project file does not exist
|
|
|
- QtWidgets.QMessageBox.warning(self.ui, 'Error', 'Could not find project file: %s' % os.path.join(selection, 'project.json'))
|
|
|
+ if not retval:
|
|
|
+ return
|
|
|
+
|
|
|
+ # copy path to selection or question user if not given
|
|
|
+ if path is not None and path != False:
|
|
|
+ selection = path
|
|
|
+ else:
|
|
|
+ selection, _ = QtWidgets.QFileDialog.getOpenFileName(self.ui, 'Select Project Folder', filter='project.json')
|
|
|
+
|
|
|
+ # check if path exists and open project
|
|
|
+ if len(selection) > 0 and os.path.exists(selection):
|
|
|
+ self._project = Project(selection)
|
|
|
+ if self._project.last_error is not None:
|
|
|
+ error_string = self._project.last_error
|
|
|
+ try:
|
|
|
+ QtWidgets.QMessageBox.warning(self.ui, 'Error', 'Error while opening (see log for details): %s'
|
|
|
+ % error_string)
|
|
|
+ self._project.close()
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+ self._project = None
|
|
|
+ elif len(selection) > 0: # Project file does not exist
|
|
|
+ QtWidgets.QMessageBox.warning(self.ui, 'Error', 'Could not find project file: %s' % selection)
|
|
|
|
|
|
def _project_save(self):
|
|
|
self._project.save()
|