-
Notifications
You must be signed in to change notification settings - Fork 3
/
ui.py
139 lines (102 loc) · 4.15 KB
/
ui.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
# SPDX-FileCopyrightText: 2020-2024 Mikhail Rachinskiy
# SPDX-License-Identifier: GPL-3.0-or-later
import bpy
from bpy.types import Panel, PropertyGroup, UILayout
from . import problemlib, var
def upd_problems_popover_width():
if bpy.app.translations.locale == "ru_RU":
width = 15
else:
width = 12
if VIEW3D_PT_sidekick_problems.bl_ui_units_x == width:
return
VIEW3D_PT_sidekick_problems.bl_ui_units_x = width
bpy.utils.unregister_class(VIEW3D_PT_sidekick_problems)
bpy.utils.register_class(VIEW3D_PT_sidekick_problems)
def draw_3dview_header(self, context):
row = self.layout.row(align=True)
row.prop(context.window_manager.sidekick, "show_problems", text="", icon="ERROR")
row.popover(panel="VIEW3D_PT_sidekick_problems", text="")
def draw_object_context_menu(self, context):
layout = self.layout
layout.operator_context = "INVOKE_DEFAULT"
layout.separator()
layout.operator("object.sidekick_ignore")
class VIEW3D_PT_sidekick_problems(Panel):
bl_label = "Problems"
bl_space_type = "VIEW_3D"
bl_region_type = "HEADER"
bl_context = "objectmode"
bl_ui_units_x = 12
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
layout.label(text="Problems")
if var.Report.problems:
col = layout.column()
for problem in var.Report.problems:
row = col.row()
row1 = row.row()
row1.alignment = "LEFT"
row1.operator(
"wm.sidekick_show_description",
text=problem.title,
icon="CANCEL" if problem.type is problemlib.TYPE_ERROR else "ERROR",
emboss=False,
).code = problem.code
if problem.select:
row2 = row.row()
row2.alignment = "RIGHT"
row2.operator("object.sidekick_select", text="", icon="RESTRICT_SELECT_OFF", emboss=False).code = problem.code
else:
box = layout.box()
box.label(text="No problems found")
if var.Report.problems_ignored:
layout.separator()
layout.label(text="Ignored")
col = layout.column()
col.active = False
for problem in var.Report.problems_ignored:
row = col.row()
row1 = row.row()
row1.alignment = "LEFT"
row1.operator(
"wm.sidekick_show_description",
text=problem.title,
icon="CANCEL" if problem.type is problemlib.TYPE_ERROR else "ERROR",
emboss=False,
).code = problem.code
if problem.select:
row2 = row.row()
row2.alignment = "RIGHT"
op = row2.operator("object.sidekick_select", text="", icon="RESTRICT_SELECT_OFF", emboss=False)
op.code = problem.code
op.use_ignored = True
# Preferences
# ---------------------------
def _prop_panel(layout: UILayout, data: PropertyGroup, prop: str) -> bool:
enabled = getattr(data, prop)
sub = layout.row()
sub.use_property_split = False
sub.alignment = "LEFT"
sub.prop(data, prop, icon="DOWNARROW_HLT" if enabled else "RIGHTARROW", emboss=False)
return enabled
def prefs_ui(self, context):
wm_props = context.window_manager.sidekick
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
main = layout.column()
if _prop_panel(main, wm_props, "prefs_show_interface"):
main.prop(self, "overlay_style")
if _prop_panel(main, wm_props, "prefs_show_problems"):
for code in problemlib.coll.keys():
if code == 101:
col = main.column(heading="Object")
elif code == 201:
col = main.column(heading="Relations")
elif code == 301:
col = main.column(heading="Object Data")
elif code == 401:
col = main.column(heading="Scene")
col.prop(self, f"problem_{code}")