As I've seen in other display drivers it's common to extend the framebuf.FrameBuffer class.
However I'm fairly new to (micro)python and I'm seeing some weird results.
First of all, this code seems to work just fine:
class Super:
def __init__(self, name):
self.name = name
print(name)
class Sub(Super):
def __init__(self):
super().__init__('name')
Sub()
However trying to achieve the same thing with the FrameBuffer class (code below) keeps resulting in an error 'function missing 4 required positional arguments'
import framebuf
class Display(framebuf.FrameBuffer):
def __init__(self):
self.buffer = bytearray(1)
self.width = 1
self.height = 1
super().__init__(self.buffer, self.width, self.height, framebuf.GS4_HMSB)
Display()
So it seems it's impossible to define a new constructor for subclasses?
Question regarding inheritance (extending framebuf)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Question regarding inheritance (extending framebuf)
Your code runs here on a Pyboard V1.1 running firmware v1.9.3-362-g2ad555b-dirty on 2018-03-17. Are you running reasonably up to date firmware? The ability to subclass the framebuf class is fairly recent.
Note that, in general, subclassing built-in types is not fully supported - see this doc. As you showed, subclassing types defined in Python is OK. Secondly you will find an example where the framebuf class is subclassed in the official SSD1306 driver here. The constructor is very similar to yours.
Note that, in general, subclassing built-in types is not fully supported - see this doc. As you showed, subclassing types defined in Python is OK. Secondly you will find an example where the framebuf class is subclassed in the official SSD1306 driver here. The constructor is very similar to yours.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Question regarding inheritance (extending framebuf)
Hi, thanks for the fast reply.
I should have tested with the latest version (d'uh). On my osx build of micropython it also works. I'm using a WiPy which is unfortunately still on an older micropython version : (
I should have tested with the latest version (d'uh). On my osx build of micropython it also works. I'm using a WiPy which is unfortunately still on an older micropython version : (