Created
October 15, 2020 13:09
-
-
Save nutti/6d06ee1ab43cc9b6d02e14988f62ba3b to your computer and use it in GitHub Desktop.
[Blender 2.91] blf module bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
"name": "Modal Operator Demo 1", | |
"author": "nutti", | |
"version": (1, 0, 0), | |
"blender": (2, 91, 0), | |
"location": "3D View > Sidebar > Modal Ops", | |
"category": "System", | |
} | |
import bpy | |
import blf | |
REGION_TYPE = 'UI' | |
def draw_callback_fn(context): | |
font_id = 0 | |
font_size = 30 | |
dpi = context.preferences.system.dpi | |
blf.size(font_id, font_size, dpi) | |
blf.position(font_id, 200, 200, 0) | |
blf.draw(font_id, "Text") | |
class DEMO_OT_ModalOps(bpy.types.Operator): | |
bl_idname = "wm.demo_modal_ops" | |
bl_label = "Modal Ops" | |
bl_description = "Modal Ops Desc" | |
bl_options = {'REGISTER'} | |
draw_handler = None | |
timer = None | |
def finalize(self, context): | |
cls = self.__class__ | |
bpy.types.SpaceView3D.draw_handler_remove(cls.draw_handler, REGION_TYPE) | |
context.window_manager.event_timer_remove(cls.timer) | |
cls.timer = None | |
cls.draw_handler = None | |
def modal(self, context, event): | |
cls = self.__class__ | |
if cls.draw_handler is None: | |
return {'FINISHED'} | |
context.area.tag_redraw() | |
return {'PASS_THROUGH'} | |
def invoke(self, context, event): | |
cls = self.__class__ | |
if cls.draw_handler: | |
self.finalize(context) | |
context.area.tag_redraw() | |
return {'FINISHED'} | |
else: | |
context.window_manager.modal_handler_add(self) | |
cls.draw_handler = bpy.types.SpaceView3D.draw_handler_add( | |
draw_callback_fn, (context, ), REGION_TYPE, 'POST_PIXEL') | |
cls.timer = context.window_manager.event_timer_add(0.1, window=context.window) | |
context.area.tag_redraw() | |
return {'RUNNING_MODAL'} | |
class DEMO_PT_ModalOps(bpy.types.Panel): | |
bl_idname = "DEMO_PT_ModalOps" | |
bl_label = "Modal Ops" | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'UI' | |
bl_category = "Modal Ops" | |
def draw(self, context): | |
layout = self.layout | |
layout.operator(DEMO_OT_ModalOps.bl_idname) | |
classes = [ | |
DEMO_OT_ModalOps, | |
DEMO_PT_ModalOps, | |
] | |
def register(): | |
for cls_ in classes: | |
bpy.utils.register_class(cls_) | |
def unregister(): | |
for cls_ in reversed(classes): | |
bpy.utils.unregister_class(cls_) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment