Rearranged UI and improved library handling

This commit is contained in:
Patrick Felixberger
2020-04-21 23:01:17 +02:00
parent dc54f08020
commit 5df3bd337e
4 changed files with 170 additions and 132 deletions

View File

@@ -63,7 +63,7 @@
<item>
<widget class="QLabel" name="ToolTable">
<property name="text">
<string>Tool Table</string>
<string>Tool Tables</string>
</property>
</widget>
</item>
@@ -130,100 +130,145 @@
</layout>
</item>
<item>
<widget class="QListWidget" name="TableList"/>
<widget class="QListWidget" name="TableList">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTableView" name="toolTable">
<property name="acceptDrops">
<bool>true</bool>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Table of Tool Bits of the library.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
<item>
<widget class="QTableView" name="toolTable">
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Table of Tool Bits of the library.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="midLineWidth">
<number>0</number>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="addToolController">
<property name="text">
<string>Add Tool(s) to Job</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/edit_OK.svg</normaloff>:/icons/edit_OK.svg</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>140</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="libraryCancel">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Close the Tool Bit Library Editor&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Cancel</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/button_invalid.svg</normaloff>:/icons/button_invalid.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="librarySave">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save the current Library&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Save Table</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/document-save.svg</normaloff>:/icons/document-save.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="librarySaveAs">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save the library to a new file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Save Table As...</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/document-save-as.svg</normaloff>:/icons/document-save-as.svg</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addToolController">
<property name="text">
<string>Add Tool Controller(s) to Job</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/edit_OK.svg</normaloff>:/icons/edit_OK.svg</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>14</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="libraryCancel">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Close the Tool Bit Library Editor&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Cancel</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/button_invalid.svg</normaloff>:/icons/button_invalid.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="libraryOpen">
<property name="text">
@@ -235,38 +280,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="librarySave">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save the current Library&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Save Table</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/document-save.svg</normaloff>:/icons/document-save.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="librarySaveAs">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save the library to a new file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Save Table As...</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/document-save-as.svg</normaloff>:/icons/document-save-as.svg</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
@@ -286,7 +299,7 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add another Tool Bit to this library.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Add Toolbit ...</string>
<string>Add Toolbit</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
@@ -300,7 +313,7 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Delete selected Tool Bit(s) from the library.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Remove Selected</string>
<string>Remove</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">

View File

@@ -44,6 +44,7 @@ PostProcessorOutputPolicy = "PostProcessorOutputPolicy"
LastPathToolBit = "LastPathToolBit"
LastPathToolLibrary = "LastPathToolLibrary"
LastPathToolShape = "LastPathToolShape"
LastPathToolTable ="LastPathToolTable"
UseLegacyTools = "UseLegacyTools"
UseAbsoluteToolPaths = "UseAbsoluteToolPaths"
@@ -209,6 +210,7 @@ def defaultOutputPolicy():
def defaultStockTemplate():
return preferences().GetString(DefaultStockTemplate, "")
def setDefaultStockTemplate(template):
preferences().SetString(DefaultStockTemplate, template)
@@ -223,16 +225,24 @@ def experimentalFeaturesEnabled():
def lastPathToolBit():
return preferences().GetString(LastPathToolBit, pathDefaultToolsPath('Bit'))
def setLastPathToolBit(path):
return preferences().SetString(LastPathToolBit, path)
def lastPathToolLibrary():
return preferences().GetString(LastPathToolLibrary, pathDefaultToolsPath('Library'))
def setLastPathToolLibrary(path):
return preferences().SetString(LastPathToolLibrary, path)
def lastPathToolShape():
return preferences().GetString(LastPathToolShape, pathDefaultToolsPath('Shape'))
def setLastPathToolShape(path):
return preferences().SetString(LastPathToolShape, path)
def lastPathToolTable():
return preferences().GetString(LastPathToolTable, "")
def setLastPathToolTable(table):
return preferences().SetString(LastPathToolTable, table)

View File

@@ -91,7 +91,7 @@ class CommandToolBitLibraryLoad:
library = PathToolBitLibraryGui.ToolBitLibrary()
if 1 == library.open(dialog=True) and job:
if 1 == library.open() and job:
for nr, tool in library.selectedOrAllTools():
tc = PathToolControllerGui.Create("TC: {}".format(tool.Label), tool, nr)
job.Proxy.addToolController(tc)

View File

@@ -224,7 +224,8 @@ class ToolBitLibrary(object):
reply = QtGui.QMessageBox.question(self.form, 'Warning', "Delete " + os.path.basename(self.path) + "?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
if reply == QtGui.QMessageBox.Yes and len(self.path) > 0:
os.remove(self.path)
self.libraryOpen(False)
PathPreferences.setLastPathToolTable("")
self.libraryOpen(filedialog=False)
def toolEnumerate(self):
PathLog.track()
@@ -252,9 +253,11 @@ class ToolBitLibrary(object):
'''open(path=None, dialog=False) ... load library stored in path and bring up ui.
Returns 1 if user pressed OK, 0 otherwise.'''
if path:
self.libraryOpen(False)
self.libraryOpen(path, filedialog=False)
elif dialog:
self.libraryOpen()
self.libraryOpen(None, True)
else:
self.libraryOpen(None, False)
return self.form.exec_()
def updateToolbar(self):
@@ -263,22 +266,23 @@ class ToolBitLibrary(object):
else:
self.form.librarySave.setEnabled(False)
def libraryOpen(self, filedialog=True):
def libraryOpen(self, path = None, filedialog=True):
import glob
PathLog.track()
if filedialog:
path = PathPreferences.lastPathToolLibrary()
if filedialog or len(path) == 0:
path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary(), 1)
#p = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
if len(path) > 0:
PathPreferences.setLastPathToolLibrary(path)
else:
return
else:
path = PathPreferences.lastPathToolLibrary()
self.form.TableList.clear()
self.LibFiles.clear()
# Find all tool tables in directory
for file in glob.glob(path + '/*.fctl'):
self.LibFiles.append(file)
@@ -304,10 +308,17 @@ class ToolBitLibrary(object):
self.model.setHorizontalHeaderLabels(self.columnNames())
self.toolTableView.resizeColumnsToContents()
self.toolTableView.setUpdatesEnabled(True)
if len(self.LibFiles) > 0:
self.libraryLoad(self.LibFiles[0])
self.form.TableList.setCurrentRow(0)
for idx in range(len(self.LibFiles)):
if PathPreferences.lastPathToolTable() == os.path.basename(self.LibFiles[idx]):
break
if idx >= len(self.LibFiles):
idx = 0
self.libraryLoad(self.LibFiles[idx])
self.form.TableList.setCurrentRow(idx)
self.form.ButtonRemoveToolTable.setEnabled(True)
self.form.ButtonRenameToolTable.setEnabled(True)
@@ -318,6 +329,7 @@ class ToolBitLibrary(object):
if path:
with open(path) as fp:
PathPreferences.setLastPathToolTable(os.path.basename(path))
library = json.load(fp)
for toolBit in library['tools']:
@@ -333,6 +345,8 @@ class ToolBitLibrary(object):
self.toolTableView.resizeColumnsToContents()
self.toolTableView.setUpdatesEnabled(True)
#PathPreferences.setLastPathToolLibrary(path)
self.form.setWindowTitle("{} - {}".format(self.title, os.path.basename(path) if path else ''))
self.path = path
@@ -347,7 +361,7 @@ class ToolBitLibrary(object):
newName, ok = QtGui.QInputDialog.getText(None, translate("TooltableEditor","Rename Tooltable"),translate("TooltableEditor","Enter Name:"),QtGui.QLineEdit.Normal,name)
if ok and newName:
os.rename(PathPreferences.lastPathToolLibrary() + '/' + name, PathPreferences.lastPathToolLibrary() + '/' + newName)
self.libraryOpen(False)
self.libraryOpen(filedialog=False)
#def createToolBit(self):
# tool = PathToolBit.ToolBitFactory().Create()
@@ -437,7 +451,7 @@ class ToolBitLibrary(object):
filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \
translate("TooltableEditor", "Save toolbit library", None), \
None, "{};;{}".format(TooltableTypeJSON, \
PathPreferences.lastPathToolLibrary(), "{};;{}".format(TooltableTypeJSON, \
TooltableTypeLinuxCNC))
# filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \
# 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
@@ -451,7 +465,8 @@ class ToolBitLibrary(object):
self.path = path
self.librarySave()
self.updateToolbar()
self.libraryOpen(False)
PathPreferences.setLastPathToolTable(os.path.basename(path))
self.libraryOpen(None, False)
def libraryCancel(self):
self.form.close()
@@ -487,7 +502,7 @@ class ToolBitLibrary(object):
self.form.ButtonRenameToolTable.clicked.connect(self.renameLibrary)
#self.form.libraryNew.clicked.connect(self.libraryNew)
self.form.libraryOpen.clicked.connect(partial(self.libraryOpen, True))
self.form.libraryOpen.clicked.connect(partial(self.libraryOpen, filedialog=True))
self.form.librarySave.clicked.connect(self.librarySave)
self.form.librarySaveAs.clicked.connect(self.librarySaveAs)
self.form.libraryCancel.clicked.connect(self.libraryCancel)