Skip to content

Commit

Permalink
AddonManager: Don't overwrite displayed text after a module install/r…
Browse files Browse the repository at this point in the history
…emoval
  • Loading branch information
yorikvanhavre committed Jan 7, 2019
1 parent 1a8d3a7 commit a9f1a0c
Showing 1 changed file with 55 additions and 25 deletions.
80 changes: 55 additions & 25 deletions src/Mod/AddonManager/AddonManager.py
Expand Up @@ -389,7 +389,7 @@ def add_macro(self, macro):
if macro.is_installed(): if macro.is_installed():
self.listMacros.addItem(QtGui.QListWidgetItem(QtGui.QIcon.fromTheme('dialog-ok'), macro.name + str(' (Installed)'))) self.listMacros.addItem(QtGui.QListWidgetItem(QtGui.QIcon.fromTheme('dialog-ok'), macro.name + str(' (Installed)')))
else: else:
self.listMacros.addItem(macro.name) self.listMacros.addItem(" "+macro.name)


def showlink(self,link): def showlink(self,link):
"""opens a link with the system browser""" """opens a link with the system browser"""
Expand Down Expand Up @@ -423,7 +423,7 @@ def install(self,repos=None):
self.labelDescription.setText(translate("AddonsInstaller", "Macro successfully installed. The macro is now available from the Macros dialog.")) self.labelDescription.setText(translate("AddonsInstaller", "Macro successfully installed. The macro is now available from the Macros dialog."))
else: else:
self.labelDescription.setText(translate("AddonsInstaller", "Unable to install")) self.labelDescription.setText(translate("AddonsInstaller", "Unable to install"))
self.update_status() self.update_status(soft=True)


def show_progress_bar(self, state): def show_progress_bar(self, state):
if state == True: if state == True:
Expand Down Expand Up @@ -490,24 +490,53 @@ def remove(self):
self.labelDescription.setText(translate('AddonsInstaller', 'Macro successfully removed.')) self.labelDescription.setText(translate('AddonsInstaller', 'Macro successfully removed.'))
else: else:
self.labelDescription.setText(translate('AddonsInstaller', 'Macro could not be removed.')) self.labelDescription.setText(translate('AddonsInstaller', 'Macro could not be removed.'))
self.update_status() self.update_status(soft=True)

def update_status(self,soft=False):

"Updates the list of wbs/macros. If soft is true, items are not recreated (and therefore display text no triggered)"


def update_status(self):
self.listWorkbenches.clear()
self.listMacros.clear()
moddir = FreeCAD.getUserAppDataDir() + os.sep + "Mod" moddir = FreeCAD.getUserAppDataDir() + os.sep + "Mod"
for wb in self.repos: if soft:
if os.path.exists(os.path.join(moddir,wb[0])): for i in range(self.listWorkbenches.count()):
self.listWorkbenches.addItem(QtGui.QListWidgetItem(QtGui.QIcon.fromTheme("dialog-ok"),str(wb[0]) + str(" (Installed)"))) txt = self.listWorkbenches.item(i).text().strip()
wb[2] = 1 if txt.endswith(" (Installed)"):
else: txt = txt[:-12]
self.listWorkbenches.addItem(" "+str(wb[0])) elif txt.endswith(" (Update available)"):
wb[2] = 0 txt = txt[:-19]
for macro in self.macros: if os.path.exists(os.path.join(moddir,txt)):
if macro.is_installed(): self.listWorkbenches.item(i).setText(txt+" (Installed)")
self.listMacros.addItem(QtGui.QListWidgetItem(QtGui.QIcon.fromTheme('dialog-ok'), macro.name + str(' (Installed)'))) self.listWorkbenches.item(i).setIcon(QtGui.QIcon.fromTheme("dialog-ok"))
else: else:
self.listMacros.addItem(macro.name) self.listWorkbenches.item(i).setText(" "+txt)
self.listWorkbenches.item(i).setIcon(QtGui.QIcon())
for i in range(self.listMacros.count()):
txt = self.listMacros.item(i).text().strip()
if txt.endswith(" (Installed)"):
txt = txt[:-12]
elif txt.endswith(" (Update available)"):
txt = txt[:-19]
if os.path.exists(os.path.join(moddir,txt)):
self.listMacros.item(i).setText(txt+" (Installed)")
self.listMacros.item(i).setIcon(QtGui.QIcon.fromTheme("dialog-ok"))
else:
self.listMacros.item(i).setText(" "+txt)
self.listMacros.item(i).setIcon(QtGui.QIcon())
else:
self.listWorkbenches.clear()
self.listMacros.clear()
for wb in self.repos:
if os.path.exists(os.path.join(moddir,wb[0])):
self.listWorkbenches.addItem(QtGui.QListWidgetItem(QtGui.QIcon.fromTheme("dialog-ok"),str(wb[0]) + str(" (Installed)")))
wb[2] = 1
else:
self.listWorkbenches.addItem(" "+str(wb[0]))
wb[2] = 0
for macro in self.macros:
if macro.is_installed():
self.listMacros.addItem(QtGui.QListWidgetItem(QtGui.QIcon.fromTheme('dialog-ok'), macro.name + str(' (Installed)')))
else:
self.listMacros.addItem(" "+macro.name)


def mark(self,repo): def mark(self,repo):
for i in range(self.listWorkbenches.count()): for i in range(self.listWorkbenches.count()):
Expand Down Expand Up @@ -918,13 +947,14 @@ def run(self):
macro_dir = FreeCAD.getUserMacroDir(True) macro_dir = FreeCAD.getUserMacroDir(True)
if not os.path.exists(macro_dir): if not os.path.exists(macro_dir):
os.makedirs(macro_dir) os.makedirs(macro_dir)
for f in os.listdir(clonedir): if os.path.exists(clonedir):
if f.lower().endswith(".fcmacro"): for f in os.listdir(clonedir):
print("copying macro:",f) if f.lower().endswith(".fcmacro"):
symlink(os.path.join(clonedir, f), os.path.join(macro_dir, f)) print("copying macro:",f)
FreeCAD.ParamGet('User parameter:Plugins/'+self.repos[idx][0]).SetString("destination",clonedir) symlink(os.path.join(clonedir, f), os.path.join(macro_dir, f))
answer += translate("AddonsInstaller", "A macro has been installed and is available the Macros menu") + ": <b>" FreeCAD.ParamGet('User parameter:Plugins/'+self.repos[idx][0]).SetString("destination",clonedir)
answer += f + "</b>" answer += translate("AddonsInstaller", "A macro has been installed and is available the Macros menu") + ": <b>"
answer += f + "</b>"
self.progressbar_show.emit(False) self.progressbar_show.emit(False)
self.info_label.emit(answer) self.info_label.emit(answer)
self.stop = True self.stop = True
Expand Down

0 comments on commit a9f1a0c

Please sign in to comment.