A Little Help With PyQt Radio Buttons Please

Need help, or want to share a macro? Post here!
mario52
Posts: 2861
Joined: Wed May 16, 2012 2:13 pm

Re: A Little Help With PyQt Radio Buttons Please

Postby mario52 » Tue Feb 04, 2014 1:38 pm

hi
here a small example with buttom radio, check box and lineedit
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: A Little Help With PyQt Radio Buttons Please

Postby quick61 » Tue Feb 04, 2014 4:14 pm

yorik wrote:There is a bug in Draft scale that prevents the legacy mode to work on bsplines, that I just fixed now.
Well, that explains that. Thanks Yorik.
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: A Little Help With PyQt Radio Buttons Please

Postby quick61 » Tue Feb 04, 2014 5:07 pm

yorik wrote:There is a bug in Draft scale that prevents the legacy mode to work on bsplines, that I just fixed now.
Just compiled and that didn't seem to of fixed it. In fact, I am now getting new errors from Draft.py in Report view when I run the script. This looks like it should of been an easy enough fix, but maybe this is why it wasn't in there in the furst place?

Code: Select all

Traceback (most recent call last):
  File "/home/mark/Build/FreeCAD/Mod/Draft/Draft.py", line 3953, in onChanged
    self.createGeometry(fp)
  File "/home/mark/Build/FreeCAD/Mod/Draft/Draft.py", line 3971, in createGeometry
    spline.interpolate(fp.Points, False)
<type 'exceptions.Exception'>: not enough points given
Traceback (most recent call last):
  File "/home/mark/Build/FreeCAD/Mod/Draft/Draft.py", line 3949, in execute
    self.createGeometry(fp)
  File "/home/mark/Build/FreeCAD/Mod/Draft/Draft.py", line 3971, in createGeometry
    spline.interpolate(fp.Points, False)
<type 'exceptions.Exception'>: not enough points given
BSpline: not enough points given
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: A Little Help With PyQt Radio Buttons Please

Postby quick61 » Tue Feb 04, 2014 5:24 pm

OK, just confirmed this. Changed elif getType(obj) in ["Wire","BSpline"]: back to elif getType(obj) == "Wire": and the errors stopped.

I'll go ahead and add this to Mantas. Done - issue #0001385
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
yorik
Site Admin
Posts: 11711
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: A Little Help With PyQt Radio Buttons Please

Postby yorik » Tue Feb 04, 2014 6:09 pm

That's what you get when fixing things too fast :) it should work now...
User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: A Little Help With PyQt Radio Buttons Please

Postby quick61 » Tue Feb 04, 2014 6:23 pm

yorik wrote:That's what you get when fixing things too fast :) it should work now...

That seems to work a treat! Thanks.

This is working well enough now to put on the Macros recipes page. I probably should do 2 versions, one with just the DWire and the full one for versions = < 0.14 3077. A little more testing and it should be good to go.

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
wandererfan
Posts: 3677
Joined: Tue Nov 06, 2012 5:42 pm

Re: A Little Help With PyQt Radio Buttons Please

Postby wandererfan » Tue Feb 04, 2014 6:46 pm

wandererfan wrote:I can't get the BSpline part to run, but it's probably something in my OCC rather than your macro. I get
"...in createGeometry
spline.interpolate(fp.Points, True)
<type 'exceptions.Exception'>: BSplCLib::Interpolate
BSpline: BSplCLib::Interpolate"
If I use "n12.dat" from here: http://aerospace.illinois.edu/m-selig/a ... ase.html#N
with the BSpline option I get a segfault.

If I use "n2414.dat" or "naca2421" the BSpline works great. :?

The good news is that now I have OCE-0.15-dev!
User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: A Little Help With PyQt Radio Buttons Please

Postby quick61 » Tue Feb 04, 2014 7:14 pm

Edit - Scripts and instructions now on the FreeCAD Wiki pages Macros recipes under Utility.
wandererfan wrote:
wandererfan wrote:I can't get the BSpline part to run, but it's probably something in my OCC rather than your macro. I get
"...in createGeometry
spline.interpolate(fp.Points, True)
<type 'exceptions.Exception'>: BSplCLib::Interpolate
BSpline: BSplCLib::Interpolate"
If I use "n12.dat" from here: http://aerospace.illinois.edu/m-selig/a ... ase.html#N
with the BSpline option I get a segfault.

If I use "n2414.dat" or "naca2421" the BSpline works great. :?

The good news is that now I have OCE-0.15-dev!
I think once you start really looking at things like Boolean ops function better, Loft and Sweep have better surfaces, etc., you'll start to wonder why you didn't make the move sooner. ;)

Yea, some of those .dat files on that site are not formatted correctly. I think some of them were contribs from sources other than them or they didn't get translated properly when moved from paper to text file. :?

If there is a foil that your really need, you can usually get it open in XFLR5 and edit/fix/save, and it will result in a readable format. Once you really start going through that data base, there are more than a few that have funky formats.

On another note - Here are the 2 final Macros. The first, V 1.5 should work with about all valid FreeCAD and OCE/OCC versions. The second one works for FreeCAD versions = or > 0.14 3077 and best with OCE/OCC 6.7

Airfoil Import & Scale v1.5

Code: Select all

# # # #
#
# AIRFOIL IMPORT & SCALE v1.5
# 
# Imports and scales an Airfoil in the form of a Draft Wire (DWire) 
#
# # # #


from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QLineEdit
import FreeCAD, FreeCADGui, Draft
import importAirfoilDAT

# Select .dat airfoil data file to be imported

filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open An Airfoil File','*.dat')

class p():

    def proceed(self):
            try:
                
                # This produces a scaled Airfoil with a DWire

                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
            
            except:
                FreeCAD.Console.PrintError("Error, not a valid .dat file\n")

            self.close()

    def close(self):
        self.dialog.hide()

    def __init__(self):
        self.dialog = None
        self.s1 = None

        # Make dialog box and get the scale size

        self.dialog = QtGui.QDialog()
        self.dialog.resize(350,100)
        self.dialog.setWindowTitle("Airfoil Import & Scale")
        la = QtGui.QVBoxLayout(self.dialog)
        t1 = QtGui.QLabel("Chord Length")
        la.addWidget(t1)
        self.s1 = QtGui.QLineEdit()
        la.addWidget(self.s1)

        # Add OK / Cancel buttons

        okbox = QtGui.QDialogButtonBox(self.dialog)
        okbox.setOrientation(QtCore.Qt.Horizontal)
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        la.addWidget(okbox)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
        self.dialog.show()
        self.dialog.exec_()

p()
Airfoil Import & Scale v2

Code: Select all

# # # #
#
# AIRFOIL IMPORT & SCALE v2.
# 
# Imports and scales an Airfoil in the form of a Draft Wire (DWire) or Basic Spline (BSpline)
#
# For FreeCAD Versions = or > 0.14 Revision 3077
#
# Works best with OCC/OCE = or > 6.7
#
# # # #


from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QLineEdit, QRadioButton
import FreeCAD, FreeCADGui, Draft
import importAirfoilDAT

# Select .dat airfoil data file to be imported

filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open An Airfoil File','*.dat')

class p():

    def proceed(self):
        if self.radio1.isChecked():
            try:
                
                # This produces a scaled Airfoil with a DWire

                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
            
            except:
                FreeCAD.Console.PrintError("Error, not a valid .dat file\n")

            self.close()

        if self.radio2.isChecked():
            try:

                # This produces a scaled Airfoil with a BSpline

                scalefactor=float(self.s1.text())
                f1=str(filename)
                importAirfoilDAT.insert(f1,"Unnamed")
                points = FreeCAD.ActiveDocument.ActiveObject.Points
                Draft.makeBSpline(points, closed=True)
                Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(scalefactor,scalefactor,scalefactor),center=App.Vector(0,0,0),legacy=True)
                App.getDocument("Unnamed").removeObject("DWire")

            except:
                FreeCAD.Console.PrintError("Error, not a valid .dat file\n")

            self.close()

    def close(self):
        self.dialog.hide()


    def __init__(self):
        self.dialog = None
        self.s1 = None


        # Make dialog box and get the scale size

        self.dialog = QtGui.QDialog()
        self.dialog.resize(350,100)
        self.dialog.setWindowTitle("Airfoil Import & Scale")
        la = QtGui.QVBoxLayout(self.dialog)
        t1 = QtGui.QLabel("Chord Length")
        la.addWidget(t1)
        self.s1 = QtGui.QLineEdit()
        la.addWidget(self.s1)

        # Add radio buttons to select between DWire and BSpline

        self.radio1 = QRadioButton("Make DWire")
        self.radio2 = QRadioButton("Make BSpline")

            # set default to DWire & make radio buttons - Change self.radio1.setChecked(True) to
            # self.radio2.setChecked(True) to ste BSpline as default

        self.radio1.setChecked(True)
        la.addWidget(self.radio1)
        la.addWidget(self.radio2)

        # Add OK / Cancel buttons

        okbox = QtGui.QDialogButtonBox(self.dialog)
        okbox.setOrientation(QtCore.Qt.Horizontal)
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        la.addWidget(okbox)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.proceed)
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
        self.dialog.show()
        self.dialog.exec_()

p()
Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
mario52
Posts: 2861
Joined: Wed May 16, 2012 2:13 pm

Re: A Little Help With PyQt Radio Buttons Please

Postby mario52 » Thu Feb 06, 2014 1:29 pm

hi quick61
I allowed myself to make an image for your macro if this drawing does not suit you you can always replace it with "Import a new version of this file".
PS: I believe that we should put your macro in the "Object creation" section and not "Utility"
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
User avatar
quick61
Posts: 3793
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: A Little Help With PyQt Radio Buttons Please

Postby quick61 » Thu Feb 06, 2014 5:18 pm

mario52 wrote:hi quick61
I allowed myself to make an image for your macro if this drawing does not suit you you can always replace it with "Import a new version of this file".
PS: I believe that we should put your macro in the "Object creation" section and not "Utility"
mario
Hi Mario. That's fine. Looks good enough to me. Once I have a full model of one of my R/C gliders done, I might update it, but until then, yours will definitely do the job. Thank you!

Your probably right, it would be better under "Object creation" ... Done - Moved it.

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?