Notes for Python

1. Every type implements __str__() and __repr__() for debug printing

2. Simple (non-union) enum types implement__richcmp__():

align = LayoutAlignItems.Stretch if align == LayoutAlignItems.Stretch: print("ok!")

3. union enums have a @staticmethod constructor and a hidden .match() function that will return the enum tag as a string and the enum payload as a PyObject:

size = OptionLogicalSize.Some(LogicalSize(600, 800)) tag, payload = size.match() if tag == "Some": print("size is {}, {}".format(payload.width, payload.height)) elif tag == "None": print("no size available")

4. new() constructors are the default constructors:

dom = Dom(NodeType.Div) # not!

5. If no explicit new() constructors exist, the default constructor takes all arguments in the order as they are specified in the API:

# API: struct ColorU { r: u8, g: u8, b: u8 a: u8 } # therefore the arguments to the default constructor are passed in order: color = ColorU(/*r*/ 255, /*g*/ 255, /*b*/ 255, /*a*/ 255)

6. Whenever a RefAny parameter is required to call a function, you can use any PyObject as a replacement:

mydata = MyClass() # your custom data type # App::new() takes a RefAny as the first argument - pass in your custom data type here app = App(mydata, AppConfig(LayoutSolver.Default))

7. All functions that take a *Vec type accept a PyList and all *Option types are automatically converted to and from Pythons None value:

monitors = app.get_monitors() # returns MonitorVec = PyList[Monitor] print(str(monitors[0])) # returns OptionLogicalPosition = Optional[LogicalPosition] cursor_relative = callbackinfo.get_cursor_relative_to_viewport() if cursor_relative is not None: print(str(cursor_relative))

8. Due to a bug in the Python PyO3 bindings, you cannot modify a struct through a struct (see issue).

window = WindowCreateOptions(LayoutSolver.Default) window.state.flags.frame = WindowFrame.Maximized # does not work # workaround (yes, it's annoying): state = window.state.copy() flags = state.flags.copy() flags.frame = WindowFrame.Maximized state.flags = flags window.state = state