mottosso / Qt.py

Minimal Python 2 & 3 shim around all Qt bindings - PySide, PySide2, PyQt4 and PyQt5.
MIT License
896 stars 252 forks source link

fix translate arguments #381

Closed jdorr closed 1 year ago

jdorr commented 1 year ago

In this pull request, I update the logic in translate() to allow optional arguments.

I decided to open this pull request after I ran into a ui file compilation difference:

pyside2-uic foo.ui --> QCoreApplication.translate("MainWindow", u"MainWindow", None) (pyside-5.15.4)
pyside2-uic foo.ui --> QCoreApplication.translate("MainWindow", u"MainWindow", None, -1) (pyside-5.12.6)

Notice how the first compilation with pyside-5.15.4 returns translate with 3 arguments instead of 4. When we eventually use QtCompat.translate() we run into the following error:

  File "/dd/shows/DEV01/user/work.akelada/tools/cent7_64/package/launchpad/0.1.2/python/launchpad/Ui_launchpad_UI.py", line 205, in retranslateUi
    MainWindow.setWindowTitle(QtCompat.translate("MainWindow", u"MainWindow", None))
  File "/dd/tools/cent7_64/package/qt_py/1.3.6/python/Qt.py", line 844, in _translate
    "Expected 4 or 5 arguments, got {0}.".format(len(args) + 2))
TypeError: Expected 4 or 5 arguments, got 3.

Now translate("MainWindow", u"MainWindow", None) will work since n defaults to -1.

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

mottosso commented 1 year ago

Almost got it haha.

Here's what I would do.

  1. On GitHub.com
  2. Make a new branch
  3. Open Qt.py in the browser editor here on GitHub
  4. Copy/paste your local Qt.py source code into the Qt.py in your webbrowser editor
  5. Commit

image

Now you know the user who committed the code and the user making the PR are one and the same.