pybank r82 - in trunk: bank overrides



Author: walters
Date: Fri Oct 24 14:11:36 2008
New Revision: 82
URL: http://svn.gnome.org/viewvc/pybank?rev=82&view=rev

Log:
Make-go pybank again.

Unify invocation a bit more.  Method and Function both subclass
Callable.

Stub out TYPE_TAG_ARRAY handling, only allow None.



Modified:
   trunk/bank/bank-argument.c
   trunk/bank/bank-info.c
   trunk/bank/btypes.py
   trunk/overrides/Gtk.py

Modified: trunk/bank/bank-argument.c
==============================================================================
--- trunk/bank/bank-argument.c	(original)
+++ trunk/bank/bank-argument.c	Fri Oct 24 14:11:36 2008
@@ -48,6 +48,10 @@
 	else
 	    arg.v_pointer = PyCObject_AsVoidPtr(object);
 	break;
+    case GI_TYPE_TAG_ARRAY:
+	g_assert (object == Py_None);
+	arg.v_pointer = NULL;
+	break;
     case GI_TYPE_TAG_ERROR:
         /* Allow NULL GError, otherwise fall through */
         if (object == Py_None) {
@@ -96,6 +100,10 @@
     case GI_TYPE_TAG_INTERFACE:
 	obj = PyCObject_FromVoidPtr(arg->v_pointer, NULL);
 	break;
+    case GI_TYPE_TAG_ARRAY:
+	obj = Py_None;
+	Py_INCREF(Py_None);
+	break;
     default:
 	g_print("<GArg->PyO> GITypeTag %s is unhandled\n",
 		g_type_tag_to_string(type_tag));

Modified: trunk/bank/bank-info.c
==============================================================================
--- trunk/bank/bank-info.c	(original)
+++ trunk/bank/bank-info.c	Fri Oct 24 14:11:36 2008
@@ -346,10 +346,16 @@
     for (i = 0; i < g_callable_info_get_n_args((GICallableInfo*)self->info); i++) {
 	arg_info = g_callable_info_get_arg((GICallableInfo*)self->info, i);
 	direction = g_arg_info_get_direction(arg_info);
-	if (direction == GI_DIRECTION_IN)
+	if (direction == GI_DIRECTION_IN) {
 	    n_in_args++;
-	if (direction == GI_DIRECTION_OUT)
+	} else if (direction == GI_DIRECTION_OUT) {
 	    n_out_args++;
+	} else if (direction == GI_DIRECTION_INOUT) {
+	    /* FIXME - just map these as in args temporarily, we need to
+	     * get gtk_init_check etc. working */
+	    n_in_args++;
+	    n_out_args++;
+	}
 	g_base_info_unref((GIBaseInfo*)arg_info);
     }
 

Modified: trunk/bank/btypes.py
==============================================================================
--- trunk/bank/btypes.py	(original)
+++ trunk/bank/btypes.py	Fri Oct 24 14:11:36 2008
@@ -21,7 +21,7 @@
 
 from .repository import repository
 
-class Function(object):
+class Callable(object):
     def __init__(self, info):
         self.info = info
 
@@ -36,10 +36,12 @@
                      repo.TYPE_TAG_UINT8):
             if not isinstance(value, int):
                 raise TypeError("%s must be int, not %s" % (name, type(value).__name__))
-
         elif tag == repo.TYPE_TAG_INTERFACE:
             # TODO
             pass
+        elif tag == repo.TYPE_TAG_ARRAY:
+            if value is not None:
+                raise TypeError("Must pass None for arrays currently")
         elif tag == repo.TYPE_TAG_ERROR:
             # TODO
             pass
@@ -49,57 +51,10 @@
     def __call__(self, *args, **kwargs):
         infoArgs = list(self.info.getArgs())
         totalInArgs = len(args) + len(kwargs)
-        requiredArgs = self.info.isMethod() and 1 or 0
-        for arg in infoArgs:
-            if arg.getDirection() == repo.DIRECTION_IN:
-                requiredArgs += 1
-
-        if totalInArgs != requiredArgs:
-            raise TypeError('%r requires %d arguments' % (
-                self, requiredArgs))
-
-        inArgs = []
-        for i, value in enumerate(args):
-            infoArg = infoArgs[i]
-            argType = infoArg.getType()
-            name = infoArg.getName()
-            self.type_check(name, value, argType)
-
-            value = getattr(value, '_object', value)
-            inArgs.append(value)
-
-        retval = self.info.invoke(*inArgs)
-        return retval
-
-    def __repr__(self):
-        return "<function %s>" % (self.info.getName(),)
-
-
-class Method(Function):
-    def __init__(self, info, className, static=False):
-        Function.__init__(self, info)
-        self.object = None
-        self.className = className
-        self.static = static
-        self.__name__ = info.getName()
-        self.__module__ = info.getNamespace()
-
-    def newType(self, retval, type_info=None):
-        if type_info == None:
-            type_info = self.info.getReturnType()
-
-        info = type_info.getInterface()
-        klass = getClass(info)
-        obj = klass.__new__(klass)
-        obj._object = retval
-        return obj
-
-    def __call__(self, *args, **kwargs):
-        infoArgs = list(self.info.getArgs())
-        totalInArgs = len(args) + len(kwargs)
         requiredArgs = 0
         for arg in infoArgs:
-            if arg.getDirection() == repo.DIRECTION_IN:
+            direct = arg.getDirection()
+            if direct in [repo.DIRECTION_IN, repo.DIRECTION_INOUT]:
                 requiredArgs += 1
 
         obj = None
@@ -113,15 +68,14 @@
                 obj = args[0]
 
         if totalInArgs != requiredArgs:
-            raise TypeError('%s requires %d arguments' % (
-                self.__name__, requiredArgs))
+            raise TypeError('%r requires %d arguments' % (
+                self, requiredArgs))
 
         inArgs = []
-        offset = is_method and 1 or 0
         for i, value in enumerate(args):
-            # We'll type check later
-            if not (is_method and i == 0):
-                infoArg = infoArgs[i-offset]
+            if not is_method or i > 0:
+                off = is_method and 1 or 0
+                infoArg = infoArgs[i-off]
                 argType = infoArg.getType()
                 name = infoArg.getName()
                 self.type_check(name, value, argType)
@@ -153,6 +107,36 @@
 
         return retval
 
+
+class Function(Callable):
+    def __init__(self, info):
+        Callable.__init__(self, info)
+        self.info = info
+        self.static = True
+
+    def __repr__(self):
+        return "<function %s>" % (self.info.getName(),)
+
+
+class Method(Callable):
+    def __init__(self, info, className, static=False):
+        Callable.__init__(self, info)
+        self.object = None
+        self.className = className
+        self.static = static
+        self.__name__ = info.getName()
+        self.__module__ = info.getNamespace()
+
+    def newType(self, retval, type_info=None):
+        if type_info == None:
+            type_info = self.info.getReturnType()
+
+        info = type_info.getInterface()
+        klass = getClass(info)
+        obj = klass.__new__(klass)
+        obj._object = retval
+        return obj
+
     def __get__(self, instance, type):
         if instance is None:
             return self

Modified: trunk/overrides/Gtk.py
==============================================================================
--- trunk/overrides/Gtk.py	(original)
+++ trunk/overrides/Gtk.py	Fri Oct 24 14:11:36 2008
@@ -2,7 +2,7 @@
 
 class GtkModule(DynamicModule):
     def created(self):
-        self.init_check(0, 0)
+        self.init_check(0, None)
         #if self.init_check(len(sys.argv), sys.argv):
         #    raise RuntimeError("could not open display")
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]