Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
feat: property in the prefs to check for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
werwack committed Jun 22, 2022
1 parent aa0817c commit b16a6db
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-----
## 1.3.5 (2022-06-22)
- Added a preference property to toggle the check for updates

-----
## 1.3.1 (2022-06-02)
- Code refactor to allow more flexibility on the use of rendering resolution for Shot Manager
Expand Down
4 changes: 2 additions & 2 deletions stampinfo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"author": "Julien Blervaque (aka Werwack) - Ubisoft",
"description": "Stamp scene information on the rendered images",
"blender": (3, 1, 0),
"version": (1, 3, 1),
"version": (1, 3, 5),
"location": "View3D > Stamp Info",
"wiki_url": "https://ubisoft-stampinfo.readthedocs.io",
"doc_url": "https://ubisoft-stampinfo.readthedocs.io",
"tracker_url": "https://github.com/ubisoft/stampinfo/issues",
"support": "COMMUNITY",
# "warning": "BETA Version",
Expand Down
49 changes: 34 additions & 15 deletions stampinfo/addon_prefs/addon_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
from stampinfo.utils import utils
from stampinfo.utils.utils_os import get_latest_release_version

# from ..config import config

from stampinfo.config import config
from stampinfo.config import sm_logging

_logger = sm_logging.getLogger(__name__)
Expand Down Expand Up @@ -57,32 +56,52 @@ def version(self):
description="Store the version of the latest release of the add-on as an integer if there is an online release"
"\nthat is more recent than this version. If there is none then the value is 0",
# default=2005001,
default=1007016,
default=1000000,
)

checkForNewAvailableVersion: BoolProperty(
name="Check for Updates",
description=(
"If checked then the add-on automaticaly see if a new release\n"
"is available online, and if so then a red world icon is displayed at the\n"
"top right corner of the main panel"
),
default=True,
)

isInitialized: BoolProperty(
name="Preferences Initialization State",
description=(
"Flag to validate that Stamp Info preferences have been correctly initialized"
"\nThis flag can be changed for debug purpose: activate the debug mode and go to the add-on Preferences, in the Debug tab"
),
default=False,
)

def initialize_stamp_info_prefs(self):
print("\nInitializing Stamp Info Preferences...")

versionStr = get_latest_release_version("https://github.com/ubisoft/stampinfo/releases/latest", verbose=True)

if versionStr is not None:
# version string from the tags used by our releases on GitHub is formated as this: v<int>.<int>.<int>
version = utils.convertVersionStrToInt(versionStr)
self.newAvailableVersion = 0

_logger.debug_ext(
f"Checking for updates: Latest version of Ubisoft Stamp Info online is: {versionStr}", col="BLUE"
if self.checkForNewAvailableVersion and not config.devDebug:
versionStr = get_latest_release_version(
"https://github.com/ubisoft/stampinfo/releases/latest", verbose=True
)
if self.version()[1] < version:
_logger.debug_ext(" New version available online...", col="BLUE")
self.newAvailableVersion = version

if versionStr is not None:
# version string from the tags used by our releases on GitHub is formated as this: v<int>.<int>.<int>
version = utils.convertVersionStrToInt(versionStr)

_logger.debug_ext(
f"Checking for updates: Latest version of Ubisoft Stamp Info online is: {versionStr}", col="BLUE"
)
if self.version()[1] < version:
_logger.debug_ext(" New version available online...", col="BLUE")
self.newAvailableVersion = version
else:
self.newAvailableVersion = 0
else:
self.newAvailableVersion = 0
else:
self.newAvailableVersion = 0

self.isInitialized = True

Expand Down
44 changes: 40 additions & 4 deletions stampinfo/addon_prefs/addon_prefs_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def draw_addon_prefs(self, context):
layout = self.layout
# layout = layout.column(align=False)

# Dependencies
###############
drawDependencies(context, layout)

# General
###############

splitFactor = 0.3

box = layout.box()
Expand All @@ -40,6 +47,11 @@ def draw_addon_prefs(self, context):
subCol.prop(self, "display_main_panel", text="Display Stamp Info panel in the 3D View tabs")
subCol.prop(self, "write_still")

drawGeneral(context, self, layout)

# Technical settings
###############

layout.separator(factor=0.5)
layout.label(text="Technical Settings:")
box = layout.box()
Expand All @@ -50,10 +62,6 @@ def draw_addon_prefs(self, context):
subCol.prop(self, "delete_temp_scene")
subCol.prop(self, "delete_temp_images")

# Dependencies
###############
drawDependencies(context, layout)

# Dev and debug
###############
box = layout.box()
Expand All @@ -79,3 +87,31 @@ def draw_addon_prefs(self, context):
rowRight.operator("uas_stamp_info.enable_debug", text="Turn Off").enable_debug = False
else:
rowRight.operator("uas_stamp_info.enable_debug", text="Turn On").enable_debug = True

if config.devDebug:
# initialization state
initRow = box.row()
initRow.prop(self, "isInitialized")


##################################################################
# Draw functions
##################################################################


def drawGeneral(context, prefs, layout):
box = layout.box()
# collapsable_panel(box, prefs, "addonPrefs_ui_expanded", text="UI")
# if prefs.addonPrefs_ui_expanded:
uiSplitFactor = 0.15

# column component here is technicaly not necessary but reduces the space between lines
col = box.column()

# split = col.split(factor=uiSplitFactor)
# rowLeft = split.row()
# rowLeft.separator()
# rowRight = split.row()
row = col.row()
row.separator(factor=3)
row.prop(prefs, "checkForNewAvailableVersion", text="Check for Updates")
2 changes: 1 addition & 1 deletion stampinfo/ui/dependencies_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ def drawDependencies(context, layout: bpy.types.UILayout, **kwargs):
subRow.alert = True
subRow.label(text="Module not found - Add-on cannot run normally")

box.separator()
box.separator(factor=0.2)
1 change: 1 addition & 0 deletions stampinfo/ui/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def draw(self, context):
row = layout.row(align=True)
row.operator("preferences.addon_show", text="Add-on Preferences...", icon="PREFERENCES").module = "stampinfo"

layout.separator()
row = layout.row(align=True)
row.operator(
"stampinfo.open_documentation_url", text="Documentation", icon="HELP"
Expand Down
2 changes: 1 addition & 1 deletion stampinfo/ui/si_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def draw_header_preset(self, context):
row.separator(factor=2)
row.menu("UAS_MT_StampInfo_prefs_mainmenu", icon="PREFERENCES", text="")

if prefs.newAvailableVersion:
if not config.devDebug and prefs.checkForNewAvailableVersion and prefs.newAvailableVersion:
row.separator(factor=0.5)
subRow = row.row()
subRow.alert = True
Expand Down

0 comments on commit b16a6db

Please sign in to comment.