Basic Job preferences dialog

This commit is contained in:
ml 2016-10-23 14:02:15 -07:00 committed by wmayer
parent 4262094bb6
commit f5f85eba70
6 changed files with 141 additions and 33 deletions

View File

@ -52,7 +52,6 @@ SET(PathScripts_SRCS
PathScripts/PathComment.py PathScripts/PathComment.py
PathScripts/PathStop.py PathScripts/PathStop.py
PathScripts/PathFromShape.py PathScripts/PathFromShape.py
PathScripts/DlgSettingsPath.ui
PathScripts/PathKurveUtils.py PathScripts/PathKurveUtils.py
PathScripts/PathAreaUtils.py PathScripts/PathAreaUtils.py
PathScripts/slic3r_pre.py PathScripts/slic3r_pre.py
@ -68,6 +67,7 @@ SET(PathScripts_SRCS
PathScripts/PathSanity.py PathScripts/PathSanity.py
PathScripts/PathToolLibraryManager.py PathScripts/PathToolLibraryManager.py
PathScripts/DogboneDressup.py PathScripts/DogboneDressup.py
PathScripts/PathPreferencesPathJob.py
) )
SET(PathScripts_NC_SRCS SET(PathScripts_NC_SRCS

View File

@ -86,5 +86,6 @@
<file>panels/ContourEdit.ui</file> <file>panels/ContourEdit.ui</file>
<file>panels/ProfileEdgesEdit.ui</file> <file>panels/ProfileEdgesEdit.ui</file>
<file>panels/DogboneEdit.ui</file> <file>panels/DogboneEdit.ui</file>
<file>preferences/PathJob.ui</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>General Path settings</string> <string>Job Preferences</string>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<property name="spacing"> <property name="spacing">
@ -29,7 +29,7 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_12"> <layout class="QHBoxLayout" name="horizontalLayout_12">
<item> <item>
<widget class="Gui::PrefCheckBox" name="pathTestSetting1"> <widget class="QCheckBox" name="pathTestSetting1">
<property name="toolTip"> <property name="toolTip">
<string>If this option is enabled, new paths will automatically be placed in the active project, which will be created if necessary.</string> <string>If this option is enabled, new paths will automatically be placed in the active project, which will be created if necessary.</string>
</property> </property>
@ -55,25 +55,38 @@
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Job Output</string> <string>Post Processor</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<item row="0" column="0"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Default Post Processor</string> <string>Default Post Processor</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="1" column="1">
<widget class="QComboBox" name="defaultPostProcessor">
<property name="prefEntry" stdset="0">
<string>DefaultPostProcessor</string>
</property>
<property name="prefPath" stdset="0">
<string>Mod/Path</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Default Arguments</string> <string>Default Arguments</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="3" column="1">
<widget class="Gui::PrefLineEdit" name="defaultPostProcessorArgs"> <widget class="QLineEdit" name="defaultPostProcessorArgs">
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Optional arguments passed to the default Post Processor specified above. See the Post Processor's documentation for supported arguments.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Optional arguments passed to the default Post Processor specified above. See the Post Processor's documentation for supported arguments.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
@ -85,16 +98,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="0">
<widget class="Gui::PrefLineEdit" name="defaultPostProcessor"> <widget class="QLabel" name="label_3">
<property name="prefEntry" stdset="0"> <property name="text">
<cstring>DefaultPostProcessor</cstring> <string>Enabled Post Processors </string>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QListWidget" name="postProcessorList"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -115,13 +128,6 @@
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction> <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<customwidgets>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -70,6 +70,7 @@ class PathWorkbench (Workbench):
from PathScripts import PathContour from PathScripts import PathContour
from PathScripts import PathProfileEdges from PathScripts import PathProfileEdges
from PathScripts import DogboneDressup from PathScripts import DogboneDressup
from PathScripts import PathPreferencesPathJob
import PathCommands import PathCommands
# build commands list # build commands list
@ -115,9 +116,7 @@ class PathWorkbench (Workbench):
self.appendMenu([translate("Path", "&Path")], extracmdlist) self.appendMenu([translate("Path", "&Path")], extracmdlist)
# Add preferences pages # Add preferences pages
import os FreeCADGui.addPreferencePage(PathPreferencesPathJob.Page, "Path")
FreeCADGui.addPreferencePage(FreeCAD.getHomePath(
) + os.sep + "Mod" + os.sep + "Path" + os.sep + "PathScripts" + os.sep + "DlgSettingsPath.ui", "Path")
Log('Loading Path workbench... done\n') Log('Loading Path workbench... done\n')

View File

@ -47,11 +47,14 @@ except AttributeError:
def translate(context, text, disambig=None): def translate(context, text, disambig=None):
return QtGui.QApplication.translate(context, text, disambig) return QtGui.QApplication.translate(context, text, disambig)
class PostProcessor:
class ObjectPathJob: Default = "PostProcessorDefault"
DefaultArgs = "PostProcessorDefaultArgs"
Blacklist = "PostProcessorBlacklist"
@classmethod @classmethod
def allPostProcessors(cls): def all(cls):
path = FreeCAD.getHomePath() + ("Mod/Path/PathScripts/") path = FreeCAD.getHomePath() + ("Mod/Path/PathScripts/")
posts = glob.glob(path + '/*_post.py') posts = glob.glob(path + '/*_post.py')
allposts = [ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts] allposts = [ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts]
@ -64,6 +67,39 @@ class ObjectPathJob:
allposts.sort() allposts.sort()
return allposts return allposts
@classmethod
def allEnabled(cls):
blacklist = cls.blacklist()
return [processor for processor in cls.all() if not processor in blacklist]
@classmethod
def default(cls):
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
return preferences.GetString(cls.Default, "")
@classmethod
def defaultArgs(cls):
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
return preferences.GetString(cls.DefaultArgs, "")
@classmethod
def blacklist(cls):
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
blacklist = preferences.GetString(cls.Blacklist, "")
if not blacklist:
return []
return eval(blacklist)
@classmethod
def saveDefaults(cls, processor, args, blacklist):
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
preferences.SetString(cls.Default, processor)
preferences.SetString(cls.DefaultArgs, args)
preferences.SetString(cls.Blacklist, "%s" % (blacklist))
class ObjectPathJob:
def __init__(self, obj): def __init__(self, obj):
# obj.addProperty("App::PropertyFile", "PostProcessor", "CodeOutput", "Select the Post Processor file for this project") # obj.addProperty("App::PropertyFile", "PostProcessor", "CodeOutput", "Select the Post Processor file for this project")
obj.addProperty("App::PropertyFile", "OutputFile", "CodeOutput", QtCore.QT_TRANSLATE_NOOP("App::Property","The NC output file for this project")) obj.addProperty("App::PropertyFile", "OutputFile", "CodeOutput", QtCore.QT_TRANSLATE_NOOP("App::Property","The NC output file for this project"))
@ -71,7 +107,7 @@ class ObjectPathJob:
obj.addProperty("App::PropertyString", "Description", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","An optional description for this job")) obj.addProperty("App::PropertyString", "Description", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","An optional description for this job"))
obj.addProperty("App::PropertyEnumeration", "PostProcessor", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","Select the Post Processor")) obj.addProperty("App::PropertyEnumeration", "PostProcessor", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","Select the Post Processor"))
obj.PostProcessor = self.allPostProcessors() obj.PostProcessor = PostProcessor.allEnabled()
obj.PostProcessor = 'dumper' obj.PostProcessor = 'dumper'
obj.addProperty("App::PropertyString", "PostProcessorArgs", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property", "Arguments for the Post Processor (specific to the script)")) obj.addProperty("App::PropertyString", "PostProcessorArgs", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property", "Arguments for the Post Processor (specific to the script)"))
obj.PostProcessorArgs = "" obj.PostProcessorArgs = ""
@ -94,12 +130,10 @@ class ObjectPathJob:
obj.Proxy = self obj.Proxy = self
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path") defaultPostProcessor = PostProcessor.default()
defaultPostProcessor = preferences.GetString("DefaultPostProcessor", "")
print("DefaultPostProcessor = '%s'" % defaultPostProcessor)
if defaultPostProcessor: if defaultPostProcessor:
obj.PostProcessor = defaultPostProcessor obj.PostProcessor = defaultPostProcessor
obj.PostProcessorArgs = preferences.GetString("DefaultPostProcessorArgs", "") obj.PostProcessorArgs = PostProcessor.defaultArgs()
if FreeCAD.GuiUp: if FreeCAD.GuiUp:
ViewProviderJob(obj.ViewObject) ViewProviderJob(obj.ViewObject)
@ -258,7 +292,7 @@ class TaskPanel:
self.form = FreeCADGui.PySideUic.loadUi(":/panels/JobEdit.ui") self.form = FreeCADGui.PySideUic.loadUi(":/panels/JobEdit.ui")
#self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/JobEdit.ui") #self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/JobEdit.ui")
for post in ObjectPathJob.allPostProcessors(): for post in PostProcessor.allEnabled():
self.form.cboPostProcessor.addItem(post) self.form.cboPostProcessor.addItem(post)
self.updating = False self.updating = False

View File

@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2014 Yorik van Havre <yorik@uncreated.net> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import FreeCADGui
from PySide import QtCore, QtGui
from PathScripts import PathJob
class Page:
def __init__(self, parent=None):
self.form = FreeCADGui.PySideUic.loadUi(":preferences/PathJob.ui")
def saveSettings(self):
print("saveSettings")
processor = str(self.form.defaultPostProcessor.currentText())
args = str(self.form.defaultPostProcessorArgs.text())
blacklist = []
for i in range(0, self.form.postProcessorList.count()):
item = self.form.postProcessorList.item(i)
if item.checkState() == QtCore.Qt.CheckState.Unchecked:
blacklist.append(item.text())
PathJob.PostProcessor.saveDefaults(processor, args, blacklist)
def loadSettings(self):
print("loadSettings")
self.form.defaultPostProcessor.addItem("")
blacklist = PathJob.PostProcessor.blacklist()
for processor in PathJob.PostProcessor.all():
self.form.defaultPostProcessor.addItem(processor)
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)
postindex = self.form.defaultPostProcessor.findText(PathJob.PostProcessor.default(), QtCore.Qt.MatchFixedString)
if postindex >= 0:
self.form.defaultPostProcessor.blockSignals(True)
self.form.defaultPostProcessor.setCurrentIndex(postindex)
self.form.defaultPostProcessor.blockSignals(False)
self.form.defaultPostProcessorArgs.setText(PathJob.PostProcessor.defaultArgs())