Skip to content

Commit

Permalink
Version 2.9.11
Browse files Browse the repository at this point in the history
- Enable isLatestRelease
- Change isLatestRelease to use threading.Thread instead of QThread
- Fix timeAgo format
- Add studiolibrary.config.set(name, value)
  • Loading branch information
krathjen committed Feb 27, 2023
1 parent b93e1f1 commit 4624b73
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/studiolibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.

__version__ = "2.9.10"
__version__ = "2.9.11"


def version():
Expand Down
10 changes: 10 additions & 0 deletions src/studiolibrary/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/studiolibrary/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 4 additions & 20 deletions src/studiolibrary/librarywindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
20 changes: 14 additions & 6 deletions src/studiolibrary/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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


Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4624b73

Please sign in to comment.