Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 339ee5f

Browse files
committed
gtkagg fixes
svn path=/trunk/matplotlib/; revision=318
1 parent 1bfe787 commit 339ee5f

5 files changed

Lines changed: 65 additions & 67 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
New entries should be added at the top
22

3+
34
2004-05-26 Added Gary's errorbar stuff and made some fixes for length
45
one plots and constant data plots - JDH
56

MANIFEST

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ examples/README
174174
examples/__init__.py
175175
examples/alignment_test.py
176176
examples/anim.py
177+
examples/anim_tk.py
177178
examples/arctest.py
178179
examples/axes_demo.py
179180
examples/axes_props.py
@@ -398,6 +399,7 @@ matplotlib/backends/tkagg.py
398399
src/_backend_agg.cpp
399400
src/_backend_agg.h
400401
src/_gtkagg.cpp
402+
src/_gtkaggold.cpp
401403
src/_gtkgd.c
402404
src/_image.cpp
403405
src/_image.h

TODO

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@
394394

395395
-- DONE y tick outside frame?
396396

397-
-- incorporate gary's errorbar
397+
-- DONE incorporate gary's errorbar
398398

399-
-- bug in -45 newline text
399+
-- bug in -45 newline text
400+
401+
-- write to stream in Agg
402+
403+
-- gtkagg bug in win98

setupext.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,12 @@ def build_ft2font(ext_modules, packages):
255255
def build_gtkagg(ext_modules, packages):
256256
global BUILT_GTKAGG
257257
if BUILT_GTKAGG: return # only build it if you you haven't already
258+
deps = ['src/_gtkagg.cpp']
259+
deps.extend(glob.glob('CXX/*.cxx'))
260+
deps.extend(glob.glob('CXX/*.c'))
261+
258262
module = Extension('matplotlib.backends._gtkagg',
259-
['src/_gtkagg.cpp'],
263+
deps,
260264
)
261265

262266

src/_gtkagg.cpp

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,74 @@
1-
/* Helper functions for converting an agg image buffer to a gtk drawable
2-
efficiently
3-
*/
4-
#include <Python.h>
5-
#include <pygobject.h>
6-
#include <pygtk/pygtk.h>
71
#include <cstring>
82
#include <cerrno>
93
#include <cstdio>
4+
#include <iostream>
5+
#include <cmath>
6+
#include <utility>
107

11-
#include "_backend_agg.h"
8+
#include <pygobject.h>
9+
#include <pygtk/pygtk.h>
1210

13-
static PyObject *ErrorObject;
14-
static PyTypeObject *PyGObject_Type=NULL;
11+
#include "_backend_agg.h"
1512

13+
// the extension module
14+
class _gtkagg_module : public Py::ExtensionModule<_gtkagg_module>
15+
{
16+
public:
17+
_gtkagg_module()
18+
: Py::ExtensionModule<_gtkagg_module>( "_gtkagg" )
19+
{
20+
add_varargs_method("agg_to_gtk_drawable",
21+
&_gtkagg_module::agg_to_gtk_drawable,
22+
"Draw to a gtk drawable from a agg buffer.");
23+
initialize( "The _gtkagg module" );
24+
}
25+
26+
virtual ~_gtkagg_module() {}
27+
28+
private:
29+
30+
Py::Object agg_to_gtk_drawable(const Py::Tuple &args) {
1631

17-
static PyObject *
18-
_agg_to_gtk_drawable(PyObject *self, PyObject *args) {
32+
args.verify_length(2);
1933

20-
PyGObject *py_drawable = NULL;
21-
GdkDrawable *drawable = NULL;
22-
GdkGC* gc = NULL;
2334

24-
PyObject* aggo;
25-
35+
PyGObject *py_drawable = (PyGObject *)(args[0].ptr());
36+
RendererAgg* aggRenderer = static_cast<RendererAgg*>(args[1].ptr());
2637

27-
if (!PyArg_ParseTuple(args, "O!O", PyGObject_Type,
28-
&py_drawable, &aggo))
29-
return NULL;
38+
39+
GdkDrawable *drawable = GDK_DRAWABLE(py_drawable->obj);
40+
GdkGC* gc = gdk_gc_new(drawable);
3041

42+
unsigned int width = aggRenderer->get_width();
43+
unsigned int height = aggRenderer->get_height();
3144

32-
RendererAgg* aggRenderer = (RendererAgg*)aggo;
45+
gdk_draw_rgb_32_image(drawable, gc, 0, 0,
46+
width,
47+
height,
48+
GDK_RGB_DITHER_NORMAL,
49+
aggRenderer->pixBuffer,
50+
width*4);
3351

34-
drawable = GDK_DRAWABLE(py_drawable->obj);
35-
gc = gdk_gc_new(drawable);
52+
return Py::Object();
3653

37-
unsigned int width = aggRenderer->get_width();
38-
unsigned int height = aggRenderer->get_height();
54+
}
55+
};
3956

40-
gdk_draw_rgb_32_image(drawable, gc, 0, 0,
41-
width,
42-
height,
43-
GDK_RGB_DITHER_NORMAL,
44-
aggRenderer->pixBuffer,
45-
width*4);
46-
47-
Py_INCREF(Py_None);
48-
return Py_None;
49-
}
50-
5157

58+
extern "C"
59+
DL_EXPORT(void)
60+
init_gtkagg(void)
61+
{
62+
init_pygobject();
63+
init_pygtk();
64+
//suppress unused warning by creating in two lines
65+
static _gtkagg_module* _gtkagg = NULL;
66+
_gtkagg = new _gtkagg_module;
5267

68+
};
5369

5470

55-
static struct PyMethodDef _gtkagg_methods[] = {
56-
{"agg_to_gtk_drawable", (PyCFunction)_agg_to_gtk_drawable, METH_VARARGS,
57-
"Draw to a gtk drawable from a agg buffer."},
58-
{NULL, NULL} /* sentinel */
59-
};
6071

6172

62-
extern "C"
63-
DL_EXPORT(void) init_gtkagg(void)
64-
{
65-
PyObject *module, *d;
66-
6773

6874

69-
init_pygobject();
70-
init_pygtk();
71-
/* Create the module and add the functions */
72-
Py_InitModule("_gtkagg", _gtkagg_methods);
73-
module = PyImport_ImportModule("gobject");
74-
if (module) {
75-
PyGObject_Type =
76-
(PyTypeObject*)PyObject_GetAttrString(module, "GObject");
77-
Py_DECREF(module);
78-
}
79-
/* Add some symbolic constants to the module */
80-
d = PyModule_GetDict(module);
81-
ErrorObject = PyString_FromString("_gtkagg.error");
82-
PyDict_SetItemString(d, "error", ErrorObject);
83-
84-
/* Check for errors */
85-
if (PyErr_Occurred())
86-
Py_FatalError("can't initialize module _gtkagg");
87-
}

0 commit comments

Comments
 (0)