@@ -382,14 +382,11 @@ class ObjectBlockView(FBD_model.ObjectBlock, gui.SvgSubcontainer, MoveableWidget
382382
383383 reference_object = None
384384
385- io_font_size = 12
386- io_left_right_offset = 10
387-
388385 def __init__ (self , obj , container , x = 10 , y = 10 , * args , ** kwargs ):
389386 name = obj .__class__ .__name__
390387 self .reference_object = obj
391388 FBD_model .ObjectBlock .__init__ (self , name )
392- gui .SvgSubcontainer .__init__ (self , x , y , self . calc_width (), self . calc_height () , * args , ** kwargs )
389+ gui .SvgSubcontainer .__init__ (self , x , y , 0 , 0 , * args , ** kwargs )
393390 MoveableWidget .__init__ (self , container , * args , ** kwargs )
394391
395392 self .outline = gui .SvgRectangle (0 , 0 , "100%" , "100%" )
@@ -403,33 +400,31 @@ def __init__(self, obj, container, x = 10, y = 10, *args, **kwargs):
403400 self .label .css_font_size = gui .to_pix (self .label_font_size )
404401 self .append (self .label )
405402
406- self .onselection_start = self .container .onselection_start
407- self .onselection_end = self .container .onselection_end
408-
409403 """
410404 for (method_name, method) in inspect.getmembers(self.reference_object, inspect.ismethod):
411405 #try:
412406 #c = types.new_class(method_name, (FunctionBlockView,))
413407 #setattr(c, "do", types.MethodType(getattr(self.reference_object, method_name), c))
414408 #c.do.__dict__['_outputs'] = []
415409 #FBD_model.FunctionBlock.decorate_process(['OUT'])(c.do)
416- #self.add_fb_view (c(method_name, container))
417- self.add_fb_view (ObjectFunctionBlockView(self.reference_object, method, method_name, method_name, self))
410+ #self.add_function_block_view (c(method_name, container))
411+ self.add_function_block_view (ObjectFunctionBlockView(self.reference_object, method, method_name, method_name, self))
418412 #except:
419413 # pass
420414
421415 for (class_name, _class) in inspect.getmembers(self.reference_object):
422416 evt = getattr(self.reference_object, class_name)
423417 if issubclass(type(_class), gui.ClassEventConnector):
424418 #self.append(ObjectBlockView(evt, self))
425- self.add_fb_view (ObjectFunctionBlockView(evt, evt, "do", evt.event_method_bound.__name__ + ".do", self))
419+ self.add_function_block_view (ObjectFunctionBlockView(evt, evt, "do", evt.event_method_bound.__name__ + ".do", self))
426420 """
427421 self .stop_drag .do (lambda emitter , x , y :self .adjust_geometry ())
422+ self .adjust_geometry ()
428423
429424 def calc_height (self ):
430425 xmax = ymax = 0
431- if not self .FBs is None :
432- for fb in self . FBs . values ( ):
426+ for fb in self .children . values () :
427+ if issubclass ( type ( fb ), FunctionBlockView ):
433428 x , y = fb .get_position ()
434429 w , h = fb .get_size ()
435430 xmax = max (xmax , x + w )
@@ -439,68 +434,35 @@ def calc_height(self):
439434
440435 def calc_width (self ):
441436 xmax = ymax = 0
442- if not self .FBs is None :
443- for fb in self . FBs . values ( ):
437+ for fb in self .children . values () :
438+ if issubclass ( type ( fb ), FunctionBlockView ):
444439 x , y = fb .get_position ()
445440 w , h = fb .get_size ()
446441 xmax = max (xmax , x + w )
447442 ymax = max (ymax , y + h )
448443
449444 return max ((len (self .name ) * self .label_font_size * 0.6 ), xmax )
450445
451- def add_fb_view (self , fb_view_instance ):
452- self .FBs [fb_view_instance .name ] = fb_view_instance
453-
454- self .append (fb_view_instance )
455- for fb in self .FBs .values ():
456- fb .adjust_geometry ()
457- fb .on_drag .do (self .onfunction_block_position_changed )
458- self .adjust_geometry ()
459-
460- def add_io_widget (self , widget ):
461- widget .label .css_font_size = gui .to_pix (self .io_font_size )
462- widget .set_size (len (widget .name ) * self .io_font_size , self .io_font_size )
463-
464- FBD_model .FunctionBlock .add_io (self , widget )
465- self .append (widget )
466- widget .onmousedown .do (self .container .onselection_start , js_stop_propagation = True , js_prevent_default = True )
467- widget .onmouseup .do (self .container .onselection_end , js_stop_propagation = True , js_prevent_default = True )
468-
446+ def add_function_block_view (self , fb_view_instance ):
447+ self .container .add_function_block (fb_view_instance )
448+ for fb in self .children .values ():
449+ if issubclass (type (fb ), FunctionBlockView ):
450+ fb .adjust_geometry ()
451+ fb .on_drag .do (self .onfunction_block_position_changed )
469452 self .adjust_geometry ()
470453
471454 def onfunction_block_position_changed (self , emitter , x , y ):
472455 emitter .adjust_geometry ()
473456 self .adjust_geometry ()
474457
475458 def adjust_geometry (self ):
476- w , h = self .get_size ()
477-
478- i = 1
479- for inp in self .inputs .values ():
480- inp .set_position (0 , self .label_font_size + self .io_font_size * i )
481- inp .onpositionchanged ()
482- i += 1
483-
484- i = 1
485- for o in self .outputs .values ():
486- ow , oh = o .get_size ()
487- o .set_position (w - ow , self .label_font_size + self .io_font_size * i )
488- o .onpositionchanged ()
489- i += 1
490-
491459 gui ._MixinSvgSize .set_size (self , self .calc_width (), self .calc_height ())
492460
493461 def set_position (self , x , y ):
494- for fb in self .FBs .values ():
495- fb .onposition_changed ()
462+ for fb in self .children .values ():
463+ if issubclass (type (fb ), FunctionBlockView ):
464+ fb .onposition_changed ()
496465
497- for inp in self .inputs .values ():
498- inp .onpositionchanged ()
499-
500- for o in self .outputs .values ():
501- o .onpositionchanged ()
502- #w, h = self.get_size()
503- #self.attr_viewBox = "%s %s %s %s"%(x, y, x+w, y+h)
504466 return gui .SvgSubcontainer .set_position (self , x , y )
505467
506468 def set_name (self , name ):
@@ -514,12 +476,12 @@ def __init__(self, obj, container, x = 10, y = 10, *args, **kwargs):
514476 ObjectBlockView .__init__ (self , obj , container , x = 10 , y = 10 , * args , ** kwargs )
515477
516478 txt = gui .TextInput ()
517- ofbv = ObjectFunctionBlockView (self .reference_object , txt .get_value , "get_value" , "get_value" , self )
479+ ofbv = ObjectFunctionBlockView (self .reference_object , txt .get_value , "get_value" , "get_value" , self . container )
518480 ofbv .add_io_widget (OutputView ("Value" ))
519- self .add_fb_view (ofbv )
481+ self .add_function_block_view (ofbv )
520482
521- ofbv = ObjectFunctionBlockView (self .reference_object , txt .set_value , "set_value" , "set_value" , self )
522- self .add_fb_view (ofbv )
483+ ofbv = ObjectFunctionBlockView (self .reference_object , txt .set_value , "set_value" , "set_value" , self . container )
484+ self .add_function_block_view (ofbv )
523485
524486 """
525487 ie = InputEvent("onclicked", self.callback_test)
0 commit comments