I have a vanilla EditText which I use for numbers and I want to be able to hit up/down (also with shift) to change the value. This really isn’t about Glyphs, but I haven’t been able to find a way to do it. How difficult is it?
vanilla.TextBox, simply use
GSSteppingTextField. You initialize an object with something like:
self.w.numberField = GSSteppingTextField.alloc().init()
To get an overview, put
GSSteppingTextField into the Method Reporter, then you see the PyObjC methods available. You will recognize a lot from Vanilla.
I made a small subclass of
GSSteppingTextField = objc.lookUpClass("GSSteppingTextField") class ArrowEditText (EditText): nsTextFieldClass = GSSteppingTextField def _setCallback(self, callback): super(ArrowEditText, self)._setCallback(callback) if callback is not None and self._continuous: self._nsObject.setContinuous_(True) self._nsObject.setAction_(self._target.action_) self._nsObject.setTarget_(self._target)
then you can use it like this:
class EditTextDemo(): def __init__(self): self.w = Window((100, 42)) self.w.editText = ArrowEditText((10, 10, -10, 22), callback=self.editTextCallback, continuous=True) self.w.open() def editTextCallback(self, sender): print "text entry!", sender.get() EditTextDemo()
Love it! I’ll buy you guys a beer at TYPO Labs!
Is there a way to transform the
GSSteppingTextField into a cell? I currently use dynamically generated NSSliderCell in the ColumnDescriptions of a Vanilla List and would like to replace them by the Stepping Feld.
The cell can’t do anything. Only the NSControl that contains the cell can handle keyboard events.
What are you trying to do?
So among other items vanilla list can have a SliderListCell which I can customize by subclassing its NSSliderCell. As declared in the vanilla docu, these List Item Cells should only be used in the columnDescriptions argument during the construction. That’s what I did back then when writing a plugin. The code is very extensive and everything is built around the columnDescriptions architecture. The list items are loaded dynamically, context based.
But now I find the Sliders inconvenient UI-wise and would like to replace them with something that behaves like a GSSteppingTextField. Unfortunately I could only manage to use a NSTextFieldCell, but this one is annoying, because you need to double click and hit enter to change the value. Also you cannot change the value with the arrow keys.
This is a great snippet! Is there a way to change the “empty” input value from 0 to something else from outside? So when you click an arrow on an empty input it gives say 101 instead of 1?
You could just show the 100 as default? I would expect to always show a value, so there is not “Empty” state.
Sure, I just show default values as placeholders to make it more clear to see which are changed and which are not.
The steppingextField has a
plainValue property. You can try to put your default value in there. Then stepping should pick it up as a starting point.