Skip to content

Conversation

@cmusinsky
Copy link

…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.

…rather than Python str so it matches the signature of QByteArray
@volodya31415
Copy link

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.

@illucent
Copy link

illucent commented Feb 14, 2020

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

@sAlexander
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants