JaWeilBaum / pyqtlet2

pyqtlet2 extends pyqtlet which initially brought Leaflet maps to PyQt5 and PySide6.
Other
37 stars 19 forks source link

PySide Support #26

Closed EasyIsrael closed 2 years ago

EasyIsrael commented 2 years ago

I want to switching my application to pyside because of licensing issues. there exists qtpy, which is a wrapper for pyqt5 and pyside2. in my fork of pyqtlet2 i added qtpy, so that i can use either pyqt5 or pyside2.

The newest qtpy repository has no QWebEngineScript so i forked this project too (qtpy) and extended it, to get pyqtlet2 running.

to switch between pyside and PyQt you have just to change the QT_APP variable to "pyqt5"

import sys
import os
os.environ['QT_API'] = 'pyside2'
import qtpy
from qtpy.QtWidgets import QApplication, QLabel
from qtpylet import L,MapWidget

app = QApplication(sys.argv)
mapWidget = MapWidget()
map = L.map(mapWidget)
map.setView([12.97, 77.59], 10)
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map)
mapWidget.show()
app.exec_()
danielhrisca commented 2 years ago

Hello @EasyIsrae I've tried your code but it fails for PySide6

  File "d:\02__PythonWorkspace\pyqtlet2\qtpylet\__init__.py", line 8, in <module>
    from .mapwidget import MapWidget
  File "d:\02__PythonWorkspace\pyqtlet2\qtpylet\mapwidget.py", line 9, in <module>
    from qtpy.QtWebEngineWidgets import ( QWebEngineView, QWebEnginePage, QWebEngineSettings,
ImportError: cannot import name 'QWebEngineScript' from 'qtpy.QtWebEngineWidgets' (D:\TMP\_venv_3.9\lib\site-packages\qtpy\QtWebEngineWidgets.py)
JaWeilBaum commented 2 years ago

@EasyIsrael Did you already try the implementation which @danielhrisca provided in his PR #25 ?

EasyIsrael commented 2 years ago

No, I didn't. I don't have Pyside6 here.

Leon Friedmann @.***> schrieb am So., 27. Feb. 2022, 16:16:

@EasyIsrael https://github.com/EasyIsrael Did you already try the implementation which @danielhrisca https://github.com/danielhrisca provided in his PR #25 https://github.com/JaWeilBaum/pyqtlet2/pull/25 ?

— Reply to this email directly, view it on GitHub https://github.com/JaWeilBaum/pyqtlet2/issues/26#issuecomment-1053585645, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXHBXPTSGVYHT4LYIUXQLLU5I55NANCNFSM5PLS4PTQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

EasyIsrael commented 2 years ago

okay, now that the changes from danielhrisca are alreade merged to the master branch,

it seems that you don't want another library dependency that could make problems. it's okay, then we invent the wheel again and make our own qtpy-implementation here.

the changes from danielhrisca works only for PySide6, not for PySide2 and not for PyQt6. But it isn't just so easy as i thought to just only use qtpy . Every supported variant has to be tested.

danielhrisca commented 2 years ago

Qtpy would be better, probably just some import tweaks

EasyIsrael commented 2 years ago

It's a bit more to do for us, but it has also some advantages to not have much dependencies. I've already done my changes to your version, I will do PySide2 support, but PyQt6 support is someone elses job, if he wants to support it also.

EasyIsrael commented 2 years ago

I'm facing a problem , that you can not choose the version you want to use, if you have both( PyQt5 and PySide) installed. So what should we do? The Problem with PySide6 and my first PR is just that PySide has reorganized the WebEngineWidgets and you can not import QWebEnginePage, QWebEngineSettings and QWebEngineScript from it because they are now in QWebEngineCore. These are all things that qtpy takes care of.

I think we should decide which way to go (choose qtpy dependency or our own implementation). But if we choose to implement all variations in pyqtlet2, then we should add the possibility to change the API manually, when we have installed more than one Qt-Versions.

@danielhrisca and @JaWeilBaum what do you think?

danielhrisca commented 2 years ago

The Qt binding selection is done using an environment variable (see https://github.com/spyder-ide/qtpy/blob/cb168120fc00615bd2341107cd2b722cf903ff43/qtpy/__init__.py#L9)

I think the user should do this before importing pyqtlet2

danielhrisca commented 2 years ago

@EasyIsrael @JaWeilBaum I've opened https://github.com/JaWeilBaum/pyqtlet2/pull/28 for qtpy support

JaWeilBaum commented 2 years ago

Closed with the merge of #28