Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
160 lines (130 sloc) 4.82 KB
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Addon Updater Demo",
"description": "Demo addon for showcasing the blender-addon-updater module",
"author": "Patrick W. Crawford",
"version": (1, 0, 6),
"blender": (2, 7, 8),
"location": "View 3D > Tool Shelf > Demo Updater",
"warning": "", # used for warning icon and text in addons panel
"wiki_url": "https://github.com/CGCookie/blender-addon-updater",
"tracker_url": "https://github.com/CGCookie/blender-addon-updater/issues",
"category": "System"
}
import bpy
# updater ops import, all setup in this file
from . import addon_updater_ops
class DemoUpdaterPanel(bpy.types.Panel):
"""Panel to demo popup notice and ignoring functionality"""
bl_label = "Updater Demo Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_context = "objectmode"
bl_category = "Tools"
def draw(self, context):
layout = self.layout
# Call to check for update in background
# note: built-in checks ensure it runs at most once
# and will run in the background thread, not blocking
# or hanging blender
# Internally also checks to see if auto-check enabled
# and if the time interval has passed
addon_updater_ops.check_for_update_background()
layout.label("Demo Updater Addon")
layout.label("")
col = layout.column()
col.scale_y = 0.7
col.label("If an update is ready,")
col.label("popup triggered by opening")
col.label("this panel, plus a box ui")
# could also use your own custom drawing
# based on shared variables
if addon_updater_ops.updater.update_ready == True:
layout.label("Custom update message", icon="INFO")
layout.label("")
# call built-in function with draw code/checks
addon_updater_ops.update_notice_box_ui(self, context)
# demo bare-bones preferences
class DemoPreferences(bpy.types.AddonPreferences):
bl_idname = __package__
# addon updater preferences
auto_check_update = bpy.props.BoolProperty(
name="Auto-check for Update",
description="If enabled, auto-check for updates using an interval",
default=False,
)
updater_intrval_months = bpy.props.IntProperty(
name='Months',
description="Number of months between checking for updates",
default=0,
min=0
)
updater_intrval_days = bpy.props.IntProperty(
name='Days',
description="Number of days between checking for updates",
default=7,
min=0,
max=31
)
updater_intrval_hours = bpy.props.IntProperty(
name='Hours',
description="Number of hours between checking for updates",
default=0,
min=0,
max=23
)
updater_intrval_minutes = bpy.props.IntProperty(
name='Minutes',
description="Number of minutes between checking for updates",
default=0,
min=0,
max=59
)
def draw(self, context):
layout = self.layout
# col = layout.column() # works best if a column, or even just self.layout
mainrow = layout.row()
col = mainrow.column()
# updater draw function
# could also pass in col as third arg
addon_updater_ops.update_settings_ui(self, context)
# Alternate draw function, which is more condensed and can be
# placed within an existing draw function. Only contains:
# 1) check for update/update now buttons
# 2) toggle for auto-check (interval will be equal to what is set above)
# addon_updater_ops.update_settings_ui_condensed(self, context, col)
# Adding another column to help show the above condensed ui as one column
# col = mainrow.column()
# col.scale_y = 2
# col.operator("wm.url_open","Open webpage ").url=addon_updater_ops.updater.website
def register():
# addon updater code and configurations
# in case of broken version, try to register the updater first
# so that users can revert back to a working version
addon_updater_ops.register(bl_info)
# register the example panel, to show updater buttons
bpy.utils.register_class(DemoPreferences)
bpy.utils.register_class(DemoUpdaterPanel)
def unregister():
# addon updater unregister
addon_updater_ops.unregister()
# register the example panel, to show updater buttons
bpy.utils.unregister_class(DemoPreferences)
bpy.utils.unregister_class(DemoUpdaterPanel)