RNA read-only wrapped wmEvent so python operators invoke functions
authorCampbell Barton <ideasman42@gmail.com>
Sun, 21 Jun 2009 14:30:59 +0000 (14:30 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 21 Jun 2009 14:30:59 +0000 (14:30 +0000)
* 2 new enums event_value_items and event_type_items in RNA_enum_types.h
* WM_key_event_string now uses an RNA enum lookup rather then its own switch statement.
* moved wmEvent from WM_types.h into DNA_windowmanager_types.h
* added RNA_enum_identifier and RNA_enum_name to get strings from an enum value.

source/blender/editors/transform/transform_input.c
source/blender/editors/transform/transform_ndofinput.c
source/blender/editors/transform/transform_numinput.c
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/makesrna/RNA_access.h
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_wm.c
source/blender/python/intern/bpy_operator_wrap.c
source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/wm_keymap.c

index 4d721a83c78a6fe7758ba2844e97cd09a1937c87..76b3f58f75cdbe248bae168b54800381d7af4e0a 100644 (file)
@@ -26,6 +26,7 @@
 #include <math.h>
 
 #include "DNA_screen_types.h"
+#include "DNA_windowmanager_types.h"
 
 #include "BLI_arithb.h"
 
index c52492ebd6be23039203c5c9fa8a8a0e9d776a1f..9c2a1a7db6d55144f9595a8ac675289ed1069b76 100644 (file)
@@ -31,6 +31,7 @@
 #include "BKE_utildefines.h"   /* ABS */
 
 #include "DNA_view3d_types.h" /* for G.vd (view3d) */
+#include "DNA_windowmanager_types.h" /* for G.vd (view3d) */
 
 #include "WM_types.h"
 
index 34976105db3324e776bfe049d77f2ea48233de59..f5f1d5fac9ecfa5bdbaa383db1f3956a09e99da6 100644 (file)
@@ -34,6 +34,7 @@
 #include "BKE_utildefines.h"   /* ABS */
 
 #include "WM_types.h"
+#include "DNA_windowmanager_types.h"
 
 #include "transform.h"
 
index 7d6b5ec876436a0636ec6e396b85e52e900b0613..e02d2984771af1a9682c03803dba145cccb3d347 100644 (file)
@@ -222,5 +222,36 @@ typedef enum wmRadialControlMode {
        WM_RADIALCONTROL_ANGLE
 } wmRadialControlMode;
 
+/* ************** wmEvent ************************ */
+/* for read-only rna access, dont save this */
+
+/* each event should have full modifier state */
+/* event comes from eventmanager and from keymap */
+typedef struct wmEvent {
+       struct wmEvent *next, *prev;
+       
+       short type;                     /* event code itself (short, is also in keymap) */
+       short val;                      /* press, release, scrollvalue */
+       short x, y;                     /* mouse pointer position, screen coord */
+       short mval[2];          /* region mouse position, name convention pre 2.5 :) */
+       short prevx, prevy;     /* previous mouse pointer position */
+       short unicode;          /* future, ghost? */
+       char ascii;                     /* from ghost */
+       char pad;
+       
+       /* modifier states */
+       short shift, ctrl, alt, oskey;  /* oskey is apple or windowskey, value denotes order of pressed */
+       short keymodifier;                              /* rawkey modifier */
+       
+       /* keymap item, set by handler (weak?) */
+       const char *keymap_idname;
+       
+       /* custom data */
+       short custom;   /* custom data type, stylus, 6dof, see wm_event_types.h */
+       void *customdata;       /* ascii, unicode, mouse coords, angles, vectors, dragdrop info */
+       short customdatafree;
+       
+} wmEvent;
+
 #endif /* DNA_WINDOWMANAGER_TYPES_H */
 
index 9b653bd924a57522750bc723646820047701bdb8..4a074ab1546ff5dad7e4d5004eb9fb9cb04d0ac3 100644 (file)
@@ -172,6 +172,7 @@ extern StructRNA RNA_EnvironmentMap;
 extern StructRNA RNA_EnvironmentMapTexture;
 extern StructRNA RNA_ExplodeModifier;
 extern StructRNA RNA_ExpressionController;
+extern StructRNA RNA_Event;
 extern StructRNA RNA_FCurve;
 extern StructRNA RNA_FModifier;
 extern StructRNA RNA_FModifierCycles;
@@ -541,6 +542,9 @@ void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin,
 void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax);
 void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision);
 
+int RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **identifier);
+int RNA_enum_name(const EnumPropertyItem *item, const int value, const char **name);
+
 void RNA_property_enum_items(PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **item, int *totitem);
 int RNA_property_enum_value(PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value);
 int RNA_property_enum_identifier(PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier);
index c679d9fc5449d6171c0355813f56750849b3fa1b..276f421c5867c33dbf5fb32a0203dec04f309542 100644 (file)
@@ -40,6 +40,9 @@ extern EnumPropertyItem beztriple_interpolation_mode_items[];
 
 extern EnumPropertyItem fmodifier_type_items[];
 
+extern EnumPropertyItem event_value_items[];
+extern EnumPropertyItem event_type_items[];
+
 #endif /* RNA_ENUM_TYPES */
 
 
index ba893319ce98f0ffb3029de71d40dc74c4ef25ca..13686809cd2eb5f52f64607f9b2e7491040d265f 100644 (file)
@@ -669,6 +669,28 @@ int RNA_property_enum_value(PointerRNA *ptr, PropertyRNA *prop, const char *iden
        return 0;
 }
 
+int RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **identifier)
+{
+       for (; item->identifier; item++) {
+               if(item->value==value) {
+                       *identifier = item->identifier;
+                       return 1;
+               }
+       }
+       return 0;
+}
+
+int RNA_enum_name(const EnumPropertyItem *item, const int value, const char **name)
+{
+       for (; item->identifier; item++) {
+               if(item->value==value) {
+                       *name = item->name;
+                       return 1;
+               }
+       }
+       return 0;
+}
+
 int RNA_property_enum_identifier(PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier)
 {      
        const EnumPropertyItem *item;
@@ -676,14 +698,7 @@ int RNA_property_enum_identifier(PointerRNA *ptr, PropertyRNA *prop, const int v
        
        RNA_property_enum_items(ptr, prop, &item, &totitem);
        
-       for(i=0; i<totitem; i++) {
-               if(item[i].value==value) {
-                       *identifier = item[i].identifier;
-                       return 1;
-               }
-       }
-       
-       return 0;
+       return RNA_enum_identifier(item, value, identifier);
 }
 
 const char *RNA_property_ui_name(PropertyRNA *prop)
index df07e03850ad8286991210bdbd830eb51f61e32c..a1b51084fca71cf9cf1060efdd4b84b08c48c5a1 100644 (file)
 #include "rna_internal.h"
 
 #include "DNA_windowmanager_types.h"
+#include "WM_types.h" /* wmEvent */
+
+
+EnumPropertyItem event_value_items[] = {
+       {KM_ANY, "ANY", 0, "Any", ""},
+       {KM_NOTHING, "NOTHING", 0, "Nothing", ""},
+       {KM_PRESS, "PRESS", 0, "Press", ""},
+       {KM_RELEASE, "RELEASE", 0, "Release", ""},
+       {0, NULL, 0, NULL, NULL}};
+
+/* not returned: CAPSLOCKKEY, UNKNOWNKEY, COMMANDKEY, GRLESSKEY */
+EnumPropertyItem event_type_items[] = {
+       {AKEY, "A", 0, "A", ""},
+       {BKEY, "B", 0, "B", ""},
+       {CKEY, "C", 0, "C", ""},
+       {DKEY, "D", 0, "D", ""},
+       {EKEY, "E", 0, "E", ""},
+       {FKEY, "F", 0, "F", ""},
+       {GKEY, "G", 0, "G", ""},
+       {HKEY, "H", 0, "H", ""},
+       {IKEY, "I", 0, "I", ""},
+       {JKEY, "J", 0, "J", ""},
+       {KKEY, "K", 0, "K", ""},
+       {LKEY, "L", 0, "L", ""},
+       {MKEY, "M", 0, "M", ""},
+       {NKEY, "N", 0, "N", ""},
+       {OKEY, "O", 0, "O", ""},
+       {PKEY, "P", 0, "P", ""},
+       {QKEY, "Q", 0, "Q", ""},
+       {RKEY, "R", 0, "R", ""},
+       {SKEY, "S", 0, "S", ""},
+       {TKEY, "T", 0, "T", ""},
+       {UKEY, "U", 0, "U", ""},
+       {VKEY, "V", 0, "V", ""},
+       {WKEY, "W", 0, "W", ""},
+       {XKEY, "X", 0, "X", ""},
+       {YKEY, "Y", 0, "Y", ""},
+       {ZKEY, "Z", 0, "Z", ""},
+       
+       {ZEROKEY, "ZERO",       0, "Zero Key", ""},
+       {ONEKEY, "ONE",         0, "One Key", ""},
+       {TWOKEY, "TWO",         0, "Two Key", ""},
+       {THREEKEY, "THREE",     0, "Three Key", ""},
+       {FOURKEY, "FOUR",       0, "Four Key", ""},
+       {FIVEKEY, "FIVE",       0, "Five Key", ""},
+       {SIXKEY, "SIX",         0, "Six Key", ""},
+       {SEVENKEY, "SEVEN",     0, "Seven Key", ""},
+       {EIGHTKEY, "EIGHT",     0, "Eight Key", ""},
+       {NINEKEY, "NINE",       0, "Nine Key", ""},
+       
+       {LEFTCTRLKEY,   "LEFT_CTRL",    0, "Left Ctrl", ""},
+       {LEFTALTKEY,    "LEFT_ALT",             0, "Left Alt", ""},
+       {RIGHTALTKEY,   "RIGHT_ALT",    0, "Right Alt", ""},
+       {RIGHTCTRLKEY,  "RIGHT_CTRL",   0, "Rightctrl", ""},
+       {RIGHTSHIFTKEY, "RIGHT_SHIFT",  0, "Rightshift", ""},
+       {LEFTSHIFTKEY,  "LEFT_SHIFT",   0, "Leftshift", ""},
+       
+       {ESCKEY, "ESC", 0, "Esc", ""},
+       {TABKEY, "TAB", 0, "Tab", ""},
+       {RETKEY, "RET", 0, "Return", ""},
+       {SPACEKEY, "SPACE", 0, "Spacebar", ""},
+       {LINEFEEDKEY, "LINE_FEED", 0, "Line Feed", ""},
+       {BACKSPACEKEY, "BACK_SPACE", 0, "Back Space", ""},
+       {DELKEY, "DEL", 0, "Delete", ""},
+       {SEMICOLONKEY, "SEMI_COLON", 0, "Semicolon", ""},
+       {PERIODKEY, "PERIOD", 0, "Period", ""},
+       {COMMAKEY, "COMMA", 0, "Comma", ""},
+       {QUOTEKEY, "QUOTE", 0, "Quote", ""},
+       {ACCENTGRAVEKEY, "ACCENT_GRAVE", 0, "Accentgrave", ""},
+       {MINUSKEY, "MINUS", 0, "Minus", ""},
+       {SLASHKEY, "SLASH", 0, "Slash", ""},
+       {BACKSLASHKEY, "BACK_SLASH", 0, "Backslash", ""},
+       {EQUALKEY, "EQUAL", 0, "Equal", ""},
+       {LEFTBRACKETKEY, "LEFT_BRACKET", 0, "Leftbracket", ""},
+       {RIGHTBRACKETKEY, "RIGHT_BRACKET", 0, "Rightbracket", ""},
+       {LEFTARROWKEY, "LEFT_ARROW", 0, "Left Arrow", ""},
+       {DOWNARROWKEY, "DOWN_ARROW", 0, "Down Arrow", ""},
+       {RIGHTARROWKEY, "RIGHT_ARROW", 0, "Right Arrow", ""},
+       {UPARROWKEY, "UP_ARROW", 0, "Up Arrow", ""},
+       {PAD2, "NUMPAD_2", 0, "Numpad 2", ""},
+       {PAD4, "NUMPAD_4", 0, "Numpad 4", ""},
+       {PAD6, "NUMPAD_6", 0, "Numpad 6", ""},
+       {PAD8, "NUMPAD_8", 0, "Numpad 8", ""},
+       {PAD1, "NUMPAD_1", 0, "Numpad 1", ""},
+       {PAD3, "NUMPAD_3", 0, "Numpad 3", ""},
+       {PAD5, "NUMPAD_5", 0, "Numpad 5", ""},
+       {PAD7, "NUMPAD_7", 0, "Numpad 7", ""},
+       {PAD9, "NUMPAD_9", 0, "Numpad 9", ""},
+       {PADPERIOD, "NUMPAD_PERIOD", 0, "Numpad .", ""},
+       {PADSLASHKEY, "NUMPAD_SLASH", 0, "Numpad /", ""},
+       {PADASTERKEY, "NUMPAD_ASTERIX", 0, "Numpad *", ""},
+       {PAD0, "NUMPAD_0", 0, "Numpad 0", ""},
+       {PADMINUS, "NUMPAD_MINUS", 0, "Numpad -", ""},
+       {PADENTER, "NUMPAD_ENTER", 0, "Numpad Enter", ""},
+       {PADPLUSKEY, "NUMPAD_PLUS", 0, "Numpad +", ""},
+       {F1KEY, "F1", 0, "F1", ""},
+       {F2KEY, "F2", 0, "F2", ""},
+       {F3KEY, "F3", 0, "F3", ""},
+       {F4KEY, "F4", 0, "F4", ""},
+       {F5KEY, "F5", 0, "F5", ""},
+       {F6KEY, "F6", 0, "F6", ""},
+       {F7KEY, "F7", 0, "F7", ""},
+       {F8KEY, "F8", 0, "F8", ""},
+       {F9KEY, "F9", 0, "F9", ""},
+       {F10KEY, "F10", 0, "F10", ""},
+       {F11KEY, "F11", 0, "F11", ""},
+       {F12KEY, "F12", 0, "F12", ""},
+       {PAUSEKEY, "PAUSE", 0, "Pause", ""},
+       {INSERTKEY, "INSERT", 0, "Insert", ""},
+       {HOMEKEY, "HOME", 0, "Home", ""},
+       {PAGEUPKEY, "PAGE_UP", 0, "Page Up", ""},
+       {PAGEDOWNKEY, "PAGE_DOWN", 0, "Page Down", ""},
+       {ENDKEY, "END", 0, "End", ""},
+       {0, NULL, 0, NULL, NULL}};      
 
 #ifdef RNA_RUNTIME
 
@@ -87,6 +201,20 @@ static PointerRNA rna_Operator_properties_get(PointerRNA *ptr)
        return rna_pointer_inherit_refine(ptr, &RNA_OperatorProperties, op->properties);
 }
 
+
+static int rna_Event_ascii_get(PointerRNA *ptr, char *value)
+{
+       wmEvent *event= (wmEvent*)ptr->id.data;
+       value[0]= event->ascii;
+       value[1]= '\0';
+}
+
+static int rna_Event_ascii_length(PointerRNA *ptr)
+{
+       wmEvent *event= (wmEvent*)ptr->id.data;
+       return (event->ascii)? 1 : 0;
+}
+
 #else
 
 static void rna_def_operator(BlenderRNA *brna)
@@ -146,7 +274,80 @@ static void rna_def_operator_filelist_element(BlenderRNA *brna)
        RNA_def_property_flag(prop, PROP_IDPROPERTY);
        RNA_def_property_ui_text(prop, "Name", "the name of a file or directory within a file list");
 }
+       
+static void rna_def_event(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+       
+       srna= RNA_def_struct(brna, "Event", NULL);
+       RNA_def_struct_ui_text(srna, "Event", "Window Manager Event");
+       RNA_def_struct_sdna(srna, "wmEvent");
+
+       /* strings */
+       prop= RNA_def_property(srna, "ascii", PROP_STRING, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_string_funcs(prop, "rna_Event_ascii_get", "rna_Event_ascii_length", NULL);
+       RNA_def_property_ui_text(prop, "ASCII", "Single ASCII character for this event.");
+
+
+       /* enums */
+       prop= RNA_def_property(srna, "value", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "val");
+       RNA_def_property_enum_items(prop, event_value_items);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Value",  "The type of event, only applies to some.");
+       
+       prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "type");
+       RNA_def_property_enum_items(prop, event_type_items);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Type",  "");
+
+
+       /* mouse */
+       prop= RNA_def_property(srna, "mouse_x", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "x");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Mouse X Position", "The window relative vertical location of the mouse.");
+       
+       prop= RNA_def_property(srna, "mouse_y", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "y");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Mouse Y Position", "The window relative horizontal location of the mouse.");
+       
+       prop= RNA_def_property(srna, "mouse_prev_x", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "prevx");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Mouse Previous X Position", "The window relative vertical location of the mouse.");
+       
+       prop= RNA_def_property(srna, "mouse_prev_y", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "prevy");
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Mouse Previous Y Position", "The window relative horizontal location of the mouse.");   
+
 
+       /* modifiers */
+       prop= RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "shift", 1);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Shift", "True when the shift key is held.");
+       
+       prop= RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 1);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Ctrl", "True when the shift key is held.");
+       
+       prop= RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "alt", 1);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Alt", "True when the shift key is held.");
+       
+       prop= RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "oskey", 1);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "OS Key", "True when the shift key is held.");
+}
 
 static void rna_def_windowmanager(BlenderRNA *brna)
 {
@@ -169,6 +370,7 @@ void RNA_def_wm(BlenderRNA *brna)
        rna_def_operator(brna);
        rna_def_operator_utils(brna);
        rna_def_operator_filelist_element(brna);
+       rna_def_event(brna);
        rna_def_windowmanager(brna);
 }
 
index f4fdd0c61940053d509efede2ac18d08a8f3d329..542de6bd9b84f4f653d83b48a655c331e6d7eac3 100644 (file)
 #define PYOP_ATTR_IDNAME               "__name__"      /* use pythons class name */
 #define PYOP_ATTR_DESCRIPTION  "__doc__"       /* use pythons docstring */
 
-static PyObject *pyop_dict_from_event(wmEvent *event)
-{
-       PyObject *dict= PyDict_New();
-       PyObject *item;
-       char *cstring, ascii[2];
-
-       /* type */
-       item= PyUnicode_FromString(WM_key_event_string(event->type));
-       PyDict_SetItemString(dict, "type", item);       Py_DECREF(item);
-
-       /* val */
-       switch(event->val) {
-       case KM_ANY:
-               cstring = "ANY";
-               break;
-       case KM_RELEASE:
-               cstring = "RELEASE";
-               break;
-       case KM_PRESS:
-               cstring = "PRESS";
-               break;
-       default:
-               cstring = "UNKNOWN";
-               break;
-       }
-
-       item= PyUnicode_FromString(cstring);
-       PyDict_SetItemString(dict, "val", item);        Py_DECREF(item);
-
-       /* x, y (mouse) */
-       item= PyLong_FromLong(event->x);
-       PyDict_SetItemString(dict, "x", item);          Py_DECREF(item);
-
-       item= PyLong_FromLong(event->y);
-       PyDict_SetItemString(dict, "y", item);          Py_DECREF(item);
-
-       item= PyLong_FromLong(event->prevx);
-       PyDict_SetItemString(dict, "prevx", item);      Py_DECREF(item);
-
-       item= PyLong_FromLong(event->prevy);
-       PyDict_SetItemString(dict, "prevy", item);      Py_DECREF(item);
-
-       /* ascii */
-       ascii[0]= event->ascii;
-       ascii[1]= '\0';
-       item= PyUnicode_FromString(ascii);
-       PyDict_SetItemString(dict, "ascii", item);      Py_DECREF(item);
-
-       /* modifier keys */
-       item= PyLong_FromLong(event->shift);
-       PyDict_SetItemString(dict, "shift", item);      Py_DECREF(item);
-
-       item= PyLong_FromLong(event->ctrl);
-       PyDict_SetItemString(dict, "ctrl", item);       Py_DECREF(item);
-
-       item= PyLong_FromLong(event->alt);
-       PyDict_SetItemString(dict, "alt", item);        Py_DECREF(item);
-
-       item= PyLong_FromLong(event->oskey);
-       PyDict_SetItemString(dict, "oskey", item);      Py_DECREF(item);
-
-
-
-       /* modifier */
-#if 0
-       item= PyTuple_New(0);
-       if(event->keymodifier & KM_SHIFT) {
-               _PyTuple_Resize(&item, size+1);
-               PyTuple_SET_ITEM(item, size, _PyUnicode_AsString("SHIFT"));
-               size++;
-       }
-       if(event->keymodifier & KM_CTRL) {
-               _PyTuple_Resize(&item, size+1);
-               PyTuple_SET_ITEM(item, size, _PyUnicode_AsString("CTRL"));
-               size++;
-       }
-       if(event->keymodifier & KM_ALT) {
-               _PyTuple_Resize(&item, size+1);
-               PyTuple_SET_ITEM(item, size, _PyUnicode_AsString("ALT"));
-               size++;
-       }
-       if(event->keymodifier & KM_OSKEY) {
-               _PyTuple_Resize(&item, size+1);
-               PyTuple_SET_ITEM(item, size, _PyUnicode_AsString("OSKEY"));
-               size++;
-       }
-       PyDict_SetItemString(dict, "keymodifier", item);        Py_DECREF(item);
-#endif
-
-       return dict;
-}
-
 static struct BPY_flag_def pyop_ret_flags[] = {
        {"RUNNING_MODAL", OPERATOR_RUNNING_MODAL},
        {"CANCELLED", OPERATOR_CANCELLED},
@@ -180,6 +88,7 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
        int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED);
        PointerRNA ptr_context;
        PointerRNA ptr_operator;
+       PointerRNA ptr_event;
        PyObject *py_operator;
 
        PyGILState_STATE gilstate = PyGILState_Ensure();
@@ -230,11 +139,13 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve
                if (mode==PYOP_INVOKE) {
                        item= PyObject_GetAttrString(py_class, "invoke");
                        args = PyTuple_New(3);
+                       
+                       RNA_pointer_create(NULL, &RNA_Event, event, &ptr_event);
 
                        // PyTuple_SET_ITEM "steals" object reference, it is
                        // an object passed shouldn't be DECREF'ed
                        PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
-                       PyTuple_SET_ITEM(args, 2, pyop_dict_from_event(event));
+                       PyTuple_SET_ITEM(args, 2, pyrna_struct_CreatePyObject(&ptr_event));
                }
                else if (mode==PYOP_EXEC) {
                        item= PyObject_GetAttrString(py_class, "execute");
index 739cfbcc1ac7fc94298821ebd7869db5e6ef57d8..9b987cdfa510379679a2e70f471ef88fc91a69b3 100644 (file)
@@ -58,37 +58,6 @@ enum {
        WM_OP_EXEC_SCREEN
 };
 
-/* ************** wmEvent ************************ */
-
-/* each event should have full modifier state */
-/* event comes from eventmanager and from keymap */
-typedef struct wmEvent {
-       struct wmEvent *next, *prev;
-       
-       short type;                     /* event code itself (short, is also in keymap) */
-       short val;                      /* press, release, scrollvalue */
-       short x, y;                     /* mouse pointer position, screen coord */
-       short mval[2];          /* region mouse position, name convention pre 2.5 :) */
-       short prevx, prevy;     /* previous mouse pointer position */
-       short unicode;          /* future, ghost? */
-       char ascii;                     /* from ghost */
-       char pad;
-       
-       /* modifier states */
-       short shift, ctrl, alt, oskey;  /* oskey is apple or windowskey, value denotes order of pressed */
-       short keymodifier;                              /* rawkey modifier */
-       
-       /* keymap item, set by handler (weak?) */
-       const char *keymap_idname;
-       
-       /* custom data */
-       short custom;   /* custom data type, stylus, 6dof, see wm_event_types.h */
-       void *customdata;       /* ascii, unicode, mouse coords, angles, vectors, dragdrop info */
-       short customdatafree;
-       
-} wmEvent;
-
-
 /* ************** wmKeyMap ************************ */
 
 /* modifier */
index 7528321c7c5baeb05dace1037969cfe7254cdbe0..85028e3ea1a5a33f1f8458855557b94498aab028 100644 (file)
@@ -44,6 +44,7 @@
 
 #include "RNA_access.h"
 #include "RNA_types.h"
+#include "RNA_enum_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -155,313 +156,9 @@ ListBase *WM_keymap_listbase(wmWindowManager *wm, const char *nameid, int spacei
 
 char *WM_key_event_string(short type)
 {
-       /* not returned: CAPSLOCKKEY, UNKNOWNKEY, COMMANDKEY, GRLESSKEY */
-
-       switch(type) {
-       case AKEY:
-               return "A";
-               break;
-       case BKEY:
-               return "B";
-               break;
-       case CKEY:
-               return "C";
-               break;
-       case DKEY:
-               return "D";
-               break;
-       case EKEY:
-               return "E";
-               break;
-       case FKEY:
-               return "F";
-               break;
-       case GKEY:
-               return "G";
-               break;
-       case HKEY:
-               return "H";
-               break;
-       case IKEY:
-               return "I";
-               break;
-       case JKEY:
-               return "J";
-               break;
-       case KKEY:
-               return "K";
-               break;
-       case LKEY:
-               return "L";
-               break;
-       case MKEY:
-               return "M";
-               break;
-       case NKEY:
-               return "N";
-               break;
-       case OKEY:
-               return "O";
-               break;
-       case PKEY:
-               return "P";
-               break;
-       case QKEY:
-               return "Q";
-               break;
-       case RKEY:
-               return "R";
-               break;
-       case SKEY:
-               return "S";
-               break;
-       case TKEY:
-               return "T";
-               break;
-       case UKEY:
-               return "U";
-               break;
-       case VKEY:
-               return "V";
-               break;
-       case WKEY:
-               return "W";
-               break;
-       case XKEY:
-               return "X";
-               break;
-       case YKEY:
-               return "Y";
-               break;
-       case ZKEY:
-               return "Z";
-               break;
-
-       case ZEROKEY:
-               return "Zero";
-               break;
-       case ONEKEY:
-               return "One";
-               break;
-       case TWOKEY:
-               return "Two";
-               break;
-       case THREEKEY:
-               return "Three";
-               break;
-       case FOURKEY:
-               return "Four";
-               break;
-       case FIVEKEY:
-               return "Five";
-               break;
-       case SIXKEY:
-               return "Six";
-               break;
-       case SEVENKEY:
-               return "Seven";
-               break;
-       case EIGHTKEY:
-               return "Eight";
-               break;
-       case NINEKEY:
-               return "Nine";
-               break;
-
-       case LEFTCTRLKEY:
-               return "Leftctrl";
-               break;
-       case LEFTALTKEY:
-               return "Leftalt";
-               break;
-       case RIGHTALTKEY:
-               return "Rightalt";
-               break;
-       case RIGHTCTRLKEY:
-               return "Rightctrl";
-               break;
-       case RIGHTSHIFTKEY:
-               return "Rightshift";
-               break;
-       case LEFTSHIFTKEY:
-               return "Leftshift";
-               break;
-
-       case ESCKEY:
-               return "Esc";
-               break;
-       case TABKEY:
-               return "Tab";
-               break;
-       case RETKEY:
-               return "Ret";
-               break;
-       case SPACEKEY:
-               return "Space";
-               break;
-       case LINEFEEDKEY:
-               return "Linefeed";
-               break;
-       case BACKSPACEKEY:
-               return "Backspace";
-               break;
-       case DELKEY:
-               return "Del";
-               break;
-       case SEMICOLONKEY:
-               return "Semicolon";
-               break;
-       case PERIODKEY:
-               return "Period";
-               break;
-       case COMMAKEY:
-               return "Comma";
-               break;
-       case QUOTEKEY:
-               return "Quote";
-               break;
-       case ACCENTGRAVEKEY:
-               return "Accentgrave";
-               break;
-       case MINUSKEY:
-               return "Minus";
-               break;
-       case SLASHKEY:
-               return "Slash";
-               break;
-       case BACKSLASHKEY:
-               return "Backslash";
-               break;
-       case EQUALKEY:
-               return "Equal";
-               break;
-       case LEFTBRACKETKEY:
-               return "Leftbracket";
-               break;
-       case RIGHTBRACKETKEY:
-               return "Rightbracket";
-               break;
-
-       case LEFTARROWKEY:
-               return "Leftarrow";
-               break;
-       case DOWNARROWKEY:
-               return "Downarrow";
-               break;
-       case RIGHTARROWKEY:
-               return "Rightarrow";
-               break;
-       case UPARROWKEY:
-               return "Uparrow";
-               break;
-
-       case PAD2:
-               return "Numpad 2";
-               break;
-       case PAD4:
-               return "Numpad 4";
-               break;
-       case PAD6:
-               return "Numpad 6";
-               break;
-       case PAD8:
-               return "Numpad 8";
-               break;
-       case PAD1:
-               return "Numpad 1";
-               break;
-       case PAD3:
-               return "Numpad 3";
-               break;
-       case PAD5:
-               return "Numpad 5";
-               break;
-       case PAD7:
-               return "Numpad 7";
-               break;
-       case PAD9:
-               return "Numpad 9";
-               break;
-
-       case PADPERIOD:
-               return "Numpad .";
-               break;
-       case PADSLASHKEY:
-               return "Numpad /";
-               break;
-       case PADASTERKEY:
-               return "Numpad *";
-               break;
-
-       case PAD0:
-               return "Numpad 0";
-               break;
-       case PADMINUS:
-               return "Numpad -";
-               break;
-       case PADENTER:
-               return "Numpad Enter";
-               break;
-       case PADPLUSKEY:
-               return "Numpad +";
-               break;
-
-       case F1KEY:
-               return "F1";
-               break;
-       case F2KEY:
-               return "F2";
-               break;
-       case F3KEY:
-               return "F3";
-               break;
-       case F4KEY:
-               return "F4";
-               break;
-       case F5KEY:
-               return "F5";
-               break;
-       case F6KEY:
-               return "F6";
-               break;
-       case F7KEY:
-               return "F7";
-               break;
-       case F8KEY:
-               return "F8";
-               break;
-       case F9KEY:
-               return "F9";
-               break;
-       case F10KEY:
-               return "F10";
-               break;
-       case F11KEY:
-               return "F11";
-               break;
-       case F12KEY:
-               return "F12";
-               break;
-
-       case PAUSEKEY:
-               return "Pause";
-               break;
-       case INSERTKEY:
-               return "Insert";
-               break;
-       case HOMEKEY:
-               return "Home";
-               break;
-       case PAGEUPKEY:
-               return "Pageup";
-               break;
-       case PAGEDOWNKEY:
-               return "Pagedown";
-               break;
-       case ENDKEY:
-               return "End";
-               break;
-       }
+       const char *name= NULL;
+       if(RNA_enum_name(event_type_items, (int)type, &name))
+               return name;
        
        return "";
 }