From b040e651d317d0657e3d6fa858a0c875c67ec9a6 Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Thu, 6 May 2021 11:00:09 +0200 Subject: [PATCH 1/2] drop old file --- nodes/exchange/bezier_in.py | 2 +- nodes/exchange/nurbs_in.py | 2 +- nodes/list_mutators/multi_cache.py | 2 +- nodes/logic/evolver.py | 2 +- nodes/logic/genes_holder.py | 2 +- nodes/network/file_path.py | 2 +- nodes/scene/objects_in_lite.py | 2 +- nodes/scene/objects_mk3.py | 2 +- nodes/solid/export_solid.py | 2 +- nodes/svg/svg_document.py | 2 +- nodes/viz/viewer_waveform_output.py | 2 +- ui/nodeview_operators.py | 2 +- utils/__init__.py | 7 +-- utils/sv_3dview_tools.py | 2 +- utils/sv_obj_baker.py | 2 +- utils/sv_operator_mixins.py | 85 +++++++++++++++++++++++------ utils/sv_operator_utils.py | 72 ------------------------ 17 files changed, 84 insertions(+), 108 deletions(-) delete mode 100644 utils/sv_operator_utils.py diff --git a/nodes/exchange/bezier_in.py b/nodes/exchange/bezier_in.py index 43b7b556fc..35497c2b86 100644 --- a/nodes/exchange/bezier_in.py +++ b/nodes/exchange/bezier_in.py @@ -12,7 +12,7 @@ from sverchok.node_tree import SverchCustomTreeNode from sverchok.utils.nodes_mixins.sv_animatable_nodes import SvAnimatableNode from sverchok.utils.nodes_mixins.show_3d_properties import Show3DProperties -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator from sverchok.data_structure import updateNode, zip_long_repeat, split_by_count from sverchok.utils.curve.algorithms import concatenate_curves from sverchok.utils.curve.bezier import SvCubicBezierCurve diff --git a/nodes/exchange/nurbs_in.py b/nodes/exchange/nurbs_in.py index 3357310217..eee38dd886 100644 --- a/nodes/exchange/nurbs_in.py +++ b/nodes/exchange/nurbs_in.py @@ -12,7 +12,7 @@ from sverchok.node_tree import SverchCustomTreeNode from sverchok.utils.nodes_mixins.sv_animatable_nodes import SvAnimatableNode from sverchok.utils.nodes_mixins.show_3d_properties import Show3DProperties -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator from sverchok.data_structure import updateNode, zip_long_repeat, split_by_count from sverchok.utils.curve import knotvector as sv_knotvector from sverchok.utils.curve.nurbs import SvNurbsCurve diff --git a/nodes/list_mutators/multi_cache.py b/nodes/list_mutators/multi_cache.py index 3a9e840319..d2a726ef33 100644 --- a/nodes/list_mutators/multi_cache.py +++ b/nodes/list_mutators/multi_cache.py @@ -15,7 +15,7 @@ from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import changable_sockets, dataCorrect, updateNode, zip_long_repeat -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator class SvvMultiCacheReset(bpy.types.Operator, SvGenericNodeLocator): diff --git a/nodes/logic/evolver.py b/nodes/logic/evolver.py index a2d8013d6c..53574a9c42 100644 --- a/nodes/logic/evolver.py +++ b/nodes/logic/evolver.py @@ -21,7 +21,7 @@ from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode from sverchok.core.update_system import make_tree_from_nodes, do_update -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator from sverchok.utils.listutils import ( listinput_getI, listinput_getF, diff --git a/nodes/logic/genes_holder.py b/nodes/logic/genes_holder.py index b4e1cfa780..4d01c19e63 100644 --- a/nodes/logic/genes_holder.py +++ b/nodes/logic/genes_holder.py @@ -14,7 +14,7 @@ from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import dataCorrect, updateNode -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator class SvGenesHolderReset(bpy.types.Operator, SvGenericNodeLocator): diff --git a/nodes/network/file_path.py b/nodes/network/file_path.py index 691f463e0b..83c5a31cd3 100644 --- a/nodes/network/file_path.py +++ b/nodes/network/file_path.py @@ -23,7 +23,7 @@ from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode, match_long_repeat from sverchok.utils.modules import sv_bmesh -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator class SvFilePathFinder(bpy.types.Operator, SvGenericNodeLocator): diff --git a/nodes/scene/objects_in_lite.py b/nodes/scene/objects_in_lite.py index 089ddaae59..e34cb111a0 100644 --- a/nodes/scene/objects_in_lite.py +++ b/nodes/scene/objects_in_lite.py @@ -11,7 +11,7 @@ import sverchok from sverchok.utils.mesh_repr_utils import flatten, unflatten, generate_object from sverchok.utils.sv_bmesh_utils import bmesh_from_pydata -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode diff --git a/nodes/scene/objects_mk3.py b/nodes/scene/objects_mk3.py index f6a2e5b635..4fd95e0628 100644 --- a/nodes/scene/objects_mk3.py +++ b/nodes/scene/objects_mk3.py @@ -12,7 +12,7 @@ import sverchok from sverchok.node_tree import SverchCustomTreeNode from sverchok.utils.nodes_mixins.sv_animatable_nodes import SvAnimatableNode -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator from sverchok.data_structure import updateNode from sverchok.utils.sv_bmesh_utils import pydata_from_bmesh from sverchok.core.handlers import get_sv_depsgraph, set_sv_depsgraph_need diff --git a/nodes/solid/export_solid.py b/nodes/solid/export_solid.py index 4a08c44b4b..d457b2a1da 100644 --- a/nodes/solid/export_solid.py +++ b/nodes/solid/export_solid.py @@ -10,7 +10,7 @@ from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import flatten_data, map_recursive -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator from sverchok.utils.curve.core import SvCurve from sverchok.utils.surface.core import SvSurface from sverchok.utils.logging import debug diff --git a/nodes/svg/svg_document.py b/nodes/svg/svg_document.py index 3b11eb2a0d..b970514f38 100644 --- a/nodes/svg/svg_document.py +++ b/nodes/svg/svg_document.py @@ -26,7 +26,7 @@ import sverchok from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator evolver_mem = {} diff --git a/nodes/viz/viewer_waveform_output.py b/nodes/viz/viewer_waveform_output.py index ff9e992117..9530e1306f 100644 --- a/nodes/viz/viewer_waveform_output.py +++ b/nodes/viz/viewer_waveform_output.py @@ -20,7 +20,7 @@ from mathutils import Vector from sverchok.utils.context_managers import sv_preferences -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator from sverchok.node_tree import SverchCustomTreeNode from sverchok.data_structure import updateNode, node_id from sverchok.ui import bgl_callback_nodeview as nvBGL diff --git a/ui/nodeview_operators.py b/ui/nodeview_operators.py index 883ebd80df..b52421c327 100644 --- a/ui/nodeview_operators.py +++ b/ui/nodeview_operators.py @@ -5,7 +5,7 @@ # SPDX-License-Identifier: GPL3 # License-Filename: LICENSE -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator import bpy class SvNodeViewZoomBorder(bpy.types.Operator, SvGenericNodeLocator): diff --git a/utils/__init__.py b/utils/__init__.py index 3a3848dfe1..40eaf79393 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -84,12 +84,9 @@ def auto_gather_node_classes(start_module = None): def get_node_class_reference(bl_idname): - # formerly stuff like: - # cls = getattr(bpy.types, self.cls_bl_idname, None) - if bl_idname == "NodeReroute": return getattr(bpy.types, bl_idname) - # this will also return a Nonetype if the ref isn't found, and the class ref if found + return node_classes.get(bl_idname) @@ -138,7 +135,7 @@ def app_handler_ops(append=None, remove=None): "text_editor_submenu", "text_editor_plugins", # UI operators and tools "sv_IO_pointer_helpers", - "sv_IO_monad_helpers", "sv_operator_utils", + "sv_IO_monad_helpers", "sv_operator_mixins", "sv_gist_tools", "sv_IO_panel_tools", "sv_load_archived_blend", "monad", "sv_help", "sv_default_macros", "sv_macro_utils", "sv_extra_search", "sv_3dview_tools", "sv_update_utils", "sv_obj_helper", "sv_batch_primitives", "sv_idx_viewer28_draw", diff --git a/utils/sv_3dview_tools.py b/utils/sv_3dview_tools.py index 1e419caf52..1f28b865c5 100644 --- a/utils/sv_3dview_tools.py +++ b/utils/sv_3dview_tools.py @@ -12,7 +12,7 @@ from sverchok.core.socket_conversions import is_matrix from sverchok.utils.modules import geom_utils -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator def get_matrix(socket): diff --git a/utils/sv_obj_baker.py b/utils/sv_obj_baker.py index 3bcf3bf3d4..b0e4701f4a 100644 --- a/utils/sv_obj_baker.py +++ b/utils/sv_obj_baker.py @@ -11,7 +11,7 @@ from mathutils import Vector, Matrix from sverchok.data_structure import node_id, dataCorrect, dataCorrect_np -from sverchok.utils.sv_operator_utils import SvGenericNodeLocator +from sverchok.utils.sv_operator_mixins import SvGenericNodeLocator cache_viewer_baker = {} diff --git a/utils/sv_operator_mixins.py b/utils/sv_operator_mixins.py index 0d38801738..ae678018c2 100644 --- a/utils/sv_operator_mixins.py +++ b/utils/sv_operator_mixins.py @@ -1,22 +1,40 @@ -# ##### 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 ##### +# This file is part of project Sverchok. It's copyrighted by the contributors +# recorded in the version control history of the file, available from +# its original location https://github.com/nortikin/sverchok/commit/master +# +# SPDX-License-Identifier: GPL3 +# License-Filename: LICENSE + import bpy +from bpy.props import StringProperty + +class SvGenericNodeLocator(): + """ + usage: + add this to an Operator class definition if you need to track the origin + of a click. + + see at the bottom of this file in " class SvGenericCallbackOldOp " how to use it. + + """ + tree_name: StringProperty(default='', description="name of the node tree") + node_name: StringProperty(default='', description="name of the node") + + def get_node(self, context): + """ context.node is usually provided, else tree_name/node_name must be passed """ + if self.tree_name and self.node_name: + return bpy.data.node_groups[self.tree_name].nodes[self.node_name] + + if hasattr(context, "node"): + return context.node + + print("treename or nodename not supplied, node not found in available trees") + print(f"received tree_name: {tree_name} and node_name: {node_name}") + return None + + def get_tree(self): + return bpy.data.node_groups.get(self.tree_name) class SvGenericCallbackWithParams(): @@ -159,3 +177,36 @@ def invoke(self, context, event): wm = context.window_manager wm.fileselect_add(self) return {'RUNNING_MODAL'} + + +class SvGenericCallbackOldOp(bpy.types.Operator, SvGenericNodeLocator): + """ + This operator is generic and will call .fn_name on the instance of the caller node + """ + bl_idname = "node.sverchok_generic_callback_old" + bl_label = "Sverchok text input" + bl_options = {'REGISTER', 'UNDO'} + + fn_name: StringProperty(name='function name') + + def execute(self, context): + n = self.get_node(context) + if not n: + return {'CANCELLED'} + + f = getattr(n, self.fn_name, None) + if not f: + msg = "{0} has no function named '{1}'".format(n.name, self.fn_name) + self.report({"WARNING"}, msg) + return {'CANCELLED'} + f() + + return {'FINISHED'} + + +def register(): + bpy.utils.register_class(SvGenericCallbackOldOp) + + +def unregister(): + bpy.utils.unregister_class(SvGenericCallbackOldOp) diff --git a/utils/sv_operator_utils.py b/utils/sv_operator_utils.py deleted file mode 100644 index 321184230c..0000000000 --- a/utils/sv_operator_utils.py +++ /dev/null @@ -1,72 +0,0 @@ -# This file is part of project Sverchok. It's copyrighted by the contributors -# recorded in the version control history of the file, available from -# its original location https://github.com/nortikin/sverchok/commit/master -# -# SPDX-License-Identifier: GPL3 -# License-Filename: LICENSE - - -import bpy -from bpy.props import StringProperty - -class SvGenericNodeLocator(): - tree_name: StringProperty(default='', description="name of the node tree") - node_name: StringProperty(default='', description="name of the node") - - def get_node(self, context): - """ context.node is usually provided, else tree_name/node_name must be passed """ - if self.tree_name and self.node_name: - return bpy.data.node_groups[self.tree_name].nodes[self.node_name] - - if hasattr(context, "node"): - return context.node - - print("treename or nodename not supplied, node not found in available trees") - print(f"received tree_name: {tree_name} and node_name: {node_name}") - return None - - def get_tree(self): - return bpy.data.node_groups.get(self.tree_name) - - -class SvGenericCallbackOldOp(bpy.types.Operator): - """ - This operator is generic and will call .fn_name on the instance of the caller node - """ - bl_idname = "node.sverchok_generic_callback_old" - bl_label = "Sverchok text input" - bl_options = {'REGISTER', 'UNDO'} - - fn_name: StringProperty(name='function name') - - # this information is not communicated unless you trigger it from a node - # in the case the operator button appears on a 3dview panel, it will need to pass these too. - tree_name: StringProperty(default='') - node_name: StringProperty(default='') - - def get_node(self, context): - """ context.node is usually provided, else tree_name/node_name must be passed """ - if self.tree_name and self.node_name: - return bpy.data.node_groups[self.tree_name].nodes[self.node_name] - - return context.node - - def execute(self, context): - n = self.get_node(context) - - f = getattr(n, self.fn_name, None) - if not f: - msg = "{0} has no function named '{1}'".format(n.name, self.fn_name) - self.report({"WARNING"}, msg) - return {'CANCELLED'} - f() - - return {'FINISHED'} - - -def register(): - bpy.utils.register_class(SvGenericCallbackOldOp) - - -def unregister(): - bpy.utils.unregister_class(SvGenericCallbackOldOp) From c1ff79a650029463e789c087a5c8e1e850d55dd0 Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Thu, 6 May 2021 11:06:27 +0200 Subject: [PATCH 2/2] add doscstring --- utils/sv_operator_mixins.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/sv_operator_mixins.py b/utils/sv_operator_mixins.py index ae678018c2..59a052d9f0 100644 --- a/utils/sv_operator_mixins.py +++ b/utils/sv_operator_mixins.py @@ -16,6 +16,11 @@ class SvGenericNodeLocator(): of a click. see at the bottom of this file in " class SvGenericCallbackOldOp " how to use it. + you can then use the "node.wrapper_tracked_ui_draw_op", in the UI draw function.. + + f.ex: + callback = "node.sverchok_mesh_baker_mk3" + self.wrapper_tracked_ui_draw_op(row, callback, icon='', text='') """ tree_name: StringProperty(default='', description="name of the node tree") @@ -196,7 +201,7 @@ def execute(self, context): f = getattr(n, self.fn_name, None) if not f: - msg = "{0} has no function named '{1}'".format(n.name, self.fn_name) + msg = f"{n.name} has no function named '{self.fn_name}'" self.report({"WARNING"}, msg) return {'CANCELLED'} f()