[giv] Fixed compilation errors and added a python example for remote controlling giv.



commit 490b31547b0b3e7b7544088f867ccbe15c01536c
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Sun Dec 25 23:37:34 2011 +0200

    Fixed compilation errors and added a python example for remote controlling giv.

 python/giv-client.py |   26 ++++++++++++++++++++++++++
 src/plugins/npy.c    |   13 ++++++-------
 src/plugins/tiff.c   |    1 -
 3 files changed, 32 insertions(+), 8 deletions(-)
---
diff --git a/python/giv-client.py b/python/giv-client.py
new file mode 100644
index 0000000..2d55198
--- /dev/null
+++ b/python/giv-client.py
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+"""
+An example of how to create an external jsonrpc client for controlling
+giv.
+"""
+
+import httplib
+import random
+
+conn = httplib.HTTPConnection('localhost:8222')
+headers = {"Content-type": "application/x-www-form-urlencoded",
+           "Accept": "text/plain",
+           }
+example_dir = "/home/dov/github/giv/examples/"
+#example_dir = "c:/progra~1/giv/examples"
+
+for i in range(10):
+  request = ('{"jsonrpc": "2.0", '
+             '"method": "load_file", '
+             '"params": [\"'+example_dir+'/%s"], '
+             '"id": %d}'%(['lena.pgm','maja.pgm'][i%2],
+                          random.randint(1,100)))
+  
+  conn.request("POST", url="", body= request, headers=headers)
+  response = conn.getresponse()
+  print response.read()
diff --git a/src/plugins/npy.c b/src/plugins/npy.c
index 8dd6967..bff1e68 100644
--- a/src/plugins/npy.c
+++ b/src/plugins/npy.c
@@ -9,7 +9,6 @@
 #include <stdlib.h>
 #include "../givimage.h"
 #include "../givplugin.h"
-#include "../givregex.h"
 #include <glib.h>
 #include <math.h>
 
@@ -52,15 +51,15 @@ GivImage *giv_plugin_load_file(const char *filename,
     
     // Use regex to parse the header. Should update this to allow
     // user attributes.
-    GivRegex *regex = g_regex_new ("^\\{\\s*"
-                                   "'descr':\\s*\\'(.*?)\\'\\s*,\\s*"
-                                   "'fortran_order':\\s*(\\w+)\\s*,\\s*"
-                                   "'shape':\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\),?\\s*"
-                                   "\\}", 0, 0, error);
+    GRegex *regex = g_regex_new ("^\\{\\s*"
+                                 "'descr':\\s*\\'(.*?)\\'\\s*,\\s*"
+                                 "'fortran_order':\\s*(\\w+)\\s*,\\s*"
+                                 "'shape':\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\),?\\s*"
+                                 "\\}", 0, 0, error);
     if (*error) 
         return NULL;
 
-    GivMatchInfo *match_info = NULL;
+    GMatchInfo *match_info = NULL;
     gboolean is_match = g_regex_match_full(regex,
                                            npy_string+10,
                                            header_len,
diff --git a/src/plugins/tiff.c b/src/plugins/tiff.c
index 5cc2eba..f2a0c7c 100644
--- a/src/plugins/tiff.c
+++ b/src/plugins/tiff.c
@@ -9,7 +9,6 @@
 #include <stdlib.h>
 #include "../givimage.h"
 #include "../givplugin.h"
-#include "../givregex.h"
 #include <glib.h>
 #include <math.h>
 #include "tiffio.h"



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