-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix problems when both PyQt5 & PySide2 are in venv
See the explanatory comment in fbs_runtime/application_context/PyQt5.py.
- Loading branch information
Showing
5 changed files
with
83 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Earlier fbs versions had the following code: | ||
try: | ||
from PyQt5 import ... | ||
except ImportError: | ||
from PySide2 import ... | ||
This lead to problems when both PyQt5 and PySide2 were on PYTHONPATH: | ||
1) PyInstaller packaged both (!) libraries because it saw both imports. | ||
2) The above made fbs always use PyQt5. But if the user's app uses PySide2, | ||
then PySide2 and PyQt5 classes / code would be mixed. | ||
3) It wasn't clear (or deterministic, really) which Python binding took | ||
precedence. For instance, PyQt5 and PySide2 set different QML search paths. | ||
To fix this problems, the above code was split into separate files: One that | ||
contains all PyQt5 imports, and another that contains all PySide2 imports. The | ||
user is supposed to import precisely one of the two. This makes PyInstaller | ||
only package the one necessary library, and prevents the above problems. | ||
""" | ||
|
||
from . import _ApplicationContext, _QtBinding, cached_property | ||
from PyQt5.QtGui import QIcon | ||
from PyQt5.QtWidgets import QApplication | ||
from PyQt5.QtNetwork import QAbstractSocket | ||
|
||
class ApplicationContext(_ApplicationContext): | ||
@cached_property | ||
def _qt_binding(self): | ||
return _QtBinding(QApplication, QIcon, QAbstractSocket) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Earlier fbs versions had the following code: | ||
try: | ||
from PyQt5 import ... | ||
except ImportError: | ||
from PySide2 import ... | ||
This lead to problems when both PyQt5 and PySide2 were on PYTHONPATH: | ||
1) PyInstaller packaged both (!) libraries because it saw both imports. | ||
2) The above made fbs always use PyQt5. But if the user's app uses PySide2, | ||
then PySide2 and PyQt5 classes / code would be mixed. | ||
3) It wasn't clear (or deterministic, really) which Python binding took | ||
precedence. For instance, PyQt5 and PySide2 set different QML search paths. | ||
To fix this problems, the above code was split into separate files: One that | ||
contains all PyQt5 imports, and another that contains all PySide2 imports. The | ||
user is supposed to import precisely one of the two. This makes PyInstaller | ||
only package the one necessary library, and prevents the above problems. | ||
""" | ||
|
||
from . import _ApplicationContext, _QtBinding, cached_property | ||
from PySide2.QtGui import QIcon | ||
from PySide2.QtWidgets import QApplication | ||
from PySide2.QtNetwork import QAbstractSocket | ||
|
||
class ApplicationContext(_ApplicationContext): | ||
@cached_property | ||
def _qt_binding(self): | ||
return _QtBinding(QApplication, QIcon, QAbstractSocket) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters