MCPcopy Index your code
hub / github.com/rawpython/remi / WidgetHelper

Class WidgetHelper

editor/editor_widgets.py:464–569  ·  view source on GitHub ↗

Allocates the Widget to which it refers, interfacing to the user in order to obtain the necessary attribute values obtains the constructor parameters, asks for them in a dialog puts the values in an attribute called constructor

Source from the content-addressed store, hash-verified

462
463
464class WidgetHelper(gui.HBox):
465 """ Allocates the Widget to which it refers,
466 interfacing to the user in order to obtain the necessary attribute values
467 obtains the constructor parameters, asks for them in a dialog
468 puts the values in an attribute called constructor
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'):
514 return
515 if not (hasattr(node, 'variable_name') and not node.variable_name is None):
516 return
517 self.varname_list.append(node.variable_name)
518 for child in node.children.values():
519 self.build_widget_name_list_from_tree(child)
520
521 def build_widget_used_keys_list_from_tree(self, node):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected