PySide migration

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!
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: PySide migration

Post by jreinhardt »

A user of BOLTS experiences some strange issues related to loading ui files. He uses:
Windows 7
Platform: 32-bit
Version: 0.14.3389
Python version: 2.6.2
Qt version: 4.5.2
Coin version: 3.1.0
SoQt version: 1.4.1
OCC version: 6.5.1
BOLTS fails to load a ui file called "bolts_widget.ui", the error message suggests a escaping issue:
0.14\bin\python26.zip\xml\etree\ElementTree.py", line 579, in parse <type 'exceptions.IOError'>:
[Errno 22] invalid mode ('rb') or filename: 'C:\Program Files (x86)\FreeCAD 0.14\BOLTS\gui\x08oltswidget.ui
Apparently, the "\b" in the path gets interpreted as an escape sequence. However, I use os.path.join to construct all the paths, so everything should be properly escaped.

Further investigation suggests that the problem might be in uic

as

Code: Select all

open(r"C:\Program Files (x86)\FreeCAD 0.14\BOLTS\gui\boltswidget.ui")
open("C:\\Program Files (x86)\\FreeCAD 0.14\\BOLTS\\gui\\boltswidget.ui")
succeed, but

Code: Select all

uic.loadUiType(r"C:\Program Files (x86)\FreeCAD 0.14\BOLTS\gui\boltswidget.ui")
uic.loadUiType("C:\\Program Files (x86)\\FreeCAD 0.14\\BOLTS\\gui\\boltswidget.ui")
fail with the aforementioned error.

Looking at the PySideUicModule code (src/Gui/WidgetFactory.cpp:445), I believe escaping might be lost when constructing the python script in-memory.

Now I am not sure about how to best work around this. Just replacing the backslashes to forward slashes might work, as apparently windows recognises them as path separators.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: PySide migration

Post by wmayer »

git commit 8dbbdd3 fixes the issue by replacing backslashes with slashes. The reason for the failure of the backslashes is that the path internally goes through Python and thus loses one backslash. And then it goes through Python calls again and then the simple backslashes are handled as escape sequences.
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: PySide migration

Post by jreinhardt »

Thanks a lot.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: PySide migration

Post by jmaustpc »

Hi all
I have updated this wiki page section which was previously PyQt4 to PySide. If I should not have done so, then someone can click "undo" ... or re-edit the wiki page. :)

http://www.freecadweb.org/wiki/index.ph ... y_PyQt4.29

1) could a Mac person tell me what to put in the Mac section please? Can I just simply change "PyQt in Home Brew" reference, to PySide or not....?

2) Can one of you RPM based distro people check what the package name typically is for PySide in the common RPM based distros? This is a link to the paragraph in question. http://www.freecadweb.org/wiki/index.ph ... ules#Linux

3) I left the PyQt4 tutorial links at the bottom for now as I though they could probably still be of some value (considering the similarities between PyQt4 and PySide)....if someone wants to post some links for something similar in PySide I will happily add them to the wiki and, if appropriate, I can delete the older PyQt4 at some point in the future.



Jim
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: PySide migration

Post by mario52 »

hi
in addition to changing all PyQt4 in PySide
here few some modifications to adapt PyQt4 to PySide (observed in my macro)

unicode :

Code: Select all

#        text = unicode(text, 'ISO-8859-1').encode('UTF-8') # PyQt4
change by

Code: Select all

       text = text.encode('utf-8')                         # PySide
________________________________________________
QFileDialog : getOpenFileName

Code: Select all

#        OpenName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Read a txt file"),path,"*.FCInfo *.txt")            # PyQt4
change by

Code: Select all

        OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Read a txt file", path, "*.FCInfo *.txt")  # PySide
________________________________________________
QFileDialog : getSaveFileName

Code: Select all

#        SaveName = QFileDialog.getSaveFileName(None,QString.fromLocal8Bit("Save a file FCInfo"),path,"*.FCInfo")   # PyQt4
change by

Code: Select all

        SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Save a file FCInfo", path, "*.FCInfo")   # PySide
________________________________________________
test op self.pushButton (accentuated, over 128)

Code: Select all

#        if self.pushButton_Ra.text() == "Degré":   # PyQt4
change by

Code: Select all

        choice = self.pushButton_Ra.text()          # PySide
        choice = choice.encode('utf-8')             # PySide
        if choice == "Degré":                       # PySide
________________________________________________
base program

Code: Select all

#app = QtGui.qApp                                 # PyQt4
#FCmw = app.activeWindow()                        # PyQt4
change by

Code: Select all

FCmw = FreeCADGui.getMainWindow()                 # PySide
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply