C backend possible?

Hello,
Is it possible to have a C backend logic to a frontend wxWidgets application?
For example, a simple calculator gui made with wx and the calculations done with C?
if it’s possible, please guide me
thanks

Yes, it’s possible, you can write the C backend as a C extension, e.g. using Cython as the glue between your C code and your Python code.

Another option is to package your C code as a shared library (.dll/.so), and using ctypes or cffi to interface.

Whether it’s a good idea is another matter. You sure you can’t just write the whole thing in Python?

Thank you for the input.
Nope, as a matter of fact I will need the C performance because I’m trying to make a 3d modeller. Do you think it wouldn’t matter to write it in python?

Put all the time-critical, number-crunchy bits in a C extension module. Put all the rest in Python where Python is fast enough. This will get you started:

https://docs.python.org/3/extending/extending.html

Depending on your needs, using numpy arrays to pass the data between C and Python might be a good way to go, but it would be a more advanced thing that you probably would not want to tackle until you’ve mastered the basics of Python extensions.

1 Like

Thanks. Would it still be possible to do multithreading and memory management in C?

Yes, of course. Python does that in C afterall.

It would be great to have an example of wxPython/C interaction for grid data tables and window redrawing.

E.g. my code is in Python and holds most data in numpy arrays.

For displaying in a virtual grid, I have classes derived from GridTableBase. Such a grid feels much slower than a grid in wxWidgets. Probably the Get… methods could somehow be implemented in a C++ base class that my Python code then derives from. (Having to code the complete GridTable in C++ would be not so nice.)

Similar for the EVT_PAINT handler which needs to draw lines from the numpy data. It would be nice to have the inner loop in C++.