Couple of Qt Questions.

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Couple of Qt Questions.

Post by keithsloan52 »

openBrain wrote: Wed May 26, 2021 2:40 pm
keithsloan52 wrote: Wed May 26, 2021 2:35 pm

Code: Select all

5:33:37  Traceback (most recent call last):
15:33:37    File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/GDMLCommands.py", line 798, in actionMesh
15:33:37      print(self.form.meshInfoLayout.Vertex)
15:33:37  AttributeError: 'PySide2.QtWidgets.QHBoxLayout' object has no attribute 'Vertex'
So it does not show up in the form or the layout :-(
I don't really understand. Of course it has no 'Vertex' attribute if you didn't modify other lines of the snippet. :?

Maybe the simple so you hopefully understand. Take the snippet as it was some post above and change

Code: Select all

print(dir(self.form.meshinfoLayout))
to

Code: Select all

print(dir(self.form))
and you'll see 'Vertex' ;)
Nope, that is where I started

My first course of action was a print(dir(self.form)) and it is still there
When I go in a second time it shows

Code: Select all

15:33:37  Check Form
15:33:37  ['DrawChildren', 'DrawWindowBackground', 'IgnoreMask', 'PaintDeviceMetric', 'PdmDepth', 'PdmDevicePixelRatio', 'PdmDevicePixelRatioScaled', 'PdmDpiX', 'PdmDpiY', 'PdmHeight', 'PdmHeightMM', 'PdmNumColors', 'PdmPhysicalDpiX', 'PdmPhysicalDpiY', 'PdmWidth', 'PdmWidthMM', 'RenderFlag', 'RenderFlags', 'Vlayout', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'acceptDrops', 'accessibleDescription', 'accessibleName', 'actionEvent', 'actions', 'activateWindow', 'addAction', 'addActions', 'adjustSize', 'autoFillBackground', 'backgroundRole', 'backingStore', 'baseSize', 'blockSignals', 'buttonMesh', 'changeEvent', 'childAt', 'childEvent', 'children', 'childrenRect', 'childrenRegion', 'clearFocus', 'clearMask', 'close', 'closeEvent', 'colorCount', 'connect', 'connectNotify', 'contentsMargins', 'contentsRect', 'contextMenuEvent', 'contextMenuPolicy', 'create', 'createWinId', 'createWindowContainer', 'cursor', 'curveLen', 'customContextMenuRequested', 'customEvent', 'deleteLater', 'depth', 'destroy', 'destroyed', 'devType', 'devicePixelRatio', 'devicePixelRatioF', 'devicePixelRatioFScale', 'disconnect', 'disconnectNotify', 'dragEnterEvent', 'dragLeaveEvent', 'dragMoveEvent', 'dropEvent', 'dumpObjectInfo', 'dumpObjectTree', 'dynamicPropertyNames', 'effectiveWinId', 'emit', 'ensurePolished', 'enterEvent', 'event', 'eventFilter', 'find', 'findChild', 'findChildren', 'focusInEvent', 'focusNextChild', 'focusNextPrevChild', 'focusOutEvent', 'focusPolicy', 'focusPreviousChild', 'focusProxy', 'focusWidget', 'font', 'fontInfo', 'fontMetrics', 'foregroundRole', 'frameGeometry', 'frameSize', 'geometry', 'getContentsMargins', 'grab', 'grabGesture', 'grabKeyboard', 'grabMouse', 'grabShortcut', 'graphicsEffect', 'graphicsProxyWidget', 'hasFocus', 'hasHeightForWidth', 'hasMouseTracking', 'hasTabletTracking', 'height', 'heightForWidth', 'heightMM', 'hide', 'hideEvent', 'inherits', 'initPainter', 'inputMethodEvent', 'inputMethodHints', 'inputMethodQuery', 'insertAction', 'insertActions', 'installEventFilter', 'internalWinId', 'isActiveWindow', 'isAncestorOf', 'isEnabled', 'isEnabledTo', 'isEnabledToTLW', 'isFullScreen', 'isHidden', 'isLeftToRight', 'isMaximized', 'isMinimized', 'isModal', 'isRightToLeft', 'isSignalConnected', 'isTopLevel', 'isVisible', 'isVisibleTo', 'isWidgetType', 'isWindow', 'isWindowModified', 'isWindowType', 'keyPressEvent', 'keyReleaseEvent', 'keyboardGrabber', 'killTimer', 'layout', 'layoutDirection', 'leaveEvent', 'locale', 'logicalDpiX', 'logicalDpiY', 'lower', 'mapFrom', 'mapFromGlobal', 'mapFromParent', 'mapTo', 'mapToGlobal', 'mapToParent', 'mask', 'maxLen', 'maximumHeight', 'maximumSize', 'maximumWidth', 'meshInfoLayout', 'meshParmsLayout', 'metaObject', 'metric', 'minimumHeight', 'minimumSize', 'minimumSizeHint', 'minimumWidth', 'mouseDoubleClickEvent', 'mouseGrabber', 'mouseMoveEvent', 'mousePressEvent', 'mouseReleaseEvent', 'move', 'moveEvent', 'moveToThread', 'nativeEvent', 'nativeParentWidget', 'nextInFocusChain', 'normalGeometry', 'objectName', 'objectNameChanged', 'overrideWindowFlags', 'overrideWindowState', 'paintEngine', 'paintEvent', 'painters', 'paintingActive', 'palette', 'parent', 'parentWidget', 'physicalDpiX', 'physicalDpiY', 'pointLen', 'pos', 'previousInFocusChain', 'property', 'raise_', 'receivers', 'rect', 'redirected', 'registerUserData', 'releaseKeyboard', 'releaseMouse', 'releaseShortcut', 'removeAction', 'removeEventFilter', 'render', 'repaint', 'resize', 'resizeEvent', 'restoreGeometry', 'retranslateUi', 'saveGeometry', 'scroll', 'sender', 'senderSignalIndex', 'setAcceptDrops', 'setAccessibleDescription', 'setAccessibleName', 'setAttribute', 'setAutoFillBackground', 'setBackgroundRole', 'setBaseSize', 'setContentsMargins', 'setContextMenuPolic...
i.e. Has Vlayout, meshInfoLayout, 'meshParmsLayout etc but No Vertex or Facets

The panel shows the Vertex and Facet Widgets :-(

And if I add code to add them I get a second set.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Couple of Qt Questions.

Post by openBrain »

keithsloan52 wrote: Wed May 26, 2021 4:40 pm i.e. Has Vlayout, meshInfoLayout, 'meshParmsLayout etc but No Vertex or Facets

The panel shows the Vertex and Facet Widgets :-(

And if I add code to add them I get a second set.
I think missing attributes are deleted somewhere in the code. Of course deleting them doesn't delete the QWidget so they still are present.
Do you have a pointer to the whole code?
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Couple of Qt Questions.

Post by keithsloan52 »

openBrain wrote: Wed May 26, 2021 5:04 pm
keithsloan52 wrote: Wed May 26, 2021 4:40 pm i.e. Has Vlayout, meshInfoLayout, 'meshParmsLayout etc but No Vertex or Facets

The panel shows the Vertex and Facet Widgets :-(

And if I add code to add them I get a second set.
I think missing attributes are deleted somewhere in the code. Of course deleting them doesn't delete the QWidget so they still are present.
Do you have a pointer to the whole code?
The code is in github repro https://github.com/KeithSloan/GDML in branch Gmsh
relevant code is in GDMLCommands.py see def actionMesh in class AddTessellateTask
Can give more info if required.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Couple of Qt Questions.

Post by openBrain »

OK, not so easy to read.
ATM I saw nothing really weird except you set 2 times the layout :
https://github.com/KeithSloan/GDML/blob ... ds.py#L809
and
https://github.com/KeithSloan/GDML/blob ... ds.py#L697
do the same and I'm not sure this is really good.

Will try to have a second look when brain has cooled down. :)
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Couple of Qt Questions.

Post by keithsloan52 »

openBrain wrote: Thu May 27, 2021 12:45 pm OK, not so easy to read.
ATM I saw nothing really weird except you set 2 times the layout :
https://github.com/KeithSloan/GDML/blob ... ds.py#L809
and
https://github.com/KeithSloan/GDML/blob ... ds.py#L697
do the same and I'm not sure this is really good.

Will try to have a second look when brain has cooled down. :)
I assumed I had to set it after updating it. i.e the very first time the panel is shown the meshInfo is not shown and after a mesh had been created it is shown. Is there another call to say it has been updated.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Couple of Qt Questions.

Post by openBrain »

keithsloan52 wrote: Thu May 27, 2021 2:54 pm I assumed I had to set it after updating it. i.e the very first time the panel is shown the meshInfo is not shown and after a mesh had been created it is shown. Is there another call to say it has been updated.
It should update by itself automatically once it has been set.
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Couple of Qt Questions.

Post by keithsloan52 »

openBrain wrote: Thu May 27, 2021 3:01 pm
keithsloan52 wrote: Thu May 27, 2021 2:54 pm I assumed I had to set it after updating it. i.e the very first time the panel is shown the meshInfo is not shown and after a mesh had been created it is shown. Is there another call to say it has been updated.
It should update by itself automatically once it has been set.
Okay did not seem to make any difference.

BUT Getting closer
If I define the Vertex and Facets Field when I create the form ( Rather than after meshing ) i.e.

Code: Select all

self.Vertex = oField('Vertex',6,'')
self.Facets = oField('Facets',6,'')
But don't add the layout meshInfoLayout until after the mesh is created it still works initially
and I can find and have access to self.form.Vertex on subsequent entry to the panel
But if I then try to update with

Code: Select all

self.form.Vertex.value.setText(str(len(vertex)))
It does not update straight away, but If I access the panel again the updated values are there
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Couple of Qt Questions.

Post by openBrain »

keithsloan52 wrote: Thu May 27, 2021 4:00 pm Okay did not seem to make any difference.

BUT Getting closer
If I define the Vertex and Facets Field when I create the form ( Rather than after meshing ) i.e.

Code: Select all

self.Vertex = oField('Vertex',6,'')
self.Facets = oField('Facets',6,'')
I guess these lines are in another class because 'self.Vertex' != 'self.form.Vertex'
But if I then try to update with

Code: Select all

self.form.Vertex.value.setText(str(len(vertex)))
It does not update straight away, but If I access the panel again the updated values are there
Blind guess but depending on exactly where you do the setText, you can have to enforce Gui updating with

Code: Select all

FreeCADGui.updateGui()
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Couple of Qt Questions.

Post by keithsloan52 »

openBrain wrote: Thu May 27, 2021 4:27 pm
keithsloan52 wrote: Thu May 27, 2021 4:00 pm Okay did not seem to make any difference.

BUT Getting closer
If I define the Vertex and Facets Field when I create the form ( Rather than after meshing ) i.e.

Code: Select all

self.Vertex = oField('Vertex',6,'')
self.Facets = oField('Facets',6,'')
I guess these lines are in another class because 'self.Vertex' != 'self.form.Vertex'
Yes they are in the section where the panel is created
But if I then try to update with

Code: Select all

self.form.Vertex.value.setText(str(len(vertex)))
It does not update straight away, but If I access the panel again the updated values are there
Blind guess but depending on exactly where you do the setText, you can have to enforce Gui updating with

Code: Select all

FreeCADGui.updateGui()
Good try but no cigar
My guess is that one has to call something to cause Qt to update the dialogue panel
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Couple of Qt Questions.

Post by keithsloan52 »

Has something to do with if I close the task panel and go back in it no longer updates the Vertex and Facets info.
Post Reply