LNXSDK/leenkx/blender/lnx/logicnode/custom/LN_create_element.py
2025-01-22 16:18:30 +01:00

451 lines
22 KiB
Python

from lnx.logicnode.lnx_nodes import *
class CreateElementNode(LnxLogicTreeNode):
"""Create Element"""
bl_idname = 'LNCreateElementNode'
bl_label = 'Create Element'
bl_description = 'Create Element'
lnx_category = 'HTML'
lnx_version = 1
data_map = {}
@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 {
'a': 0,
'abbr': 1,
'address': 2,
'area': 3,
'article': 4,
'aside': 5,
'audio': 6,
'bold': 7,
'base': 8,
'bdi': 9,
'bdo': 10,
'blockquote': 11,
'body': 12,
'br': 13,
'button': 14,
'canvas': 15,
'caption': 16,
'cite': 17,
'code': 18,
'col': 19,
'colgroup': 20,
'data': 21,
'datalist': 22,
'dd': 23,
'del': 24,
'details': 25,
'dfn': 26,
'dialog': 27,
'div': 28,
'dl': 29,
'dt': 30,
'em': 31,
'embed': 32,
'fieldset': 33,
'figcaption': 34,
'figure': 35,
'footer': 36,
'form': 37,
'h1': 38,
'h2': 39,
'h3': 40,
'h4': 41,
'h5': 42,
'h6': 43,
'head': 44,
'header': 45,
'hgroup': 46,
'hr': 47,
'html': 48,
'i': 49,
'iframe': 50,
'img': 51,
'input': 52,
'ins': 53,
'kdb': 54,
'label': 55,
'legend': 56,
'li': 57,
'link': 58,
'main': 59,
'map': 60,
'mark': 61,
'menu': 62,
'meta': 63,
'meter': 64,
'nav': 65,
'noscript': 66,
'object': 67,
'ol': 68,
'optgroup': 69,
'option': 70,
'output': 71,
'p': 72,
'picture': 73,
'pre': 74,
'progress': 75,
'q': 76,
's': 77,
'samp': 78,
'script': 79,
'section': 80,
'select': 81,
'slot': 82,
'small': 83,
'source': 84,
'span': 85,
'strong': 86,
'style': 87,
'sub': 88,
'summary': 89,
'sup': 90,
'table': 91,
'tbody': 92,
'td': 93,
'template': 94,
'textarea': 95,
'tfoot': 96,
'th': 97,
'thead': 98,
'time': 99,
'title': 100,
'tr': 101,
'track': 102,
'u': 103,
'ul': 104,
'var': 105,
'video': 106,
'wbr': 107,
'custom': 108
}.get(type_name, 72)
def get_enum(self):
return self.get('property0', 72)
def set_enum(self, value):
select_current = self.get_enum_id_value(self, 'property0', value)
select_prev = self.property0
if select_prev != select_current:
for i in range(len(self.inputs)):
if type(self.inputs[i]) is str:
if len(self.inputs[i].default_value_raw) > 0:
self.data_map[self.inputs[i].name] = self.inputs[i].default_value_raw
else:
self.data_map[self.inputs[i].name] = ""
else:
self.data_map[self.inputs[i].name] = self.inputs[i].default_value_raw
for i in self.inputs:
self.inputs.remove(i)
index = self.get_count_in(select_current)
if (index != 44 and index != 48 and index != 63 and index != 100):
if (index != 87):
self.add_input('LnxStringSocket', 'Content')
self.add_input('LnxStringSocket', 'ID')
self.add_input('LnxStringSocket', 'Class')
self.add_input('LnxStringSocket', 'Style')
match index:
case 0:
self.add_input('LnxStringSocket', 'Href', default_value='#')
case 3:
self.add_input('LnxStringSocket', 'Alt')
self.add_input('LnxStringSocket', 'Coords')
self.add_input('LnxStringSocket', 'Href')
case 6:
self.add_input('LnxStringSocket', 'Src')
case 11:
self.add_input('LnxStringSocket', 'Cite', default_value='URL')
case 14:
self.add_input('LnxStringSocket', 'Type', default_value='Submit')
case 15:
self.add_input('LnxStringSocket', 'Height', default_value='150px')
self.add_input('LnxStringSocket', 'Width', default_value='300px')
case 19 | 20:
self.add_input('LnxStringSocket', 'Span')
case 21:
self.add_input('LnxStringSocket', 'Value')
case 24 | 53:
self.add_input('LnxStringSocket', 'Cite', default_value='URL')
self.add_input('LnxStringSocket', 'Datetime', default_value='YYYY-MM-DDThh:mm:ssTZD')
case 26:
self.add_input('LnxStringSocket', 'Title')
case 32:
self.add_input('LnxStringSocket', 'Src', default_value='URL')
self.add_input('LnxStringSocket', 'Type')
self.add_input('LnxStringSocket', 'Height')
self.add_input('LnxStringSocket', 'Width')
case 33:
self.add_input('LnxStringSocket', 'Form')
self.add_input('LnxStringSocket', 'Name')
case 37:
self.add_input('LnxStringSocket', 'Action', default_value='URL')
self.add_input('LnxStringSocket', 'Method', default_value='get')
case 44:
self.add_input('LnxStringSocket', 'Profile', default_value='URI')
case 48:
self.add_input('LnxBoolSocket', 'xmlns' , default_value=False )
case 50:
self.add_input('LnxStringSocket', 'Src', default_value='URL')
self.add_input('LnxStringSocket', 'Height' , default_value="150px" )
self.add_input('LnxStringSocket', 'Width', default_value='300px')
case 51:
self.add_input('LnxStringSocket', 'Src')
self.add_input('LnxStringSocket', 'Height' , default_value='150px')
self.add_input('LnxStringSocket', 'Width', default_value='150px')
case 52:
self.add_input('LnxStringSocket', 'Type', default_value='text')
self.add_input('LnxStringSocket', 'Value')
case 55:
self.add_input('LnxStringSocket', 'For', default_value='element_id')
self.add_input('LnxStringSocket', 'Form', default_value='form_id')
case 57:
self.add_input('LnxStringSocket', 'Value')
case 58:
self.add_input('LnxStringSocket', 'Href', default_value='#')
self.add_input('LnxStringSocket', 'Hreflang', default_value='en')
self.add_input('LnxStringSocket', 'Title')
case 58:
self.add_input('LnxStringSocket', 'Name', default_value='mapname')
case 63:
self.add_input('LnxStringSocket', 'Charset', default_value='character_set')
self.add_input('LnxStringSocket', 'Content', default_value='text')
case 64:
self.add_input('LnxStringSocket', 'form', default_value='form_id')
self.add_input('LnxStringSocket', 'high')
self.add_input('LnxStringSocket', 'low')
self.add_input('LnxStringSocket', 'max')
self.add_input('LnxStringSocket', 'min')
self.add_input('LnxStringSocket', 'optimum')
self.add_input('LnxStringSocket', 'value')
case 67:
self.add_input('LnxStringSocket', 'data', default_value='URL')
self.add_input('LnxStringSocket', 'form', default_value='form_id')
self.add_input('LnxStringSocket', 'height', default_value='pixels')
self.add_input('LnxStringSocket', 'name', default_value='name')
self.add_input('LnxStringSocket', 'type', default_value='media_type')
self.add_input('LnxStringSocket', 'usemap', default_value='#mapname')
self.add_input('LnxStringSocket', 'width', default_value='pixels')
case 68:
self.add_input('LnxStringSocket', 'start', default_value='number')
case 69:
self.add_input('LnxStringSocket', 'label', default_value='text')
case 70:
self.add_input('LnxStringSocket', 'label', default_value='text')
self.add_input('LnxStringSocket', 'value', default_value='value')
case 71:
self.add_input('LnxStringSocket', 'for', default_value='element_id')
self.add_input('LnxStringSocket', 'form', default_value='form_id')
self.add_input('LnxStringSocket', 'name', default_value='name')
case 75:
self.add_input('LnxStringSocket', 'max', default_value='number')
self.add_input('LnxStringSocket', 'value', default_value='number')
case 76:
self.add_input('LnxStringSocket', 'cite', default_value='URL')
case 78:
self.add_input('LnxStringSocket', 'cite', default_value='URL')
case 79:
self.add_input('LnxStringSocket', 'integrity' , default_value='filehash')
self.add_input('LnxStringSocket', 'Src')
self.add_input('LnxStringSocket', 'type', default_value='scripttype')
case 81:
self.add_input('LnxStringSocket', 'form' , default_value='form_id')
self.add_input('LnxStringSocket', 'name' , default_value='text')
self.add_input('LnxStringSocket', 'type', default_value='scripttype')
self.add_input('LnxStringSocket', 'size', default_value='number')
case 84:
self.add_input('LnxStringSocket', 'size')
self.add_input('LnxStringSocket', 'src' , default_value='URL')
self.add_input('LnxStringSocket', 'srcset', default_value='URL')
case 87:
self.add_input('LnxStringSocket', 'type', default_value='media_type')
case 93:
self.add_input('LnxStringSocket', 'colspan' , default_value='number')
self.add_input('LnxStringSocket', 'headers' , default_value='header_id')
self.add_input('LnxStringSocket', 'rowspan', default_value='number')
case 95:
self.add_input('LnxStringSocket', 'cols' , default_value='number')
self.add_input('LnxStringSocket', 'dirname' , default_value='name.dir')
self.add_input('LnxStringSocket', 'rowspan', default_value='number')
self.add_input('LnxStringSocket', 'form', default_value='form_id')
self.add_input('LnxStringSocket', 'maxlength', default_value='number')
self.add_input('LnxStringSocket', 'name' , default_value='text')
self.add_input('LnxStringSocket', 'placeholder' , default_value='text')
self.add_input('LnxStringSocket', 'rows' , default_value='number')
case 97:
self.add_input('LnxStringSocket', 'abbr' , default_value='text')
self.add_input('LnxStringSocket', 'colspan' , default_value='number')
self.add_input('LnxStringSocket', 'headers', default_value='header_id')
self.add_input('LnxStringSocket', 'rowspan', default_value='number')
case 99:
self.add_input('LnxStringSocket', 'Datetime', default_value='YYYY-MM-DDThh:mm:ssTZD')
case 102:
self.add_input('LnxStringSocket', 'Src', default_value='URL')
self.add_input('LnxStringSocket', 'srclang', default_value='en')
self.add_input('LnxStringSocket', 'label', default_value='text')
case 106:
self.add_input('LnxStringSocket', 'Src', default_value='URL')
self.add_input('LnxStringSocket', 'width', default_value='pixels')
self.add_input('LnxStringSocket', 'height', default_value='pixels')
self.add_input('LnxStringSocket', 'poster', default_value='URL')
for i in range(len(self.inputs)):
if self.inputs[i].name in self.data_map:
self.inputs[i].default_value_raw = self.data_map[self.inputs[i].name]
self['property0'] = value
self.data_map = {}
property0: HaxeEnumProperty(
'property0',
items = [('a', 'A', '<a>: The Anchor element'),
('abbr', 'Abbr', '<abbr>: The Abbreviation element'),
('address', 'Address', '<address>: The Contact Address element'),
('area', 'Area', '<area>: The Image Map Area element'),
('article', 'Article', '<article>: The Article Contents element'),
('aside', 'Aside', '<aside>: The Aside element'),
('audio', 'Audio', '<audio>: The Embed Audio element'),
('bold', 'Bold', '<b>: The Bring Bold Attention To element'),
('base', 'Base', '<base>: The Document Base URL element'),
('bdi', 'Bdi', '<bdi>: The Bidirectional Isolate element'),
('bdo', 'Bdo', '<bdo>: The Bidirectional Text Override element'),
('blockquote', 'Blockquote', '<blockquote>: The Block Quotation element'),
('body', 'Body', '<body>: The Document Body element'),
('br', 'Br', '<br>: The Line Break element'),
('button', 'Button', '<button>: The Button element'),
('canvas', 'Canvas', '<canvas>: The Graphics Canvas element'),
('caption', 'Caption', '<caption>: The Table Caption element'),
('cite', 'Cite', '<cite>: The Citation element'),
('code', 'Code', '<code>: The Inline Code element'),
('col', 'Col', '<col>: The Table Column element'),
('colgroup', 'Colgroup', '<colgroup>: The Table Column Group element'),
('data', 'Data', '<data>: The Data element'),
('datalist', 'Datalist', '<datalist>: The HTML Data List element'),
('dd', 'Dd', '<dd>: The Description Details element'),
('del', 'Del', '<del>: The Deleted Text element'),
('details', 'Details', '<details>: The Details disclosure element'),
('dfn', 'Dfn', '<dfn>: The Definition element'),
('dialog', 'Dialog', '<dialog>: The Dialog element'),
('div', 'Div', '<div>: The Content Division / Divider element'),
('dl', 'Dl', '<dl>: The Description List element'),
('dt', 'Dt', '<dt>: The Description Term element'),
('em', 'Em', '<em>: The Emphasis element'),
('embed', 'Embed', '<embed>: The Embed External Content element'),
('fieldset', 'Fieldset', '<fieldset>: The Field Set element'),
('figcaption', 'Figcaption', '<figcaption>: The Figure Caption element'),
('figure', 'Figure', '<figure>: The Figure with Optional Caption element'),
('footer', 'Footer', '<footer>: The Footer Element'),
('form', 'Form', '<form>: The Form element'),
('h1', 'H1', '<h1>: The Size 1 Heading'),
('h2', 'H2', '<h2>: The Size 2 Heading'),
('h3', 'H3', '<h3>: The Size 3 Heading'),
('h4', 'H4', '<h4>: The Size 4 Heading'),
('h5', 'H5', '<h5>: The Size 5 Heading'),
('h6', 'H6', '<h6>: The Size 6 Heading'),
('head', 'Head', '<head>: The Document Metadata (Head) element'),
('header', 'Header', '<header>: The Header element'),
('hgroup', 'Hgroup', '<hgroup>: The Header element'),
('hr', 'Hr', '<hr>: The Thematic Break (Horizontal Rule) element'),
('html', 'Html', '<html>: The HTML Document / Root element'),
('i', 'I', '<i>: The Idiomatic Text element'),
('iframe', 'Iframe', '<iframe>: The Inline Frame element'),#51
('img', 'Img', '<img>: The Image Embed element'),
('input', 'Input', '<input>: The Input (Form Input) element'),
('ins', 'Ins', '<ins>: The Inserted Text Element'),
('kbd', 'Kbd', '<kbd>: The Keyboard Input element'),
('label', 'Label', '<label>: The Label element'),
('legend', 'Legend', '<legend>: The Field Set Legend element'),
('li', 'Li', '<li>: The List Item element'),
('link', 'Link', '<link>: The External Resource Link element'),#59
('main', 'Main', '<main>: The Main Body element'),
('map', 'Map', '<map>: The Image Map element'),
('mark', 'Mark', '<mark>: The Mark Text element'),
('menu', 'Menu', '<menu>: The Menu element'),
('meta', 'Meta', '<meta>: The metadata element'),
('meter', 'Meter', '<meter>: The HTML Meter element'),
('nav', 'Nav', '<nav>: The Navigation Section element'),
('noscript', 'Noscript', '<noscript>: The Noscript element'),
('object', 'Object', '<object>: The External Object element'),
('ol', 'Ol', '<ol>: The Ordered List element'),
('optgroup', 'Optgroup', '<optgroup>: The Option Group element'),
('option', 'Option', '<option>: The HTML Option element'),
('output', 'Output', '<output>: The Output element'),
('p', 'P', '<p>: The Paragraph element'),
('picture', 'Picture', '<picture>: The Picture element'),
('pre', 'Pre', '<pre>: The Preformatted Text element'),
('progress', 'Progress', '<progress>: The Progress Indicator element'),
('q', 'Q', '<q>: The Inline Quotation element'),
('s', 'S', '<s>: The Strikethrough element'),
('sample', 'Sample', '<samp>: The Sample Output element'),
('script', 'Script', '<script>: The Script element'), #68
('section', 'Section', '<section>: The Generic Section element'),
('select', 'Select', '<select>: The HTML Select element'),
('slot', 'Slot', '<slot>: The Web Component Slot element'),
('small', 'Small', '<small>: The Small Side Comment element'),
('source', 'Source', '<source>: The Media or Image Source element'),
('span', 'Span', '<span>: The Content Span element'),
('strong', 'Strong', '<strong>: The Strong Importance element'),
('style', 'Style', '<style>: The Style Information element'),
('sub', 'Sub', '<sub>: The Subscript element'),
('summary', 'Summary', '<summary>: The Disclosure Summary element'),
('sup', 'Sup', '<sup>: The Superscript element'),
('table', 'Table', '<table>: The Table element'),
('tbody', 'Tbody', '<tbody>: The Table Body element'),
('td', 'Td', '<td>: The Table Data Cell element'),
('template', 'Template', '<template>: The Content Template element'),
('textarea', 'Textarea', '<textarea>: The Textarea element'),
('tfoot', 'Tfoot', '<tfoot>: The Table Foot element'),
('th', 'Th', '<th>: The Table Header element'),
('thead', 'Thead', '<thead>: The Table Head element'),
('time', 'Time', '<time>: The (Date) Time element'),
('title', 'Title', '<title>: The Document Title element'),
('tr', 'Tr', '<tr>: The Table Row element'),
('track', 'Track', '<track>: The Embed Text Track element'),
('u', 'U', '<u>: The Unarticulated Annotation (Underline) element'),
('ul', 'Ul', '<ul>: The Unordered List element'),
('var', 'Var', '<var>: The Variable element'),
('video', 'Video', '<video>: The Video Embed element'),
('wbr', 'Wbr', '<wbr>: The Line Break Opportunity element'),
('custom', 'Custom', '<*/Custom*/>: The Output element')],
name='',
default='p',
set=set_enum,
get=get_enum)
def lnx_init(self, context):
self.add_input('LnxStringSocket', 'Content')
self.add_input('LnxStringSocket', 'ID')
self.add_input('LnxStringSocket', 'Class')
self.add_input('LnxStringSocket', 'Style')
self.add_output('LnxDynamicSocket', 'Element')
self.add_output('LnxStringSocket', 'HTML')
def draw_buttons(self, context, layout):
layout.prop(self, 'property0')
def draw_label(self) -> str:
context = self.inputs[0].get_default_value()
if len(context) > 0:
return f'<{self.property0}> {context} </{self.property0}>'
return f'Create <{self.property0}>'
def register():
add_category('HTML', icon='SEQ_STRIP_META')
CreateElementNode.on_register()