Essential Text Editor add-ons for coders

Here’s the code for the above mentioned horizontal searchbar in the footer(nb. it replaces all menus):
https://blenderartists.org/uploads/default/original/4X/8/c/5/8c5f9147424ae273e3a835195b3405f9daf3a747.gif

@iceythe Couldn’t get active_item to work, but auto-add selection to find box when opening.

For a much more verbose output in the Info Editor, an(unexposed) operator is added to the Info Editor menus in this add-on:
image

I wrote an addon for the text editor long time ago to make my life easier when i was coding in the text editor.
pistiwique_pie_text_editor
I just updated it by merging 2 addons.
The version is for Blender 2.79 but i’d like to update it for Blender 2.8.

4 Likes

That’s a shame.

Looks like activate_init only works when called by bpy.ops.wm.call_menu(), so I guess it only works for popups, sadly. I used it when I tried to make a search popover in the past, but gave up since blender doesn’t really support persistent ui popups through python yet.

Speaking of search operator, there are things that could have been better both UI wise and functionally (don’t worry, it’s not a laundry list, just some observations I’ve made in the past).

  • It needs a way of choosing search directions

  • A non-1996 way of handling when no matches are found
    ie. not throwing a total of 3 errors (status bar, popup and in system console)

  • The eyedropper icon next to the search text needs to go. There is nothing we are “sampling”.

  • All of the sub-operators find_set_selected need to go. The main operator covers their usage.

  • Wrap search needs to always be on by default. “Darn it, forgot to turn wrap off” said absolutely no-one ever. In fact, it should be called “Loop”, because “Wrap” has a different meaning in a text context.

  • Case property needs to be an icon depicting two As, (eg. “Aa”), or called Case Sensitive.

1 Like

Yes, I agree on all of that, but it’s C stuff if that is to be implemented in Blender, so that’s out of my skills.

@pistiwique Absolutely brilliant add-on! Love the navigation system and everything else.

not reading through the whole thread so this may have been mentioned before- but the reason why I don’t and will NEVER use the text editor in Blender is because of how Blender’s window manager handles area focus. Most modern apps require you to click in an area to ‘activate’ it, but blender lets you just hover over to change the context.area, which means in a text editor if you bump your mouse and accidentally send it over into the terminal or outliner- you’re firing off hotkeys for who knows what rather than typing code.

it’s maddening.

2 Likes

Unfortunately, I don’t think developers will dwell on the text editor. It had to be created to tinker with a few lines of code, not to create a complete addon.
But at least we can improve it a little bit via Python

Actually text entry boxes have typing focus no matter what area the mouse cursor is above and it can be stopped by clicking outside of the typing focus area(the same behavior would be nice to have in the text editor, but again we need someone who can code in C to lift that code fro the text widget into the text editor):

In this example I’m typing without stop, notice the mouse position when letters are added:
type_focus

2 Likes

Technically speaking, blender allows this using modals to block input in different areas. The event system outputs full ascii and makes it pretty seamless (it’s literally just event.ascii straight into bpy.ops.text.insert()).

If it’s a good idea, however, is a different matter. Blender’s context paradigm being built around following the mouse cursor.

I suggested the Test Editor focus here: https://developer.blender.org/D5047

Maybe Harley and @iceythe are right, that this would be too big a change in the Blender paradigm.

@iceythe Have you already made a script which gives the TE focus? Maybe this could be a nice add-on?

if that got fixed I’d be much more inclined to use blender’s text editor for one-off simple scripts rather than firing up vscode. If they can fix it for the text editor they should also fix it on the terminal window too- I actually run into this problem with the terminal FAR more frequently than the text editor since it’s so small by default and easy for the mouse to move outside the area’s bounds

It has now been made a design issue up for discussion: https://developer.blender.org/T68830

1 Like

Pablo is touching on the latest Text Editor developments in Blender Today: https://youtu.be/9ILBCGY84cg?t=2168

3 Likes

Some organizing work on the Templates menu by Campbell and I:


To get people started coding, what are the most essential templates missing from the included collection?

5 Likes

Here’s an alternate UI take on selection and preview of Python Templates(just a mock up). Unfortunately Blender widgets do not have a multiline or a line wrap function.
template_list

I’ve been working on updating the Code Editor add-on to 2.81, but I’m running out of time. Here is the current script: https://paste.ofcode.org/S6HUEFUst2h7C5dGptzxkV

As it is right now it installs and runs without errors initially, but right clicking in the Text Editor context menu Blender for opering the add-on doesn’t work because all of the openGL code must be rewritten. All help appreciated.

4 Likes

If anyone would like to help with updating Code Editor then the 2.81 code can be found here: https://github.com/tin2tin/CodeEditor/tree/2.80

All the openGL code needs to be updated to use GPU draw instead, but when completed the Text Editor will look and feel much more like a modern text editor with mini-map, indentation marks, tabs, margin line, highlightning etc.

Stuff like auto brackets and smart_complete is working.

2 Likes

I came across some words the coder of Code Editor wrote about his add-on:

" So some time ago I wrote this addon to improve some Text editor functionality so I don’t have to go the external path. Nowadays I would code some of it’s parts differently and better (especially the multithreaded minimap updating) so any feedback is very welcomed. Here are the features:

  • Start and End with right-click in any Text-editor window (it also ends with F8 because when scripting an addon you need to reload with F8 and that is not possible because this addon is a modal operator. So you need F8 + F8 + Right-click>Start_again )
  • When started it adjusts the text-editor to the addon preferences, so you don’t have to set line_numbers, syntax_highlight, text_margin etc. every time you open new text-editor window (this is frustating blender behavior, these settings should be global…)
    enter image description here
  • It follows blender theme colors. The default ones are bad, so here I give you a good ones so its usable:
    enter image description here
  • It adds a scrollable and clickable code minimap with syntax highlighting, which fades out when window is too small. It is done in another thread and has lazy updating to not lag the text-editor (python is slow for this). It can be disabled in preferences with just setting huge Hide Panel threshold :
    enter image description here
  • It adds markers to visualize indentation, and it displays the scope of defs and classes (you can see it above in the gif). The scopes could be minimized but this didn’t make it into this release because when blender crashes you would loose the hidden code parts (the lines were removed from text and stored in custom property). You can see the toggle icons when you hover over line numbers.
  • Autocompletes brackets and “”,‘’:
    enter image description here
  • Use Alt + C for magic:
    • put things in lists:
      enter image description here
  • evaluate expressions (it knows pi, e, phi(golden ratio) and g(grav accel)):enter image description here
  • stringify words when cursor just after the word:enter image description here
  • Correct Home and Shift+Home behavior. Will move to first letter of line or to the previous indent. Alt+Home now moves to the line beginning:
    enter image description here
  • Make comments with Alt+D. (Remove with Ctrl+Shift+D - this one is not new):
    enter image description here
  • With multiple text-files it displays tabs to quickly switch between (blender has tabs but does not use them where it should…)
    enter image description here

All this was good enough for me not to use external editor. Multiple variables highlighting and multi-editing (like Sublime has) was planned but abandoned. Maybe if enough people will be interested I could further improve this. But I don’t see Blender addon python api strong enough to do this properly, this should be done in Blenders code for performance (like that scintilla patch)."

https://blender.stackexchange.com/questions/31126/workflow-for-developing-add-on-script/31195#31195

7 Likes

Here’s a test version updated for using the new gpu module. I only touched the draw code and I haven’t tested it fully, or even played around with it. You can see parts I changed here.

10 Likes

@iceythe Thank you! Thank you! I nearly gave up on this stuff. Thank you very much!!!

Wow, this is a giant leap for a Blender Text Editor v. 2.0 add-on which absolutely should be included with Blender!

Everyone using the Text Editor should give this a spin, and maybe a hand too if the add-on can be improved/optimized or expanded.

2 Likes