Basic Job preferences dialog

This commit is contained in:
ml
2016-11-02 10:58:35 +01:00
committed by wmayer
parent 4262094bb6
commit f5f85eba70
6 changed files with 141 additions and 33 deletions
-127
View File
@@ -1,127 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::Dialog::DlgSettingsPath</class>
<widget class="QWidget" name="Gui::Dialog::DlgSettingsPath">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>503</width>
<height>526</height>
</rect>
</property>
<property name="windowTitle">
<string>General Path settings</string>
</property>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>General Path settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="Gui::PrefCheckBox" name="pathTestSetting1">
<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>
</property>
<property name="text">
<string>Automatic project handling</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>pathAutoProject</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Job Output</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Default Post Processor</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Default Arguments</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::PrefLineEdit" name="defaultPostProcessorArgs">
<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>
</property>
<property name="prefEntry" stdset="0">
<cstring>DefaultPostProcessorArgs</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefLineEdit" name="defaultPostProcessor">
<property name="prefEntry" stdset="0">
<cstring>DefaultPostProcessor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Path</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<customwidgets>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
+42 -8
View File
@@ -47,11 +47,14 @@ except AttributeError:
def translate(context, text, disambig=None):
return QtGui.QApplication.translate(context, text, disambig)
class PostProcessor:
class ObjectPathJob:
Default = "PostProcessorDefault"
DefaultArgs = "PostProcessorDefaultArgs"
Blacklist = "PostProcessorBlacklist"
@classmethod
def allPostProcessors(cls):
def all(cls):
path = FreeCAD.getHomePath() + ("Mod/Path/PathScripts/")
posts = glob.glob(path + '/*_post.py')
allposts = [ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts]
@@ -64,6 +67,39 @@ class ObjectPathJob:
allposts.sort()
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):
# 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"))
@@ -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::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.addProperty("App::PropertyString", "PostProcessorArgs", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property", "Arguments for the Post Processor (specific to the script)"))
obj.PostProcessorArgs = ""
@@ -94,12 +130,10 @@ class ObjectPathJob:
obj.Proxy = self
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
defaultPostProcessor = preferences.GetString("DefaultPostProcessor", "")
print("DefaultPostProcessor = '%s'" % defaultPostProcessor)
defaultPostProcessor = PostProcessor.default()
if defaultPostProcessor:
obj.PostProcessor = defaultPostProcessor
obj.PostProcessorArgs = preferences.GetString("DefaultPostProcessorArgs", "")
obj.PostProcessorArgs = PostProcessor.defaultArgs()
if FreeCAD.GuiUp:
ViewProviderJob(obj.ViewObject)
@@ -258,7 +292,7 @@ class TaskPanel:
self.form = FreeCADGui.PySideUic.loadUi(":/panels/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.updating = False
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2014 Yorik van Havre <[email protected]> *
# * *
# * 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())