Improvements to the macro
* Translatable texts * Options are hidden by default * Different icon for the 'Private' folder
This commit is contained in:
parent
aa33cccd5f
commit
d67f2271db
1 changed files with 79 additions and 44 deletions
|
@ -77,18 +77,16 @@ import FreeCAD, FreeCADGui, Part, zipfile, tempfile, Mesh, os, subprocess
|
||||||
from PySide import QtGui, QtCore
|
from PySide import QtGui, QtCore
|
||||||
|
|
||||||
param = FreeCAD.ParamGet('User parameter:Plugins/partlib')
|
param = FreeCAD.ParamGet('User parameter:Plugins/partlib')
|
||||||
s=param.GetString('destination')
|
s = param.GetString('destination')
|
||||||
print('User parameter:Plugins/partlib : destination : ',s)
|
#print('User parameter:Plugins/partlib : destination : ',s)
|
||||||
|
|
||||||
if s<>'':
|
if s:
|
||||||
LIBRARYPATH = s
|
LIBRARYPATH = s
|
||||||
else:
|
else:
|
||||||
folderDialog = QtGui.QFileDialog.getExistingDirectory(None,u"Choose folder library")
|
folderDialog = QtGui.QFileDialog.getExistingDirectory(None,QtGui.QApplication.translate("PartsLibrary", "Location of your existing Parts library", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
param.SetString('destination',folderDialog)
|
param.SetString('destination',folderDialog)
|
||||||
s=param.GetString('destination')
|
LIBRARYPATH = param.GetString('destination')
|
||||||
LIBRARYPATH = s
|
|
||||||
|
|
||||||
#global ExpFileSystemModel why this line?
|
|
||||||
class ExpFileSystemModel(QtGui.QFileSystemModel):
|
class ExpFileSystemModel(QtGui.QFileSystemModel):
|
||||||
"a custom QFileSystemModel that displays freecad file icons"
|
"a custom QFileSystemModel that displays freecad file icons"
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -98,6 +96,8 @@ class ExpFileSystemModel(QtGui.QFileSystemModel):
|
||||||
if index.column() == 0 and role == QtCore.Qt.DecorationRole:
|
if index.column() == 0 and role == QtCore.Qt.DecorationRole:
|
||||||
if index.data().lower().endswith('.fcstd'):
|
if index.data().lower().endswith('.fcstd'):
|
||||||
return QtGui.QIcon(':icons/freecad-doc.png')
|
return QtGui.QIcon(':icons/freecad-doc.png')
|
||||||
|
elif index.data().lower() == "private":
|
||||||
|
return QtGui.QIcon.fromTheme("folder-lock")
|
||||||
return super(ExpFileSystemModel, self).data(index, role)
|
return super(ExpFileSystemModel, self).data(index, role)
|
||||||
|
|
||||||
class ExpDockWidget(QtGui.QDockWidget):
|
class ExpDockWidget(QtGui.QDockWidget):
|
||||||
|
@ -107,9 +107,8 @@ class ExpDockWidget(QtGui.QDockWidget):
|
||||||
QtGui.QDockWidget.__init__(self)
|
QtGui.QDockWidget.__init__(self)
|
||||||
|
|
||||||
self.setObjectName("PartsLibrary")
|
self.setObjectName("PartsLibrary")
|
||||||
self.setWindowTitle("Parts Library")
|
|
||||||
|
|
||||||
# setting up a directory model that shows only fcstd and step
|
# setting up a directory model that shows only fcstd, step and brep
|
||||||
self.dirmodel = ExpFileSystemModel()
|
self.dirmodel = ExpFileSystemModel()
|
||||||
self.dirmodel.setRootPath(LIBRARYPATH)
|
self.dirmodel.setRootPath(LIBRARYPATH)
|
||||||
self.dirmodel.setNameFilters(["*.fcstd","*.FcStd","*.FCSTD","*.stp","*.STP","*.step","*.STEP", "*.brp", "*.BRP", "*.brep", "*.BREP"])
|
self.dirmodel.setNameFilters(["*.fcstd","*.FcStd","*.FCSTD","*.stp","*.STP","*.step","*.STEP", "*.brp", "*.BRP", "*.brep", "*.BREP"])
|
||||||
|
@ -125,53 +124,66 @@ class ExpDockWidget(QtGui.QDockWidget):
|
||||||
folder.hideColumn(2)
|
folder.hideColumn(2)
|
||||||
folder.hideColumn(3)
|
folder.hideColumn(3)
|
||||||
folder.setRootIndex(self.dirmodel.index(LIBRARYPATH))
|
folder.setRootIndex(self.dirmodel.index(LIBRARYPATH))
|
||||||
|
|
||||||
self.preview = QtGui.QLabel()
|
self.preview = QtGui.QLabel()
|
||||||
self.preview.setFixedHeight(128)
|
self.preview.setFixedHeight(128)
|
||||||
|
|
||||||
updatebutton = QtGui.QPushButton("Update")
|
self.updatebutton = QtGui.QPushButton()
|
||||||
icon = QtGui.QIcon.fromTheme("edit-redo")
|
icon = QtGui.QIcon.fromTheme("emblem-synchronizing")
|
||||||
updatebutton.setIcon(icon)
|
self.updatebutton.setIcon(icon)
|
||||||
updatebutton.clicked.connect(self.updatelibrary)
|
self.updatebutton.clicked.connect(self.updatelibrary)
|
||||||
|
self.updatebutton.hide()
|
||||||
|
|
||||||
configbutton = QtGui.QPushButton()
|
self.configbutton = QtGui.QPushButton()
|
||||||
icon = QtGui.QIcon.fromTheme("document-properties")
|
icon = QtGui.QIcon.fromTheme("emblem-system")
|
||||||
configbutton.setIcon(icon)
|
self.configbutton.setIcon(icon)
|
||||||
configbutton.clicked.connect(self.setconfig)
|
self.configbutton.clicked.connect(self.setconfig)
|
||||||
|
self.configbutton.hide()
|
||||||
|
|
||||||
formatLabel = QtGui.QLabel("Add to library")
|
self.formatLabel = QtGui.QLabel()
|
||||||
|
self.formatLabel.hide()
|
||||||
|
|
||||||
savebutton = QtGui.QPushButton("Save")
|
self.savebutton = QtGui.QPushButton()
|
||||||
icon = QtGui.QIcon.fromTheme("document-save")
|
icon = QtGui.QIcon.fromTheme("document-save")
|
||||||
savebutton.setIcon(icon)
|
self.savebutton.setIcon(icon)
|
||||||
savebutton.clicked.connect(self.addtolibrary)
|
self.savebutton.clicked.connect(self.addtolibrary)
|
||||||
|
self.savebutton.hide()
|
||||||
|
|
||||||
pushbutton = QtGui.QPushButton("Push")
|
self.pushbutton = QtGui.QPushButton()
|
||||||
icon = QtGui.QIcon.fromTheme("document-export")
|
icon = QtGui.QIcon.fromTheme("document-export")
|
||||||
pushbutton.setIcon(icon)
|
self.pushbutton.setIcon(icon)
|
||||||
pushbutton.clicked.connect(self.pushlibrary)
|
self.pushbutton.clicked.connect(self.pushlibrary)
|
||||||
|
self.pushbutton.hide()
|
||||||
|
|
||||||
fcstdCB = QtGui.QCheckBox('FCStd')
|
self.optbutton = QtGui.QPushButton()
|
||||||
fcstdCB.setCheckState(QtCore.Qt.Checked)
|
self.optbutton.clicked.connect(self.showoptions)
|
||||||
fcstdCB.setEnabled(False)
|
|
||||||
|
self.fcstdCB = QtGui.QCheckBox('FCStd')
|
||||||
|
self.fcstdCB.setCheckState(QtCore.Qt.Checked)
|
||||||
|
self.fcstdCB.setEnabled(False)
|
||||||
|
self.fcstdCB.hide()
|
||||||
self.stepCB = QtGui.QCheckBox('STEP')
|
self.stepCB = QtGui.QCheckBox('STEP')
|
||||||
self.stepCB.setCheckState(QtCore.Qt.Checked)
|
self.stepCB.setCheckState(QtCore.Qt.Checked)
|
||||||
|
self.stepCB.hide()
|
||||||
self.stlCB = QtGui.QCheckBox('STL')
|
self.stlCB = QtGui.QCheckBox('STL')
|
||||||
self.stlCB.setCheckState(QtCore.Qt.Checked)
|
self.stlCB.setCheckState(QtCore.Qt.Checked)
|
||||||
|
self.stlCB.hide()
|
||||||
|
|
||||||
container = QtGui.QWidget()
|
container = QtGui.QWidget()
|
||||||
grid = QtGui.QGridLayout()
|
grid = QtGui.QGridLayout()
|
||||||
grid.setSpacing(10)
|
grid.setSpacing(10)
|
||||||
|
|
||||||
grid.addWidget(updatebutton,0,0,1,2)
|
grid.addWidget(folder,0,0,1,3)
|
||||||
grid.addWidget(configbutton,0,2,1,1)
|
grid.addWidget(self.updatebutton,1,1,1,1)
|
||||||
grid.addWidget(folder,1,0,1,3)
|
grid.addWidget(self.configbutton,1,2,1,1)
|
||||||
grid.addWidget(self.preview,2,0,5,1)
|
grid.addWidget(self.preview,1,0,5,1)
|
||||||
grid.addWidget(formatLabel,2,1,1,2)
|
grid.addWidget(self.formatLabel,2,1,1,2)
|
||||||
grid.addWidget(fcstdCB,3,1,1,2)
|
grid.addWidget(self.fcstdCB,3,1,1,2)
|
||||||
grid.addWidget(self.stepCB,4,1,1,2)
|
grid.addWidget(self.stepCB,4,1,1,2)
|
||||||
grid.addWidget(self.stlCB,5,1,1,2)
|
grid.addWidget(self.stlCB,5,1,1,2)
|
||||||
grid.addWidget(savebutton,6,1,1,1)
|
grid.addWidget(self.savebutton,6,1,1,1)
|
||||||
grid.addWidget(pushbutton,6,2,1,1)
|
grid.addWidget(self.pushbutton,6,2,1,1)
|
||||||
|
grid.addWidget(self.optbutton,6,0,1,1)
|
||||||
|
|
||||||
global repo
|
global repo
|
||||||
repo = None
|
repo = None
|
||||||
|
@ -191,9 +203,19 @@ class ExpDockWidget(QtGui.QDockWidget):
|
||||||
updatebutton.setEnabled(False)
|
updatebutton.setEnabled(False)
|
||||||
configbutton.setEnabled(False)
|
configbutton.setEnabled(False)
|
||||||
pushbutton.setEnabled(False)
|
pushbutton.setEnabled(False)
|
||||||
|
|
||||||
|
self.retranslateUi()
|
||||||
container.setLayout(grid)
|
container.setLayout(grid)
|
||||||
self.setWidget(container)
|
self.setWidget(container)
|
||||||
|
|
||||||
|
def retranslateUi(self):
|
||||||
|
self.setWindowTitle(QtGui.QApplication.translate("PartsLibrary", "PartsLibrary", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.updatebutton.setText(QtGui.QApplication.translate("PartsLibrary", "Update", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.configbutton.setText(QtGui.QApplication.translate("PartsLibrary", "Config", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.formatLabel.setText(QtGui.QApplication.translate("PartsLibrary", "Add to library", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.savebutton.setText(QtGui.QApplication.translate("PartsLibrary", "Save", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.pushbutton.setText(QtGui.QApplication.translate("PartsLibrary", "Push", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
self.optbutton.setText(QtGui.QApplication.translate("PartsLibrary", "Show options >>", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
def clicked(self, index):
|
def clicked(self, index):
|
||||||
path = self.dirmodel.filePath(index)
|
path = self.dirmodel.filePath(index)
|
||||||
|
@ -273,6 +295,19 @@ class ExpDockWidget(QtGui.QDockWidget):
|
||||||
else:
|
else:
|
||||||
d.lineEdit_2.setText(repo.remote().url)
|
d.lineEdit_2.setText(repo.remote().url)
|
||||||
r = d.exec_()
|
r = d.exec_()
|
||||||
|
|
||||||
|
def showoptions(self):
|
||||||
|
controls = [self.updatebutton,self.configbutton,self.formatLabel,
|
||||||
|
self.fcstdCB,self.stepCB,self.stlCB,self.savebutton,self.pushbutton]
|
||||||
|
if self.updatebutton.isVisible():
|
||||||
|
for c in controls:
|
||||||
|
c.hide()
|
||||||
|
self.optbutton.setText(QtGui.QApplication.translate("PartsLibrary", "Show options >>", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
else:
|
||||||
|
for c in controls:
|
||||||
|
c.show()
|
||||||
|
self.optbutton.setText(QtGui.QApplication.translate("PartsLibrary", "Hide options <<", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
|
|
||||||
class ConfigDialog(QtGui.QDialog):
|
class ConfigDialog(QtGui.QDialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -316,14 +351,14 @@ class ConfigDialog(QtGui.QDialog):
|
||||||
QtCore.QMetaObject.connectSlotsByName(self)
|
QtCore.QMetaObject.connectSlotsByName(self)
|
||||||
|
|
||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
self.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
|
self.setWindowTitle(QtGui.QApplication.translate("PartsLibrary", "PartsLibrary", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.groupBox.setTitle(QtGui.QApplication.translate("Dialog", "pull server (where you get your updates from)", None, QtGui.QApplication.UnicodeUTF8))
|
self.groupBox.setTitle(QtGui.QApplication.translate("PartsLibrary", "pull server (where you get your updates from)", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.lineEdit.setToolTip(QtGui.QApplication.translate("Dialog", "Enter the URL of the pull server here", None, QtGui.QApplication.UnicodeUTF8))
|
self.lineEdit.setToolTip(QtGui.QApplication.translate("PartsLibrary", "Enter the URL of the pull server here", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.pushButton.setToolTip(QtGui.QApplication.translate("Dialog", "Use the official FreeCAD-library repository", None, QtGui.QApplication.UnicodeUTF8))
|
self.pushButton.setToolTip(QtGui.QApplication.translate("PartsLibrary", "Use the official FreeCAD-library repository", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.pushButton.setText(QtGui.QApplication.translate("Dialog", "use official", None, QtGui.QApplication.UnicodeUTF8))
|
self.pushButton.setText(QtGui.QApplication.translate("PartsLibrary", "use official", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.groupBox_2.setTitle(QtGui.QApplication.translate("Dialog", "push server (where you push your changes to)", None, QtGui.QApplication.UnicodeUTF8))
|
self.groupBox_2.setTitle(QtGui.QApplication.translate("PartsLibrary", "push server (where you push your changes to)", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.lineEdit_2.setToolTip(QtGui.QApplication.translate("Dialog", "Enter the URL of the push server here", None, QtGui.QApplication.UnicodeUTF8))
|
self.lineEdit_2.setToolTip(QtGui.QApplication.translate("PartsLibrary", "Enter the URL of the push server here", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.label.setText(QtGui.QApplication.translate("Dialog", "Warning: You need write permission on this server", None, QtGui.QApplication.UnicodeUTF8))
|
self.label.setText(QtGui.QApplication.translate("PartsLibrary", "Warning: You need write permission on this server", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
def setdefaulturl(self):
|
def setdefaulturl(self):
|
||||||
self.lineEdit.setText("https://github.com/FreeCAD/FreeCAD-library.git")
|
self.lineEdit.setText("https://github.com/FreeCAD/FreeCAD-library.git")
|
||||||
|
|
Loading…
Add table
Reference in a new issue