forked from CGCookie/blender-addon-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
160 lines (128 loc) · 4.87 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# ##### 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, neomonkeus",
"version": (1, 1, 1),
"blender": (2, 80, 0),
"location": "View 3D > Tool Shelf > Demo Updater",
"warning": "",
"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_DemoUpdaterPanel_hello"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS' if bpy.app.version < (2, 80) else 'UI'
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(text="Demo Updater Addon")
layout.label(text="")
col = layout.column()
col.scale_y = 0.7
col.label(text="If an update is ready,")
col.label(text="popup triggered by opening")
col.label(text="this panel, plus a box ui")
# Could also use your own custom drawing based on shared variables.
if addon_updater_ops.updater.update_ready:
layout.label(text="Custom update message", icon="INFO")
layout.label(text="")
# Call built-in function with draw code/checks.
addon_updater_ops.update_notice_box_ui(self, context)
@addon_updater_ops.make_annotations
class DemoPreferences(bpy.types.AddonPreferences):
"""Demo bare-bones preferences"""
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_interval_months = bpy.props.IntProperty(
name='Months',
description="Number of months between checking for updates",
default=0,
min=0)
updater_interval_days = bpy.props.IntProperty(
name='Days',
description="Number of days between checking for updates",
default=7,
min=0,
max=31)
updater_interval_hours = bpy.props.IntProperty(
name='Hours',
description="Number of hours between checking for updates",
default=0,
min=0,
max=23)
updater_interval_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
# 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
# ops = col.operator("wm.url_open","Open webpage ")
# ops.url=addon_updater_ops.updater.website
classes = (
DemoPreferences,
DemoUpdaterPanel
)
def register():
# Addon updater code and configurations.
# In case of a 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.
for cls in classes:
addon_updater_ops.make_annotations(cls) # Avoid blender 2.8 warnings.
bpy.utils.register_class(cls)
def unregister():
# Addon updater unregister.
addon_updater_ops.unregister()
for cls in reversed(classes):
bpy.utils.unregister_class(cls)