Fixed crash after creating a new project on commandline

This commit is contained in:
tassaron 2017-06-23 07:42:46 -04:00
commit f8628333af
1 changed files with 14 additions and 4 deletions

View File

@ -212,6 +212,8 @@ class MainWindow(QtGui.QMainWindow):
window.show() window.show()
if project and project != self.autosavePath: if project and project != self.autosavePath:
if not project.endswith('.avp'):
project += '.avp'
# open a project from the commandline # open a project from the commandline
if not os.path.dirname(project): if not os.path.dirname(project):
project = os.path.join(os.path.expanduser('~'), project) project = os.path.join(os.path.expanduser('~'), project)
@ -350,8 +352,15 @@ class MainWindow(QtGui.QMainWindow):
return False return False
def saveProjectChanges(self): def saveProjectChanges(self):
os.remove(self.currentProject) try:
os.rename(self.autosavePath, self.currentProject) os.remove(self.currentProject)
os.rename(self.autosavePath, self.currentProject)
return True
except (FileNotFoundError, IsADirectoryError) as e:
self.showMessage(
msg='Project file couldn\'t be saved.',
detail=str(e))
return False
def openInputFileDialog(self): def openInputFileDialog(self):
inputDir = self.settings.value("inputDir", os.path.expanduser("~")) inputDir = self.settings.value("inputDir", os.path.expanduser("~"))
@ -592,6 +601,7 @@ class MainWindow(QtGui.QMainWindow):
self.openSaveProjectDialog() self.openSaveProjectDialog()
def openSaveChangesDialog(self, phrase): def openSaveChangesDialog(self, phrase):
success = True
if self.autosaveExists(identical=False): if self.autosaveExists(identical=False):
ch = self.showMessage( ch = self.showMessage(
msg="You have unsaved changes in project '%s'. " msg="You have unsaved changes in project '%s'. "
@ -600,9 +610,9 @@ class MainWindow(QtGui.QMainWindow):
phrase), phrase),
showCancel=True) showCancel=True)
if ch: if ch:
self.saveProjectChanges() success = self.saveProjectChanges()
if os.path.exists(self.autosavePath): if success and os.path.exists(self.autosavePath):
os.remove(self.autosavePath) os.remove(self.autosavePath)
def openSaveProjectDialog(self): def openSaveProjectDialog(self):