Addon Manager: Translation cleanup
pylupdate does not extract translations when f-strings are used for the translated text, so all f-strings are migrated to calls to format(). Several other minor translation issues are also addressed. NOTE: This code has been run through the Black reformatter, which adds trailing commas in many places that the stock Qt 5.x pylupdate does not recognize. This code must be processed with the corrected pylupdate to generate the correct translations.
This commit is contained in:
@@ -34,7 +34,6 @@ from typing import Dict
|
||||
from PySide2 import QtGui, QtCore, QtWidgets
|
||||
import FreeCADGui
|
||||
|
||||
from addonmanager_utilities import translate # this needs to be as is for pylupdate
|
||||
from addonmanager_workers import *
|
||||
import addonmanager_utilities as utils
|
||||
import AddonManager_rc
|
||||
@@ -44,6 +43,8 @@ from AddonManagerRepo import AddonManagerRepo
|
||||
|
||||
from NetworkManager import HAVE_QTNETWORK, InitializeNetworkManager
|
||||
|
||||
translate = FreeCAD.Qt.translate
|
||||
|
||||
__title__ = "FreeCAD Addon Manager Module"
|
||||
__author__ = "Yorik van Havre", "Jonathan Wiedemann", "Kurt Kremitzki", "Chris Hennes"
|
||||
__url__ = "http://www.freecad.org"
|
||||
@@ -238,9 +239,12 @@ class CommandAddonManager:
|
||||
)
|
||||
else:
|
||||
QtWidgets.QMessageBox.critical(
|
||||
None,
|
||||
translate("AddonsInstaller", "Missing dependency"),
|
||||
translate("AddonsInstaller", "Could not import QtNetwork -- see Report View for details. Addon Manager unavailable."),
|
||||
None,
|
||||
translate("AddonsInstaller", "Missing dependency"),
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
"Could not import QtNetwork -- see Report View for details. Addon Manager unavailable.",
|
||||
),
|
||||
)
|
||||
|
||||
def launch(self) -> None:
|
||||
@@ -424,8 +428,8 @@ class CommandAddonManager:
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Worker process {worker} is taking a long time to stop...\n",
|
||||
)
|
||||
"Worker process {} is taking a long time to stop...\n",
|
||||
).format(worker)
|
||||
)
|
||||
|
||||
def wait_on_other_workers(self) -> None:
|
||||
@@ -763,13 +767,10 @@ class CommandAddonManager:
|
||||
"""enables the update button"""
|
||||
|
||||
if number_of_updates:
|
||||
self.dialog.buttonUpdateAll.setText(
|
||||
translate("AddonsInstaller", "Apply")
|
||||
+ " "
|
||||
+ str(number_of_updates)
|
||||
+ " "
|
||||
+ translate("AddonsInstaller", "update(s)")
|
||||
s = translate(
|
||||
"AddonsInstaller", "Apply {} update(s)", "", number_of_updates
|
||||
)
|
||||
self.dialog.buttonUpdateAll.setText(s.format(number_of_updates))
|
||||
self.dialog.buttonUpdateAll.setEnabled(True)
|
||||
else:
|
||||
self.dialog.buttonUpdateAll.setText(
|
||||
@@ -784,9 +785,9 @@ class CommandAddonManager:
|
||||
addon_repo.icon = self.get_icon(addon_repo)
|
||||
for repo in self.item_model.repos:
|
||||
if repo.name == addon_repo.name:
|
||||
FreeCAD.Console.PrintLog(
|
||||
f"Possible duplicate addon: ignoring second addition of {addon_repo.name}\n"
|
||||
)
|
||||
# FreeCAD.Console.PrintLog(
|
||||
# f"Possible duplicate addon: ignoring second addition of {addon_repo.name}\n"
|
||||
# )
|
||||
return
|
||||
self.item_model.append_item(addon_repo)
|
||||
|
||||
@@ -907,8 +908,8 @@ class CommandAddonManager:
|
||||
if bad_packages:
|
||||
message = translate(
|
||||
"AddonsInstaller",
|
||||
"The Addon {repo.name} requires Python packages that are not installed, and cannot be installed automatically. To use this workbench you must install the following Python packages manually:",
|
||||
)
|
||||
"The Addon {} requires Python packages that are not installed, and cannot be installed automatically. To use this workbench you must install the following Python packages manually:",
|
||||
).format(repo.name)
|
||||
if len(bad_packages) < 15:
|
||||
for dep in bad_packages:
|
||||
message += f"\n * {dep}"
|
||||
@@ -951,13 +952,13 @@ class CommandAddonManager:
|
||||
name = missing_wbs[0]
|
||||
message = translate(
|
||||
"AddonsInstaller",
|
||||
f"Installing {addon} requires '{name}', which is not installed in your copy of FreeCAD.",
|
||||
)
|
||||
"Installing {} requires '{}', which is not installed in your copy of FreeCAD.",
|
||||
).format(addon, name)
|
||||
else:
|
||||
message = translate(
|
||||
"AddonsInstaller",
|
||||
f"Installing {addon} requires the following workbenches, which are not installed in your copy of FreeCAD:\n",
|
||||
)
|
||||
"Installing {} requires the following workbenches, which are not installed in your copy of FreeCAD:\n",
|
||||
).format(addon)
|
||||
for wb in missing_wbs:
|
||||
message += " - " + wb + "\n"
|
||||
QtWidgets.QMessageBox.critical(
|
||||
@@ -1068,8 +1069,8 @@ class CommandAddonManager:
|
||||
+ "\n\n"
|
||||
+ translate(
|
||||
"AddonsInstaller",
|
||||
f"Dependencies could not be installed. Continue with installation of {repo.name} anyway?",
|
||||
),
|
||||
"Dependencies could not be installed. Continue with installation of {} anyway?",
|
||||
).format(repo.name),
|
||||
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
|
||||
)
|
||||
if result == QtWidgets.QMessageBox.Yes:
|
||||
@@ -1088,8 +1089,8 @@ class CommandAddonManager:
|
||||
+ f"\n\n{command}\n\n"
|
||||
+ translate(
|
||||
"AddonsInstaller",
|
||||
f"Continue with installation of {repo.name} anyway?",
|
||||
),
|
||||
"Continue with installation of {} anyway?",
|
||||
).format(repo.name),
|
||||
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
|
||||
)
|
||||
if result == QtWidgets.QMessageBox.Yes:
|
||||
@@ -1273,8 +1274,10 @@ class CommandAddonManager:
|
||||
result = "".join([repo.name + "\n" for repo in repos])
|
||||
else:
|
||||
result = translate(
|
||||
"AddonsInstaller", f"{num_updates} total, see Report view for list"
|
||||
)
|
||||
"AddonsInstaller",
|
||||
"{} total, see Report view for list",
|
||||
"Describes the number of updates that were completed ('{}' is replaced by the number of updates)",
|
||||
).format(num_updates)
|
||||
for repo in repos:
|
||||
FreeCAD.Console.PrintMessage(f"{message}: {repo.name}\n")
|
||||
return result
|
||||
@@ -1360,9 +1363,9 @@ class CommandAddonManager:
|
||||
"""Update the progress bar, showing it if it's hidden"""
|
||||
|
||||
if current_value < 0:
|
||||
FreeCAD.Console.PrintWarning(
|
||||
f"Addon Manager: Internal error, current progress value is negative in region {self.current_progress_region}"
|
||||
)
|
||||
current_value = 0
|
||||
elif current_value > max_value:
|
||||
current_value = max_value
|
||||
|
||||
self.show_progress_widgets()
|
||||
region_size = 100.0 / self.number_of_progress_regions
|
||||
@@ -1496,8 +1499,8 @@ class CommandAddonManager:
|
||||
FreeCAD.Console.PrintMessage(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Macro {macro_filename} has local changes in the macros directory, so is not being removed by this uninstall process.\n",
|
||||
)
|
||||
"Macro {} has local changes in the macros directory, so is not being removed by this uninstall process.\n",
|
||||
).format(macro_filename)
|
||||
)
|
||||
|
||||
if os.path.exists(clonedir):
|
||||
|
||||
@@ -109,9 +109,9 @@ if HAVE_QTNETWORK:
|
||||
self.track_progress = track_progress
|
||||
|
||||
class NetworkManager(QtCore.QObject):
|
||||
"""A single global instance of NetworkManager is instantiated and stored as
|
||||
AM_NETWORK_MANAGER. Outside threads should send GET requests to this class by
|
||||
calling the submit_unmonitored_request() or submit_monitored_request() function,
|
||||
"""A single global instance of NetworkManager is instantiated and stored as
|
||||
AM_NETWORK_MANAGER. Outside threads should send GET requests to this class by
|
||||
calling the submit_unmonitored_request() or submit_monitored_request() function,
|
||||
as needed. See the documentation of those functions for details."""
|
||||
|
||||
# Connect to complete for requests with no progress monitoring (e.g. small amounts of data)
|
||||
@@ -154,8 +154,10 @@ if HAVE_QTNETWORK:
|
||||
self.QNAM.proxyAuthenticationRequired.connect(self.__authenticate_proxy)
|
||||
self.QNAM.authenticationRequired.connect(self.__authenticate_resource)
|
||||
|
||||
qnam_cache = QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.CacheLocation);
|
||||
os.makedirs(qnam_cache,exist_ok=True)
|
||||
qnam_cache = QtCore.QStandardPaths.writableLocation(
|
||||
QtCore.QStandardPaths.CacheLocation
|
||||
)
|
||||
os.makedirs(qnam_cache, exist_ok=True)
|
||||
self.diskCache = QtNetwork.QNetworkDiskCache()
|
||||
self.diskCache.setCacheDirectory(qnam_cache)
|
||||
self.QNAM.setCache(self.diskCache)
|
||||
@@ -239,9 +241,7 @@ if HAVE_QTNETWORK:
|
||||
lambda i=item.index: self.__data_incoming(i)
|
||||
)
|
||||
reply.downloadProgress.connect(
|
||||
lambda a, b, i=item.index: self.progress_made.emit(
|
||||
i, a, b
|
||||
)
|
||||
lambda a, b, i=item.index: self.progress_made.emit(i, a, b)
|
||||
)
|
||||
self.replies[item.index] = reply
|
||||
except queue.Empty:
|
||||
@@ -462,8 +462,8 @@ else: # HAVE_QTNETWORK is false:
|
||||
def submit_monitored_request(self, _) -> int:
|
||||
current_index = next(itertools.count())
|
||||
self.monitored_queue.put(current_index)
|
||||
return current_index
|
||||
|
||||
return current_index
|
||||
|
||||
def blocking_get(self, _: str) -> QtCore.QByteArray:
|
||||
return None
|
||||
|
||||
@@ -481,6 +481,7 @@ def InitializeNetworkManager():
|
||||
if AM_NETWORK_MANAGER is None:
|
||||
AM_NETWORK_MANAGER = NetworkManager()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
app = QtCore.QCoreApplication()
|
||||
|
||||
@@ -171,8 +171,8 @@ class Macro(object):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Unable to open macro wiki page at {url}",
|
||||
)
|
||||
"Unable to open macro wiki page at {}",
|
||||
).format(url)
|
||||
+ "\n"
|
||||
)
|
||||
return
|
||||
@@ -188,8 +188,8 @@ class Macro(object):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Unable to open macro code URL {rawcodeurl}",
|
||||
)
|
||||
"Unable to open macro code URL {rawcodeurl}",
|
||||
).format(rawcodeurl)
|
||||
+ "\n"
|
||||
)
|
||||
return
|
||||
@@ -221,8 +221,8 @@ class Macro(object):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Unable to retrieve a description from the wiki for macro {self.name}",
|
||||
)
|
||||
"Unable to retrieve a description from the wiki for macro {}",
|
||||
).format(self.name)
|
||||
+ "\n"
|
||||
)
|
||||
desc = "No description available"
|
||||
@@ -322,8 +322,8 @@ class Macro(object):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Failed to remove macro file '{dst_file}': it might not exist, or its permissions changed",
|
||||
)
|
||||
"Failed to remove macro file '{}': it might not exist, or its permissions changed",
|
||||
).format(dst_file)
|
||||
+ "\n"
|
||||
)
|
||||
return True
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
import os
|
||||
import re
|
||||
import ctypes
|
||||
import ssl
|
||||
from typing import Union, Optional
|
||||
|
||||
import urllib
|
||||
@@ -38,20 +37,6 @@ from PySide2 import QtCore, QtWidgets
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
|
||||
# check for SSL support
|
||||
|
||||
ssl_ctx = None
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
# ssl_ctx = ssl.create_default_context(cafile=certifi.where())
|
||||
# ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
||||
ssl_ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# @package AddonManager_utilities
|
||||
# \ingroup ADDONMANAGER
|
||||
@@ -59,15 +44,7 @@ else:
|
||||
# @{
|
||||
|
||||
|
||||
def translate(context, text, disambig=None):
|
||||
"Main translation function"
|
||||
|
||||
try:
|
||||
_encoding = QtWidgets.QApplication.UnicodeUTF8
|
||||
except AttributeError:
|
||||
return QtWidgets.QApplication.translate(context, text, disambig)
|
||||
else:
|
||||
return QtWidgets.QApplication.translate(context, text, disambig, _encoding)
|
||||
translate = FreeCAD.Qt.translate
|
||||
|
||||
|
||||
def symlink(source, link_name):
|
||||
|
||||
@@ -65,7 +65,7 @@ try:
|
||||
have_git = hasattr(git, "Repo")
|
||||
if not have_git:
|
||||
FreeCAD.Console.PrintMessage(
|
||||
"'import git' gave strange results (no Repo attribute)..."
|
||||
"'import git' gave strange results (no Repo attribute)... do you have GitPython installed?"
|
||||
)
|
||||
except ImportError:
|
||||
pass
|
||||
@@ -115,9 +115,7 @@ class ConnectionChecker(QtCore.QThread):
|
||||
QtCore.QThread.__init__(self)
|
||||
|
||||
def run(self):
|
||||
FreeCAD.Console.PrintLog(
|
||||
translate("AddonsInstaller", "Checking network connection...\n")
|
||||
)
|
||||
FreeCAD.Console.PrintLog("Checking network connection...\n")
|
||||
url = "https://api.github.com/zen"
|
||||
result = NetworkManager.AM_NETWORK_MANAGER.blocking_get(url)
|
||||
if QtCore.QThread.currentThread().isInterruptionRequested():
|
||||
@@ -425,7 +423,9 @@ class CheckWorkbenchesForUpdatesWorker(QtCore.QThread):
|
||||
self.update_status.emit(wb)
|
||||
except Exception:
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate("AddonsInstaller", "git fetch failed for {}").format(wb.name)
|
||||
translate("AddonsInstaller", "git fetch failed for {}").format(
|
||||
wb.name
|
||||
)
|
||||
)
|
||||
|
||||
def check_package(self, package: AddonManagerRepo) -> None:
|
||||
@@ -460,8 +460,8 @@ class CheckWorkbenchesForUpdatesWorker(QtCore.QThread):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Failed to read metadata from {installed_metadata_file}",
|
||||
)
|
||||
"Failed to read metadata from {name}",
|
||||
).format(name=installed_metadata_file)
|
||||
+ "\n"
|
||||
)
|
||||
|
||||
@@ -482,8 +482,8 @@ class CheckWorkbenchesForUpdatesWorker(QtCore.QThread):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Failed to fetch code for macro '{macro_wrapper.macro.name}'",
|
||||
)
|
||||
"Failed to fetch code for macro '{name}'",
|
||||
).format(name=macro_wrapper.macro.name)
|
||||
+ "\n"
|
||||
)
|
||||
return
|
||||
@@ -540,7 +540,7 @@ class FillMacroListWorker(QtCore.QThread):
|
||||
if not self.current_thread.isInterruptionRequested():
|
||||
self.status_message_signal.emit(
|
||||
translate(
|
||||
"AddonInstaller",
|
||||
"AddonsInstaller",
|
||||
"Retrieving macros from FreeCAD/FreeCAD-Macros Git repository",
|
||||
)
|
||||
)
|
||||
@@ -549,7 +549,7 @@ class FillMacroListWorker(QtCore.QThread):
|
||||
if not self.current_thread.isInterruptionRequested():
|
||||
self.status_message_signal.emit(
|
||||
translate(
|
||||
"AddonInstaller",
|
||||
"AddonsInstaller",
|
||||
"Retrieving macros from FreeCAD wiki",
|
||||
)
|
||||
)
|
||||
@@ -627,7 +627,9 @@ class FillMacroListWorker(QtCore.QThread):
|
||||
Reads only the page https://wiki.freecad.org/Macros_recipes
|
||||
"""
|
||||
|
||||
p = NetworkManager.AM_NETWORK_MANAGER.blocking_get("https://wiki.freecad.org/Macros_recipes")
|
||||
p = NetworkManager.AM_NETWORK_MANAGER.blocking_get(
|
||||
"https://wiki.freecad.org/Macros_recipes"
|
||||
)
|
||||
if not p:
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
@@ -701,7 +703,11 @@ class CacheMacroCode(QtCore.QThread):
|
||||
worker.requestInterruption()
|
||||
if not worker.wait(100):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
f"Addon Manager: a worker process failed to halt ({worker.macro.name})"
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
"Addon Manager: a worker process failed to halt ({name})",
|
||||
).format(name=worker.macro.name)
|
||||
+ "\n"
|
||||
)
|
||||
return
|
||||
# Ensure our signals propagate out by running an internal thread-local event loop
|
||||
@@ -716,7 +722,11 @@ class CacheMacroCode(QtCore.QThread):
|
||||
worker.wait(50)
|
||||
if not worker.isFinished():
|
||||
FreeCAD.Console.PrintError(
|
||||
f"Addon Manager: a worker process failed to complete while fetching {worker.macro.name}\n"
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
"Addon Manager: a worker process failed to complete while fetching {name}",
|
||||
).format(name=worker.macro.name)
|
||||
+ "\n"
|
||||
)
|
||||
|
||||
self.repo_queue.join()
|
||||
@@ -729,8 +739,8 @@ class CacheMacroCode(QtCore.QThread):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Out of {num_macros} macros, {num_failed} timed out while processing",
|
||||
)
|
||||
"Out of {num_macros} macros, {num_failed} timed out while processing",
|
||||
).format(num_macros=num_macros, num_failed=num_failed)
|
||||
)
|
||||
|
||||
def update_and_advance(self, repo: AddonManagerRepo) -> None:
|
||||
@@ -760,8 +770,8 @@ class CacheMacroCode(QtCore.QThread):
|
||||
self.status_message.emit(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Getting metadata from macro {next_repo.macro.name}",
|
||||
)
|
||||
"Getting metadata from macro {}",
|
||||
).format(next_repo.macro.name)
|
||||
)
|
||||
worker.start()
|
||||
except queue.Empty:
|
||||
@@ -773,8 +783,8 @@ class CacheMacroCode(QtCore.QThread):
|
||||
FreeCAD.Console.PrintWarning(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Timeout while fetching metadata for macro {macro_name}",
|
||||
)
|
||||
"Timeout while fetching metadata for macro {}",
|
||||
).format(macro_name)
|
||||
+ "\n"
|
||||
)
|
||||
worker.blockSignals(True)
|
||||
@@ -782,7 +792,10 @@ class CacheMacroCode(QtCore.QThread):
|
||||
worker.wait(100)
|
||||
if worker.isRunning():
|
||||
FreeCAD.Console.PrintError(
|
||||
f"Failed to kill process for macro {macro_name}!\n"
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
"Failed to kill process for macro {}!\n",
|
||||
).format(macro_name)
|
||||
)
|
||||
with self.lock:
|
||||
self.failed.append(macro_name)
|
||||
@@ -808,7 +821,7 @@ class ShowWorker(QtCore.QThread):
|
||||
u = None
|
||||
url = self.repo.url
|
||||
self.status_message.emit(
|
||||
translate("AddonsInstaller", "Retrieving info from") + " " + str(url)
|
||||
translate("AddonsInstaller", "Retrieving info from {}").format(str(url))
|
||||
)
|
||||
desc = ""
|
||||
regex = utils.get_readme_regex(self.repo)
|
||||
@@ -942,7 +955,9 @@ class ShowWorker(QtCore.QThread):
|
||||
storename = os.path.join(store, wbName + name[-remainChars:])
|
||||
if not os.path.exists(storename):
|
||||
try:
|
||||
imagedata = NetworkManager.AM_NETWORK_MANAGER.blocking_get(path)
|
||||
imagedata = NetworkManager.AM_NETWORK_MANAGER.blocking_get(
|
||||
path
|
||||
)
|
||||
if not imagedata:
|
||||
raise Exception
|
||||
except Exception:
|
||||
@@ -1227,12 +1242,14 @@ class InstallWorkbenchWorker(QtCore.QThread):
|
||||
|
||||
NetworkManager.AM_NETWORK_MANAGER.progress_made.connect(self.update_zip_status)
|
||||
NetworkManager.AM_NETWORK_MANAGER.progress_complete.connect(self.finish_zip)
|
||||
self.zip_download_index = NetworkManager.AM_NETWORK_MANAGER.submit_monitored_get(zipurl)
|
||||
self.zip_download_index = (
|
||||
NetworkManager.AM_NETWORK_MANAGER.submit_monitored_get(zipurl)
|
||||
)
|
||||
|
||||
def update_zip_status(self, index: int, bytes_read: int, data_size: int):
|
||||
if index == self.zip_download_index:
|
||||
locale = QtCore.QLocale()
|
||||
if data_size > 10 * 1024 * 1024: # To avoid overflows, show MB instead
|
||||
if data_size > 10 * 1024 * 1024: # To avoid overflows, show MB instead
|
||||
MB_read = bytes_read / 1024 / 1024
|
||||
MB_total = data_size / 1024 / 1024
|
||||
self.progress_made.emit(MB_read, MB_total)
|
||||
@@ -1242,7 +1259,11 @@ class InstallWorkbenchWorker(QtCore.QThread):
|
||||
self.status_message.emit(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Downloading: {mbytes_str}MB of {mbytes_total_str}MB ({percent}%)",
|
||||
"Downloading: {mbytes_str}MB of {mbytes_total_str}MB ({percent}%)",
|
||||
).format(
|
||||
mbytes_str=mbytes_str,
|
||||
mbytes_total_str=mbytes_total_str,
|
||||
percent=percent,
|
||||
)
|
||||
)
|
||||
elif data_size > 0:
|
||||
@@ -1253,7 +1274,11 @@ class InstallWorkbenchWorker(QtCore.QThread):
|
||||
self.status_message.emit(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Downloading: {bytes_str} of {bytes_total_str} bytes ({percent}%)",
|
||||
"Downloading: {bytes_str} of {bytes_total_str} bytes ({percent}%)",
|
||||
).format(
|
||||
bytes_str=bytes_str,
|
||||
bytes_total_str=bytes_total_str,
|
||||
percent=percent,
|
||||
)
|
||||
)
|
||||
else:
|
||||
@@ -1262,8 +1287,8 @@ class InstallWorkbenchWorker(QtCore.QThread):
|
||||
self.status_message.emit(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Downloading: {bytes_str}MB of unknown total",
|
||||
)
|
||||
"Downloading: {bytes_str}MB of unknown total",
|
||||
).format(bytes_str=bytes_str)
|
||||
)
|
||||
|
||||
def finish_zip(self, index: int, response_code: int, filename: os.PathLike):
|
||||
@@ -1273,8 +1298,8 @@ class InstallWorkbenchWorker(QtCore.QThread):
|
||||
self.repo,
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Error: Error while downloading ZIP file for {self.repo.display_name}",
|
||||
),
|
||||
"Error: Error while downloading ZIP file for {}",
|
||||
).format(self.repo.display_name),
|
||||
)
|
||||
return
|
||||
|
||||
@@ -1298,8 +1323,8 @@ class InstallWorkbenchWorker(QtCore.QThread):
|
||||
self.repo,
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Successfully installed {self.repo.display_name} from ZIP file",
|
||||
),
|
||||
"Successfully installed {} from ZIP file",
|
||||
).format(self.repo.display_name),
|
||||
)
|
||||
|
||||
def update_metadata(self):
|
||||
@@ -1412,8 +1437,8 @@ class DependencyInstallationWorker(QtCore.QThread):
|
||||
self.emit.failure(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Installation of Python package {pymod} failed",
|
||||
),
|
||||
"Installation of Python package {} failed",
|
||||
).format(pymod),
|
||||
proc.stderr,
|
||||
)
|
||||
return
|
||||
@@ -1431,8 +1456,8 @@ class DependencyInstallationWorker(QtCore.QThread):
|
||||
self.emit.failure(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Installation of Python package {pymod} failed",
|
||||
),
|
||||
"Installation of Python package {} failed",
|
||||
).format(pymod),
|
||||
proc.stderr,
|
||||
)
|
||||
return
|
||||
@@ -1537,7 +1562,9 @@ class UpdateMetadataCacheWorker(QtCore.QThread):
|
||||
|
||||
while self.requests:
|
||||
if current_thread.isInterruptionRequested():
|
||||
NetworkManager.AM_NETWORK_MANAGER.completed.disconnect(self.download_completed)
|
||||
NetworkManager.AM_NETWORK_MANAGER.completed.disconnect(
|
||||
self.download_completed
|
||||
)
|
||||
for request in self.requests.keys():
|
||||
NetworkManager.AM_NETWORK_MANAGER.abort(request)
|
||||
return
|
||||
@@ -1581,7 +1608,9 @@ class UpdateMetadataCacheWorker(QtCore.QThread):
|
||||
metadata = FreeCAD.Metadata(new_xml_file)
|
||||
repo.metadata = metadata
|
||||
self.status_message.emit(
|
||||
translate("AddonsInstaller", f"Downloaded package.xml for {repo.name}")
|
||||
translate("AddonsInstaller", "Downloaded package.xml for {}").format(
|
||||
repo.name
|
||||
)
|
||||
)
|
||||
|
||||
# Grab a new copy of the icon as well: we couldn't enqueue this earlier because
|
||||
@@ -1609,8 +1638,8 @@ class UpdateMetadataCacheWorker(QtCore.QThread):
|
||||
|
||||
def process_metadata_txt(self, repo: AddonManagerRepo, data: QtCore.QByteArray):
|
||||
self.status_message.emit(
|
||||
translate(
|
||||
"AddonsInstaller", f"Downloaded metadata.txt for {repo.display_name}"
|
||||
translate("AddonsInstaller", "Downloaded metadata.txt for {}").format(
|
||||
repo.display_name
|
||||
)
|
||||
)
|
||||
f = io.StringIO(data.data().decode("utf8"))
|
||||
@@ -1659,8 +1688,8 @@ class UpdateMetadataCacheWorker(QtCore.QThread):
|
||||
self.status_message.emit(
|
||||
translate(
|
||||
"AddonsInstaller",
|
||||
f"Downloaded requirements.txt for {repo.display_name}",
|
||||
)
|
||||
"Downloaded requirements.txt for {}",
|
||||
).format(repo.display_name)
|
||||
)
|
||||
f = io.StringIO(data.data().decode("utf8"))
|
||||
lines = f.readlines()
|
||||
@@ -1683,7 +1712,9 @@ class UpdateMetadataCacheWorker(QtCore.QThread):
|
||||
|
||||
def process_icon(self, repo: AddonManagerRepo, data: QtCore.QByteArray):
|
||||
self.status_message.emit(
|
||||
translate("AddonsInstaller", f"Downloaded icon for {repo.display_name}")
|
||||
translate("AddonsInstaller", "Downloaded icon for {}").format(
|
||||
repo.display_name
|
||||
)
|
||||
)
|
||||
cache_file = repo.get_cached_icon_filename()
|
||||
with open(cache_file, "wb") as icon_file:
|
||||
|
||||
@@ -108,18 +108,18 @@ class PackageDetails(QWidget):
|
||||
if version and date:
|
||||
installed_version_string += (
|
||||
translate(
|
||||
"AddonsInstaller", f"Version {version} installed on {date}"
|
||||
)
|
||||
"AddonsInstaller", "Version {version} installed on {date}"
|
||||
).format(version=version, date=date)
|
||||
+ ". "
|
||||
)
|
||||
elif version:
|
||||
installed_version_string += (
|
||||
translate("AddonsInstaller", f"Version {version} installed") + ". "
|
||||
)
|
||||
translate("AddonsInstaller", "Version {version} installed") + ". "
|
||||
).format(version=version)
|
||||
elif date:
|
||||
installed_version_string += (
|
||||
translate("AddonsInstaller", f"Installed on {date}") + ". "
|
||||
)
|
||||
translate("AddonsInstaller", "Installed on {date}") + ". "
|
||||
).format(date=date)
|
||||
else:
|
||||
installed_version_string += (
|
||||
translate("AddonsInstaller", "Installed") + ". "
|
||||
|
||||
@@ -31,12 +31,13 @@ from PySide2.QtWidgets import *
|
||||
from enum import IntEnum
|
||||
import threading
|
||||
|
||||
from addonmanager_utilities import translate # this needs to be as is for pylupdate
|
||||
from AddonManagerRepo import AddonManagerRepo
|
||||
|
||||
from compact_view import Ui_CompactView
|
||||
from expanded_view import Ui_ExpandedView
|
||||
|
||||
translate = FreeCAD.Qt.translate
|
||||
|
||||
|
||||
class ListDisplayStyle(IntEnum):
|
||||
COMPACT = 0
|
||||
@@ -201,20 +202,17 @@ class PackageListItemModel(QAbstractListModel):
|
||||
if role == Qt.ToolTipRole:
|
||||
tooltip = ""
|
||||
if self.repos[row].repo_type == AddonManagerRepo.RepoType.PACKAGE:
|
||||
tooltip = (
|
||||
translate("AddonsInstaller", "Click for details about package")
|
||||
+ f" '{self.repos[row].display_name}'"
|
||||
)
|
||||
tooltip = translate(
|
||||
"AddonsInstaller", "Click for details about package {}"
|
||||
).format(self.repos[row].display_name)
|
||||
elif self.repos[row].repo_type == AddonManagerRepo.RepoType.WORKBENCH:
|
||||
tooltip = (
|
||||
translate("AddonsInstaller", "Click for details about workbench")
|
||||
+ f" '{self.repos[row].display_name}'"
|
||||
)
|
||||
tooltip = translate(
|
||||
"AddonsInstaller", "Click for details about workbench {}"
|
||||
).format(self.repos[row].display_name)
|
||||
elif self.repos[row].repo_type == AddonManagerRepo.RepoType.MACRO:
|
||||
tooltip = (
|
||||
translate("AddonsInstaller", "Click for details about macro")
|
||||
+ f" '{self.repos[row].display_name}'"
|
||||
)
|
||||
tooltip = translate(
|
||||
"AddonsInstaller", "Click for details about macro {}"
|
||||
).format(self.repos[row].display_name)
|
||||
return tooltip
|
||||
elif role == PackageListItemModel.DataAccessRole:
|
||||
return self.repos[row]
|
||||
@@ -345,19 +343,18 @@ class PackageListItemDelegate(QStyledItemDelegate):
|
||||
self.widget.ui.labelVersion.setText(f"<i>v{repo.metadata.Version}</i>")
|
||||
if self.displayStyle == ListDisplayStyle.EXPANDED:
|
||||
maintainers = repo.metadata.Maintainer
|
||||
maintainers_string = ""
|
||||
string = ""
|
||||
if len(maintainers) == 1:
|
||||
maintainers_string = (
|
||||
string = (
|
||||
translate("AddonsInstaller", "Maintainer")
|
||||
+ f": {maintainers[0]['name']} <{maintainers[0]['email']}>"
|
||||
)
|
||||
elif len(maintainers) > 1:
|
||||
maintainers_string = translate("AddonsInstaller", "Maintainers:")
|
||||
n = len(maintainers)
|
||||
string = translate("AddonsInstaller", "Maintainers:", "", n)
|
||||
for maintainer in maintainers:
|
||||
maintainers_string += (
|
||||
f"\n{maintainer['name']} <{maintainer['email']}>"
|
||||
)
|
||||
self.widget.ui.labelMaintainer.setText(maintainers_string)
|
||||
string += f"\n{maintainer['name']} <{maintainer['email']}>"
|
||||
self.widget.ui.labelMaintainer.setText(string)
|
||||
elif repo.macro and repo.macro.parsed:
|
||||
self.widget.ui.labelDescription.setText(repo.macro.comment)
|
||||
self.widget.ui.labelVersion.setText(repo.macro.version)
|
||||
|
||||
Reference in New Issue
Block a user