-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcm_prefs.py
236 lines (195 loc) · 8.17 KB
/
cm_prefs.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Copyright 2017 CrowdMaster Developer Team
#
# ##### BEGIN GPL LICENSE BLOCK ######
# This file is part of CrowdMaster.
#
# CrowdMaster 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 3 of the License, or
# (at your option) any later version.
#
# CrowdMaster 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 CrowdMaster. If not, see <http://www.gnu.org/licenses/>.
# ##### END GPL LICENSE BLOCK #####
import logging
import os
import bpy
from bpy.props import BoolProperty, EnumProperty, IntProperty
from bpy.types import AddonPreferences, Operator
from . import addon_updater_ops
from .cm_iconLoad import cicon
logger = logging.getLogger("CrowdMaster")
class CMSavePrefs(Operator):
"""Save the CrowdMaster preferences """
bl_idname = "scene.cm_save_prefs"
bl_label = "Save Settings"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.wm.save_userpref()
return {'FINISHED'}
def updateLogger(self, context):
preferences = context.user_preferences.addons[__package__].preferences
if preferences.show_debug_options:
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
else:
logging.basicConfig(level=logging.INFO, format='%(message)s')
class CMPreferences(AddonPreferences):
bl_idname = __package__
scriptdir = bpy.path.abspath(os.path.dirname(__file__))
auto_check_update = BoolProperty(
name="Auto-check for Update",
description="If enabled, auto-check for updates using an interval",
default=True,
)
updater_intrval_months = IntProperty(
name='Months',
description="Number of months between checking for updates",
default=0,
min=0
)
updater_intrval_days = IntProperty(
name='Days',
description="Number of days between checking for updates",
default=5,
min=0,
)
updater_intrval_hours = IntProperty(
name='Hours',
description="Number of hours between checking for updates",
default=0,
min=0,
max=23
)
updater_intrval_minutes = IntProperty(
name='Minutes',
description="Number of minutes between checking for updates",
default=0,
min=0,
max=59
)
use_custom_icons = BoolProperty(
name="Use Custom Icons",
description="Chose whether to use the custom icons that come with the addon or not.",
default=True,
)
show_debug_options = BoolProperty(
name="Show Debug Options",
description="Chose whether to show the debug options in the interface. This also enables debug mode.",
default=False,
update=updateLogger,
)
show_debug_timings = BoolProperty(
name="Show Debug Timings",
description="Time and print to console the times taken by elements of the system.",
default=False,
)
play_animation = BoolProperty(
name="Start Animation Automatically",
description="Start and stop the animation automatically when the start and stop sim buttons are pressed.",
default=True,
)
ask_to_save = BoolProperty(
name="Ask To Save",
description="Chose whether the current file has to be saved or not before simulating or generating.",
default=True,
)
use_node_color = BoolProperty(
name="Use Node Color",
description="Choose whether or not to show the node info colors while simulating.",
default=True,
)
prefs_tab_items = [
("GEN", "General Settings", "General settings for the addon."),
("UPDATE", "Addon Update Settings", "Settings for the addon updater."),
("DEBUG", "Debug Options", "Debug settings and utilities.")]
prefs_tab = EnumProperty(name="Options Set", items=prefs_tab_items)
def draw(self, context):
layout = self.layout
preferences = context.user_preferences.addons[__package__].preferences
row = layout.row()
row.prop(preferences, "prefs_tab", expand=True)
if preferences.prefs_tab == "GEN":
row = layout.row()
row.prop(preferences, 'use_custom_icons', icon_value=cicon('plug'))
if preferences.use_custom_icons:
row.prop(preferences, 'play_animation',
icon_value=cicon('shuffle'))
else:
row.prop(preferences, 'play_animation', icon='ACTION')
row = layout.row()
row.prop(preferences, 'ask_to_save', icon='SAVE_AS')
row.prop(preferences, 'use_node_color', icon='COLOR')
row = layout.row()
if preferences.use_custom_icons:
row.prop(preferences, 'show_debug_options',
icon_value=cicon('code'))
else:
row.prop(preferences, 'show_debug_options',
icon='RECOVER_AUTO')
if preferences.prefs_tab == "UPDATE":
layout.row()
addon_updater_ops.update_settings_ui(self, context)
if preferences.prefs_tab == "DEBUG":
if preferences.show_debug_options:
row = layout.row()
row.scale_y = 1.25
row.operator("scene.cm_run_short_tests", icon='CONSOLE')
#row = layout.row()
#row.scale_y = 1.25
#row.operator("scene.cm_run_long_tests", icon='QUIT')
row = layout.row()
row.scale_y = 1.25
row.prop(preferences, 'show_debug_timings', icon='TIME')
else:
row = layout.row()
row.label(
"Enable Show Debug Options to access these settings (only for developers).")
row = layout.row()
if preferences.use_custom_icons:
row.prop(preferences, 'show_debug_options',
icon_value=cicon('code'))
else:
row.prop(preferences, 'show_debug_options',
icon='RECOVER_AUTO')
box = layout.box()
row = box.row(align=True)
row.scale_y = 1.2
if preferences.use_custom_icons:
row.operator("wm.url_open", text="Our Website", icon_value=cicon(
'house')).url = "http://crowdmaster.org/"
row.operator("wm.url_open", text="Email Us", icon_value=cicon(
'email')).url = "mailto:[email protected]"
else:
row.operator("wm.url_open", text="Our Website",
icon='URL').url = "http://crowdmaster.org/"
row.operator("wm.url_open", text="Email Us",
icon='URL').url = "mailto:[email protected]"
row = box.row()
row.scale_y = 1.25
row.operator("scene.cm_save_prefs", icon='SAVE_PREFS')
def draw_cmweb_item(self, context):
preferences = context.user_preferences.addons[__package__].preferences
self.layout.separator()
if preferences.use_custom_icons:
self.layout.operator("wm.url_open", text="CrowdMaster Website", icon_value=cicon(
'house'),).url = "http://crowdmaster.org/"
self.layout.operator("wm.url_open", text="CrowdMaster Email", icon_value=cicon(
'email'),).url = "mailto:[email protected]"
else:
self.layout.operator("wm.url_open", text="Our Website",
icon='URL').url = "http://crowdmaster.org/"
self.layout.operator("wm.url_open", text="Email Us",
icon='URL').url = "mailto:[email protected]"
def register():
bpy.utils.register_class(CMSavePrefs)
bpy.utils.register_class(CMPreferences)
bpy.types.INFO_MT_help.append(draw_cmweb_item)
def unregister():
bpy.utils.unregister_class(CMSavePrefs)
bpy.utils.unregister_class(CMPreferences)
bpy.types.INFO_MT_help.remove(draw_cmweb_item)