vanilla icon indicating copy to clipboard operation
vanilla copied to clipboard

AttributeError when calling vanilla.TextEditor.enable(onOff)

Open jtanadi opened this issue 7 years ago • 7 comments

Hi, when I do this:

self.w.textEditor = TextEditor((10, 10, 200, 200), "text")
self.w.textEditor.enable(False)

I get an:

File "/Applications/RoboFont.app/Contents/Resources/lib/python3.6/vanilla/vanillaBase.py", line 115, in enable
    self._nsObject.setEnabled_(onOff)
AttributeError: 'NSScrollView' object has no attribute 'setEnabled_'

jtanadi avatar Nov 29 '18 12:11 jtanadi

Try EditText instead of TextEditor. Only certain controls support disabling, and the vanilla API isn't quite clear about that. Not sure how to solve this, but it's an interesting issue.

justvanrossum avatar Nov 29 '18 12:11 justvanrossum

I didn't know that EditText supports multiline text. I think that works for now, but EditText can't scroll, so I may need to go back to a read-only TextEditor later.

I suppose TextEditor.enable(onOff) can be taken off the documentation for now—but I'm also not sure how up-to-date the doc is anyway.

jtanadi avatar Nov 29 '18 15:11 jtanadi

yeah enable(value) is a method in the parent vanillaBaseClass... so that is the reason why its ending up in the docs.

I guess the best option is to move enable(value) from the vanillaBase to the VanillaBaseControl https://github.com/typesupply/vanilla/blob/master/Lib/vanilla/vanillaBase.py#L111

similar to the method isEnabled()

An other option could be raise an error in the TextEditor subclass, and have an adjusted doc string, so it can be documented as such.

typemytype avatar Nov 29 '18 22:11 typemytype

The NSTextView has an editable property. That should have the desired effect.

schriftgestalt avatar Jan 12 '19 12:01 schriftgestalt

That's something different from a disabled control: it will only make the editor non-editable, it won't change its appearance to "disabled".

image

from vanilla import *

w = Window((180, 260))
w.button1 = Button((10, 10, 160, 24), "Button Enabled")
w.button2 = Button((10, 50, 160, 24), "Button Disabled")
w.button2.enable(False)
w.et1 = EditText((10, 90, 160, 24), "EditText Enabled")
w.et2 = EditText((10, 130, 160, 24), "EditText Disabled")
w.et2.enable(False)
w.te1 = TextEditor((10, 170, 160, 26), "TextEditor Editable")
w.te2 = TextEditor((10, 210, 160, 26), "TextEditor not Editable")
w.te2._textView.setEditable_(False)
w.open()

So, while the error message is confusing (TextEditor should ideally not have an enable() method), the behavior is correct, in that a TextEditor simply isn't a "control".

justvanrossum avatar Jan 12 '19 14:01 justvanrossum

But it is the most important property. Making it look grey is easy.

schriftgestalt avatar Jan 12 '19 15:01 schriftgestalt

a combo of setEditable_, setSelectable_ and setAlphaValue_ mimics setEnabled_

from vanilla import *

w = Window((180, 260))
w.l = List((0, 0, 0, 0), [])
w.button1 = Button((10, 10, 160, 24), "Button Enabled")
w.button2 = Button((10, 50, 160, 24), "Button Disabled")
w.button2.enable(False)
w.et1 = EditText((10, 90, 160, 24), "EditText Enabled")
w.et2 = EditText((10, 130, 160, 24), "EditText Disabled")
w.et2.enable(False)
w.te1 = TextEditor((10, 170, 160, 26), "TextEditor Editable")
w.te2 = TextEditor((10, 210, 160, 26), "TextEditor not Editable")


# disable edits
w.te2._textView.setEditable_(False)
# disable selectable
w.te2._textView.setSelectable_(False)
# draw opaque 
w.te2._textView.setAlphaValue_(.2)
w.open()

Screen Shot 2020-06-30 at 22 06 46

typemytype avatar Jun 30 '20 20:06 typemytype

I used @typemytype's suggestion:

import vanilla

w = vanilla.Window((200, 200))
w.te = vanilla.TextEditor((0, 0, 0, 0), "Testing.")
w.te.enable(False)
w.open()

typesupply avatar Dec 20 '23 16:12 typesupply