diff options
author | Hans Breuer <hans@breuer.org> | 2002-04-21 20:21:27 +0000 |
---|---|---|
committer | Hans Breuer <hans@src.gnome.org> | 2002-04-21 20:21:27 +0000 |
commit | 1067be1cc6340705ede7131b5f26ae28daeaea75 (patch) | |
tree | 6121c81d1c9fffece4db2d23a03c1d92b6ef9da3 | |
parent | 51f2bcf9332693198db10c92eda16051b8e7d757 (diff) | |
download | pygtk-1067be1cc6340705ede7131b5f26ae28daeaea75.tar.gz |
added parameter --errorfilename to allow redirection of stderr even with
2002-04-21 Hans Breuer <hans@breuer.org>
* codegen/codegen.py : added parameter --errorfilename
to allow redirection of stderr even with clumsy windoze
shell
* codegen/override.py : extended to allow 'sys.platform'
specific ignores
* examples/pygtk-demo/demos/colorsel.py : use
color = gtk.gdk.color_parse("blue")
to get the initial color
* examples/pygtk-demo/demos/draw.py : (new file)
demonstrating some simple drawing operations. It is
using the gtk.GC interface additions below.
* gtk/gdk.override : implement GdkGC.tp_getattr,
GdkGC.tp_setattr and gdk_gc_set_dashes (ported from #if 0'ed
code in gtk/gtk-types.c (should be removed there ?)
* gtk/gtk.override : ignore-win32 GTK_TYPE_PLUG
GTK_TYPE_SOCKET gtk_socket_new (the TYPE ignores do not work yet)
* config.h.win32 makefile.msc pygtk/makefile.msc :
new files to build pygtk on windoze using the established
glib/build/win32 infrastructure
* pygtk/gtk/gtk-fake-win32.c : (new file) implementing
gtk_plug_get_type() and gtk_socket_get_type(). It could
vanish if codegen/codegen.py has learned something like
'ignore-class-$(sys.platform) or my GtkPlug/GtkSocket
patch gets accepted with Gtk.
* gtk/gtkmodule.c : added a g_assert() to ensure importing
pygobject did work.
-rw-r--r-- | ChangeLog | 37 | ||||
-rw-r--r-- | codegen/codegen.py | 7 | ||||
-rw-r--r-- | codegen/override.py | 4 | ||||
-rw-r--r-- | config.h.win32 | 4 | ||||
-rw-r--r-- | examples/pygtk-demo/demos/colorsel.py | 9 | ||||
-rw-r--r-- | gtk/gdk.override | 173 | ||||
-rw-r--r-- | gtk/gtk-fake-win32.c | 26 | ||||
-rw-r--r-- | gtk/gtk.override | 6 | ||||
-rw-r--r-- | gtk/gtkmodule.c | 1 | ||||
-rw-r--r-- | gtk/makefile.msc | 93 | ||||
-rw-r--r-- | makefile.msc | 104 |
11 files changed, 453 insertions, 11 deletions
@@ -1,3 +1,40 @@ +2002-04-21 Hans Breuer <hans@breuer.org> + + * codegen/codegen.py : added parameter --errorfilename + to allow redirection of stderr even with clumsy windoze + shell + + * codegen/override.py : extended to allow 'sys.platform' + specific ignores + + * examples/pygtk-demo/demos/colorsel.py : use + color = gtk.gdk.color_parse("blue") + to get the initial color + + * examples/pygtk-demo/demos/draw.py : (new file) + demonstrating some simple drawing operations. It is + using the gtk.GC interface additions below. + + * gtk/gdk.override : implement GdkGC.tp_getattr, + GdkGC.tp_setattr and gdk_gc_set_dashes (ported from #if 0'ed + code in gtk/gtk-types.c (should be removed there ?) + + * gtk/gtk.override : ignore-win32 GTK_TYPE_PLUG + GTK_TYPE_SOCKET gtk_socket_new (the TYPE ignores do not work yet) + + * config.h.win32 makefile.msc pygtk/makefile.msc : + new files to build pygtk on windoze using the established + glib/build/win32 infrastructure + + * pygtk/gtk/gtk-fake-win32.c : (new file) implementing + gtk_plug_get_type() and gtk_socket_get_type(). It could + vanish if codegen/codegen.py has learned something like + 'ignore-class-$(sys.platform) or my GtkPlug/GtkSocket + patch gets accepted with Gtk. + + * gtk/gtkmodule.c : added a g_assert() to ensure importing + pygobject did work. + 2002-04-21 James Henstridge <james@daa.com.au> * gtk/gtk.override (_wrap_gtk_drag_dest_find_target): implement. diff --git a/codegen/codegen.py b/codegen/codegen.py index 24def4ff..cc4fe10d 100644 --- a/codegen/codegen.py +++ b/codegen/codegen.py @@ -734,9 +734,10 @@ def main(): o = override.Overrides() prefix = 'pygtk' outfilename = None + errorfilename = None opts, args = getopt.getopt(sys.argv[1:], "o:p:r:t:", ["override=", "prefix=", "register=", "outfilename=", - "load-types="]) + "load-types=", "errorfilename="]) for opt, arg in opts: if opt in ('-o', '--override'): o = override.Overrides(arg) @@ -749,6 +750,8 @@ def main(): del p elif opt == '--outfilename': outfilename = arg + elif opt == '--errorfilename': + errorfilename = arg elif opt in ('-t', '--load-types'): globals = {} execfile(arg, globals) @@ -756,6 +759,8 @@ def main(): sys.stderr.write( 'usage: codegen.py [-o overridesfile] [-p prefix] defsfile\n') sys.exit(1) + if errorfilename: + sys.stderr = open(errorfilename, "w") p = defsparser.DefsParser(args[0]) if not outfilename: outfilename = os.path.splitext(args[0])[0] + '.c' diff --git a/codegen/override.py b/codegen/override.py index 574f0576..93f563c6 100644 --- a/codegen/override.py +++ b/codegen/override.py @@ -59,10 +59,10 @@ class Overrides: else: line = buffer ; rest = '' words = string.split(line) - if words[0] == 'ignore': + if words[0] == 'ignore' or words[0] == 'ignore-' + sys.platform : for func in words[1:]: self.ignores[func] = 1 for func in string.split(rest): self.ignores[func] = 1 - elif words[0] == 'ignore-glob': + elif words[0] == 'ignore-glob' or words[0] == 'ignore-glob-' + sys.platform : for func in words[1:]: self.glob_ignores.append(func) for func in string.split(rest): self.glob_ignores.append(func) diff --git a/config.h.win32 b/config.h.win32 new file mode 100644 index 00000000..1c7aa301 --- /dev/null +++ b/config.h.win32 @@ -0,0 +1,4 @@ + +#define PYGTK_MAJOR_VERSION (1) +#define PYGTK_MINOR_VERSION (99) +#define PYGTK_MICRO_VERSION (8) diff --git a/examples/pygtk-demo/demos/colorsel.py b/examples/pygtk-demo/demos/colorsel.py index b04e4c24..2408cdea 100644 --- a/examples/pygtk-demo/demos/colorsel.py +++ b/examples/pygtk-demo/demos/colorsel.py @@ -34,13 +34,7 @@ def change_color_cb(w): def main(): global window, color, da - # How do I get a GdkColor? - # GdkColormap.alloc() wants a GtkColor, not strings nor (r, g, b) and - # gtk.gdk.Color isn't implemented... - #color = gtk.gdk.Color() - #color.red = 0 - #color.blue = 0xFFFF - #color.green = 0 + color = gtk.gdk.color_parse("blue") window = gtk.Window() window.set_title("Color selection") @@ -60,7 +54,6 @@ def main(): da = gtk.DrawingArea() da.set_size_request(200, 200) - color = da.get_style().white da.modify_bg(gtk.STATE_NORMAL, color) frame.add(da) diff --git a/gtk/gdk.override b/gtk/gdk.override index b3a6056b..6224d214 100644 --- a/gtk/gdk.override +++ b/gtk/gdk.override @@ -1207,6 +1207,179 @@ _wrap_gdk_gc_new_with_values(PyGObject *self, PyObject *args, PyObject *kwargs) return pygc; } %% +override-slot GdkGC.tp_getattr +PyObject * +_wrap_gdk_gc_tp_getattr(PyGObject *self, char *attr) +{ + GdkGCValues gc; + + if (!strcmp(attr, "__members__")) + return Py_BuildValue("[ssssssssssssssssss]", "background", "cap_style", + "clip_mask", "clip_x_origin", "clip_y_origin", + "fill", "font", "foreground", "function", + "graphics_exposures", "join_style", "line_style", + "line_width", "stipple", "sub_window", "tile", + "ts_x_origin", "ts_y_origin"); + gdk_gc_get_values(GDK_GC(self->obj), &gc); + if (!strcmp(attr, "foreground")) + return pyg_boxed_new(GDK_TYPE_COLOR, &(gc.foreground), TRUE, TRUE); + if (!strcmp(attr, "background")) + return pyg_boxed_new(GDK_TYPE_COLOR, &(gc.background), TRUE, TRUE); + if (!strcmp(attr, "font")) + return pyg_boxed_new(GDK_TYPE_FONT, gc.font, TRUE, TRUE); + if (!strcmp(attr, "function")) + return PyInt_FromLong(gc.function); + if (!strcmp(attr, "fill")) + return PyInt_FromLong(gc.fill); + if (!strcmp(attr, "tile")) + return pygobject_new((GObject *)gc.tile); + if (!strcmp(attr, "stipple")) + return pygobject_new((GObject *)gc.stipple); + if (!strcmp(attr, "clip_mask")) + return pygobject_new((GObject *)gc.clip_mask); + if (!strcmp(attr, "subwindow_mode")) + return PyInt_FromLong(gc.subwindow_mode); + if (!strcmp(attr, "ts_x_origin")) + return PyInt_FromLong(gc.ts_x_origin); + if (!strcmp(attr, "ts_y_origin")) + return PyInt_FromLong(gc.ts_y_origin); + if (!strcmp(attr, "clip_x_origin")) + return PyInt_FromLong(gc.clip_x_origin); + if (!strcmp(attr, "clip_y_origin")) + return PyInt_FromLong(gc.clip_y_origin); + if (!strcmp(attr, "graphics_exposures")) + return PyInt_FromLong(gc.graphics_exposures); + if (!strcmp(attr, "line_width")) + return PyInt_FromLong(gc.line_width); + if (!strcmp(attr, "line_style")) + return PyInt_FromLong(gc.line_style); + if (!strcmp(attr, "cap_style")) + return PyInt_FromLong(gc.cap_style); + if (!strcmp(attr, "join_style")) + return PyInt_FromLong(gc.join_style); + + { + PyObject *name = PyString_FromString(attr); + PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, name); + Py_DECREF(name); + return ret; + } +} +%% +override-slot GdkGC.tp_setattr +static int +_wrap_gdk_gc_tp_setattr(PyGObject *self, char *attr, PyObject *value) +{ + GdkGC *gc = GDK_GC(self->obj); + + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, "can't delete attributes"); + return -1; + } + if (PyInt_Check(value)) { + int i = PyInt_AsLong(value); + GdkGCValues v; + gdk_gc_get_values(gc, &v); + if (!strcmp(attr, "function")) gdk_gc_set_function(gc, i); + else if (!strcmp(attr, "fill")) gdk_gc_set_fill(gc, i); + else if (!strcmp(attr, "subwindow_mode")) gdk_gc_set_subwindow(gc, i); + else if (!strcmp(attr, "ts_x_origin")) + gdk_gc_set_ts_origin(gc, i, v.ts_y_origin); + else if (!strcmp(attr, "ts_y_origin")) + gdk_gc_set_ts_origin(gc, v.ts_x_origin, i); + else if (!strcmp(attr, "clip_x_origin")) + gdk_gc_set_clip_origin(gc, i, v.clip_y_origin); + else if (!strcmp(attr, "clip_y_origin")) + gdk_gc_set_clip_origin(gc, v.clip_x_origin, i); + else if (!strcmp(attr, "graphics_exposures")) gdk_gc_set_exposures(gc, i); + else if (!strcmp(attr, "line_width")) + gdk_gc_set_line_attributes(gc, i,v.line_style,v.cap_style,v.join_style); + else if (!strcmp(attr, "line_style")) + gdk_gc_set_line_attributes(gc, v.line_width,i,v.cap_style,v.join_style); + else if (!strcmp(attr, "cap_style")) + gdk_gc_set_line_attributes(gc, v.line_width,v.line_style,i,v.join_style); + else if (!strcmp(attr, "join_style")) + gdk_gc_set_line_attributes(gc, v.line_width,v.line_style,v.cap_style,i); + else { + PyErr_SetString(PyExc_TypeError,"type mismatch"); + return -1; + } + } else if (pyg_boxed_check(value, GDK_TYPE_COLOR)) { + GdkColor *c = pyg_boxed_get(value, GdkColor); + if (!strcmp(attr, "foreground")) gdk_gc_set_foreground(gc, c); + else if (!strcmp(attr, "background")) gdk_gc_set_background(gc, c); + else { + PyErr_SetString(PyExc_TypeError,"type mismatch"); + return -1; + } + } else if (pyg_boxed_check(value, GDK_TYPE_FONT)) { + if (!strcmp(attr, "font")) gdk_gc_set_font(gc, pyg_boxed_get(value, GdkFont)); + else{ + PyErr_SetString(PyExc_TypeError,"type mismatch"); + return -1; + } + } else if (pygobject_check(value, &PyGdkWindow_Type) || value == Py_None) { + PyGObject *window = (PyGObject *)value; + GdkWindow *w = (value==Py_None)?NULL:GDK_WINDOW(window->obj); + if (!strcmp(attr, "tile")) gdk_gc_set_tile(gc, w); + else if (!strcmp(attr, "stipple")) gdk_gc_set_stipple(gc, w); + else if (!strcmp(attr, "clip_mask")) gdk_gc_set_clip_mask(gc, w); + else { + PyErr_SetString(PyExc_TypeError,"type mismatch"); + return -1; + } + } else { + PyErr_SetString(PyExc_TypeError,"type mismatch"); + return -1; + } + + { + PyObject *name = PyString_FromString(attr); + int ret = PyObject_GenericSetAttr ((PyObject *)self, name, value); + Py_DECREF(name); + return ret; + } + return 0; +} +%% +override gdk_gc_set_dashes +static PyObject * +_wrap_gdk_gc_set_dashes(PyGObject *self, PyObject *args) +{ + gint dash_offset, n, i; + PyObject *list; + guchar *dash_list; + + if (!PyArg_ParseTuple(args, "iO:GdkGC.set_dashes", &dash_offset, &list)) + return NULL; + if (!PySequence_Check(list)) { + PyErr_SetString(PyExc_TypeError, "second argument must be a sequence"); + return NULL; + } + n = PySequence_Length(list); + dash_list = g_new(char, n); + for (i = 0; i < n; i++) { + PyObject *item = PySequence_GetItem(list, i); + Py_DECREF(item); + + if (!PyInt_Check(item)) { + PyErr_SetString(PyExc_TypeError, "sequence member must be an int"); + g_free(dash_list); + return NULL; + } + dash_list[i] = (guchar)PyInt_AsLong(item); + if (dash_list[i] == 0) { + PyErr_SetString(PyExc_TypeError, "sequence member must not be 0"); + g_free(dash_list); + return NULL; + } + } + gdk_gc_set_dashes(GDK_GC(self->obj), dash_offset, dash_list, n); + g_free(dash_list); + Py_INCREF(Py_None); + return Py_None; +} +%% override gdk_drawable_get_size noargs static PyObject * _wrap_gdk_drawable_get_size(PyGObject *self) diff --git a/gtk/gtk-fake-win32.c b/gtk/gtk-fake-win32.c new file mode 100644 index 00000000..0163d686 --- /dev/null +++ b/gtk/gtk-fake-win32.c @@ -0,0 +1,26 @@ +#include <gtk/gtksocket.h> +#include <gtk/gtkplug.h> + +GtkType +gtk_plug_get_type () +{ + static int n = 0; + + if (n > 0) /* first call causes no harm */ + g_warning ("GtkPlug not yet available on win32!"); + n++; + + return 0; +} + +GtkType +gtk_socket_get_type () +{ + static int n = 0; + + if (n > 0) + g_warning ("GtkSocket not yet available on win32!"); + n++; + + return 0; +}
\ No newline at end of file diff --git a/gtk/gtk.override b/gtk/gtk.override index c658b430..005eab97 100644 --- a/gtk/gtk.override +++ b/gtk/gtk.override @@ -5569,3 +5569,9 @@ _wrap_gtk_im_context_get_surrounding(PyGObject *self) Py_INCREF(Py_None); return Py_None; } +%% +ignore-win32 + GTK_TYPE_PLUG + GTK_TYPE_SOCKET + gtk_socket_new +%% diff --git a/gtk/gtkmodule.c b/gtk/gtkmodule.c index 664e4ba0..27b8b658 100644 --- a/gtk/gtkmodule.c +++ b/gtk/gtkmodule.c @@ -35,6 +35,7 @@ init_gtk(void) /* initialise gobject */ init_pygobject(); + g_assert(pygobject_register_class != NULL); /* set the default python encoding to utf-8 */ PyUnicode_SetDefaultEncoding("utf-8"); diff --git a/gtk/makefile.msc b/gtk/makefile.msc new file mode 100644 index 00000000..c275ae52 --- /dev/null +++ b/gtk/makefile.msc @@ -0,0 +1,93 @@ +TOP = ..\..\.. +!INCLUDE $(TOP)\glib\build\win32\make.msc + +#DEBUG=1 + +PYTHON = d:\devel\python22 +!IFNDEF DEBUG +EXTRALIBS = $(PYTHON)\libs\python22.lib user32.lib +!ELSE +EXTRALIBS = $(PYTHON)\Python-2.2\PCbuild\python22_d.lib user32.lib +PYD_POSTFIX = _d +!ENDIF + +EXTRACFLAGS = -I$(PYTHON)\include +MODULE_EXT = pyd + +MODULES = _gtk # libglade gtkgl + +sub-all: + for %d in ($(MODULES)) do nmake -nologo -f makefile.msc sub-one THIS=%d + +sub-one : + nmake -nologo -f makefile.msc MODULE=$(THIS) $(THIS)$(PYD_POSTFIX).$(MODULE_EXT) OBJ_$(THIS)=1 + +all : \ + sub-all + +# nothing much configuarable below this line ... +################################################################# + +.SUFFIXES: .defs .c .exe + +gtk.c : gtk.defs gtk.override +gdk.c : gdk.defs gdk.override +libglade.c : libglade.defs libglade.override +gtkgl.c : gtkgl.defs gtkgl.override + +.defs.c : + $(PYTHON)\python ../codegen/codegen.py \ + --register ../pango-types.defs \ + --register ../atk-types.defs \ + --register ../gtk/gdk-types.defs \ + --register ../gtk/gtk-types.defs \ + --override $*.override \ + --errorfilename gen-$*.err \ + --prefix py$* $*.defs > gen-$*.c + copy gen-$*.c $*.c + del gen-$*.c + +LDFLAGS = /link /machine:ix86 $(LINKDEBUG) +INSTALL = copy + +# GTK_ENABLE_BROKEN for GtkText, GtkTree?? \ +INCLUDES = \ + -FImsvc_recommended_pragmas.h \ + -DHAVE_CONFIG_H -I.. -I. $(EXTRACFLAGS) \ + $(GLIB_CFLAGS) $(GTK2_CFLAGS) $(PANGO_CFLAGS) \ + -DGTK_ENABLE_BROKEN \ + -DVERSION=\"1.99.8\" + +# -I$(LIBGLADE) -I$(LIBXML) + +!IFDEF OBJ__gtk +OBJECTS = \ + gtk.obj \ + gtkmodule.obj \ + gtkobject-support.obj \ + gtk-types.obj \ + gdk.obj \ + pygtktreemodel.obj \ + gtk-fake-win32.obj +!ENDIF + +!IFNDEF OBJECTS +OBJECTS = \ + $(MODULE).obj \ + $(MODULE)module.obj +!ENDIF + + +$(MODULE)$(PYD_POSTFIX).$(MODULE_EXT) : $(OBJECTS) + $(CC) $(CFLAGS) -LD -Fe$@ $(OBJECTS) $(LDFLAGS) $(EXTRALIBS) \ + $(GTK2_LIBS) $(GLIB_LIBS) $(ATK_LIBS) /export:init$(MODULE) + +clean:: + del *.pyc + del *.pyd + +extra-clean: + del gtk.c + del gdk.c + del libglade.c + del gtkgl.c
\ No newline at end of file diff --git a/makefile.msc b/makefile.msc new file mode 100644 index 00000000..84e19784 --- /dev/null +++ b/makefile.msc @@ -0,0 +1,104 @@ +TOP = ..\.. +!INCLUDE $(TOP)\glib\build\win32\make.msc + +#DEBUG=1 + +PYTHON = d:\devel\python22 +!IFNDEF DEBUG +EXTRALIBS = $(PYTHON)\libs\python22.lib user32.lib +!ELSE +EXTRALIBS = $(PYTHON)\Python-2.2\PCbuild\python22_d.lib user32.lib +# Python in Debug Build requires a modue name postfix +PYD_POSTFIX = _d +!ENDIF + +EXTRACFLAGS = -I$(PYTHON)\include +MODULE_EXT = pyd + +MODULES = gobject atk pango + +sub-all: + for %d in ($(MODULES)) do nmake -nologo -f makefile.msc sub-one THIS=%d + +sub-one : + nmake -nologo -f makefile.msc MODULE=$(THIS) $(THIS)$(PYD_POSTFIX).$(MODULE_EXT) OBJ_$(THIS)=1 + +sub-clean : + cd gtk + nmake -nologo -f makefile.msc clean + cd .. + +sub-gtk : + cd gtk + nmake -nologo -f makefile.msc $(TARGET) + cd .. + +all : \ + config.h \ + sub-all \ + sub-gtk + +# nothing much configuarable below this line ... +################################################################# + +.SUFFIXES: .defs .c .exe + +atk.c : atk.defs atk.override +pango.c : pango.defs pango.override + +.defs.c : + $(PYTHON)\python codegen/codegen.py \ + --register pango-types.defs \ + --register atk-types.defs \ +# --register gtk/gdk-types.defs \ +# --register gtk/gtk-types.defs \ + --override $*.override \ + --errorfilename gen-$*.err \ + --prefix py$* $*.defs > gen-$*.c + copy gen-$*.c $*.c + del gen-$*.c + +# cl -? describes the options +# CC = cl -GA -G5 -GF $(OPTIMIZE) -W3 -nologo + +LDFLAGS = /link /machine:ix86 $(LINKDEBUG) + +INCLUDES = \ + -FImsvc_recommended_pragmas.h \ + -DHAVE_CONFIG_H $(EXTRACFLAGS) \ + -I. $(GLIB_CFLAGS) $(PANGO_CFLAGS) $(ATK_CFLAGS) + +# -I$(LIBGLADE) -I$(LIBXML) + +!IFDEF OBJ_gobject +OBJECTS = \ + gobjectmodule.obj \ + pygboxed.obj \ + pygobject.obj \ + pygtype.obj +!ENDIF + +!IFDEF OBJ_atk +EXTRALIBS = $(EXTRALIBS) $(ATK_LIBS) +!ENDIF + +!IFDEF OBJ_pango +EXTRALIBS = $(EXTRALIBS) $(PANGO_LIBS) +!ENDIF + +!IFNDEF OBJECTS +OBJECTS = \ + $(MODULE).obj \ + $(MODULE)module.obj +!ENDIF + +config.h : config.h.win32 + copy config.h.win32 config.h + +$(MODULE)$(PYD_POSTFIX).$(MODULE_EXT) : $(OBJECTS) + $(CC) $(CFLAGS) -LD -Fe$@ $(OBJECTS) $(LDFLAGS) $(EXTRALIBS) \ + $(GLIB_LIBS) /export:init$(MODULE) + +clean:: sub-clean + del *.pyc + del *.pyd |