(self, appInstance, widgetClass, **kwargs_to_widget)
| 469 | """ |
| 470 | |
| 471 | def __init__(self, appInstance, widgetClass, **kwargs_to_widget): |
| 472 | self.kwargs_to_widget = kwargs_to_widget |
| 473 | self.appInstance = appInstance |
| 474 | self.widgetClass = widgetClass |
| 475 | super(WidgetHelper, self).__init__() |
| 476 | self.style.update({'background-color': 'rgb(250,250,250)', 'width': "auto", 'margin':"2px", |
| 477 | "height": "60px", "justify-content": "center", "align-items": "center", |
| 478 | 'font-size': '12px'}) |
| 479 | if hasattr(widgetClass, "icon"): |
| 480 | if type(widgetClass.icon) == gui.Svg: |
| 481 | self.icon = widgetClass.icon |
| 482 | elif widgetClass.icon == None: |
| 483 | self.icon = default_icon(self.widgetClass.__name__) |
| 484 | else: |
| 485 | icon_file = widgetClass.icon |
| 486 | self.icon = gui.Image(icon_file, width='auto', margin='2px') |
| 487 | else: |
| 488 | icon_file = '/editor_resources:widget_%s.png' % self.widgetClass.__name__ |
| 489 | if os.path.exists(self.appInstance._get_static_file(icon_file)): |
| 490 | self.icon = gui.Image(icon_file, width='auto', margin='2px') |
| 491 | else: |
| 492 | self.icon = default_icon(self.widgetClass.__name__) |
| 493 | |
| 494 | self.icon.style['max-width'] = '100%' |
| 495 | self.icon.style['image-rendering'] = 'auto' |
| 496 | self.icon.attributes['draggable'] = 'false' |
| 497 | self.icon.attributes['ondragstart'] = "event.preventDefault();" |
| 498 | self.append(self.icon, 'icon') |
| 499 | self.append(gui.Label(self.widgetClass.__name__), 'label') |
| 500 | self.children['label'].style.update({'margin-left':'2px', 'margin-right':'3px'}) |
| 501 | |
| 502 | self.attributes.update({'draggable': 'true', |
| 503 | 'ondragstart': "this.style.cursor='move'; event.dataTransfer.dropEffect = 'move'; event.dataTransfer.setData('application/json', JSON.stringify(['add',event.target.id,(event.clientX),(event.clientY)]));", |
| 504 | 'ondragover': "event.preventDefault();", |
| 505 | 'ondrop': "event.preventDefault();return false;"}) |
| 506 | |
| 507 | # this dictionary will contain optional style attributes that have to be added to the widget once created |
| 508 | self.optional_style_dict = {} |
| 509 | |
| 510 | self.onclick.do(self.create_instance) |
| 511 | |
| 512 | def build_widget_name_list_from_tree(self, node): |
| 513 | if not hasattr(node, 'attributes'): |
nothing calls this directly
no test coverage detected