113 lines
4.1 KiB
Python
113 lines
4.1 KiB
Python
|
from lnx.logicnode.lnx_nodes import *
|
||
|
|
||
|
|
||
|
class RenderElementNode(LnxLogicTreeNode):
|
||
|
"""Render Element"""
|
||
|
bl_idname = 'LNRenderElementNode'
|
||
|
bl_label = 'Render Element'
|
||
|
bl_description = 'Render Element'
|
||
|
lnx_category = 'HTML'
|
||
|
lnx_version = 1
|
||
|
|
||
|
@staticmethod
|
||
|
def get_enum_id_value(obj, prop_name, value):
|
||
|
return obj.bl_rna.properties[prop_name].enum_items[value].identifier
|
||
|
|
||
|
@staticmethod
|
||
|
def get_count_in(type_name):
|
||
|
return {
|
||
|
'append': 0,
|
||
|
'appendChild': 1,
|
||
|
'appendTorrent': 2,
|
||
|
'prepend': 3,
|
||
|
'prependChild': 4,
|
||
|
'innerHTML': 5,
|
||
|
'innerText': 6,
|
||
|
'insertAdjacentHTML': 7,
|
||
|
}.get(type_name, 0)
|
||
|
|
||
|
def get_enum(self):
|
||
|
return self.get('property0', 0)
|
||
|
|
||
|
def set_enum(self, value):
|
||
|
# Checking the selection of each type
|
||
|
select_current = self.get_enum_id_value(self, 'property0', value)
|
||
|
select_prev = self.property0
|
||
|
|
||
|
#Check if type changed
|
||
|
if select_prev != select_current:
|
||
|
|
||
|
for i in self.inputs:
|
||
|
self.inputs.remove(i)
|
||
|
|
||
|
# Arguements for type Client
|
||
|
index = self.get_count_in(select_current)
|
||
|
|
||
|
match index:
|
||
|
case 2:
|
||
|
self.add_input('LnxNodeSocketAction', 'In')
|
||
|
self.add_input('LnxDynamicSocket', 'Torrent')
|
||
|
self.add_input('LnxStringSocket', 'Selector')
|
||
|
case 5:
|
||
|
self.add_input('LnxNodeSocketAction', 'In')
|
||
|
self.add_input('LnxDynamicSocket', 'Element')
|
||
|
self.add_input('LnxStringSocket', 'HTML')
|
||
|
case 6:
|
||
|
self.add_input('LnxNodeSocketAction', 'In')
|
||
|
self.add_input('LnxDynamicSocket', 'Element')
|
||
|
self.add_input('LnxStringSocket', 'Text')
|
||
|
case 7:
|
||
|
self.add_input('LnxNodeSocketAction', 'In')
|
||
|
self.add_input('LnxStringSocket', 'HTML')
|
||
|
self.add_input('LnxStringSocket', 'Selector')
|
||
|
case _:
|
||
|
self.add_input('LnxNodeSocketAction', 'In')
|
||
|
self.add_input('LnxDynamicSocket', 'Element')
|
||
|
self.add_input('LnxStringSocket', 'Selector')
|
||
|
|
||
|
self['property0'] = value
|
||
|
|
||
|
property0: HaxeEnumProperty(
|
||
|
'property0',
|
||
|
items = [('append', 'Append', 'Append Element to Another'),
|
||
|
('appendChild', 'AppendChild', 'AppendChild Element to Another'),
|
||
|
('appendTorrent', 'AppendTorrent', 'Append Torrent file to an Element'),
|
||
|
('prepend', 'Prepend', 'Prepend Element to Another'),
|
||
|
('prependChild', 'PrependChild', 'PrependChild Element to Another'),
|
||
|
('innerHTML', 'InnerHTML', 'Insert Element as InnerHTML'),
|
||
|
('innerText', 'InnerText', 'Insert Element as InnerText'),
|
||
|
('insertAdjacentHTML', 'AdjacentHTML', 'Insert Element as Adjacent HTML')],
|
||
|
name='',
|
||
|
default='append',
|
||
|
set=set_enum,
|
||
|
get=get_enum)
|
||
|
|
||
|
property1: HaxeEnumProperty(
|
||
|
'property1',
|
||
|
items = [('beforebegin', 'Before Begin', '"Position beforebegin"'),
|
||
|
('afterbegin', 'After Begin', '"Position afterbegin"'),
|
||
|
('beforeend', 'Before End', '"Position beforeend"'),
|
||
|
('afterend', 'After End', '"Position afterend"')],
|
||
|
name='',
|
||
|
default='beforebegin')
|
||
|
|
||
|
def lnx_init(self, context):
|
||
|
self.add_input('LnxNodeSocketAction', 'In')
|
||
|
self.add_input('LnxDynamicSocket', 'Element')
|
||
|
self.add_input('LnxStringSocket', 'Selector')
|
||
|
|
||
|
self.add_output('LnxNodeSocketAction', 'Out')
|
||
|
|
||
|
|
||
|
def draw_buttons(self, context, layout):
|
||
|
layout.prop(self, 'property0')
|
||
|
if str(self.property0) == 'innerText' or str(self.property0) == 'innerHTML':
|
||
|
return
|
||
|
else:
|
||
|
layout.prop(self, 'property1')
|
||
|
|
||
|
|
||
|
def register():
|
||
|
add_category('HTML', icon='SEQ_STRIP_META')
|
||
|
RenderElementNode.on_register()
|