From c2de89e35d4c0b3387826d51dc8073d24ba0b9b7 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sat, 15 Apr 2017 17:17:25 +0200 Subject: [PATCH 01/25] add base class for searchbox --- __init__.py | 2 +- ui/nodeview_keymaps.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 59d5dbc47..1e05b85e6 100755 --- a/__init__.py +++ b/__init__.py @@ -92,7 +92,7 @@ utils_modules = [ "text_editor_submenu", "text_editor_plugins", # UI operators and tools "sv_panels_tools", "sv_gist_tools", "sv_IO_panel_tools", "sv_load_zipped_blend", - "monad", "sv_help", + "monad", "sv_help", "sv_extra_search", #"loadscript", "debug_script", "sv_update_utils" ] diff --git a/ui/nodeview_keymaps.py b/ui/nodeview_keymaps.py index 838b1e482..6c6961293 100644 --- a/ui/nodeview_keymaps.py +++ b/ui/nodeview_keymaps.py @@ -51,6 +51,11 @@ def add_keymap(): kmi.properties.name = "NODEVIEW_MT_Dynamic_Menu" nodeview_keymaps.append((km, kmi)) + # TAB | enter or exit monad depending on selection and edit_tree type + kmi = km.keymap_items.new('node.sv_extra_search', 'RIGHT_BRACKET', 'PRESS', shift=True) + nodeview_keymaps.append((km, kmi)) + + def remove_keymap(): -- GitLab From 4ed716df4695b9b59372775aadba5260ec77958e Mon Sep 17 00:00:00 2001 From: zeffii Date: Sat, 15 Apr 2017 20:49:58 +0200 Subject: [PATCH 02/25] add faster search! --- utils/sv_extra_search.py | 81 ++++++++++++++++++++++++++++++++++ utils/sv_macro_utils.py | 94 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 utils/sv_extra_search.py create mode 100644 utils/sv_macro_utils.py diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py new file mode 100644 index 000000000..2fc36a041 --- /dev/null +++ b/utils/sv_extra_search.py @@ -0,0 +1,81 @@ +# ##### 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 ##### + + +import bpy + +import sverchok +import nodeitems_utils +from sverchok.menu import make_node_cats +from sverchok.ui.sv_icons import custom_icon +from nodeitems_utils import _node_categories + +sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} +node_cats = make_node_cats() +addon_name = sverchok.__name__ + + +def gather_items(): + fx = [] + idx = 0 + for catname, node_list in node_cats.items(): + for index, item in enumerate(node_list): + if item[0] in {'separator', 'NodeReroute'}: + continue + nodetype = getattr(bpy.types, item[0]) + fx.append((str(idx), nodetype.bl_label, nodetype.bl_rna.description, idx)) + idx += 1 + return fx + +loop = {} + +def item_cb(self, context): + return loop.get('results') + + +class SvExtraSearch(bpy.types.Operator): + """ Extra Search library """ + bl_idname = "node.sv_extra_search" + bl_label = "Extra Search" + bl_property = "my_enum" + + my_enum = bpy.props.EnumProperty(items=item_cb) + + def execute(self, context): + self.report({'INFO'}, "Selected: %s" % self.my_enum) + print(loop['results'][int(self.my_enum)]) + return {'FINISHED'} + + def invoke(self, context, event): + loop['results'] = gather_items() + wm = context.window_manager + wm.invoke_search_popup(self) + return {'FINISHED'} + + +classes = [SvExtraSearch,] + + +def register(): + for class_name in classes: + bpy.utils.register_class(class_name) + + +def unregister(): + for class_name in classes: + bpy.utils.unregister_class(class_name) diff --git a/utils/sv_macro_utils.py b/utils/sv_macro_utils.py new file mode 100644 index 000000000..f31a3d3a0 --- /dev/null +++ b/utils/sv_macro_utils.py @@ -0,0 +1,94 @@ +# ##### 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 ##### + +import re + +import bpy +from bpy.props import StringProperty + +import sverchok + + +# pylint: disable=w0141 +# pylint: disable=w0123 + +def convert_string_to_settings(arguments): + + # expects (varname=value,....) + # for example (selected_mode="int", fruits=20, alama=[0,0,0]) + def deform_args(**args): + return args + + unsorted_dict = eval('deform_args{arguments}'.format(**vars()), locals(), locals()) + pattern = r'(\w+\s*)=' + results = re.findall(pattern, arguments) + return [(varname, unsorted_dict[varname]) for varname in results] + + +class SvMacroInterpretter(bpy.types.Operator): + """ Launch menu item as a macro """ + bl_idname = "node.sv_macro_interpretter" + bl_label = "Sverchok check for new minor version" + bl_options = {'REGISTER'} + + macro_bl_idname = StringProperty() + settings = StringProperty() + + def create_node(self, context, node_type): + space = context.space_data + tree = space.edit_tree + + # select only the new node + for n in tree.nodes: + n.select = False + + node = tree.nodes.new(type=node_type) + + if self.settings: + settings = convert_string_to_settings(self.settings) + for name, value in settings: + try: + setattr(node, name, value) + except AttributeError as e: + self.report({'ERROR_INVALID_INPUT'}, "Node has no attribute " + name) + print(str(e)) + + node.select = True + tree.nodes.active = node + node.location = space.cursor_location + return node + + + def execute(self, context): + self.create_node(context, self.macro_bl_idname) + bpy.ops.node.translate_attach_remove_on_cancel('INVOKE_DEFAULT') + return {'FINISHED'} + + +classes = (SvMacroInterpretter,) + + +def register(): + for class_name in classes: + bpy.utils.register_class(class_name) + + +def unregister(): + for class_name in classes: + bpy.utils.unregister_class(class_name) + -- GitLab From 44381e28e298632344a54baf8d5bb910440c72bf Mon Sep 17 00:00:00 2001 From: zeffii Date: Sat, 15 Apr 2017 21:27:28 +0200 Subject: [PATCH 03/25] add nicer result shoting uses | --- utils/sv_extra_search.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 2fc36a041..de55c82e8 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -30,6 +30,12 @@ node_cats = make_node_cats() addon_name = sverchok.__name__ +macros = { + "obj vd": ["active_obj into objlite + vdmk2"," "], + "objs vd": ["multi obj in"," "] +} + + def gather_items(): fx = [] idx = 0 @@ -38,8 +44,13 @@ def gather_items(): if item[0] in {'separator', 'NodeReroute'}: continue nodetype = getattr(bpy.types, item[0]) - fx.append((str(idx), nodetype.bl_label, nodetype.bl_rna.description, idx)) + fx.append((str(idx), nodetype.bl_label, '', idx)) idx += 1 + + for k, v in macros.items(): + fx.append((k, k + " | " + v[0], '', idx)) + idx += 1 + return fx loop = {} @@ -58,7 +69,10 @@ class SvExtraSearch(bpy.types.Operator): def execute(self, context): self.report({'INFO'}, "Selected: %s" % self.my_enum) - print(loop['results'][int(self.my_enum)]) + if self.my_enum.isnumeric(): + print(loop['results'][int(self.my_enum)]) + else: + print(self.my_enum) return {'FINISHED'} def invoke(self, context, event): -- GitLab From 76e0cf528300a2f38da276933c4bf29285b01d86 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sat, 15 Apr 2017 22:03:21 +0200 Subject: [PATCH 04/25] add description for nodes --- utils/sv_extra_search.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index de55c82e8..c5a746305 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -44,7 +44,9 @@ def gather_items(): if item[0] in {'separator', 'NodeReroute'}: continue nodetype = getattr(bpy.types, item[0]) - fx.append((str(idx), nodetype.bl_label, '', idx)) + desc = nodetype.bl_rna.description + show_string = nodetype.bl_label + ((' | ' + desc) if desc else '') + fx.append((str(idx), show_string, '', idx)) idx += 1 for k, v in macros.items(): -- GitLab From c925aef436867dc3a0ef2e3329552d1231163597 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sat, 15 Apr 2017 23:06:19 +0200 Subject: [PATCH 05/25] add user defined macro route --- utils/sv_extra_search.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index c5a746305..d1cea0ff0 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -29,8 +29,10 @@ sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} node_cats = make_node_cats() addon_name = sverchok.__name__ +# pylint: disable=c0326 macros = { + # trigger: [descriptor, action route] "obj vd": ["active_obj into objlite + vdmk2"," "], "objs vd": ["multi obj in"," "] } @@ -39,8 +41,8 @@ macros = { def gather_items(): fx = [] idx = 0 - for catname, node_list in node_cats.items(): - for index, item in enumerate(node_list): + for _, node_list in node_cats.items(): + for item in node_list: if item[0] in {'separator', 'NodeReroute'}: continue nodetype = getattr(bpy.types, item[0]) @@ -53,6 +55,8 @@ def gather_items(): fx.append((k, k + " | " + v[0], '', idx)) idx += 1 + # extend(idx, fx, '/datafiles/sverchok/user_macros.fx') + return fx loop = {} -- GitLab From fb844d00b2ef5946c7d4fb320cdf206508019026 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 10:21:24 +0200 Subject: [PATCH 06/25] makes default macros non-local --- __init__.py | 2 +- utils/sv_default_macros.py | 12 ++++++++++++ utils/sv_extra_search.py | 5 +++-- utils/sv_macro_utils.py | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 utils/sv_default_macros.py diff --git a/__init__.py b/__init__.py index 1e05b85e6..6bf49731c 100755 --- a/__init__.py +++ b/__init__.py @@ -92,7 +92,7 @@ utils_modules = [ "text_editor_submenu", "text_editor_plugins", # UI operators and tools "sv_panels_tools", "sv_gist_tools", "sv_IO_panel_tools", "sv_load_zipped_blend", - "monad", "sv_help", "sv_extra_search", + "monad", "sv_help", "sv_default_macros", "sv_macro_utils", "sv_extra_search", #"loadscript", "debug_script", "sv_update_utils" ] diff --git a/utils/sv_default_macros.py b/utils/sv_default_macros.py new file mode 100644 index 000000000..4631e26c6 --- /dev/null +++ b/utils/sv_default_macros.py @@ -0,0 +1,12 @@ +macros = { + # trigger: [descriptor, action route] + "> obj vd": [ + "active_obj into objlite + vdmk2", + " "], + "> objs vd": [ + "multi obj in", + " "] +} + + + diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index d1cea0ff0..d850fa734 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -23,6 +23,7 @@ import sverchok import nodeitems_utils from sverchok.menu import make_node_cats from sverchok.ui.sv_icons import custom_icon +from sverchok.utils.sv_default_macros import macros from nodeitems_utils import _node_categories sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} @@ -33,8 +34,8 @@ addon_name = sverchok.__name__ macros = { # trigger: [descriptor, action route] - "obj vd": ["active_obj into objlite + vdmk2"," "], - "objs vd": ["multi obj in"," "] + "> obj vd": ["active_obj into objlite + vdmk2"," "], + "> objs vd": ["multi obj in"," "] } diff --git a/utils/sv_macro_utils.py b/utils/sv_macro_utils.py index f31a3d3a0..2f027a84a 100644 --- a/utils/sv_macro_utils.py +++ b/utils/sv_macro_utils.py @@ -27,6 +27,8 @@ import sverchok # pylint: disable=w0141 # pylint: disable=w0123 + + def convert_string_to_settings(arguments): # expects (varname=value,....) -- GitLab From 92b5239a08b2b41f55d26f72d6b160471b7258fa Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 10:38:49 +0200 Subject: [PATCH 07/25] makes default macros non-local --- nodes/generator/random_vector_mk2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes/generator/random_vector_mk2.py b/nodes/generator/random_vector_mk2.py index cd5d06fc7..906d560fd 100644 --- a/nodes/generator/random_vector_mk2.py +++ b/nodes/generator/random_vector_mk2.py @@ -25,7 +25,7 @@ from sverchok.data_structure import updateNode, match_long_repeat class RandomVectorNodeMK2(bpy.types.Node, SverchCustomTreeNode): - ''' Random Vectors with len=1 MK2, Unit Vectors''' + ''' Random unit Vectors''' bl_idname = 'RandomVectorNodeMK2' bl_label = 'Random Vector MK2' bl_icon = 'RNDCURVE' -- GitLab From 404119646cf00552bdc4cb41efd080ac05614782 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 11:05:15 +0200 Subject: [PATCH 08/25] add docstring splitter on tripple fwslash --- nodes/generators_extended/profile.py | 4 ++++ utils/sv_extra_search.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/nodes/generators_extended/profile.py b/nodes/generators_extended/profile.py index a3a785a63..bda94f2c2 100644 --- a/nodes/generators_extended/profile.py +++ b/nodes/generators_extended/profile.py @@ -514,12 +514,16 @@ class SvPrifilizer(bpy.types.Operator): class SvProfileNode(bpy.types.Node, SverchCustomTreeNode): ''' + svg-like 2d profiles /// + SvProfileNode generates one or more profiles / elevation segments using; assignments, variables, and a string descriptor similar to SVG. This node expects simple input, or vectorized input. - sockets with no input are automatically 0, not None - The longest input array will be used to extend the shorter ones, using last value repeat. + + ''' bl_idname = 'SvProfileNode' bl_label = 'Profile Parametric' diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index d850fa734..cfd6131ef 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -48,6 +48,8 @@ def gather_items(): continue nodetype = getattr(bpy.types, item[0]) desc = nodetype.bl_rna.description + if '///' in desc: + desc = desc.strip().split('///')[0] show_string = nodetype.bl_label + ((' | ' + desc) if desc else '') fx.append((str(idx), show_string, '', idx)) idx += 1 -- GitLab From 3765de6c2485eda640b31c6f0bb2a410fa844c96 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 11:24:20 +0200 Subject: [PATCH 09/25] add supplement to matrix apply --- nodes/generators_extended/profile.py | 3 +-- nodes/matrix/apply_and_join.py | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nodes/generators_extended/profile.py b/nodes/generators_extended/profile.py index bda94f2c2..306c834b1 100644 --- a/nodes/generators_extended/profile.py +++ b/nodes/generators_extended/profile.py @@ -522,9 +522,8 @@ class SvProfileNode(bpy.types.Node, SverchCustomTreeNode): This node expects simple input, or vectorized input. - sockets with no input are automatically 0, not None - The longest input array will be used to extend the shorter ones, using last value repeat. - - ''' + bl_idname = 'SvProfileNode' bl_label = 'Profile Parametric' bl_icon = 'OUTLINER_OB_EMPTY' diff --git a/nodes/matrix/apply_and_join.py b/nodes/matrix/apply_and_join.py index fdaeb8f86..6a765f35c 100644 --- a/nodes/matrix/apply_and_join.py +++ b/nodes/matrix/apply_and_join.py @@ -25,8 +25,12 @@ from sverchok.utils.sv_mesh_utils import mesh_join class SvMatrixApplyJoinNode(bpy.types.Node, SverchCustomTreeNode): - ''' Multiply vectors on matrices with several objects in output, - and process edges & faces too ''' + ''' + M * verts (optional join) /// + + Multiply vectors on matrices with several objects in output, + and process edges & faces too + ''' bl_idname = 'SvMatrixApplyJoinNode' bl_label = 'Matrix Apply' bl_icon = 'OUTLINER_OB_EMPTY' -- GitLab From a1a736e1dca33407b897380e7c29aaa2465882fc Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 11:29:14 +0200 Subject: [PATCH 10/25] add supplement to debugprint --- nodes/text/debug_print.py | 2 +- utils/sv_extra_search.py | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/nodes/text/debug_print.py b/nodes/text/debug_print.py index 738e51565..064fce391 100644 --- a/nodes/text/debug_print.py +++ b/nodes/text/debug_print.py @@ -24,7 +24,7 @@ from sverchok.data_structure import multi_socket, updateNode class SvDebugPrintNode(bpy.types.Node, SverchCustomTreeNode): - ''' SvDebugPrintNode ''' + ''' print socket data to terminal ''' bl_idname = 'SvDebugPrintNode' bl_label = 'Debug print' bl_icon = 'OUTLINER_OB_EMPTY' diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index cfd6131ef..ea635b044 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -32,12 +32,6 @@ addon_name = sverchok.__name__ # pylint: disable=c0326 -macros = { - # trigger: [descriptor, action route] - "> obj vd": ["active_obj into objlite + vdmk2"," "], - "> objs vd": ["multi obj in"," "] -} - def gather_items(): fx = [] @@ -51,7 +45,7 @@ def gather_items(): if '///' in desc: desc = desc.strip().split('///')[0] show_string = nodetype.bl_label + ((' | ' + desc) if desc else '') - fx.append((str(idx), show_string, '', idx)) + fx.append((str(idx), show_string.strip(), '', idx)) idx += 1 for k, v in macros.items(): -- GitLab From b36993461e1a09214a5172eba866e3faf0228db1 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 11:38:15 +0200 Subject: [PATCH 11/25] add til funcs for sv_extra_search --- utils/sv_default_macros.py | 15 ++++++++------- utils/sv_extra_search.py | 5 ++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/utils/sv_default_macros.py b/utils/sv_default_macros.py index 4631e26c6..5d6523e42 100644 --- a/utils/sv_default_macros.py +++ b/utils/sv_default_macros.py @@ -1,11 +1,12 @@ macros = { - # trigger: [descriptor, action route] - "> obj vd": [ - "active_obj into objlite + vdmk2", - " "], - "> objs vd": [ - "multi obj in", - " "] + "> obj vd": { + 'display_name': "active_obj into objlite + vdmk2", + 'file': 'macro', + 'ident': 'obj_in_lite_and_vd'}, + "> objs vd": { + 'display_name': "multi obj in + vdmk2", + 'file':'macro', + 'ident': 'ob3_and_vd'} } diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index ea635b044..260041115 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -32,6 +32,9 @@ addon_name = sverchok.__name__ # pylint: disable=c0326 +def format_item(k, v): + return k + " | " + v['display_name'] + def gather_items(): fx = [] @@ -49,7 +52,7 @@ def gather_items(): idx += 1 for k, v in macros.items(): - fx.append((k, k + " | " + v[0], '', idx)) + fx.append((k, format_item(k, v), '', idx)) idx += 1 # extend(idx, fx, '/datafiles/sverchok/user_macros.fx') -- GitLab From 604882e493b60bd0ba21c02e8a065a9f303838dd Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 11:55:43 +0200 Subject: [PATCH 12/25] add til funcs for sv_extra_search --- utils/sv_extra_search.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 260041115..36adc43e0 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -35,6 +35,15 @@ addon_name = sverchok.__name__ def format_item(k, v): return k + " | " + v['display_name'] +def slice_docstring(desc): + if '///' in desc: + desc = desc.strip().split('///')[0] + return desc + +def ensure_valid_show_string(item): + nodetype = getattr(bpy.types, item[0]) + desc = slice_docstring(nodetype.bl_rna.description) + return nodetype.bl_label + ((' | ' + desc) if desc else '').strip() def gather_items(): fx = [] @@ -43,12 +52,8 @@ def gather_items(): for item in node_list: if item[0] in {'separator', 'NodeReroute'}: continue - nodetype = getattr(bpy.types, item[0]) - desc = nodetype.bl_rna.description - if '///' in desc: - desc = desc.strip().split('///')[0] - show_string = nodetype.bl_label + ((' | ' + desc) if desc else '') - fx.append((str(idx), show_string.strip(), '', idx)) + + fx.append((str(idx), ensure_valid_show_string(item), '', idx)) idx += 1 for k, v in macros.items(): -- GitLab From 68b819681c7b69c447b56d21b03d70b856ec9c84 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 13:56:13 +0200 Subject: [PATCH 13/25] add verbose_macro_hanlder to DefaultMacros class --- utils/sv_default_macros.py | 46 ++++++++++++++++++++++++++++++++++++-- utils/sv_extra_search.py | 7 +++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/utils/sv_default_macros.py b/utils/sv_default_macros.py index 5d6523e42..beba4a9f0 100644 --- a/utils/sv_default_macros.py +++ b/utils/sv_default_macros.py @@ -1,13 +1,55 @@ +import bpy + macros = { "> obj vd": { 'display_name': "active_obj into objlite + vdmk2", 'file': 'macro', - 'ident': 'obj_in_lite_and_vd'}, + 'ident': ['verbose_macro_handler', 'obj vd']}, "> objs vd": { 'display_name': "multi obj in + vdmk2", 'file':'macro', - 'ident': 'ob3_and_vd'} + 'ident': ['verbose_macro_handler', 'ob3_and_vd']} } +sv_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} + +class DefaultMacros(): + + @classmethod + def ensure_nodetree(cls, operator, context): + ''' + if no active nodetree + add new empty node tree, set fakeuser immediately + ''' + if not context.space_data.tree_type in sv_types: + print('not running from a sv nodetree') + return + + if not hasattr(context.space_data.edit_tree, 'nodes'): + msg_one = 'going to add a new empty node tree' + msg_two = 'added new node tree' + print(msg_one) + operator.report({"WARNING"}, msg_one) + ng_params = {'name': 'unnamed_tree', 'type': 'SverchCustomTreeType'} + ng = bpy.data.node_groups.new(**ng_params) + ng.use_fake_user = True + context.space_data.node_tree = ng + operator.report({"WARNING"}, msg_two) + + @classmethod + def verbose_macro_handler(cls, operator, context, term): + + cls.ensure_nodetree(operator, context) + tree = context.space_data.edit_tree + nodes, links = tree.nodes, tree.links + if term == 'obj vd': + obj_in_node = nodes.new('SvObjInLite') + obj_in_node.dget() + vd_node = nodes.new('ViewerNode2') + vd_node.location = obj_in_node.location.x + 180, obj_in_node.location.y + + links.new(obj_in_node.outputs[0], vd_node.inputs[0]) + links.new(obj_in_node.outputs[2], vd_node.inputs[1]) + links.new(obj_in_node.outputs[3], vd_node.inputs[2]) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 36adc43e0..861ace796 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -23,7 +23,7 @@ import sverchok import nodeitems_utils from sverchok.menu import make_node_cats from sverchok.ui.sv_icons import custom_icon -from sverchok.utils.sv_default_macros import macros +from sverchok.utils.sv_default_macros import macros, DefaultMacros from nodeitems_utils import _node_categories sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} @@ -84,6 +84,11 @@ class SvExtraSearch(bpy.types.Operator): print(loop['results'][int(self.my_enum)]) else: print(self.my_enum) + macro_reference = macros.get(self.my_enum) + if macro_reference: + handler, term = macro_reference.get('ident') + getattr(DefaultMacros, handler)(self, context, term) + return {'FINISHED'} def invoke(self, context, event): -- GitLab From 4c1a3d997e8b4eb1111a30b426cf683332f16082 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 15:25:42 +0200 Subject: [PATCH 14/25] adds prelim solve for long description --- utils/sv_extra_search.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 861ace796..fdf1a7bb0 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -41,9 +41,17 @@ def slice_docstring(desc): return desc def ensure_valid_show_string(item): + ''' the font is not fixed width, it makes litle sense to calculate chars''' + hardcoded_maxlen = 20 nodetype = getattr(bpy.types, item[0]) desc = slice_docstring(nodetype.bl_rna.description) - return nodetype.bl_label + ((' | ' + desc) if desc else '').strip() + + # this needs revision + description = ((' | ' + desc) if desc else '').strip() + if len(description) > hardcoded_maxlen: + description = description[hardcoded_maxlen:] + + return nodetype.bl_label + description def gather_items(): fx = [] -- GitLab From ef3849c369932c89c5b0e1d734081792b25fc2e7 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 15:31:12 +0200 Subject: [PATCH 15/25] adds further solution for long description (not final) --- utils/sv_extra_search.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index fdf1a7bb0..f5a4c84d4 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -44,12 +44,11 @@ def ensure_valid_show_string(item): ''' the font is not fixed width, it makes litle sense to calculate chars''' hardcoded_maxlen = 20 nodetype = getattr(bpy.types, item[0]) - desc = slice_docstring(nodetype.bl_rna.description) + description = slice_docstring(nodetype.bl_rna.description).strip() - # this needs revision - description = ((' | ' + desc) if desc else '').strip() - if len(description) > hardcoded_maxlen: - description = description[hardcoded_maxlen:] + # ensure it's not too long + if description and len(description) > hardcoded_maxlen: + description = ' | ' + description[:hardcoded_maxlen] return nodetype.bl_label + description -- GitLab From 5832a41ef53660235a0e9a75689f017d864239b2 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 16:24:42 +0200 Subject: [PATCH 16/25] adds macro: objs vd --- utils/sv_default_macros.py | 13 +++++++++++-- utils/sv_extra_search.py | 6 ++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/utils/sv_default_macros.py b/utils/sv_default_macros.py index beba4a9f0..013c3ef83 100644 --- a/utils/sv_default_macros.py +++ b/utils/sv_default_macros.py @@ -8,7 +8,7 @@ macros = { "> objs vd": { 'display_name': "multi obj in + vdmk2", 'file':'macro', - 'ident': ['verbose_macro_handler', 'ob3_and_vd']} + 'ident': ['verbose_macro_handler', 'objs vd']} } sv_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} @@ -52,4 +52,13 @@ class DefaultMacros(): links.new(obj_in_node.outputs[0], vd_node.inputs[0]) links.new(obj_in_node.outputs[2], vd_node.inputs[1]) - links.new(obj_in_node.outputs[3], vd_node.inputs[2]) + links.new(obj_in_node.outputs[3], vd_node.inputs[2]) + elif term == 'objs vd': + obj_in_node = nodes.new('SvObjectsNodeMK3') + obj_in_node.get_objects_from_scene(operator) + vd_node = nodes.new('ViewerNode2') + vd_node.location = obj_in_node.location.x + 180, obj_in_node.location.y + + links.new(obj_in_node.outputs[0], vd_node.inputs[0]) + links.new(obj_in_node.outputs[2], vd_node.inputs[1]) + links.new(obj_in_node.outputs[3], vd_node.inputs[2]) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index f5a4c84d4..814ff5edb 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -47,8 +47,10 @@ def ensure_valid_show_string(item): description = slice_docstring(nodetype.bl_rna.description).strip() # ensure it's not too long - if description and len(description) > hardcoded_maxlen: - description = ' | ' + description[:hardcoded_maxlen] + if description: + if len(description) > hardcoded_maxlen: + description = description[:hardcoded_maxlen] + description = ' | ' + description return nodetype.bl_label + description -- GitLab From c6071930a37d58bf920411fb7a33a42c2931ae81 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 16:43:44 +0200 Subject: [PATCH 17/25] adjust more docstrings --- nodes/vector/color_in.py | 2 +- nodes/vector/color_out.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nodes/vector/color_in.py b/nodes/vector/color_in.py index ad96c4f98..b9dcf66b8 100644 --- a/nodes/vector/color_in.py +++ b/nodes/vector/color_in.py @@ -36,7 +36,7 @@ def fprop_generator(**altprops): class SvColorsInNode(bpy.types.Node, SverchCustomTreeNode): - ''' Generator for Color data , color combine''' + ''' rgb(a) ---> color /// Generator for Color data''' bl_idname = 'SvColorsInNode' bl_label = 'Color in' sv_icon = 'SV_COMBINE_IN' diff --git a/nodes/vector/color_out.py b/nodes/vector/color_out.py index d09e9616f..7aa1b8d6f 100644 --- a/nodes/vector/color_out.py +++ b/nodes/vector/color_out.py @@ -31,7 +31,7 @@ nodule_color = (0.899, 0.8052, 0.0, 1.0) class SvColorsOutNode(bpy.types.Node, SverchCustomTreeNode): - ''' Generator for Color data , color separate''' + ''' color ---> rgb(a) /// Generator for Color data''' bl_idname = 'SvColorsOutNode' bl_label = 'Color Out' sv_icon = 'SV_COMBINE_OUT' -- GitLab From 03e3fa7603969f15d3a98bb94e3f208a4a68d53a Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 17:46:12 +0200 Subject: [PATCH 18/25] add macro : sn petal --- utils/sv_default_macros.py | 51 +++++++++++++++++++++++++++++++++++++- utils/sv_extra_search.py | 1 + 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/utils/sv_default_macros.py b/utils/sv_default_macros.py index 013c3ef83..b5c504f10 100644 --- a/utils/sv_default_macros.py +++ b/utils/sv_default_macros.py @@ -1,5 +1,31 @@ +# ##### 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 ##### + +import os +import webbrowser + import bpy +from sverchok.utils.sv_update_utils import sv_get_local_path + + + + macros = { "> obj vd": { 'display_name': "active_obj into objlite + vdmk2", @@ -8,11 +34,20 @@ macros = { "> objs vd": { 'display_name': "multi obj in + vdmk2", 'file':'macro', - 'ident': ['verbose_macro_handler', 'objs vd']} + 'ident': ['verbose_macro_handler', 'objs vd']}, + "> zen": { + 'display_name': "zen of Sverchok", + 'file':'macro', + 'ident': ['verbose_macro_handler', 'zen']}, + "> sn petal": { + 'display_name': "load snlite w/ petalsine", + 'file':'macro', + 'ident': ['verbose_macro_handler', 'sn petal']} } sv_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} + class DefaultMacros(): @classmethod @@ -62,3 +97,17 @@ class DefaultMacros(): links.new(obj_in_node.outputs[0], vd_node.inputs[0]) links.new(obj_in_node.outputs[2], vd_node.inputs[1]) links.new(obj_in_node.outputs[3], vd_node.inputs[2]) + elif term == 'zen': + full_url_term = 'https://blenderpython.tumblr.com/post/91951323209/zen-of-sverchok' + webbrowser.open(full_url_term) + elif term == 'sn petal': + snlite = nodes.new('SvScriptNodeLite') + # set location of snlite based on mouse? + + sv_path = os.path.dirname(sv_get_local_path()[0]) + snlite_template_path = os.path.join(sv_path, 'node_scripts', 'SNLite_templates') + fullpath = os.path.join(snlite_template_path, 'petal_sine.py') + + txt = bpy.data.texts.load(fullpath) + snlite.script_name = os.path.basename(txt.name) + snlite.load() diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 814ff5edb..87c637839 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -101,6 +101,7 @@ class SvExtraSearch(bpy.types.Operator): return {'FINISHED'} def invoke(self, context, event): + # event contains mouse xy, can pass too! loop['results'] = gather_items() wm = context.window_manager wm.invoke_search_popup(self) -- GitLab From 15da0f27d9793096dad6991910963921cb5cbcc6 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 20:02:24 +0200 Subject: [PATCH 19/25] enable node adding from shift] --- nodes/vector/axis_input_mk2.py | 2 +- utils/sv_default_macros.py | 4 +--- utils/sv_extra_search.py | 21 +++++++++++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/nodes/vector/axis_input_mk2.py b/nodes/vector/axis_input_mk2.py index e8b03f227..175ff06dd 100644 --- a/nodes/vector/axis_input_mk2.py +++ b/nodes/vector/axis_input_mk2.py @@ -27,7 +27,7 @@ class SvAxisInputNodeMK2(bpy.types.Node, SverchCustomTreeNode): ''' Generator for X, Y or Z axis. ''' bl_idname = 'SvAxisInputNodeMK2' - bl_label = 'Vector X | Y | Z' + bl_label = 'Vector X/Y/Z' bl_icon = 'MANIPUL' m = [("-1", "-1", "", 0), ("0", "0", "", 1), ("1", "1", "", 2)] diff --git a/utils/sv_default_macros.py b/utils/sv_default_macros.py index b5c504f10..03fdac460 100644 --- a/utils/sv_default_macros.py +++ b/utils/sv_default_macros.py @@ -24,8 +24,6 @@ import bpy from sverchok.utils.sv_update_utils import sv_get_local_path - - macros = { "> obj vd": { 'display_name': "active_obj into objlite + vdmk2", @@ -65,7 +63,7 @@ class DefaultMacros(): msg_two = 'added new node tree' print(msg_one) operator.report({"WARNING"}, msg_one) - ng_params = {'name': 'unnamed_tree', 'type': 'SverchCustomTreeType'} + ng_params = {'name': 'NodeTree', 'type': 'SverchCustomTreeType'} ng = bpy.data.node_groups.new(**ng_params) ng.use_fake_user = True context.space_data.node_tree = ng diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 87c637839..056f6afb2 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -30,6 +30,9 @@ sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} node_cats = make_node_cats() addon_name = sverchok.__name__ +loop = {} +loop_reverse = {} + # pylint: disable=c0326 def format_item(k, v): @@ -44,6 +47,7 @@ def ensure_valid_show_string(item): ''' the font is not fixed width, it makes litle sense to calculate chars''' hardcoded_maxlen = 20 nodetype = getattr(bpy.types, item[0]) + loop_reverse[nodetype.bl_label] = item[0] description = slice_docstring(nodetype.bl_rna.description).strip() # ensure it's not too long @@ -73,7 +77,6 @@ def gather_items(): return fx -loop = {} def item_cb(self, context): return loop.get('results') @@ -87,10 +90,24 @@ class SvExtraSearch(bpy.types.Operator): my_enum = bpy.props.EnumProperty(items=item_cb) + def bl_idname_from_bl_label(self, context): + macro_result = loop['results'][int(self.my_enum)] + """ + if ' | ' in macro_result[1]: + bl_label = macro_result[1].split(' | ')[0].strip() + else: + bl_label = macro_result[1].strip() + """ + + bl_label = macro_result[1].split(' | ')[0].strip() + return loop_reverse[bl_label] + def execute(self, context): self.report({'INFO'}, "Selected: %s" % self.my_enum) if self.my_enum.isnumeric(): - print(loop['results'][int(self.my_enum)]) + macro_bl_idname = self.bl_idname_from_bl_label(self) + DefaultMacros.ensure_nodetree(self, context) + bpy.ops.node.sv_macro_interpretter(macro_bl_idname=macro_bl_idname) else: print(self.my_enum) macro_reference = macros.get(self.my_enum) -- GitLab From c61b44267d1a35495fad32cadbdd313869a5e9f5 Mon Sep 17 00:00:00 2001 From: zeffii Date: Sun, 16 Apr 2017 22:54:28 +0200 Subject: [PATCH 20/25] adjust docstring of axis input --- nodes/vector/axis_input_mk2.py | 2 +- utils/sv_extra_search.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nodes/vector/axis_input_mk2.py b/nodes/vector/axis_input_mk2.py index 175ff06dd..6a772221d 100644 --- a/nodes/vector/axis_input_mk2.py +++ b/nodes/vector/axis_input_mk2.py @@ -24,7 +24,7 @@ from sverchok.data_structure import updateNode class SvAxisInputNodeMK2(bpy.types.Node, SverchCustomTreeNode): - ''' Generator for X, Y or Z axis. ''' + ''' axis input ''' bl_idname = 'SvAxisInputNodeMK2' bl_label = 'Vector X/Y/Z' diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 056f6afb2..b5a4203e8 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -103,7 +103,7 @@ class SvExtraSearch(bpy.types.Operator): return loop_reverse[bl_label] def execute(self, context): - self.report({'INFO'}, "Selected: %s" % self.my_enum) + # self.report({'INFO'}, "Selected: %s" % self.my_enum) if self.my_enum.isnumeric(): macro_bl_idname = self.bl_idname_from_bl_label(self) DefaultMacros.ensure_nodetree(self, context) -- GitLab From 50529062bc41fa20fe0725d62c1fdf0d48fb6627 Mon Sep 17 00:00:00 2001 From: zeffii Date: Mon, 17 Apr 2017 16:01:30 +0200 Subject: [PATCH 21/25] adds macro loading from files --- utils/sv_extra_search.py | 41 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index b5a4203e8..2e28450be 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -16,7 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### - +import os +import importlib.util as getutil import bpy import sverchok @@ -35,9 +36,16 @@ loop_reverse = {} # pylint: disable=c0326 + +ddir = lambda content: [n for n in dir(content) if not n.startswith('__')] + + def format_item(k, v): return k + " | " + v['display_name'] +def format_macro_item(k, v): + return '< ' + k.replace('_', ' ') + " | " + slice_docstring(v) + def slice_docstring(desc): if '///' in desc: desc = desc.strip().split('///')[0] @@ -58,6 +66,33 @@ def ensure_valid_show_string(item): return nodetype.bl_label + description +def function_iterator(module_file): + for name in ddir(module_file): + obj = getattr(module_file, name) + if callable(obj): + yield name, obj.__doc__ + +def get_main_macro_module(fullpath): + if os.path.exists(fullpath): + spec = getutil.spec_from_file_location("macro_module.name", fullpath) + macro_module = getutil.module_from_spec(spec) + spec.loader.exec_module(macro_module) + return macro_module + +def fx_extend(idx, datastorage, filepath): + # shall be dynamic + datafiles = r'C:\Users\zeffi\AppData\Roaming\Blender Foundation\Blender\2.78' + fullpath = os.path.join(datafiles, filepath) + + macro_module = get_main_macro_module(fullpath) + if not macro_module: + return + + for func_name, func_descriptor in function_iterator(macro_module): + datastorage.append((func_name, format_macro_item(func_name, func_descriptor), '', idx)) + idx +=1 + + def gather_items(): fx = [] idx = 0 @@ -72,8 +107,8 @@ def gather_items(): for k, v in macros.items(): fx.append((k, format_item(k, v), '', idx)) idx += 1 - - # extend(idx, fx, '/datafiles/sverchok/user_macros.fx') + + fx_extend(idx, fx, 'datafiles/sverchok/user_macros/macros.py') return fx -- GitLab From 5ec32add0078bb2d61ebdb0ce2a978d9fa9cc21a Mon Sep 17 00:00:00 2001 From: zeffii Date: Mon, 17 Apr 2017 17:28:12 +0200 Subject: [PATCH 22/25] implements user macros - (currently without params) --- utils/sv_extra_search.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 2e28450be..602ec2a97 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -33,7 +33,6 @@ addon_name = sverchok.__name__ loop = {} loop_reverse = {} - # pylint: disable=c0326 @@ -77,6 +76,7 @@ def get_main_macro_module(fullpath): spec = getutil.spec_from_file_location("macro_module.name", fullpath) macro_module = getutil.module_from_spec(spec) spec.loader.exec_module(macro_module) + globals()['sv_macro_module'] = macro_module return macro_module def fx_extend(idx, datastorage, filepath): @@ -144,12 +144,17 @@ class SvExtraSearch(bpy.types.Operator): DefaultMacros.ensure_nodetree(self, context) bpy.ops.node.sv_macro_interpretter(macro_bl_idname=macro_bl_idname) else: - print(self.my_enum) macro_reference = macros.get(self.my_enum) + if macro_reference: handler, term = macro_reference.get('ident') getattr(DefaultMacros, handler)(self, context, term) + elif hasattr(globals()['sv_macro_module'], self.my_enum): + func = getattr(globals()['sv_macro_module'], self.my_enum) + func(self, context) + + return {'FINISHED'} def invoke(self, context, event): -- GitLab From c70826f9e1c478d55d6090e25935e637ab944b08 Mon Sep 17 00:00:00 2001 From: zeffii Date: Mon, 17 Apr 2017 21:42:37 +0200 Subject: [PATCH 23/25] add less wasteful macro storing --- utils/sv_extra_search.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index 602ec2a97..c363016d2 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -27,15 +27,15 @@ from sverchok.ui.sv_icons import custom_icon from sverchok.utils.sv_default_macros import macros, DefaultMacros from nodeitems_utils import _node_categories +# pylint: disable=c0326 + sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} node_cats = make_node_cats() addon_name = sverchok.__name__ loop = {} loop_reverse = {} -# pylint: disable=c0326 - - +local_macros = {} ddir = lambda content: [n for n in dir(content) if not n.startswith('__')] @@ -50,20 +50,20 @@ def slice_docstring(desc): desc = desc.strip().split('///')[0] return desc -def ensure_valid_show_string(item): - ''' the font is not fixed width, it makes litle sense to calculate chars''' +def ensure_short_description(description): + ''' the font is not fixed width, it makes litle sense to calculate chars ''' hardcoded_maxlen = 20 - nodetype = getattr(bpy.types, item[0]) - loop_reverse[nodetype.bl_label] = item[0] - description = slice_docstring(nodetype.bl_rna.description).strip() - - # ensure it's not too long if description: if len(description) > hardcoded_maxlen: description = description[:hardcoded_maxlen] description = ' | ' + description - - return nodetype.bl_label + description + return description + +def ensure_valid_show_string(item): + nodetype = getattr(bpy.types, item[0]) + loop_reverse[nodetype.bl_label] = item[0] + description = slice_docstring(nodetype.bl_rna.description).strip() + return nodetype.bl_label + ensure_short_description(description) def function_iterator(module_file): for name in ddir(module_file): @@ -73,10 +73,11 @@ def function_iterator(module_file): def get_main_macro_module(fullpath): if os.path.exists(fullpath): + print('--- first time getting sv_macro_module --- ') spec = getutil.spec_from_file_location("macro_module.name", fullpath) macro_module = getutil.module_from_spec(spec) spec.loader.exec_module(macro_module) - globals()['sv_macro_module'] = macro_module + local_macros['sv_macro_module'] = macro_module return macro_module def fx_extend(idx, datastorage, filepath): @@ -84,7 +85,10 @@ def fx_extend(idx, datastorage, filepath): datafiles = r'C:\Users\zeffi\AppData\Roaming\Blender Foundation\Blender\2.78' fullpath = os.path.join(datafiles, filepath) - macro_module = get_main_macro_module(fullpath) + # load from previous obtained module, else get from fullpath. + macro_module = local_macros.get('sv_macro_module') + if not macro_module: + macro_module = get_main_macro_module(fullpath) if not macro_module: return @@ -138,6 +142,7 @@ class SvExtraSearch(bpy.types.Operator): return loop_reverse[bl_label] def execute(self, context): + # print(context.space_data.cursor_location) (in nodeview space) # self.report({'INFO'}, "Selected: %s" % self.my_enum) if self.my_enum.isnumeric(): macro_bl_idname = self.bl_idname_from_bl_label(self) @@ -150,15 +155,14 @@ class SvExtraSearch(bpy.types.Operator): handler, term = macro_reference.get('ident') getattr(DefaultMacros, handler)(self, context, term) - elif hasattr(globals()['sv_macro_module'], self.my_enum): - func = getattr(globals()['sv_macro_module'], self.my_enum) + elif hasattr(local_macros['sv_macro_module'], self.my_enum): + func = getattr(local_macros['sv_macro_module'], self.my_enum) func(self, context) - return {'FINISHED'} def invoke(self, context, event): - # event contains mouse xy, can pass too! + context.space_data.cursor_location_from_region(event.mouse_region_x, event.mouse_region_y) loop['results'] = gather_items() wm = context.window_manager wm.invoke_search_popup(self) -- GitLab From d5c4f7aac41e99dbf669ed7b8253b93638b2feba Mon Sep 17 00:00:00 2001 From: zeffii Date: Tue, 18 Apr 2017 10:54:00 +0200 Subject: [PATCH 24/25] add system based datafiles/sverchok location getter --- utils/sv_extra_search.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index c363016d2..a338ec585 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -81,8 +81,8 @@ def get_main_macro_module(fullpath): return macro_module def fx_extend(idx, datastorage, filepath): - # shall be dynamic - datafiles = r'C:\Users\zeffi\AppData\Roaming\Blender Foundation\Blender\2.78' + + datafiles = os.path.join(bpy.utils.user_resource('DATAFILES', path='sverchok', create=True)) fullpath = os.path.join(datafiles, filepath) # load from previous obtained module, else get from fullpath. @@ -112,7 +112,7 @@ def gather_items(): fx.append((k, format_item(k, v), '', idx)) idx += 1 - fx_extend(idx, fx, 'datafiles/sverchok/user_macros/macros.py') + fx_extend(idx, fx, 'user_macros/macros.py') return fx -- GitLab From 8906a3463850fc6b1a6df27bda27f0b0bbf22a15 Mon Sep 17 00:00:00 2001 From: zeffii Date: Tue, 18 Apr 2017 10:56:36 +0200 Subject: [PATCH 25/25] remove unused comment --- utils/sv_extra_search.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/utils/sv_extra_search.py b/utils/sv_extra_search.py index a338ec585..f5a5d354d 100644 --- a/utils/sv_extra_search.py +++ b/utils/sv_extra_search.py @@ -131,13 +131,6 @@ class SvExtraSearch(bpy.types.Operator): def bl_idname_from_bl_label(self, context): macro_result = loop['results'][int(self.my_enum)] - """ - if ' | ' in macro_result[1]: - bl_label = macro_result[1].split(' | ')[0].strip() - else: - bl_label = macro_result[1].strip() - """ - bl_label = macro_result[1].split(' | ')[0].strip() return loop_reverse[bl_label] -- GitLab