Material: Editor and import, fix openfile and savefile if no filename is given, make open and save work the same way

This commit is contained in:
Bernd Hahnebach
2018-06-01 08:21:28 +02:00
parent 428e9ea5ed
commit bf11a5f239
2 changed files with 5 additions and 4 deletions

View File

@@ -261,11 +261,12 @@ class MaterialEditor:
def openfile(self):
"Opens a FCMat file"
filename = QtGui.QFileDialog.getOpenFileName(QtGui.QApplication.activeWindow(),'Open FreeCAD Material file','*.FCMat')
filetuple = QtGui.QFileDialog.getOpenFileName(QtGui.QApplication.activeWindow(),'Open FreeCAD Material file','*.FCMat')
filename = filetuple[0] # a tuple of two empty strings returns True, so use the filename directly
if filename:
self.clearEditor()
import importFCMat
d = importFCMat.read(filename[0])
d = importFCMat.read(filename)
if d:
self.updateContents(d)
@@ -275,7 +276,8 @@ class MaterialEditor:
name = str(self.widget.Editor.findItems(translate("Material","Name"),QtCore.Qt.MatchRecursive,0)[0].text(1))
if not name:
name = "Material"
filename = QtGui.QFileDialog.getSaveFileName(QtGui.QApplication.activeWindow(),'Save FreeCAD Material file',name+'.FCMat')
filetuple = QtGui.QFileDialog.getSaveFileName(QtGui.QApplication.activeWindow(),'Save FreeCAD Material file',name+'.FCMat')
filename = filetuple[0] # a tuple of two empty strings returns True, so use the filename directly
if filename:
d = self.getDict()
if d:

View File

@@ -122,7 +122,6 @@ def write(filename,dictionary):
user[k] = i
# write header
rev = FreeCAD.ConfigGet("BuildVersionMajor")+"."+FreeCAD.ConfigGet("BuildVersionMinor")+" "+FreeCAD.ConfigGet("BuildRevision")
filename = filename[0]
if isinstance(filename,unicode):
import sys
filename = filename.encode(sys.getfilesystemencoding())