def enable_clicked(self) -> None: self.repo.enable() self.set_disable_button_state() self.update_status.emit(self.repo) self.ui.labelWarningInfo.show() self.ui.labelWarningInfo.setText("<h3>" + translate( "AddonsInstaller", "This Addon will be enabled next time you restart FreeCAD.") + "</h3>") self.ui.labelWarningInfo.setStyleSheet("color:" + utils.bright_color_string())
def enable_clicked(self) -> None: """Called by the Enable button, enables this Addon and updates GUI to reflect that status.""" self.repo.enable() self.repo.set_status(Addon.Status.PENDING_RESTART) self.set_disable_button_state() self.update_status.emit(self.repo) self.ui.labelWarningInfo.show() self.ui.labelWarningInfo.setText("<h3>" + translate( "AddonsInstaller", "This Addon will be enabled next time you restart FreeCAD.", ) + "</h3>") self.ui.labelWarningInfo.setStyleSheet("color:" + utils.bright_color_string())
def display_repo_status(self, status): repo = self.repo self.set_change_branch_button_state() if status != AddonManagerRepo.UpdateStatus.NOT_INSTALLED: version = repo.installed_version date = "" installed_version_string = "<h3>" if repo.updated_timestamp: date = (QDateTime.fromTime_t( repo.updated_timestamp).date().toString( Qt.SystemLocaleShortDate)) if version and date: installed_version_string += ( translate("AddonsInstaller", "Version {version} installed on {date}").format( version=version, date=date) + ". ") elif version: installed_version_string += (translate( "AddonsInstaller", "Version {version} installed") + ". ").format(version=version) elif date: installed_version_string += ( translate("AddonsInstaller", "Installed on {date}") + ". ").format(date=date) else: installed_version_string += ( translate("AddonsInstaller", "Installed") + ". ") if status == AddonManagerRepo.UpdateStatus.UPDATE_AVAILABLE: if repo.metadata: installed_version_string += ("<b>" + translate( "AddonsInstaller", "On branch {}, update available to version", ).format(repo.branch) + " ") installed_version_string += repo.metadata.Version installed_version_string += ".</b>" elif repo.macro and repo.macro.version: installed_version_string += ("<b>" + translate( "AddonsInstaller", "Update available to version") + " ") installed_version_string += repo.macro.version installed_version_string += ".</b>" else: installed_version_string += ("<b>" + translate( "AddonsInstaller", "An update is available", ) + ".</b>") elif status == AddonManagerRepo.UpdateStatus.NO_UPDATE_AVAILABLE: detached_head = False branch = repo.branch if have_git and repo.repo_type != AddonManagerRepo.RepoType.MACRO: basedir = FreeCAD.getUserAppDataDir() moddir = os.path.join(basedir, "Mod", repo.name) if os.path.exists(os.path.join(moddir, ".git")): gitrepo = git.Repo(moddir) branch = gitrepo.head.ref.name detached_head = gitrepo.head.is_detached if detached_head: installed_version_string += (translate( "AddonsInstaller", "Git tag '{}' checked out, no updates possible", ).format(branch) + ".") else: installed_version_string += (translate( "AddonsInstaller", "This is the latest version available for branch {}", ).format(branch) + ".") elif status == AddonManagerRepo.UpdateStatus.PENDING_RESTART: installed_version_string += ( translate("AddonsInstaller", "Updated, please restart FreeCAD to use") + ".") elif status == AddonManagerRepo.UpdateStatus.UNCHECKED: pref = FreeCAD.ParamGet( "User parameter:BaseApp/Preferences/Addons") autocheck = pref.GetBool("AutoCheck", False) if autocheck: installed_version_string += (translate( "AddonsInstaller", "Update check in progress") + ".") else: installed_version_string += ( translate("AddonsInstaller", "Automatic update checks disabled") + ".") installed_version_string += "</h3>" self.ui.labelPackageDetails.setText(installed_version_string) if repo.status() == AddonManagerRepo.UpdateStatus.UPDATE_AVAILABLE: self.ui.labelPackageDetails.setStyleSheet( "color:" + utils.attention_color_string()) else: self.ui.labelPackageDetails.setStyleSheet( "color:" + utils.bright_color_string()) self.ui.labelPackageDetails.show() if repo.macro is not None: moddir = FreeCAD.getUserMacroDir(True) else: basedir = FreeCAD.getUserAppDataDir() moddir = os.path.join(basedir, "Mod", repo.name) installationLocationString = ( translate("AddonsInstaller", "Installation location") + ": " + moddir) self.ui.labelInstallationLocation.setText( installationLocationString) self.ui.labelInstallationLocation.show() else: self.ui.labelPackageDetails.hide() self.ui.labelInstallationLocation.hide() if status == AddonManagerRepo.UpdateStatus.NOT_INSTALLED: self.ui.buttonInstall.show() self.ui.buttonUninstall.hide() self.ui.buttonUpdate.hide() self.ui.buttonCheckForUpdate.hide() elif status == AddonManagerRepo.UpdateStatus.NO_UPDATE_AVAILABLE: self.ui.buttonInstall.hide() self.ui.buttonUninstall.show() self.ui.buttonUpdate.hide() self.ui.buttonCheckForUpdate.hide() elif status == AddonManagerRepo.UpdateStatus.UPDATE_AVAILABLE: self.ui.buttonInstall.hide() self.ui.buttonUninstall.show() self.ui.buttonUpdate.show() self.ui.buttonCheckForUpdate.hide() elif status == AddonManagerRepo.UpdateStatus.UNCHECKED: self.ui.buttonInstall.hide() self.ui.buttonUninstall.show() self.ui.buttonUpdate.hide() self.ui.buttonCheckForUpdate.show() elif status == AddonManagerRepo.UpdateStatus.PENDING_RESTART: self.ui.buttonInstall.hide() self.ui.buttonUninstall.show() self.ui.buttonUpdate.hide() self.ui.buttonCheckForUpdate.hide() required_version = self.requires_newer_freecad() if repo.obsolete: self.ui.labelWarningInfo.show() self.ui.labelWarningInfo.setText("<h1>" + translate( "AddonsInstaller", "WARNING: This addon is obsolete") + "</h1>") self.ui.labelWarningInfo.setStyleSheet( "color:" + utils.warning_color_string()) elif repo.python2: self.ui.labelWarningInfo.show() self.ui.labelWarningInfo.setText("<h1>" + translate( "AddonsInstaller", "WARNING: This addon is Python 2 Only") + "</h1>") self.ui.labelWarningInfo.setStyleSheet( "color:" + utils.warning_color_string()) elif required_version: self.ui.labelWarningInfo.show() self.ui.labelWarningInfo.setText("<h1>" + translate( "AddonsInstaller", "WARNING: This addon requires FreeCAD ") + required_version + "</h1>") self.ui.labelWarningInfo.setStyleSheet( "color:" + utils.warning_color_string()) else: self.ui.labelWarningInfo.hide()
def show_repo(self, repo: AddonManagerRepo, reload: bool = False) -> None: self.repo = repo if self.worker is not None: if not self.worker.isFinished(): self.worker.requestInterruption() self.worker.wait() # Always load bare macros from scratch, we need to grab their code, which isn't cached force_reload = reload if repo.repo_type == AddonManagerRepo.RepoType.MACRO: force_reload = True self.check_and_clean_cache(force_reload) if repo.repo_type == AddonManagerRepo.RepoType.MACRO: self.show_macro(repo) self.ui.buttonExecute.show() elif repo.repo_type == AddonManagerRepo.RepoType.WORKBENCH: self.show_workbench(repo) self.ui.buttonExecute.hide() elif repo.repo_type == AddonManagerRepo.RepoType.PACKAGE: self.show_package(repo) self.ui.buttonExecute.hide() if repo.update_status != AddonManagerRepo.UpdateStatus.NOT_INSTALLED: version = repo.installed_version date = "" installed_version_string = "<h3>" if repo.updated_timestamp: date = (QDateTime.fromTime_t( repo.updated_timestamp).date().toString( Qt.SystemLocaleShortDate)) if version and date: installed_version_string += ( translate("AddonsInstaller", f"Version {version} installed on {date}") + ". ") elif version: installed_version_string += (translate( "AddonsInstaller", f"Version {version} installed") + ". ") elif date: installed_version_string += ( translate("AddonsInstaller", f"Installed on {date}") + ". ") else: installed_version_string += ( translate("AddonsInstaller", "Installed") + ". ") if repo.update_status == AddonManagerRepo.UpdateStatus.UPDATE_AVAILABLE: if repo.metadata: installed_version_string += ("<b>" + translate( "AddonsInstaller", "Update available to version") + " ") installed_version_string += repo.metadata.Version installed_version_string += ".</b>" elif repo.macro and repo.macro.version: installed_version_string += ("<b>" + translate( "AddonsInstaller", "Update available to version") + " ") installed_version_string += repo.macro.version installed_version_string += ".</b>" else: installed_version_string += ("<b>" + translate( "AddonsInstaller", "An update is available", ) + ".</b>") elif (repo.update_status == AddonManagerRepo.UpdateStatus.NO_UPDATE_AVAILABLE): installed_version_string += ( translate("AddonsInstaller", "This is the latest version available") + ".") elif repo.update_status == AddonManagerRepo.UpdateStatus.PENDING_RESTART: installed_version_string += ( translate("AddonsInstaller", "Updated, please restart FreeCAD to use") + ".") elif repo.update_status == AddonManagerRepo.UpdateStatus.UNCHECKED: pref = FreeCAD.ParamGet( "User parameter:BaseApp/Preferences/Addons") autocheck = pref.GetBool("AutoCheck", False) if autocheck: installed_version_string += (translate( "AddonsInstaller", "Update check in progress") + ".") else: installed_version_string += ( translate("AddonsInstaller", "Automatic update checks disabled") + ".") installed_version_string += "</h3>" self.ui.labelPackageDetails.setText(installed_version_string) if repo.update_status == AddonManagerRepo.UpdateStatus.UPDATE_AVAILABLE: self.ui.labelPackageDetails.setStyleSheet( "color:" + utils.attention_color_string()) else: self.ui.labelPackageDetails.setStyleSheet( "color:" + utils.bright_color_string()) self.ui.labelPackageDetails.show() if repo.macro is not None: moddir = FreeCAD.getUserMacroDir(True) else: basedir = FreeCAD.getUserAppDataDir() moddir = os.path.join(basedir, "Mod", repo.name) installationLocationString = ( translate("AddonsInstaller", "Installation location") + ": " + moddir) self.ui.labelInstallationLocation.setText( installationLocationString) self.ui.labelInstallationLocation.show() else: self.ui.labelPackageDetails.hide() self.ui.labelInstallationLocation.hide() if repo.update_status == AddonManagerRepo.UpdateStatus.NOT_INSTALLED: self.ui.buttonInstall.show() self.ui.buttonUninstall.hide() self.ui.buttonUpdate.hide() self.ui.buttonCheckForUpdate.hide() elif repo.update_status == AddonManagerRepo.UpdateStatus.NO_UPDATE_AVAILABLE: self.ui.buttonInstall.hide() self.ui.buttonUninstall.show() self.ui.buttonUpdate.hide() self.ui.buttonCheckForUpdate.hide() elif repo.update_status == AddonManagerRepo.UpdateStatus.UPDATE_AVAILABLE: self.ui.buttonInstall.hide() self.ui.buttonUninstall.show() self.ui.buttonUpdate.show() self.ui.buttonCheckForUpdate.hide() elif repo.update_status == AddonManagerRepo.UpdateStatus.UNCHECKED: self.ui.buttonInstall.hide() self.ui.buttonUninstall.show() self.ui.buttonUpdate.hide() self.ui.buttonCheckForUpdate.show() elif repo.update_status == AddonManagerRepo.UpdateStatus.PENDING_RESTART: self.ui.buttonInstall.hide() self.ui.buttonUninstall.show() self.ui.buttonUpdate.hide() self.ui.buttonCheckForUpdate.hide() if repo.obsolete: self.ui.labelWarningInfo.show() self.ui.labelWarningInfo.setText("<h1>" + translate( "AddonsInstaller", "WARNING: This addon is obsolete") + "</h1>") self.ui.labelWarningInfo.setStyleSheet( "color:" + utils.warning_color_string()) elif repo.python2: self.ui.labelWarningInfo.show() self.ui.labelWarningInfo.setText("<h1>" + translate( "AddonsInstaller", "WARNING: This addon is Python 2 Only") + "</h1>") self.ui.labelWarningInfo.setStyleSheet( "color:" + utils.warning_color_string()) else: self.ui.labelWarningInfo.hide()