Cleanup: quiet float argument to in type warning
[blender-addons.git] / mesh_snap_utilities_line / preferences.py
blob3b04b9da3ea4b27053fd3bb9d41721b256b46419
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
5 from bpy.props import (
6 EnumProperty,
7 StringProperty,
8 BoolProperty,
9 IntProperty,
10 FloatVectorProperty,
11 FloatProperty,
14 from bpy.app.translations import contexts as i18n_contexts
16 import rna_keymap_ui
19 class SnapUtilitiesPreferences(bpy.types.AddonPreferences):
20 # this must match the addon name, use '__package__'
21 # when defining this in a submodule of a python package.
22 bl_idname = __package__
24 intersect: BoolProperty(
25 name="Intersect",
26 description="intersects created line with the existing edges, even if the lines do not intersect",
27 default=True)
29 create_face: BoolProperty(name="Create faces",
30 description="Create faces defined by enclosed edges",
31 default=False)
33 outer_verts: BoolProperty(name="Snap to outer vertices",
34 description="The vertices of the objects are not activated also snapped",
35 default=True)
37 increments_grid: BoolProperty(name="Increments of Grid",
38 description="Snap to increments of grid",
39 default=False)
41 auto_constrain: BoolProperty(name="Automatic Constraint",
42 description="Detects a direction to constrain depending on the position of the mouse",
43 default=False)
45 incremental: FloatProperty(name="Incremental",
46 description="Snap in defined increments",
47 default=0,
48 min=0,
49 step=1,
50 precision=3)
52 relative_scale: FloatProperty(name="Relative Scale",
53 description="Value that divides the global scale",
54 default=1,
55 min=0,
56 step=1,
57 precision=3)
59 out_color: FloatVectorProperty(name="Floor",
60 default=(0.0, 0.0, 0.0, 0.5),
61 size=4,
62 subtype="COLOR",
63 min=0,
64 max=1)
66 face_color: FloatVectorProperty(name="Face Highlighted",
67 default=(1.0, 0.8, 0.0, 0.5),
68 size=4,
69 subtype="COLOR",
70 min=0,
71 max=1)
73 edge_color: FloatVectorProperty(name="Edge Highlighted",
74 default=(0.0, 0.8, 1.0, 0.5),
75 size=4,
76 subtype="COLOR",
77 min=0,
78 max=1)
80 vert_color: FloatVectorProperty(name="Vertex Highlighted",
81 default=(1.0, 0.5, 0.0, 0.5),
82 size=4, subtype="COLOR",
83 min=0,
84 max=1)
86 center_color: FloatVectorProperty(name="Middle of the Edge",
87 default=(1.0, 0.0, 1.0, 1.0),
88 size=4,
89 subtype="COLOR",
90 min=0,
91 max=1)
93 perpendicular_color: FloatVectorProperty(name="Perpendicular Point",
94 default=(0.1, 0.5, 0.5, 1.0),
95 size=4,
96 subtype="COLOR",
97 min=0,
98 max=1)
100 constrain_shift_color: FloatVectorProperty(name="Shift Constrain",
101 default=(0.8, 0.5, 0.4, 1.0),
102 size=4,
103 subtype="COLOR",
104 min=0,
105 max=1)
107 tabs: EnumProperty(name="Tabs",
108 items=[("GENERAL", "General", ""),
109 ("KEYMAPS", "Keymaps", ""),
110 ("COLORS", "Colors", ""),
111 ("HELP", "Links", ""), ],
112 default="GENERAL")
114 def draw(self, context):
115 layout = self.layout
117 # TAB BAR
118 row = layout.row()
119 row.prop(self, "tabs", expand=True)
121 box = layout.box()
123 if self.tabs == "GENERAL":
124 self.draw_general(box)
126 elif self.tabs == "COLORS":
127 self.draw_snap_utilities_colors(box)
129 elif self.tabs == "KEYMAPS":
130 self.draw_snap_utilities_keymaps(context, box)
132 elif self.tabs == "HELP":
133 self.draw_snap_utilities_help(box)
135 def draw_general(self, layout):
136 row = layout.row()
137 col = row.column()
139 col.label(text="Snap Properties:")
140 col.prop(self, "incremental")
141 col.prop(self, "increments_grid")
142 if self.increments_grid:
143 col.prop(self, "relative_scale")
145 col.prop(self, "outer_verts")
146 row.separator()
148 col = row.column()
149 col.label(text="Line Tool:")
150 col.prop(self, "intersect")
151 col.prop(self, "create_face")
153 def draw_snap_utilities_colors(self, layout):
154 layout.use_property_split = True
156 flow = layout.grid_flow(
157 row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
159 flow.prop(self, "out_color")
160 flow.prop(self, "constrain_shift_color")
161 flow.prop(self, "face_color")
162 flow.prop(self, "edge_color")
163 flow.prop(self, "vert_color")
164 flow.prop(self, "center_color")
165 flow.prop(self, "perpendicular_color")
167 def draw_snap_utilities_help(self, layout):
168 # layout.operator("wm.url_open", text="Gumroad Page", icon='HELP',).url = "https://gum.co/IaqQf"
169 # layout.operator("wm.url_open", text="Blender Market Page", icon='HELP',).url = "https://blendermarket.com/products/snap-utilities"
170 layout.operator("wm.url_open", text="Wiki", icon='HELP',
171 ).url = "https://github.com/Mano-Wii/Addon-Snap-Utilities-Line/wiki"
172 layout.operator("wm.url_open", text="Forum", icon='HELP',
173 ).url = "https://blenderartists.org/t/cad-snap-utilities"
175 def draw_snap_utilities_keymaps(self, context, layout):
176 from .keys import (
177 generate_snap_utilities_global_keymaps,
178 generate_snap_utilities_tools_keymaps,
181 wm = context.window_manager
182 # kc = wm.keyconfigs.addon
183 kc = wm.keyconfigs.user
185 layout.label(text="Global:")
187 for km_name, km_args, km_content in generate_snap_utilities_global_keymaps():
188 km = kc.keymaps.get(km_name)
189 if km:
190 self.draw_snap_utilities_km(kc, km, layout)
192 layout.label(text="Tools:")
194 for km_name, km_args, km_content in generate_snap_utilities_tools_keymaps():
195 km = kc.keymaps.get(km_name)
196 if km:
197 self.draw_snap_utilities_km(kc, km, layout)
199 @staticmethod
200 def draw_snap_utilities_km(kc, km, layout):
201 layout.context_pointer_set("keymap", km)
203 row = layout.row()
204 row.prop(km, "show_expanded_items", text="", emboss=False)
205 row.label(text=km.name, text_ctxt=i18n_contexts.id_windowmanager)
207 if km.show_expanded_items:
208 col = layout.column()
210 for kmi in km.keymap_items:
211 if "snap_utilities" in kmi.idname:
212 rna_keymap_ui.draw_kmi(
213 ["ADDON", "USER", "DEFAULT"], kc, km, kmi, col, 0)