Added template selection and preference integration to job creation dialog.
This commit is contained in:
@@ -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_()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user