Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

GeometrySerializer cannot be instantiated or sub-classed

Open daemotron opened this issue 3 years ago • 1 comments
trafficstars

Operating system: Windows 11 wxPython version & source: 4.1.1 installed from pypi (wheel) Python version & source: 3.8.10 (stock, installer from python.org)

Description of the problem:

I'm trying to implement a serializer that can be used with wx.TopLevelWindow.SaveGeometry(). Following the documentation and this discussion, I tried implementing a class inheriting from wx.TopLevelWindow.GeometrySerializer. However, this leads to a type error, no matter whether I try inheriting directly, or using wx.TopLevelWindow.GeometrySerializer as meta class.

Implementation attempt
import wx


class MySerializer(metaclass=wx.TopLevelWindow.GeometrySerializer):

    def SaveField(self, name, value):
        print("[{name}] = {value}".format(name=name, value=value))

    def RestoreField(self, name):
        print("I want {name}".format(name=name))


serializer = MySerializer()
TypeError thrown by the code above
Traceback (most recent call last):
  File "serializer.py", line 4, in <module>
    class MySerializer(metaclass=wx.TopLevelWindow.GeometrySerializer):
TypeError: wx._core.GeometrySerializer cannot be instantiated or sub-classed

daemotron avatar Feb 26 '22 11:02 daemotron

Confirmed. The issue is that wx.TopLevelWindow.GeometrySerializer isn't exposed. The etg scripts don't seem to be able to handle classes defined within classes, as best as I can see.

swt2c avatar Feb 27 '22 16:02 swt2c