From c121c6c0f72aada21cd7d4be6e02fe083b693e6f Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Fri, 9 Jun 2017 18:49:04 -0700 Subject: [PATCH] Added template selection and preference integration to job creation dialog. --- .../Path/Gui/Resources/panels/DlgJobCreate.ui | 10 ------ src/Mod/Path/PathScripts/PathJob.py | 36 +++++++++++++++++-- src/Mod/Path/PathScripts/PathPreferences.py | 32 ++++++++++++----- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/DlgJobCreate.ui b/src/Mod/Path/Gui/Resources/panels/DlgJobCreate.ui index 98d69bc8a9..6ad723138d 100644 --- a/src/Mod/Path/Gui/Resources/panels/DlgJobCreate.ui +++ b/src/Mod/Path/Gui/Resources/panels/DlgJobCreate.ui @@ -39,16 +39,6 @@ true - - - - - - - - Job.xml - - diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index 3a6192b1fe..454dbc02bc 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -27,7 +27,9 @@ import FreeCAD import Path import PathScripts.PathLog as PathLog import PathScripts.PathToolController as PathToolController +import glob import lxml.etree as xml +import os import sys from PySide import QtCore, QtGui @@ -38,8 +40,8 @@ from PathScripts.PathPreferences import PathPreferences if sys.version_info.major >= 3: xrange = range -LOG_MODULE = PathLog.thisModule() -PathLog.setLevel(PathLog.Level.INFO, LOG_MODULE) +PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) +PathLog.trackModule() FreeCADGui = None if FreeCAD.GuiUp: @@ -314,12 +316,40 @@ class DlgJobCreate: self.dialog.cbModel.addItem(solid.Label) self.dialog.cbModel.setCurrentIndex(index) + templateFiles = [] + for path in PathPreferences.searchPaths(): + templateFiles.extend(self.templateFilesIn(path)) + + template = {} + for tFile in templateFiles: + name = os.path.split(os.path.splitext(tFile)[0])[1][4:] + if name in template: + basename = name + i = 0 + while name in template: + i = i + 1 + name = basename + " (%s)" % i + PathLog.track(name, tFile) + template[name] = tFile + selectTemplate = PathPreferences.defaultJobTemplate() + index = 0 + self.dialog.cbTemplate.addItem('', '') + for name in sorted(template.keys()): + if template[name] == selectTemplate: + index = self.dialog.cbTemplate.count() + self.dialog.cbTemplate.addItem(name, template[name]) + self.dialog.cbTemplate.setCurrentIndex(index) + + def templateFilesIn(self, path): + PathLog.track(path) + return glob.glob(path + '/job_*.xml') + def getModel(self): label = self.dialog.cbModel.currentText() return filter(lambda obj: obj.Label == label, FreeCAD.ActiveDocument.Objects)[0] def getTemplate(self): - return self.dialog.cbTemplate.currentText() + return self.dialog.cbTemplate.itemData(self.dialog.cbTemplate.currentIndex()) def exec_(self): return self.dialog.exec_() diff --git a/src/Mod/Path/PathScripts/PathPreferences.py b/src/Mod/Path/PathScripts/PathPreferences.py index afa448d431..4dbbc01fc4 100644 --- a/src/Mod/Path/PathScripts/PathPreferences.py +++ b/src/Mod/Path/PathScripts/PathPreferences.py @@ -23,9 +23,8 @@ # *************************************************************************** import FreeCAD -import os import glob - +import os import PathScripts.PathLog as PathLog PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) @@ -48,15 +47,16 @@ class PathPreferences: def preferences(cls): return FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path") + @classmethod + def pathScriptsSourcePath(cls): + return FreeCAD.getHomePath() + ("Mod/Path/PathScripts/") + @classmethod def allAvailablePostProcessors(cls): - path = FreeCAD.getHomePath() + ("Mod/Path/PathScripts/") - posts = glob.glob(path + '/*_post.py') + posts = glob.glob(cls.pathScriptsSourcePath() + '/*_post.py') allposts = [ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts] - grp = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") - path = grp.GetString("MacroPath", FreeCAD.getUserAppDataDir()) - posts = glob.glob(path + '/*_post.py') + posts = glob.glob(cls.macroFilePath() + '/*_post.py') allposts.extend([ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts]) allposts.sort() @@ -95,10 +95,24 @@ class PathPreferences: def filePath(cls): path = cls.defaultFilePath() if not path: - grp = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") - path = grp.GetString("MacroPath", FreeCAD.getUserAppDataDir()) + path = cls.macroFilePath() return path + @classmethod + def macroFilePath(cls): + grp = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") + return grp.GetString("MacroPath", FreeCAD.getUserAppDataDir()) + + @classmethod + def searchPaths(cls): + paths = [] + p = cls.defaultFilePath() + if p: + paths.append(p) + paths.append(cls.macroFilePath()) + paths.append(cls.pathScriptsSourcePath()) + return paths + @classmethod def defaultJobTemplate(cls): return cls.preferences().GetString(cls.DefaultJobTemplate)