Skip to content

Commit

Permalink
Improved default behaviour and removed output-policy from job settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert authored and wwmayer committed Nov 2, 2016
1 parent 1879103 commit 422ac08
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 83 deletions.
53 changes: 4 additions & 49 deletions src/Mod/Path/Gui/Resources/panels/JobEdit.ui
Expand Up @@ -145,8 +145,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>378</width>
<height>391</height>
<width>353</width>
<height>173</height>
</rect>
</property>
<attribute name="icon">
Expand Down Expand Up @@ -215,8 +215,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>424</width>
<height>376</height>
<width>378</width>
<height>391</height>
</rect>
</property>
<attribute name="icon">
Expand Down Expand Up @@ -263,51 +263,6 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>File Save Policy</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QComboBox" name="cboOutputPolicy">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Choose how to deal with potential file name conflicts. Always open a dialog, only open a dialog if the output file already exists, overwrite any existing file or add a unique (3 digit) sequential ID to the file name.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<item>
<property name="text">
<string></string>
</property>
</item>
<item>
<property name="text">
<string>Open File Dialog</string>
</property>
</item>
<item>
<property name="text">
<string>Open File Dialog on conflict</string>
</property>
</item>
<item>
<property name="text">
<string>Overwrite existing file</string>
</property>
</item>
<item>
<property name="text">
<string>Append Unique ID on conflict</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
33 changes: 7 additions & 26 deletions src/Mod/Path/PathScripts/PathJob.py
Expand Up @@ -48,31 +48,20 @@ def translate(context, text, disambig=None):
def translate(context, text, disambig=None):
return QtGui.QApplication.translate(context, text, disambig)

class OutputPolicy:
Default = ''
Dialog = 'Open File Dialog'
DialogOnConflict = 'Open File Dialog on conflict'
Overwrite = 'Overwrite existing file'
AppendID = 'Append Unique ID on conflict'
All = [Default, Dialog, DialogOnConflict, Overwrite, AppendID]

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"))
obj.OutputFile = ''
obj.OutputFile = PathPreferences.defaultOutputFile()
obj.setEditorMode("OutputFile", 0) # set to default mode
obj.addProperty("App::PropertyEnumeration", "OutputPolicy", "CodeOutput", QtCore.QT_TRANSLATE_NOOP("App::Property","The policy on how to save output files and resolve name conflicts"))
obj.OutputPolicy = OutputPolicy.All
obj.OutputPolicy = OutputPolicy.Default

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 = PathPreferences.allEnabledPostProcessors([''])
obj.PostProcessor = ''
obj.PostProcessor = PathPreferences.defaultPostProcessor()
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 = PathPreferences.defaultPostProcessorArgs()
obj.addProperty("App::PropertyString", "MachineName", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","Name of the Machine that will use the CNC program"))

obj.addProperty("Path::PropertyTooltable", "Tooltable", "Base", QtCore.QT_TRANSLATE_NOOP("App::Property","The tooltable used for this CNC program"))
Expand Down Expand Up @@ -270,16 +259,10 @@ def updateTooltips(self):
def getFields(self):
'''sets properties in the object to match the form'''
if self.obj:
if hasattr(self.obj, "PostProcessor"):
self.obj.PostProcessor = str(self.form.cboPostProcessor.currentText())
if hasattr(self.obj, "PostProcessorArgs"):
self.obj.PostProcessorArgs = str(self.form.cboPostProcessorArgs.displayText())
if hasattr(self.obj, "Label"):
self.obj.Label = str(self.form.leLabel.text())
if hasattr(self.obj, "OutputFile"):
self.obj.OutputFile = str(self.form.leOutputFile.text())
if hasattr(self.obj, "OutputPolicy"):
self.obj.OutputPolicy = str(self.form.cboOutputPolicy.currentText())
self.obj.PostProcessor = str(self.form.cboPostProcessor.currentText())
self.obj.PostProcessorArgs = str(self.form.cboPostProcessorArgs.displayText())
self.obj.Label = str(self.form.leLabel.text())
self.obj.OutputFile = str(self.form.leOutputFile.text())

oldlist = self.obj.Group
newlist = []
Expand Down Expand Up @@ -313,7 +296,6 @@ def setFields(self):

self.form.leLabel.setText(self.obj.Label)
self.form.leOutputFile.setText(self.obj.OutputFile)
self.selectComboBoxText(self.form.cboOutputPolicy, self.obj.OutputPolicy)

self.selectComboBoxText(self.form.cboPostProcessor, self.obj.PostProcessor)
self.obj.Proxy.onChanged(self.obj, "PostProcessor")
Expand Down Expand Up @@ -347,7 +329,6 @@ def setupUi(self):
# Connect Signals and Slots
self.form.cboPostProcessor.currentIndexChanged.connect(self.getFields)
self.form.leOutputFile.editingFinished.connect(self.getFields)
self.form.cboOutputPolicy.currentIndexChanged.connect(self.getFields)
self.form.leLabel.editingFinished.connect(self.getFields)
self.form.btnSelectFile.clicked.connect(self.setFile)
self.form.PathsList.indexesMoved.connect(self.getFields)
Expand Down
16 changes: 8 additions & 8 deletions src/Mod/Path/PathScripts/PathPost.py
Expand Up @@ -45,20 +45,22 @@ class DlgSelectPostProcessor:

def __init__(self, parent=None):
self.dialog = FreeCADGui.PySideUic.loadUi(":/panels/DlgSelectPostProcessor.ui")
firstItem = None
for post in PathPreferences.allEnabledPostProcessors():
item = QtGui.QListWidgetItem(post)
item.setFlags(QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled)
self.dialog.lwPostProcessor.addItem(item)
if not firstItem:
firstItem = item
if firstItem:
self.dialog.lwPostProcessor.setCurrentItem(firstItem)
else:
self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
self.tooltips = {}
self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
self.dialog.lwPostProcessor.itemDoubleClicked.connect(self.dialog.accept)
self.dialog.lwPostProcessor.itemSelectionChanged.connect(self.enableOkButton)
self.dialog.lwPostProcessor.setMouseTracking(True)
self.dialog.lwPostProcessor.itemEntered.connect(self.updateTooltip)

def enableOkButton(self):
self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)

def updateTooltip(self, item):
if item.text() in self.tooltips.keys():
tooltip = self.tooltips[item.text()]
Expand Down Expand Up @@ -104,9 +106,7 @@ def resolveFileName(self, job):
M = pref.GetString("MacroPath", FreeCAD.getUserAppDataDir())
filename = filename.replace('%M', M)

policy = job.OutputPolicy
if not policy or policy == '':
policy = PathPreferences.defaultOutputPolicy()
policy = PathPreferences.defaultOutputPolicy()

openDialog = policy == 'Open File Dialog'
if os.path.isdir(filename) or not os.path.isdir(os.path.dirname(filename)):
Expand Down

0 comments on commit 422ac08

Please sign in to comment.