Multi-line Text Area in UI

Hi,

I am new to python and trying to show a multi line text area in a panel for user input. So far I have implemented two ‘hacky’ solutions using blf (which has word wrap built in), and another method that parses text and then displays the output as a series of labels. Neither are very user friendly. I am surprised Blender doesn’t have support for multi line text area.

The following code is not correct but Is it possible to show a text data block in the UI?

row.prop(bpy.data.texts, 'Text')

Yeah blf/bgl are your best options right now along with modal operator abuse for input. Playing nice with UILayout is another problem.

If you actually want to draw something custom inside a panel, you might have to add a bunch of dummy elements to reserve the space (like labels with icon “BLANK1”) then try to introspect the actual coordinates of the dummy elements by reconstructing, in python using ctypes, the native structs from the UILayout and drawing source code.

And just dealing with drawing is one thing, the other problem is user input, which has to be done with a modal operator being used in a non-modal way.

It quickly becomes a giant pain in the ass.

Now if you ignore trying to put something in a UILayout, things get easier and a custom UI is definitely possible, but again modal operators are a pain and the entire solution is very hacky. For example this experiment I did way back when: https://www.youtube.com/watch?v=3ZjZ1bx2hag

I might develop that idea further, but I would rather wait to see what 2.8 does first. Do I want a multiline text UI widget that integrates into a panel, yes. I would hope that 2.8 would bring something like this to the table.

1 Like

Hi SynaGl0w,

Thanks for answering. Your thoughts are what I was thinking. I might have a go at this, but I am new to programming/python. It may be a good way to learn new stuff.

I’m thinking I will make it a pop-up text box for user input/word wrapping and then have a go at displaying the results in a panel. To allow resizing of properties/tool-shelves etc I’m guessing the panel will need its own word wrap function to display a number of labels based on the number of lines it returns. Then maybe have an edit button if you wish to edit the text. The pop-up can run as a modal operator in that case?

Been mucking around with bgl and blf and a modal draw operator. So far I have got a pop-up that opens and allows text input and then uses a simple greedy algorithm for text wrapping. Just trying to implement copy/paste functions and mouse selection of text. Next I plan to show the results in a panel or node etc.

I love the non modal pop-ups you made in that video, very clever! Maybe once i put up a bit of code you could have a look and offer feedback or maybe even a bit of that voodoo magic code from your video to improve the UI!

I know 2.8 will break the code but I think it might be a good learning exercise for me anyway.