[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16613] trunk/blender/source/blender: == Python Space Handlers ==
Willian Padovani Germano
wpgermano at gmail.com
Fri Sep 19 20:53:40 CEST 2008
Revision: 16613
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16613
Author: ianwill
Date: 2008-09-19 20:53:05 +0200 (Fri, 19 Sep 2008)
Log Message:
-----------
== Python Space Handlers ==
Patch #9673: "Short patch to make spacehandler event scripts work more like normal python gui script handlers" by Steven Truppe:
http://projects.blender.org/tracker/?func=detail&atid=127&aid=9673&group_id=9
This patch adds the Blender.eventValue variable available for space handlers, holding the event value (aka 1 for button and key presses, X or Y coordinate for mousex / mousey movement). Thanks, Steven. PS: this doesn't break existing scripts.
Modified Paths:
--------------
trunk/blender/source/blender/python/BPY_extern.h
trunk/blender/source/blender/python/BPY_interface.c
trunk/blender/source/blender/python/api2_2x/doc/API_intro.py
trunk/blender/source/blender/python/api2_2x/doc/API_related.py
trunk/blender/source/blender/python/api2_2x/doc/Blender.py
trunk/blender/source/blender/src/drawview.c
trunk/blender/source/blender/src/space.c
Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h 2008-09-19 16:09:26 UTC (rev 16612)
+++ trunk/blender/source/blender/python/BPY_extern.h 2008-09-19 18:53:05 UTC (rev 16613)
@@ -112,7 +112,7 @@
int BPY_has_spacehandler(struct Text *text, struct ScrArea *sa);
void BPY_screen_free_spacehandlers(struct bScreen *sc);
int BPY_do_spacehandlers(struct ScrArea *sa, unsigned short event,
- unsigned short space_event);
+ short eventValue, unsigned short space_event);
void BPY_pydriver_update(void);
float BPY_pydriver_eval(struct IpoDriver *driver);
Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c 2008-09-19 16:09:26 UTC (rev 16612)
+++ trunk/blender/source/blender/python/BPY_interface.c 2008-09-19 18:53:05 UTC (rev 16613)
@@ -2475,7 +2475,7 @@
}
int BPY_do_spacehandlers( ScrArea *sa, unsigned short event,
- unsigned short space_event )
+ short eventValue, unsigned short space_event )
{
ScriptLink *scriptlink;
int retval = 0;
@@ -2515,8 +2515,9 @@
PyDict_SetItemString(g_blenderdict, "bylink", Py_True);
/* unlike normal scriptlinks, here Blender.link is int (space event type) */
EXPP_dict_set_item_str(g_blenderdict, "link", PyInt_FromLong(space_event));
- /* note: DRAW space_events set event to 0 */
+ /* note: DRAW space_events set event and val to 0 */
EXPP_dict_set_item_str(g_blenderdict, "event", PyInt_FromLong(event));
+ EXPP_dict_set_item_str(g_blenderdict, "eventValue", PyInt_FromLong(eventValue));
/* now run all assigned space handlers for this space and space_event */
for( index = 0; index < scriptlink->totscript; index++ ) {
Modified: trunk/blender/source/blender/python/api2_2x/doc/API_intro.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/API_intro.py 2008-09-19 16:09:26 UTC (rev 16612)
+++ trunk/blender/source/blender/python/api2_2x/doc/API_intro.py 2008-09-19 18:53:05 UTC (rev 16613)
@@ -61,6 +61,14 @@
- L{World}
- L{sys<Sys>}
+ Additional information:
+ -----------------------
+ - L{API_related}:
+ - Calling scripts from command line
+ - Script links and space handlers
+ - How to register scripts in menus
+ - Recommended ways to document and support configuration options
+
Introduction:
=============
Modified: trunk/blender/source/blender/python/api2_2x/doc/API_related.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/API_related.py 2008-09-19 16:09:26 UTC (rev 16612)
+++ trunk/blender/source/blender/python/api2_2x/doc/API_related.py 2008-09-19 18:53:05 UTC (rev 16613)
@@ -226,6 +226,7 @@
import Blender
from Blender import Draw
evt = Blender.event
+ val = Blender.eventValue
return_it = False
if evt == Draw.LEFTMOUSE:
@@ -233,7 +234,7 @@
elif evt == Draw.AKEY:
print "Swallowing an 'a' character"
else:
- print "Let the 3D View itself process this event:", evt
+ print "Let the 3D View itself process this event: %d with value %d" % (evt, val)
return_it = True
# if Blender should not process itself the passed event:
@@ -249,8 +250,14 @@
tells what space this handler belongs to and the handler's type
(EVENT, DRAW);
- B{event}:
- - EVENT handlers: an input event (check keys and mouse events in L{Draw})
- to be processed or ignored.
+ - EVENT handlers: an input event (check keys and mouse events in
+ L{Draw}) to be processed or ignored;
+ - DRAW handlers: 0 always;
+ - B{eventValue}:
+ - EVENT handlers: the event value, it indicates mouse button or key
+ presses (since we don't pass releases) as 1 and mouse movements
+ (Draw.MOUSE.X and Draw.MOUSE.Y) as the current x or y coordinate,
+ for example;
- DRAW handlers: 0 always.
B{Guidelines (important)}:
Modified: trunk/blender/source/blender/python/api2_2x/doc/Blender.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Blender.py 2008-09-19 16:09:26 UTC (rev 16612)
+++ trunk/blender/source/blender/python/api2_2x/doc/Blender.py 2008-09-19 18:53:05 UTC (rev 16613)
@@ -10,8 +10,8 @@
"""
The main Blender module.
-B{New}: L{Run}, L{UpdateMenus}, new options to L{Get}, L{ShowHelp},
-L{SpaceHandlers} dictionary.
+B{New}: new var L{eventValue} for space handlers, L{Run}, L{UpdateMenus},
+new options to L{Get}, L{ShowHelp}, L{SpaceHandlers} dictionary.
L{UnpackModes} dictionary.
Blender
@@ -34,7 +34,11 @@
- for normal L{GUI<Draw.Register>} scripts I{during the events callback},
it holds the ascii value of the current event, if it is a valid one.
Users interested in this should also check the builtin 'ord' and 'chr'
- Python functions.
+ Python functions.
+ at type eventValue: int
+ at var eventValue: used only for EVENT space handlers, it holds the event value:
+ - for mouse button and key presses it's 1, for mouse movement
+ (Draw.MOUSEX and Draw.MOUSEY) it has the new x or y coordinate, resp.
@type mode: string
@var mode: Blender's current mode:
- 'interactive': normal mode, with an open window answering to user input;
Modified: trunk/blender/source/blender/src/drawview.c
===================================================================
--- trunk/blender/source/blender/src/drawview.c 2008-09-19 16:09:26 UTC (rev 16612)
+++ trunk/blender/source/blender/src/drawview.c 2008-09-19 18:53:05 UTC (rev 16613)
@@ -3422,7 +3422,7 @@
/* run any view3d draw handler script links */
if (sa->scriptlink.totscript)
- BPY_do_spacehandlers(sa, 0, SPACEHANDLER_VIEW3D_DRAW);
+ BPY_do_spacehandlers(sa, 0, 0, SPACEHANDLER_VIEW3D_DRAW);
/* run scene redraw script links */
if((G.f & G_DOSCRIPTLINKS) && G.scene->scriptlink.totscript &&
Modified: trunk/blender/source/blender/src/space.c
===================================================================
--- trunk/blender/source/blender/src/space.c 2008-09-19 16:09:26 UTC (rev 16612)
+++ trunk/blender/source/blender/src/space.c 2008-09-19 18:53:05 UTC (rev 16613)
@@ -1206,8 +1206,8 @@
*/
if(event==LEFTMOUSE) {
/* run any view3d event handler script links */
- if (event && sa->scriptlink.totscript) {
- if (BPY_do_spacehandlers(sa, event, SPACEHANDLER_VIEW3D_EVENT))
+ if (sa->scriptlink.totscript) {
+ if (BPY_do_spacehandlers(sa, event, val, SPACEHANDLER_VIEW3D_EVENT))
return; /* return if event was processed (swallowed) by handler(s) */
}
@@ -1268,7 +1268,7 @@
/* run any view3d event handler script links */
if (event && sa->scriptlink.totscript)
- if (BPY_do_spacehandlers(sa, event, SPACEHANDLER_VIEW3D_EVENT))
+ if (BPY_do_spacehandlers(sa, event, val, SPACEHANDLER_VIEW3D_EVENT))
return; /* return if event was processed (swallowed) by handler(s) */
/* TEXTEDITING?? */
More information about the Bf-blender-cvs
mailing list