2
$\begingroup$

Lets say there are operators (buttons .etc) that run or save the text in Text Editor. I need to change the text before such operators execute.

Is there a way involving some callback functions, listeners or handlers?

If there is not, is there a way to remove UI element and replace it in the same spot with custom operator? I only found a way how to append or prepend an operator to such menu or header.

$\endgroup$
3
+50
$\begingroup$

I don't think that there are listeners which you can use in that way.

But what you can do is your idea in the second question. You could replace the button with a custom operator which executes your code first and calls the original operator afterwards. You can access the sources if you right-click on that original button and choose edit source. After that go to the scripting view and choose the source file available in the dropdown box

enter image description here

$\endgroup$
  • $\begingroup$ I cant change the source code, this must work from addon. So I can only change it like: bpy.types.TEXT_HT_header.prepend(foo). The difficult part is to remove the old entry and place a new one in that spot. $\endgroup$ – Jaroslav Jerryno Novotny Dec 4 '14 at 11:55
  • $\begingroup$ Can you re-register the same operator to override its function? Although, then you'd have to do the work of that operator yourself. $\endgroup$ – Mike Pan Dec 5 '14 at 1:38
  • 1
    $\begingroup$ Yeah I can re-register those classes in addon but that would be super dirty, there must be a cleaner way. I can't believe that there is no callback or anything in something such important as operators. Half of blender stands on them.. $\endgroup$ – Jaroslav Jerryno Novotny Dec 5 '14 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.