Upgraded macro with update button and git config dialog
This commit is contained in:
parent
8f864e4961
commit
1f024befc0
1 changed files with 145 additions and 28 deletions
|
@ -44,6 +44,32 @@ USAGE
|
|||
|
||||
This macro adds a browser window to the FreeCAD interface, from
|
||||
which you can browse and install items from the library.
|
||||
|
||||
ADVANCED USE
|
||||
|
||||
The update, config, and push buttons all rely on git, and need the
|
||||
python-git package installed. Once that is done, and provided the
|
||||
library is a git repository (ie. you cloned it with git instead of
|
||||
just downloading it), the above mentioned buttons will be enabled.
|
||||
|
||||
The "update" button will simply update your local library with the
|
||||
latest contents from the online repository.
|
||||
|
||||
CONTRIBUTING
|
||||
|
||||
When cloning the official FreeCAD Parts library, you will usually
|
||||
not have write permission to it, and therefore cannot push to it.
|
||||
|
||||
The best way to proceed is, instead of cloning the FreeCAD library
|
||||
directly, to fork it first (for example using the github "fork"
|
||||
button), then clone that foked repo instead, where you will have
|
||||
the correct permissions.
|
||||
|
||||
Once you pushed some contents there, you can make a pull request on
|
||||
the official repo to have it merged.
|
||||
|
||||
If you create a folder named Private in your library, it won't be
|
||||
considered when pushing, so you can place private Parts there.
|
||||
'''
|
||||
|
||||
|
||||
|
@ -62,7 +88,7 @@ else:
|
|||
s=param.GetString('destination')
|
||||
LIBRARYPATH = s
|
||||
|
||||
global ExpFileSystemModel
|
||||
#global ExpFileSystemModel why this line?
|
||||
class ExpFileSystemModel(QtGui.QFileSystemModel):
|
||||
"a custom QFileSystemModel that displays freecad file icons"
|
||||
def __init__(self):
|
||||
|
@ -101,15 +127,29 @@ class ExpDockWidget(QtGui.QDockWidget):
|
|||
folder.setRootIndex(self.dirmodel.index(LIBRARYPATH))
|
||||
self.preview = QtGui.QLabel()
|
||||
self.preview.setFixedHeight(128)
|
||||
|
||||
updatebutton = QtGui.QPushButton("Update")
|
||||
icon = QtGui.QIcon.fromTheme("edit-redo")
|
||||
updatebutton.setIcon(icon)
|
||||
updatebutton.clicked.connect(self.updatelibrary)
|
||||
|
||||
configbutton = QtGui.QPushButton()
|
||||
icon = QtGui.QIcon.fromTheme("document-properties")
|
||||
configbutton.setIcon(icon)
|
||||
configbutton.clicked.connect(self.setconfig)
|
||||
|
||||
formatLabel = QtGui.QLabel("Add to library")
|
||||
|
||||
savebutton = QtGui.QPushButton("Save")
|
||||
icon = QtGui.QIcon.fromTheme("document-save")
|
||||
savebutton.setIcon(icon)
|
||||
savebutton.clicked.connect(self.addtolibrary)
|
||||
|
||||
pushbutton = QtGui.QPushButton("Push")
|
||||
icon = QtGui.QIcon.fromTheme("document-export")
|
||||
pushbutton.setIcon(icon)
|
||||
pushbutton.clicked.connect(self.pushlibrary)
|
||||
|
||||
fcstdCB = QtGui.QCheckBox('FCStd')
|
||||
fcstdCB.setCheckState(QtCore.Qt.Checked)
|
||||
fcstdCB.setEnabled(False)
|
||||
|
@ -122,14 +162,35 @@ class ExpDockWidget(QtGui.QDockWidget):
|
|||
grid = QtGui.QGridLayout()
|
||||
grid.setSpacing(10)
|
||||
|
||||
grid.addWidget(folder,0,0,1,3)
|
||||
grid.addWidget(self.preview,1,0,5,1)
|
||||
grid.addWidget(formatLabel,1,1,1,2)
|
||||
grid.addWidget(fcstdCB,2,1,1,2)
|
||||
grid.addWidget(self.stepCB,3,1,1,2)
|
||||
grid.addWidget(self.stlCB,4,1,1,2)
|
||||
grid.addWidget(savebutton,5,1,1,1)
|
||||
grid.addWidget(pushbutton,5,2,1,1)
|
||||
grid.addWidget(updatebutton,0,0,1,2)
|
||||
grid.addWidget(configbutton,0,2,1,1)
|
||||
grid.addWidget(folder,1,0,1,3)
|
||||
grid.addWidget(self.preview,2,0,5,1)
|
||||
grid.addWidget(formatLabel,2,1,1,2)
|
||||
grid.addWidget(fcstdCB,3,1,1,2)
|
||||
grid.addWidget(self.stepCB,4,1,1,2)
|
||||
grid.addWidget(self.stlCB,5,1,1,2)
|
||||
grid.addWidget(savebutton,6,1,1,1)
|
||||
grid.addWidget(pushbutton,6,2,1,1)
|
||||
|
||||
global repo
|
||||
repo = None
|
||||
try:
|
||||
import git
|
||||
except:
|
||||
FreeCAD.Console.PrintWarning("python-git not found. Git-related functions are disabled\n")
|
||||
try:
|
||||
repo = git.Repo(LIBRARYPATH)
|
||||
except:
|
||||
FreeCAD.Console.PrintError("Your library is not a valid Git repository. Please clone it with git first.\n")
|
||||
return
|
||||
if not repo.remotes:
|
||||
FreeCAD.Console.PrintWarning("No remote repository set.\n")
|
||||
return
|
||||
if not repo:
|
||||
updatebutton.setEnabled(False)
|
||||
configbutton.setEnabled(False)
|
||||
pushbutton.setEnabled(False)
|
||||
|
||||
container.setLayout(grid)
|
||||
self.setWidget(container)
|
||||
|
@ -182,27 +243,10 @@ class ExpDockWidget(QtGui.QDockWidget):
|
|||
Mesh.export(toexport,STLfilename)
|
||||
|
||||
def pushlibrary(self):
|
||||
try:
|
||||
import git
|
||||
except:
|
||||
FreeCAD.Console.PrintError("The Python Git module was not found. Please install the python-git package.\n")
|
||||
return
|
||||
try:
|
||||
repo = git.Repo(LIBRARYPATH)
|
||||
except:
|
||||
FreeCAD.Console.PrintError("Your library is not a valid Git repository. Please fork/clone it first.\n")
|
||||
return
|
||||
pushOK = True
|
||||
if not repo.remotes:
|
||||
FreeCAD.Console.PrintWarning("Arch","Warning: no remote repository set. Unable to push")
|
||||
pushOK = False
|
||||
modified_files = repo.git.diff("--name-only").split()
|
||||
untracked_files = repo.git.ls_files("--other","--exclude-standard").split()
|
||||
import ArchServer
|
||||
d = ArchServer._ArchGitDialog()
|
||||
if not pushOK:
|
||||
d.checkBox.setChecked(False)
|
||||
d.checkBox.setEnabled(False)
|
||||
d.label.setText(str(len(modified_files)+len(untracked_files))+" new and modified file(s)")
|
||||
d.lineEdit.setText("Changed " + str(modified_files))
|
||||
d.checkBox.hide()
|
||||
|
@ -214,8 +258,82 @@ class ExpDockWidget(QtGui.QDockWidget):
|
|||
repo.git.add(o)
|
||||
repo.git.commit(m=d.lineEdit.text())
|
||||
if d.checkBox.isChecked():
|
||||
repo.git.push()
|
||||
repo.git.push()
|
||||
|
||||
def updatelibrary(self):
|
||||
repo.git.pull()
|
||||
|
||||
def setconfig(self):
|
||||
d = ConfigDialog()
|
||||
d.lineEdit.setText(repo.remote().url)
|
||||
if hasattr(repo.remote(),"pushurl"):
|
||||
d.lineEdit_2.setText(repo.remote().pushurl)
|
||||
else:
|
||||
d.lineEdit_2.setText(repo.remote().url)
|
||||
r = d.exec_()
|
||||
|
||||
class ConfigDialog(QtGui.QDialog):
|
||||
def __init__(self):
|
||||
QtGui.QDialog.__init__(self)
|
||||
self.setObjectName("GitConfig")
|
||||
self.resize(318, 202)
|
||||
self.verticalLayout = QtGui.QVBoxLayout(self)
|
||||
self.verticalLayout.setObjectName("verticalLayout")
|
||||
self.groupBox = QtGui.QGroupBox(self)
|
||||
self.groupBox.setObjectName("groupBox")
|
||||
self.horizontalLayout = QtGui.QHBoxLayout(self.groupBox)
|
||||
self.horizontalLayout.setObjectName("horizontalLayout")
|
||||
self.lineEdit = QtGui.QLineEdit(self.groupBox)
|
||||
self.lineEdit.setObjectName("lineEdit")
|
||||
self.horizontalLayout.addWidget(self.lineEdit)
|
||||
self.pushButton = QtGui.QPushButton(self.groupBox)
|
||||
self.pushButton.setObjectName("pushButton")
|
||||
self.horizontalLayout.addWidget(self.pushButton)
|
||||
self.verticalLayout.addWidget(self.groupBox)
|
||||
self.groupBox_2 = QtGui.QGroupBox(self)
|
||||
self.groupBox_2.setObjectName("groupBox_2")
|
||||
self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox_2)
|
||||
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
||||
self.lineEdit_2 = QtGui.QLineEdit(self.groupBox_2)
|
||||
self.lineEdit_2.setObjectName("lineEdit_2")
|
||||
self.verticalLayout_2.addWidget(self.lineEdit_2)
|
||||
self.label = QtGui.QLabel(self.groupBox_2)
|
||||
self.label.setObjectName("label")
|
||||
self.verticalLayout_2.addWidget(self.label)
|
||||
self.verticalLayout.addWidget(self.groupBox_2)
|
||||
self.buttonBox = QtGui.QDialogButtonBox(self)
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
|
||||
self.buttonBox.setObjectName("buttonBox")
|
||||
self.verticalLayout.addWidget(self.buttonBox)
|
||||
|
||||
self.retranslateUi()
|
||||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.accept)
|
||||
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject)
|
||||
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.setdefaulturl)
|
||||
QtCore.QMetaObject.connectSlotsByName(self)
|
||||
|
||||
def retranslateUi(self):
|
||||
self.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.groupBox.setTitle(QtGui.QApplication.translate("Dialog", "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.pushButton.setToolTip(QtGui.QApplication.translate("Dialog", "Use the official FreeCAD-library repository", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.pushButton.setText(QtGui.QApplication.translate("Dialog", "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.lineEdit_2.setToolTip(QtGui.QApplication.translate("Dialog", "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))
|
||||
|
||||
def setdefaulturl(self):
|
||||
self.lineEdit.setText("https://github.com/FreeCAD/FreeCAD-library.git")
|
||||
|
||||
def accept(self):
|
||||
cw = repo.remote().config_writer
|
||||
if self.lineEdit.text():
|
||||
cw.set("url", str(self.lineEdit.text()))
|
||||
if self.lineEdit_2.text():
|
||||
cw.set("pushurl", str(self.lineEdit_2.text()))
|
||||
cw.release()
|
||||
QtGui.QDialog.accept()
|
||||
|
||||
if QtCore.QDir(LIBRARYPATH).exists():
|
||||
m = FreeCADGui.getMainWindow()
|
||||
|
@ -229,4 +347,3 @@ if QtCore.QDir(LIBRARYPATH).exists():
|
|||
m.addDockWidget(QtCore.Qt.RightDockWidgetArea,ExpDockWidget(LIBRARYPATH))
|
||||
else:
|
||||
print "Library path ", LIBRARYPATH, "not found."
|
||||
print "Please set the correct path to your Parts library in the macro script"
|
||||
|
|
Loading…
Add table
Reference in a new issue