Calling a super class's constructor

Ok, let’s say I want to make a subclass of View, so I write a class method to do constructor stuff:

*new{|parent, bounds, leftPanel, rightPanel, dominant=\left|
	^super.new(parent, bounds).initPanes(nil, nil, leftPanel, rightPanel, dominant);
}

And this totally does not work. How do I tell it to run the super constructor first??

That looks ok to me in the sense that it’s the same pattern as, for example, the code for Checkbox:

CheckBox : View {

	*qtClass { ^'QcCheckBox' }

	*new{ |parent,bounds,text|
		^super.new(parent,bounds).init(text)
	}

	init{ |text|
		this.string_(text)
	}
. . .

Can you explain more about what you mean by “does not work”? Did it not compile, or did you get an error when running it?
Best,
Paul

If I comment out all of the contents of initPanes, it should just act like a completely normal View class.
However, trying to use it as a View with the following code:

(
j = SplitHPanel().background_(Color.rand);
j.toFrontAction = { "Something should have happened".postln};
j.front
)

Does nothing. No errors are generated, but it also doesn’t open a window or post anything to the post window.

I’m guessing there’s something very fiddly that would fix it, but I just can’t find it…

It worked fine here: I made this test class:

TestViewClass : View {

	*new{|parent, bounds, leftPanel, rightPanel, dominant=\left|
		^super.new(parent, bounds).initPanes(nil, nil, leftPanel, rightPanel, dominant);
	}
	initPanes{
	}
}

I put it in the extensions folder, recompiled and ran this:

(
j = TestViewClass().background_(Color.rand);
j.toFrontAction = { "Something should have happened".postln};
j.front
)

It showed the window as expected and posted this:

-> a TestViewClass
Something should have happened

So your error must be due to something else.
Perhaps you could show the full text of your class.
Best,
Paul

I’d suspect the initPanes isn’t returning this.

1 Like