ModularM
Modular2y ago
5 replies
NixonInnes

Struct wrapping Python object

Please excuse me if this is a really noobie question, I'm just picking up the language...

I'm trying to port an old GUI application I wrote in Python using Pyglet. My plan is currently, assuming there are no Mojo GUI library, reimplement all of the data processing in Mojo with an interface to Python to draw the UI.

The first pattern I imagined would be something like:

# window.mojo
struct Window:
    var _window: _something_

    def __init__(inout self):
        self._window = self.get_window()

    def get_window(self) -> _something_:
        # ... import pywindow stuff here
        return pywindow.Window()


where I have a Python module which defines a window:

# py/window.py
import pyglet

class Window(pyglet.window.Window):
    ...


The glaringly obvious question is, should I do this? Second is, how should I type the struct? And lastly, if this is possible, what are the implications of referencing a PythonObject in my Mojo struct?
Was this page helpful?