Author: mattip <[email protected]>
Branch: demo-cleanup
Changeset: r2436:a34f6189d2b6
Date: 2015-11-24 20:04 +0200
http://bitbucket.org/cffi/cffi/changeset/a34f6189d2b6/
Log: split the demo into two files
diff --git a/demo/xclient.py b/demo/xclient.py
--- a/demo/xclient.py
+++ b/demo/xclient.py
@@ -1,35 +1,14 @@
-import sys
+import sys, os
+
+# If the build script was run immediately before this script, the cffi module
+# ends up in the current directory. Make sure we can import it.
sys.path.append('.')
+
try:
- import _xclient
+ from _xclient import ffi, lib
except ImportError:
- from cffi import FFI
- _ffi = FFI()
- _ffi.cdef("""
-
- typedef ... Display;
- typedef struct { ...; } Window;
-
- typedef struct { int type; ...; } XEvent;
-
- Display *XOpenDisplay(char *display_name);
- Window DefaultRootWindow(Display *display);
- int XMapRaised(Display *display, Window w);
- Window XCreateSimpleWindow(Display *display, Window parent, int x, int y,
- unsigned int width, unsigned int height,
- unsigned int border_width, unsigned long border,
- unsigned long background);
- int XNextEvent(Display *display, XEvent *event_return);
- """)
-
- _ffi.set_source('_xclient', """
- #include <X11/Xlib.h>
- """, libraries=['X11'])
- _ffi.compile()
- import _xclient
-
-ffi = _xclient.ffi
-lib = _xclient.lib
+ print 'run %s_build first, then make sure the shared object is on
sys.path' % os.path.splitext(__file__)[0]
+ sys.exit(-1)
class XError(Exception):
pass
diff --git a/demo/xclient_build.py b/demo/xclient_build.py
new file mode 100644
--- /dev/null
+++ b/demo/xclient_build.py
@@ -0,0 +1,24 @@
+from cffi import FFI
+_ffi = FFI()
+_ffi.cdef("""
+
+typedef ... Display;
+typedef struct { ...; } Window;
+
+typedef struct { int type; ...; } XEvent;
+
+Display *XOpenDisplay(char *display_name);
+Window DefaultRootWindow(Display *display);
+int XMapRaised(Display *display, Window w);
+Window XCreateSimpleWindow(Display *display, Window parent, int x, int y,
+ unsigned int width, unsigned int height,
+ unsigned int border_width, unsigned long border,
+ unsigned long background);
+int XNextEvent(Display *display, XEvent *event_return);
+""")
+
+_ffi.set_source('_xclient', """
+ #include <X11/Xlib.h>
+""", libraries=['X11'])
+_ffi.compile()
+
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit