FreeCAD_drawing_dimensioning icon indicating copy to clipboard operation
FreeCAD_drawing_dimensioning copied to clipboard

changing PySide2.QtCore.QByteArray calls to be utf-8-encoded strings …

Open cmusinsky opened this issue 5 years ago • 3 comments

…rather than Python str so it matches the signature of QByteArray.

Running FreeCAD 0.18.3 on Ubuntu 19.10 I was getting errors adding a dimension to a drawing. Error such as: raceback (most recent call last): File "/home/musinsky/.FreeCAD/Mod/FreeCAD_drawing_dimensioning/drawingDimensioning/selectionOverlay/init.py", line 23, in mousePressEvent self._onClickFun( event, self, self.elementXML, self.elementParms, self.elementViewObject ) File "/home/musinsky/.FreeCAD/Mod/FreeCAD_drawing_dimensioning/drawingDimensioning/linearDimension.py", line 214, in selectDimensioningPoint previewDimension.initializePreview( d, linearDimension_points_preview, linearDimension_points_clickHandler ) File "/home/musinsky/.FreeCAD/Mod/FreeCAD_drawing_dimensioning/drawingDimensioning/previewDimension.py", line 60, in initializePreview preview.SVGRenderer.load( QtCore.QByteArray( ''' ''' % (drawingVars.width, drawingVars.height) ) ) #without this something goes wrong... TypeError: 'PySide2.QtCore.QByteArray' called with wrong argument types: PySide2.QtCore.QByteArray(str) Supported signatures: PySide2.QtCore.QByteArray() PySide2.QtCore.QByteArray(bytearray) PySide2.QtCore.QByteArray(bytes) PySide2.QtCore.QByteArray(PySide2.QtCore.QByteArray) PySide2.QtCore.QByteArray(int, char)

By encoding each QByteArray string as utf-8, the call is now working and the dimension shows up as expected since it now matches the 'bytes' signature for QByteArray.

cmusinsky avatar Dec 11 '19 03:12 cmusinsky

I just made a similar change to get the workbench working on Kubuntu 18.04. Would be nice to merge - TechDraw needs a lot more work.

volodya31415 avatar Feb 01 '20 18:02 volodya31415

Using Python for hex, strings, bytes and integers Functions expect bytes. For this, there is the .encode() string method. As an example, consider the following:

drawingDimensioning/grid.py

                svg_parms = (
                    '<svg width="%i" height="%i"> <path stroke="%srgb(0, 255, 0)" stroke-width="%f" d="%s"/> </svg>'
                    % (drawingVars.width, drawingVars.height, clr, lineWidth, dArg)
                )

and then:

self.SVGRenderer.load(QtCore.QByteArray(svg_parms.encode()))

the same for functions containing svg strings in drawingDimensioning/previewDimension.py file

illucent avatar Feb 14 '20 20:02 illucent

I also experienced the issue described above on FreeCAD version 0.18.4, which is the current version of FreeCAD as of today.

The patch proposed in this pull request fixed the issue for me.

I applied the patch to a local version of this plugin with:

wget https://github.com/hamish2014/FreeCAD_drawing_dimensioning/pull/124/commits/a3188b4d8ceaeda77783cf8803fd8da1f7922f0e.patch
git apply a3188b4d8ceaeda77783cf8803fd8da1f7922f0e.patch

Thank you @hamish2014 for creating such a great plugin, and thank you @cmusinsky for tracking down this issue and proposing a fix.

sAlexander avatar Oct 07 '20 17:10 sAlexander