Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/python_api/examples/blf.py49
-rw-r--r--source/blender/python/intern/bpy_rna_callback.c6
2 files changed, 28 insertions, 27 deletions
diff --git a/doc/python_api/examples/blf.py b/doc/python_api/examples/blf.py
index f6e87cf488d..e288ac9db66 100644
--- a/doc/python_api/examples/blf.py
+++ b/doc/python_api/examples/blf.py
@@ -2,43 +2,44 @@
Hello World Text Example
++++++++++++++++++++++++
-Blender Game Engine example of using the blf module. For this module to work we
+Example of using the blf module. For this module to work we
need to use the OpenGL wrapper :class:`~bgl` as well.
"""
-# import game engine modules
-from bge import render
-from bge import logic
# import stand alone modules
import bgl
import blf
+import bpy
+font_info = {
+ "font_id": 0,
+ "handler": None,
+}
def init():
"""init function - runs once"""
- # create a new font object, use external ttf file
- font_path = logic.expandPath('//Zeyada.ttf')
- # store the font indice - to use later
- logic.font_id = blf.load(font_path)
+ import os
+ # Create a new font object, use external ttf file.
+ font_path = bpy.path.abspath('//Zeyada.ttf')
+ # Store the font indice - to use later.
+ if os.path.exists(font_path):
+ font_info["font_id"] = blf.load(font_path)
+ else:
+ # Default font.
+ font_info["font_id"] = 0
# set the font drawing routine to run every frame
- scene = logic.getCurrentScene()
- scene.post_draw = [write]
+ font_info["handler"] = bpy.types.SpaceView3D.draw_handler_add(
+ draw_callback_px, (None, None), 'WINDOW', 'POST_PIXEL')
-def write():
- """write on screen"""
- width = render.getWindowWidth()
- height = render.getWindowHeight()
-
- # OpenGL setup
- bgl.glMatrixMode(bgl.GL_PROJECTION)
- bgl.glLoadIdentity()
- bgl.gluOrtho2D(0, width, 0, height)
- bgl.glMatrixMode(bgl.GL_MODELVIEW)
- bgl.glLoadIdentity()
-
+def draw_callback_px(self, context):
+ """Draw on the viewports"""
# BLF drawing routine
- font_id = logic.font_id
- blf.position(font_id, (width * 0.2), (height * 0.3), 0)
+ font_id = font_info["font_id"]
+ blf.position(font_id, 2, 80, 0)
blf.size(font_id, 50, 72)
blf.draw(font_id, "Hello World")
+
+
+if __name__ == '__main__':
+ init()
diff --git a/source/blender/python/intern/bpy_rna_callback.c b/source/blender/python/intern/bpy_rna_callback.c
index 68783feacd9..01a25137a98 100644
--- a/source/blender/python/intern/bpy_rna_callback.c
+++ b/source/blender/python/intern/bpy_rna_callback.c
@@ -189,7 +189,7 @@ PyObject *pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) < 2) {
- PyErr_SetString(PyExc_ValueError, "handler_add(handle): expected at least 2 args");
+ PyErr_SetString(PyExc_ValueError, "handler_add(handler): expected at least 2 args");
return NULL;
}
@@ -252,7 +252,7 @@ PyObject *pyrna_callback_classmethod_remove(PyObject *UNUSED(self), PyObject *ar
int cb_regiontype;
if (PyTuple_GET_SIZE(args) < 2) {
- PyErr_SetString(PyExc_ValueError, "callback_remove(handle): expected at least 2 args");
+ PyErr_SetString(PyExc_ValueError, "callback_remove(handler): expected at least 2 args");
return NULL;
}
@@ -263,7 +263,7 @@ PyObject *pyrna_callback_classmethod_remove(PyObject *UNUSED(self), PyObject *ar
py_handle = PyTuple_GET_ITEM(args, 1);
handle = PyCapsule_GetPointer(py_handle, RNA_CAPSULE_ID);
if (handle == NULL) {
- PyErr_SetString(PyExc_ValueError, "callback_remove(handle): NULL handle given, invalid or already removed");
+ PyErr_SetString(PyExc_ValueError, "callback_remove(handler): NULL handler given, invalid or already removed");
return NULL;
}