I'm trying to write a sequencer add-on. I need it to add a bgl
UI on top of the sequencer timeline, without a real interactive part, so I'm trying to make it a kind of "static handler" (I'm no coder, I don't know the specific term for it) instead of a modal operator with timer.
So far, I have this working, but I can't find a way to unregister it correctly when deactivating the add-on...
Here's example code with "hello world":
bl_info = {
"name": "modaltest",
"author": "tonton",
"version": (0, 1),
"blender": (2, 7, 9),
"location": "Sequencer",
"description": "",
"wiki_url": "",
"tracker_url": "",
"category": "Sequencer"}
import bpy
import bgl
import blf
def draw_callback_px():
font_id = 0 # XXX, need to find out how best to get this.
# draw some text
blf.position(font_id, 15, 30, 0)
blf.size(font_id, 20, 72)
blf.draw(font_id, "Hello Word ")
def register():
bpy.types.SpaceSequenceEditor.draw_handler_add(draw_callback_px, (), 'WINDOW', 'POST_PIXEL')
def unregister():
bpy.types.SpaceSequenceEditor.draw_handler_remove(draw_callback_px)
I tried a bunch of ways to unregister the handler, nothing so far has worked. Do you know what I am doing wrong? Thank you very much in advance! :D
SpaceSequenceEditor
andArea.type
$\endgroup$widgets = {}
defined globally. Add to in registerwidgets["Foo"] = DisplayClass()
and in unregisterfor key, dc in widgets.items(): dc.remove_handle()
Note might be an issue passing context as argument from register method, could instead use bpy.context in draw callback. It's late here, will get back to it if need be. $\endgroup$