def get_expanded_update_string(self, repo: AddonManagerRepo) -> str: """Get a multi-line string listing details about the installed version and date""" result = "" installed_version_string = "" if repo.status() != AddonManagerRepo.UpdateStatus.NOT_INSTALLED: if repo.installed_version: installed_version_string = ( "<br/>" + translate("AddonsInstaller", "Installed version") + ": ") installed_version_string += repo.installed_version else: installed_version_string = "<br/>" + translate( "AddonsInstaller", "Unknown version") installed_date_string = "" if repo.updated_timestamp: installed_date_string = ( "<br/>" + translate("AddonsInstaller", "Installed on") + ": ") installed_date_string += (QDateTime.fromTime_t( repo.updated_timestamp).date().toString( Qt.SystemLocaleShortDate)) available_version_string = "" if repo.metadata: available_version_string = ( "<br/>" + translate("AddonsInstaller", "Available version") + ": ") available_version_string += repo.metadata.Version if repo.status() == AddonManagerRepo.UpdateStatus.UNCHECKED: result = translate("AddonsInstaller", "Installed") result += installed_version_string result += installed_date_string elif repo.status( ) == AddonManagerRepo.UpdateStatus.NO_UPDATE_AVAILABLE: result = translate("AddonsInstaller", "Up-to-date") result += installed_version_string result += installed_date_string elif repo.status() == AddonManagerRepo.UpdateStatus.UPDATE_AVAILABLE: result = translate("AddonsInstaller", "Update available") result += installed_version_string result += installed_date_string result += available_version_string elif repo.status() == AddonManagerRepo.UpdateStatus.PENDING_RESTART: result = translate("AddonsInstaller", "Pending restart") if repo.is_disabled(): style = "style='color:" + utils.warning_color_string( ) + "; font-weight:bold;'" result += f"<br/><span {style}>[" + translate( "AddonsInstaller", "DISABLED") + "]</span>" return result
def show_repo(self, repo: Addon, reload: bool = False) -> None: """The main entry point for this class, shows the package details and related buttons for the provided repo. If reload is true, then even if this is already the current repo the data is reloaded.""" # If this is the same repo we were already showing, we do not have to do the # expensive refetch unless reload is true if self.repo != repo or reload: self.repo = repo if HAS_QTWEBENGINE: self.ui.loadingLabel.show() self.ui.slowLoadLabel.hide() self.ui.webView.setHtml("<html><body>Loading...</body></html>") self.ui.webView.hide() self.ui.progressBar.show() self.timeout = QTimer.singleShot( 6000, self.long_load_running) # Six seconds else: self.ui.missingWebViewLabel.setStyleSheet( "color:" + utils.warning_color_string()) if self.worker is not None: if not self.worker.isFinished(): self.worker.requestInterruption() self.worker.wait() if repo.repo_type == Addon.Kind.MACRO: self.show_macro(repo) self.ui.buttonExecute.show() elif repo.repo_type == Addon.Kind.WORKBENCH: self.show_workbench(repo) self.ui.buttonExecute.hide() elif repo.repo_type == Addon.Kind.PACKAGE: self.show_package(repo) self.ui.buttonExecute.hide() if repo.status() == Addon.Status.UNCHECKED: if not self.status_update_thread: self.status_update_thread = QThread() self.status_create_addon_list_worker = CheckSingleUpdateWorker( repo) self.status_create_addon_list_worker.moveToThread( self.status_update_thread) self.status_update_thread.finished.connect( self.status_create_addon_list_worker.deleteLater) self.check_for_update.connect( self.status_create_addon_list_worker.do_work) self.status_create_addon_list_worker.update_status.connect( self.display_repo_status) self.status_update_thread.start() self.check_for_update.emit(self.repo) self.display_repo_status(self.repo.update_status)
def get_compact_update_string(self, repo: Addon) -> str: """Get a single-line string listing details about the installed version and date""" result = "" if repo.status() == Addon.Status.UNCHECKED: result = translate("AddonsInstaller", "Installed") elif repo.status() == Addon.Status.NO_UPDATE_AVAILABLE: result = translate("AddonsInstaller", "Up-to-date") elif repo.status() == Addon.Status.UPDATE_AVAILABLE: result = translate("AddonsInstaller", "Update available") elif repo.status() == Addon.Status.PENDING_RESTART: result = translate("AddonsInstaller", "Pending restart") if repo.is_disabled(): style = ("style='color:" + utils.warning_color_string() + "; font-weight:bold;'") result += (f"<span {style}> [" + translate("AddonsInstaller", "DISABLED") + "]</span>") return result
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()