Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison between integers and StandardButton fails for Python task dialogs with PySide6 #14639

Closed
2 tasks done
marioalexis84 opened this issue Jun 12, 2024 · 8 comments · Fixed by #14648
Closed
2 tasks done
Labels
Bug This issue or PR is related to a bug Coding: Python Coding issue related to Python Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD

Comments

@marioalexis84
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Problem description

With PySide6, comparison between integers and StandardButton fails for Python task dialogs.
For example, in the Gmsh task panel, to make the button Apply works again, I need to change:

 def clicked(self, button):
 if button == QtGui.QDialogButtonBox.Apply:
 ...

to:

 def clicked(self, button):
 if button == QtGui.QDialogButtonBox.Apply.value:

@wwmayer, maybe some relation with #13902?

Full version info

OS: Arch Linux (XFCE/xfce)
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.37710 (Git)
Build type: Unknown
Branch: (HEAD detached at a6937d8d26)
Hash: a6937d8d2677594f548af218cc92f797d9a475d9
Python 3.12.3, Qt 6.7.1, Coin 4.0.2, Vtk 9.3.0, OCC 7.7.2
Locale: English/United States (en_US)
Installed mods: 
  * fasteners 0.5.17
  * OpenTheme 2024.4.20

Subproject(s) affected?

None

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@wwmayer
Copy link
Contributor

wwmayer commented Jun 12, 2024

It seems to be a problem for newer PySide versions. With my Qt 6.2.4 and corresponding PySide version it works without problems.

if button == QtGui.QDialogButtonBox.Apply.value:

The value attribute doesn't exist for older PySide versions. To make it working for all PySide versions you should try:

def clicked(self, button):
    if button == int(QtGui.QDialogButtonBox.Apply):

@marioalexis84
Copy link
Member Author

it does not work:
<class 'TypeError'>: int() argument must be a string, a bytes-like object or a real number, not 'StandardButton'

@wwmayer
Copy link
Contributor

wwmayer commented Jun 12, 2024

OK, then the alternative is to modify TaskDialogPython::clicked(int i) where the int should be converted into a QtGui.QDialogButtonBox.StandardButton and passed to the clicked() method of the Python wrapper.

Does this code snippet work for you?

from PySide import QtGui
QtGui.QDialogButtonBox.StandardButton(33554432)

@marioalexis84
Copy link
Member Author

The code snippet works.

With:

    def clicked(self, button):
        b=QtGui.QDialogButtonBox.StandardButton(button)
        if b == QtGui.QDialogButtonBox.Apply:

the button works normally.

@wwmayer
Copy link
Contributor

wwmayer commented Jun 12, 2024

OK, I will prepare a PR to handle this and #14156

Can you also check whether this works for you? #14156 (comment)

@marioalexis84
Copy link
Member Author

With #14156 (comment) buttons are not even added and there is an error generated when executing Gui.Control.showDialog.

<input>(1)<class 'TypeError'>: int() argument must be a string, a bytes-like object or a real number, not 'StandardButton'

image

@wwmayer
Copy link
Contributor

wwmayer commented Jun 12, 2024

Thanks for testing. Yes, according to the docs PyNumber_Long in C is equal to int() in Python and will fail in your case. So, I have to additionally check if the passed object has the attribute value and do the cast on that.

wwmayer added a commit to wwmayer/FreeCAD that referenced this issue Jun 12, 2024
Fixes FreeCAD#14639: Comparison between integers and StandardButton fails for Python task dialogs with PySide6
@wwmayer
Copy link
Contributor

wwmayer commented Jun 12, 2024

#14648

@maxwxyz maxwxyz added Bug This issue or PR is related to a bug Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD Coding: Python Coding issue related to Python labels Jun 13, 2024
wwmayer added a commit to wwmayer/FreeCAD that referenced this issue Jun 13, 2024
Fixes FreeCAD#14639: Comparison between integers and StandardButton fails for Python task dialogs with PySide6
wwmayer added a commit to wwmayer/FreeCAD that referenced this issue Jun 13, 2024
Fixes FreeCAD#14639: Comparison between integers and StandardButton fails for Python task dialogs with PySide6
chennes pushed a commit that referenced this issue Jun 17, 2024
Fixes #14639: Comparison between integers and StandardButton fails for Python task dialogs with PySide6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This issue or PR is related to a bug Coding: Python Coding issue related to Python Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants