Problem with controls from array created with getChildrenOfWidget()

ruekakaruekaka Posts: 346

Hello.

I stumbled into a strange problem when using getChildrenOfWidget() to get the controls of a form.

(I didn't test all types yet, but I found 3 types where I can't get the value of the control)

I create 3 prompts of the following types: DzFloatSlider, DzIntSlider and DzColorWgt

When I access the objects direct it works as expected (although the class name is different):

ce_test_prompt_3: [object Object] (Class name: DsColorWgt) [x:216, y:250, w:560, h:24 || value.name: #256997] (Name: ce_test_prompt_3)
ne_test_prompt_4: [object Object] (Class name: DsIntSlider) [x:216, y:275, w:560, h:26 || min: -100, max: 100, value: 77 (Name: ne_test_prompt_4)
ne_test_prompt_5: [object Object] (Class name: DsFloatSlider) [x:216, y:305, w:560, h:26 || min: -1000, max: 1000, value: 12.34000015258789 (Name: ne_test_prompt_5)

But when I use getChildrenOfWidget() and pick the 3 controls from the array I get the following:

control: [object Object] (Class name: DzColorWgt)[<<<-Result of expression 'theVar.value' [undefined] is not an object.->>>] (Name: ce_test_prompt_3)
control: [object Object] (Class name: DzIntSlider) [x:216, y:275, w:560, h:26 || min: undefined, max: undefined, value: undefined (Name: ne_test_prompt_4)
control: [object Object] (Class name: DzFloatSlider) [x:216, y:305, w:560, h:26 || min: undefined, max: undefined, value: undefined (Name: ne_test_prompt_5)

The (e.g.) text property of a line edit control or the checked property of a checkbox show the correct value when picked from the array.

How can I access the values from the controls taken from the array?

Any hint is highly welcome.

With kind regards,

Ruediger Kabbasch

 

Post edited by Chohole on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,842

    There really isn't enough context to offer anything

  • ruekakaruekaka Posts: 346
    edited June 2020

    O.K., I thought I described all the details blush

    Anyway, I created the most simple example to reproduce it:

    // DAZ Studio version 4.12.1.117 filetype DAZ Scriptvar m42Maindialog = null;var textEdit      = null;var colorEdit     = null;var doubleEdit    = null;var integerEdit   = null;var lineEdit      = nullvar buttonTest    = null;(   function()   {      PrepareMainDialog("Array tester", 800, 600);      m42Maindialog.exec();   })();function PrepareMainDialog(formCaption, width, height){   m42Maindialog            = new DzDialog;   m42Maindialog.name       = "m42_main_form";   m42Maindialog.caption    = formCaption;   m42Maindialog.width      = width;   m42Maindialog.height     = height;   m42Maindialog.minWidth   = width;   m42Maindialog.minHeight  = height;   m42Maindialog.maxWidth   = width;   m42Maindialog.maxHeight  = height;   buttonTest = new DzPushButton(m42Maindialog);   buttonTest.text      = "Run Test";   buttonTest.name      = "buttonTest";   buttonTest.width     = 200;   buttonTest.height    = 24;   buttonTest.x         = 10;   buttonTest.y         = 10;   connect(buttonTest, "clicked()", testButtonClick);      lineEdit = new DzLineEdit(m42Maindialog);   lineEdit.text      = "Text value";   lineEdit.name      = "lineEdit";   lineEdit.width     = 780;   lineEdit.height    = 20;   lineEdit.x         = 10;   lineEdit.y         = 40;      colorEdit = new DzColorWgt(m42Maindialog);   colorEdit.name      = "colorEdit";   colorEdit.width     = 780;   colorEdit.height    = 20;   colorEdit.x         = 10;   colorEdit.y         = 70;   colorEdit.value     = Color(37, 105, 151);      integerEdit = new DzIntSlider(m42Maindialog);   integerEdit.name      = "integerEdit";   integerEdit.width     = 780;   integerEdit.height    = 20;   integerEdit.x         = 10;   integerEdit.y         = 100;   integerEdit.value     = 77;   integerEdit.min       = -100;   integerEdit.max       = 100;   doubleEdit = new DzFloatSlider(m42Maindialog);   doubleEdit.name       = "doubleEdit";   doubleEdit.width      = 780;   doubleEdit.height     = 20;   doubleEdit.x          = 10;   doubleEdit.y          = 130;   doubleEdit.value      = 123.465;   doubleEdit.min        = -1000;   doubleEdit.max        = 1000;   doubleEdit.sensitivity = 0.5;   textEdit = new DzTextEdit(m42Maindialog);   textEdit.text      = "";   textEdit.name      = "textEdit";   textEdit.width     = 780;   textEdit.height    = 410;   textEdit.x         = 10;   textEdit.y         = 160;}function WriteControlInfo(theControl){   var curInfo      = "[--- I G N O R E D ---]";   var curClassName = theControl.className();   try   {      if ((curClassName == "DzWidget") || (curClassName == "DzTabWidget"))      {         curInfo = " ["                 + "x:" + theControl.x                 + ", y:" + theControl.y                 + ", w:" + theControl.width                 + ", h:" + theControl.height                 + "]";      }      else if ((curClassName == "DzIntSlider") || (curClassName == "DzFloatSlider") || (curClassName == "DsIntSlider") || (curClassName == "DsFloatSlider"))      {         curInfo = " ["                 + "x:" + theControl.x                 + ", y:" + theControl.y                 + ", w:" + theControl.width                 + ", h:" + theControl.height                 + " || min: " + theControl.min                 + ", max: " + theControl.max                 + ", value: " + theControl.value                 + "]";      }      else if ((curClassName == "QLineEdit") || (curClassName == "DzLineEdit"))      {         curInfo = " ["                 + "x:" + theControl.x                 + ", y:" + theControl.y                 + ", w:" + theControl.width                 + ", h:" + theControl.height                 + " || text: " + theControl.text                 + "]";      }      else if (curClassName == "QCheckBox")      {         curInfo = " ["                 + "x:" + theControl.x                 + ", y:" + theControl.y                 + ", w:" + theControl.width                 + ", h:" + theControl.height                 + " || checked: " + theControl.checked                 + "]";      }      else if ((curClassName == "DzColorWgt") || (curClassName == "DsColorWgt"))      {         curInfo = " ["                 + "x:" + theControl.x                 + ", y:" + theControl.y                 + ", w:" + theControl.width                 + ", h:" + theControl.height                 + " || value.name: " + theControl.value.name                 + "]";      } //&lt;- if (theControl.className == "DzWidget")   }   catch (Exception)   {      curInfo = "[&lt;&lt;&lt;-" + Exception.message + "-&gt;&gt;&gt;]";   }   curInfo = "Name: " + theControl.name + ", Class name: " + curClassName + " || " + curInfo;   textEdit.append(curInfo);}function testButtonClick(){   textEdit.clear();   WriteControlInfo(textEdit);   WriteControlInfo(colorEdit);   WriteControlInfo(doubleEdit);   WriteControlInfo(integerEdit);   WriteControlInfo(lineEdit);      textEdit.append("");   curControls = m42Maindialog.getChildrenOfWidget();   for (iControl = 0; iControl &lt; curControls.length; iControl++)   {      if (curControls[iControl].name.length &gt; 0)      {         WriteControlInfo(curControls[iControl]);      }   }}

    An example output is attached as a screenshot

     

    problem_with_control_array_2.png
    670 x 233 - 32K
    Post edited by ruekaka on
  • andya_b341b7c5f5andya_b341b7c5f5 Posts: 694
    edited July 2020

    I don't have a solution but agree something is odd.

    I have been trying to use a DzColorWgt and found that the object returned by the DzColorWgt constructor has a className  of DsColorWgt and says it inherits from DsColorWgt.  This has a property 'value' which is initialized as a Color object (255,255,255), and can be  updated. 

    If you attempt to retrieve this widget using getWidget(), or [DzDialog].getChildrenOfWidget() you will get an object that has a className of DzColorWgt.  More importantly, the object does not have the property 'value' now.  I would not be surprised at all if the same is true of findChildOfWidget().

    (   function()   {	  var dummyDialog = new DzBasicDialog();	  var DzClrWgt = new DzColorWgt(dummyDialog);	  DzClrWgt.name = 'DzClrWgt';	  if (DzClrWgt.hasOwnProperty('value')) {		  print('Initial value: = ', DzClrWgt.value.red, DzClrWgt.value.green, DzClrWgt.value.blue);		}	  DzClrWgt.value = Color(100, 50, 0);	  DzClrWgt.col = Color(101, 50, 0);	  print('DzClrWgt: className = ', DzClrWgt.className(), ' name = ', DzClrWgt.name, 	  	'objectName = ', DzClrWgt.objectName);	  print('DzClrWgt proto ', DzClrWgt.prototype, DzClrWgt.__proto__.name);	  print('DzClrWgt.value = ', DzClrWgt.value.red);	  if (DzClrWgt.hasOwnProperty('value')) {	  	print('DzClrWgt has own prop value');	  }	  if (DzClrWgt.hasOwnProperty('col')) {	  	print('DzClrWgt has own prop col');	  }	  	  print('Enumerable properties...');	  for (var p in DzClrWgt) {	  	if (p == 'value' || p == 'col') {		  	print(p, DzClrWgt[p])		  }	  }	  print('Enumerable and non-enumerable propertes found directly on object...');	  var arr = Object.getOwnPropertyNames(DzColorWgt)	  var ownprops = arr.filter(	  	function(x) 	  	{ 	  		if ((x == 'value') || (x == 'col')) {return x}; 	  	}	  )	  ownprops.forEach(	  	function(x) { print(x) }	  )	  	  if (DzClrWgt.inherits('DsColorWgt')) {	  	print('DzClrWgt inherits DsColorWgt')	  }	  	  var w = DzClrWgt.getWidget();          print('DzClrWgt.getWidget: className ', w.className(),       	      ', value = ', w.value,       	      ', name = ', w.name);      	          print('DzClrWgt.getWidget props: ');	  if (w.hasOwnProperty('value')) {	  	print('w has own prop value');	  }	            for (var p in w) {      	  if (p == 'value') {		  	print(p, w[p])		  }	  }	  var ownprops = Object.getOwnPropertyNames(w)	  ownprops.filter(	  	function(x) 	  	{ 	  		if (x == 'value') {return x}; 	  	}	  )          try {	      print('w.value ', w.value.red);	      }	  catch(err) {	  	print('w.value - ', err);	  }	  print('getChildOfWidget props');	  var chArr = dummyDialog.getChildrenOfWidget('DzClrWgt');	  chArr.forEach(		function(x) {			print(x.name, x.className(), x.objectName)		}	  )	  try {		print(chArr[0].value.red);	  } catch(err) {		print('w.value - ', err);	  }   })();
    Executing Script...
    Initial value: =  255 255 255
    DzClrWgt: className =  DsColorWgt  name =  DzClrWgt objectName =  DzClrWgt
    DzClrWgt proto  undefined undefined
    DzClrWgt.value =  100
    DzClrWgt has own prop value
    DzClrWgt has own prop col
    Enumerable properties...
    value [object Object]
    col [object Object]
    Enumerable and non-enumerable propertes found directly on object...
    value
    col
    DzClrWgt inherits DsColorWgt
    DzClrWgt.getWidget: className  DzColorWgt , value =  undefined , name =  DzClrWgt
    DzClrWgt.getWidget props: 
    w.value -  TypeError: Result of expression 'w.value' [undefined] is not an object.
    getChildOfWidget props
    DzClrWgt DzColorWgt DzClrWgt
    w.value -  TypeError: Result of expression 'chArr[0].value' [undefined] is not an object.
    Result: 
    Script executed in 0 secs 21 msecs.
    Post edited by andya_b341b7c5f5 on
Sign In or Register to comment.