-
Notifications
You must be signed in to change notification settings - Fork 207
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
Add PySide6 Compatible Picamera2 Widgets #1198
Conversation
Hi, and thanks very much for doing this, it looks really interesting! I'd like to merge this but have a couple of questions.
Thanks again! |
This pull request has been open for quite some time. Would it be possible to get it merged soon? Also, if it's going to be merged, I think it would be beneficial to add support for PySide2 as well. The changes required for that are minimal, and it would ensure better compatibility across different environments. Let me know if there's anything I can do to help speed up the process! |
Hi and thanks for the comments. Yes, the purpose behind my question (about not copying entire files) was in large part related to this - how to support more versions of the GUI. It supports PyQt5 now, but PySide6 would be a very useful addition. But then, presumably someone will want PyQt6 too, and then maybe other versions of PyQt/Side... So the question is mostly about how to manage and implement this in a way that can be maintained. I don't have time to look at this at the moment, and nor do I have any great expertise in PyQt or PySide. I'm wondering if anyone else has any suggestions? |
Hi, I have been considering what the best way forward for this might be, though there are a few things to take into account. We do need to reduce duplicated code, and allow for addition of different Qt GUI Python implementations, but it also needs to be kept compatible with current implementations (e.g. a QPicamera2 call using PyQt5 by default). I was also thinking it is best to not rely on there being only one Python Qt implementation on the environment, and therefore having a order of precedence on the import of Qt implementations isn't ideal, it is best if it can be selected. I'm working on a solution for these issues, would you think it necessary to allow for different Qt implementations to be used within the same Python program? |
Hi, and thanks for the reply. I can't say that I see any need for people to run different versions of PtQt (or whatever) in the same process, so my feeling is that we don't need to worry about that. That sounds fair to me, but I'm open to persuasion if anyone disagrees! :) So anyway, I think that means that some kind of scheme where maybe it tries multiple alternatives - but ideally lets you choose if you want - sounds promising? |
Signed-off-by: Levi Dean <leviodean@gmail.com>
… and QSide6Picamera2 respectively) Signed-off-by: Levi Dean <leviodean@gmail.com>
I have found a solution for these issues and am in the process of properly implementing it. |
Great, keep us posted, and thank you very much! |
…ra2, and QGlSide6Picamera2 respectively) Signed-off-by: Levi Dean <leviodean@gmail.com>
Signed-off-by: Levi Dean <leviodean@gmail.com>
Signed-off-by: Levi Dean <leviodean@gmail.com>
Hi, so there were a couple of test failures there. I don't think the flake8/lint ones are terribly major and should be easy to clear up. You should be able to get flake8 running as a pre-commit check with something like
The static type checking is a work-in-progress. Another contributor is very kindly helping to improve the typing hints, but there's a lot to do so we're a bit in the middle of things. But I think it's probably only the two errors at the end that matter at the moment. If you have |
Signed-off-by: Levi Dean <leviodean@gmail.com>
Signed-off-by: Levi Dean <leviodean@gmail.com>
I believe I have now corrected those errors (which were both type checking errors too), and also corrected the linting. This should now be compatible with PyQt5, PyQt6, PySide2, and PySide6, though only in widget format which will need to be added to your own application (the default preview window will still attempt to use PyQt5). Classes can be imported from picamera2.previews.qt as before for specific versions use classes as follows:
All classes can be interacted with in identical ways, except for the different Qt implementation in their application. These classes are lazy loaded in picamera2.previews.qt so may not show up in syntax highlighting as they are dynamically accessed whereas syntax highlighting often relies on static analysis. |
Signed-off-by: Levi Dean <leviodean@gmail.com>
Also, I have not yet added examples to the examples folder or added tests for each new class to the the CI tests, I am planning on doing so at some point but can do a new pull request for that once I have done so, if that helps. |
Thanks, that's looking good! So if I'm running a different GUI framework, all I do is replace
by
(or whichever). Obviously the rest of the GUI code is not the camera system's concern. I guess I should just have a read through to make sure I understand what's going on, and also I should try it out on at least one of the other frameworks, so maybe just give me a day or so to do that. Final question... if one did want the automatic preview to select the flavour of Qt that is installed, do you have any ideas on that? Maybe I can give that some thought too once I've got a bit more of an understanding. Thanks again! |
Yes you just replace the import as you stated, In terms of the automatic preview you'd probably want something similar to what is done for the QPicamera2 class as the QtPreviewBase class is dependent on the imported Qt implementation. Duplication of that class for each implementation would also work but would again result in large amounts of code duplication. I could potentially implement this at some point if necessary. |
Sure! Let me try all this first, and hopefully merge tomorrow. And we can leave other stuff on the back burner just for the moment! |
I have tried with pyside2 and 6 it is working wonderfully , but I try many thing but i can't get it work with QML(qt 5) and pyside2 , i know I am asking lot but if you know about qml and can make one example it will be big help ( i have to use it until i make new app in pyside6) |
I've tried out PyQt6 and PySide6 with a little test app based on this one. Both worked perfectly (ignoring a minor sytnax change to the label alignment). Just as a note for anyone else, to make the PySide6 version work, I had to do
before it would run. (I can probably add those to the CI tests which will ensure we never break this new functionality completely.) |
Widgets "QGlPicamera2" and "QPicamera2" should be imported from from "picamera2.previews.qt_pyside6", rather than "picamera2.previews.qt", for use with PySide6.
Widgets can be used within a PySide6 application the same as they would with PyQt5.
Example of using QGLPicamera2 widget with PySide6 (modified from example in Picamera2 manual):
A QPicamera2 widget (no GPU integration) can be used identically by simply replacing "QGlPicamera2" with "QPicamera2".