Skip to content

Commit

Permalink
AddonManager: Allow to restart FreeCAD directly from the addon manage…
Browse files Browse the repository at this point in the history
…r after installing/updating addons
  • Loading branch information
yorikvanhavre committed May 21, 2019
1 parent abb253a commit 2a9bd6d
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/Mod/AddonManager/AddonManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
NOGIT = False # for debugging purposes, set this to True to always use http downloads

MACROS_BLACKLIST = ["BOLTS","WorkFeatures","how to install","PartsLibrary","FCGear"]
OBSOLETE = ["assembly2"]
OBSOLETE = ["assembly2","drawing_dimensioning","cura_engine"] # These addons will print an additional message informing the user

if sys.version_info.major < 3:
import StringIO as io
Expand All @@ -69,8 +69,9 @@


def symlink(source, link_name):
if os.path.exists(link_name):
print("macro already exists")
if os.path.exists(link_name) or os.path.lexists(link_name):
#print("macro already exists")
pass
else:
os_symlink = getattr(os, "symlink", None)
if callable(os_symlink):
Expand All @@ -84,7 +85,6 @@ def symlink(source, link_name):
# set the SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag
# (see https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/#joC5tFKhdXs2gGml.97)
flags += 2

if csl(link_name, source, flags) == 0:
raise ctypes.WinError()

Expand Down Expand Up @@ -297,7 +297,19 @@ def reject(self):
oktoclose = False
if oktoclose:
if hasattr(self,"install_worker"):
QtGui.QMessageBox.information(self, translate("AddonsInstaller","Addon manager"), translate("AddonsInstaller","Please restart FreeCAD for changes to take effect."))
m = QtGui.QMessageBox()
m.setWindowTitle(translate("AddonsInstaller","Addon manager"))
m.setText(translate("AddonsInstaller","You must restart FreeCAD for changes to take effect. Press Ok to restart FreeCAD now, or Cancel to restart later."))
m.setIcon(m.Warning)
m.setStandardButtons(m.Ok | m.Cancel)
m.setDefaultButton(m.Cancel)
ret = m.exec()
if ret == m.Ok:
shutil.rmtree(self.macro_repo_dir,onerror=self.remove_readonly)
# restart FreeCAD - https://richardstechnotes.com/2014/06/28/restarting-a-qt-app-programmatically/
args = QtGui.QApplication.arguments()[1:]
QtCore.QProcess.startDetached(QtGui.QApplication.applicationFilePath(),args)
QtCore.QCoreApplication.quit()
shutil.rmtree(self.macro_repo_dir,onerror=self.remove_readonly)
QtGui.QDialog.reject(self)

Expand All @@ -306,6 +318,7 @@ def retranslateUi(self):
self.labelDescription.setText(translate("AddonsInstaller", "Downloading addon list..."))
self.buttonExecute.setText(translate("AddonsInstaller", "Execute"))
self.buttonExecute.setToolTip(translate("AddonsInstaller", "This button runs the selected macro (which must be installed first)"))
self.buttonCheck.setText(translate("AddonsInstaller", "Check"))
self.buttonCheck.setToolTip(translate("AddonsInstaller", "Check for available updates"))
self.buttonCancel.setText(translate("AddonsInstaller", "Close"))
self.buttonInstall.setText(translate("AddonsInstaller", "Install / update"))
Expand All @@ -332,6 +345,7 @@ def check_updates(self):
self.check_worker.mark.connect(self.mark)
self.check_worker.info_label.connect(self.set_information_label)
self.check_worker.progressbar_show.connect(self.show_progress_bar)
self.check_worker.change_button.connect(self.change_update_button)
self.check_worker.start()
else:
self.install(self.doUpdate)
Expand Down Expand Up @@ -550,6 +564,14 @@ def mark(self,repo):
if not repo in self.doUpdate:
self.doUpdate.append(repo)

def change_update_button(self):
self.buttonCheck.setText(translate("AddonsInstaller", "Update all"))
self.buttonCheck.setToolTip(translate("AddonsInstaller", "Apply all available updates"))





class UpdateWorker(QtCore.QThread):

info_label = QtCore.Signal(str)
Expand Down Expand Up @@ -640,6 +662,7 @@ class CheckWBWorker(QtCore.QThread):
info_label = QtCore.Signal(str)
mark = QtCore.Signal(str)
progressbar_show = QtCore.Signal(bool)
change_button = QtCore.Signal()

def __init__(self,repos):
QtCore.QThread.__init__(self)
Expand Down Expand Up @@ -688,6 +711,7 @@ def run(self):
self.progressbar_show.emit(False)
if upds:
self.info_label.emit(str(len(upds))+" "+translate("AddonsInstaller", "update(s) available")+": "+",".join(upds)+". "+translate("AddonsInstaller","Press the update button again to update them all at once."))
self.change_button.emit()
else:
self.info_label.emit(translate("AddonsInstaller","Everything is up to date"))
self.stop = True
Expand Down

0 comments on commit 2a9bd6d

Please sign in to comment.