Add tool table list to UI

This commit is contained in:
Patrick F
2020-04-10 22:10:35 +02:00
parent 034b48f849
commit c94ef27e0d
4 changed files with 313 additions and 105 deletions

View File

@@ -14,95 +14,147 @@
<string>ToolBit Library</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="toolAdd">
<property name="toolTip">
<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>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/list-add.svg</normaloff>:/icons/list-add.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="toolDelete">
<property name="toolTip">
<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>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/list-remove.svg</normaloff>:/icons/list-remove.svg</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<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="toolEnumerate">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Assigne numbers to each Tool Bit according to its current position in the library. The first Tool Bit is assigned the ID 1.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Enumerate</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/button_sort.svg</normaloff>:/icons/button_sort.svg</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QWidget" name="toolTableGroup" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTableView" name="toolTable">
<property name="acceptDrops">
<bool>true</bool>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<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>
<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="QWidget" name="verticalWidget" native="true">
<property name="maximumSize">
<size>
<width>226</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="ToolTable">
<property name="text">
<string>Tool Table</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonRenameToolTable">
<property name="maximumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/edit-edit.svg</normaloff>:/icons/edit-edit.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonAddToolTable">
<property name="maximumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/list-add.svg</normaloff>:/icons/list-add.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="ButtonRemoveToolTable">
<property name="maximumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/list-remove.svg</normaloff>:/icons/list-remove.svg</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="TableList"/>
</item>
</layout>
</widget>
</item>
<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="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>
</layout>
</item>
</layout>
</widget>
@@ -112,7 +164,7 @@
<item>
<widget class="QPushButton" name="addToolController">
<property name="text">
<string>Add Selected as Tool Controllers in the Job</string>
<string>Add Tool Controller(s) to Job</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
@@ -150,7 +202,7 @@
<item>
<widget class="QPushButton" name="libraryOpen">
<property name="text">
<string>Open Table</string>
<string>Open Library</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
@@ -188,6 +240,65 @@
</item>
</layout>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_2">
<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="toolAdd">
<property name="toolTip">
<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>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/list-add.svg</normaloff>:/icons/list-add.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="toolDelete">
<property name="toolTip">
<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>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/list-remove.svg</normaloff>:/icons/list-remove.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="toolEnumerate">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Assigne numbers to each Tool Bit according to its current position in the library. The first Tool Bit is assigned the ID 1.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Enumerate</string>
</property>
<property name="icon">
<iconset resource="../../../../../Gui/Icons/resource.qrc">
<normaloff>:/icons/button_sort.svg</normaloff>:/icons/button_sort.svg</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>

View File

@@ -84,7 +84,6 @@ def allEnabledPostProcessors(include = None):
return l
return enabled
def defaultPostProcessor():
pref = preferences()
return pref.GetString(PostProcessorDefault, "")
@@ -195,7 +194,6 @@ def setPostProcessorDefaults(processor, args, blacklist):
pref.SetString(PostProcessorDefaultArgs, args)
pref.SetString(PostProcessorBlacklist, "%s" % (blacklist))
def setOutputFileDefaults(fileName, policy):
pref = preferences()
pref.SetString(PostProcessorOutputFile, fileName)
@@ -216,6 +214,7 @@ def setDefaultStockTemplate(template):
def defaultTaskPanelLayout():
return preferences().GetInt(DefaultTaskPanelLayout, 0)
def setDefaultTaskPanelLayout(style):
preferences().SetInt(DefaultTaskPanelLayout, style)

View File

@@ -49,7 +49,7 @@ class CommandToolBitLibraryOpen:
lastlib = PathPreferences.lastPathToolLibrary()
if PathPreferences.toolsOpenLastLibrary() and lastlib.endswith('.fctl'):
if PathPreferences.toolsOpenLastLibrary():
library.open(lastlib)
else:
library.open()

View File

@@ -3,6 +3,7 @@
# ***************************************************************************
# * *
# * Copyright (c) 2019 sliptonic <shopinthewoods@gmail.com> *
# * Copyright (c) 2020 Schildkroet *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
@@ -32,11 +33,13 @@ import PathScripts.PathToolBitGui as PathToolBitGui
import PathScripts.PathToolBitEdit as PathToolBitEdit
import PathScripts.PathToolControllerGui as PathToolControllerGui
import PathScripts.PathUtilsGui as PathUtilsGui
from PySide import QtCore, QtGui
import PySide
import json
import os
import traceback
import uuid as UUID
import glob
#PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
#PathLog.trackModule(PathLog.thisModule())
@@ -141,8 +144,11 @@ class ToolBitLibrary(object):
self.form.toolTable.hide()
self.setupUI()
self.title = self.form.windowTitle()
self.LibFiles = []
if path:
self.libraryLoad(path)
self.form.addToolController.setEnabled(False)
def _toolAdd(self, nr, tool, path):
toolNr = PySide.QtGui.QStandardItem()
@@ -210,6 +216,12 @@ class ToolBitLibrary(object):
selectedRows = set([index.row() for index in self.toolTableView.selectedIndexes()])
for row in sorted(list(selectedRows), key = lambda r: -r):
self.model.removeRows(row, 1)
def libraryDelete(self):
PathLog.track()
if len(self.path) > 0:
os.remove(self.path)
self.libraryOpen(False)
def toolEnumerate(self):
PathLog.track()
@@ -225,10 +237,14 @@ class ToolBitLibrary(object):
addTCAllText = translate("PathToolLibraryManager", "Add ALL as Tool Controllers in the Job")
if sel:
self.form.addToolController.setText(addTCSelectedText)
self.form.addToolController.setEnabled(True)
else:
self.form.addToolController.setText(addTCAllText)
self.form.addToolController.setEnabled(False)
def tableSelected(self, index):
''' loads the tools for the selected tool table '''
name = self.form.TableList.itemWidget(self.form.TableList.itemFromIndex(index)).getTableName()
self.libraryLoad(PathPreferences.lastPathToolLibrary() + '/' + name)
def open(self, path=None, dialog=False):
'''open(path=None, dialog=False) ... load library stored in path and bring up ui.
@@ -249,29 +265,50 @@ class ToolBitLibrary(object):
else:
self.form.librarySave.setEnabled(False)
def libraryOpen(self):
def libraryOpen(self, filedialog=True):
PathLog.track()
filename = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl')
if filename and filename[0]:
print(filename)
print(filename[0])
path = filename[0]
PathPreferences.setLastPathToolLibrary(filename[0])
if filedialog:
path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary(), 1)
if len(path) > 0:
PathPreferences.setLastPathToolLibrary(path)
else:
return
else:
path = PathPreferences.lastPathToolLibrary()
if not PathPreferences.toolsOpenLastLibrary():
PathPreferences.setLastPathToolLibrary(os.path.dirname(filename[0]))
#path = os.path.dirname(path)
self.form.TableList.clear()
self.LibFiles.clear()
self.libraryLoad(path)
# Find all tool tables in directory
for file in glob.glob(path + '/*.fctl'):
self.LibFiles.append(file)
self.LibFiles.sort()
for table in self.LibFiles:
listWidgetItem = QtGui.QListWidgetItem()
listItem = ToolTableListWidgetItem()
listItem.setTableName(os.path.basename(table))
listItem.setIcon(QtGui.QPixmap(':/icons/Path-ToolTable.svg'))
#listItem.toolMoved.connect(self.reloadReset)
listWidgetItem.setSizeHint(QtCore.QSize(0,40))
self.form.TableList.addItem(listWidgetItem)
self.form.TableList.setItemWidget(listWidgetItem, listItem)
if len(self.LibFiles) > 0:
self.libraryLoad(self.LibFiles[0])
self.form.TableList.setCurrentRow(0)
def libraryLoad(self, path):
self.toolTableView.setUpdatesEnabled(False)
self.model.clear()
self.model.setHorizontalHeaderLabels(self.columnNames())
if path:
print(f"Path: {path}")
#print(f"Path: {path}")
with open(path) as fp:
library = json.load(fp)
for toolBit in library['tools']:
nr = toolBit['nr']
bit = PathToolBit.findBit(toolBit['path'])
@@ -281,7 +318,9 @@ class ToolBitLibrary(object):
self._toolAdd(nr, tool, bit)
else:
PathLog.error("Could not find tool #{}: {}".format(nr, library['tools'][nr]))
self.toolTableView.resizeColumnsToContents()
self.toolTableView.setUpdatesEnabled(True)
self.form.setWindowTitle("{} - {}".format(self.title, os.path.basename(path) if path else ''))
@@ -290,6 +329,14 @@ class ToolBitLibrary(object):
def libraryNew(self):
self.libraryLoad(None)
self.librarySaveAs()
def renameLibrary(self):
name = self.form.TableList.itemWidget(self.form.TableList.currentItem()).getTableName()
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)
#def createToolBit(self):
# tool = PathToolBit.ToolBitFactory().Create()
@@ -393,8 +440,7 @@ class ToolBitLibrary(object):
self.path = path
self.librarySave()
self.updateToolbar()
self.libraryOpen(False)
def libraryCancel(self):
self.form.close()
@@ -425,6 +471,10 @@ class ToolBitLibrary(object):
self.form.toolEnumerate.clicked.connect(self.toolEnumerate)
# self.form.createToolBit.clicked.connect(self.createToolBit)
self.form.ButtonAddToolTable.clicked.connect(self.libraryNew)
self.form.ButtonRemoveToolTable.clicked.connect(self.libraryDelete)
self.form.ButtonRenameToolTable.clicked.connect(self.renameLibrary)
#self.form.libraryNew.clicked.connect(self.libraryNew)
self.form.libraryOpen.clicked.connect(self.libraryOpen)
self.form.librarySave.clicked.connect(self.librarySave)
@@ -433,6 +483,54 @@ class ToolBitLibrary(object):
self.form.addToolController.clicked.connect(self.selectedOrAllToolControllers)
self.form.TableList.clicked.connect(self.tableSelected)
self.toolSelect([], [])
self.updateToolbar()
PathLog.track('-')
class ToolTableListWidgetItem(QtGui.QWidget):
toolMoved = QtCore.Signal()
def __init__(self):
super(ToolTableListWidgetItem, self).__init__()
#self.tlm = TLM
self.setAcceptDrops(True)
self.mainLayout = QtGui.QHBoxLayout()
self.iconQLabel = QtGui.QLabel()
self.tableNameLabel = QtGui.QLabel()
self.mainLayout.addWidget(self.iconQLabel, 0)
self.mainLayout.addWidget(self.tableNameLabel, 1)
self.setLayout(self.mainLayout)
def setTableName (self, text):
self.tableNameLabel.setText(text)
def getTableName(self):
return self.tableNameLabel.text()
def setIcon (self, icon):
icon = icon.scaled(22, 22)
self.iconQLabel.setPixmap(icon)
def dragEnterEvent(self, e):
#currentToolTable = self.tlm.getCurrentTableName()
thisToolTable = self.getTableName()
#if not currentToolTable == thisToolTable:
# e.accept()
#else:
# e.ignore()
def dropEvent(self, e):
selectedTools = e.source().selectedIndexes()
if selectedTools:
toolData = selectedTools[1].data()
if toolData:
#self.tlm.moveToTable(int(toolData), self.getTableName())
self.toolMoved.emit()