wgpu-py icon indicating copy to clipboard operation
wgpu-py copied to clipboard

More GUI backends

Open Korijn opened this issue 5 years ago • 34 comments

Done

  • PySide/PySide2/PySide6/PyQt4-6
  • GLFW
  • wxPython Phoenix Thanks @Correct-Syntax #133
  • jupyter (via jupyter_rfb)

To do (PRs welcome)

  • [ ] Beeware/toga
  • [ ] pyglet
  • [ ] pygame
  • [ ] pyimgui

Won't support:

  • TkInter: see #69
  • SDL2 (no decent wrapping library available)

Korijn avatar Dec 24 '19 08:12 Korijn

TkInter would be interesting, I had not thought of it yet because it does not support GL. But it might work with wgpu, IF we can get the native window id.

almarklein avatar Dec 24 '19 08:12 almarklein

This seems to be maintained (somewhat): https://github.com/marcusva/py-sdl2

Korijn avatar Dec 24 '19 10:12 Korijn

Yeah, but I think you still need to install the native sdl2 libs manually.

almarklein avatar Dec 28 '19 10:12 almarklein

Ah right. That sucks. OK!

Korijn avatar Dec 28 '19 13:12 Korijn

In that case, I think we can just drop SDL, until a better package comes along in the ecosystem.

Korijn avatar Jan 02 '20 18:01 Korijn

yeah. glfw is very similar in providing a solid lightweight window. So there's not really a use-case except maybe someone wanting to use sdl2 already for something else, or something.

almarklein avatar Jan 02 '20 21:01 almarklein

Also added PySide/PyQt4. It should not be too hard to make the Qt backend work for these as well.

almarklein avatar Jan 02 '20 21:01 almarklein

https://beeware.org/ is apparently also a thing nowadays :)

Korijn avatar Feb 07 '20 08:02 Korijn

Not at all a priority, but, pyglet is another lib that we could target.

Korijn avatar May 05 '20 20:05 Korijn

Integration with pyimgui would also bring very interesting user interface elements to the table.

Korijn avatar Oct 31 '20 10:10 Korijn

How hard would this be to implement for wxPython Phoenix? What's required? I'd consider helping, if possible.

Correct-Syntax avatar Feb 22 '21 17:02 Correct-Syntax

@Correct-Syntax that would be great! There is not that much "stuff to wrap", but how hard it is depends a lot on how easy the toolkit makes it to e.g. obtain the window id. And there can be tricky edge-cases like this.

That said, the idea is to keep the wrapping minimal to what's needed to have a canvas to draw to. E.g. we don't try to create a unified event system or something.

almarklein avatar Feb 22 '21 19:02 almarklein

So, what exactly from wgpu needs to be put into wxpython? I guess I need a bit more context to help.

Getting the window id with wxpython is as simple as thewindowobject.GetId(). Not sure if that's what you mean.

Correct-Syntax avatar Feb 22 '21 20:02 Correct-Syntax

It looks like the qt widget subclasses WgpuCanvasBase. Would I be right to say that all that should be needed is to basically translate that qt.py into wxpython?

Correct-Syntax avatar Feb 22 '21 20:02 Correct-Syntax

Yeah, the qt version could be a good staring point, but you may not need to do the trick with two classes for wx. Also have a look at base.py which shows the messages that must be implemented. Don't hesitate to ask for help if things are unclear - you'd be the first to create a gui backend except ourselves.

almarklein avatar Feb 22 '21 20:02 almarklein

Alright, thanks! I'll see if I can get something working. Open pull request then, correct?

Correct-Syntax avatar Feb 22 '21 20:02 Correct-Syntax

Yes, a PR would be great. We could discuss further there :)

almarklein avatar Feb 22 '21 20:02 almarklein

Updated the opening post, thanks @Correct-Syntax

I also added ipynotebook static and interactive

Korijn avatar Mar 26 '21 08:03 Korijn

I was wondering how wgpu-py and pyimgui would fit together

they both have a GLFW backend, is there maybe some way to render them as different passes into the same window canvas?

otherwise this appears to be a native wgpu renderer for imgui: https://github.com/Yatekii/imgui-wgpu-rs

anentropic avatar Jan 19 '22 22:01 anentropic

is there maybe some way to render them as different passes into the same window canvas?

ImGUI says that it "outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application", so maybe this could work? This would need some research. I know that Datoviz (which is based on Vulkan) has imgui integration of some sort.

almarklein avatar Jan 20 '22 09:01 almarklein

Hi,

Very nice project guys.

i have one question : why dont tkinter ? it will be awesome if it is possible, as tkinter is part of standard python, no additional dependencies,, no licences etc... i think standard python really need to have great solution for 3d.

llluuulll avatar Feb 17 '22 01:02 llluuulll

@almarklein

Hi,

Very nice project guys.

Thank you!

i have one question : why dont tkinter ? it will be awesome if it is possible, as tkinter is part of standard python, no additional dependencies,, no licences etc...

We did have it at some point but it had some issues, see #69 for some history.

Maybe @almarklein can comment here as well.

If you (or anyone else) feel like working on it, you can find the last version of the code we had for tk here, to use as a starting point: https://github.com/pygfx/wgpu-py/blob/7977a0688a462eeed3ef555000596db8a423ab42/wgpu/gui/tk.py

i think standard python really need to have great solution for 3d.

We agree, this is the main motivation behind this project!

Korijn avatar Feb 17 '22 06:02 Korijn

Yeah, it looked like it was not possible to get the window id on some OS's, and where it did work, it did not work well at all. Together with the lack of proper support for hidpi displays this simply is not worth it. I would not recommend anyone trying to make it work. I would be reluctant to accept PR's that add support for it, because we'd be stuck maintaining a flaky backend.

Glfw is now widely available, easy to install, stable, lightweight, libre license ... there is really no need for a tk backend.

almarklein avatar Feb 17 '22 08:02 almarklein

Glfw is now widely available, easy to install, stable, lightweight, libre license ... there is really no need for a tk backend.

I guess there is a need in places where you don't control the environment you are running in, and you are stuck with tk. On the other hand, in those cases you also don't have access to wgpu-py, so... yeah. I guess you're right, Almar.

Korijn avatar Feb 17 '22 09:02 Korijn

Hi,

Thx for the details answer. Ok ... Yes, sadly tk seem not to be the easiest when it came to customize and mixed with other tech.

Just to precise my context : My need for gui with python it is at work, for the new program i work on.

Previusly i was using python only in two scenario :

  • As script inside other programs (blender, motionbuilder, maya, etc...), the gui need is provided by the hosting program.
  • As files to run from cmd for automated processing with no need for gui.

So, i never use tk before this new standalone program demand with the requirement to use python only. To be autonomous and packaged as portable exe (no deployment or installer) and don't have any licencing issue.

Mainly, tk was feeting the bill for this program until now, the demand evolute to the need for 3d visualisation capability, and ... tk dont feet the bill anymore.

At the end it is sad the standard python stick with tk and seem not looking to integrate one other more modern and friendly framework in his standard distro.

llluuulll avatar Feb 17 '22 14:02 llluuulll

So, i never use tk before this new standalone program demand with the requirement to use python only. To be autonomous and packaged as portable exe (no deployment or installer) and don't have any licencing issue.

For the record, Glfw still fits these requirements. If you can install wgpu-py, you can also install glfw.

almarklein avatar Feb 17 '22 19:02 almarklein

HI,

Yes, i can use additional python library in regard to the need of no licence. For that i am looking at what is existing etc... Glfw as nice it can be, will not suit my need because is not a gui framework but just a windowing layer.

And i have a complete and complex program to create, the 3d viewer part is just one part of. Also, the program run on Windows and due to the current pandemic is primarily used on standard remote session witch simply disqualify any openGL backend.

Your solution look sweet to me because is using the correct backend per platform, so directx for my case on windows. Also is a solution to integrate with an gui framework of choice.

Anyway, thanks for answering and the talking point.

llluuulll avatar Feb 17 '22 20:02 llluuulll

Glfw as nice it can be, will not suit my need because is not a gui framework but just a windowing layer.

Good point :)

What about PySide6 though? That's lgpl and stable.

almarklein avatar Feb 17 '22 21:02 almarklein

hehehe

Yes, i have an experience with Qt (c++) it is a massive framework. To correctly use Qt it is need to use Qt, i mean all Qt and the editor too. They have an Qt something class for allmost anything, at the end the experience is not really c++ anymore, is ... Qt ++ :)

So i guess the python wrapper (pyside6 or QtPython as they call it too) follow the same quality and logic.

But, the licencing is becoming the problem with Qt. And they have send signals to any compagny who use Qt for small or big project to ensure the licencing is well understood and applied. The company who employ me have decided to cut of all sort of Qt use.

i am looking at dearpygui ... have you a point of view about ?

llluuulll avatar Feb 17 '22 21:02 llluuulll

@llluuulll Sorry if I misunderstood your use case, but would wxPython work? See license here https://wxpython.org/pages/license/index.html It's about the only one not mentioned so far.

Correct-Syntax avatar Feb 17 '22 21:02 Correct-Syntax