Skip to content

Commit

Permalink
add mixin (#4035)
Browse files Browse the repository at this point in the history
* add mixin

* rectify whitespace
  • Loading branch information
zeffii authored Apr 10, 2021
1 parent 0190005 commit e233031
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions ui/nodeview_space_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ def draw(self, context):
layout_draw_categories(self.layout, self.bl_label, node_cats[self.bl_label])
# prop_menu_enum(data, property, text="", text_ctxt="", icon='NONE')


class SV_NodeTree_Poll():
"""
mixin to detect if the current nodetree is a Sverchok type nodetree, if not poll returns False
"""
@classmethod
def poll(cls, context):
tree_type = context.space_data.tree_type
if tree_type in sv_tree_types:
return True


# quick class factory.
def make_class(name, bl_label):
global menu_class_by_title
Expand All @@ -151,16 +163,9 @@ def make_class(name, bl_label):
menu_class_by_title[bl_label] = clazz
return clazz

class NODEVIEW_MT_Dynamic_Menu(bpy.types.Menu):
bl_label = "Sverchok Nodes"

@classmethod
def poll(cls, context):
tree_type = context.space_data.tree_type
if tree_type in sv_tree_types:
#menu_prefs['show_icons'] = get_icon_switch()
# print('showing', menu_prefs['show_icons'])
return True
class NODEVIEW_MT_Dynamic_Menu(bpy.types.Menu, SV_NodeTree_Poll):
bl_label = "Sverchok Nodes"

def draw(self, context):

Expand Down Expand Up @@ -200,9 +205,10 @@ def draw(self, context):
layout.menu("NODEVIEW_MT_EX_" + category.identifier)


class NodePatialMenuTemplate(bpy.types.Menu):
class NodePatialMenuTemplate(bpy.types.Menu, SV_NodeTree_Poll):
bl_label = ""
items = []

def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
Expand Down

0 comments on commit e233031

Please sign in to comment.