forked from hlorus/CAD_Sketcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.py
290 lines (241 loc) · 7.99 KB
/
preferences.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import sys
from pathlib import Path
import logging
import bpy
from bpy.types import AddonPreferences, Panel, Menu
from bl_ui.utils import PresetPanel
from bpy.props import (
PointerProperty,
BoolProperty,
StringProperty,
EnumProperty,
IntProperty,
FloatProperty,
)
from . import theme
from .. import global_data, units
from ..declarations import Operators
from ..utilities.register import get_path, get_name
from ..utilities.view import update_cb
log_levels = [
("CRITICAL", "Critical", "", 0),
("ERROR", "Error", "", 1),
("WARNING", "Warning", "", 2),
("INFO", "Info", "", 3),
("DEBUG", "Debug", "", 4),
("NOTSET", "Notset", "", 5),
]
logger = logging.getLogger(__name__)
def get_log_level(self):
prop = self.bl_rna.properties["logging_level"]
items = prop.enum_items
default_value = items[prop.default].value
item = items[self.get("logging_level", default_value)]
return item.value
def set_log_level(self, value):
items = self.bl_rna.properties["logging_level"].enum_items
item = items[value]
level = item.identifier
logger.info("setting log level: {}".format(item.name))
self["logging_level"] = level
logger.setLevel(level)
def get_wheel():
p = Path(__file__).parent.absolute()
from sys import platform, version_info
if platform == "linux" or platform == "linux2":
# Linux
platform_strig = "linux"
elif platform == "darwin":
# OS X
platform_strig = "macosx"
elif platform == "win32":
# Windows
platform_strig = "win"
matches = list(
p.glob(
"**/*cp{}{}*{}*.whl".format(
version_info.major, version_info.minor, platform_strig
)
)
)
if matches:
match = matches[0]
logger.info("Local installation file available: " + str(match))
return match.as_posix()
return ""
# Presets
class SKETCHER_PT_theme_presets(PresetPanel, Panel):
bl_label = "Theme Presets"
preset_subdir = "bgs/theme"
preset_operator = "script.execute_preset"
preset_add_operator = "bgs.theme_preset_add"
class SKETCHER_MT_theme_presets(Menu):
bl_label = "Theme Presets"
preset_subdir = "bgs/theme"
preset_operator = "script.execute_preset"
draw = Menu.draw_preset
class Preferences(AddonPreferences):
path = get_path()
bl_idname = get_name()
theme_settings: PointerProperty(type=theme.ThemeSettings)
show_debug_settings: BoolProperty(
name="Show Debug Settings",
default=False,
)
show_theme_settings: BoolProperty(
name="Show Theme Settings",
description="Expand this box to show various theme settings",
default=False,
)
package_path: StringProperty(
name="Package Filepath",
description="Filepath to the module's .whl file",
subtype="FILE_PATH",
default=get_wheel(),
)
logging_level: EnumProperty(
name="Logging Level",
items=log_levels,
get=get_log_level,
set=set_log_level,
default=2,
)
hide_inactive_constraints: BoolProperty(
name="Hide inactive Constraints", default=True, update=update_cb
)
all_entities_selectable: BoolProperty(
name="Make all Entities Selectable", update=update_cb
)
force_redraw: BoolProperty(name="Force Entity Redraw", default=True)
decimal_precision: IntProperty(
name="Decimal Precision",
description="Number of digits after the comma",
default=3,
min=0,
soft_max=7,
)
imperial_precision: units.imperial_precision_prop
angle_precision: IntProperty(
name="Angle Precision",
min=0,
max=5,
default=0,
description="Angle decimal precision",
)
auto_hide_objects: BoolProperty(
name="Auto Fade Objects",
description="Fade curves/meshes while in sketch mode",
default=True,
)
entity_scale: FloatProperty(
name="Entity Scale", default=1.0, min=0.1, soft_max=3.0, update=theme.update
)
workplane_size: FloatProperty(
name="Workplane Size", default=0.4, soft_min=0.1, soft_max=1.0
)
gizmo_scale: FloatProperty(
name="Icon Scale", default=15.0, min=1.0, soft_max=25.0, update=theme.update
)
text_size: IntProperty(name="Text Size", default=15, min=5, soft_max=25)
arrow_scale: FloatProperty(name="Arrow Scale", default=1, min=0.2, soft_max=3)
use_align_view: BoolProperty(
name="Align View",
description="Automatically align view to workplane when activating a sketch.",
default=False,
)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
box = layout.box()
box.label(text="Solver Module")
if global_data.registered:
box.label(text="Registered", icon="CHECKMARK")
module = sys.modules["py_slvs"]
box.label(text="Path: " + module.__path__[0])
else:
row = box.row()
row.label(text="Module isn't Registered", icon="CANCEL")
split = box.split(factor=0.8)
split.prop(self, "package_path", text="")
split.operator(
Operators.InstallPackage,
text="Install from File",
).package = self.package_path
row = box.row()
row.operator(
Operators.InstallPackage,
text="Install from PIP",
).package = "py-slvs"
box = layout.box()
box.label(text="General")
col = box.column(align=True)
col.prop(self, "auto_hide_objects")
if self.show_debug_settings:
col.prop(self, "use_align_view")
col.prop(self, "entity_scale")
col.prop(self, "workplane_size")
col.prop(self, "gizmo_scale")
col.prop(self, "text_size")
col.prop(self, "arrow_scale")
box = layout.box()
box.label(text="Units")
col = box.column(align=True)
col.prop(self, "decimal_precision")
col.prop(self, "imperial_precision")
col.prop(self, "angle_precision")
box = layout.box()
box.label(text="Advanced")
col = box.column(align=True)
col.prop(self, "show_debug_settings")
col.prop(self, "logging_level")
box = layout.box()
row = box.row()
row.use_property_split = False
subrow = row.row()
subrow.alignment = "LEFT"
subrow.prop(
self,
"show_theme_settings",
text="Theme",
emboss=False,
icon="TRIA_DOWN" if self.show_theme_settings else "TRIA_RIGHT",
)
subrow = row.row()
subrow.alignment = "RIGHT"
if global_data.registered:
SKETCHER_PT_theme_presets.draw_panel_header(subrow)
if self.show_theme_settings:
row = box.row()
row = box.row()
flow = row.grid_flow(
row_major=False,
columns=0,
even_columns=True,
even_rows=False,
align=False,
)
def list_props_recursiv(base):
for prop in base.rna_type.properties:
prop_name = prop.identifier
if prop_name in ("name", "rna_type"):
continue
row = flow.row()
if type(prop) == bpy.types.PointerProperty:
row.label(text=prop.name)
list_props_recursiv(getattr(base, prop_name))
else:
row.prop(base, prop_name)
list_props_recursiv(self.theme_settings)
classes = (
SKETCHER_MT_theme_presets,
SKETCHER_PT_theme_presets,
Preferences,
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)