def loadSettings(self): self.form.leDefaultFilePath.setText(PathPreferences.defaultFilePath()) self.form.leDefaultJobTemplate.setText(PathPreferences.defaultJobTemplate()) blacklist = PathPreferences.postProcessorBlacklist() for processor in PathPreferences.allAvailablePostProcessors(): item = QtGui.QListWidgetItem(processor) if processor in blacklist: item.setCheckState(QtCore.Qt.CheckState.Unchecked) else: item.setCheckState(QtCore.Qt.CheckState.Checked) item.setFlags( QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled | QtCore.Qt.ItemFlag.ItemIsUserCheckable) self.form.postProcessorList.addItem(item) self.verifyAndUpdateDefaultPostProcessorWith(PathPreferences.defaultPostProcessor()) self.form.defaultPostProcessorArgs.setText(PathPreferences.defaultPostProcessorArgs()) geomTol = Units.Quantity(PathPreferences.defaultGeometryTolerance(), Units.Length) self.form.geometryTolerance.setText(geomTol.UserString) self.form.leOutputFile.setText(PathPreferences.defaultOutputFile()) self.selectComboEntry(self.form.cboOutputPolicy, PathPreferences.defaultOutputPolicy()) self.form.tbDefaultFilePath.clicked.connect(self.browseDefaultFilePath) self.form.tbDefaultJobTemplate.clicked.connect(self.browseDefaultJobTemplate) self.form.postProcessorList.itemEntered.connect(self.setProcessorListTooltip) self.form.postProcessorList.itemChanged.connect(self.verifyAndUpdateDefaultPostProcessor) self.form.defaultPostProcessor.currentIndexChanged.connect(self.updateDefaultPostProcessorToolTip) self.form.tbOutputFile.clicked.connect(self.browseOutputFile) self.loadStockSettings()
def loadSettings(self): blacklist = PathPreferences.postProcessorBlacklist() for processor in PathPreferences.allAvailablePostProcessors(): item = QtGui.QListWidgetItem(processor) if processor in blacklist: item.setCheckState(QtCore.Qt.CheckState.Unchecked) else: item.setCheckState(QtCore.Qt.CheckState.Checked) item.setFlags(QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled | QtCore.Qt.ItemFlag.ItemIsUserCheckable) self.form.postProcessorList.addItem(item) self.verifyAndUpdateDefaultPostProcessorWith( PathPreferences.defaultPostProcessor()) self.form.defaultPostProcessorArgs.setText( PathPreferences.defaultPostProcessorArgs()) geomTol = Units.Quantity(PathPreferences.defaultGeometryTolerance(), Units.Length) self.form.geometryTolerance.setText(geomTol.UserString) self.form.leOutputFile.setText(PathPreferences.defaultOutputFile()) self.selectComboEntry(self.form.cboOutputPolicy, PathPreferences.defaultOutputPolicy()) self.form.postProcessorList.itemEntered.connect( self.setProcessorListTooltip) self.form.postProcessorList.itemChanged.connect( self.verifyAndUpdateDefaultPostProcessor) self.form.defaultPostProcessor.currentIndexChanged.connect( self.updateDefaultPostProcessorToolTip) self.form.pbBrowseFileSystem.clicked.connect(self.browseFileSystem)
def resolveFileName(self, job): path = PathPreferences.defaultOutputFile() if job.PostProcessorOutputFile: path = job.PostProcessorOutputFile filename = path if '%D' in filename: D = FreeCAD.ActiveDocument.FileName if D: D = os.path.dirname(D) # in case the document is in the current working directory if not D: D = '.' else: FreeCAD.Console.PrintError("Please save document in order to resolve output path!\n") return None filename = filename.replace('%D', D) if '%d' in filename: d = FreeCAD.ActiveDocument.Label filename = filename.replace('%d', d) if '%j' in filename: j = job.Label filename = filename.replace('%j', j) if '%M' in filename: pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") M = pref.GetString("MacroPath", FreeCAD.getUserAppDataDir()) filename = filename.replace('%M', M) policy = PathPreferences.defaultOutputPolicy() openDialog = policy == 'Open File Dialog' if os.path.isdir(filename) or not os.path.isdir(os.path.dirname(filename)): # Either the entire filename resolves into a directory or the parent directory doesn't exist. # Either way I don't know what to do - ask for help openDialog = True if os.path.isfile(filename) and not openDialog: if policy == 'Open File Dialog on conflict': openDialog = True elif policy == 'Append Unique ID on conflict': fn, ext = os.path.splitext(filename) nr = fn[-3:] n = 1 if nr.isdigit(): n = int(nr) while os.path.isfile("%s%03d%s" % (fn, n, ext)): n = n + 1 filename = "%s%03d%s" % (fn, n, ext) if openDialog: foo = QtGui.QFileDialog.getSaveFileName(QtGui.QApplication.activeWindow(), "Output File", filename) if foo: filename = foo[0] else: filename = None return filename
def resolveFileName(self, job): path = PathPreferences.defaultOutputFile() if job.OutputFile: path = job.OutputFile filename = path if '%D' in filename: D = FreeCAD.ActiveDocument.FileName if D: D = os.path.dirname(D) else: FreeCAD.Console.PrintError( "Please save document in order to resolve output path!\n") return None filename = filename.replace('%D', D) if '%d' in filename: d = FreeCAD.ActiveDocument.Label filename = filename.replace('%d', d) if '%j' in filename: j = job.Label filename = filename.replace('%j', j) if '%M' in filename: pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") M = pref.GetString("MacroPath", FreeCAD.getUserAppDataDir()) filename = filename.replace('%M', M) policy = PathPreferences.defaultOutputPolicy() openDialog = policy == 'Open File Dialog' if os.path.isdir(filename) or not os.path.isdir( os.path.dirname(filename)): # Either the entire filename resolves into a directory or the parent directory doesn't exist. # Either way I don't know what to do - ask for help openDialog = True if os.path.isfile(filename) and not openDialog: if policy == 'Open File Dialog on conflict': openDialog = True elif policy == 'Append Unique ID on conflict': fn, ext = os.path.splitext(filename) nr = fn[-3:] n = 1 if nr.isdigit(): n = int(nr) while os.path.isfile("%s%03d%s" % (fn, n, ext)): n = n + 1 filename = "%s%03d%s" % (fn, n, ext) if openDialog: foo = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(), "Output File", filename) if foo: filename = foo[0] else: filename = None return filename
def resolveFileName(self, job): # print("resolveFileName(%s)" % job.Label) path = PathPreferences.defaultOutputFile() if job.OutputFile: path = job.OutputFile filename = path if "%D" in filename: D = FreeCAD.ActiveDocument.FileName if D: D = os.path.dirname(D) else: FreeCAD.Console.PrintError("Please save document in order to resolve output path!\n") return None filename = filename.replace("%D", D) if "%d" in filename: d = FreeCAD.ActiveDocument.Label filename = filename.replace("%d", d) if "%j" in filename: j = job.Label filename = filename.replace("%j", j) if "%M" in filename: pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") M = pref.GetString("MacroPath", FreeCAD.getUserAppDataDir()) filename = filename.replace("%M", M) policy = PathPreferences.defaultOutputPolicy() openDialog = policy == "Open File Dialog" if os.path.isdir(filename) or not os.path.isdir(os.path.dirname(filename)): # Either the entire filename resolves into a directory or the parent directory doesn't exist. # Either way I don't know what to do - ask for help openDialog = True if os.path.isfile(filename) and not openDialog: if policy == "Open File Dialog on conflict": openDialog = True elif policy == "Append Unique ID on conflict": fn, ext = os.path.splitext(filename) nr = fn[-3:] n = 1 if nr.isdigit(): n = int(nr) while os.path.isfile("%s%03d%s" % (fn, n, ext)): n = n + 1 filename = "%s%03d%s" % (fn, n, ext) if openDialog: foo = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(), "Output File", filename) if foo: filename = foo[0] else: filename = None # print("resolveFileName(%s, %s) -> '%s'" % (path, policy, filename)) return filename
def loadSettings(self): blacklist = PathPreferences.postProcessorBlacklist() for processor in PathPreferences.allAvailablePostProcessors(): item = QtGui.QListWidgetItem(processor) if processor in blacklist: item.setCheckState(QtCore.Qt.CheckState.Unchecked) else: item.setCheckState(QtCore.Qt.CheckState.Checked) item.setFlags( QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled | QtCore.Qt.ItemFlag.ItemIsUserCheckable) self.form.postProcessorList.addItem(item) self.verifyAndUpdateDefaultPostProcessorWith(PathPreferences.defaultPostProcessor()) self.form.defaultPostProcessorArgs.setText(PathPreferences.defaultPostProcessorArgs()) self.form.leOutputFile.setText(PathPreferences.defaultOutputFile()) self.selectComboEntry(self.form.cboOutputPolicy, PathPreferences.defaultOutputPolicy()) self.form.postProcessorList.itemEntered.connect(self.setProcessorListTooltip) self.form.postProcessorList.itemChanged.connect(self.verifyAndUpdateDefaultPostProcessor) self.form.defaultPostProcessor.currentIndexChanged.connect(self.updateDefaultPostProcessorToolTip) self.form.pbBrowseFileSystem.clicked.connect(self.browseFileSystem)