Building a GUI in Rust (classical vs wasm; having an interface/console for scripting to e.g., python)

How to best create a GUI in RUST that contains a Python interpreter console that can influence what's shown and happens in the GUI? (An answer could be broader and point out how experience of mixing with other languages too.)
A python interpreter inside the GUI would be practical because some RUST functions interfaced to python (pyo3) could be connected by the software. By means of python scripts one would be able to do more cumbersome operations on the data such as creating many objects from datasets, populating objects, loading from and saving results to files.., having the GUI for doing basic workflows, visualizing and keeping well track (and not everybody likes to script too). Possibly the Python code could be run in a separate thread.

Here how it could look like:

There are e.g., egui as a recently and actively developed option or druid. There is also web assembly which might be a safer bet concerning long term availability of the tool and ease of distribution (e.g. if I would need e.g., a graphical feature in the future, it might be easier to do it in HTML or even in pure RUST). So I tend to decide for WASM (although a single compiled binary that only needs to be started is of course nice). I see that there are projects such as rustpython who give some hints or examples that such a thing is possible, but to a large extent, those examples, crates are in early development and additionally often do not compile/lack instructions.

Below are results from a research I performed about python console and GUIs in general and RUST in particular; my feeling is that there is nothing mature though.

https://www.areweguiyet.com

1 Like

If say this depends on what your GUI experience and tastes are.

The one I've been keeping my eye on but haven't had a chance to use yet is Tauri which wraps the system-provided webview nicely, so you can treat it like a better Electron.

I've also heard good things about the gtk bindings, but I've never really been a fan of classic widget toolkits.

I don't think I'd say any of the rust native libraries are mature: you can do cool things for sure, and they are really interestingly designed, but the polish and breadth isn't there yet. egui is really neat for throwing together a quick tool though.

3 Likes

I thank you a lot for your answer and opinion. - I have some experience with python GUIs, using e.g. qt (implementing the classes for the functionality) and tried also some other frameworks.

Yes, I also found Tauri for wasm and it looks promising. One can create nice, colorful and clearly arranged interfaces; appeals to me.

I struggle with researching the route towards integrating the components. I think I will ask the pyO3 guys if they know if and how it is possible to integrate a console; perhaps in egui/tauri at a later point when I am able to ask better questions.

1 Like

Since it's html, you just need to pipe text both ways, them drop in a terminal library (first thing I found: @piopli/terminal-ui - npm)

2 Likes

Oho. Thank you for giving me this tip, @simonbuchan. I will delve into and experiment with that and hope to be able to post some useful code snippets. :crossed_fingers: :+1:

It's actually wry that wraps the system webview; tauri provides a backend and bundles everything up.

I started using tauri in a project recently, but found that all I really needed was wry!

2 Likes

The Tauri team spun out wry during dev, so I count it as part of the ecosystem. :person_shrugging:

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.