Avices on getting code input from user for an addon

I am making an addon that need to handle some code expression that the user is going to write.

At first, I was making a Panel with a text input but I saw that we can only make a single line text input.

So I just realized that there was already a text editor in Blender that could handle all the common operations when editing code.

I have few questions :

  • I was thinking about integrating my panel inside the text editor window but the N key to open the right panel doesn’t work because it’s inserting a n letter rather than calling the shortcut, is there a way to trigger it rather than clicking?

  • When we create a file, it’s displaying the execute button when writing python scripts. If I want to execute my own files, is it possible to overwrite the behavior of that button? If it’s not possible, is it possible to add another button to this header (with a custom icon)? :

Capture d’écran de 2020-11-15 00-03-51

  • Most of the live coding editors have the ability to execute snippets of code by selecting them and pressing Ctrl+ENTER to evaluate them. How complex is it to implement in Python?

Thanks

you can use ctrl +T to toggle the side panel for text editor and for 3rd point you can change the keymap for run script in preferences

I wonder if maybe a custom node-tree would be a better user-interface for your addon? Nodes are essentially visual coding.

Nice thanks for the tips!

I managed to do that by effectively adding a keymap for CTRL+RET in the text editor:

km = kc.keymaps.new(name="Text", space_type="TEXT_EDITOR")

kmi = km.keymap_items.new(
  EXPRTONODES_OT_Parse.bl_idname, type="RET", value="PRESS", ctrl=True
)

addon_keymaps.append((km, kmi))

Then in my operator I get the selection and do something with it :+1:

Yes I would do that for this kind of addon but here the goal of the addon is to convert code into nodes (and not the opposite !) :wink:

Not sure if it makes sense but it’s a nice example to start building blender addons

:smiley: glad to hear it helped @johhnry . i was looking for some ideas for creating addons for blender