| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  | # ##### 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 ##### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # <pep8 compliant> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import bpy as _bpy | 
					
						
							|  |  |  | import bpyml | 
					
						
							| 
									
										
										
										
											2017-11-29 18:00:41 +11:00
										 |  |  | from bpyml import ( | 
					
						
							|  |  |  |     TAG, | 
					
						
							|  |  |  |     ARGS, | 
					
						
							|  |  |  |     CHILDREN, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | _uilayout_rna = _bpy.types.UILayout.bl_rna | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-08 01:32:34 +00:00
										 |  |  | _uilayout_tags = ( | 
					
						
							|  |  |  |     ["ui"] + | 
					
						
							|  |  |  |     _uilayout_rna.properties.keys() + | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  |     _uilayout_rna.functions.keys() | 
					
						
							| 
									
										
										
										
											2017-11-29 18:00:41 +11:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # these need to be imported directly | 
					
						
							|  |  |  | # >>> from bpyml_ui.locals import * | 
					
						
							| 
									
										
										
										
											2010-09-07 15:17:42 +00:00
										 |  |  | locals = bpyml.tag_module("%s.locals" % __name__, _uilayout_tags) | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _parse_rna(prop, value): | 
					
						
							|  |  |  |     if prop.type == 'FLOAT': | 
					
						
							|  |  |  |         value = float(value) | 
					
						
							|  |  |  |     elif prop.type == 'INT': | 
					
						
							|  |  |  |         value = int(value) | 
					
						
							|  |  |  |     elif prop.type == 'BOOLEAN': | 
					
						
							| 
									
										
										
										
											2011-08-08 05:21:37 +00:00
										 |  |  |         if value in {True, False}: | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  |             pass | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2011-08-08 05:21:37 +00:00
										 |  |  |             if value not in {"True", "False"}: | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  |                 raise Exception("invalid bool value: %s" % value) | 
					
						
							|  |  |  |             value = bool(value == "True") | 
					
						
							| 
									
										
										
										
											2011-08-08 05:21:37 +00:00
										 |  |  |     elif prop.type in {'STRING', 'ENUM'}: | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  |         pass | 
					
						
							|  |  |  |     elif prop.type == 'POINTER': | 
					
						
							|  |  |  |         value = eval("_bpy." + value) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         raise Exception("type not supported %s.%s" % (prop.identifier, prop.type)) | 
					
						
							|  |  |  |     return value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _parse_rna_args(base, py_node): | 
					
						
							|  |  |  |     rna_params = base.bl_rna.functions[py_node[TAG]].parameters | 
					
						
							|  |  |  |     args = {} | 
					
						
							|  |  |  |     for key, value in py_node[ARGS].items(): | 
					
						
							|  |  |  |         args[key] = _parse_rna(rna_params[key], value) | 
					
						
							|  |  |  |     return args | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _call_recursive(context, base, py_node): | 
					
						
							| 
									
										
										
										
											2011-04-01 02:41:15 +00:00
										 |  |  |     # prop = base.bl_rna.properties.get(py_node[TAG]) | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  |     if py_node[TAG] in base.bl_rna.properties: | 
					
						
							|  |  |  |         value = py_node[ARGS].get("expr") | 
					
						
							|  |  |  |         if value: | 
					
						
							|  |  |  |             value = eval(value, {"context": _bpy.context}) | 
					
						
							|  |  |  |             setattr(base, py_node[TAG], value) | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2012-06-19 22:17:19 +00:00
										 |  |  |             value = py_node[ARGS]["value"]  # have to have this | 
					
						
							| 
									
										
										
										
											2011-04-01 02:41:15 +00:00
										 |  |  |             setattr(base, py_node[TAG], value) | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  |     else: | 
					
						
							|  |  |  |         args = _parse_rna_args(base, py_node) | 
					
						
							|  |  |  |         func_new = getattr(base, py_node[TAG]) | 
					
						
							| 
									
										
										
										
											2010-09-07 15:17:42 +00:00
										 |  |  |         base_new = func_new(**args)  # call blender func | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  |         if base_new is not None: | 
					
						
							|  |  |  |             for py_node_child in py_node[CHILDREN]: | 
					
						
							|  |  |  |                 _call_recursive(context, base_new, py_node_child) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 15:35:06 +11:00
										 |  |  | class BPyML_BaseUI: | 
					
						
							| 
									
										
										
										
											2012-07-03 09:02:41 +00:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  |     This is a mix-in class that defines a draw function | 
					
						
							|  |  |  |     which checks for draw_data | 
					
						
							| 
									
										
										
										
											2012-07-03 09:02:41 +00:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2010-08-11 15:11:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def draw(self, context): | 
					
						
							|  |  |  |         layout = self.layout | 
					
						
							|  |  |  |         for py_node in self.draw_data[CHILDREN]: | 
					
						
							|  |  |  |             _call_recursive(context, layout, py_node) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def draw_header(self, context): | 
					
						
							|  |  |  |         layout = self.layout | 
					
						
							|  |  |  |         for py_node in self.draw_header_data[CHILDREN]: | 
					
						
							|  |  |  |             _call_recursive(context, layout, py_node) |