diff --git a/src/studiolibrary/__init__.py b/src/studiolibrary/__init__.py index 7f26d8bb..66062bf2 100644 --- a/src/studiolibrary/__init__.py +++ b/src/studiolibrary/__init__.py @@ -10,7 +10,7 @@ # You should have received a copy of the GNU Lesser General Public # License along with this library. If not, see . -__version__ = "2.9.10" +__version__ = "2.9.11" def version(): diff --git a/src/studiolibrary/config.py b/src/studiolibrary/config.py index fab6357b..40dc8726 100644 --- a/src/studiolibrary/config.py +++ b/src/studiolibrary/config.py @@ -31,6 +31,16 @@ def get(*args): return _config.get(*args) +def set(key, value): + + global _config + + if not _config: + _config = read(paths()) + + _config[key] = value + + def paths(): """ Return all possible config paths. diff --git a/src/studiolibrary/config/default.json b/src/studiolibrary/config/default.json index f25c891b..b02a4104 100644 --- a/src/studiolibrary/config/default.json +++ b/src/studiolibrary/config/default.json @@ -9,6 +9,11 @@ // 2. The other way is to create an environment variable with the name // STUDIO_LIBRARY_CONFIG_PATH. The value of this variable should be the // full path to your config.json file. +// +// 3. Or you could use code to modify the config before loading the window. +// import studiolibrary +// studiolibrary.config.set("recursiveSearchDepth", 6) +// studiolibrary.main() { // The database path is used for caching the library items. diff --git a/src/studiolibrary/librarywindow.py b/src/studiolibrary/librarywindow.py index 185046aa..27718026 100644 --- a/src/studiolibrary/librarywindow.py +++ b/src/studiolibrary/librarywindow.py @@ -268,6 +268,7 @@ def __init__(self, parent=None, name="", path=""): self._updateAvailableButton = QtWidgets.QPushButton(self._statusWidget) self._updateAvailableButton.setObjectName("updateAvailableButton") self._updateAvailableButton.setText("Update Available") + self._updateAvailableButton.setCursor(QtCore.Qt.PointingHandCursor) self._updateAvailableButton.hide() self._updateAvailableButton.clicked.connect(self.openReleasesUrl) @@ -502,29 +503,12 @@ def _folderSelectionChanged(self): def checkForUpdate(self): """Check if there are any new versions available.""" - class _Thread(QtCore.QThread): - def __init__(self, parent, func): - super(_Thread, self).__init__(parent) - self._func = func - self._result = None - - def run(self): - try: - self._result = self._func() - except Exception as error: - logger.exception(error) - - def result(self): - return self._result - if studiolibrary.config.get("checkForUpdateEnabled"): - self._checkForUpdateThread = _Thread(self, studiolibrary.isLatestRelease) - self._checkForUpdateThread.finished.connect(self.checkForUpdateFinished) - self._checkForUpdateThread.start() + studiolibrary.isLatestRelease(callback=self.checkForUpdateFinished) - def checkForUpdateFinished(self): + def checkForUpdateFinished(self, isReleaseLatest): """Triggered when the check for update thread has finished.""" - if self._checkForUpdateThread.result(): + if isReleaseLatest: self._updateAvailableButton.show() else: self._updateAvailableButton.hide() diff --git a/src/studiolibrary/utils.py b/src/studiolibrary/utils.py index ac0d6d9c..aae006ea 100644 --- a/src/studiolibrary/utils.py +++ b/src/studiolibrary/utils.py @@ -252,19 +252,24 @@ def setLibraries(libraries): removeLibrary(name) -def isLatestRelease(): +def isLatestRelease(callback=None): + thread = threading.Thread(target=_isLatestRelease, args=(callback,)) + thread.start() + + +def _isLatestRelease(callback=None): """ Check if the installed version of the Studio Library is the latest. :rtype: bool """ - return False - url = "https://api.github.com/repos/krathjen/studiolibrary/releases/latest" + try: f = urllib.request.urlopen(url) result = json.load(f) except Exception: + callback(False) return False if result: @@ -273,13 +278,16 @@ def isLatestRelease(): # Ignore beta releases if the current version is not beta if "b" in latestVersion and "b" not in currentVersion: + callback(False) return False v1 = distutils.version.LooseVersion(latestVersion) v2 = distutils.version.LooseVersion(currentVersion) + callback(v1 > v2) return v1 > v2 + callback(False) return False @@ -1309,15 +1317,15 @@ def timeAgo(timeStamp): if secondsDiff < 10: return "just now" if secondsDiff < 60: - return str(secondsDiff) + " seconds ago" + return "{:.0f} seconds ago".format(secondsDiff) if secondsDiff < 120: return "a minute ago" if secondsDiff < 3600: - return str(secondsDiff / 60) + " minutes ago" + return "{:.0f} minutes ago".format(secondsDiff / 60) if secondsDiff < 7200: return "an hour ago" if secondsDiff < 86400: - return str(secondsDiff / 3600) + " hours ago" + return "{:.0f} hours ago".format(secondsDiff / 3600) if dayDiff == 1: return "yesterday"